2016-11-28 17:38:06 -08:00
|
|
|
/*
|
|
|
|
|
Copyright 2016 The Rook Authors. All rights reserved.
|
|
|
|
|
|
|
|
|
|
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.
|
|
|
|
|
*/
|
2016-12-01 16:10:46 -08:00
|
|
|
package filesystem
|
2016-11-28 17:38:06 -08:00
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"fmt"
|
|
|
|
|
"os"
|
|
|
|
|
|
2017-10-05 10:00:19 -07:00
|
|
|
"github.com/rook/rook/cmd/rookctl/pool"
|
2017-06-20 12:10:30 -07:00
|
|
|
"github.com/rook/rook/cmd/rookctl/rook"
|
2016-11-28 17:38:06 -08:00
|
|
|
"github.com/rook/rook/pkg/model"
|
|
|
|
|
"github.com/rook/rook/pkg/rook/client"
|
|
|
|
|
"github.com/rook/rook/pkg/util/flags"
|
|
|
|
|
"github.com/spf13/cobra"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
var (
|
2017-10-05 10:00:19 -07:00
|
|
|
fileRequest model.FilesystemRequest
|
|
|
|
|
dataConfig pool.Config
|
|
|
|
|
metadataConfig pool.Config
|
2016-11-28 17:38:06 -08:00
|
|
|
)
|
|
|
|
|
|
2016-12-01 16:10:46 -08:00
|
|
|
var createCmd = &cobra.Command{
|
2016-11-28 17:38:06 -08:00
|
|
|
Use: "create",
|
|
|
|
|
Short: "Creates a new shared filesystem in the cluster",
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func init() {
|
2017-10-05 10:00:19 -07:00
|
|
|
createCmd.Flags().StringVarP(&fileRequest.Name, "name", "n", "", "Name of new filesystem to create (required)")
|
|
|
|
|
createCmd.Flags().Int32VarP(&fileRequest.MetadataServer.ActiveCount, "active-mds", "a", 1, "Number of active MDS servers")
|
|
|
|
|
pool.AddPoolFlags(createCmd, "data-", &dataConfig)
|
|
|
|
|
pool.AddPoolFlags(createCmd, "metadata-", &metadataConfig)
|
2016-11-28 17:38:06 -08:00
|
|
|
|
2016-12-01 16:10:46 -08:00
|
|
|
createCmd.RunE = createFilesystemEntry
|
2016-11-28 17:38:06 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func createFilesystemEntry(cmd *cobra.Command, args []string) error {
|
2016-12-01 16:10:46 -08:00
|
|
|
rook.SetupLogging()
|
|
|
|
|
|
2017-10-05 10:00:19 -07:00
|
|
|
if err := flags.VerifyRequiredFlags(cmd, []string{"name", "data-type", "metadata-type"}); err != nil {
|
2016-11-28 17:38:06 -08:00
|
|
|
return err
|
|
|
|
|
}
|
|
|
|
|
|
2017-10-05 10:00:19 -07:00
|
|
|
dataPool, err := pool.ConfigToModel(dataConfig)
|
2016-11-28 17:38:06 -08:00
|
|
|
if err != nil {
|
2017-10-05 10:00:19 -07:00
|
|
|
fmt.Fprintln(os.Stderr, "failed to read data settings", err)
|
2016-11-28 17:38:06 -08:00
|
|
|
os.Exit(1)
|
|
|
|
|
}
|
2017-10-05 10:00:19 -07:00
|
|
|
fileRequest.DataPools = append(fileRequest.DataPools, *dataPool)
|
|
|
|
|
metadataPool, err := pool.ConfigToModel(metadataConfig)
|
|
|
|
|
if err != nil {
|
|
|
|
|
fmt.Fprintln(os.Stderr, "failed to read metadata settings", err)
|
|
|
|
|
os.Exit(1)
|
|
|
|
|
}
|
|
|
|
|
fileRequest.MetadataPool = *metadataPool
|
2016-11-28 17:38:06 -08:00
|
|
|
|
2017-10-05 10:00:19 -07:00
|
|
|
c := rook.NewRookNetworkRestClient()
|
|
|
|
|
out, err := createFilesystem(fileRequest, c)
|
|
|
|
|
if err != nil {
|
|
|
|
|
fmt.Fprintln(os.Stderr, fmt.Errorf("failed to create new file system %s: %+v", fileRequest.Name, err))
|
|
|
|
|
os.Exit(1)
|
|
|
|
|
}
|
|
|
|
|
fmt.Fprintln(os.Stdout, out)
|
2016-11-28 17:38:06 -08:00
|
|
|
return nil
|
|
|
|
|
}
|
|
|
|
|
|
2017-10-05 10:00:19 -07:00
|
|
|
func createFilesystem(request model.FilesystemRequest, c client.RookRestClient) (string, error) {
|
|
|
|
|
_, err := c.CreateFilesystem(request)
|
|
|
|
|
if err != nil {
|
|
|
|
|
return "", fmt.Errorf("failed to create new file system %s: %+v", request.Name, err)
|
2016-11-28 17:38:06 -08:00
|
|
|
}
|
|
|
|
|
|
2017-10-05 10:00:19 -07:00
|
|
|
return fmt.Sprintf("succeeded starting creation of shared filesystem %s", request.Name), nil
|
2016-11-28 17:38:06 -08:00
|
|
|
}
|