yunion.io/x/cloudmux@v0.3.10-0-alpha.1/pkg/multicloud/esxi/shell/cluster.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 ClusterListOptions struct {
    26  		DATACENTER string `help:"List clusters in datacenter"`
    27  	}
    28  	shellutils.R(&ClusterListOptions{}, "cluster-list", "List all clusters", func(cli *esxi.SESXiClient, args *ClusterListOptions) error {
    29  		dc, err := cli.FindDatacenterByMoId(args.DATACENTER)
    30  		if err != nil {
    31  			return err
    32  		}
    33  		clusters, err := dc.ListClusters()
    34  		if err != nil {
    35  			return err
    36  		}
    37  		printList(clusters, nil)
    38  		return nil
    39  	})
    40  
    41  	type ClusterPoolListOptions struct {
    42  		DATACENTER string `help:"List clusters in datacenter"`
    43  		CLUSTER    string `help:"List cluster resource pool"`
    44  	}
    45  
    46  	shellutils.R(&ClusterPoolListOptions{}, "cluster-pool-list", "List all cluster resource pool", func(cli *esxi.SESXiClient, args *ClusterPoolListOptions) error {
    47  		dc, err := cli.FindDatacenterByMoId(args.DATACENTER)
    48  		if err != nil {
    49  			return err
    50  		}
    51  		cluster, err := dc.GetCluster(args.CLUSTER)
    52  		if err != nil {
    53  			return err
    54  		}
    55  		pools, err := cluster.ListResourcePools()
    56  		if err != nil {
    57  			return errors.Wrap(err, "ListResourcePools")
    58  		}
    59  		printList(pools, nil)
    60  		return nil
    61  	})
    62  
    63  	type ClusterPoolSyncOptions struct {
    64  		DATACENTER string `help:"List clusters in datacenter"`
    65  		CLUSTER    string `help:"List cluster resource pool"`
    66  		Name       string `help:"Resource pool name"`
    67  	}
    68  
    69  	shellutils.R(&ClusterPoolSyncOptions{}, "cluster-pool-sync", "Sync cluster resource pool", func(cli *esxi.SESXiClient, args *ClusterPoolSyncOptions) error {
    70  		dc, err := cli.FindDatacenterByMoId(args.DATACENTER)
    71  		if err != nil {
    72  			return err
    73  		}
    74  		cluster, err := dc.GetCluster(args.CLUSTER)
    75  		if err != nil {
    76  			return err
    77  		}
    78  		pool, err := cluster.SyncResourcePool(args.Name)
    79  		if err != nil {
    80  			return errors.Wrap(err, "SyncResourcePool")
    81  		}
    82  		printObject(pool)
    83  		return nil
    84  	})
    85  
    86  }