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) }
func TestUpdate(t *testing.T) { th.SetupHTTP() defer th.TeardownHTTP() th.Mux.HandleFunc("/v2.0/networks/4e8e5957-649f-477b-9e5b-f1f75b21c03c", func(w http.ResponseWriter, r *http.Request) { th.TestMethod(t, r, "PUT") th.TestHeader(t, r, "X-Auth-Token", fake.TokenID) th.TestHeader(t, r, "Content-Type", "application/json") th.TestHeader(t, r, "Accept", "application/json") th.TestJSONRequest(t, r, ` { "network": { "name": "new_network_name", "admin_state_up": false, "shared": true } } `) w.Header().Add("Content-Type", "application/json") w.WriteHeader(http.StatusOK) fmt.Fprintf(w, ` { "network": { "status": "ACTIVE", "subnets": [ "54d6f61d-db07-451c-9ab3-b9609b6b6f0b" ], "name": "private-network", "provider:physical_network": null, "admin_state_up": true, "tenant_id": "4fd44f30292945e481c7b8a0c8908869", "provider:network_type": "local", "shared": true, "id": "d32019d3-bc6e-4319-9c1d-6722fc136a22", "provider:segmentation_id": null } } `) }) iTrue := true options := networks.UpdateOpts{Name: "new_network_name", AdminStateUp: gophercloud.Disabled, Shared: &iTrue} res := networks.Update(fake.ServiceClient(), "4e8e5957-649f-477b-9e5b-f1f75b21c03c", options) n, err := provider.ExtractUpdate(res) th.AssertNoErr(t, err) th.AssertEquals(t, "", n.PhysicalNetwork) th.AssertEquals(t, "local", n.NetworkType) th.AssertEquals(t, "", n.SegmentationID) }
func TestUpdate(t *testing.T) { th.SetupHTTP() defer th.TeardownHTTP() th.Mux.HandleFunc("/v2.0/networks/4e8e5957-649f-477b-9e5b-f1f75b21c03c", func(w http.ResponseWriter, r *http.Request) { th.TestMethod(t, r, "PUT") th.TestHeader(t, r, "X-Auth-Token", fake.TokenID) th.TestHeader(t, r, "Content-Type", "application/json") th.TestHeader(t, r, "Accept", "application/json") th.TestJSONRequest(t, r, ` { "network": { "name": "new_network_name", "admin_state_up": false, "shared": true } } `) w.Header().Add("Content-Type", "application/json") w.WriteHeader(http.StatusOK) fmt.Fprintf(w, ` { "network": { "status": "ACTIVE", "subnets": [], "name": "new_network_name", "admin_state_up": false, "tenant_id": "4fd44f30292945e481c7b8a0c8908869", "shared": true, "id": "4e8e5957-649f-477b-9e5b-f1f75b21c03c" } } `) }) iTrue, iFalse := true, false options := networks.UpdateOpts{Name: "new_network_name", AdminStateUp: &iFalse, Shared: &iTrue} n, err := networks.Update(fake.ServiceClient(), "4e8e5957-649f-477b-9e5b-f1f75b21c03c", options).Extract() th.AssertNoErr(t, err) th.AssertEquals(t, n.Name, "new_network_name") th.AssertEquals(t, n.AdminStateUp, false) th.AssertEquals(t, n.Shared, true) th.AssertEquals(t, n.ID, "4e8e5957-649f-477b-9e5b-f1f75b21c03c") }
func TestUpdate(t *testing.T) { th.SetupHTTP() defer th.TeardownHTTP() th.Mux.HandleFunc("/networks/4e8e5957-649f-477b-9e5b-f1f75b21c03c", func(w http.ResponseWriter, r *http.Request) { th.TestMethod(t, r, "PUT") th.TestHeader(t, r, "X-Auth-Token", fake.TokenID) th.TestHeader(t, r, "Content-Type", "application/json") th.TestHeader(t, r, "Accept", "application/json") th.TestJSONRequest(t, r, ` { "network": { "router:external": true, "name": "new_name" } } `) w.Header().Add("Content-Type", "application/json") w.WriteHeader(http.StatusOK) fmt.Fprintf(w, ` { "network": { "admin_state_up": true, "id": "8d05a1b1-297a-46ca-8974-17debf51ca3c", "name": "new_name", "router:external": true, "shared": false, "status": "ACTIVE", "subnets": [ "2f1fb918-9b0e-4bf9-9a50-6cebbb4db2c5" ], "tenant_id": "5eb8995cf717462c9df8d1edfa498010" } } `) }) options := external.UpdateOpts{networks.UpdateOpts{Name: "new_name"}, gophercloud.Enabled} res := networks.Update(fake.ServiceClient(), "4e8e5957-649f-477b-9e5b-f1f75b21c03c", options) n, err := external.ExtractUpdate(res) th.AssertNoErr(t, err) th.AssertEquals(t, true, n.External) }
func resourceNetworkingNetworkV2Update(d *schema.ResourceData, meta interface{}) error { config := meta.(*Config) networkingClient, err := config.networkingV2Client(GetRegion(d)) if err != nil { return fmt.Errorf("Error creating OpenStack networking client: %s", err) } var updateOpts networks.UpdateOpts if d.HasChange("name") { updateOpts.Name = d.Get("name").(string) } if d.HasChange("admin_state_up") { asuRaw := d.Get("admin_state_up").(string) if asuRaw != "" { asu, err := strconv.ParseBool(asuRaw) if err != nil { return fmt.Errorf("admin_state_up, if provided, must be either 'true' or 'false'") } updateOpts.AdminStateUp = &asu } } if d.HasChange("shared") { sharedRaw := d.Get("shared").(string) if sharedRaw != "" { shared, err := strconv.ParseBool(sharedRaw) if err != nil { return fmt.Errorf("shared, if provided, must be either 'true' or 'false': %v", err) } updateOpts.Shared = &shared } } log.Printf("[DEBUG] Updating Network %s with options: %+v", d.Id(), updateOpts) _, err = networks.Update(networkingClient, d.Id(), updateOpts).Extract() if err != nil { return fmt.Errorf("Error updating OpenStack Neutron Network: %s", err) } return resourceNetworkingNetworkV2Read(d, meta) }