本文整理匯總了Golang中github.com/gophercloud/gophercloud/acceptance/clients.NewNetworkV2Client函數的典型用法代碼示例。如果您正苦於以下問題:Golang NewNetworkV2Client函數的具體用法?Golang NewNetworkV2Client怎麽用?Golang NewNetworkV2Client使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了NewNetworkV2Client函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: TestNetworksCRUD
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: TestLayer3RouterCreateDelete
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: TestRuleCRUD
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: TestMonitorsCRUD
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)
}
示例5: TestLayer3FloatingIPsCreateDelete
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: TestExtensionGet
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: TestVIPsCRUD
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: TestMembersCRUD
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: TestFirewallCRUD
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: TestLayer3RouterInterface
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)
}
}
示例11: TestPortsbindingCRUD
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: TestPoolsCRUD
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: TestFirewallList
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: TestNetworksList
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: TestVIPsList
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)
}
}