Skip to content

Commit 033f06d

Browse files
authored
cmd: Add deployment resource stop and stop-maintenance cmds (#81)
Adds the following commands: - `ecctl deployment resource stop <deployment-id>` which stops a deployment resource. - `ecctl deployment resource stop-maintenance <deployment-id>` which stops maintenance mode on a deployment resource. They both require the `--type` flag and should use either `--all` to target all instances of the specified type, or `--instance-id` to specify which instances to target
1 parent d2c27b5 commit 033f06d

14 files changed

+1348
-3
lines changed
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
// Licensed to Elasticsearch B.V. under one or more contributor
2+
// license agreements. See the NOTICE file distributed with
3+
// this work for additional information regarding copyright
4+
// ownership. Elasticsearch B.V. licenses this file to you under
5+
// the Apache License, Version 2.0 (the "License"); you may
6+
// not use this file except in compliance with the License.
7+
// You may obtain a copy of the License at
8+
//
9+
// http://www.apache.org/licenses/LICENSE-2.0
10+
//
11+
// Unless required by applicable law or agreed to in writing,
12+
// software distributed under the License is distributed on an
13+
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
// KIND, either express or implied. See the License for the
15+
// specific language governing permissions and limitations
16+
// under the License.
17+
18+
package cmddeploymentresource
19+
20+
import (
21+
"fmt"
22+
23+
"github.com/elastic/cloud-sdk-go/pkg/util/ec"
24+
"github.com/spf13/cobra"
25+
26+
cmdutil "github.com/elastic/ecctl/cmd/util"
27+
"github.com/elastic/ecctl/pkg/deployment/depresource"
28+
"github.com/elastic/ecctl/pkg/ecctl"
29+
)
30+
31+
var stopMaintCmd = &cobra.Command{
32+
Use: "stop-maintenance <deployment id> --type <type> [--all|--i <instance-id>,<instance-id>]",
33+
Short: "Stops maintenance mode on a deployment resource",
34+
PreRunE: cmdutil.MinimumNArgsAndUUID(1),
35+
RunE: func(cmd *cobra.Command, args []string) error {
36+
resType, _ := cmd.Flags().GetString("type")
37+
refID, _ := cmd.Flags().GetString("ref-id")
38+
instanceID, _ := cmd.Flags().GetStringSlice("instance-id")
39+
ignoreMissing, _ := cmd.Flags().GetBool("ignore-missing")
40+
all, _ := cmd.Flags().GetBool("all")
41+
42+
if err := cmdutil.IncompatibleFlags(cmd, "all", "instance-id"); err != nil {
43+
fmt.Fprintln(cmd.OutOrStderr(), err)
44+
}
45+
46+
_, err := depresource.StopMaintenanceModeAllOrSpecified(depresource.StopInstancesParams{
47+
StopParams: depresource.StopParams{
48+
API: ecctl.Get().API,
49+
DeploymentID: args[0],
50+
Type: resType,
51+
RefID: refID,
52+
All: all,
53+
},
54+
InstanceIDs: instanceID,
55+
IgnoreMissing: ec.Bool(ignoreMissing),
56+
})
57+
if err != nil {
58+
return err
59+
}
60+
61+
return nil
62+
63+
},
64+
}
65+
66+
func init() {
67+
Command.AddCommand(stopMaintCmd)
68+
stopMaintCmd.Flags().Bool("all", false, "Stops maintenance mode on all instances of a defined resource type")
69+
stopMaintCmd.Flags().Bool("ignore-missing", false, "If set and the specified instance does not exist, then quietly proceed to the next instance")
70+
stopMaintCmd.Flags().String("type", "", "Deployment resource type to use (elasticsearch, kibana, apm, or appsearch)")
71+
stopMaintCmd.MarkFlagRequired("type")
72+
stopMaintCmd.Flags().String("ref-id", "", "Optional deployment RefId, if not set, the RefId will be auto-discovered")
73+
stopMaintCmd.Flags().StringSliceP("instance-id", "i", nil, "Deployment instance IDs to use (e.g. instance-0000000001)")
74+
}

cmd/deployment/resource/stop.go

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
// Licensed to Elasticsearch B.V. under one or more contributor
2+
// license agreements. See the NOTICE file distributed with
3+
// this work for additional information regarding copyright
4+
// ownership. Elasticsearch B.V. licenses this file to you under
5+
// the Apache License, Version 2.0 (the "License"); you may
6+
// not use this file except in compliance with the License.
7+
// You may obtain a copy of the License at
8+
//
9+
// http://www.apache.org/licenses/LICENSE-2.0
10+
//
11+
// Unless required by applicable law or agreed to in writing,
12+
// software distributed under the License is distributed on an
13+
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
// KIND, either express or implied. See the License for the
15+
// specific language governing permissions and limitations
16+
// under the License.
17+
18+
package cmddeploymentresource
19+
20+
import (
21+
"fmt"
22+
"os"
23+
24+
"github.com/elastic/cloud-sdk-go/pkg/util/ec"
25+
"github.com/spf13/cobra"
26+
27+
cmdutil "github.com/elastic/ecctl/cmd/util"
28+
"github.com/elastic/ecctl/pkg/deployment/depresource"
29+
"github.com/elastic/ecctl/pkg/ecctl"
30+
)
31+
32+
var stopCmd = &cobra.Command{
33+
Use: "stop <deployment id> --type <type> [--all|--i <instance-id>,<instance-id>]",
34+
Short: "Stops a deployment resource",
35+
PreRunE: cmdutil.MinimumNArgsAndUUID(1),
36+
RunE: func(cmd *cobra.Command, args []string) error {
37+
resType, _ := cmd.Flags().GetString("type")
38+
refID, _ := cmd.Flags().GetString("ref-id")
39+
instanceID, _ := cmd.Flags().GetStringSlice("instance-id")
40+
ignoreMissing, _ := cmd.Flags().GetBool("ignore-missing")
41+
all, _ := cmd.Flags().GetBool("all")
42+
force, _ := cmd.Flags().GetBool("force")
43+
44+
if err := cmdutil.IncompatibleFlags(cmd, "all", "instance-id"); err != nil {
45+
fmt.Fprintln(cmd.OutOrStderr(), err)
46+
}
47+
48+
var msg = "This action will incur in downtime if used with the --all flag. Do you want to continue? [y/n]: "
49+
if all && !force && !cmdutil.ConfirmAction(msg, os.Stderr, os.Stdout) {
50+
return nil
51+
}
52+
53+
_, err := depresource.StopAllOrSpecified(depresource.StopInstancesParams{
54+
StopParams: depresource.StopParams{
55+
API: ecctl.Get().API,
56+
DeploymentID: args[0],
57+
Type: resType,
58+
RefID: refID,
59+
All: all,
60+
},
61+
InstanceIDs: instanceID,
62+
IgnoreMissing: ec.Bool(ignoreMissing),
63+
})
64+
if err != nil {
65+
return err
66+
}
67+
68+
return nil
69+
70+
},
71+
}
72+
73+
func init() {
74+
Command.AddCommand(stopCmd)
75+
stopCmd.Flags().Bool("all", false, "Stops all instances of a defined resource type")
76+
stopCmd.Flags().Bool("ignore-missing", false, "If set and the specified instance does not exist, then quietly proceed to the next instance")
77+
stopCmd.Flags().String("type", "", "Deployment resource type to stop (elasticsearch, kibana, apm, or appsearch)")
78+
stopCmd.MarkFlagRequired("type")
79+
stopCmd.Flags().String("ref-id", "", "Optional deployment RefId, if not set, the RefId will be auto-discovered")
80+
stopCmd.Flags().StringSliceP("instance-id", "i", nil, "Deployment instance IDs to stop (e.g. instance-0000000001)")
81+
}

docs/ecctl_deployment_resource.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,5 +40,7 @@ ecctl deployment resource [flags]
4040

4141
* [ecctl deployment](ecctl_deployment.md) - Manages deployments
4242
* [ecctl deployment resource shutdown](ecctl_deployment_resource_shutdown.md) - Shuts down a deployment resource by its type and ref-id
43+
* [ecctl deployment resource stop](ecctl_deployment_resource_stop.md) - Stops a deployment resource
44+
* [ecctl deployment resource stop-maintenance](ecctl_deployment_resource_stop-maintenance.md) - Stops maintenance mode on a deployment resource
4345
* [ecctl deployment resource upgrade](ecctl_deployment_resource_upgrade.md) - Upgrades a deployment resource
4446

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
## ecctl deployment resource stop-maintenance
2+
3+
Stops maintenance mode on a deployment resource
4+
5+
### Synopsis
6+
7+
Stops maintenance mode on a deployment resource
8+
9+
```
10+
ecctl deployment resource stop-maintenance <deployment id> --type <type> [--all|--i <instance-id>,<instance-id>] [flags]
11+
```
12+
13+
### Options
14+
15+
```
16+
--all Stops maintenance mode on all instances of a defined resource type
17+
-h, --help help for stop-maintenance
18+
--ignore-missing If set and the specified instance does not exist, then quietly proceed to the next instance
19+
-i, --instance-id strings Deployment instance IDs to use (e.g. instance-0000000001)
20+
--ref-id string Optional deployment RefId, if not set, the RefId will be auto-discovered
21+
--type string Deployment resource type to use (elasticsearch, kibana, apm, or appsearch)
22+
```
23+
24+
### Options inherited from parent commands
25+
26+
```
27+
--apikey string API key to use to authenticate (If empty will look for EC_APIKEY environment variable)
28+
--config string Config name, used to have multiple configs in $HOME/.ecctl/<env> (default "config")
29+
--force Do not ask for confirmation
30+
--format string Formats the output using a Go template
31+
--host string Base URL to use
32+
--insecure Skips all TLS validation
33+
--message string A message to set on cluster operation
34+
--output string Output format [text|json] (default "text")
35+
--pass string Password to use to authenticate (If empty will look for EC_PASS environment variable)
36+
--pprof Enables pprofing and saves the profile to pprof-20060102150405
37+
-q, --quiet Suppresses the configuration file used for the run, if any
38+
--timeout duration Timeout to use on all HTTP calls (default 30s)
39+
--trace Enables tracing saves the trace to trace-20060102150405
40+
--user string Username to use to authenticate (If empty will look for EC_USER environment variable)
41+
--verbose Enable verbose mode
42+
```
43+
44+
### SEE ALSO
45+
46+
* [ecctl deployment resource](ecctl_deployment_resource.md) - Manages deployment resources
47+
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
## ecctl deployment resource stop
2+
3+
Stops a deployment resource
4+
5+
### Synopsis
6+
7+
Stops a deployment resource
8+
9+
```
10+
ecctl deployment resource stop <deployment id> --type <type> [--all|--i <instance-id>,<instance-id>] [flags]
11+
```
12+
13+
### Options
14+
15+
```
16+
--all Stops all instances of a defined resource type
17+
-h, --help help for stop
18+
--ignore-missing If set and the specified instance does not exist, then quietly proceed to the next instance
19+
-i, --instance-id strings Deployment instance IDs to stop (e.g. instance-0000000001)
20+
--ref-id string Optional deployment RefId, if not set, the RefId will be auto-discovered
21+
--type string Deployment resource type to stop (elasticsearch, kibana, apm, or appsearch)
22+
```
23+
24+
### Options inherited from parent commands
25+
26+
```
27+
--apikey string API key to use to authenticate (If empty will look for EC_APIKEY environment variable)
28+
--config string Config name, used to have multiple configs in $HOME/.ecctl/<env> (default "config")
29+
--force Do not ask for confirmation
30+
--format string Formats the output using a Go template
31+
--host string Base URL to use
32+
--insecure Skips all TLS validation
33+
--message string A message to set on cluster operation
34+
--output string Output format [text|json] (default "text")
35+
--pass string Password to use to authenticate (If empty will look for EC_PASS environment variable)
36+
--pprof Enables pprofing and saves the profile to pprof-20060102150405
37+
-q, --quiet Suppresses the configuration file used for the run, if any
38+
--timeout duration Timeout to use on all HTTP calls (default 30s)
39+
--trace Enables tracing saves the trace to trace-20060102150405
40+
--user string Username to use to authenticate (If empty will look for EC_USER environment variable)
41+
--verbose Enable verbose mode
42+
```
43+
44+
### SEE ALSO
45+
46+
* [ecctl deployment resource](ecctl_deployment_resource.md) - Manages deployment resources
47+

go.mod

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ require (
2121
github.com/spf13/viper v1.6.1
2222
golang.org/x/crypto v0.0.0-20190829043050-9756ffdc2472
2323
golang.org/x/oauth2 v0.0.0-20190211225200-5f6b76b7c9dd // indirect
24+
golang.org/x/tools v0.0.0-20190617190820-da514acc4774 // indirect
2425
)
2526

2627
replace sourcegraph.com/sourcegraph/go-diff v0.5.1 => github.com/sourcegraph/go-diff v0.5.1

0 commit comments

Comments
 (0)