Skip to content

Commit edeabee

Browse files
authored
cmd: new appsearch shutdown and delete commands (#188)
Implements the new `ecctl deployment appsearch shutdown <deployment id>` and `ecctl deployment appsearch delete <deployment id>` commands
1 parent a721a14 commit edeabee

File tree

6 files changed

+214
-1
lines changed

6 files changed

+214
-1
lines changed

cmd/deployment/appsearch/delete.go

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
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 cmdappsearch
19+
20+
import (
21+
"os"
22+
23+
sdkcmdutil "github.com/elastic/cloud-sdk-go/pkg/util/cmdutil"
24+
"github.com/spf13/cobra"
25+
26+
"github.com/elastic/ecctl/pkg/deployment"
27+
"github.com/elastic/ecctl/pkg/deployment/depresource"
28+
"github.com/elastic/ecctl/pkg/ecctl"
29+
)
30+
31+
var deleteCmd = &cobra.Command{
32+
Use: "delete <deployment id>",
33+
Short: "Deletes a previously shut down AppSearch deployment resource",
34+
PreRunE: sdkcmdutil.MinimumNArgsAndUUID(1),
35+
RunE: func(cmd *cobra.Command, args []string) error {
36+
refID, _ := cmd.Flags().GetString("ref-id")
37+
38+
force, _ := cmd.Flags().GetBool("force")
39+
var msg = "This action will delete the AppSearch deployment resource and its configuration history. Do you want to continue? [y/n]: "
40+
if !force && !sdkcmdutil.ConfirmAction(msg, os.Stderr, os.Stdout) {
41+
return nil
42+
}
43+
44+
return depresource.DeleteStateless(depresource.DeleteStatelessParams{
45+
ResourceParams: deployment.ResourceParams{
46+
API: ecctl.Get().API,
47+
DeploymentID: args[0],
48+
Type: "appsearch",
49+
RefID: refID,
50+
},
51+
})
52+
},
53+
}
54+
55+
func init() {
56+
Command.AddCommand(deleteCmd)
57+
deleteCmd.Flags().String("ref-id", "", "Optional RefId, auto-discovered if not specified")
58+
}

cmd/deployment/appsearch/shutdown.go

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
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 cmdappsearch
19+
20+
import (
21+
"os"
22+
23+
"github.com/elastic/cloud-sdk-go/pkg/util/cmdutil"
24+
"github.com/spf13/cobra"
25+
26+
"github.com/elastic/ecctl/pkg/deployment"
27+
"github.com/elastic/ecctl/pkg/deployment/depresource"
28+
"github.com/elastic/ecctl/pkg/ecctl"
29+
)
30+
31+
var shutdownCmd = &cobra.Command{
32+
Use: "shutdown <deployment id>",
33+
Short: "Shuts down an AppSearch deployment",
34+
PreRunE: cmdutil.MinimumNArgsAndUUID(1),
35+
RunE: func(cmd *cobra.Command, args []string) error {
36+
refID, _ := cmd.Flags().GetString("ref-id")
37+
skipSnapshot, _ := cmd.Flags().GetBool("skip-snapshot")
38+
hide, _ := cmd.Flags().GetBool("hide")
39+
40+
force, _ := cmd.Flags().GetBool("force")
41+
var msg = "This action will shutdown the AppSearch deployment. Do you want to continue? [y/n]: "
42+
if !force && !cmdutil.ConfirmAction(msg, os.Stderr, os.Stdout) {
43+
return nil
44+
}
45+
46+
return depresource.Shutdown(depresource.ShutdownParams{
47+
ResourceParams: deployment.ResourceParams{
48+
API: ecctl.Get().API,
49+
DeploymentID: args[0],
50+
Type: "appsearch",
51+
RefID: refID,
52+
},
53+
SkipSnapshot: skipSnapshot,
54+
Hide: hide,
55+
})
56+
57+
},
58+
}
59+
60+
func init() {
61+
Command.AddCommand(shutdownCmd)
62+
shutdownCmd.Flags().String("ref-id", "", "Optional RefId, auto-discovered if not specified")
63+
shutdownCmd.Flags().Bool("skip-snapshot", false, "Optional flag to toggle skipping the snapshot before shutting it down")
64+
shutdownCmd.Flags().Bool("hide", false, "Optionally hides the deployment resource from being listed by default")
65+
}

docs/ecctl_deployment_appsearch.md

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

4141
* [ecctl deployment](ecctl_deployment.md) - Manages deployments
4242
* [ecctl deployment appsearch create](ecctl_deployment_appsearch_create.md) - Creates an AppSearch instance
43+
* [ecctl deployment appsearch delete](ecctl_deployment_appsearch_delete.md) - Deletes a previously shut down AppSearch deployment resource
4344
* [ecctl deployment appsearch show](ecctl_deployment_appsearch_show.md) - Shows the specified AppSearch deployment
45+
* [ecctl deployment appsearch shutdown](ecctl_deployment_appsearch_shutdown.md) - Shuts down an AppSearch deployment
4446

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
## ecctl deployment appsearch delete
2+
3+
Deletes a previously shut down AppSearch deployment resource
4+
5+
### Synopsis
6+
7+
Deletes a previously shut down AppSearch deployment resource
8+
9+
```
10+
ecctl deployment appsearch delete <deployment id> [flags]
11+
```
12+
13+
### Options
14+
15+
```
16+
-h, --help help for delete
17+
--ref-id string Optional RefId, auto-discovered if not specified
18+
```
19+
20+
### Options inherited from parent commands
21+
22+
```
23+
--apikey string API key to use to authenticate (If empty will look for EC_APIKEY environment variable)
24+
--config string Config name, used to have multiple configs in $HOME/.ecctl/<env> (default "config")
25+
--force Do not ask for confirmation
26+
--format string Formats the output using a Go template
27+
--host string Base URL to use
28+
--insecure Skips all TLS validation
29+
--message string A message to set on cluster operation
30+
--output string Output format [text|json] (default "text")
31+
--pass string Password to use to authenticate (If empty will look for EC_PASS environment variable)
32+
--pprof Enables pprofing and saves the profile to pprof-20060102150405
33+
-q, --quiet Suppresses the configuration file used for the run, if any
34+
--timeout duration Timeout to use on all HTTP calls (default 30s)
35+
--trace Enables tracing saves the trace to trace-20060102150405
36+
--user string Username to use to authenticate (If empty will look for EC_USER environment variable)
37+
--verbose Enable verbose mode
38+
```
39+
40+
### SEE ALSO
41+
42+
* [ecctl deployment appsearch](ecctl_deployment_appsearch.md) - Manages AppSearch deployments
43+
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
## ecctl deployment appsearch shutdown
2+
3+
Shuts down an AppSearch deployment
4+
5+
### Synopsis
6+
7+
Shuts down an AppSearch deployment
8+
9+
```
10+
ecctl deployment appsearch shutdown <deployment id> [flags]
11+
```
12+
13+
### Options
14+
15+
```
16+
-h, --help help for shutdown
17+
--hide Optionally hides the deployment resource from being listed by default
18+
--ref-id string Optional RefId, auto-discovered if not specified
19+
--skip-snapshot Optional flag to toggle skipping the snapshot before shutting it down
20+
```
21+
22+
### Options inherited from parent commands
23+
24+
```
25+
--apikey string API key to use to authenticate (If empty will look for EC_APIKEY environment variable)
26+
--config string Config name, used to have multiple configs in $HOME/.ecctl/<env> (default "config")
27+
--force Do not ask for confirmation
28+
--format string Formats the output using a Go template
29+
--host string Base URL to use
30+
--insecure Skips all TLS validation
31+
--message string A message to set on cluster operation
32+
--output string Output format [text|json] (default "text")
33+
--pass string Password to use to authenticate (If empty will look for EC_PASS environment variable)
34+
--pprof Enables pprofing and saves the profile to pprof-20060102150405
35+
-q, --quiet Suppresses the configuration file used for the run, if any
36+
--timeout duration Timeout to use on all HTTP calls (default 30s)
37+
--trace Enables tracing saves the trace to trace-20060102150405
38+
--user string Username to use to authenticate (If empty will look for EC_USER environment variable)
39+
--verbose Enable verbose mode
40+
```
41+
42+
### SEE ALSO
43+
44+
* [ecctl deployment appsearch](ecctl_deployment_appsearch.md) - Manages AppSearch deployments
45+

pkg/deployment/depresource/delete_stateless.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ func (params *DeleteStatelessParams) Validate() error {
4545
return merr.ErrorOrNil()
4646
}
4747

48-
// DeleteStateless upgrades a stateless deployment resource like APM, Kibana
48+
// DeleteStateless deletes a stateless deployment resource like APM, Kibana
4949
// and AppSearch.
5050
func DeleteStateless(params DeleteStatelessParams) error {
5151
if err := params.Validate(); err != nil {

0 commit comments

Comments
 (0)