Created
February 9, 2018 21:47
-
-
Save stack72/15a03b45a8e53546b80aee3ab5662e86 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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