yunion.io/x/cloudmux@v0.3.10-0-alpha.1/pkg/multicloud/bingocloud/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 bingocloud
    16  
    17  import (
    18  	"yunion.io/x/pkg/errors"
    19  
    20  	api "yunion.io/x/cloudmux/pkg/apis/compute"
    21  	"yunion.io/x/cloudmux/pkg/cloudprovider"
    22  	"yunion.io/x/cloudmux/pkg/multicloud"
    23  )
    24  
    25  type SCluster struct {
    26  	multicloud.SResourceBase
    27  	multicloud.STagBase
    28  
    29  	region *SRegion
    30  
    31  	ClusterControllerSet []struct {
    32  		Address string
    33  		Role    string
    34  	}
    35  	ClusterId        string
    36  	ClusterName      string
    37  	CreateVolumeMode string
    38  	ExtendDiskMode   string
    39  	Hypervisor       string
    40  	MaxVolumeStorage string
    41  	SchedPolicy      string
    42  	Status           string
    43  }
    44  
    45  func (self *SCluster) GetGlobalId() string {
    46  	return self.ClusterId
    47  }
    48  
    49  func (self *SCluster) GetId() string {
    50  	return self.ClusterId
    51  }
    52  
    53  func (self *SCluster) GetName() string {
    54  	return self.ClusterName
    55  }
    56  
    57  func (self *SCluster) GetStatus() string {
    58  	if self.Status == "available" {
    59  		return api.ZONE_ENABLE
    60  	}
    61  	return api.ZONE_DISABLE
    62  }
    63  
    64  func (self *SCluster) GetI18n() cloudprovider.SModelI18nTable {
    65  	return cloudprovider.SModelI18nTable{}
    66  }
    67  
    68  func (self *SCluster) GetIRegion() cloudprovider.ICloudRegion {
    69  	return self.region
    70  }
    71  
    72  func (self *SRegion) GetIZones() ([]cloudprovider.ICloudZone, error) {
    73  	clusters, err := self.GetClusters()
    74  	if err != nil {
    75  		return nil, errors.Wrapf(err, "GetClusters")
    76  	}
    77  	ret := []cloudprovider.ICloudZone{}
    78  	for i := range clusters {
    79  		clusters[i].region = self
    80  		ret = append(ret, &clusters[i])
    81  	}
    82  	return ret, nil
    83  }
    84  
    85  func (self *SRegion) GetIZoneById(id string) (cloudprovider.ICloudZone, error) {
    86  	zones, err := self.GetIZones()
    87  	if err != nil {
    88  		return nil, err
    89  	}
    90  	for i := range zones {
    91  		if zones[i].GetGlobalId() == id {
    92  			return zones[i], nil
    93  		}
    94  	}
    95  	return nil, errors.Wrapf(cloudprovider.ErrNotFound, id)
    96  }
    97  
    98  func (self *SRegion) GetClusters() ([]SCluster, error) {
    99  	resp, err := self.invoke("DescribeClusters", nil)
   100  	if err != nil {
   101  		return nil, err
   102  	}
   103  	ret := []SCluster{}
   104  	return ret, resp.Unmarshal(&ret, "clusterSet")
   105  }