|
| 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 startMaintCmd = &cobra.Command{ |
| 33 | + Use: "start-maintenance <deployment id> --type <type> [--all|--i <instance-id>,<instance-id>]", |
| 34 | + Short: "Starts maintenance mode on 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.StartMaintenanceModeAllOrSpecified(depresource.StartInstancesParams{ |
| 54 | + StartParams: depresource.StartParams{ |
| 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(startMaintCmd) |
| 75 | + startMaintCmd.Flags().Bool("all", false, "Starts maintenance mode on all instances of a defined resource type") |
| 76 | + startMaintCmd.Flags().Bool("ignore-missing", false, "If set and the specified instance does not exist, then quietly proceed to the next instance") |
| 77 | + startMaintCmd.Flags().String("type", "", "Deployment resource type to use (elasticsearch, kibana, apm, or appsearch)") |
| 78 | + startMaintCmd.MarkFlagRequired("type") |
| 79 | + startMaintCmd.Flags().String("ref-id", "", "Optional deployment RefId, if not set, the RefId will be auto-discovered") |
| 80 | + startMaintCmd.Flags().StringSliceP("instance-id", "i", nil, "Deployment instance IDs to use (e.g. instance-0000000001)") |
| 81 | +} |
0 commit comments