fix(region): vender update

This commit is contained in:
ioito
2022-11-11 11:05:50 +08:00
parent 6173bffe87
commit 02875a31e6
6 changed files with 31 additions and 17 deletions
+1 -1
View File
@@ -83,7 +83,7 @@ require (
k8s.io/client-go v0.19.3
k8s.io/cluster-bootstrap v0.19.3
moul.io/http2curl/v2 v2.3.0
yunion.io/x/cloudmux v0.3.10-0-alpha.1.0.20221110030606-998da89d7f4d
yunion.io/x/cloudmux v0.3.10-0-alpha.1.0.20221111025915-ff307c592d7d
yunion.io/x/executor v0.0.0-20211018100936-39a2cd966656
yunion.io/x/jsonutils v1.0.1-0.20220819091305-3bab322ab4fd
yunion.io/x/log v1.0.0
+2 -2
View File
@@ -1162,8 +1162,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.20221110030606-998da89d7f4d h1:4Q3DFKvkGmuYH9AcNWVSy690SIBwkszFAwwwLr13Tlk=
yunion.io/x/cloudmux v0.3.10-0-alpha.1.0.20221110030606-998da89d7f4d/go.mod h1:drc/WDD65r6wI1tSejk19xcl9QwmzZlgJGXN7a9o2KQ=
yunion.io/x/cloudmux v0.3.10-0-alpha.1.0.20221111025915-ff307c592d7d h1:4+xSygGpc2iehPhHjz3WRYnPt0ZrQIAlDTk44iVjJuk=
yunion.io/x/cloudmux v0.3.10-0-alpha.1.0.20221111025915-ff307c592d7d/go.mod h1:drc/WDD65r6wI1tSejk19xcl9QwmzZlgJGXN7a9o2KQ=
yunion.io/x/executor v0.0.0-20211018100936-39a2cd966656 h1:0zlZD5uhZoIHgLVAWCz2aHaYk2ZrNsACCYD7R6EIBII=
yunion.io/x/executor v0.0.0-20211018100936-39a2cd966656/go.mod h1:Uxuou9WQIeJXNpy7t2fPLL0BYLvLiMvGQwY7Qc6aSws=
yunion.io/x/jsonutils v0.0.0-20190625054549-a964e1e8a051/go.mod h1:4N0/RVzsYL3kH3WE/H1BjUQdFiWu50JGCFQuuy+Z634=
+1 -1
View File
@@ -1428,7 +1428,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.20221110030606-998da89d7f4d
# yunion.io/x/cloudmux v0.3.10-0-alpha.1.0.20221111025915-ff307c592d7d
## explicit; go 1.18
yunion.io/x/cloudmux/pkg/apis
yunion.io/x/cloudmux/pkg/apis/billing
+7 -4
View File
@@ -18,6 +18,7 @@ import (
"fmt"
"net/http"
"strings"
"sync"
"time"
"yunion.io/x/log"
@@ -46,7 +47,7 @@ const (
HUAWEI_API_VERSION = ""
)
var HUAWEI_REGION_CACHES = map[string]userRegionsCache{}
var HUAWEI_REGION_CACHES sync.Map
type userRegionsCache struct {
UserId string
@@ -202,17 +203,19 @@ func (self *SHuaweiClient) fetchRegions() error {
return errors.Wrap(err, "GetUserId")
}
if regionsCache, ok := HUAWEI_REGION_CACHES[userId]; !ok || regionsCache.ExpireAt.Sub(time.Now()).Seconds() > 0 {
if regionsCache, ok := HUAWEI_REGION_CACHES.Load(userId); !ok || regionsCache.(*userRegionsCache).ExpireAt.Sub(time.Now()).Seconds() > 0 {
regions := make([]SRegion, 0)
err := doListAll(huawei.Regions.List, nil, &regions)
if err != nil {
return errors.Wrap(err, "Regions.List")
}
HUAWEI_REGION_CACHES[userId] = userRegionsCache{ExpireAt: time.Now().Add(24 * time.Hour), UserId: userId, Regions: regions}
HUAWEI_REGION_CACHES.Store(userId, &userRegionsCache{ExpireAt: time.Now().Add(24 * time.Hour), UserId: userId, Regions: regions})
}
self.regions = HUAWEI_REGION_CACHES[userId].Regions
if regionsCache, ok := HUAWEI_REGION_CACHES.Load(userId); ok {
self.regions = regionsCache.(*userRegionsCache).Regions
}
}
filtedRegions := make([]SRegion, 0)
+4 -2
View File
@@ -23,12 +23,14 @@ import (
func (self *SRemoteFileClient) GetMetrics(opts *cloudprovider.MetricListOptions) ([]cloudprovider.MetricValues, error) {
switch opts.ResourceType {
case cloudprovider.METRIC_RESOURCE_TYPE_SERVER:
return self.GetEcsMetrics(opts)
return self.GetRemoteMetrics(opts)
case cloudprovider.METRIC_RESOURCE_TYPE_RDS:
return self.GetRemoteMetrics(opts)
default:
return nil, errors.Wrapf(cloudprovider.ErrNotImplemented, "%s", opts.ResourceType)
}
}
func (self *SRemoteFileClient) GetEcsMetrics(opts *cloudprovider.MetricListOptions) ([]cloudprovider.MetricValues, error) {
func (self *SRemoteFileClient) GetRemoteMetrics(opts *cloudprovider.MetricListOptions) ([]cloudprovider.MetricValues, error) {
return self.getMetrics(opts.ResourceType, opts.MetricType)
}
+16 -7
View File
@@ -18,6 +18,7 @@ import (
"context"
"fmt"
"net/http"
"sync"
"yunion.io/x/jsonutils"
@@ -55,7 +56,7 @@ type RemoteFileClientConfig struct {
lbs []SLoadbalancer
misc []SMisc
secgroups []SSecurityGroup
metrics map[string]interface{}
metrics []map[cloudprovider.TMetricType]map[string]interface{}
debug bool
}
@@ -81,6 +82,7 @@ func (cfg *RemoteFileClientConfig) Debug(debug bool) *RemoteFileClientConfig {
type SRemoteFileClient struct {
*RemoteFileClientConfig
lock sync.Mutex
}
func NewRemoteFileClient(cfg *RemoteFileClientConfig) (*SRemoteFileClient, error) {
@@ -286,22 +288,29 @@ func (self *SRemoteFileClient) GetStorages() ([]SStorage, error) {
func (self *SRemoteFileClient) getMetrics(resourceType cloudprovider.TResourceType, metricType cloudprovider.TMetricType) ([]cloudprovider.MetricValues, error) {
ret := []cloudprovider.MetricValues{}
res := fmt.Sprintf("%s/%s", resourceType, metricType)
if self.metrics == nil {
self.metrics = map[string]interface{}{}
self.lock.Lock()
defer self.lock.Unlock()
self.metrics = []map[cloudprovider.TMetricType]map[string]interface{}{}
resp, err := self.get("metrics")
if err != nil {
return nil, err
}
err = resp.Unmarshal(self.metrics)
err = resp.Unmarshal(&self.metrics)
if err != nil {
return nil, err
}
}
values, ok := self.metrics[res]
if ok {
jsonutils.Update(&ret, values)
for _, metric := range self.metrics {
values, ok := metric[metricType]
if ok {
mid := cloudprovider.MetricValues{}
jsonutils.Update(&mid, values)
ret = append(ret, mid)
}
}
return ret, nil
}