Example #1
0
File: create.go Project: flazz/rack
func (command *commandCreate) Execute(resource *handler.Resource) {
	opts := resource.Params.(*paramsCreate).opts
	subnet, err := subnets.Create(command.Ctx.ServiceClient, opts).Extract()
	if err != nil {
		resource.Err = err
		return
	}
	resource.Result = subnetSingle(subnet)
}
Example #2
0
func createSubnet(networkID string) (string, error) {
	s, err := subnets.Create(Client, osSubnets.CreateOpts{
		NetworkID:  networkID,
		CIDR:       "192.168.199.0/24",
		IPVersion:  osSubnets.IPv4,
		Name:       "my_subnet",
		EnableDHCP: osSubnets.Down,
	}).Extract()
	return s.ID, err
}
Example #3
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)
}