github.com/huaweicloud/golangsdk@v0.0.0-20210831081626-d823fe11ceba/openstack/networking/v2/extensions/portsecurity/doc.go (about) 1 /* 2 Package portsecurity provides information and interaction with the port 3 security extension for the OpenStack Networking service. 4 5 Example to List Networks with Port Security Information 6 7 type NetworkWithPortSecurityExt struct { 8 networks.Network 9 portsecurity.PortSecurityExt 10 } 11 12 var allNetworks []NetworkWithPortSecurityExt 13 14 listOpts := networks.ListOpts{ 15 Name: "network_1", 16 } 17 18 allPages, err := networks.List(networkClient, listOpts).AllPages() 19 if err != nil { 20 panic(err) 21 } 22 23 err = networks.ExtractNetworksInto(allPages, &allNetworks) 24 if err != nil { 25 panic(err) 26 } 27 28 for _, network := range allNetworks { 29 fmt.Println("%+v\n", network) 30 } 31 32 Example to Create a Network without Port Security 33 34 var networkWithPortSecurityExt struct { 35 networks.Network 36 portsecurity.PortSecurityExt 37 } 38 39 networkCreateOpts := networks.CreateOpts{ 40 Name: "private", 41 } 42 43 iFalse := false 44 createOpts := portsecurity.NetworkCreateOptsExt{ 45 CreateOptsBuilder: networkCreateOpts, 46 PortSecurityEnabled: &iFalse, 47 } 48 49 err := networks.Create(networkClient, createOpts).ExtractInto(&networkWithPortSecurityExt) 50 if err != nil { 51 panic(err) 52 } 53 54 fmt.Println("%+v\n", networkWithPortSecurityExt) 55 56 Example to Disable Port Security on an Existing Network 57 58 var networkWithPortSecurityExt struct { 59 networks.Network 60 portsecurity.PortSecurityExt 61 } 62 63 iFalse := false 64 networkID := "4e8e5957-649f-477b-9e5b-f1f75b21c03c" 65 networkUpdateOpts := networks.UpdateOpts{} 66 updateOpts := portsecurity.NetworkUpdateOptsExt{ 67 UpdateOptsBuilder: networkUpdateOpts, 68 PortSecurityEnabled: &iFalse, 69 } 70 71 err := networks.Update(networkClient, networkID, updateOpts).ExtractInto(&networkWithPortSecurityExt) 72 if err != nil { 73 panic(err) 74 } 75 76 fmt.Println("%+v\n", networkWithPortSecurityExt) 77 78 Example to Get a Port with Port Security Information 79 80 var portWithPortSecurityExtensions struct { 81 ports.Port 82 portsecurity.PortSecurityExt 83 } 84 85 portID := "46d4bfb9-b26e-41f3-bd2e-e6dcc1ccedb2" 86 87 err := ports.Get(networkingClient, portID).ExtractInto(&portWithPortSecurityExtensions) 88 if err != nil { 89 panic(err) 90 } 91 92 fmt.Println("%+v\n", portWithPortSecurityExtensions) 93 94 Example to Create a Port Without Port Security 95 96 var portWithPortSecurityExtensions struct { 97 ports.Port 98 portsecurity.PortSecurityExt 99 } 100 101 iFalse := false 102 networkID := "4e8e5957-649f-477b-9e5b-f1f75b21c03c" 103 subnetID := "a87cc70a-3e15-4acf-8205-9b711a3531b7" 104 105 portCreateOpts := ports.CreateOpts{ 106 NetworkID: networkID, 107 FixedIPs: []ports.IP{ports.IP{SubnetID: subnetID}}, 108 } 109 110 createOpts := portsecurity.PortCreateOptsExt{ 111 CreateOptsBuilder: portCreateOpts, 112 PortSecurityEnabled: &iFalse, 113 } 114 115 err := ports.Create(networkingClient, createOpts).ExtractInto(&portWithPortSecurityExtensions) 116 if err != nil { 117 panic(err) 118 } 119 120 fmt.Println("%+v\n", portWithPortSecurityExtensions) 121 122 Example to Disable Port Security on an Existing Port 123 124 var portWithPortSecurityExtensions struct { 125 ports.Port 126 portsecurity.PortSecurityExt 127 } 128 129 iFalse := false 130 portID := "65c0ee9f-d634-4522-8954-51021b570b0d" 131 132 portUpdateOpts := ports.UpdateOpts{} 133 updateOpts := portsecurity.PortUpdateOptsExt{ 134 UpdateOptsBuilder: portUpdateOpts, 135 PortSecurityEnabled: &iFalse, 136 } 137 138 err := ports.Update(networkingClient, portID, updateOpts).ExtractInto(&portWithPortSecurityExtensions) 139 if err != nil { 140 panic(err) 141 } 142 143 fmt.Println("%+v\n", portWithPortSecurityExtensions) 144 */ 145 package portsecurity