commands

package
v19.10.0+incompatible Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 12, 2019 License: Apache-2.0 Imports: 12 Imported by: 2

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ClusterAddFeatureCommand = cli.Command{
	Name:        "add-feature",
	Usage:       "add-feature CLUSTERNAME FEATURENAME",
	Description: "Adds a feature on the cluster",
	Category:    "Features",

	Flags: []cli.Flag{
		cli.BoolFlag{
			Name: "skip-proxy",
		},
		cli.StringSliceFlag{
			Name: "param, p",
		},
	},

	Action: func(c *cli.Context) error {
		err := extractClusterArgument(c)
		if err != nil {
			return err
		}
		err = extractFeatureArgument(c)
		if err != nil {
			return err
		}
		return cli.NewExitError("Not yet implemented", int(ExitCode.NotImplemented))
	},
}

ClusterAddFeatureCommand ...

View Source
var ClusterCallCommand = cli.Command{
	Name:  "call",
	Usage: "call [options] CLUSTERNAME COMMAND [PARAM ...]",
	Description: `
Calls a COMMAND on the designated target of the cluster CLUSTERNAME.
By default, the target is any available master (--any-master).

Note:
Everything after COMMAND will be considered a parameter of the COMMAND.
`,
	Category: "Cluster",

	Flags: []cli.Flag{
		cli.BoolFlag{
			Name: "any-master, m",
		},
		cli.BoolFlag{
			Name: "all-masters, a",
		},
		cli.StringFlag{
			Name: "master",
		},
	},

	Action: func(c *cli.Context) error {
		err := extractClusterArgument(c)
		if err != nil {
			return err
		}

		anyMaster := c.Bool("any-master")
		allMasters := c.Bool("all-masters")
		master := c.String("master")
		target := ""
		if allMasters {
			target = "-a"
		} else if master != "" {
			target = "--master " + master
		}
		if anyMaster || target == "" {
			target = "-m"
		}

		args := c.Args()
		tail := args.Tail()
		command := args.Get(1)

		cmdStr := fmt.Sprintf("safescale cluster call %s %s %s %s", target, clusterName, command, strings.Join(tail[1:], " "))
		cmdStr = RebrandCommand(cmdStr)
		log.Debugf("Calling '%s'", cmdStr)
		return runCommand(cmdStr)
	},
}

ClusterCallCommand handles 'perform dcos CLUSTERNAME'

View Source
var ClusterCreateCommand = cli.Command{
	Name:      "create",
	Aliases:   []string{"new"},
	Usage:     "Creates a cluster",
	ArgsUsage: "CLUSTERNAME",
	Category:  "Cluster",

	Flags: []cli.Flag{
		cli.StringFlag{
			Name:  "complexity, C",
			Usage: "Defines the sizing of the cluster: Small, Normal, Large (default: Normal)",
		},
		cli.StringFlag{
			Name:  "flavor, F",
			Usage: "Defines the type of the cluster; can be BOH, SWARM, OHPC, DCOS, K8S (default: K8S)",
		},
		cli.BoolFlag{
			Name:  "keep-on-failure, k",
			Usage: "If used, the resources are not deleted on failure (default: not set)",
		},
		cli.StringFlag{
			Name:  "cidr, N",
			Usage: "Defines the CIDR of the network to use with cluster (default: 192.168.0.0/16)",
		},
		cli.StringSliceFlag{
			Name:  "disable",
			Usage: "Allows to disable addition of default features",
		},
		cli.StringFlag{
			Name:  "os",
			Usage: "Defines the operating system to use",
		},
		cli.UintFlag{
			Name:  "cpu",
			Usage: "Defines the number of cpu of masters and nodes in the cluster",
		},
		cli.Float64Flag{
			Name:  "ram",
			Usage: "Defines the size of RAM of masters and nodes in the cluster (in GB)",
		},
		cli.UintFlag{
			Name:  "disk",
			Usage: "Defines the size of system disk of masters and nodes (in GB)",
		},
	},

	Action: func(c *cli.Context) error {
		err := extractClusterArgument(c)
		if err != nil {
			return err
		}

		complexityStr := c.String("complexity")
		if complexityStr == "" {
			complexityStr = "Normal"
		}
		cidr := c.String("cidr")
		keep := c.Bool("keep-on-failure")
		cpu := c.Uint("cpu")
		ram := c.Float64("ram")
		disk := c.Uint("disk")

		cmdStr := fmt.Sprintf("safescale cluster create %s -F DCOS -C %s -N %s --cpu %d --ram %f --disk %d",
			clusterName, complexityStr, cidr, cpu, ram, disk)
		if keep {
			cmdStr += " -k"
		}
		cmdStr = RebrandCommand(cmdStr)
		err = runCommand(cmdStr)
		if err != nil {
			return err
		}

		cmdStr = fmt.Sprintf("safescale cluster add-feature %s sparkmaster", clusterName)
		err = runCommand(cmdStr)
		if err != nil {
			return err
		}

		return nil
	},
}

