github.com/vmware/govmomi@v0.43.0/govc/cluster/create.go (about) 1 /* 2 Copyright (c) 2015 VMware, Inc. All Rights Reserved. 3 4 Licensed under the Apache License, Version 2.0 (the "License"); 5 you may not use this file except in compliance with the License. 6 You may obtain a copy of the License at 7 8 http://www.apache.org/licenses/LICENSE-2.0 9 10 Unless required by applicable law or agreed to in writing, software 11 distributed under the License is distributed on an "AS IS" BASIS, 12 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 See the License for the specific language governing permissions and 14 limitations under the License. 15 */ 16 17 package cluster 18 19 import ( 20 "context" 21 "flag" 22 23 "github.com/vmware/govmomi/govc/cli" 24 "github.com/vmware/govmomi/govc/flags" 25 "github.com/vmware/govmomi/vim25/types" 26 ) 27 28 type create struct { 29 *flags.FolderFlag 30 31 types.ClusterConfigSpecEx 32 } 33 34 func init() { 35 cli.Register("cluster.create", &create{}) 36 } 37 38 func (cmd *create) Register(ctx context.Context, f *flag.FlagSet) { 39 cmd.FolderFlag, ctx = flags.NewFolderFlag(ctx) 40 cmd.FolderFlag.Register(ctx, f) 41 } 42 43 func (cmd *create) Usage() string { 44 return "CLUSTER" 45 } 46 47 func (cmd *create) Description() string { 48 return `Create CLUSTER in datacenter. 49 50 The cluster is added to the folder specified by the 'folder' flag. If not given, 51 this defaults to the host folder in the specified or default datacenter. 52 53 Examples: 54 govc cluster.create ClusterA 55 govc cluster.create -folder /dc2/test-folder ClusterB` 56 } 57 58 func (cmd *create) Process(ctx context.Context) error { 59 if err := cmd.FolderFlag.Process(ctx); err != nil { 60 return err 61 } 62 return nil 63 } 64 65 func (cmd *create) Run(ctx context.Context, f *flag.FlagSet) error { 66 if f.NArg() != 1 { 67 return flag.ErrHelp 68 } 69 70 folder, err := cmd.FolderOrDefault("host") 71 if err != nil { 72 return err 73 } 74 75 _, err = folder.CreateCluster(ctx, f.Arg(0), cmd.ClusterConfigSpecEx) 76 77 return err 78 }