-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
ee8fc19
commit 8d124d2
Showing
22 changed files
with
429 additions
and
283 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package hosts | ||
|
||
const ( | ||
spot string = "spot" | ||
spotDesc string = "if this flag is set the host will be created only on the region set by the AWS Env (AWS_DEFAULT_REGION)" | ||
airgap string = "airgap" | ||
airgapDesc string = "if this flag is set the host will be created as airgap machine. Access will done through a bastion" | ||
) |
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
package hosts | ||
|
||
import ( | ||
params "github.com/adrianriobo/qenvs/cmd/cmd/constants" | ||
qenvsContext "github.com/adrianriobo/qenvs/pkg/manager/context" | ||
"github.com/adrianriobo/qenvs/pkg/provider/aws/action/windows" | ||
"github.com/adrianriobo/qenvs/pkg/util/logging" | ||
"github.com/spf13/cobra" | ||
"github.com/spf13/pflag" | ||
"github.com/spf13/viper" | ||
) | ||
|
||
const ( | ||
cmdWindows = "windows" | ||
cmdWindowsDesc = "create windows dedicated host" | ||
|
||
amiName string = "ami-name" | ||
amiNameDesc string = "name for the custom ami to be used within windows machine. Check README on how to build it" | ||
amiNameDefault string = "Windows_Server-2019-English-Full-HyperV*" | ||
amiUsername string = "ami-username" | ||
amiUsernameDesc string = "name for de default user on the custom AMI" | ||
amiUsernameDefault string = "ec2-user" | ||
amiOwner string = "ami-owner" | ||
amiOwnerDesc string = "alias name for the owner of the custom AMI" | ||
amiOwnerDefault string = "self" | ||
) | ||
|
||
func GetWindowsCmd() *cobra.Command { | ||
c := &cobra.Command{ | ||
Use: cmdWindows, | ||
Short: cmdWindowsDesc, | ||
RunE: func(cmd *cobra.Command, args []string) error { | ||
if err := viper.BindPFlags(cmd.Flags()); err != nil { | ||
return err | ||
} | ||
return nil | ||
}, | ||
} | ||
c.AddCommand(getWindowsCreate(), getWindowsDestroy()) | ||
return c | ||
} | ||
|
||
func getWindowsCreate() *cobra.Command { | ||
c := &cobra.Command{ | ||
Use: params.CreateCmdName, | ||
Short: params.CreateCmdName, | ||
RunE: func(cmd *cobra.Command, args []string) error { | ||
if err := viper.BindPFlags(cmd.Flags()); err != nil { | ||
return err | ||
} | ||
|
||
// Initialize context | ||
qenvsContext.Init( | ||
viper.GetString(params.ProjectName), | ||
viper.GetString(params.BackedURL), | ||
viper.GetString(params.ConnectionDetailsOutput), | ||
viper.GetStringMapString(params.Tags)) | ||
|
||
// Run create | ||
if err := windows.Create( | ||
&windows.WindowsRequest{ | ||
Prefix: "main", | ||
AMIName: viper.GetString(amiName), | ||
AMIUser: viper.GetString(amiUsername), | ||
AMIOwner: viper.GetString(amiOwner), | ||
Spot: viper.IsSet(spot), | ||
Airgap: viper.IsSet(airgap)}); err != nil { | ||
logging.Error(err) | ||
} | ||
return nil | ||
}, | ||
} | ||
flagSet := pflag.NewFlagSet(params.CreateCmdName, pflag.ExitOnError) | ||
flagSet.StringP(params.ConnectionDetailsOutput, "", "", params.ConnectionDetailsOutputDesc) | ||
flagSet.StringToStringP(params.Tags, "", nil, params.TagsDesc) | ||
flagSet.StringP(amiName, "", amiNameDefault, amiNameDesc) | ||
flagSet.StringP(amiUsername, "", amiUsernameDefault, amiUsernameDesc) | ||
flagSet.StringP(amiOwner, "", amiOwnerDefault, amiOwnerDesc) | ||
flagSet.Bool(airgap, false, airgapDesc) | ||
flagSet.Bool(spot, false, spotDesc) | ||
c.PersistentFlags().AddFlagSet(flagSet) | ||
return c | ||
} | ||
|
||
func getWindowsDestroy() *cobra.Command { | ||
c := &cobra.Command{ | ||
Use: params.DestroyCmdName, | ||
Short: params.DestroyCmdName, | ||
RunE: func(cmd *cobra.Command, args []string) error { | ||
if err := viper.BindPFlags(cmd.Flags()); err != nil { | ||
return err | ||
} | ||
|
||
qenvsContext.InitBase( | ||
viper.GetString(params.ProjectName), | ||
viper.GetString(params.BackedURL)) | ||
|
||
if err := windows.Destroy(); err != nil { | ||
logging.Error(err) | ||
} | ||
return nil | ||
}, | ||
} | ||
return c | ||
} |
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Oops, something went wrong.