Example #1
0
func (command *commandUpload) HandleFlags(resource *handler.Resource) error {
	err := command.Ctx.CheckFlagsSet([]string{"container", "name"})
	if err != nil {
		return err
	}

	c := command.Ctx.CLIContext

	opts := osObjects.CreateOpts{
		ContentLength: int64(c.Int("content-length")),
		ContentType:   c.String("content-type"),
	}

	if c.IsSet("content-encoding") && c.String("content-encoding") != "gzip" {
		opts.ContentEncoding = c.String("content-encoding")
	}

	resource.Params = &paramsUpload{
		container: c.String("container"),
		object:    c.String("name"),
		opts:      opts,
	}

	return nil
}
Example #2
0
func (command *commandGetMetadata) HandleFlags(resource *handler.Resource) error {
	serverID, err := command.Ctx.IDOrName(osServers.IDFromName)
	resource.Params = &paramsGetMetadata{
		serverID: serverID,
	}
	return err
}
Example #3
0
func (command *commandList) HandleFlags(resource *handler.Resource) error {
	c := command.Ctx.CLIContext
	opts := &osNetworks.ListOpts{
		Name:     c.String("name"),
		TenantID: c.String("tenant-id"),
		Status:   c.String("status"),
		Marker:   c.String("marker"),
		Limit:    c.Int("limit"),
	}
	if c.IsSet("up") {
		upRaw := c.String("up")
		up, err := strconv.ParseBool(upRaw)
		if err != nil {
			return fmt.Errorf("Invalid value for flag `up`: %s. Options are: true, false", upRaw)
		}
		opts.AdminStateUp = &up
	}
	if c.IsSet("shared") {
		sharedRaw := c.String("shared")
		shared, err := strconv.ParseBool(sharedRaw)
		if err != nil {
			return fmt.Errorf("Invalid value for flag `shared`: %s. Options are: true, false", sharedRaw)
		}
		opts.Shared = &shared
	}
	resource.Params = &paramsList{
		opts:     opts,
		allPages: c.Bool("all-pages"),
	}
	return nil
}
Example #4
0
func (command *commandUpdate) HandleFlags(resource *handler.Resource) error {
	c := command.Ctx.CLIContext

	err := command.Ctx.CheckFlagsSet([]string{"name"})
	if err != nil {
		return err
	}

	opts := containers.UpdateOpts{
		ContainerRead:  c.String("container-read"),
		ContainerWrite: c.String("container-write"),
	}
	if c.IsSet("metadata") {
		metadata, err := command.Ctx.CheckKVFlag("metadata")
		if err != nil {
			return err
		}
		opts.Metadata = metadata
	}
	resource.Params = &paramsUpdate{
		container: c.String("name"),
		opts:      opts,
	}
	return nil
}
Example #5
0
File: list.go Project: flazz/rack
func (command *commandList) HandleFlags(resource *handler.Resource) error {
	c := command.Ctx.CLIContext
	opts := &osSubnets.ListOpts{
		Name:      c.String("name"),
		NetworkID: c.String("network-id"),
		IPVersion: c.Int("ip-version"),
		GatewayIP: c.String("gateway-ip"),
		TenantID:  c.String("tenant-id"),
		CIDR:      c.String("cidr"),
		Marker:    c.String("marker"),
		Limit:     c.Int("limit"),
	}
	if c.IsSet("enable-dhcp") {
		dhcpRaw := c.String("enable-dhcp")
		dhcp, err := strconv.ParseBool(dhcpRaw)
		if err != nil {
			return fmt.Errorf("Invalid value for flag `enable-dhcp`: %s. Options are: true, false", dhcpRaw)
		}
		opts.EnableDHCP = &dhcp
	}
	resource.Params = &paramsList{
		opts:     opts,
		allPages: c.Bool("all-pages"),
	}
	return nil
}
Example #6
0
func (command *commandEmpty) HandleFlags(resource *handler.Resource) error {
	resource.Params = &paramsEmpty{
		quiet:       command.Ctx.CLIContext.Bool("quiet"),
		concurrency: command.Ctx.CLIContext.Int("concurrency"),
	}
	return nil
}
Example #7
0
func (command *commandUploadDir) HandleFlags(resource *handler.Resource) error {
	if err := command.Ctx.CheckFlagsSet([]string{"container"}); err != nil {
		return err
	}

	c := command.Ctx.CLIContext

	opts := objects.CreateOpts{
		ContentType: c.String("content-type"),
	}

	conc := c.Int("concurrency")
	if conc <= 0 {
		conc = 100
	}

	resource.Params = &paramsUploadDir{
		container:   c.String("container"),
		dir:         c.String("dir"),
		opts:        opts,
		concurrency: conc,
		quiet:       c.Bool("quiet"),
		recurse:     c.Bool("recurse"),
	}

	return nil
}
Example #8
0
func (command *commandUpload) HandleFlags(resource *handler.Resource) error {
	err := command.Ctx.CheckFlagsSet([]string{"name"})
	if err != nil {
		return err
	}

	opts := &osKeypairs.CreateOpts{
		Name: command.Ctx.CLIContext.String("name"),
	}

	if command.Ctx.CLIContext.IsSet("file") {
		s := command.Ctx.CLIContext.String("file")
		pk, err := ioutil.ReadFile(s)
		if err != nil {
			return err
		}
		opts.PublicKey = string(pk)
	} else if command.Ctx.CLIContext.IsSet("public-key") {
		s := command.Ctx.CLIContext.String("public-key")
		opts.PublicKey = s
	} else {
		return fmt.Errorf("One of 'public-key' and 'file' must be provided.")
	}

	resource.Params = &paramsUpload{
		opts: opts,
	}

	return nil
}
Example #9
0
File: list.go Project: flazz/rack
func (command *commandList) HandleFlags(resource *handler.Resource) error {
	c := command.Ctx.CLIContext

	opts := &osSecurityGroupRules.ListOpts{
		Direction:    c.String("direction"),
		PortRangeMax: c.Int("port-range-max"),
		PortRangeMin: c.Int("port-range-min"),
		Protocol:     c.String("protocol"),
		SecGroupID:   c.String("security-group-id"),
		TenantID:     c.String("tenant-id"),
		Marker:       c.String("marker"),
		Limit:        c.Int("limit"),
	}

	if c.IsSet("ether-type") {
		etherType := c.String("ether-type")
		switch etherType {
		case "ipv4":
			opts.EtherType = osSecurityGroupRules.Ether4
		case "ipv6":
			opts.EtherType = osSecurityGroupRules.Ether6
		default:
			return fmt.Errorf("Invalid value for `ether-type`: %s. Options are: ipv4, ipv6", etherType)
		}
	}

	resource.Params = &paramsList{
		opts:     opts,
		allPages: c.Bool("all-pages"),
	}

	return nil
}
Example #10
0
func (command *commandUpdate) HandleFlags(resource *handler.Resource) error {
	portID, err := command.Ctx.IDOrName(osPorts.IDFromName)
	if err != nil {
		return err
	}

	c := command.Ctx.CLIContext
	opts := &osPorts.UpdateOpts{
		Name:     c.String("rename"),
		DeviceID: c.String("device-id"),
	}

	if c.IsSet("up") {
		upRaw := c.String("up")
		up, err := strconv.ParseBool(upRaw)
		if err != nil {
			return fmt.Errorf("Invalid value for flag `up`: %s. Options are: true, false", upRaw)
		}
		opts.AdminStateUp = &up
	}

	if c.IsSet("security-groups") {
		opts.SecurityGroups = strings.Split(c.String("security-groups"), ",")
	}

	resource.Params = &paramsUpdate{
		portID: portID,
		opts:   opts,
	}

	return nil
}
Example #11
0
func (command *commandDelete) HandleFlags(resource *handler.Resource) error {
	resource.Params = &paramsDelete{
		purge:       command.Ctx.CLIContext.Bool("purge"),
		quiet:       command.Ctx.CLIContext.Bool("quiet"),
		concurrency: command.Ctx.CLIContext.Int("concurrency"),
	}
	return nil
}
Example #12
0
File: delete.go Project: flazz/rack
func (command *commandDelete) HandleFlags(resource *handler.Resource) error {
	err := command.Ctx.CheckFlagsSet([]string{"container"})
	if err != nil {
		return err
	}
	container := command.Ctx.CLIContext.String("container")
	resource.Params = &paramsDelete{
		container: container,
	}
	return nil
}
Example #13
0
func (command *commandGetMetadata) HandleFlags(resource *handler.Resource) error {
	err := command.Ctx.CheckFlagsSet([]string{"name"})
	if err != nil {
		return err
	}

	resource.Params = &paramsGetMetadata{
		containerName: command.Ctx.CLIContext.String("name"),
	}
	return err
}
Example #14
0
File: update.go Project: flazz/rack
func (command *commandUpdate) HandleFlags(resource *handler.Resource) error {
	subnetID, err := command.Ctx.IDOrName(osSubnets.IDFromName)
	if err != nil {
		return err
	}

	c := command.Ctx.CLIContext

	opts := &osSubnets.UpdateOpts{
		Name:      c.String("rename"),
		GatewayIP: c.String("gateway-ip"),
	}

	/*
		if c.IsSet("enable-dhcp") {
			enableDHCPRaw := c.String("enable-dhcp")
			enableDHCP, err := strconv.ParseBool(enableDHCPRaw)
			if err != nil {
				return fmt.Errorf("Invalid value for flag `shared`: %s. Options are: true, false", enableDHCPRaw)
			}
			opts.EnableDHCP = &enableDHCP
		}
	*/

	if c.IsSet("dns-nameservers") {
		opts.DNSNameservers = strings.Split(c.String("dns-nameservers"), ",")
	}

	/*
		if c.IsSet("host-route") {
			hostRoutesRaw := c.StringSlice("host-route")
			hostRoutesRawSlice, err := command.Ctx.CheckStructFlag(hostRoutesRaw)
			if err != nil {
				return err
			}
			hostRoutes := make([]osSubnets.HostRoute, len(hostRoutesRawSlice))
			for i, hostRouteMap := range hostRoutesRawSlice {
				hostRoutes[i] = osSubnets.HostRoute{
					DestinationCIDR: hostRouteMap["dest"].(string),
					NextHop:         hostRouteMap["next"].(string),
				}
			}
			opts.HostRoutes = hostRoutes
		}
	*/

	resource.Params = &paramsUpdate{
		opts:     opts,
		subnetID: subnetID,
	}

	return nil
}
Example #15
0
func (command *commandDeleteMetadata) HandleFlags(resource *handler.Resource) error {
	err := command.Ctx.CheckFlagsSet([]string{"metadata"})
	if err != nil {
		return err
	}

	serverID, err := command.Ctx.IDOrName(osServers.IDFromName)
	resource.Params = &paramsDeleteMetadata{
		serverID:     serverID,
		metadataKeys: strings.Split(command.Ctx.CLIContext.String("metadata"), ","),
	}
	return err
}
Example #16
0
func (command *commandDownload) HandleFlags(resource *handler.Resource) error {
	err := command.Ctx.CheckFlagsSet([]string{"container", "name"})
	if err != nil {
		return err
	}
	container := command.Ctx.CLIContext.String("container")
	object := command.Ctx.CLIContext.String("name")
	resource.Params = &paramsDownload{
		container: container,
		object:    object,
	}
	return nil
}
Example #17
0
func (command *commandUpdateMetadata) HandleFlags(resource *handler.Resource) error {
	metadata, err := command.Ctx.CheckKVFlag("metadata")
	if err != nil {
		return err
	}
	opts := osServers.MetadataOpts(metadata)

	serverID, err := command.Ctx.IDOrName(osServers.IDFromName)
	resource.Params = &paramsUpdateMetadata{
		serverID: serverID,
		opts:     &opts,
	}
	return err
}
Example #18
0
func (command *commandList) HandleFlags(resource *handler.Resource) error {
	c := command.Ctx.CLIContext

	opts := &osVolumes.ListOpts{
		Name:   c.String("name"),
		Status: c.String("status"),
	}

	resource.Params = &paramsList{
		opts: opts,
	}

	return nil
}
Example #19
0
File: list.go Project: hdansou/rack
func (command *commandList) HandleFlags(resource *handler.Resource) error {
	c := command.Ctx.CLIContext
	opts := &osImages.ListOpts{
		Name:   c.String("name"),
		Status: c.String("status"),
		Marker: c.String("marker"),
		Limit:  c.Int("limit"),
	}
	resource.Params = &paramsList{
		opts:     opts,
		allPages: c.Bool("all-pages"),
	}
	return nil
}
Example #20
0
File: resize.go Project: flazz/rack
func (command *commandResize) HandleFlags(resource *handler.Resource) error {
	err := command.Ctx.CheckFlagsSet([]string{"flavor-id"})
	if err != nil {
		return err
	}
	flavorID := command.Ctx.CLIContext.String("flavor-id")
	opts := &osServers.ResizeOpts{
		FlavorRef: flavorID,
	}
	resource.Params = &paramsResize{
		opts: opts,
	}
	return nil
}
Example #21
0
File: list.go Project: hdansou/rack
func (command *commandList) HandleFlags(resource *handler.Resource) error {
	c := command.Ctx.CLIContext
	opts := &flavors.ListOpts{
		MinDisk: c.Int("min-disk"),
		MinRAM:  c.Int("min-ram"),
		Marker:  c.String("marker"),
		Limit:   c.Int("limit"),
	}
	resource.Params = &paramsList{
		opts:     opts,
		allPages: c.Bool("all-pages"),
	}
	return nil
}
Example #22
0
func (command *commandReboot) HandleFlags(resource *handler.Resource) error {
	c := command.Context().CLIContext
	var how osServers.RebootMethod
	if c.IsSet("soft") {
		how = osServers.OSReboot
	}
	if c.IsSet("hard") {
		how = osServers.PowerCycle
	}
	if how == "" {
		return output.ErrMissingFlag{Msg: "One of either --soft or --hard must be provided."}
	}
	resource.Params = &paramsReboot{how: how}
	return nil
}
Example #23
0
File: list.go Project: hdansou/rack
func (command *commandList) HandleFlags(resource *handler.Resource) error {
	c := command.Ctx.CLIContext
	opts := &osContainers.ListOpts{
		Full:      c.Bool("full"),
		Prefix:    c.String("prefix"),
		EndMarker: c.String("end-marker"),
		Marker:    c.String("marker"),
		Limit:     c.Int("limit"),
	}

	resource.Params = &paramsList{
		opts:     opts,
		allPages: c.Bool("all-pages"),
	}
	return nil
}
Example #24
0
func (command *commandDeleteMetadata) HandleFlags(resource *handler.Resource) error {
	err := command.Ctx.CheckFlagsSet([]string{"name", "metadata-keys"})
	if err != nil {
		return err
	}
	metadataKeys := strings.Split(command.Ctx.CLIContext.String("metadata-keys"), ",")
	for i, k := range metadataKeys {
		metadataKeys[i] = strings.Title(k)
	}

	resource.Params = &paramsDeleteMetadata{
		containerName: command.Ctx.CLIContext.String("name"),
		metadataKeys:  metadataKeys,
	}
	return nil
}
Example #25
0
func (command *commandCreate) HandleFlags(resource *handler.Resource) error {
	serverID, err := serverIDorName(command.Ctx)
	if err != nil {
		return err
	}

	c := command.Ctx.CLIContext
	opts := &osVolumeAttach.CreateOpts{
		Device: c.String("device"),
	}

	resource.Params = &paramsCreate{
		opts:     opts,
		serverID: serverID,
	}
	return nil
}
Example #26
0
func (command *commandDelete) HandleFlags(resource *handler.Resource) error {
	serverID, err := serverIDorName(command.Ctx)
	if err != nil {
		return err
	}

	err = command.Ctx.CheckFlagsSet([]string{"id"})
	if err != nil {
		return err
	}

	resource.Params = &paramsDelete{
		attachmentID: command.Ctx.CLIContext.String("id"),
		serverID:     serverID,
	}
	return nil
}
Example #27
0
func (command *commandUpdateMetadata) HandleFlags(resource *handler.Resource) error {
	err := command.Ctx.CheckFlagsSet([]string{"name", "metadata"})
	if err != nil {
		return err
	}

	metadata, err := command.Ctx.CheckKVFlag("metadata")
	if err != nil {
		return err
	}

	resource.Params = &paramsUpdateMetadata{
		containerName: command.Ctx.CLIContext.String("name"),
		metadata:      metadata,
	}
	return err
}
Example #28
0
File: list.go Project: hdansou/rack
func (command *commandList) HandleFlags(resource *handler.Resource) error {
	c := command.Ctx.CLIContext

	opts := &osSecurityGroups.ListOpts{
		Name:     c.String("name"),
		TenantID: c.String("tenant-id"),
		Marker:   c.String("marker"),
		Limit:    c.Int("limit"),
	}

	resource.Params = &paramsList{
		opts:     opts,
		allPages: c.Bool("all-pages"),
	}

	return nil
}
Example #29
0
func (command *commandCreate) HandleFlags(resource *handler.Resource) error {
	err := command.Ctx.CheckFlagsSet([]string{"name"})
	if err != nil {
		return err
	}

	c := command.Ctx.CLIContext
	opts := &osSecurityGroups.CreateOpts{
		Name:        c.String("name"),
		Description: c.String("description"),
	}

	resource.Params = &paramsCreate{
		opts: opts,
	}

	return nil
}
Example #30
0
File: create.go Project: flazz/rack
func (command *commandCreate) HandleFlags(resource *handler.Resource) error {
	c := command.Ctx.CLIContext
	opts := &osNetworks.CreateOpts{
		TenantID: c.String("tenant-id"),
	}
	if c.IsSet("up") {
		up := true
		opts.AdminStateUp = &up
	}
	if c.IsSet("shared") {
		shared := true
		opts.Shared = &shared
	}
	resource.Params = &paramsCreate{
		opts: opts,
	}
	return nil
}