ref: 79803b98b551ad1d924594263038bc901f684233 cisco/csc/cmd/instance/launch.go -rw-r--r-- 768 bytes View raw
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
package instance

import (
	"cisco/csc/cmd"
	"cisco/sdk"
	"fmt"
	"github.com/spf13/cobra"
)

var instanceLaunch = &cobra.Command{
	Use:   "launch",
	Short: "Create a launch instance",
	Args:  cobra.ExactArgs(3),
	Run: func(cmd *cobra.Command, args []string) {
		name := args[0]
		os := args[1]
		model := args[2]
		size, _ := cmd.Flags().GetUint("size")

		err := cisco.NewInstance(cisco.InstanceNew{
			Name: name,
			OS:   os,
			Type: model,
			Size: size,
		})

		if err != nil {
			fmt.Printf("Error: %s\n", err.Error())
		}

		err = cisco.StartInstance(name)
		if err != nil {
			fmt.Printf("Error: %s\n", err.Error())
		}

	},
}

func init() {
	instanceLaunch.Flags().Uint("size", 0, "Instance disk size (GB)")
	cmd.InstanceRootCmd.AddCommand(instanceLaunch)
}