/
target.go
71 lines (60 loc) · 1.96 KB
/
target.go
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
package target
import (
"github.com/spf13/cobra"
"github.com/spf13/pflag"
"github.com/appbricks/cloud-builder/target"
cbcli_utils "github.com/appbricks/cloud-builder-cli/utils"
)
var TargetCommands = &cobra.Command{
Use: "target",
Short: "List, show detail of running targets and configure quick launch recipes.",
Long: `
A target is an instance of a recipe that can be launched with a
single click to a cloud region. When a recipe is configured for a
particular cloud it will enumerate all the regions of that cloud as
quick lauch targets. The sub-commands below allow you to launch, view
amd manage these target spaces.
`,
}
func init() {
TargetCommands.AddCommand(createCommand)
TargetCommands.AddCommand(listCommand)
TargetCommands.AddCommand(showCommand)
TargetCommands.AddCommand(configureCommand)
TargetCommands.AddCommand(launchCommand)
TargetCommands.AddCommand(deleteCommand)
TargetCommands.AddCommand(suspendCommand)
TargetCommands.AddCommand(resumeCommand)
TargetCommands.AddCommand(connectCommand)
TargetCommands.AddCommand(sshCommand)
}
type commonFlags struct {
region string
space string
}
func bindCommonFlags(
flags *pflag.FlagSet,
commonFlags *commonFlags,
) {
flags.StringVarP(&commonFlags.region, "region", "r", "",
"space target's region")
flags.StringVarP(&commonFlags.space, "space", "s", "",
"application's attached space target\n(format <recipe>/<cloud>/<region>/<name>)")
}
func getTargetKeyFromArgs(
recipe, iaas, deploymentName string,
commonFlags *commonFlags,
) string {
var (
targetKey string
)
if len(commonFlags.region) > 0 && len(commonFlags.space) > 0 {
cbcli_utils.ShowErrorAndExit("Please provide only one of region or space options for target lookup.")
}
if len(commonFlags.region) > 0 {
targetKey = target.CreateKey(recipe, iaas, commonFlags.region, deploymentName)
} else if len(commonFlags.space) > 0 {
targetKey = target.CreateKey(recipe, iaas, deploymentName, "<"+commonFlags.space)
}
return targetKey
}