yunion.io/x/cloudmux@v0.3.10-0-alpha.1/pkg/multicloud/esxi/shell/resourcepool.go (about) 1 // Copyright 2019 Yunion 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 package shell 16 17 import ( 18 "yunion.io/x/pkg/errors" 19 20 "yunion.io/x/cloudmux/pkg/multicloud/esxi" 21 "yunion.io/x/onecloud/pkg/util/shellutils" 22 ) 23 24 func init() { 25 type ResourcePoolListOptions struct { 26 DATACENTER string `help:"List resource pool in datacenter"` 27 } 28 shellutils.R(&ResourcePoolListOptions{}, "resource-pool-list", "List all resource pools", func(cli *esxi.SESXiClient, args *ResourcePoolListOptions) error { 29 dc, err := cli.FindDatacenterByMoId(args.DATACENTER) 30 if err != nil { 31 return err 32 } 33 pools, err := dc.GetResourcePools() 34 if err != nil { 35 return err 36 } 37 printList(pools, nil) 38 return nil 39 }) 40 41 type ResourcePoolCreateOptions struct { 42 DATACENTER string `help:"Create resource pool in datacenter"` 43 CLUSTER string `help:"Cluster name"` 44 NAME string `help:"Resource pool name"` 45 } 46 47 shellutils.R(&ResourcePoolCreateOptions{}, "resource-pool-create", "Create resource pool", func(cli *esxi.SESXiClient, args *ResourcePoolCreateOptions) error { 48 dc, err := cli.FindDatacenterByMoId(args.DATACENTER) 49 if err != nil { 50 return err 51 } 52 cluster, err := dc.GetCluster(args.CLUSTER) 53 if err != nil { 54 return errors.Wrap(err, "GetCluster") 55 } 56 pool, err := cluster.CreateResourcePool(args.NAME) 57 if err != nil { 58 return err 59 } 60 printObject(pool) 61 return nil 62 }) 63 }