ClusterCreateCommand handles 'perform <clustername> create"

View Source
var ClusterDeleteCommand = cli.Command{
	Name:      "delete",
	Aliases:   []string{"destroy", "remove", "rm"},
	ArgsUsage: "CLUSTERNAME",
	Category:  "Cluster",

	Flags: []cli.Flag{
		cli.BoolFlag{
			Name: "assume-yes, yes, y",
		},
		cli.BoolFlag{
			Name: "force, f",
		},
	},

	Action: func(c *cli.Context) error {
		err := extractClusterArgument(c)
		if err != nil {
			return err
		}

		yes := c.Bool("assume-yes")

		cmdStr := fmt.Sprintf("safescale cluster rm %s", clusterName)
		if yes {
			cmdStr += " -y"
		}
		cmdStr = RebrandCommand(cmdStr)
		return runCommand(cmdStr)
	},
}

ClusterDeleteCommand handles 'perform <clustername> delete'

View Source
var ClusterDeleteFeatureCommand = cli.Command{
	Name:     "delete-feature",
	Aliases:  []string{"rm-feature", "uninstall-feature", "remove-feature"},
	Usage:    "Deletes a feature from the cluster",
	Category: "Features",

	Action: func(c *cli.Context) error {
		err := extractClusterArgument(c)
		if err != nil {
			return err
		}
		err = extractFeatureArgument(c)
		if err != nil {
			return err
		}
		return cli.NewExitError("Not yet implemented", int(ExitCode.NotImplemented))
	},
}

ClusterDeleteFeatureCommand ...

View Source
var ClusterDeleteNodeCommand = cli.Command{
	Name:     "delete-node",
	Aliases:  []string{"destroy-node", "remove-node", "rm-node"},
	Usage:    "Deletes a node of the cluster",
	Category: "Node",

	Action: func(c *cli.Context) error {
		yes := c.Bool("assume-yes")
		force := c.Bool("force")
		cmdStr := fmt.Sprintf("safescale cluster delete-node %s %s", clusterName, nodeName)
		if yes {
			cmdStr += " -y"
		}
		if force {
			cmdStr += " -f"
		}
		cmdStr = RebrandCommand(cmdStr)
		log.Debugf("Calling '%s'", cmdStr)
		return runCommand(cmdStr)
	},
}

ClusterDeleteNodeCommand ...

View Source
var ClusterDisableFeatureCommand = cli.Command{
	Name:        "disable-feature",
	Usage:       "disable-feature FEATURENAME",
	Description: "Disables a feature (if the feature behaves like a service)",
	Category:    "Features",

	Action: func(c *cli.Context) error {
		featureName := c.Args().Get(1)

		if featureName == "" {
			msg := "Invalid empty argument FEATURENAME"
			return cli.NewExitError(msg, int(ExitCode.InvalidArgument))
		}
		return cli.NewExitError("Not yet implemented", int(ExitCode.NotImplemented))
	},
}

ClusterDisableFeatureCommand ...

View Source
var ClusterEnableFeatureCommand = cli.Command{
	Name:     "enable-feature",
	Usage:    "Enables a feature (if the feature behaves like a service)",
	Category: "Features",

	Action: func(c *cli.Context) error {
		err := extractFeatureArgument(c)
		if err != nil {
			return err
		}
		return cli.NewExitError("Not yet implemented", int(ExitCode.NotImplemented))
	},
}

