mirror of
https://github.com/yunionio/cloudpods.git
synced 2026-09-24 16:03:43 +08:00
Merge pull request #13762 from ioito/hotfix/qx-bingo-fix
fix(region): bingocloud sync fix
This commit is contained in:
@@ -29,10 +29,10 @@ import (
|
||||
"time"
|
||||
|
||||
xj "github.com/basgys/goxml2json"
|
||||
"github.com/pkg/errors"
|
||||
|
||||
"yunion.io/x/jsonutils"
|
||||
"yunion.io/x/log"
|
||||
"yunion.io/x/pkg/errors"
|
||||
|
||||
api "yunion.io/x/onecloud/pkg/apis/compute"
|
||||
"yunion.io/x/onecloud/pkg/cloudprovider"
|
||||
@@ -41,6 +41,8 @@ import (
|
||||
|
||||
const (
|
||||
CLOUD_PROVIDER_BINGO_CLOUD = api.CLOUD_PROVIDER_BINGO_CLOUD
|
||||
|
||||
MAX_RESULT = 20
|
||||
)
|
||||
|
||||
type BingoCloudConfig struct {
|
||||
|
||||
@@ -0,0 +1,105 @@
|
||||
// Copyright 2019 Yunion
|
||||
//
|
||||
// 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.
|
||||
|
||||
package bingocloud
|
||||
|
||||
import (
|
||||
"yunion.io/x/pkg/errors"
|
||||
|
||||
api "yunion.io/x/onecloud/pkg/apis/compute"
|
||||
"yunion.io/x/onecloud/pkg/cloudprovider"
|
||||
"yunion.io/x/onecloud/pkg/multicloud"
|
||||
)
|
||||
|
||||
type SCluster struct {
|
||||
multicloud.SResourceBase
|
||||
multicloud.STagBase
|
||||
|
||||
region *SRegion
|
||||
|
||||
ClusterControllerSet []struct {
|
||||
Address string
|
||||
Role string
|
||||
}
|
||||
ClusterId string
|
||||
ClusterName string
|
||||
CreateVolumeMode string
|
||||
ExtendDiskMode string
|
||||
Hypervisor string
|
||||
MaxVolumeStorage string
|
||||
SchedPolicy string
|
||||
Status string
|
||||
}
|
||||
|
||||
func (self *SCluster) GetGlobalId() string {
|
||||
return self.ClusterId
|
||||
}
|
||||
|
||||
func (self *SCluster) GetId() string {
|
||||
return self.ClusterId
|
||||
}
|
||||
|
||||
func (self *SCluster) GetName() string {
|
||||
return self.ClusterName
|
||||
}
|
||||
|
||||
func (self *SCluster) GetStatus() string {
|
||||
if self.Status == "available" {
|
||||
return api.ZONE_ENABLE
|
||||
}
|
||||
return api.ZONE_DISABLE
|
||||
}
|
||||
|
||||
func (self *SCluster) GetI18n() cloudprovider.SModelI18nTable {
|
||||
return cloudprovider.SModelI18nTable{}
|
||||
}
|
||||
|
||||
func (self *SCluster) GetIRegion() cloudprovider.ICloudRegion {
|
||||
return self.region
|
||||
}
|
||||
|
||||
func (self *SRegion) GetIZones() ([]cloudprovider.ICloudZone, error) {
|
||||
clusters, err := self.GetClusters()
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(err, "GetClusters")
|
||||
}
|
||||
ret := []cloudprovider.ICloudZone{}
|
||||
for i := range clusters {
|
||||
clusters[i].region = self
|
||||
ret = append(ret, &clusters[i])
|
||||
}
|
||||
return ret, nil
|
||||
}
|
||||
|
||||
func (self *SRegion) GetIZoneById(id string) (cloudprovider.ICloudZone, error) {
|
||||
zones, err := self.GetIZones()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
for i := range zones {
|
||||
if zones[i].GetGlobalId() == id {
|
||||
return zones[i], nil
|
||||
}
|
||||
}
|
||||
return nil, errors.Wrapf(cloudprovider.ErrNotFound, id)
|
||||
}
|
||||
|
||||
func (self *SRegion) GetClusters() ([]SCluster, error) {
|
||||
resp, err := self.invoke("DescribeClusters", nil)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
ret := []SCluster{}
|
||||
return ret, resp.Unmarshal(&ret, "clusterSet")
|
||||
}
|
||||
@@ -16,6 +16,7 @@ package bingocloud
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
|
||||
"yunion.io/x/pkg/errors"
|
||||
|
||||
@@ -177,14 +178,21 @@ func (self *SDisk) GetStatus() string {
|
||||
}
|
||||
}
|
||||
|
||||
func (self *SRegion) GetDisks(id, nextToken string) ([]SDisk, string, error) {
|
||||
func (self *SRegion) GetDisks(id string, maxResult int, nextToken string) ([]SDisk, string, error) {
|
||||
params := map[string]string{}
|
||||
idx := 1
|
||||
if len(id) > 0 {
|
||||
params["volumeId"] = id
|
||||
params[fmt.Sprintf("Filter.%d.Name", idx)] = "volume-id"
|
||||
params[fmt.Sprintf("Filter.%d.Value.1", idx)] = id
|
||||
idx++
|
||||
}
|
||||
|
||||
if len(nextToken) > 0 {
|
||||
params["nextToken"] = nextToken
|
||||
}
|
||||
if maxResult > 0 {
|
||||
params["maxRecords"] = fmt.Sprintf("%d", maxResult)
|
||||
}
|
||||
resp, err := self.invoke("DescribeVolumes", params)
|
||||
if err != nil {
|
||||
return nil, "", err
|
||||
@@ -198,14 +206,14 @@ func (self *SRegion) GetDisks(id, nextToken string) ([]SDisk, string, error) {
|
||||
}
|
||||
|
||||
func (self *SStorage) GetIDisks() ([]cloudprovider.ICloudDisk, error) {
|
||||
part, nextToken, err := self.zone.region.GetDisks("", "")
|
||||
part, nextToken, err := self.cluster.region.GetDisks("", MAX_RESULT, "")
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
disks := []SDisk{}
|
||||
disks = append(disks, part...)
|
||||
for len(nextToken) > 0 {
|
||||
part, nextToken, err = self.zone.region.GetDisks("", nextToken)
|
||||
part, nextToken, err = self.cluster.region.GetDisks("", MAX_RESULT, nextToken)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -222,7 +230,7 @@ func (self *SStorage) GetIDisks() ([]cloudprovider.ICloudDisk, error) {
|
||||
}
|
||||
|
||||
func (self *SStorage) GetIDiskById(id string) (cloudprovider.ICloudDisk, error) {
|
||||
disk, err := self.zone.region.GetDisk(id)
|
||||
disk, err := self.cluster.region.GetDisk(id)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -234,7 +242,7 @@ func (self *SStorage) GetIDiskById(id string) (cloudprovider.ICloudDisk, error)
|
||||
}
|
||||
|
||||
func (self *SRegion) GetDisk(id string) (*SDisk, error) {
|
||||
disks, _, err := self.GetDisks(id, "")
|
||||
disks, _, err := self.GetDisks(id, 1, "")
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
@@ -14,12 +14,99 @@
|
||||
|
||||
package bingocloud
|
||||
|
||||
import "github.com/pkg/errors"
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"yunion.io/x/pkg/errors"
|
||||
|
||||
api "yunion.io/x/onecloud/pkg/apis/compute"
|
||||
"yunion.io/x/onecloud/pkg/cloudprovider"
|
||||
"yunion.io/x/onecloud/pkg/multicloud"
|
||||
)
|
||||
|
||||
type SEip struct {
|
||||
multicloud.SEipBase
|
||||
multicloud.BingoTags
|
||||
|
||||
region *SRegion
|
||||
|
||||
AddressId string
|
||||
AddressType string
|
||||
Bandtype string
|
||||
Bandwidth int
|
||||
CanAssociate bool
|
||||
InstanceId string
|
||||
Owner string
|
||||
PublicIp string
|
||||
SubnetId string
|
||||
VpcId string
|
||||
}
|
||||
|
||||
func (self *SRegion) GetEips(ip, nextToken string) ([]SEip, string, error) {
|
||||
func (self *SEip) GetId() string {
|
||||
return self.PublicIp
|
||||
}
|
||||
|
||||
func (self *SEip) GetGlobalId() string {
|
||||
return self.PublicIp
|
||||
}
|
||||
|
||||
func (self *SEip) GetName() string {
|
||||
return self.PublicIp
|
||||
}
|
||||
|
||||
func (self *SEip) GetIpAddr() string {
|
||||
return self.PublicIp
|
||||
}
|
||||
|
||||
func (self *SEip) GetMode() string {
|
||||
return api.EIP_MODE_STANDALONE_EIP
|
||||
}
|
||||
|
||||
func (self *SEip) GetINetworkId() string {
|
||||
return self.SubnetId
|
||||
}
|
||||
|
||||
func (self *SEip) GetAssociationType() string {
|
||||
return api.EIP_ASSOCIATE_TYPE_SERVER
|
||||
}
|
||||
|
||||
func (self *SEip) GetAssociationExternalId() string {
|
||||
return self.InstanceId
|
||||
}
|
||||
|
||||
func (self *SEip) GetBandwidth() int {
|
||||
return self.Bandwidth
|
||||
}
|
||||
|
||||
func (self *SEip) GetInternetChargeType() string {
|
||||
return api.EIP_CHARGE_TYPE_BY_BANDWIDTH
|
||||
}
|
||||
|
||||
func (self *SEip) Delete() error {
|
||||
return cloudprovider.ErrNotImplemented
|
||||
}
|
||||
|
||||
func (self *SEip) Associate(conf *cloudprovider.AssociateConfig) error {
|
||||
return cloudprovider.ErrNotImplemented
|
||||
}
|
||||
|
||||
func (self *SEip) Dissociate() error {
|
||||
return cloudprovider.ErrNotImplemented
|
||||
}
|
||||
|
||||
func (self *SEip) ChangeBandwidth(bw int) error {
|
||||
return cloudprovider.ErrNotImplemented
|
||||
}
|
||||
|
||||
func (self *SEip) GetProjectId() string {
|
||||
return ""
|
||||
}
|
||||
|
||||
func (self *SEip) GetStatus() string {
|
||||
return api.EIP_STATUS_READY
|
||||
}
|
||||
|
||||
func (self *SRegion) GetEips(ip, instanceId, nextToken string) ([]SEip, string, error) {
|
||||
params := map[string]string{}
|
||||
if len(ip) > 0 {
|
||||
params["publicIp"] = ip
|
||||
@@ -27,6 +114,14 @@ func (self *SRegion) GetEips(ip, nextToken string) ([]SEip, string, error) {
|
||||
if len(nextToken) > 0 {
|
||||
params["nextToken"] = nextToken
|
||||
}
|
||||
|
||||
idx := 1
|
||||
if len(instanceId) > 0 {
|
||||
params[fmt.Sprintf("Filter.%d.Name", idx)] = "instance-id"
|
||||
params[fmt.Sprintf("Filter.%d.Value.1", idx)] = instanceId
|
||||
idx++
|
||||
}
|
||||
|
||||
resp, err := self.invoke("DescribeAddresses", params)
|
||||
if err != nil {
|
||||
return nil, "", errors.Wrapf(err, "DescribeAddresses")
|
||||
@@ -38,3 +133,39 @@ func (self *SRegion) GetEips(ip, nextToken string) ([]SEip, string, error) {
|
||||
resp.Unmarshal(&ret)
|
||||
return ret.AddressesSet, ret.NextToken, nil
|
||||
}
|
||||
|
||||
func (self *SRegion) GetIEips() ([]cloudprovider.ICloudEIP, error) {
|
||||
part, nextToken, err := self.GetEips("", "", "")
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
eips := []SEip{}
|
||||
eips = append(eips, part...)
|
||||
for len(nextToken) > 0 {
|
||||
part, nextToken, err = self.GetEips("", "", nextToken)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
eips = append(eips, part...)
|
||||
}
|
||||
ret := []cloudprovider.ICloudEIP{}
|
||||
for i := range eips {
|
||||
eips[i].region = self
|
||||
ret = append(ret, &eips[i])
|
||||
}
|
||||
return ret, nil
|
||||
}
|
||||
|
||||
func (self *SRegion) GetIEipById(id string) (cloudprovider.ICloudEIP, error) {
|
||||
eips, _, err := self.GetEips(id, "", "")
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
for i := range eips {
|
||||
if eips[i].GetGlobalId() == id {
|
||||
eips[i].region = self
|
||||
return &eips[i], nil
|
||||
}
|
||||
}
|
||||
return nil, errors.Wrapf(cloudprovider.ErrNotFound, id)
|
||||
}
|
||||
|
||||
@@ -15,23 +15,10 @@
|
||||
package bingocloud
|
||||
|
||||
import (
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"yunion.io/x/jsonutils"
|
||||
"yunion.io/x/pkg/errors"
|
||||
|
||||
api "yunion.io/x/onecloud/pkg/apis/compute"
|
||||
"yunion.io/x/onecloud/pkg/cloudprovider"
|
||||
"yunion.io/x/onecloud/pkg/multicloud"
|
||||
)
|
||||
|
||||
type SHost struct {
|
||||
multicloud.SHostBase
|
||||
multicloud.STagBase
|
||||
|
||||
zone *SZone
|
||||
|
||||
CPUHz string `json:"CpuHz"`
|
||||
ModelId string `json:"ModelId"`
|
||||
MonitorType string `json:"MonitorType"`
|
||||
@@ -65,150 +52,6 @@ type SHost struct {
|
||||
HostName string `json:"HostName"`
|
||||
}
|
||||
|
||||
func (self *SHost) GetId() string {
|
||||
return self.HostId
|
||||
}
|
||||
|
||||
func (self *SHost) GetGlobalId() string {
|
||||
return self.HostId
|
||||
}
|
||||
|
||||
func (self *SHost) GetName() string {
|
||||
return self.HostName
|
||||
}
|
||||
|
||||
func (self *SHost) GetAccessIp() string {
|
||||
return self.HostIP
|
||||
}
|
||||
|
||||
func (self *SHost) GetAccessMac() string {
|
||||
return ""
|
||||
}
|
||||
|
||||
func (self *SHost) GetSysInfo() jsonutils.JSONObject {
|
||||
return jsonutils.NewDict()
|
||||
}
|
||||
|
||||
func (self *SHost) GetSN() string {
|
||||
return self.BaseBoardSerial
|
||||
}
|
||||
|
||||
func (self *SHost) GetCpuCount() int {
|
||||
return self.CPUCores
|
||||
}
|
||||
|
||||
func (self *SHost) GetNodeCount() int8 {
|
||||
return 1
|
||||
}
|
||||
|
||||
func (self *SHost) GetCpuDesc() string {
|
||||
return self.CPUKind
|
||||
}
|
||||
|
||||
func (self *SHost) GetCpuMhz() int {
|
||||
return 0
|
||||
}
|
||||
|
||||
func (self *SHost) GetCpuCmtbound() float32 {
|
||||
return 1
|
||||
}
|
||||
|
||||
func (self *SHost) GetMemSizeMB() int {
|
||||
return self.Memory
|
||||
}
|
||||
|
||||
func (self *SHost) GetMemCmtbound() float32 {
|
||||
return 1
|
||||
}
|
||||
|
||||
func (self *SHost) GetReservedMemoryMb() int {
|
||||
return 0
|
||||
}
|
||||
|
||||
func (self *SHost) GetStorageSizeMB() int {
|
||||
return 0
|
||||
}
|
||||
|
||||
func (self *SHost) GetStorageType() string {
|
||||
return api.STORAGE_LOCAL_SSD
|
||||
}
|
||||
|
||||
func (self *SHost) GetHostType() string {
|
||||
return api.HOST_TYPE_BINGO_CLOUD
|
||||
}
|
||||
|
||||
func (self *SHost) CreateVM(desc *cloudprovider.SManagedVMCreateConfig) (cloudprovider.ICloudVM, error) {
|
||||
return nil, cloudprovider.ErrNotImplemented
|
||||
}
|
||||
|
||||
func (self *SHost) GetIStorages() ([]cloudprovider.ICloudStorage, error) {
|
||||
return self.zone.GetIStorages()
|
||||
}
|
||||
|
||||
func (self *SHost) GetIStorageById(id string) (cloudprovider.ICloudStorage, error) {
|
||||
return self.zone.GetIStorageById(id)
|
||||
}
|
||||
|
||||
func (self *SHost) GetEnabled() bool {
|
||||
return true
|
||||
}
|
||||
|
||||
func (self *SHost) GetHostStatus() string {
|
||||
if self.Status == "available" {
|
||||
return api.HOST_ONLINE
|
||||
}
|
||||
return api.HOST_OFFLINE
|
||||
}
|
||||
|
||||
func (self *SHost) GetIHostNics() ([]cloudprovider.ICloudHostNetInterface, error) {
|
||||
return nil, cloudprovider.ErrNotImplemented
|
||||
}
|
||||
|
||||
func (self *SHost) GetIVMs() ([]cloudprovider.ICloudVM, error) {
|
||||
vms := []SInstance{}
|
||||
part, nextToken, err := self.zone.region.GetInstances("", self.zone.ZoneName, 100, "")
|
||||
vms = append(vms, part...)
|
||||
for len(nextToken) > 0 {
|
||||
part, nextToken, err = self.zone.region.GetInstances("", self.zone.ZoneName, 100, nextToken)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
vms = append(vms, part...)
|
||||
}
|
||||
ret := []cloudprovider.ICloudVM{}
|
||||
for i := range vms {
|
||||
if strings.HasSuffix(vms[i].InstancesSet.HostAddress, self.HostIP) {
|
||||
vms[i].host = self
|
||||
ret = append(ret, &vms[i])
|
||||
}
|
||||
}
|
||||
return ret, nil
|
||||
}
|
||||
|
||||
func (self *SHost) GetIVMById(id string) (cloudprovider.ICloudVM, error) {
|
||||
return nil, cloudprovider.ErrNotImplemented
|
||||
}
|
||||
|
||||
func (self *SHost) GetIWires() ([]cloudprovider.ICloudWire, error) {
|
||||
return nil, cloudprovider.ErrNotImplemented
|
||||
}
|
||||
|
||||
func (self *SHost) GetSchedtags() ([]string, error) {
|
||||
return []string{}, nil
|
||||
}
|
||||
|
||||
func (self *SHost) GetIsMaintenance() bool {
|
||||
return false
|
||||
}
|
||||
|
||||
func (self *SHost) GetVersion() string {
|
||||
return ""
|
||||
}
|
||||
|
||||
func (self *SHost) GetStatus() string {
|
||||
return api.HOST_STATUS_RUNNING
|
||||
}
|
||||
|
||||
func (self *SRegion) GetHosts(nextToken string) ([]SHost, string, error) {
|
||||
params := map[string]string{}
|
||||
if len(nextToken) > 0 {
|
||||
@@ -227,38 +70,3 @@ func (self *SRegion) GetHosts(nextToken string) ([]SHost, string, error) {
|
||||
resp.Unmarshal(&ret)
|
||||
return ret.DescribePhysicalHostsResult.PhysicalHostSet, ret.NextToken, nil
|
||||
}
|
||||
|
||||
func (self *SZone) GetIHostById(id string) (cloudprovider.ICloudHost, error) {
|
||||
hosts, err := self.region.GetIHosts()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
for i := range hosts {
|
||||
if hosts[i].GetGlobalId() == id {
|
||||
return hosts[i], nil
|
||||
}
|
||||
}
|
||||
return nil, errors.Wrapf(cloudprovider.ErrNotFound, id)
|
||||
}
|
||||
|
||||
func (self *SZone) GetIHosts() ([]cloudprovider.ICloudHost, error) {
|
||||
hosts := []SHost{}
|
||||
part, nextToken, err := self.region.GetHosts("")
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
hosts = append(hosts, part...)
|
||||
for len(nextToken) > 0 {
|
||||
part, nextToken, err = self.region.GetHosts(nextToken)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
hosts = append(hosts, part...)
|
||||
}
|
||||
ret := []cloudprovider.ICloudHost{}
|
||||
for i := range hosts {
|
||||
hosts[i].zone = self
|
||||
ret = append(ret, &hosts[i])
|
||||
}
|
||||
return ret, nil
|
||||
}
|
||||
|
||||
@@ -28,7 +28,7 @@ import (
|
||||
type SInstance struct {
|
||||
multicloud.BingoTags
|
||||
multicloud.SInstanceBase
|
||||
host *SHost
|
||||
node *SNode
|
||||
|
||||
ReservationId string `json:"reservationId"`
|
||||
OwnerId string
|
||||
@@ -232,7 +232,7 @@ func (self *SInstance) GetHostname() string {
|
||||
}
|
||||
|
||||
func (self *SInstance) GetIHost() cloudprovider.ICloudHost {
|
||||
return self.host
|
||||
return self.node
|
||||
}
|
||||
|
||||
func (self *SInstance) GetIHostId() string {
|
||||
@@ -248,7 +248,7 @@ func (self *SInstance) GetHypervisor() string {
|
||||
}
|
||||
|
||||
func (self *SInstance) GetIDisks() ([]cloudprovider.ICloudDisk, error) {
|
||||
storages, err := self.host.zone.region.getStorages()
|
||||
storages, err := self.node.cluster.region.getStorages()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -258,13 +258,13 @@ func (self *SInstance) GetIDisks() ([]cloudprovider.ICloudDisk, error) {
|
||||
}
|
||||
ret := []cloudprovider.ICloudDisk{}
|
||||
for _, _disk := range self.InstancesSet.BlockDeviceMapping {
|
||||
disk, err := self.host.zone.region.GetDisk(_disk.Ebs.VolumeId)
|
||||
disk, err := self.node.cluster.region.GetDisk(_disk.Ebs.VolumeId)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
storage, ok := storageMaps[disk.StorageId]
|
||||
if ok {
|
||||
storage.zone = self.host.zone
|
||||
storage.cluster = self.node.cluster
|
||||
disk.storage = &storage
|
||||
ret = append(ret, disk)
|
||||
}
|
||||
@@ -273,7 +273,7 @@ func (self *SInstance) GetIDisks() ([]cloudprovider.ICloudDisk, error) {
|
||||
}
|
||||
|
||||
func (self *SInstance) GetINics() ([]cloudprovider.ICloudNic, error) {
|
||||
nics, err := self.host.zone.region.GetInstanceNics(self.InstancesSet.InstanceId)
|
||||
nics, err := self.node.cluster.region.GetInstanceNics(self.InstancesSet.InstanceId)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -285,7 +285,15 @@ func (self *SInstance) GetINics() ([]cloudprovider.ICloudNic, error) {
|
||||
}
|
||||
|
||||
func (self *SInstance) GetIEIP() (cloudprovider.ICloudEIP, error) {
|
||||
return nil, cloudprovider.ErrNotImplemented
|
||||
eips, _, err := self.node.cluster.region.GetEips("", self.InstancesSet.InstanceId, "")
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
for i := range eips {
|
||||
eips[i].region = self.node.cluster.region
|
||||
return &eips[i], nil
|
||||
}
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
func (self *SInstance) GetProjectId() string {
|
||||
@@ -294,6 +302,8 @@ func (self *SInstance) GetProjectId() string {
|
||||
|
||||
func (self *SInstance) GetStatus() string {
|
||||
switch self.InstancesSet.InstanceState.Name {
|
||||
case "stopped":
|
||||
return api.VM_READY
|
||||
default:
|
||||
return self.InstancesSet.InstanceState.Name
|
||||
}
|
||||
@@ -323,11 +333,8 @@ func (self *SInstance) UpdateVM(ctx context.Context, name string) error {
|
||||
return cloudprovider.ErrNotImplemented
|
||||
}
|
||||
|
||||
func (self *SRegion) GetInstances(id, zoneId string, maxResult int, nextToken string) ([]SInstance, string, error) {
|
||||
func (self *SRegion) GetInstances(id, nodeId string, maxResult int, nextToken string) ([]SInstance, string, error) {
|
||||
params := map[string]string{}
|
||||
if len(id) > 0 {
|
||||
params["instanceId"] = id
|
||||
}
|
||||
if maxResult > 0 {
|
||||
params["maxRecords"] = fmt.Sprintf("%d", maxResult)
|
||||
}
|
||||
@@ -336,9 +343,15 @@ func (self *SRegion) GetInstances(id, zoneId string, maxResult int, nextToken st
|
||||
}
|
||||
|
||||
idx := 1
|
||||
if len(zoneId) > 0 {
|
||||
params[fmt.Sprintf("Filter.%d.Name", idx)] = "availability-zone"
|
||||
params[fmt.Sprintf("Filter.%d.Value.1", idx)] = zoneId
|
||||
if len(nodeId) > 0 {
|
||||
params[fmt.Sprintf("Filter.%d.Name", idx)] = "node-id"
|
||||
params[fmt.Sprintf("Filter.%d.Value.1", idx)] = nodeId
|
||||
idx++
|
||||
}
|
||||
|
||||
if len(id) > 0 {
|
||||
params[fmt.Sprintf("Filter.%d.Name", idx)] = "instance-id"
|
||||
params[fmt.Sprintf("Filter.%d.Value.1", idx)] = id
|
||||
idx++
|
||||
}
|
||||
|
||||
|
||||
@@ -149,7 +149,7 @@ func (self *SWire) CreateINetwork(opts *cloudprovider.SNetworkCreateOptions) (cl
|
||||
}
|
||||
|
||||
func (self *SWire) GetINetworks() ([]cloudprovider.ICloudNetwork, error) {
|
||||
networks, err := self.vpc.region.GetNetworks("", self.zone.ZoneName, self.vpc.VpcId)
|
||||
networks, err := self.vpc.region.GetNetworks("", self.cluster.ClusterId, self.vpc.VpcId)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -174,15 +174,15 @@ func (self *SWire) GetINetworkById(id string) (cloudprovider.ICloudNetwork, erro
|
||||
return nil, errors.Wrapf(cloudprovider.ErrNotFound, id)
|
||||
}
|
||||
|
||||
func (self *SRegion) GetNetworks(id, zoneId, vpcId string) ([]SNetwork, error) {
|
||||
func (self *SRegion) GetNetworks(id, clusterId, vpcId string) ([]SNetwork, error) {
|
||||
params := map[string]string{}
|
||||
if len(id) > 0 {
|
||||
params["subnetId"] = id
|
||||
}
|
||||
idx := 1
|
||||
if len(zoneId) > 0 {
|
||||
if len(clusterId) > 0 {
|
||||
params[fmt.Sprintf("Filter.%d.Name", idx)] = "availability-zone"
|
||||
params[fmt.Sprintf("Filter.%d.Value.1", idx)] = zoneId
|
||||
params[fmt.Sprintf("Filter.%d.Value.1", idx)] = clusterId
|
||||
idx++
|
||||
}
|
||||
if len(vpcId) > 0 {
|
||||
|
||||
@@ -0,0 +1,261 @@
|
||||
// Copyright 2019 Yunion
|
||||
//
|
||||
// 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.
|
||||
|
||||
package bingocloud
|
||||
|
||||
import (
|
||||
"strings"
|
||||
|
||||
"yunion.io/x/jsonutils"
|
||||
"yunion.io/x/pkg/errors"
|
||||
|
||||
api "yunion.io/x/onecloud/pkg/apis/compute"
|
||||
"yunion.io/x/onecloud/pkg/cloudprovider"
|
||||
"yunion.io/x/onecloud/pkg/multicloud"
|
||||
)
|
||||
|
||||
type SNode struct {
|
||||
multicloud.SHostBase
|
||||
multicloud.STagBase
|
||||
|
||||
cluster *SCluster
|
||||
|
||||
ClusterId string
|
||||
CpuCores int
|
||||
CpuMax int
|
||||
CpuModel string
|
||||
CpuNode int
|
||||
CpuSockets int
|
||||
CpuUsed int
|
||||
DiskMax int
|
||||
DiskNode int
|
||||
DiskUsed int
|
||||
MemNode int
|
||||
MemoryMax int
|
||||
MemoryUsed int
|
||||
NodeId string
|
||||
NodeName string
|
||||
ScheduleTags string
|
||||
Status string
|
||||
}
|
||||
|
||||
func (self *SRegion) GetNodes(clusterId, nodeId string) ([]SNode, error) {
|
||||
params := map[string]string{}
|
||||
if len(clusterId) > 0 {
|
||||
params["clusterId"] = clusterId
|
||||
}
|
||||
if len(clusterId) > 0 {
|
||||
params["nodeId"] = nodeId
|
||||
}
|
||||
resp, err := self.invoke("DescribeNodes", params)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
ret := []SNode{}
|
||||
return ret, resp.Unmarshal(&ret, "nodeSet")
|
||||
}
|
||||
|
||||
func (self *SNode) GetId() string {
|
||||
return self.NodeId
|
||||
}
|
||||
|
||||
func (self *SNode) GetGlobalId() string {
|
||||
return self.NodeId
|
||||
}
|
||||
|
||||
func (self *SNode) GetName() string {
|
||||
return self.NodeName
|
||||
}
|
||||
|
||||
func (self *SNode) GetAccessIp() string {
|
||||
info := strings.Split(self.NodeId, "@")
|
||||
if len(info) == 2 {
|
||||
return info[1]
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
func (self *SNode) GetAccessMac() string {
|
||||
return ""
|
||||
}
|
||||
|
||||
func (self *SNode) GetSysInfo() jsonutils.JSONObject {
|
||||
return jsonutils.NewDict()
|
||||
}
|
||||
|
||||
func (self *SNode) GetSN() string {
|
||||
return ""
|
||||
}
|
||||
|
||||
func (self *SNode) GetCpuCount() int {
|
||||
return self.CpuNode
|
||||
}
|
||||
|
||||
func (self *SNode) GetNodeCount() int8 {
|
||||
return int8(self.CpuSockets)
|
||||
}
|
||||
|
||||
func (self *SNode) GetCpuDesc() string {
|
||||
return self.CpuModel
|
||||
}
|
||||
|
||||
func (self *SNode) GetCpuMhz() int {
|
||||
return 0
|
||||
}
|
||||
|
||||
func (self *SNode) GetCpuCmtbound() float32 {
|
||||
return 1
|
||||
}
|
||||
|
||||
func (self *SNode) GetMemSizeMB() int {
|
||||
return self.MemoryMax
|
||||
}
|
||||
|
||||
func (self *SNode) GetMemCmtbound() float32 {
|
||||
return 1
|
||||
}
|
||||
|
||||
func (self *SNode) GetReservedMemoryMb() int {
|
||||
return 0
|
||||
}
|
||||
|
||||
func (self *SNode) GetStorageSizeMB() int {
|
||||
return self.DiskMax * 1024
|
||||
}
|
||||
|
||||
func (self *SNode) GetStorageType() string {
|
||||
return api.STORAGE_LOCAL_SSD
|
||||
}
|
||||
|
||||
func (self *SNode) GetNodeType() string {
|
||||
return api.HOST_TYPE_BINGO_CLOUD
|
||||
}
|
||||
|
||||
func (self *SNode) CreateVM(desc *cloudprovider.SManagedVMCreateConfig) (cloudprovider.ICloudVM, error) {
|
||||
return nil, cloudprovider.ErrNotImplemented
|
||||
}
|
||||
|
||||
func (self *SNode) GetIStorages() ([]cloudprovider.ICloudStorage, error) {
|
||||
return self.cluster.GetIStorages()
|
||||
}
|
||||
|
||||
func (self *SNode) GetIStorageById(id string) (cloudprovider.ICloudStorage, error) {
|
||||
return self.cluster.GetIStorageById(id)
|
||||
}
|
||||
|
||||
func (self *SNode) GetEnabled() bool {
|
||||
return true
|
||||
}
|
||||
|
||||
func (self *SNode) GetNodeStatus() string {
|
||||
if self.Status == "available" {
|
||||
return api.HOST_ONLINE
|
||||
}
|
||||
return api.HOST_OFFLINE
|
||||
}
|
||||
|
||||
func (self *SNode) GetIHostNics() ([]cloudprovider.ICloudHostNetInterface, error) {
|
||||
return nil, cloudprovider.ErrNotImplemented
|
||||
}
|
||||
|
||||
func (self *SNode) GetIVMs() ([]cloudprovider.ICloudVM, error) {
|
||||
vms := []SInstance{}
|
||||
part, nextToken, err := self.cluster.region.GetInstances("", self.NodeId, MAX_RESULT, "")
|
||||
vms = append(vms, part...)
|
||||
for len(nextToken) > 0 {
|
||||
part, nextToken, err = self.cluster.region.GetInstances("", self.NodeId, MAX_RESULT, nextToken)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
vms = append(vms, part...)
|
||||
}
|
||||
ret := []cloudprovider.ICloudVM{}
|
||||
for i := range vms {
|
||||
vms[i].node = self
|
||||
ret = append(ret, &vms[i])
|
||||
}
|
||||
return ret, nil
|
||||
}
|
||||
|
||||
func (self *SNode) GetIVMById(id string) (cloudprovider.ICloudVM, error) {
|
||||
vms, _, err := self.cluster.region.GetInstances(id, self.NodeId, 1, "")
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
for i := range vms {
|
||||
if vms[i].GetGlobalId() == id {
|
||||
vms[i].node = self
|
||||
return &vms[i], nil
|
||||
}
|
||||
}
|
||||
return nil, cloudprovider.ErrNotFound
|
||||
}
|
||||
|
||||
func (self *SNode) GetIWires() ([]cloudprovider.ICloudWire, error) {
|
||||
return nil, cloudprovider.ErrNotImplemented
|
||||
}
|
||||
|
||||
func (self *SNode) GetSchedtags() ([]string, error) {
|
||||
return []string{}, nil
|
||||
}
|
||||
|
||||
func (self *SNode) GetIsMaintenance() bool {
|
||||
return self.Status == "maintain"
|
||||
}
|
||||
|
||||
func (self *SNode) GetVersion() string {
|
||||
return ""
|
||||
}
|
||||
|
||||
func (self *SNode) GetStatus() string {
|
||||
return api.HOST_STATUS_RUNNING
|
||||
}
|
||||
|
||||
func (self *SNode) GetHostStatus() string {
|
||||
if self.Status != "available" {
|
||||
return api.HOST_OFFLINE
|
||||
}
|
||||
return api.HOST_ONLINE
|
||||
}
|
||||
|
||||
func (self *SNode) GetHostType() string {
|
||||
return api.HOST_TYPE_BINGO_CLOUD
|
||||
}
|
||||
|
||||
func (self *SCluster) GetIHostById(id string) (cloudprovider.ICloudHost, error) {
|
||||
nodes, err := self.region.GetNodes(self.ClusterId, id)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
for i := range nodes {
|
||||
if nodes[i].GetGlobalId() == id {
|
||||
nodes[i].cluster = self
|
||||
return &nodes[i], nil
|
||||
}
|
||||
}
|
||||
return nil, errors.Wrapf(cloudprovider.ErrNotFound, id)
|
||||
}
|
||||
|
||||
func (self *SCluster) GetIHosts() ([]cloudprovider.ICloudHost, error) {
|
||||
nodes, err := self.region.GetNodes(self.ClusterId, "")
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
ret := []cloudprovider.ICloudHost{}
|
||||
for i := range nodes {
|
||||
nodes[i].cluster = self
|
||||
ret = append(ret, &nodes[i])
|
||||
}
|
||||
return ret, nil
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
// Copyright 2019 Yunion
|
||||
//
|
||||
// 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.
|
||||
|
||||
package shell
|
||||
|
||||
import (
|
||||
"yunion.io/x/onecloud/pkg/multicloud/bingocloud"
|
||||
"yunion.io/x/onecloud/pkg/util/shellutils"
|
||||
)
|
||||
|
||||
func init() {
|
||||
type ClusterListOptions struct {
|
||||
}
|
||||
shellutils.R(&ClusterListOptions{}, "cluster-list", "List clusters", func(cli *bingocloud.SRegion, args *ClusterListOptions) error {
|
||||
clusters, err := cli.GetClusters()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
printList(clusters, 0, 0, 0, nil)
|
||||
return nil
|
||||
})
|
||||
}
|
||||
@@ -22,10 +22,11 @@ import (
|
||||
func init() {
|
||||
type DiskListOptions struct {
|
||||
Id string
|
||||
MaxResult int
|
||||
NextToken string
|
||||
}
|
||||
shellutils.R(&DiskListOptions{}, "disk-list", "list disks", func(cli *bingocloud.SRegion, args *DiskListOptions) error {
|
||||
vms, _, err := cli.GetDisks(args.Id, args.NextToken)
|
||||
vms, _, err := cli.GetDisks(args.Id, args.MaxResult, args.NextToken)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -21,11 +21,12 @@ import (
|
||||
|
||||
func init() {
|
||||
type EipListOptions struct {
|
||||
Ip string
|
||||
NextToken string
|
||||
Ip string
|
||||
InstanceId string
|
||||
NextToken string
|
||||
}
|
||||
shellutils.R(&EipListOptions{}, "eip-list", "list eips", func(cli *bingocloud.SRegion, args *EipListOptions) error {
|
||||
eips, _, err := cli.GetEips(args.Ip, args.NextToken)
|
||||
eips, _, err := cli.GetEips(args.Ip, args.InstanceId, args.NextToken)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -22,12 +22,12 @@ import (
|
||||
func init() {
|
||||
type InstanceListOptions struct {
|
||||
Id string
|
||||
ZoneId string
|
||||
NodeId string
|
||||
MaxResult int
|
||||
NextToken string
|
||||
}
|
||||
shellutils.R(&InstanceListOptions{}, "instance-list", "list instances", func(cli *bingocloud.SRegion, args *InstanceListOptions) error {
|
||||
vms, _, err := cli.GetInstances(args.Id, args.ZoneId, args.MaxResult, args.NextToken)
|
||||
vms, _, err := cli.GetInstances(args.Id, args.NodeId, args.MaxResult, args.NextToken)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -0,0 +1,35 @@
|
||||
// Copyright 2019 Yunion
|
||||
//
|
||||
// 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.
|
||||
|
||||
package shell
|
||||
|
||||
import (
|
||||
"yunion.io/x/onecloud/pkg/multicloud/bingocloud"
|
||||
"yunion.io/x/onecloud/pkg/util/shellutils"
|
||||
)
|
||||
|
||||
func init() {
|
||||
type NodeListOptions struct {
|
||||
ClusterId string
|
||||
NodeId string
|
||||
}
|
||||
shellutils.R(&NodeListOptions{}, "node-list", "List nodes", func(cli *bingocloud.SRegion, args *NodeListOptions) error {
|
||||
nodes, err := cli.GetNodes(args.ClusterId, args.NodeId)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
printList(nodes, 0, 0, 0, nil)
|
||||
return nil
|
||||
})
|
||||
}
|
||||
@@ -26,7 +26,7 @@ import (
|
||||
type SStorage struct {
|
||||
multicloud.STagBase
|
||||
multicloud.SStorageBase
|
||||
zone *SZone
|
||||
cluster *SCluster
|
||||
|
||||
StorageId string `json:"storageId"`
|
||||
Location string `json:"location"`
|
||||
@@ -69,11 +69,11 @@ func (self *SStorage) DisableSync() bool {
|
||||
}
|
||||
|
||||
func (self *SStorage) GetIStoragecache() cloudprovider.ICloudStoragecache {
|
||||
return &SStoragecache{storageId: self.StorageId, storageName: self.StorageName, region: self.zone.region}
|
||||
return &SStoragecache{storageId: self.StorageId, storageName: self.StorageName, region: self.cluster.region}
|
||||
}
|
||||
|
||||
func (self *SStorage) GetIZone() cloudprovider.ICloudZone {
|
||||
return self.zone
|
||||
return self.cluster
|
||||
}
|
||||
|
||||
func (self *SStorage) GetStorageType() string {
|
||||
@@ -129,7 +129,7 @@ func (self *SRegion) GetStorages(nextToken string) ([]SStorage, string, error) {
|
||||
return ret.StorageSet, ret.NextToken, nil
|
||||
}
|
||||
|
||||
func (self *SZone) GetIStorageById(id string) (cloudprovider.ICloudStorage, error) {
|
||||
func (self *SCluster) GetIStorageById(id string) (cloudprovider.ICloudStorage, error) {
|
||||
storages, err := self.GetIStorages()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -142,14 +142,14 @@ func (self *SZone) GetIStorageById(id string) (cloudprovider.ICloudStorage, erro
|
||||
return nil, errors.Wrapf(cloudprovider.ErrNotFound, id)
|
||||
}
|
||||
|
||||
func (self *SZone) GetIStorages() ([]cloudprovider.ICloudStorage, error) {
|
||||
func (self *SCluster) GetIStorages() ([]cloudprovider.ICloudStorage, error) {
|
||||
storages, err := self.region.getStorages()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
ret := []cloudprovider.ICloudStorage{}
|
||||
for i := range storages {
|
||||
storages[i].zone = self
|
||||
storages[i].cluster = self
|
||||
ret = append(ret, &storages[i])
|
||||
}
|
||||
return ret, nil
|
||||
|
||||
@@ -28,12 +28,12 @@ type SWire struct {
|
||||
multicloud.STagBase
|
||||
multicloud.SResourceBase
|
||||
|
||||
zone *SZone
|
||||
vpc *SVpc
|
||||
cluster *SCluster
|
||||
vpc *SVpc
|
||||
}
|
||||
|
||||
func (self *SWire) GetId() string {
|
||||
return fmt.Sprintf("%s/%s", self.vpc.GetGlobalId(), self.zone.GetGlobalId())
|
||||
return fmt.Sprintf("%s/%s", self.vpc.GetGlobalId(), self.cluster.GetGlobalId())
|
||||
}
|
||||
|
||||
func (self *SWire) GetGlobalId() string {
|
||||
@@ -41,7 +41,7 @@ func (self *SWire) GetGlobalId() string {
|
||||
}
|
||||
|
||||
func (self *SWire) GetName() string {
|
||||
return fmt.Sprintf("%s-%s", self.vpc.GetName(), self.zone.GetName())
|
||||
return fmt.Sprintf("%s-%s", self.vpc.GetName(), self.cluster.GetName())
|
||||
}
|
||||
|
||||
func (self *SWire) GetBandwidth() int {
|
||||
@@ -61,7 +61,7 @@ func (self *SWire) IsEmulated() bool {
|
||||
}
|
||||
|
||||
func (self *SWire) GetIZone() cloudprovider.ICloudZone {
|
||||
return self.zone
|
||||
return self.cluster
|
||||
}
|
||||
|
||||
func (self *SVpc) GetIWireById(id string) (cloudprovider.ICloudWire, error) {
|
||||
@@ -78,15 +78,15 @@ func (self *SVpc) GetIWireById(id string) (cloudprovider.ICloudWire, error) {
|
||||
}
|
||||
|
||||
func (self *SVpc) GetIWires() ([]cloudprovider.ICloudWire, error) {
|
||||
zones, err := self.region.GetZones()
|
||||
clusters, err := self.region.GetClusters()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
ret := []cloudprovider.ICloudWire{}
|
||||
for i := range zones {
|
||||
for i := range clusters {
|
||||
wire := &SWire{
|
||||
vpc: self,
|
||||
zone: &zones[i],
|
||||
vpc: self,
|
||||
cluster: &clusters[i],
|
||||
}
|
||||
ret = append(ret, wire)
|
||||
}
|
||||
|
||||
@@ -14,51 +14,12 @@
|
||||
|
||||
package bingocloud
|
||||
|
||||
import (
|
||||
"yunion.io/x/pkg/errors"
|
||||
|
||||
api "yunion.io/x/onecloud/pkg/apis/compute"
|
||||
"yunion.io/x/onecloud/pkg/cloudprovider"
|
||||
"yunion.io/x/onecloud/pkg/multicloud"
|
||||
)
|
||||
|
||||
type SZone struct {
|
||||
multicloud.SResourceBase
|
||||
multicloud.STagBase
|
||||
|
||||
region *SRegion
|
||||
ZoneName string
|
||||
DisplayName string
|
||||
ZoneState string
|
||||
}
|
||||
|
||||
func (self *SZone) GetGlobalId() string {
|
||||
return self.ZoneName
|
||||
}
|
||||
|
||||
func (self *SZone) GetId() string {
|
||||
return self.ZoneName
|
||||
}
|
||||
|
||||
func (self *SZone) GetName() string {
|
||||
return self.DisplayName
|
||||
}
|
||||
|
||||
func (self *SZone) GetI18n() cloudprovider.SModelI18nTable {
|
||||
return cloudprovider.SModelI18nTable{}
|
||||
}
|
||||
|
||||
func (self *SZone) GetIRegion() cloudprovider.ICloudRegion {
|
||||
return self.region
|
||||
}
|
||||
|
||||
func (self *SZone) GetStatus() string {
|
||||
if self.ZoneState == "available" {
|
||||
return api.ZONE_ENABLE
|
||||
}
|
||||
return api.ZONE_DISABLE
|
||||
}
|
||||
|
||||
func (self *SRegion) GetZones() ([]SZone, error) {
|
||||
resp, err := self.invoke("DescribeAvailabilityZones", nil)
|
||||
if err != nil {
|
||||
@@ -67,29 +28,3 @@ func (self *SRegion) GetZones() ([]SZone, error) {
|
||||
ret := []SZone{}
|
||||
return ret, resp.Unmarshal(&ret, "availabilityZoneInfo")
|
||||
}
|
||||
|
||||
func (self *SRegion) GetIZones() ([]cloudprovider.ICloudZone, error) {
|
||||
zones, err := self.GetZones()
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(err, "GetZones")
|
||||
}
|
||||
ret := []cloudprovider.ICloudZone{}
|
||||
for i := range zones {
|
||||
zones[i].region = self
|
||||
ret = append(ret, &zones[i])
|
||||
}
|
||||
return ret, nil
|
||||
}
|
||||
|
||||
func (self *SRegion) GetIZoneById(id string) (cloudprovider.ICloudZone, error) {
|
||||
zones, err := self.GetIZones()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
for i := range zones {
|
||||
if zones[i].GetGlobalId() == id {
|
||||
return zones[i], nil
|
||||
}
|
||||
}
|
||||
return nil, errors.Wrapf(cloudprovider.ErrNotFound, id)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user