github.com/minio/mc@v0.0.0-20240503112107-b471de8d1882/cmd/admin-decom-start.go (about) 1 // Copyright (c) 2015-2022 MinIO, Inc. 2 // 3 // This file is part of MinIO Object Storage stack 4 // 5 // This program is free software: you can redistribute it and/or modify 6 // it under the terms of the GNU Affero General Public License as published by 7 // the Free Software Foundation, either version 3 of the License, or 8 // (at your option) any later version. 9 // 10 // This program is distributed in the hope that it will be useful 11 // but WITHOUT ANY WARRANTY; without even the implied warranty of 12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 // GNU Affero General Public License for more details. 14 // 15 // You should have received a copy of the GNU Affero General Public License 16 // along with this program. If not, see <http://www.gnu.org/licenses/>. 17 18 package cmd 19 20 import ( 21 "path/filepath" 22 23 "github.com/fatih/color" 24 "github.com/minio/cli" 25 json "github.com/minio/colorjson" 26 "github.com/minio/mc/pkg/probe" 27 "github.com/minio/pkg/v2/console" 28 ) 29 30 var adminDecommissionStartCmd = cli.Command{ 31 Name: "start", 32 Usage: "start decommissioning a pool", 33 Action: mainAdminDecommissionStart, 34 OnUsageError: onUsageError, 35 Before: setGlobalsFromContext, 36 Flags: globalFlags, 37 CustomHelpTemplate: `NAME: 38 {{.HelpName}} - {{.Usage}} 39 40 USAGE: 41 {{.HelpName}} TARGET 42 43 FLAGS: 44 {{range .VisibleFlags}}{{.}} 45 {{end}} 46 EXAMPLES: 47 1. Start decommissioning a pool for removal. 48 {{.Prompt}} {{.HelpName}} myminio/ http://server{5...8}/disk{1...4} 49 `, 50 } 51 52 // checkAdminDecommissionStartSyntax - validate all the passed arguments 53 func checkAdminDecommissionStartSyntax(ctx *cli.Context) { 54 if len(ctx.Args()) != 2 { 55 showCommandHelpAndExit(ctx, 1) // last argument is exit code 56 } 57 } 58 59 // startDecomMessage is container for make bucket success and failure messages. 60 type startDecomMessage struct { 61 Status string `json:"status"` 62 Pool string `json:"pool"` 63 } 64 65 // String colorized construct a string message. 66 func (s startDecomMessage) String() string { 67 return console.Colorize("DecomPool", "Decommission started successfully for `"+s.Pool+"`.") 68 } 69 70 // JSON jsonified decom message. 71 func (s startDecomMessage) JSON() string { 72 startDecomBytes, e := json.MarshalIndent(s, "", " ") 73 fatalIf(probe.NewError(e), "Unable to marshal into JSON.") 74 75 return string(startDecomBytes) 76 } 77 78 // mainAdminDecommissionStart is the handle for "mc admin decommission start" command. 79 func mainAdminDecommissionStart(ctx *cli.Context) error { 80 checkAdminDecommissionStartSyntax(ctx) 81 82 // Additional command speific theme customization. 83 console.SetColor("DecomPool", color.New(color.FgGreen, color.Bold)) 84 85 // Get the alias parameter from cli 86 args := ctx.Args() 87 aliasedURL := args.Get(0) 88 aliasedURL = filepath.Clean(aliasedURL) 89 90 // Create a new MinIO Admin Client 91 client, err := newAdminClient(aliasedURL) 92 fatalIf(err, "Unable to initialize admin connection.") 93 94 e := client.DecommissionPool(globalContext, args.Get(1)) 95 fatalIf(probe.NewError(e).Trace(args...), "Unable to start decommission on the specified pool") 96 97 printMsg(startDecomMessage{ 98 Status: "success", 99 Pool: args.Get(1), 100 }) 101 return nil 102 }