ClusterEnableFeatureCommand ...

View Source
var ClusterExpandCommand = cli.Command{
	Name:     "expand",
	Category: "Cluster",

	Flags: []cli.Flag{
		cli.UintFlag{
			Name:  "count, n",
			Usage: "Define the number of nodes wanted (default: 1)",
			Value: 1,
		},
		cli.BoolFlag{
			Name:  "public, p",
			Usage: "If used, the node(s) will have public IP address (default: no)",
		},
		cli.StringFlag{
			Name:  "os",
			Usage: "Define the Operating System wanted",
		},
		cli.UintFlag{
			Name:  "cpu",
			Usage: "Define the number of cpu for new node(s); default: number used at cluster creation",
			Value: 0,
		},
		cli.Float64Flag{
			Name:  "ram",
			Usage: "Define the size of RAM for new node(s) (in GB); default: size used at cluster creation",
			Value: 0.0,
		},
		cli.UintFlag{
			Name:  "disk",
			Usage: "Define the size of system disk for new node(s) (in GB); default: size used at cluster creation",
			Value: 0,
		},
		cli.BoolFlag{
			Name:   "gpu",
			Usage:  "Ask for gpu capable host; default: no",
			Hidden: true,
		},
	},

	Action: func(c *cli.Context) error {
		err := extractClusterArgument(c)
		if err != nil {
			return err
		}

		count := c.Uint("count")
		if count == 0 {
			count = 1
		}
		public := c.Bool("public")
		gpu := c.Bool("gpu")
		los := c.String("os")
		cpu := c.Uint("cpu")
		ram := c.Float64("ram")
		disk := c.Uint("disk")

		cmdStr := fmt.Sprintf("safescale cluster expand %s -n %d", clusterName, count)
		if public {
			cmdStr += " -p"
		}
		if gpu {
			cmdStr += " --gpu"
		}
		if los != "" {
			cmdStr += " --os " + los
		}
		if cpu > 0 {
			cmdStr += fmt.Sprintf(" --cpu %d", cpu)
		}
		if ram > 0.0 {
			cmdStr += fmt.Sprintf(" --ram %f ", ram)
		}
		if disk > 0 {
			cmdStr += fmt.Sprintf(" --disk %d", disk)
		}
		cmdStr = RebrandCommand(cmdStr)
		return runCommand(cmdStr)
	},
}

ClusterExpandCommand handles 'perform <clustername> expand'

View Source
var ClusterInspectCommand = cli.Command{
	Name:     "inspect",
	Aliases:  []string{"show", "get"},
	Category: "Cluster",

	Action: func(c *cli.Context) error {
		err := extractClusterArgument(c)
		if err != nil {
			return err
		}
		cmdStr := RebrandCommand(fmt.Sprintf("safescale cluster inspect %s", clusterName))
		return runCommand(cmdStr)
	},
}

ClusterInspectCommand handles 'perform <clustername inspect'

View Source
var ClusterInspectNodeCommand = cli.Command{
	Name:     "inspect-node",
	Aliases:  []string{"show-node", "get-node"},
	Usage:    "Inspects a node of the cluster",
	Category: "Node",

	Action: func(c *cli.Context) error {
		err := extractClusterArgument(c)
		if err != nil {
			return err
		}
		err = extractNodeArgument(c)
		if err != nil {
			return err
		}

		cmdStr := RebrandCommand(fmt.Sprintf("safescale cluster inspect-node %s %s", clusterName, nodeName))
		log.Debugf("Calling '%s'", cmdStr)
		return runCommand(cmdStr)
	},
}

ClusterInspectNodeCommand ...

View Source
var ClusterListCommand = cli.Command{
	Name:     "list",
	Aliases:  []string{"ls"},
	Category: "Cluster",

	Action: func(c *cli.Context) error {
		cmdStr := RebrandCommand(fmt.Sprintf("safescale cluster list"))
		log.Debugf("Calling '%s'", cmdStr)
		return runCommand(cmdStr)
	},
}

ClusterListCommand handles 'perform list'

