예제 #1
0
파일: update.go 프로젝트: flazz/rack
func (command *commandUpdate) Execute(resource *handler.Resource) {
	subnetID := resource.Params.(*paramsUpdate).subnetID
	opts := resource.Params.(*paramsUpdate).opts
	subnet, err := subnets.Update(command.Ctx.ServiceClient, subnetID, opts).Extract()
	if err != nil {
		resource.Err = err
		return
	}
	resource.Result = subnetSingle(subnet)
}
예제 #2
0
func TestSubnetCRUD(t *testing.T) {
	Setup(t)
	defer Teardown()

	// Setup network
	t.Log("Setting up network")
	n, err := networks.Create(Client, osNetworks.CreateOpts{Name: "tmp_network", AdminStateUp: osNetworks.Up}).Extract()
	th.AssertNoErr(t, err)
	networkID := n.ID
	defer networks.Delete(Client, networkID)

	// Create subnet
	t.Log("Create subnet")
	enable := false
	opts := osSubnets.CreateOpts{
		NetworkID:  networkID,
		CIDR:       "192.168.199.0/24",
		IPVersion:  osSubnets.IPv4,
		Name:       "my_subnet",
		EnableDHCP: &enable,
	}
	s, err := subnets.Create(Client, opts).Extract()
	th.AssertNoErr(t, err)

	th.AssertEquals(t, networkID, s.NetworkID)
	th.AssertEquals(t, "192.168.199.0/24", s.CIDR)
	th.AssertEquals(t, 4, s.IPVersion)
	th.AssertEquals(t, "my_subnet", s.Name)
	th.AssertEquals(t, false, s.EnableDHCP)
	subnetID := s.ID

	// Get subnet
	t.Log("Getting subnet")
	s, err = subnets.Get(Client, subnetID).Extract()
	th.AssertNoErr(t, err)
	th.AssertEquals(t, subnetID, s.ID)

	// Update subnet
	t.Log("Update subnet")
	s, err = subnets.Update(Client, subnetID, osSubnets.UpdateOpts{Name: "new_subnet_name"}).Extract()
	th.AssertNoErr(t, err)
	th.AssertEquals(t, "new_subnet_name", s.Name)

	// Delete subnet
	t.Log("Delete subnet")
	res := subnets.Delete(Client, subnetID)
	th.AssertNoErr(t, res.Err)
}