Remove detach, attach, make donut from mc - cli moved to minio-io/donut project
This commit is contained in:
@@ -1,60 +0,0 @@
|
||||
/*
|
||||
* Minimalist Object Storage, (C) 2015 Minio, Inc.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/minio-io/cli"
|
||||
)
|
||||
|
||||
func doAttachDiskCmd(c *cli.Context) {
|
||||
if !c.Args().Present() {
|
||||
fatal("no args?")
|
||||
}
|
||||
disks := c.Args()
|
||||
mcDonutConfigData, err := loadDonutConfig()
|
||||
if err != nil {
|
||||
fatal(err.Error())
|
||||
}
|
||||
donutName := c.String("name")
|
||||
if donutName == "" {
|
||||
fatal("Invalid --donut <name> is needed for attach")
|
||||
}
|
||||
if _, ok := mcDonutConfigData.Donuts[donutName]; !ok {
|
||||
msg := fmt.Sprintf("Requested donut name %s does not exist, please use ``mc donut make`` first", donutName)
|
||||
fatal(msg)
|
||||
}
|
||||
if _, ok := mcDonutConfigData.Donuts[donutName].Node["localhost"]; !ok {
|
||||
msg := fmt.Sprintf("Corrupted donut config, please consult donut experts")
|
||||
fatal(msg)
|
||||
}
|
||||
activeDisks := mcDonutConfigData.Donuts[donutName].Node["localhost"].ActiveDisks
|
||||
inactiveDisks := mcDonutConfigData.Donuts[donutName].Node["localhost"].InactiveDisks
|
||||
for _, disk := range disks {
|
||||
activeDisks = appendUniq(activeDisks, disk)
|
||||
inactiveDisks = deleteFromSlice(inactiveDisks, disk)
|
||||
}
|
||||
|
||||
mcDonutConfigData.Donuts[donutName].Node["localhost"] = nodeConfig{
|
||||
ActiveDisks: activeDisks,
|
||||
InactiveDisks: inactiveDisks,
|
||||
}
|
||||
if err := saveDonutConfig(mcDonutConfigData); err != nil {
|
||||
fatal(err.Error())
|
||||
}
|
||||
}
|
||||
@@ -1,65 +0,0 @@
|
||||
/*
|
||||
* Minimalist Object Storage, (C) 2015 Minio, Inc.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/minio-io/cli"
|
||||
)
|
||||
|
||||
func doDetachDiskCmd(c *cli.Context) {
|
||||
if !c.Args().Present() {
|
||||
fatal("no args?")
|
||||
}
|
||||
disks := c.Args()
|
||||
mcDonutConfigData, err := loadDonutConfig()
|
||||
if err != nil {
|
||||
fatal(err.Error())
|
||||
}
|
||||
donutName := c.String("name")
|
||||
if donutName == "" {
|
||||
fatal("Invalid --donut <name> is needed for attach")
|
||||
}
|
||||
if _, ok := mcDonutConfigData.Donuts[donutName]; !ok {
|
||||
msg := fmt.Sprintf("Requested donut name <%s> does not exist, please use ``mc donut make`` first", donutName)
|
||||
fatal(msg)
|
||||
}
|
||||
if _, ok := mcDonutConfigData.Donuts[donutName].Node["localhost"]; !ok {
|
||||
msg := fmt.Sprintf("Corrupted donut config, please consult donut experts")
|
||||
fatal(msg)
|
||||
}
|
||||
|
||||
inactiveDisks := mcDonutConfigData.Donuts[donutName].Node["localhost"].InactiveDisks
|
||||
activeDisks := mcDonutConfigData.Donuts[donutName].Node["localhost"].ActiveDisks
|
||||
for _, disk := range disks {
|
||||
if isStringInSlice(activeDisks, disk) {
|
||||
activeDisks = deleteFromSlice(activeDisks, disk)
|
||||
inactiveDisks = appendUniq(inactiveDisks, disk)
|
||||
} else {
|
||||
msg := fmt.Sprintf("Cannot detach disk: <%s>, not part of donut <%s>", disk, donutName)
|
||||
warning(msg)
|
||||
}
|
||||
}
|
||||
mcDonutConfigData.Donuts[donutName].Node["localhost"] = nodeConfig{
|
||||
ActiveDisks: activeDisks,
|
||||
InactiveDisks: inactiveDisks,
|
||||
}
|
||||
if err := saveDonutConfig(mcDonutConfigData); err != nil {
|
||||
fatal(err.Error())
|
||||
}
|
||||
}
|
||||
+9
-5
@@ -30,7 +30,11 @@ func doDonutListCmd(c *cli.Context) {
|
||||
if !c.Args().Present() {
|
||||
fatal("no args?")
|
||||
}
|
||||
urlArg1, err := url.Parse(c.Args().First())
|
||||
urlStr, err := parseURL(c.Args().First())
|
||||
if err != nil {
|
||||
fatal(err.Error())
|
||||
}
|
||||
u, err := url.Parse(urlStr)
|
||||
if err != nil {
|
||||
fatal(err.Error())
|
||||
}
|
||||
@@ -38,15 +42,15 @@ func doDonutListCmd(c *cli.Context) {
|
||||
if err != nil {
|
||||
fatal(err.Error())
|
||||
}
|
||||
if _, ok := mcDonutConfigData.Donuts[urlArg1.Host]; !ok {
|
||||
msg := fmt.Sprintf("requested donut: <%s> does not exist", urlArg1.Host)
|
||||
if _, ok := mcDonutConfigData.Donuts[u.Host]; !ok {
|
||||
msg := fmt.Sprintf("requested donut: <%s> does not exist", u.Host)
|
||||
fatal(msg)
|
||||
}
|
||||
nodes := make(map[string][]string)
|
||||
for k, v := range mcDonutConfigData.Donuts[urlArg1.Host].Node {
|
||||
for k, v := range mcDonutConfigData.Donuts[u.Host].Node {
|
||||
nodes[k] = v.ActiveDisks
|
||||
}
|
||||
d, err := donut.GetNewClient(urlArg1.Host, nodes)
|
||||
d, err := donut.GetNewClient(u.Host, nodes)
|
||||
if err != nil {
|
||||
fatal(err.Error())
|
||||
}
|
||||
|
||||
@@ -1,79 +0,0 @@
|
||||
/*
|
||||
* Minimalist Object Storage, (C) 2015 Minio, Inc.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
|
||||
"github.com/minio-io/cli"
|
||||
)
|
||||
|
||||
func newDonutConfig(donutName string) (*mcDonutConfig, error) {
|
||||
mcDonutConfigData := new(mcDonutConfig)
|
||||
mcDonutConfigData.Donuts = make(map[string]donutConfig)
|
||||
mcDonutConfigData.Donuts[donutName] = donutConfig{
|
||||
Node: make(map[string]nodeConfig),
|
||||
}
|
||||
mcDonutConfigData.Donuts[donutName].Node["localhost"] = nodeConfig{
|
||||
ActiveDisks: make([]string, 0),
|
||||
InactiveDisks: make([]string, 0),
|
||||
}
|
||||
return mcDonutConfigData, nil
|
||||
}
|
||||
|
||||
// doMakeDonutCmd creates a new donut
|
||||
func doMakeDonutCmd(c *cli.Context) {
|
||||
if !c.Args().Present() {
|
||||
fatal("no args?")
|
||||
}
|
||||
if len(c.Args()) != 1 {
|
||||
fatal("invalid number of args")
|
||||
}
|
||||
donutName := c.Args().First()
|
||||
if !isValidDonutName(donutName) {
|
||||
fatal("Invalid donutName")
|
||||
}
|
||||
mcDonutConfigData, err := loadDonutConfig()
|
||||
if os.IsNotExist(err) {
|
||||
mcDonutConfigData, err = newDonutConfig(donutName)
|
||||
if err != nil {
|
||||
fatal(err.Error())
|
||||
}
|
||||
if err := saveDonutConfig(mcDonutConfigData); err != nil {
|
||||
fatal(err.Error())
|
||||
}
|
||||
return
|
||||
} else if err != nil {
|
||||
fatal(err.Error())
|
||||
}
|
||||
if _, ok := mcDonutConfigData.Donuts[donutName]; !ok {
|
||||
mcDonutConfigData.Donuts[donutName] = donutConfig{
|
||||
Node: make(map[string]nodeConfig),
|
||||
}
|
||||
mcDonutConfigData.Donuts[donutName].Node["localhost"] = nodeConfig{
|
||||
ActiveDisks: make([]string, 0),
|
||||
InactiveDisks: make([]string, 0),
|
||||
}
|
||||
if err := saveDonutConfig(mcDonutConfigData); err != nil {
|
||||
fatal(err.Error())
|
||||
}
|
||||
} else {
|
||||
msg := fmt.Sprintf("donut: %s already exists", donutName)
|
||||
info(msg)
|
||||
}
|
||||
}
|
||||
@@ -20,53 +20,6 @@ import (
|
||||
"github.com/minio-io/cli"
|
||||
)
|
||||
|
||||
var makeDonutCmd = cli.Command{
|
||||
Name: "make",
|
||||
Usage: "make donut",
|
||||
Description: "Make a new donut",
|
||||
Action: doMakeDonutCmd,
|
||||
}
|
||||
|
||||
var attachDiskCmd = cli.Command{
|
||||
Name: "attach",
|
||||
Usage: "attach disk",
|
||||
Description: "Attach disk to an existing donut",
|
||||
Action: doAttachDiskCmd,
|
||||
Flags: []cli.Flag{
|
||||
cli.StringFlag{
|
||||
Name: "name",
|
||||
Usage: "Donut name",
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
var detachDiskCmd = cli.Command{
|
||||
Name: "detach",
|
||||
Usage: "detach disk",
|
||||
Description: "Detach disk from an existing donut",
|
||||
Action: doDetachDiskCmd,
|
||||
Flags: []cli.Flag{
|
||||
cli.StringFlag{
|
||||
Name: "name",
|
||||
Usage: "Donut name",
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
var healDonutCmd = cli.Command{
|
||||
Name: "heal",
|
||||
Usage: "heal donut",
|
||||
Description: "Heal donut with any errors",
|
||||
Action: doHealDonutCmd,
|
||||
}
|
||||
|
||||
var rebalanceDonutCmd = cli.Command{
|
||||
Name: "rebalance",
|
||||
Usage: "rebalance donut",
|
||||
Description: "Rebalance data on donut after adding disks",
|
||||
Action: doRebalanceDonutCmd,
|
||||
}
|
||||
|
||||
var cpDonutCmd = cli.Command{
|
||||
Name: "cp",
|
||||
Usage: "cp",
|
||||
@@ -89,18 +42,7 @@ var lsDonutCmd = cli.Command{
|
||||
}
|
||||
|
||||
var donutOptions = []cli.Command{
|
||||
makeDonutCmd,
|
||||
attachDiskCmd,
|
||||
detachDiskCmd,
|
||||
healDonutCmd,
|
||||
rebalanceDonutCmd,
|
||||
mbDonutCmd,
|
||||
lsDonutCmd,
|
||||
cpDonutCmd,
|
||||
}
|
||||
|
||||
func doHealDonutCmd(c *cli.Context) {
|
||||
}
|
||||
|
||||
func doRebalanceDonutCmd(c *cli.Context) {
|
||||
}
|
||||
|
||||
+12
-20
@@ -40,7 +40,6 @@ func getURLType(urlStr string) (uType urlType, err error) {
|
||||
if err != nil {
|
||||
return urlUnknown, err
|
||||
}
|
||||
|
||||
switch u.Scheme {
|
||||
case "http":
|
||||
fallthrough
|
||||
@@ -68,28 +67,24 @@ func isValidURL(urlStr string) bool {
|
||||
|
||||
// isValidURL checks the validity of supported URL types
|
||||
func isValidFileURL(urlStr string) bool {
|
||||
u, e := getURLType(urlStr)
|
||||
if e != nil {
|
||||
utype, e := getURLType(urlStr)
|
||||
if e != nil || utype != urlFile {
|
||||
return false
|
||||
}
|
||||
if u != urlFile {
|
||||
return false
|
||||
}
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
// fixFileURL rewrites file URL to proper file:///path/to/ form.
|
||||
func fixFileURL(urlStr string) (fixedURL string, err error) {
|
||||
ut, e := getURLType(urlStr)
|
||||
if e != nil || ut != urlFile {
|
||||
return "", e
|
||||
}
|
||||
|
||||
if urlStr == "" {
|
||||
return "", errEmptyURL
|
||||
}
|
||||
|
||||
utype, e := getURLType(urlStr)
|
||||
if e != nil || utype != urlFile {
|
||||
return "", e
|
||||
}
|
||||
|
||||
u, e := url.Parse(urlStr)
|
||||
if e != nil {
|
||||
return "", e
|
||||
@@ -114,12 +109,12 @@ func fixFileURL(urlStr string) (fixedURL string, err error) {
|
||||
|
||||
// url2Object converts URL to bucket and objectname
|
||||
func url2Object(urlStr string) (bucketName, objectName string, err error) {
|
||||
url, err := url.Parse(urlStr)
|
||||
if url.Path == "" {
|
||||
u, err := url.Parse(urlStr)
|
||||
if u.Path == "" {
|
||||
// No bucket name passed. It is a valid case
|
||||
return "", "", nil
|
||||
}
|
||||
splits := strings.SplitN(url.Path, "/", 3)
|
||||
splits := strings.SplitN(u.Path, "/", 3)
|
||||
switch len(splits) {
|
||||
case 0, 1:
|
||||
bucketName = ""
|
||||
@@ -143,7 +138,6 @@ func url2Bucket(urlStr string) (bucketName string, err error) {
|
||||
// parseURL extracts URL string from a single cmd-line argument
|
||||
func parseURL(arg string) (urlStr string, err error) {
|
||||
urlStr = arg
|
||||
|
||||
// Use default host if no argument is passed
|
||||
if urlStr == "" {
|
||||
// Load config file
|
||||
@@ -166,11 +160,9 @@ func parseURL(arg string) (urlStr string, err error) {
|
||||
|
||||
// If it is a file URL, rewrite to file:///path/to form
|
||||
if isValidFileURL(urlStr) {
|
||||
urlStr, err = fixFileURL(urlStr)
|
||||
return urlStr, err
|
||||
return fixFileURL(urlStr)
|
||||
}
|
||||
|
||||
return urlStr, err
|
||||
return urlStr, nil
|
||||
}
|
||||
|
||||
// parseURL extracts multiple URL strings from a single cmd-line argument
|
||||
|
||||
Reference in New Issue
Block a user