View Source
var ClusterListNodesCommand = cli.Command{
	Name:     "list-node",
	Aliases:  []string{"ls-node", "list-nodes", "ls-nodes"},
	Usage:    "List nodes in the cluster",
	Category: "Node",

	Flags: []cli.Flag{
		cli.BoolFlag{
			Name:  "public, p",
			Usage: "If set, list only public nodes",
		},
		cli.BoolFlag{
			Name:  "all, a",
			Usage: "If set, list all type of nodes (overcomes --public)",
		},
	},

	Action: func(c *cli.Context) error {
		err := extractClusterArgument(c)
		if err != nil {
			return err
		}
		err = extractNodeArgument(c)
		if err != nil {
			return err
		}

		public := c.Bool("public")
		all := c.Bool("all")

		cmdStr := fmt.Sprintf("safescale cluster ls-nodes %s", clusterName)
		if all {
			cmdStr += " -a"
		} else if public {
			cmdStr += " -p"
		}
		cmdStr = RebrandCommand(cmdStr)
		log.Debugf("Calling '%s'", cmdStr)
		return runCommand(cmdStr)
	},
}

ClusterListNodesCommand ...

View Source
var ClusterProbeFeatureCommand = cli.Command{
	Name:        "probe-feature",
	Aliases:     []string{"check-feature"},
	Usage:       "probe-feature CLUSTERNAME FEATURENAME",
	Description: "Determines if feature is installed on cluster.",
	Category:    "Features",

	Action: func(c *cli.Context) error {
		err := extractClusterArgument(c)
		if err != nil {
			return err
		}
		err = extractFeatureArgument(c)
		if err != nil {
			return err
		}
		return cli.NewExitError("Not yet implemented", int(ExitCode.NotImplemented))
	},
}

ClusterProbeFeatureCommand ...

View Source
var ClusterProbeNodeCommand = cli.Command{
	Name:      "probe-node",
	Usage:     "Determines the state of a node of the cluster",
	ArgsUsage: "CLUSTERNAME NODENAME",
	Category:  "Node",

	Action: func(c *cli.Context) error {
		err := extractClusterArgument(c)
		if err != nil {
			return err
		}
		err = extractNodeArgument(c)
		if err != nil {
			return err
		}

		cmdStr := RebrandCommand(fmt.Sprintf("safescale cluster probe-node %s %s", clusterName, nodeName))
		log.Debugf("Calling '%s'", cmdStr)
		return runCommand(cmdStr)
	},
}

ClusterProbeNodeCommand ...

View Source
var ClusterShrinkCommand = cli.Command{
	Name:        "shrink",
	Usage:       "shrink CLUSTERNAME",
	Description: "Removes node(s) from the cluster (starting from the last added)",
	Category:    "Cluster",

	Flags: []cli.Flag{
		cli.UintFlag{
			Name:  "count, n",
			Usage: "Define the number of nodes wanted (default: 1)",
			Value: 1,
		},
		cli.BoolFlag{
			Name:  "public, p",
			Usage: "If used, the node(s) will have public IP address (default: no)",
		},
	},

	Action: func(c *cli.Context) error {
		err := extractClusterArgument(c)
		if err != nil {
			return err
		}

		count := c.Uint("count")
		if count == 0 {
			count = 1
		}
		public := c.Bool("public")

		cmdStr := fmt.Sprintf("safescale cluster shrink %s -n %d", clusterName, count)
		if public {
			cmdStr += " -p"
		}
		cmdStr = RebrandCommand(cmdStr)
		return runCommand(cmdStr)
	},
}

ClusterShrinkCommand handles 'perform <clustername> shrink'

View Source
var ClusterStartCommand = cli.Command{
	Name:     "start",
	Aliases:  []string{"unfreeze", "boot"},
	Category: "Cluster",

	Action: func(c *cli.Context) error {
		err := extractClusterArgument(c)
		if err != nil {
			return err
		}

		cmdStr := RebrandCommand(fmt.Sprintf("safescale cluster start %s", clusterName))
		return runCommand(cmdStr)
	},
}

ClusterStartCommand handles 'perform <clustername> start'

