Skip to content

Commit

Permalink
Merge pull request #91 from rgbkrk/autoscale-set
Browse files Browse the repository at this point in the history
Allow for autoscaling.
  • Loading branch information
rgbkrk committed Jan 18, 2016
2 parents e96bc1d + 4920a57 commit b10473c
Showing 1 changed file with 34 additions and 0 deletions.
34 changes: 34 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,18 @@ type GrowCommand struct {
Nodes int
}

// AutoScaleCommand keeps context about a cluster command
type AutoScaleCommand struct {
*ClusterCommand
AutoScale string
}

// AutoScaleOn is the "give me autoscale on this cluster" string for the cli
const AutoScaleOn = "on"

// AutoScaleOff is the "turn off autoscale on this cluster" string for the cli
const AutoScaleOff = "off"

// UserNameEnvKey is the name of the env var accepted for the username
const UserNameEnvVar = "CARINA_USERNAME"

Expand Down Expand Up @@ -163,6 +175,11 @@ func New() *Application {
growCommand.Flag("by", "number of segments to increase the cluster by").Required().IntVar(&growCommand.Nodes)
growCommand.Action(growCommand.Grow)

autoscaleCommand := new(AutoScaleCommand)
autoscaleCommand.ClusterCommand = cap.NewClusterCommand(ctx, "autoscale", "Enable or disable autoscale on a cluster")
autoscaleCommand.Arg("autoscale", "whether autoscale is on or off").EnumVar(&autoscaleCommand.AutoScale, AutoScaleOn, AutoScaleOff)
autoscaleCommand.Action(autoscaleCommand.SetAutoScale)

credentialsCommand := cap.NewCredentialsCommand(ctx, "credentials", "download credentials")
credentialsCommand.Action(credentialsCommand.Download)

Expand Down Expand Up @@ -547,6 +564,23 @@ func (carina *GrowCommand) Grow(pc *kingpin.ParseContext) (err error) {
})
}

// SetAutoScale sets AutoScale on the cluster
func (carina *AutoScaleCommand) SetAutoScale(pc *kingpin.ParseContext) (err error) {
return carina.clusterApply(func(clusterName string) (*libcarina.Cluster, error) {
scale := true

switch carina.AutoScale {
case AutoScaleOn:
scale = true
break
case AutoScaleOff:
scale = false
break
}
return carina.ClusterClient.SetAutoScale(clusterName, scale)
})
}

// Rebuild nukes your cluster and builds it over again
func (carina *WaitClusterCommand) Rebuild(pc *kingpin.ParseContext) (err error) {
return carina.clusterApplyWait(carina.ClusterClient.Rebuild)
Expand Down

0 comments on commit b10473c

Please sign in to comment.