示例#1
0
文件: upload.go 项目: nelsnelson/rack
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")
	}

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

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

	return nil
}
示例#2
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
}
示例#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
}
示例#4
0
func (command *commandListEvents) HandleFlags(resource *handler.Resource) error {
	if err := command.Ctx.CheckFlagsSet([]string{"name"}); err != nil {
		return err
	}

	c := command.Ctx.CLIContext
	name := c.String("stack-name")
	id := c.String("stack-id")
	name, id, err := stackcommands.IDAndName(command.Ctx.ServiceClient, name, id)
	if err != nil {
		return err
	}
	opts := &osStackEvents.ListResourceEventsOpts{
		ResourceActions:  strings.Split(c.String("resource-actions"), ","),
		ResourceStatuses: strings.Split(c.String("resource-statuses"), ","),
		ResourceTypes:    strings.Split(c.String("resource-types"), ","),
		SortKey:          osStackEvents.SortKey(c.String("sort-key")),
		SortDir:          osStackEvents.SortDir(c.String("sort-dir")),
	}

	resource.Params = &paramsListEvents{
		opts:         opts,
		stackName:    name,
		stackID:      id,
		resourceName: c.String("name"),
	}
	return nil
}
示例#5
0
func (command *commandUploadDir) HandleFlags(resource *handler.Resource) error {
	if err := command.Ctx.CheckFlagsSet([]string{"container"}); err != nil {
		return err
	}

	c := command.Ctx.CLIContext
	containerName := c.String("container")
	if err := CheckContainerExists(command.Ctx.ServiceClient, containerName); err != nil {
		return err
	}

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

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

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

	return nil
}
示例#6
0
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
}
示例#7
0
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
}
示例#8
0
func (command *commandCreate) HandleFlags(resource *handler.Resource) error {
	c := command.Ctx.CLIContext

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

	opts := &osServers.CreateImageOpts{
		Name: c.String("name"),
	}

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

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

	if c.IsSet("server-id") {
		resource.Params.(*paramsCreate).serverID = c.String("server-id")
		return nil
	}

	serverID, err := osServers.IDFromName(command.Ctx.ServiceClient, c.String("server-name"))
	resource.Params.(*paramsCreate).serverID = serverID

	return err
}
示例#9
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
}
示例#10
0
func (command *commandValidate) HandleFlags(resource *handler.Resource) error {
	c := command.Ctx.CLIContext
	opts := osStackTemplates.ValidateOpts{}

	// check if either template url or template file is set
	if c.IsSet("template-file") {
		abs, err := filepath.Abs(c.String("template-file"))
		if err != nil {
			return err
		}
		template, err := ioutil.ReadFile(abs)
		if err != nil {
			return err
		}
		opts.Template = string(template)
	} else if c.IsSet("template-url") {
		opts.TemplateURL = c.String("template-url")
	} else {
		return errors.New("Neither template-file nor template-url specified")
	}

	resource.Params = &paramsValidate{
		opts: &opts,
	}
	return nil
}
示例#11
0
func (command *commandGetMetadata) HandleFlags(resource *handler.Resource) error {
	serverID, err := command.Ctx.IDOrName(osServers.IDFromName)
	resource.Params = &paramsGetMetadata{
		serverID: serverID,
	}
	return err
}
示例#12
0
func (command *commandListEvents) HandleFlags(resource *handler.Resource) error {
	c := command.Ctx.CLIContext

	stringResourceActions := strings.Split(c.String("resource-actions"), ",")
	resourceActions := make([]osStackEvents.ResourceAction, len(stringResourceActions))
	for i, resourceAction := range stringResourceActions {
		resourceActions[i] = osStackEvents.ResourceAction(resourceAction)
	}

	stringResourceStatuses := strings.Split(c.String("resource-statuses"), ",")
	resourceStatuses := make([]osStackEvents.ResourceStatus, len(stringResourceStatuses))
	for i, resourceStatus := range stringResourceStatuses {
		resourceStatuses[i] = osStackEvents.ResourceStatus(resourceStatus)
	}

	opts := &osStackEvents.ListOpts{
		ResourceActions:  resourceActions,
		ResourceStatuses: resourceStatuses,
		ResourceNames:    strings.Split(c.String("resource-names"), ","),
		ResourceTypes:    strings.Split(c.String("resource-types"), ","),
		SortKey:          osStackEvents.SortKey(c.String("sort-key")),
		SortDir:          osStackEvents.SortDir(c.String("sort-dir")),
	}
	resource.Params = &paramsListEvents{
		opts: opts,
	}
	return nil
}
示例#13
0
func (command *commandCreate) HandleFlags(resource *handler.Resource) error {
	err := command.Ctx.CheckFlagsSet([]string{"size"})
	if err != nil {
		return err
	}

	c := command.Ctx.CLIContext

	wait := false
	if c.IsSet("wait-for-completion") {
		wait = true
	}

	opts := &osVolumes.CreateOpts{
		Size:        c.Int("size"),
		Name:        c.String("name"),
		Description: c.String("description"),
		VolumeType:  c.String("volume-type"),
	}

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

	return nil
}
示例#14
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
}
示例#15
0
func (command *commandUpload) HandleFlags(resource *handler.Resource) error {
	err := command.Ctx.CheckFlagsSet([]string{"container"})
	if err != nil {
		return err
	}

	c := command.Ctx.CLIContext
	containerName := c.String("container")

	if err := CheckContainerExists(command.Ctx.ServiceClient, containerName); err != nil {
		return err
	}

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

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

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

	return nil
}
示例#16
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
}
示例#17
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
}
示例#18
0
func (command *commandList) HandleFlags(resource *handler.Resource) error {
	c := command.Ctx.CLIContext

	opts := &osStackResources.ListOpts{
		Depth: c.Int("depth"),
	}
	resource.Params = &paramsList{
		opts: opts,
	}
	return nil
}
示例#19
0
文件: get.go 项目: reaperzn/rack
func (command *commandGet) HandlePipe(resource *handler.Resource, item string) error {
	name, id, err := stackcommands.IDAndName(command.Ctx.ServiceClient, item, "")
	if err != nil {
		return err
	}
	resource.Params = &paramsGet{
		stackName: name,
		stackID:   id,
	}
	return nil
}
示例#20
0
func (command *commandDelete) HandleFlags(resource *handler.Resource) error {
	wait := false
	if command.Ctx.CLIContext.IsSet("wait-for-completion") {
		wait = true
	}

	resource.Params = &paramsDelete{
		wait: wait,
	}
	return nil
}
示例#21
0
文件: delete.go 项目: nelsnelson/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
}
示例#22
0
func (command *commandGetTemplate) HandleSingle(resource *handler.Resource) error {
	err := command.Ctx.CheckFlagsSet([]string{"type"})
	if err != nil {
		return err
	}

	resource.Params = &paramsGetTemplate{
		resourceType: command.Ctx.CLIContext.String("type"),
	}
	return nil
}
示例#23
0
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
}
示例#24
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 := &osStacks.CreateOpts{
		Name:         c.String("name"),
		TemplateOpts: new(osStacks.Template),
	}

	if c.IsSet("disable-rollback") {
		disableRollback := c.BoolT("disable-rollback")
		opts.DisableRollback = &disableRollback
	}

	// check if either template url or template file is set
	if c.IsSet("template-file") {
		opts.TemplateOpts.URL = c.String("template-file")
	} else if c.IsSet("template-url") {
		opts.TemplateOpts.URL = c.String("template-url")
	} else {
		return errors.New("Neither template-file nor template-url specified")
	}

	if c.IsSet("environment-file") {
		opts.EnvironmentOpts = new(osStacks.Environment)
		opts.EnvironmentOpts.URL = c.String("environment-file")
	}

	if c.IsSet("timeout") {
		opts.Timeout = c.Int("timeout")
	}

	if c.IsSet("parameters") {
		parameters, err := command.Ctx.CheckKVFlag("parameters")
		if err != nil {
			return err
		}
		opts.Parameters = parameters
	}

	if c.IsSet("tags") {
		opts.Tags = strings.Split(c.String("tags"), ",")
	}

	resource.Params = &paramsCreate{
		opts: opts,
	}
	return nil
}
示例#25
0
func (command *commandDeleteMetadata) HandleFlags(resource *handler.Resource) error {
	err := command.Ctx.CheckFlagsSet([]string{"metadata-keys"})
	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-keys"), ","),
	}
	return err
}
示例#26
0
文件: get.go 项目: nelsnelson/rack
func (command *commandGet) 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 = &paramsGet{
		container: container,
		object:    object,
	}
	return nil
}
示例#27
0
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
}
示例#28
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
}
示例#29
0
func (command *commandGet) HandleSingle(resource *handler.Resource) error {
	c := command.Ctx.CLIContext
	name := c.String("name")
	id := c.String("id")
	name, id, err := IDAndName(command.Ctx.ServiceClient, name, id)
	if err != nil {
		return err
	}
	resource.Params = &paramsGet{
		stackName: name,
		stackID:   id,
	}
	return nil
}
示例#30
0
文件: resize.go 项目: nelsnelson/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
}