func createPort(t *testing.T, networkID, subnetID string) string { enable := false opts := ports.CreateOpts{ NetworkID: networkID, Name: "my_port", AdminStateUp: &enable, FixedIPs: []ports.IP{ports.IP{SubnetID: subnetID}}, } p, err := ports.Create(Client, opts).Extract() th.AssertNoErr(t, err) th.AssertEquals(t, p.NetworkID, networkID) th.AssertEquals(t, p.Name, "my_port") th.AssertEquals(t, p.AdminStateUp, false) return p.ID }
func createInternalTopology(t *testing.T) (string, string, string) { t.Logf("Creating an internal network (for port)") opts := networks.CreateOpts{Name: "internal_network"} n, err := networks.Create(base.Client, opts).Extract() th.AssertNoErr(t, err) // A subnet is also needed subnetID := createSubnet(t, n.ID, cidr2) t.Logf("Creating an internal port on network %s", n.ID) p, err := ports.Create(base.Client, ports.CreateOpts{ NetworkID: n.ID, Name: "fixed_internal_port", }).Extract() th.AssertNoErr(t, err) return n.ID, subnetID, p.ID }
func resourceNetworkingPortV2Create(d *schema.ResourceData, meta interface{}) error { config := meta.(*Config) networkingClient, err := config.networkingV2Client(d.Get("region").(string)) if err != nil { return fmt.Errorf("Error creating OpenStack networking client: %s", err) } createOpts := ports.CreateOpts{ Name: d.Get("name").(string), AdminStateUp: resourcePortAdminStateUpV2(d), NetworkID: d.Get("network_id").(string), MACAddress: d.Get("mac_address").(string), TenantID: d.Get("tenant_id").(string), DeviceOwner: d.Get("device_owner").(string), SecurityGroups: resourcePortSecurityGroupsV2(d), DeviceID: d.Get("device_id").(string), FixedIPs: resourcePortFixedIpsV2(d), AllowedAddressPairs: resourceAllowedAddressPairsV2(d), } log.Printf("[DEBUG] Create Options: %#v", createOpts) p, err := ports.Create(networkingClient, createOpts).Extract() if err != nil { return fmt.Errorf("Error creating OpenStack Neutron network: %s", err) } log.Printf("[INFO] Network ID: %s", p.ID) log.Printf("[DEBUG] Waiting for OpenStack Neutron Port (%s) to become available.", p.ID) stateConf := &resource.StateChangeConf{ Target: []string{"ACTIVE"}, Refresh: waitForNetworkPortActive(networkingClient, p.ID), Timeout: 2 * time.Minute, Delay: 5 * time.Second, MinTimeout: 3 * time.Second, } _, err = stateConf.WaitForState() d.SetId(p.ID) return resourceNetworkingPortV2Read(d, meta) }
// Create accepts a CreateOpts struct and creates a new network using the values // provided. You must remember to provide a NetworkID value. func Create(c *gophercloud.ServiceClient, opts os.CreateOptsBuilder) os.CreateResult { return os.Create(c, opts) }