示例#1
0
func TestNetworksCRUD(t *testing.T) {
	client, err := clients.NewNetworkV2Client()
	if err != nil {
		t.Fatalf("Unable to create a network client: %v", err)
	}

	// Create a network
	network, err := CreateNetwork(t, client)
	if err != nil {
		t.Fatalf("Unable to create network: %v", err)
	}
	defer DeleteNetwork(t, client, network.ID)

	PrintNetwork(t, network)

	newName := tools.RandomString("TESTACC-", 8)
	updateOpts := &networks.UpdateOpts{
		Name: newName,
	}

	_, err = networks.Update(client, network.ID, updateOpts).Extract()
	if err != nil {
		t.Fatalf("Unable to update network: %v", err)
	}

	newNetwork, err := networks.Get(client, network.ID).Extract()
	if err != nil {
		t.Fatalf("Unable to retrieve network: %v", err)
	}

	PrintNetwork(t, newNetwork)
}
示例#2
0
func TestLayer3RouterCreateDelete(t *testing.T) {
	client, err := clients.NewNetworkV2Client()
	if err != nil {
		t.Fatalf("Unable to create a network client: %v", err)
	}

	router, err := CreateExternalRouter(t, client)
	if err != nil {
		t.Fatalf("Unable to create router: %v", err)
	}
	defer DeleteRouter(t, client, router.ID)

	PrintRouter(t, router)

	newName := tools.RandomString("TESTACC-", 8)
	updateOpts := routers.UpdateOpts{
		Name: newName,
	}

	_, err = routers.Update(client, router.ID, updateOpts).Extract()
	if err != nil {
		t.Fatalf("Unable to update router: %v", err)
	}

	newRouter, err := routers.Get(client, router.ID).Extract()
	if err != nil {
		t.Fatalf("Unable to get router: %v", err)
	}

	PrintRouter(t, newRouter)
}
示例#3
0
func TestRuleCRUD(t *testing.T) {
	client, err := clients.NewNetworkV2Client()
	if err != nil {
		t.Fatalf("Unable to create a network client: %v", err)
	}

	rule, err := CreateRule(t, client)
	if err != nil {
		t.Fatalf("Unable to create rule: %v", err)
	}
	defer DeleteRule(t, client, rule.ID)

	PrintRule(t, rule)

	ruleDescription := "Some rule description"
	updateOpts := rules.UpdateOpts{
		Description: &ruleDescription,
	}

	_, err = rules.Update(client, rule.ID, updateOpts).Extract()
	if err != nil {
		t.Fatalf("Unable to update rule: %v", err)
	}

	newRule, err := rules.Get(client, rule.ID).Extract()
	if err != nil {
		t.Fatalf("Unable to get rule: %v", err)
	}

	PrintRule(t, newRule)
}
示例#4
0
func TestMonitorsCRUD(t *testing.T) {
	client, err := clients.NewNetworkV2Client()
	if err != nil {
		t.Fatalf("Unable to create a network client: %v", err)
	}

	monitor, err := CreateMonitor(t, client)
	if err != nil {
		t.Fatalf("Unable to create monitor: %v", err)
	}
	defer DeleteMonitor(t, client, monitor.ID)

	PrintMonitor(t, monitor)

	updateOpts := monitors.UpdateOpts{
		Delay: 999,
	}

	_, err = monitors.Update(client, monitor.ID, updateOpts).Extract()
	if err != nil {
		t.Fatalf("Unable to update monitor: %v")
	}

	newMonitor, err := monitors.Get(client, monitor.ID).Extract()
	if err != nil {
		t.Fatalf("Unable to get monitor: %v")
	}

	PrintMonitor(t, newMonitor)
}
func TestLayer3FloatingIPsCreateDelete(t *testing.T) {
	client, err := clients.NewNetworkV2Client()
	if err != nil {
		t.Fatalf("Unable to create a compute client: %v", err)
	}

	choices, err := clients.AcceptanceTestChoicesFromEnv()
	if err != nil {
		t.Fatalf("Unable to get choices: %v", err)
	}

	subnet, err := networking.CreateSubnet(t, client, choices.ExternalNetworkID)
	if err != nil {
		t.Fatalf("Unable to create subnet: %v", err)
	}
	defer networking.DeleteSubnet(t, client, subnet.ID)

	router, err := CreateExternalRouter(t, client)
	if err != nil {
		t.Fatalf("Unable to create router: %v", err)
	}
	defer DeleteRouter(t, client, router.ID)

	port, err := networking.CreatePort(t, client, choices.ExternalNetworkID, subnet.ID)
	if err != nil {
		t.Fatalf("Unable to create port: %v", err)
	}

	_, err = CreateRouterInterface(t, client, port.ID, router.ID)
	if err != nil {
		t.Fatalf("Unable to create router interface: %v", err)
	}
	defer DeleteRouterInterface(t, client, port.ID, router.ID)

	fip, err := CreateFloatingIP(t, client, choices.ExternalNetworkID, port.ID)
	if err != nil {
		t.Fatalf("Unable to create floating IP: %v", err)
	}
	defer DeleteFloatingIP(t, client, fip.ID)

	newFip, err := floatingips.Get(client, fip.ID).Extract()
	if err != nil {
		t.Fatalf("Unable to get floating ip: %v", err)
	}

	PrintFloatingIP(t, newFip)

	// Disassociate the floating IP
	updateOpts := floatingips.UpdateOpts{
		PortID: nil,
	}

	newFip, err = floatingips.Update(client, fip.ID, updateOpts).Extract()
	if err != nil {
		t.Fatalf("Unable to disassociate floating IP: %v", err)
	}
}
示例#6
0
func TestExtensionGet(t *testing.T) {
	client, err := clients.NewNetworkV2Client()
	if err != nil {
		t.Fatalf("Unable to create a network client: %v", err)
	}

	extension, err := extensions.Get(client, "router").Extract()
	if err != nil {
		t.Fatalf("Unable to get extension port-security: %v", err)
	}

	openstack.PrintExtension(t, extension)
}
示例#7
0
func TestVIPsCRUD(t *testing.T) {
	client, err := clients.NewNetworkV2Client()
	if err != nil {
		t.Fatalf("Unable to create a network client: %v", err)
	}

	network, err := networking.CreateNetwork(t, client)
	if err != nil {
		t.Fatalf("Unable to create network: %v", err)
	}
	defer networking.DeleteNetwork(t, client, network.ID)

	subnet, err := networking.CreateSubnet(t, client, network.ID)
	if err != nil {
		t.Fatalf("Unable to create subnet: %v", err)
	}
	defer networking.DeleteSubnet(t, client, subnet.ID)

	pool, err := CreatePool(t, client, subnet.ID)
	if err != nil {
		t.Fatalf("Unable to create pool: %v", err)
	}
	defer DeletePool(t, client, pool.ID)

	vip, err := CreateVIP(t, client, subnet.ID, pool.ID)
	if err != nil {
		t.Fatalf("Unable to create vip: %v", err)
	}
	defer DeleteVIP(t, client, vip.ID)

	PrintVIP(t, vip)

	connLimit := 100
	updateOpts := vips.UpdateOpts{
		ConnLimit: &connLimit,
	}

	_, err = vips.Update(client, vip.ID, updateOpts).Extract()
	if err != nil {
		t.Fatalf("Unable to update vip: %v")
	}

	newVIP, err := vips.Get(client, vip.ID).Extract()
	if err != nil {
		t.Fatalf("Unable to get vip: %v")
	}

	PrintVIP(t, newVIP)
}
示例#8
0
func TestMembersCRUD(t *testing.T) {
	client, err := clients.NewNetworkV2Client()
	if err != nil {
		t.Fatalf("Unable to create a network client: %v", err)
	}

	network, err := networking.CreateNetwork(t, client)
	if err != nil {
		t.Fatalf("Unable to create network: %v", err)
	}
	defer networking.DeleteNetwork(t, client, network.ID)

	subnet, err := networking.CreateSubnet(t, client, network.ID)
	if err != nil {
		t.Fatalf("Unable to create subnet: %v", err)
	}
	defer networking.DeleteSubnet(t, client, subnet.ID)

	pool, err := CreatePool(t, client, subnet.ID)
	if err != nil {
		t.Fatalf("Unable to create pool: %v", err)
	}
	defer DeletePool(t, client, pool.ID)

	member, err := CreateMember(t, client, pool.ID)
	if err != nil {
		t.Fatalf("Unable to create member: %v", err)
	}
	defer DeleteMember(t, client, member.ID)

	PrintMember(t, member)

	updateOpts := members.UpdateOpts{
		AdminStateUp: gophercloud.Enabled,
	}

	_, err = members.Update(client, member.ID, updateOpts).Extract()
	if err != nil {
		t.Fatalf("Unable to update member: %v")
	}

	newMember, err := members.Get(client, member.ID).Extract()
	if err != nil {
		t.Fatalf("Unable to get member: %v")
	}

	PrintMember(t, newMember)
}
示例#9
0
func TestFirewallCRUD(t *testing.T) {
	client, err := clients.NewNetworkV2Client()
	if err != nil {
		t.Fatalf("Unable to create a network client: %v", err)
	}

	rule, err := CreateRule(t, client)
	if err != nil {
		t.Fatalf("Unable to create rule: %v", err)
	}
	defer DeleteRule(t, client, rule.ID)

	PrintRule(t, rule)

	policy, err := CreatePolicy(t, client, rule.ID)
	if err != nil {
		t.Fatalf("Unable to create policy: %v", err)
	}
	defer DeletePolicy(t, client, policy.ID)

	PrintPolicy(t, policy)

	firewall, err := CreateFirewall(t, client, policy.ID)
	if err != nil {
		t.Fatalf("Unable to create firewall: %v", err)
	}
	defer DeleteFirewall(t, client, firewall.ID)

	PrintFirewall(t, firewall)

	updateOpts := firewalls.UpdateOpts{
		PolicyID:    policy.ID,
		Description: "Some firewall description",
	}

	_, err = firewalls.Update(client, firewall.ID, updateOpts).Extract()
	if err != nil {
		t.Fatalf("Unable to update firewall: %v", err)
	}

	newFirewall, err := firewalls.Get(client, firewall.ID).Extract()
	if err != nil {
		t.Fatalf("Unable to get firewall: %v", err)
	}

	PrintFirewall(t, newFirewall)
}
示例#10
0
func TestLayer3RouterInterface(t *testing.T) {
	client, err := clients.NewNetworkV2Client()
	if err != nil {
		t.Fatalf("Unable to create a compute client: %v", err)
	}

	choices, err := clients.AcceptanceTestChoicesFromEnv()
	if err != nil {
		t.Fatalf("Unable to get choices: %v", err)
	}

	subnet, err := networking.CreateSubnet(t, client, choices.ExternalNetworkID)
	if err != nil {
		t.Fatalf("Unable to create subnet: %v", err)
	}
	defer networking.DeleteSubnet(t, client, subnet.ID)

	networking.PrintSubnet(t, subnet)

	router, err := CreateExternalRouter(t, client)
	if err != nil {
		t.Fatalf("Unable to create router: %v", err)
	}
	defer DeleteRouter(t, client, router.ID)

	aiOpts := routers.AddInterfaceOpts{
		SubnetID: subnet.ID,
	}

	iface, err := routers.AddInterface(client, router.ID, aiOpts).Extract()
	if err != nil {
		t.Fatalf("Failed to add interface to router: %v", err)
	}

	PrintRouter(t, router)
	PrintRouterInterface(t, iface)

	riOpts := routers.RemoveInterfaceOpts{
		SubnetID: subnet.ID,
	}

	_, err = routers.RemoveInterface(client, router.ID, riOpts).Extract()
	if err != nil {
		t.Fatalf("Failed to remove interface from router: %v", err)
	}
}
func TestPortsbindingCRUD(t *testing.T) {
	client, err := clients.NewNetworkV2Client()
	if err != nil {
		t.Fatalf("Unable to create a network client: %v", err)
	}

	// Create Network
	network, err := networking.CreateNetwork(t, client)
	if err != nil {
		t.Fatalf("Unable to create network: %v", err)
	}
	defer networking.DeleteNetwork(t, client, network.ID)

	// Create Subnet
	subnet, err := networking.CreateSubnet(t, client, network.ID)
	if err != nil {
		t.Fatalf("Unable to create subnet: %v", err)
	}
	defer networking.DeleteSubnet(t, client, subnet.ID)

	// Define a host
	hostID := "localhost"

	// Create port
	port, err := CreatePortsbinding(t, client, network.ID, subnet.ID, hostID)
	if err != nil {
		t.Fatalf("Unable to create port: %v", err)
	}
	defer networking.DeletePort(t, client, port.ID)

	PrintPortsbinding(t, port)

	// Update port
	newPortName := tools.RandomString("TESTACC-", 8)
	updateOpts := ports.UpdateOpts{
		Name: newPortName,
	}
	newPort, err := portsbinding.Update(client, port.ID, updateOpts).Extract()
	if err != nil {
		t.Fatalf("Could not update port: %v", err)
	}

	PrintPortsbinding(t, newPort)
}
示例#12
0
func TestPoolsCRUD(t *testing.T) {
	client, err := clients.NewNetworkV2Client()
	if err != nil {
		t.Fatalf("Unable to create a network client: %v", err)
	}

	network, err := networking.CreateNetwork(t, client)
	if err != nil {
		t.Fatalf("Unable to create network: %v", err)
	}
	defer networking.DeleteNetwork(t, client, network.ID)

	subnet, err := networking.CreateSubnet(t, client, network.ID)
	if err != nil {
		t.Fatalf("Unable to create subnet: %v", err)
	}
	defer networking.DeleteSubnet(t, client, subnet.ID)

	pool, err := CreatePool(t, client, subnet.ID)
	if err != nil {
		t.Fatalf("Unable to create pool: %v", err)
	}
	defer DeletePool(t, client, pool.ID)

	PrintPool(t, pool)

	updateOpts := pools.UpdateOpts{
		LBMethod: pools.LBMethodLeastConnections,
	}

	_, err = pools.Update(client, pool.ID, updateOpts).Extract()
	if err != nil {
		t.Fatalf("Unable to update pool: %v")
	}

	newPool, err := pools.Get(client, pool.ID).Extract()
	if err != nil {
		t.Fatalf("Unable to get pool: %v")
	}

	PrintPool(t, newPool)
}
示例#13
0
func TestFirewallList(t *testing.T) {
	client, err := clients.NewNetworkV2Client()
	if err != nil {
		t.Fatalf("Unable to create a network client: %v", err)
	}

	allPages, err := firewalls.List(client, nil).AllPages()
	if err != nil {
		t.Fatalf("Unable to list firewalls: %v", err)
	}

	allFirewalls, err := firewalls.ExtractFirewalls(allPages)
	if err != nil {
		t.Fatalf("Unable to extract firewalls: %v", err)
	}

	for _, firewall := range allFirewalls {
		PrintFirewall(t, &firewall)
	}
}
示例#14
0
func TestNetworksList(t *testing.T) {
	client, err := clients.NewNetworkV2Client()
	if err != nil {
		t.Fatalf("Unable to create a network client: %v", err)
	}

	allPages, err := networks.List(client, nil).AllPages()
	if err != nil {
		t.Fatalf("Unable to list networks: %v", err)
	}

	allNetworks, err := networks.ExtractNetworks(allPages)
	if err != nil {
		t.Fatalf("Unable to extract networks: %v", err)
	}

	for _, network := range allNetworks {
		PrintNetwork(t, &network)
	}
}
示例#15
0
func TestVIPsList(t *testing.T) {
	client, err := clients.NewNetworkV2Client()
	if err != nil {
		t.Fatalf("Unable to create a network client: %v", err)
	}

	allPages, err := vips.List(client, vips.ListOpts{}).AllPages()
	if err != nil {
		t.Fatalf("Unable to list vips: %v", err)
	}

	allVIPs, err := vips.ExtractVIPs(allPages)
	if err != nil {
		t.Fatalf("Unable to extract vips: %v", err)
	}

	for _, vip := range allVIPs {
		PrintVIP(t, &vip)
	}
}
示例#16
0
func TestAPIVersionsList(t *testing.T) {
	client, err := clients.NewNetworkV2Client()
	if err != nil {
		t.Fatalf("Unable to create a network client: %v", err)
	}

	allPages, err := apiversions.ListVersions(client).AllPages()
	if err != nil {
		t.Fatalf("Unable to list api versions: %v", err)
	}

	allAPIVersions, err := apiversions.ExtractAPIVersions(allPages)
	if err != nil {
		t.Fatalf("Unable to extract api versions: %v", err)
	}

	for _, apiVersion := range allAPIVersions {
		PrintAPIVersion(t, &apiVersion)
	}
}
示例#17
0
func TestSecurityGroupsCreateDelete(t *testing.T) {
	client, err := clients.NewNetworkV2Client()
	if err != nil {
		t.Fatalf("Unable to create a network client: %v", err)
	}

	group, err := CreateSecurityGroup(t, client)
	if err != nil {
		t.Fatalf("Unable to create security group: %v", err)
	}
	defer DeleteSecurityGroup(t, client, group.ID)

	rule, err := CreateSecurityGroupRule(t, client, group.ID)
	if err != nil {
		t.Fatalf("Unable to create security group rule: %v", err)
	}
	defer DeleteSecurityGroupRule(t, client, rule.ID)

	PrintSecurityGroup(t, group)
}
示例#18
0
func TestAPIResourcesList(t *testing.T) {
	client, err := clients.NewNetworkV2Client()
	if err != nil {
		t.Fatalf("Unable to create a network client: %v", err)
	}

	allPages, err := apiversions.ListVersionResources(client, "v2.0").AllPages()
	if err != nil {
		t.Fatalf("Unable to list api version reosources: %v", err)
	}

	allVersionResources, err := apiversions.ExtractVersionResources(allPages)
	if err != nil {
		t.Fatalf("Unable to extract version resources: %v", err)
	}

	for _, versionResource := range allVersionResources {
		PrintVersionResource(t, &versionResource)
	}
}
示例#19
0
func TestSubnetsList(t *testing.T) {
	client, err := clients.NewNetworkV2Client()
	if err != nil {
		t.Fatalf("Unable to create a network client: %v", err)
	}

	allPages, err := subnets.List(client, nil).AllPages()
	if err != nil {
		t.Fatalf("Unable to list subnets: %v", err)
	}

	allSubnets, err := subnets.ExtractSubnets(allPages)
	if err != nil {
		t.Fatalf("Unable to extract subnets: %v", err)
	}

	for _, subnet := range allSubnets {
		PrintSubnet(t, &subnet)
	}
}
示例#20
0
func TestPortsList(t *testing.T) {
	client, err := clients.NewNetworkV2Client()
	if err != nil {
		t.Fatalf("Unable to create a network client: %v", err)
	}

	allPages, err := ports.List(client, nil).AllPages()
	if err != nil {
		t.Fatalf("Unable to list ports: %v", err)
	}

	allPorts, err := ports.ExtractPorts(allPages)
	if err != nil {
		t.Fatalf("Unable to extract ports: %v", err)
	}

	for _, port := range allPorts {
		PrintPort(t, &port)
	}
}
示例#21
0
func TestRuleList(t *testing.T) {
	client, err := clients.NewNetworkV2Client()
	if err != nil {
		t.Fatalf("Unable to create a network client: %v", err)
	}

	allPages, err := rules.List(client, nil).AllPages()
	if err != nil {
		t.Fatalf("Unable to list rules: %v", err)
	}

	allRules, err := rules.ExtractRules(allPages)
	if err != nil {
		t.Fatalf("Unable to extract rules: %v", err)
	}

	for _, rule := range allRules {
		PrintRule(t, &rule)
	}
}
func TestLoadbalancersList(t *testing.T) {
	client, err := clients.NewNetworkV2Client()
	if err != nil {
		t.Fatalf("Unable to create a network client: %v", err)
	}

	allPages, err := loadbalancers.List(client, nil).AllPages()
	if err != nil {
		t.Fatalf("Unable to list loadbalancers: %v", err)
	}

	allLoadbalancers, err := loadbalancers.ExtractLoadBalancers(allPages)
	if err != nil {
		t.Fatalf("Unable to extract loadbalancers: %v", err)
	}

	for _, lb := range allLoadbalancers {
		PrintLoadBalancer(t, &lb)
	}
}
示例#23
0
func TestExtensionsList(t *testing.T) {
	client, err := clients.NewNetworkV2Client()
	if err != nil {
		t.Fatalf("Unable to create a network client: %v", err)
	}

	allPages, err := extensions.List(client).AllPages()
	if err != nil {
		t.Fatalf("Unable to list extensions: %v", err)
	}

	allExtensions, err := extensions.ExtractExtensions(allPages)
	if err != nil {
		t.Fatalf("Unable to extract extensions: %v", err)
	}

	for _, extension := range allExtensions {
		openstack.PrintExtension(t, &extension)
	}
}
示例#24
0
func TestMonitorsList(t *testing.T) {
	client, err := clients.NewNetworkV2Client()
	if err != nil {
		t.Fatalf("Unable to create a network client: %v", err)
	}

	allPages, err := monitors.List(client, nil).AllPages()
	if err != nil {
		t.Fatalf("Unable to list monitors: %v", err)
	}

	allMonitors, err := monitors.ExtractMonitors(allPages)
	if err != nil {
		t.Fatalf("Unable to extract monitors: %v", err)
	}

	for _, monitor := range allMonitors {
		PrintMonitor(t, &monitor)
	}
}
示例#25
0
func TestPoolsMonitors(t *testing.T) {
	client, err := clients.NewNetworkV2Client()
	if err != nil {
		t.Fatalf("Unable to create a network client: %v", err)
	}

	network, err := networking.CreateNetwork(t, client)
	if err != nil {
		t.Fatalf("Unable to create network: %v", err)
	}
	defer networking.DeleteNetwork(t, client, network.ID)

	subnet, err := networking.CreateSubnet(t, client, network.ID)
	if err != nil {
		t.Fatalf("Unable to create subnet: %v", err)
	}
	defer networking.DeleteSubnet(t, client, subnet.ID)

	pool, err := CreatePool(t, client, subnet.ID)
	if err != nil {
		t.Fatalf("Unable to create pool: %v", err)
	}
	defer DeletePool(t, client, pool.ID)

	monitor, err := CreateMonitor(t, client)
	if err != nil {
		t.Fatalf("Unable to create monitor: %v", err)
	}
	defer DeleteMonitor(t, client, monitor.ID)

	t.Logf("Associating monitor %s with pool %s", monitor.ID, pool.ID)
	if res := pools.AssociateMonitor(client, pool.ID, monitor.ID); res.Err != nil {
		t.Fatalf("Unable to associate monitor to pool")
	}

	t.Logf("Disassociating monitor %s with pool %s", monitor.ID, pool.ID)
	if res := pools.DisassociateMonitor(client, pool.ID, monitor.ID); res.Err != nil {
		t.Fatalf("Unable to disassociate monitor from pool")
	}

}
示例#26
0
func TestSubnetsNoGateway(t *testing.T) {
	client, err := clients.NewNetworkV2Client()
	if err != nil {
		t.Fatalf("Unable to create a network client: %v", err)
	}

	// Create Network
	network, err := CreateNetwork(t, client)
	if err != nil {
		t.Fatalf("Unable to create network: %v", err)
	}
	defer DeleteNetwork(t, client, network.ID)

	// Create Subnet
	subnet, err := CreateSubnetWithNoGateway(t, client, network.ID)
	if err != nil {
		t.Fatalf("Unable to create subnet: %v", err)
	}
	defer DeleteSubnet(t, client, subnet.ID)

	PrintSubnet(t, subnet)

	if subnet.GatewayIP != "" {
		t.Fatalf("A gateway exists when it shouldn't.")
	}

	subnetParts := strings.Split(subnet.CIDR, ".")
	newGateway := fmt.Sprintf("%s.%s.%s.1", subnetParts[0], subnetParts[1], subnetParts[2])
	updateOpts := subnets.UpdateOpts{
		GatewayIP: &newGateway,
	}

	newSubnet, err := subnets.Update(client, subnet.ID, updateOpts).Extract()
	if err != nil {
		t.Fatalf("Unable to update subnet")
	}

	if newSubnet.GatewayIP == "" {
		t.Fatalf("Gateway was not updated correctly")
	}
}
示例#27
0
func TestNetworksProviderCRUD(t *testing.T) {
	client, err := clients.NewNetworkV2Client()
	if err != nil {
		t.Fatalf("Unable to create a network client: %v", err)
	}

	// Create a network
	network, err := networking.CreateNetwork(t, client)
	if err != nil {
		t.Fatalf("Unable to create network: %v", err)
	}
	defer networking.DeleteNetwork(t, client, network.ID)

	getResult := networks.Get(client, network.ID)
	newNetwork, err := provider.ExtractGet(getResult)
	if err != nil {
		t.Fatalf("Unable to extract network: %v", err)
	}

	PrintNetworkExtAttrs(t, newNetwork)
}
示例#28
0
func TestSecurityGroupsList(t *testing.T) {
	client, err := clients.NewNetworkV2Client()
	if err != nil {
		t.Fatalf("Unable to create a network client: %v", err)
	}

	listOpts := groups.ListOpts{}
	allPages, err := groups.List(client, listOpts).AllPages()
	if err != nil {
		t.Fatalf("Unable to list groups: %v", err)
	}

	allGroups, err := groups.ExtractGroups(allPages)
	if err != nil {
		t.Fatalf("Unable to extract groups: %v", err)
	}

	for _, group := range allGroups {
		PrintSecurityGroup(t, &group)
	}
}
示例#29
0
func TestLayer3FloatingIPsList(t *testing.T) {
	client, err := clients.NewNetworkV2Client()
	if err != nil {
		t.Fatalf("Unable to create a compute client: %v", err)
	}

	listOpts := floatingips.ListOpts{}
	allPages, err := floatingips.List(client, listOpts).AllPages()
	if err != nil {
		t.Fatalf("Unable to list floating IPs: %v", err)
	}

	allFIPs, err := floatingips.ExtractFloatingIPs(allPages)
	if err != nil {
		t.Fatalf("Unable to extract floating IPs: %v", err)
	}

	for _, fip := range allFIPs {
		PrintFloatingIP(t, &fip)
	}
}
示例#30
0
func TestLayer3RouterList(t *testing.T) {
	client, err := clients.NewNetworkV2Client()
	if err != nil {
		t.Fatalf("Unable to create a network client: %v", err)
	}

	listOpts := routers.ListOpts{}
	allPages, err := routers.List(client, listOpts).AllPages()
	if err != nil {
		t.Fatalf("Unable to list routers: %v", err)
	}

	allRouters, err := routers.ExtractRouters(allPages)
	if err != nil {
		t.Fatalf("Unable to extract routers: %v", err)
	}

	for _, router := range allRouters {
		PrintRouter(t, &router)
	}
}