View Source
var ClusterStartFeatureCommand = cli.Command{
	Name:     "start-feature",
	Usage:    "Starts a stopped feature (if the feature behaves like service)",
	Category: "Features",

	Action: func(c *cli.Context) error {
		err := extractFeatureArgument(c)
		if err != nil {
			return err
		}
		return cli.NewExitError("Not yet implemented", int(ExitCode.NotImplemented))
	},
}

ClusterStartFeatureCommand ...

View Source
var ClusterStartNodeCommand = cli.Command{
	Name:      "start-node",
	Aliases:   []string{"unfreeze-node"},
	Usage:     "Stars a node of the cluster",
	ArgsUsage: "CLUSTERNAME NODENAME",
	Category:  "Node",

	Action: func(c *cli.Context) error {
		err := extractClusterArgument(c)
		if err != nil {
			return err
		}
		err = extractNodeArgument(c)
		if err != nil {
			return err
		}

		cmdStr := RebrandCommand(fmt.Sprintf("safescale cluster start-node %s %s", clusterName, nodeName))
		log.Debugf("Calling '%s'", cmdStr)
		return runCommand(cmdStr)
	},
}

ClusterStartNodeCommand ...

View Source
var ClusterStateCommand = cli.Command{
	Name:     "state",
	Category: "Cluster",

	Action: func(c *cli.Context) error {
		err := extractClusterArgument(c)
		if err != nil {
			return err
		}

		cmdStr := RebrandCommand(fmt.Sprintf("safescale cluster state %s", clusterName))
		return runCommand(cmdStr)
	},
}

ClusterStateCommand handles 'perform state CLUSTERNAME'

View Source
var ClusterStateFeatureCommand = cli.Command{
	Name:     "state-feature",
	Aliases:  []string{"status-feature"},
	Usage:    "Determines the state of the feature (if the feature behaves like service)",
	Category: "Features",

	Action: func(c *cli.Context) error {
		err := extractClusterArgument(c)
		if err != nil {
			return err
		}
		err = extractFeatureArgument(c)
		if err != nil {
			return err
		}
		return cli.NewExitError("Not yet implemented", int(ExitCode.NotImplemented))
	},
}

ClusterStateFeatureCommand ...

View Source
var ClusterStopCommand = cli.Command{
	Name:     "stop",
	Aliases:  []string{"freeze"},
	Category: "Cluster",

	Action: func(c *cli.Context) error {
		err := extractClusterArgument(c)
		if err != nil {
			return err
		}

		cmdStr := RebrandCommand(fmt.Sprintf("safescale cluster stop %s", clusterName))
		return runCommand(cmdStr)
	},
}

ClusterStopCommand handles 'perform <clustername> stop'

View Source
var ClusterStopFeatureCommand = cli.Command{
	Name:     "stop-feature",
	Usage:    "Stops a started feature (if the feature behaves like a service)",
	Category: "Features",

	Action: func(c *cli.Context) error {
		err := extractFeatureArgument(c)
		if err != nil {
			return err
		}
		return cli.NewExitError("Not yet implemented", int(ExitCode.NotImplemented))
	},
}

ClusterStopFeatureCommand ...

View Source
var ClusterStopNodeCommand = cli.Command{
	Name:      "stop-node",
	Aliases:   []string{"freeze-node"},
	Usage:     "Stops a node of the cluster",
	ArgsUsage: "CLUSTERNAME NODENAME",
	Category:  "Node",

	Action: func(c *cli.Context) error {
		err := extractClusterArgument(c)
		if err != nil {
			return err
		}
		err = extractNodeArgument(c)
		if err != nil {
			return err
		}

		cmdStr := RebrandCommand(fmt.Sprintf("safescale cluster stop-node %s %s", clusterName, nodeName))
		log.Debugf("Calling '%s'", cmdStr)
		return runCommand(cmdStr)
	},
}

ClusterStopNodeCommand ...

View Source
var (

	// RebrandingPrefix is used to store the optional prefix to use when calling external SafeScale commands
	RebrandingPrefix string
)

Functions

func RebrandCommand

func RebrandCommand(command string) string

RebrandCommand allows to prefix a command with cmds.RebrandingPrefix ie: with cmds.RebrandingPrefix == "safe "

"safescale ..." becomes "safe deploy ..."
with cmds.RebrandingPrefix == "my"
"perform ..." becomes "myperform ..."

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL