MCPcopy Create free account
hub / github.com/coldbrewcloud/coldbrew-cli / Run

Method Run

commands/clusterscale/command.go:41–87  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

39}
40
41func (c *Command) Run() error {
42 c.awsClient = c.globalFlags.GetAWSClient()
43
44 clusterName := strings.TrimSpace(conv.S(c.clusterNameArg))
45 if !core.ClusterNameRE.MatchString(clusterName) {
46 return console.ExitWithError(core.NewErrorExtraInfo(
47 fmt.Errorf("Invalid cluster name [%s]", clusterName), "https://github.com/coldbrewcloud/coldbrew-cli/wiki/Configuration-File#cluster"))
48 }
49
50 autoScalingGroupName := core.DefaultAutoScalingGroupName(clusterName)
51
52 console.Info("Auto Scaling Group")
53 console.DetailWithResource("Name", autoScalingGroupName)
54
55 autoScalingGroup, err := c.awsClient.AutoScaling().RetrieveAutoScalingGroup(autoScalingGroupName)
56 if err != nil {
57 return console.ExitWithErrorString("Failed to retrieve EC2 Auto Scaling Group [%s]: %s", autoScalingGroupName, err.Error())
58 }
59 if autoScalingGroup == nil {
60 return console.ExitWithErrorString("EC2 Auto Scaling Group [%s] was not found.", autoScalingGroupName)
61 }
62 if !utils.IsBlank(conv.S(autoScalingGroup.Status)) {
63 return console.ExitWithErrorString("EC2 Auto Scaling Group [%s] is being deleted: %s", autoScalingGroupName, conv.S(autoScalingGroup.Status))
64 }
65
66 currentTarget := uint16(conv.I64(autoScalingGroup.DesiredCapacity))
67 newTarget := conv.U16(c.instanceCount)
68
69 console.DetailWithResource("Current Target", fmt.Sprintf("%d", currentTarget))
70 console.DetailWithResource("New Target", fmt.Sprintf("%d", newTarget))
71
72 console.Blank()
73
74 if currentTarget < newTarget {
75 if err := c.scaleOut(autoScalingGroupName, currentTarget, newTarget); err != nil {
76 return console.ExitWithError(err)
77 }
78 } else if currentTarget > newTarget {
79 if err := c.scaleIn(autoScalingGroupName, currentTarget, newTarget); err != nil {
80 return console.ExitWithError(err)
81 }
82 } else {
83
84 }
85
86 return nil
87}
88
89func (c *Command) scaleOut(autoScalingGroupName string, currentTarget, newTarget uint16) error {
90 console.UpdatingResource(fmt.Sprintf("Updating desired capacity to %d", newTarget), autoScalingGroupName, true)

Callers

nothing calls this directly

Implementers 8

Commandcommands/clusterstatus/command.go
Commandcommands/deploy/command.go
Commandcommands/clusterdelete/command.go
Commandcommands/delete/command.go
Commandcommands/clustercreate/command.go
Commandcommands/create/command.go
Commandcommands/clusterscale/command.go
Commandcommands/status/command.go

Calls 6

scaleOutMethod · 0.95
scaleInMethod · 0.95
GetAWSClientMethod · 0.80
AutoScalingMethod · 0.80
ErrorMethod · 0.80

Tested by

no test coverage detected