Skip to content

Instantly share code, notes, and snippets.

@stack72
Created February 9, 2018 21:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save stack72/15a03b45a8e53546b80aee3ab5662e86 to your computer and use it in GitHub Desktop.
Save stack72/15a03b45a8e53546b80aee3ab5662e86 to your computer and use it in GitHub Desktop.
Cobra: &cobra.Command{
Use: "create",
Short: "create a triton instance",
SilenceUsage: true,
Args: cobra.NoArgs,
PreRunE: func(cmd *cobra.Command, args []string) error {
if cfg.GetMachineName() == "" {
return errors.New("Name must be specified for Create Instance")
}
if cfg.GetPkgName() == "" && cfg.GetPkgID() == "" {
return errors.New("Either `pkg-name` or `pkg-id` must be specified for Create Instance")
}
if cfg.GetImgID() == "" && cfg.GetImgID() == "" {
return errors.New("Either `img-name` or `img-id` must be specified for Create Instance")
}
return nil
},
RunE: func(cmd *cobra.Command, args []string) error {
cons := conswriter.GetTerminal()
c, err := cfg.New()
if err != nil {
return err
}
a, err := compute.NewGetComputeClient(c)
if err != nil {
return err
}
instance, err := a.CreateInstance()
if err != nil {
return err
}
cons.Write([]byte(fmt.Sprintf("Created instance %q (%s)", instance.Name, instance.ID)))
return nil
},
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment