-
Notifications
You must be signed in to change notification settings - Fork 7
/
cancel.go
46 lines (36 loc) · 1.07 KB
/
cancel.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
package cmd
import (
"fmt"
"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/aws/session"
"github.com/aws/aws-sdk-go/service/ec2"
"github.com/pkg/errors"
"github.com/spf13/cobra"
)
// cancelCmd represents the cancel command
var cancelCmd = &cobra.Command{
Use: "cancel",
Short: "Cancel spot instance request",
RunE: doCancel,
}
var cancelOpts = struct {
dryRun bool
requestIDs []string
}{}
func doCancel(cmd *cobra.Command, args []string) error {
svc := ec2.New(session.New(), &aws.Config{})
resp, err := svc.CancelSpotInstanceRequests(&ec2.CancelSpotInstanceRequestsInput{
DryRun: aws.Bool(cancelOpts.dryRun),
SpotInstanceRequestIds: aws.StringSlice(cancelOpts.requestIDs),
})
if err != nil {
return errors.Wrap(err, "failed to execute CancelSpotInstanceRequests")
}
fmt.Println(resp)
return nil
}
func init() {
RootCmd.AddCommand(cancelCmd)
cancelCmd.Flags().BoolVar(&cancelOpts.dryRun, "dry-run", false, "dry-run")
cancelCmd.Flags().StringSliceVar(&cancelOpts.requestIDs, "request", []string{}, "Spot instance request IDs")
}