mirror of
https://github.com/yunionio/cloudpods.git
synced 2026-09-19 02:37:24 +08:00
fix(region): vendor update (#20910)
This commit is contained in:
@@ -89,7 +89,7 @@ require (
|
||||
k8s.io/cluster-bootstrap v0.19.3
|
||||
k8s.io/cri-api v0.22.17
|
||||
moul.io/http2curl/v2 v2.3.0
|
||||
yunion.io/x/cloudmux v0.3.10-0-alpha.1.0.20240712080010-b184d0ecc090
|
||||
yunion.io/x/cloudmux v0.3.10-0-alpha.1.0.20240729040017-1941639e1510
|
||||
yunion.io/x/executor v0.0.0-20230705125604-c5ac3141db32
|
||||
yunion.io/x/jsonutils v1.0.1-0.20240203102553-4096f103b401
|
||||
yunion.io/x/log v1.0.1-0.20240305175729-7cf2d6cd5a91
|
||||
|
||||
@@ -758,8 +758,6 @@ github.com/yuin/goldmark v1.3.5/go.mod h1:mwnBkeHKe2W/ZEtQ+71ViKU8L12m81fl3OWwC1
|
||||
github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY=
|
||||
github.com/yusufpapurcu/wmi v1.2.2 h1:KBNDSne4vP5mbSWnJbO+51IMOXJB67QiYCSBrubbPRg=
|
||||
github.com/yusufpapurcu/wmi v1.2.2/go.mod h1:SBZ9tNy3G9/m5Oi98Zks0QjeHVDvuK0qfxQmPyzfmi0=
|
||||
github.com/zexi/influxql-to-metricsql v0.0.6 h1:E16T4oqgjIJtSNVvhGGHnw+pmY3yGz2iRsmmmSVuOpY=
|
||||
github.com/zexi/influxql-to-metricsql v0.0.6/go.mod h1:PyRRM+3Zrzzig6J4okYLeSv+/d+5GaL5ccBaUKQABNs=
|
||||
github.com/zexi/influxql-to-metricsql v0.0.7 h1:t2Kp6neknnOnszNl3mLteK4dSmXWglfI1JYUtRWTmyQ=
|
||||
github.com/zexi/influxql-to-metricsql v0.0.7/go.mod h1:PyRRM+3Zrzzig6J4okYLeSv+/d+5GaL5ccBaUKQABNs=
|
||||
go.etcd.io/etcd/api/v3 v3.5.0 h1:GsV3S+OfZEOCNXdtNkBSR7kgLobAa/SO6tCxRa0GAYw=
|
||||
@@ -1217,8 +1215,8 @@ sigs.k8s.io/structured-merge-diff/v4 v4.0.1/go.mod h1:bJZC9H9iH24zzfZ/41RGcq60oK
|
||||
sigs.k8s.io/yaml v1.1.0/go.mod h1:UJmg0vDUVViEyp3mgSv9WPwZCDxu4rQW1olrI1uml+o=
|
||||
sigs.k8s.io/yaml v1.2.0 h1:kr/MCeFWJWTwyaHoR9c8EjH9OumOmoF9YGiZd7lFm/Q=
|
||||
sigs.k8s.io/yaml v1.2.0/go.mod h1:yfXDCHCao9+ENCvLSE62v9VSji2MKu5jeNfTrofGhJc=
|
||||
yunion.io/x/cloudmux v0.3.10-0-alpha.1.0.20240712080010-b184d0ecc090 h1:/07EdD/RSJNFMJb/kDQCms5D5MZ8x2xH2P2eMKYUC/Y=
|
||||
yunion.io/x/cloudmux v0.3.10-0-alpha.1.0.20240712080010-b184d0ecc090/go.mod h1:iLoBHVR2Eur/1WJSGcbZaEwpzh/iqXvbFCsX9/xt8CI=
|
||||
yunion.io/x/cloudmux v0.3.10-0-alpha.1.0.20240729040017-1941639e1510 h1:mvVVQLyDUHMl0hRfli+GuFtwN5mu9fXEDcdwd59i5Rs=
|
||||
yunion.io/x/cloudmux v0.3.10-0-alpha.1.0.20240729040017-1941639e1510/go.mod h1:iLoBHVR2Eur/1WJSGcbZaEwpzh/iqXvbFCsX9/xt8CI=
|
||||
yunion.io/x/executor v0.0.0-20230705125604-c5ac3141db32 h1:v7POYkQwo1XzOxBoIoRVr/k0V9Y5JyjpshlIFa9raug=
|
||||
yunion.io/x/executor v0.0.0-20230705125604-c5ac3141db32/go.mod h1:Uxuou9WQIeJXNpy7t2fPLL0BYLvLiMvGQwY7Qc6aSws=
|
||||
yunion.io/x/jsonutils v0.0.0-20190625054549-a964e1e8a051/go.mod h1:4N0/RVzsYL3kH3WE/H1BjUQdFiWu50JGCFQuuy+Z634=
|
||||
|
||||
@@ -45,3 +45,8 @@ func SetupTest() {
|
||||
key, _ := rsa.GenerateKey(rand.Reader, 2048)
|
||||
setPrivateKey(key)
|
||||
}
|
||||
|
||||
type SApigatewayApi struct {
|
||||
Id string
|
||||
Name string
|
||||
}
|
||||
|
||||
Vendored
+1
-1
@@ -1489,7 +1489,7 @@ sigs.k8s.io/structured-merge-diff/v4/value
|
||||
# sigs.k8s.io/yaml v1.2.0
|
||||
## explicit; go 1.12
|
||||
sigs.k8s.io/yaml
|
||||
# yunion.io/x/cloudmux v0.3.10-0-alpha.1.0.20240712080010-b184d0ecc090
|
||||
# yunion.io/x/cloudmux v0.3.10-0-alpha.1.0.20240729040017-1941639e1510
|
||||
## explicit; go 1.18
|
||||
yunion.io/x/cloudmux/pkg/apis
|
||||
yunion.io/x/cloudmux/pkg/apis/billing
|
||||
|
||||
+6
-1
@@ -157,7 +157,12 @@ func (self *SGlobalLoadbalancer) GetAddress() string {
|
||||
return ""
|
||||
}
|
||||
|
||||
if self.isNameMatch(target) {
|
||||
match, err := self.isNameMatch(target)
|
||||
if err != nil {
|
||||
log.Errorf("isNameMatch error: %v", err)
|
||||
continue
|
||||
}
|
||||
if match {
|
||||
return item.IPAddress
|
||||
}
|
||||
}
|
||||
|
||||
Generated
Vendored
+11
-4
@@ -48,7 +48,7 @@ type SGlobalInstanceGroupInstance struct {
|
||||
NamedPorts []NamedPort `json:"namedPorts"`
|
||||
}
|
||||
|
||||
func (self *SGlobalLoadbalancer) isNameMatch(target interface{}) bool {
|
||||
func (self *SGlobalLoadbalancer) isNameMatch(target interface{}) (bool, error) {
|
||||
var name string
|
||||
switch t := target.(type) {
|
||||
case *STargetHttpProxy, *STargetHttpsProxy:
|
||||
@@ -59,7 +59,10 @@ func (self *SGlobalLoadbalancer) isNameMatch(target interface{}) bool {
|
||||
case *STargetHttpsProxy:
|
||||
URLMapUrl = t.(*STargetHttpsProxy).URLMap
|
||||
}
|
||||
urlMapResponse, _ := _jsonRequest(self.region.client.client, "GET", URLMapUrl, nil, false)
|
||||
urlMapResponse, err := _jsonRequest(self.region.client.client, "GET", URLMapUrl, nil, false)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
var urlMap SUrlMap
|
||||
urlMapResponse.Unmarshal(&urlMap)
|
||||
name = urlMap.Name
|
||||
@@ -71,7 +74,7 @@ func (self *SGlobalLoadbalancer) isNameMatch(target interface{}) bool {
|
||||
parts := strings.Split(t.Service, "/")
|
||||
name = parts[len(parts)-1]
|
||||
}
|
||||
return name == self.GetName()
|
||||
return name == self.GetName(), nil
|
||||
}
|
||||
|
||||
func (self *SGlobalLoadbalancer) GetForwardingRules() ([]SForwardingRule, error) {
|
||||
@@ -103,7 +106,11 @@ func (self *SGlobalLoadbalancer) GetForwardingRules() ([]SForwardingRule, error)
|
||||
return nil, errors.Wrap(err, "getGlobalAddress.target.Unmarshal")
|
||||
}
|
||||
|
||||
if self.isNameMatch(target) {
|
||||
match, err := self.isNameMatch(target)
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(err, "isNameMatch")
|
||||
}
|
||||
if match {
|
||||
_ret = append(_ret, item)
|
||||
}
|
||||
}
|
||||
|
||||
+4
-37
@@ -94,11 +94,6 @@ func (self *SHost) _createVM(name, hostname string, imgId string, sysDisk cloudp
|
||||
return "", fmt.Errorf("image %s not ready status is %s", imgId, img.ImageState)
|
||||
}
|
||||
|
||||
err = self.zone.validateStorageType(sysDisk.StorageType)
|
||||
if err != nil {
|
||||
return "", fmt.Errorf("Storage %s not avaiable: %s", sysDisk.StorageType, err)
|
||||
}
|
||||
|
||||
disks := make([]SDisk, len(diskSizes)+1)
|
||||
disks[0].DiskSize = img.ImageSize
|
||||
if sysDisk.SizeGB > 0 && sysDisk.SizeGB > img.ImageSize {
|
||||
@@ -111,43 +106,15 @@ func (self *SHost) _createVM(name, hostname string, imgId string, sysDisk cloudp
|
||||
|
||||
for i, dataDisk := range diskSizes {
|
||||
disks[i+1].DiskSize = dataDisk.SizeGB
|
||||
err = self.zone.validateStorageType(dataDisk.StorageType)
|
||||
if err != nil {
|
||||
return "", fmt.Errorf("Storage %s not avaiable: %s", dataDisk.StorageType, err)
|
||||
}
|
||||
disks[i+1].DiskType = strings.ToUpper(dataDisk.StorageType)
|
||||
}
|
||||
|
||||
if len(instanceType) > 0 {
|
||||
log.Debugf("Try instancetype : %s", instanceType)
|
||||
vmId, err := self.zone.region.CreateInstance(name, hostname, imgId, instanceType, secgroupIds, self.zone.Zone, desc, passwd, disks, networkId, ipAddr, keypair, userData, bc, projectId, publicIpBw, publicIpChargeType, tags, osType)
|
||||
if err != nil {
|
||||
return "", errors.Wrapf(err, "Failed to create specification %s", instanceType)
|
||||
}
|
||||
return vmId, nil
|
||||
}
|
||||
|
||||
instanceTypes, err := self.zone.region.GetMatchInstanceTypes(cpu, memMB, 0, self.zone.Zone)
|
||||
log.Debugf("Try instancetype : %s", instanceType)
|
||||
vmId, err := self.zone.region.CreateInstance(name, hostname, imgId, instanceType, secgroupIds, self.zone.Zone, desc, passwd, disks, networkId, ipAddr, keypair, userData, bc, projectId, publicIpBw, publicIpChargeType, tags, osType)
|
||||
if err != nil {
|
||||
return "", err
|
||||
return "", errors.Wrapf(err, "Failed to create specification %s", instanceType)
|
||||
}
|
||||
if len(instanceTypes) == 0 {
|
||||
return "", fmt.Errorf("instance type %dC%dMB not avaiable", cpu, memMB)
|
||||
}
|
||||
|
||||
var vmId string
|
||||
for _, instType := range instanceTypes {
|
||||
instanceTypeId := instType.InstanceType
|
||||
log.Debugf("Try instancetype : %s", instanceTypeId)
|
||||
vmId, err = self.zone.region.CreateInstance(name, hostname, imgId, instanceTypeId, secgroupIds, self.zone.Zone, desc, passwd, disks, networkId, ipAddr, keypair, userData, bc, projectId, publicIpBw, publicIpChargeType, tags, osType)
|
||||
if err != nil {
|
||||
log.Errorf("Failed for %s: %s", instanceTypeId, err)
|
||||
} else {
|
||||
return vmId, nil
|
||||
}
|
||||
}
|
||||
|
||||
return "", fmt.Errorf("Failed to create, %s", err.Error())
|
||||
return vmId, nil
|
||||
}
|
||||
|
||||
func (self *SHost) Refresh() error {
|
||||
|
||||
+2
-28
@@ -492,34 +492,8 @@ func (self *SInstance) RebuildRoot(ctx context.Context, desc *cloudprovider.SMan
|
||||
return instance.SystemDisk.DiskId, nil
|
||||
}
|
||||
|
||||
func (self *SInstance) ChangeConfig(ctx context.Context, config *cloudprovider.SManagedVMChangeConfig) error {
|
||||
instanceTypes := []string{}
|
||||
if len(config.InstanceType) > 0 {
|
||||
instanceTypes = []string{config.InstanceType}
|
||||
} else {
|
||||
specs, err := self.host.zone.region.GetMatchInstanceTypes(config.Cpu, config.MemoryMB, 0, self.Placement.Zone)
|
||||
if err != nil {
|
||||
return errors.Wrapf(err, "GetMatchInstanceTypes")
|
||||
}
|
||||
for _, spec := range specs {
|
||||
instanceTypes = append(instanceTypes, spec.InstanceType)
|
||||
}
|
||||
}
|
||||
|
||||
var err error
|
||||
for _, instanceType := range instanceTypes {
|
||||
err = self.host.zone.region.ChangeVMConfig(self.InstanceId, instanceType)
|
||||
if err != nil {
|
||||
log.Errorf("ChangeConfig for %s with %s error: %v", self.InstanceId, instanceType, err)
|
||||
continue
|
||||
}
|
||||
return nil
|
||||
}
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return fmt.Errorf("Failed to change vm config, specification not supported")
|
||||
func (self *SInstance) ChangeConfig(ctx context.Context, opts *cloudprovider.SManagedVMChangeConfig) error {
|
||||
return self.host.zone.region.ChangeVMConfig(self.InstanceId, opts.InstanceType)
|
||||
}
|
||||
|
||||
func (self *SInstance) AttachDisk(ctx context.Context, diskId string) error {
|
||||
|
||||
+2
-2
@@ -110,11 +110,11 @@ func (self *SRegion) GetZoneInstanceTypes(zoneId string) ([]SZoneInstanceType, e
|
||||
}
|
||||
|
||||
func (self *SRegion) GetZoneLocalStorages(zoneId string) ([]string, error) {
|
||||
storages := []string{}
|
||||
instanceTypes, err := self.GetZoneInstanceTypes(zoneId)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "GetZoneInstanceTypes")
|
||||
return storages, errors.Wrap(err, "GetZoneInstanceTypes")
|
||||
}
|
||||
storages := []string{}
|
||||
for _, instanceType := range instanceTypes {
|
||||
storage := instanceType.Externals.StorageBlockAttr.Type
|
||||
if len(storage) > 0 && !utils.IsInStringArray(storage, storages) {
|
||||
|
||||
+4
-1
@@ -374,7 +374,10 @@ func _baseJsonRequest(client *common.Client, req tchttp.Request, resp qcloudResp
|
||||
return nil, errors.Wrapf(cloudprovider.ErrNotFound, err.Error())
|
||||
}
|
||||
|
||||
if e.Code == "UnsupportedRegion" {
|
||||
if utils.IsInStringArray(e.Code, []string{
|
||||
"InvalidParameterValue.ZoneNotSupported",
|
||||
"UnsupportedRegion",
|
||||
}) {
|
||||
return nil, cloudprovider.ErrNotSupported
|
||||
}
|
||||
if e.Code == "InvalidParameterValue" && apiName == "GetMonitorData" && strings.Contains(e.Message, "the instance has been destroyed") {
|
||||
|
||||
+31
-29
@@ -332,6 +332,15 @@ func (self *SRegion) GetIZones() ([]cloudprovider.ICloudZone, error) {
|
||||
return ret, nil
|
||||
}
|
||||
|
||||
func getReplaceKey(zoneId string) string {
|
||||
replceKey := map[string]string{"1": "一", "2": "二", "3": "三", "4": "四", "5": "五", "6": "六", "7": "七", "8": "八", "9": "九"}
|
||||
info := strings.Split(zoneId, "-")
|
||||
if len(info) >= 3 {
|
||||
return replceKey[info[len(info)-1]]
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
func (self *SRegion) GetZones() ([]SZone, error) {
|
||||
body, err := self.cvmRequest("DescribeZones", map[string]string{}, true)
|
||||
if err != nil {
|
||||
@@ -342,8 +351,30 @@ func (self *SRegion) GetZones() ([]SZone, error) {
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
zoneName, zoneNameReplace := "", ""
|
||||
zoneMap := map[string]bool{}
|
||||
for i := 0; i < len(zones); i++ {
|
||||
if len(zoneName) == 0 {
|
||||
zoneName = zones[i].ZoneName
|
||||
zoneNameReplace = getReplaceKey(zones[i].Zone)
|
||||
}
|
||||
zones[i].region = self
|
||||
zoneMap[zones[i].Zone] = true
|
||||
}
|
||||
networks, err := self.GetNetworks(nil, "", "")
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(err, "GetNetworks")
|
||||
}
|
||||
for _, network := range networks {
|
||||
if _, ok := zoneMap[network.Zone]; !ok {
|
||||
zoneMap[network.Zone] = true
|
||||
zone := SZone{region: self, Zone: network.Zone, ZoneState: "Unknown"}
|
||||
newKey := getReplaceKey(network.Zone)
|
||||
if len(zoneNameReplace) > 0 && len(newKey) > 0 {
|
||||
zone.ZoneName = strings.Replace(zoneName, zoneNameReplace, newKey, 1)
|
||||
}
|
||||
zones = append(zones, zone)
|
||||
}
|
||||
}
|
||||
return zones, nil
|
||||
}
|
||||
@@ -569,35 +600,6 @@ func (self *SRegion) getStoragecache() *SStoragecache {
|
||||
return self.storageCache
|
||||
}
|
||||
|
||||
func (self *SRegion) GetMatchInstanceTypes(cpu int, memMB int, gpu int, zoneId string) ([]SInstanceType, error) {
|
||||
if self.instanceTypes == nil {
|
||||
types, err := self.GetInstanceTypes()
|
||||
if err != nil {
|
||||
log.Errorf("GetInstanceTypes %s", err)
|
||||
return nil, err
|
||||
}
|
||||
self.instanceTypes = types
|
||||
}
|
||||
|
||||
var available []string
|
||||
if len(zoneId) > 0 {
|
||||
zone, err := self.getZoneById(zoneId)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
available = zone.getAvaliableInstanceTypes()
|
||||
}
|
||||
ret := make([]SInstanceType, 0)
|
||||
for _, t := range self.instanceTypes {
|
||||
if t.CPU == cpu && memMB == t.memoryMB() && gpu == t.GPU {
|
||||
if available == nil || utils.IsInStringArray(t.InstanceType, available) {
|
||||
ret = append(ret, t)
|
||||
}
|
||||
}
|
||||
}
|
||||
return ret, nil
|
||||
}
|
||||
|
||||
func (self *SRegion) CreateInstanceSimple(name string, imgId string, cpu int, memGB int, storageType string, dataDiskSizesGB []int, networkId string, passwd string, publicKey string, secgroup string, tags map[string]string) (*SInstance, error) {
|
||||
zones, err := self.GetZones()
|
||||
if err != nil {
|
||||
|
||||
+33
-106
@@ -17,9 +17,7 @@ package qcloud
|
||||
import (
|
||||
"fmt"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"yunion.io/x/log"
|
||||
"yunion.io/x/pkg/errors"
|
||||
"yunion.io/x/pkg/utils"
|
||||
|
||||
@@ -44,13 +42,6 @@ type SZone struct {
|
||||
|
||||
host *SHost
|
||||
|
||||
istorages []cloudprovider.ICloudStorage
|
||||
|
||||
instanceTypes []string
|
||||
refreshTime time.Time
|
||||
localstorages []string
|
||||
cloudstorages []string
|
||||
|
||||
Zone string
|
||||
ZoneName string
|
||||
ZoneState string
|
||||
@@ -61,7 +52,10 @@ func (self *SZone) GetId() string {
|
||||
}
|
||||
|
||||
func (self *SZone) GetName() string {
|
||||
return self.ZoneName
|
||||
if len(self.ZoneName) > 0 {
|
||||
return self.ZoneName
|
||||
}
|
||||
return self.Zone
|
||||
}
|
||||
|
||||
func (self *SZone) GetI18n() cloudprovider.SModelI18nTable {
|
||||
@@ -75,15 +69,6 @@ func (self *SZone) GetGlobalId() string {
|
||||
return fmt.Sprintf("%s/%s", self.region.GetGlobalId(), self.Zone)
|
||||
}
|
||||
|
||||
func (self *SZone) IsEmulated() bool {
|
||||
return false
|
||||
}
|
||||
|
||||
func (self *SZone) Refresh() error {
|
||||
// do nothing
|
||||
return nil
|
||||
}
|
||||
|
||||
func (self *SZone) GetStatus() string {
|
||||
if self.ZoneState == "AVAILABLE" {
|
||||
return api.ZONE_ENABLE
|
||||
@@ -139,80 +124,55 @@ func (self *SRegion) GetDiskConfigSet(zoneName string) ([]SDiskConfigSet, error)
|
||||
return diskConfigSet, body.Unmarshal(&diskConfigSet, "DiskConfigSet")
|
||||
}
|
||||
|
||||
func (self *SZone) fetchStorages() error {
|
||||
self.istorages = []cloudprovider.ICloudStorage{}
|
||||
func (self *SZone) GetIStorages() ([]cloudprovider.ICloudStorage, error) {
|
||||
ret := []cloudprovider.ICloudStorage{}
|
||||
diskConfigSet, err := self.region.GetDiskConfigSet(self.Zone)
|
||||
if err != nil {
|
||||
return err
|
||||
return nil, err
|
||||
}
|
||||
self.cloudstorages = []string{}
|
||||
cloudstorages := []string{}
|
||||
for _, diskConfig := range diskConfigSet {
|
||||
if !utils.IsInStringArray(strings.ToUpper(diskConfig.DiskType), self.cloudstorages) {
|
||||
self.cloudstorages = append(self.cloudstorages, strings.ToUpper(diskConfig.DiskType))
|
||||
storage := SStorage{zone: self, storageType: diskConfig.DiskType, available: diskConfig.Available}
|
||||
self.istorages = append(self.istorages, &storage)
|
||||
if !utils.IsInStringArray(strings.ToUpper(diskConfig.DiskType), cloudstorages) {
|
||||
cloudstorages = append(cloudstorages, strings.ToUpper(diskConfig.DiskType))
|
||||
storage := &SStorage{zone: self, storageType: diskConfig.DiskType, available: diskConfig.Available}
|
||||
ret = append(ret, storage)
|
||||
}
|
||||
}
|
||||
for _, storageType := range []string{"CLOUD_PREMIUM", "CLOUD_SSD", "CLOUD_BASIC"} {
|
||||
if !utils.IsInStringArray(storageType, self.cloudstorages) {
|
||||
self.cloudstorages = append(self.cloudstorages, storageType)
|
||||
if !utils.IsInStringArray(storageType, cloudstorages) {
|
||||
cloudstorages = append(cloudstorages, storageType)
|
||||
storage := SStorage{zone: self, storageType: storageType, available: false}
|
||||
self.istorages = append(self.istorages, &storage)
|
||||
ret = append(ret, &storage)
|
||||
}
|
||||
}
|
||||
self.localstorages, err = self.region.GetZoneLocalStorages(self.Zone)
|
||||
if err != nil {
|
||||
log.Errorf("falied to fetch local storage for zone %s", self.Zone)
|
||||
localstorages, err := self.region.GetZoneLocalStorages(self.Zone)
|
||||
if err != nil && errors.Cause(err) != cloudprovider.ErrNotSupported {
|
||||
return nil, errors.Wrapf(err, "GetZoneLocalStorages")
|
||||
}
|
||||
for _, localstorageType := range self.localstorages {
|
||||
for _, localstorageType := range localstorages {
|
||||
storage := SLocalStorage{zone: self, storageType: localstorageType, available: true}
|
||||
self.istorages = append(self.istorages, &storage)
|
||||
ret = append(ret, &storage)
|
||||
}
|
||||
for _, storageType := range QCLOUD_LOCAL_STORAGE_TYPES {
|
||||
if !utils.IsInStringArray(storageType, self.localstorages) {
|
||||
if !utils.IsInStringArray(storageType, localstorages) {
|
||||
storage := SLocalStorage{zone: self, storageType: storageType, available: false}
|
||||
self.istorages = append(self.istorages, &storage)
|
||||
ret = append(ret, &storage)
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (self *SZone) GetIStorages() ([]cloudprovider.ICloudStorage, error) {
|
||||
if self.istorages == nil {
|
||||
err := self.fetchStorages()
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(err, "fetchStorages")
|
||||
}
|
||||
}
|
||||
return self.istorages, nil
|
||||
return ret, nil
|
||||
}
|
||||
|
||||
func (self *SZone) getLocalStorageByCategory(category string) (*SLocalStorage, error) {
|
||||
if len(self.localstorages) == 0 {
|
||||
err := self.fetchStorages()
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "fetchStorages")
|
||||
}
|
||||
localstorages, err := self.region.GetZoneLocalStorages(self.Zone)
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(err, "GetZoneLocalStorages")
|
||||
}
|
||||
if utils.IsInStringArray(strings.ToUpper(category), self.localstorages) {
|
||||
if utils.IsInStringArray(strings.ToUpper(category), localstorages) {
|
||||
return &SLocalStorage{zone: self, storageType: strings.ToUpper(category)}, nil
|
||||
}
|
||||
return nil, fmt.Errorf("No such storage %s", category)
|
||||
}
|
||||
|
||||
func (self *SZone) validateStorageType(category string) error {
|
||||
if len(self.localstorages) == 0 || len(self.cloudstorages) == 0 {
|
||||
err := self.fetchStorages()
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "fetchStorages")
|
||||
}
|
||||
}
|
||||
if utils.IsInStringArray(strings.ToUpper(category), self.localstorages) || utils.IsInStringArray(strings.ToUpper(category), self.cloudstorages) {
|
||||
return nil
|
||||
}
|
||||
return fmt.Errorf("No such storage %s", category)
|
||||
}
|
||||
|
||||
func (self *SZone) getStorageByCategory(category string) (*SStorage, error) {
|
||||
storages, err := self.GetIStorages()
|
||||
if err != nil {
|
||||
@@ -231,15 +191,13 @@ func (self *SZone) getStorageByCategory(category string) (*SStorage, error) {
|
||||
}
|
||||
|
||||
func (self *SZone) GetIStorageById(id string) (cloudprovider.ICloudStorage, error) {
|
||||
if self.istorages == nil {
|
||||
err := self.fetchStorages()
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(err, "fetchStorages")
|
||||
}
|
||||
storages, err := self.GetIStorages()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
for i := 0; i < len(self.istorages); i += 1 {
|
||||
if self.istorages[i].GetGlobalId() == id {
|
||||
return self.istorages[i], nil
|
||||
for i := 0; i < len(storages); i += 1 {
|
||||
if storages[i].GetGlobalId() == id {
|
||||
return storages[i], nil
|
||||
}
|
||||
}
|
||||
return nil, cloudprovider.ErrNotFound
|
||||
@@ -258,37 +216,6 @@ func (self *SZone) GetIWires() ([]cloudprovider.ICloudWire, error) {
|
||||
return ret, nil
|
||||
}
|
||||
|
||||
func (self *SZone) fetchInstanceTypes() {
|
||||
self.instanceTypes = []string{}
|
||||
params := map[string]string{}
|
||||
params["Region"] = self.region.Region
|
||||
params["Filters.0.Name"] = "zone"
|
||||
params["Filters.0.Values.0"] = self.Zone
|
||||
if body, err := self.region.cvmRequest("DescribeInstanceTypeConfigs", params, true); err != nil {
|
||||
log.Errorf("DescribeInstanceTypeConfigs error: %v", err)
|
||||
} else if configSet, err := body.GetArray("InstanceTypeConfigSet"); err != nil {
|
||||
log.Errorf("Get InstanceTypeConfigSet error: %v", err)
|
||||
} else {
|
||||
for _, config := range configSet {
|
||||
if instanceType, err := config.GetString("InstanceType"); err == nil && !utils.IsInStringArray(instanceType, self.instanceTypes) {
|
||||
self.instanceTypes = append(self.instanceTypes, instanceType)
|
||||
}
|
||||
}
|
||||
self.refreshTime = time.Now()
|
||||
}
|
||||
}
|
||||
|
||||
func (self *SZone) getAvaliableInstanceTypes() []string {
|
||||
if self.instanceTypes == nil || len(self.instanceTypes) == 0 || time.Now().Sub(self.refreshTime).Hours() > refreshHours() {
|
||||
self.fetchInstanceTypes()
|
||||
}
|
||||
return self.instanceTypes
|
||||
}
|
||||
|
||||
func refreshHours() float64 {
|
||||
return 5
|
||||
}
|
||||
|
||||
func (self *SZone) getCosEndpoint() string {
|
||||
return fmt.Sprintf("cos.%s.myqcloud.com", self.GetId())
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user