mirror of
https://github.com/yunionio/cloudpods.git
synced 2026-09-24 16:03:43 +08:00
fix(region): vendor update (#19948)
This commit is contained in:
@@ -88,12 +88,12 @@ 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.20240410075732-bba0a16b5380
|
||||
yunion.io/x/cloudmux v0.3.10-0-alpha.1.0.20240411035601-4e42bc16295a
|
||||
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
|
||||
yunion.io/x/ovsdb v0.0.0-20230306173834-f164f413a900
|
||||
yunion.io/x/pkg v1.10.1-0.20240409095939-7c75358eb776
|
||||
yunion.io/x/pkg v1.10.1-0.20240410104547-550ff8a373cc
|
||||
yunion.io/x/s3cli v0.0.0-20190917004522-13ac36d8687e
|
||||
yunion.io/x/sqlchemy v1.1.3-0.20240326090913-96da8bf92408
|
||||
yunion.io/x/structarg v0.0.0-20231017124457-df4d5009457c
|
||||
|
||||
@@ -1204,8 +1204,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.20240410075732-bba0a16b5380 h1:Ejit5VUJHQHjpHTcWgbH/Xd0lapkV6m1VpCvys2WK1c=
|
||||
yunion.io/x/cloudmux v0.3.10-0-alpha.1.0.20240410075732-bba0a16b5380/go.mod h1:dsUESXIbXJ+/ywbNClhldOrbPOiBi2udrgOnB/ffoWk=
|
||||
yunion.io/x/cloudmux v0.3.10-0-alpha.1.0.20240411035601-4e42bc16295a h1:rzcmnjG7Za4GAewqCa//NeinKzPZJ09icyzaoU94Ya4=
|
||||
yunion.io/x/cloudmux v0.3.10-0-alpha.1.0.20240411035601-4e42bc16295a/go.mod h1:dsUESXIbXJ+/ywbNClhldOrbPOiBi2udrgOnB/ffoWk=
|
||||
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=
|
||||
@@ -1219,8 +1219,8 @@ yunion.io/x/ovsdb v0.0.0-20230306173834-f164f413a900 h1:Hu/4ERvoWaN6aiFs4h4/yvVB
|
||||
yunion.io/x/ovsdb v0.0.0-20230306173834-f164f413a900/go.mod h1:0vLkNEhlmA64HViPBAnSTUMrx5QP1CLsxXmxDKQ80tc=
|
||||
yunion.io/x/pkg v0.0.0-20190620104149-945c25821dbf/go.mod h1:t6rEGG2sQ4J7DhFxSZVOTjNd0YO/KlfWQyK1W4tog+E=
|
||||
yunion.io/x/pkg v0.0.0-20190628082551-f4033ba2ea30/go.mod h1:t6rEGG2sQ4J7DhFxSZVOTjNd0YO/KlfWQyK1W4tog+E=
|
||||
yunion.io/x/pkg v1.10.1-0.20240409095939-7c75358eb776 h1:X6JCO6CRIB+4FKpVfvKb80em6+qyxNRCZMA6Lgtzu14=
|
||||
yunion.io/x/pkg v1.10.1-0.20240409095939-7c75358eb776/go.mod h1:ksCJVQ+DwKrJ5QBEoU8pzrDFfDaZVAFH/iJ6yQCYxJk=
|
||||
yunion.io/x/pkg v1.10.1-0.20240410104547-550ff8a373cc h1:kmTCqrss7CyIuDO6JrvCIU/iGyBlX5cS2KnS5Y2MKZA=
|
||||
yunion.io/x/pkg v1.10.1-0.20240410104547-550ff8a373cc/go.mod h1:ksCJVQ+DwKrJ5QBEoU8pzrDFfDaZVAFH/iJ6yQCYxJk=
|
||||
yunion.io/x/s3cli v0.0.0-20190917004522-13ac36d8687e h1:v+EzIadodSwkdZ/7bremd7J8J50Cise/HCylsOJngmo=
|
||||
yunion.io/x/s3cli v0.0.0-20190917004522-13ac36d8687e/go.mod h1:0iFKpOs1y4lbCxeOmq3Xx/0AcQoewVPwj62eRluioEo=
|
||||
yunion.io/x/sqlchemy v1.1.3-0.20240326090913-96da8bf92408 h1:TmkgsnVG/KsUfxaFxaYEhQs0o4nXc9fFFlqZv6mwZ/E=
|
||||
|
||||
Vendored
+2
-2
@@ -1472,7 +1472,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.20240410075732-bba0a16b5380
|
||||
# yunion.io/x/cloudmux v0.3.10-0-alpha.1.0.20240411035601-4e42bc16295a
|
||||
## explicit; go 1.18
|
||||
yunion.io/x/cloudmux/pkg/apis
|
||||
yunion.io/x/cloudmux/pkg/apis/billing
|
||||
@@ -1567,7 +1567,7 @@ yunion.io/x/log/hooks
|
||||
yunion.io/x/ovsdb/cli_util
|
||||
yunion.io/x/ovsdb/schema/ovn_nb
|
||||
yunion.io/x/ovsdb/types
|
||||
# yunion.io/x/pkg v1.10.1-0.20240409095939-7c75358eb776
|
||||
# yunion.io/x/pkg v1.10.1-0.20240410104547-550ff8a373cc
|
||||
## explicit; go 1.18
|
||||
yunion.io/x/pkg/appctx
|
||||
yunion.io/x/pkg/errors
|
||||
|
||||
+1
-1
@@ -142,7 +142,7 @@ func (self *SVpc) addWire(wire *SWire) {
|
||||
}
|
||||
|
||||
func (self *SVpc) getWireByZoneId(zoneId string) *SWire {
|
||||
for i := 0; i <= len(self.iwires); i += 1 {
|
||||
for i := 0; i < len(self.iwires); i += 1 {
|
||||
wire := self.iwires[i].(*SWire)
|
||||
if wire.zone.ZoneId == zoneId {
|
||||
return wire
|
||||
|
||||
-6
@@ -77,13 +77,7 @@ func (self *SHost) _createVM(name, hostname string, imgId string, sysDisk cloudp
|
||||
publicIpBw int, publicIpChargeType cloudprovider.TElasticipChargeType,
|
||||
tags map[string]string, osType string,
|
||||
) (string, error) {
|
||||
net := self.zone.getNetworkById(networkId)
|
||||
if net == nil {
|
||||
return "", fmt.Errorf("invalid network ID %s", networkId)
|
||||
}
|
||||
|
||||
var err error
|
||||
|
||||
keypair := ""
|
||||
if len(publicKey) > 0 {
|
||||
keypair, err = self.zone.region.syncKeypair(publicKey)
|
||||
|
||||
+1
-1
@@ -214,7 +214,7 @@ func (self *SInstance) GetInstanceType() string {
|
||||
}
|
||||
|
||||
func (self *SInstance) getVpc() (*SVpc, error) {
|
||||
return self.host.zone.region.getVpc(self.VirtualPrivateCloud.VpcId)
|
||||
return self.host.zone.region.GetVpc(self.VirtualPrivateCloud.VpcId)
|
||||
}
|
||||
|
||||
func (self *SInstance) GetIDisks() ([]cloudprovider.ICloudDisk, error) {
|
||||
|
||||
+10
-8
@@ -18,7 +18,7 @@ import (
|
||||
"bytes"
|
||||
"context"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"io"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"strconv"
|
||||
@@ -436,11 +436,11 @@ func (client *SQcloudClient) getSdkClient(regionId string) (*common.Client, erro
|
||||
httpClient := client.cpcfg.AdaptiveTimeoutHttpClient()
|
||||
ts, _ := httpClient.Transport.(*http.Transport)
|
||||
cli.WithHttpTransport(cloudprovider.GetCheckTransport(ts, func(req *http.Request) (func(resp *http.Response) error, error) {
|
||||
body, err := ioutil.ReadAll(req.Body)
|
||||
body, err := io.ReadAll(req.Body)
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(err, "ioutil.ReadAll")
|
||||
}
|
||||
req.Body = ioutil.NopCloser(bytes.NewBuffer(body))
|
||||
req.Body = io.NopCloser(bytes.NewBuffer(body))
|
||||
params, err := url.ParseQuery(string(body))
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(err, "ParseQuery(%s)", string(body))
|
||||
@@ -807,7 +807,7 @@ func (client *SQcloudClient) fetchBuckets() error {
|
||||
}
|
||||
name := bInfo.Name[:slashPos]
|
||||
region, err := client.getIRegionByRegionId(bInfo.Region)
|
||||
var zone cloudprovider.ICloudZone
|
||||
var zone *SZone = nil
|
||||
if err != nil {
|
||||
log.Errorf("fail to find region %s", bInfo.Region)
|
||||
// possibly a zone, try zone
|
||||
@@ -824,10 +824,12 @@ func (client *SQcloudClient) fetchBuckets() error {
|
||||
continue
|
||||
}
|
||||
zoneId := bInfo.Region
|
||||
zone, _ = region.(*SRegion).getZoneById(bInfo.Region)
|
||||
if zone != nil {
|
||||
zoneId = zone.GetId()
|
||||
zone, err = region.(*SRegion).getZoneById(bInfo.Region)
|
||||
if err != nil {
|
||||
log.Errorf("fail to find zone %s", zoneId)
|
||||
continue
|
||||
}
|
||||
zoneId = zone.GetId()
|
||||
log.Debugf("find zonal bucket %s", zoneId)
|
||||
}
|
||||
b := SBucket{
|
||||
@@ -838,7 +840,7 @@ func (client *SQcloudClient) fetchBuckets() error {
|
||||
CreateDate: createAt,
|
||||
}
|
||||
if zone != nil {
|
||||
b.zone = zone.(*SZone)
|
||||
b.zone = zone
|
||||
}
|
||||
ret = append(ret, &b)
|
||||
}
|
||||
|
||||
+135
-166
@@ -38,9 +38,6 @@ type SRegion struct {
|
||||
|
||||
client *SQcloudClient
|
||||
|
||||
izones []cloudprovider.ICloudZone
|
||||
ivpcs []cloudprovider.ICloudVpc
|
||||
|
||||
storageCache *SStoragecache
|
||||
|
||||
instanceTypes []SInstanceType
|
||||
@@ -110,11 +107,11 @@ func (self *SRegion) CreateIVpc(opts *cloudprovider.VpcCreateOptions) (cloudprov
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
err = self.fetchInfrastructure()
|
||||
vpc, err := self.GetVpc(vpcId)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return self.GetIVpcById(vpcId)
|
||||
return vpc, nil
|
||||
}
|
||||
|
||||
func (self *SRegion) GetCosClient(bucket *SBucket) (*cos.Client, error) {
|
||||
@@ -286,27 +283,28 @@ func (self *SRegion) GetIVpcById(id string) (cloudprovider.ICloudVpc, error) {
|
||||
}
|
||||
|
||||
func (self *SRegion) getZoneById(id string) (*SZone, error) {
|
||||
izones, err := self.GetIZones()
|
||||
zones, err := self.GetZones()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
for i := 0; i < len(izones); i += 1 {
|
||||
zone := izones[i].(*SZone)
|
||||
if zone.Zone == id {
|
||||
return zone, nil
|
||||
for i := 0; i < len(zones); i += 1 {
|
||||
if zones[i].Zone == id {
|
||||
return &zones[i], nil
|
||||
}
|
||||
}
|
||||
return nil, fmt.Errorf("no such zone %s", id)
|
||||
return nil, errors.Wrapf(cloudprovider.ErrNotFound, id)
|
||||
}
|
||||
|
||||
func (self *SRegion) GetIVpcs() ([]cloudprovider.ICloudVpc, error) {
|
||||
if self.ivpcs == nil {
|
||||
err := self.fetchInfrastructure()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
vpcs, err := self.GetVpcs(nil)
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(err, "GetVpcs")
|
||||
}
|
||||
return self.ivpcs, nil
|
||||
ret := []cloudprovider.ICloudVpc{}
|
||||
for i := range vpcs {
|
||||
ret = append(ret, &vpcs[i])
|
||||
}
|
||||
return ret, nil
|
||||
}
|
||||
|
||||
func (self *SRegion) GetIZoneById(id string) (cloudprovider.ICloudZone, error) {
|
||||
@@ -323,123 +321,85 @@ func (self *SRegion) GetIZoneById(id string) (cloudprovider.ICloudZone, error) {
|
||||
}
|
||||
|
||||
func (self *SRegion) GetIZones() ([]cloudprovider.ICloudZone, error) {
|
||||
if self.izones == nil {
|
||||
var err error
|
||||
err = self.fetchInfrastructure()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
zones, err := self.GetZones()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return self.izones, nil
|
||||
ret := []cloudprovider.ICloudZone{}
|
||||
for i := range zones {
|
||||
ret = append(ret, &zones[i])
|
||||
}
|
||||
return ret, nil
|
||||
}
|
||||
|
||||
func (self *SRegion) _fetchZones() error {
|
||||
params := make(map[string]string)
|
||||
zones := make([]SZone, 0)
|
||||
body, err := self.cvmRequest("DescribeZones", params, true)
|
||||
func (self *SRegion) GetZones() ([]SZone, error) {
|
||||
body, err := self.cvmRequest("DescribeZones", map[string]string{}, true)
|
||||
if err != nil {
|
||||
return err
|
||||
return nil, err
|
||||
}
|
||||
zones := make([]SZone, 0)
|
||||
err = body.Unmarshal(&zones, "ZoneSet")
|
||||
if err != nil {
|
||||
return err
|
||||
return nil, err
|
||||
}
|
||||
self.izones = make([]cloudprovider.ICloudZone, len(zones))
|
||||
for i := 0; i < len(zones); i++ {
|
||||
zones[i].region = self
|
||||
self.izones[i] = &zones[i]
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (self *SRegion) fetchInfrastructure() error {
|
||||
err := self._fetchZones()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
err = self.fetchIVpcs()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
for i := 0; i < len(self.ivpcs); i += 1 {
|
||||
for j := 0; j < len(self.izones); j += 1 {
|
||||
zone := self.izones[j].(*SZone)
|
||||
vpc := self.ivpcs[i].(*SVpc)
|
||||
wire := SWire{zone: zone, vpc: vpc}
|
||||
zone.addWire(&wire)
|
||||
vpc.addWire(&wire)
|
||||
}
|
||||
}
|
||||
return nil
|
||||
return zones, nil
|
||||
}
|
||||
|
||||
func (self *SRegion) DeleteVpc(vpcId string) error {
|
||||
params := make(map[string]string)
|
||||
params["VpcId"] = vpcId
|
||||
|
||||
_, err := self.vpcRequest("DeleteVpc", params)
|
||||
return err
|
||||
}
|
||||
|
||||
func (self *SRegion) getVpc(vpcId string) (*SVpc, error) {
|
||||
vpcs, total, err := self.GetVpcs([]string{vpcId}, 0, 1)
|
||||
func (self *SRegion) GetVpc(vpcId string) (*SVpc, error) {
|
||||
vpcs, err := self.GetVpcs([]string{vpcId})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if total > 1 {
|
||||
return nil, cloudprovider.ErrDuplicateId
|
||||
for i := range vpcs {
|
||||
if vpcs[i].VpcId == vpcId {
|
||||
vpcs[i].region = self
|
||||
return &vpcs[i], nil
|
||||
}
|
||||
}
|
||||
if total == 0 {
|
||||
return nil, cloudprovider.ErrNotFound
|
||||
}
|
||||
vpcs[0].region = self
|
||||
return &vpcs[0], nil
|
||||
return nil, errors.Wrapf(err, "GetVpc(%s)", vpcId)
|
||||
}
|
||||
|
||||
func (self *SRegion) fetchIVpcs() error {
|
||||
vpcs := make([]SVpc, 0)
|
||||
func (self *SRegion) GetVpcs(vpcIds []string) ([]SVpc, error) {
|
||||
params := map[string]string{
|
||||
"Limit": "100",
|
||||
}
|
||||
for index, vpcId := range vpcIds {
|
||||
params[fmt.Sprintf("VpcIds.%d", index)] = vpcId
|
||||
}
|
||||
ret := []SVpc{}
|
||||
for {
|
||||
part, total, err := self.GetVpcs(nil, len(vpcs), 50)
|
||||
resp, err := self.vpcRequest("DescribeVpcs", params)
|
||||
if err != nil {
|
||||
return err
|
||||
return nil, err
|
||||
}
|
||||
vpcs = append(vpcs, part...)
|
||||
if len(vpcs) >= total {
|
||||
part := struct {
|
||||
VpcSet []SVpc
|
||||
TotalCount float64
|
||||
}{}
|
||||
err = resp.Unmarshal(&part)
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(err, "Unmarshal")
|
||||
}
|
||||
for i := range part.VpcSet {
|
||||
part.VpcSet[i].region = self
|
||||
ret = append(ret, part.VpcSet[i])
|
||||
}
|
||||
if len(ret) >= int(part.TotalCount) || len(part.VpcSet) == 0 {
|
||||
break
|
||||
}
|
||||
params["Offset"] = fmt.Sprintf("%d", len(ret))
|
||||
}
|
||||
self.ivpcs = make([]cloudprovider.ICloudVpc, len(vpcs))
|
||||
for i := 0; i < len(vpcs); i += 1 {
|
||||
vpcs[i].region = self
|
||||
self.ivpcs[i] = &vpcs[i]
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (self *SRegion) GetVpcs(vpcIds []string, offset int, limit int) ([]SVpc, int, error) {
|
||||
if limit > 50 || limit <= 0 {
|
||||
limit = 50
|
||||
}
|
||||
params := make(map[string]string)
|
||||
params["Limit"] = fmt.Sprintf("%d", limit)
|
||||
params["Offset"] = fmt.Sprintf("%d", offset)
|
||||
if vpcIds != nil && len(vpcIds) > 0 {
|
||||
for index, vpcId := range vpcIds {
|
||||
params[fmt.Sprintf("VpcIds.%d", index)] = vpcId
|
||||
}
|
||||
}
|
||||
body, err := self.vpcRequest("DescribeVpcs", params)
|
||||
if err != nil {
|
||||
return nil, 0, err
|
||||
}
|
||||
vpcs := make([]SVpc, 0)
|
||||
err = body.Unmarshal(&vpcs, "VpcSet")
|
||||
if err != nil {
|
||||
log.Errorf("Unmarshal vpc fail %s", err)
|
||||
return nil, 0, err
|
||||
}
|
||||
total, _ := body.Float("TotalCount")
|
||||
return vpcs, int(total), nil
|
||||
return ret, nil
|
||||
}
|
||||
|
||||
func (self *SRegion) GetGeographicInfo() cloudprovider.SGeographicInfo {
|
||||
@@ -547,53 +507,58 @@ func (self *SRegion) memcachedRequest(apiName string, params map[string]string)
|
||||
return self.client.memcachedRequest(apiName, params)
|
||||
}
|
||||
|
||||
func (self *SRegion) GetNetworks(ids []string, vpcId string, offset int, limit int) ([]SNetwork, int, error) {
|
||||
if limit > 50 || limit <= 0 {
|
||||
limit = 50
|
||||
func (self *SRegion) GetNetworks(ids []string, vpcId, zone string) ([]SNetwork, error) {
|
||||
params := map[string]string{
|
||||
"Limit": "100",
|
||||
}
|
||||
for index, networkId := range ids {
|
||||
params[fmt.Sprintf("SubnetIds.%d", index)] = networkId
|
||||
}
|
||||
params := make(map[string]string)
|
||||
params["Limit"] = fmt.Sprintf("%d", limit)
|
||||
params["Offset"] = fmt.Sprintf("%d", offset)
|
||||
base := 0
|
||||
if ids != nil && len(ids) > 0 {
|
||||
for index, networkId := range ids {
|
||||
params[fmt.Sprintf("SubnetIds.%d", index)] = networkId
|
||||
}
|
||||
base += len(ids)
|
||||
}
|
||||
if len(vpcId) > 0 {
|
||||
params["Filters.0.Name"] = "vpc-id"
|
||||
params["Filters.0.Values.0"] = vpcId
|
||||
params[fmt.Sprintf("Filters.%d.Name", base)] = "vpc-id"
|
||||
params[fmt.Sprintf("Filters.%d.Values.0", base)] = vpcId
|
||||
base++
|
||||
}
|
||||
|
||||
body, err := self.vpcRequest("DescribeSubnets", params)
|
||||
if err != nil {
|
||||
log.Errorf("DescribeSubnets fail %s", err)
|
||||
return nil, 0, err
|
||||
if len(zone) > 0 {
|
||||
params[fmt.Sprintf("Filters.%d.Name", base)] = "zone"
|
||||
params[fmt.Sprintf("Filters.%d.Values.0", base)] = zone
|
||||
base++
|
||||
}
|
||||
|
||||
networks := make([]SNetwork, 0)
|
||||
err = body.Unmarshal(&networks, "SubnetSet")
|
||||
if err != nil {
|
||||
log.Errorf("Unmarshal network fail %s", err)
|
||||
return nil, 0, err
|
||||
ret := []SNetwork{}
|
||||
for {
|
||||
resp, err := self.vpcRequest("DescribeSubnets", params)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
part := struct {
|
||||
SubnetSet []SNetwork
|
||||
TotalCount float64
|
||||
}{}
|
||||
err = resp.Unmarshal(&part)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
ret = append(ret, part.SubnetSet...)
|
||||
if len(ret) >= int(part.TotalCount) || len(part.SubnetSet) == 0 {
|
||||
break
|
||||
}
|
||||
params["Offset"] = fmt.Sprintf("%d", len(ret))
|
||||
}
|
||||
total, _ := body.Float("TotalCount")
|
||||
return networks, int(total), nil
|
||||
return ret, nil
|
||||
}
|
||||
|
||||
func (self *SRegion) GetNetwork(networkId string) (*SNetwork, error) {
|
||||
networks, total, err := self.GetNetworks([]string{networkId}, "", 0, 1)
|
||||
func (self *SRegion) GetNetwork(id string) (*SNetwork, error) {
|
||||
networks, err := self.GetNetworks([]string{id}, "", "")
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if total > 1 {
|
||||
return nil, cloudprovider.ErrDuplicateId
|
||||
for i := range networks {
|
||||
if networks[i].SubnetId == id {
|
||||
return &networks[i], nil
|
||||
}
|
||||
}
|
||||
if total == 0 {
|
||||
return nil, cloudprovider.ErrNotFound
|
||||
}
|
||||
return &networks[0], nil
|
||||
return nil, errors.Wrapf(cloudprovider.ErrNotFound, id)
|
||||
}
|
||||
|
||||
func (self *SRegion) getStoragecache() *SStoragecache {
|
||||
@@ -633,39 +598,43 @@ func (self *SRegion) GetMatchInstanceTypes(cpu int, memMB int, gpu int, zoneId s
|
||||
}
|
||||
|
||||
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) {
|
||||
izones, err := self.GetIZones()
|
||||
zones, err := self.GetZones()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
for i := 0; i < len(izones); i += 1 {
|
||||
z := izones[i].(*SZone)
|
||||
log.Debugf("Search in zone %s", z.Zone)
|
||||
net := z.getNetworkById(networkId)
|
||||
if net != nil {
|
||||
desc := &cloudprovider.SManagedVMCreateConfig{
|
||||
Name: name,
|
||||
ExternalImageId: imgId,
|
||||
SysDisk: cloudprovider.SDiskInfo{SizeGB: 0, StorageType: storageType},
|
||||
Cpu: cpu,
|
||||
MemoryMB: memGB * 1024,
|
||||
ExternalNetworkId: networkId,
|
||||
Password: passwd,
|
||||
DataDisks: []cloudprovider.SDiskInfo{},
|
||||
PublicKey: publicKey,
|
||||
|
||||
Tags: tags,
|
||||
|
||||
ExternalSecgroupIds: []string{secgroup},
|
||||
}
|
||||
for _, sizeGB := range dataDiskSizesGB {
|
||||
desc.DataDisks = append(desc.DataDisks, cloudprovider.SDiskInfo{SizeGB: sizeGB, StorageType: storageType})
|
||||
}
|
||||
inst, err := z.getHost().CreateVM(desc)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return inst.(*SInstance), nil
|
||||
net, err := self.GetNetwork(networkId)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
for i := 0; i < len(zones); i += 1 {
|
||||
zone := zones[i]
|
||||
log.Debugf("Search in zone %s", zone.Zone)
|
||||
if zone.ZoneName != net.Zone {
|
||||
continue
|
||||
}
|
||||
desc := &cloudprovider.SManagedVMCreateConfig{
|
||||
Name: name,
|
||||
ExternalImageId: imgId,
|
||||
SysDisk: cloudprovider.SDiskInfo{SizeGB: 0, StorageType: storageType},
|
||||
Cpu: cpu,
|
||||
MemoryMB: memGB * 1024,
|
||||
ExternalNetworkId: networkId,
|
||||
Password: passwd,
|
||||
DataDisks: []cloudprovider.SDiskInfo{},
|
||||
PublicKey: publicKey,
|
||||
|
||||
Tags: tags,
|
||||
|
||||
ExternalSecgroupIds: []string{secgroup},
|
||||
}
|
||||
for _, sizeGB := range dataDiskSizesGB {
|
||||
desc.DataDisks = append(desc.DataDisks, cloudprovider.SDiskInfo{SizeGB: sizeGB, StorageType: storageType})
|
||||
}
|
||||
inst, err := zone.getHost().CreateVM(desc)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return inst.(*SInstance), nil
|
||||
}
|
||||
return nil, fmt.Errorf("cannot find network %s", networkId)
|
||||
}
|
||||
|
||||
+17
-54
@@ -31,8 +31,6 @@ type SVpc struct {
|
||||
|
||||
region *SRegion
|
||||
|
||||
iwires []cloudprovider.ICloudWire
|
||||
|
||||
CidrBlock string
|
||||
Ipv6CidrBlock string
|
||||
CreatedTime time.Time
|
||||
@@ -116,16 +114,6 @@ func (self *SVpc) GetIRouteTableById(routeTableId string) (cloudprovider.ICloudR
|
||||
return &routetables[0], nil
|
||||
}
|
||||
|
||||
func (self *SVpc) getWireByZoneId(zoneId string) *SWire {
|
||||
for i := 0; i <= len(self.iwires); i++ {
|
||||
wire := self.iwires[i].(*SWire)
|
||||
if wire.zone.Zone == zoneId {
|
||||
return wire
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (self *SVpc) GetINatGateways() ([]cloudprovider.ICloudNatGateway, error) {
|
||||
nats := []SNatGateway{}
|
||||
for {
|
||||
@@ -146,48 +134,30 @@ func (self *SVpc) GetINatGateways() ([]cloudprovider.ICloudNatGateway, error) {
|
||||
return inats, nil
|
||||
}
|
||||
|
||||
func (self *SVpc) fetchNetworks() error {
|
||||
networks, total, err := self.region.GetNetworks(nil, self.VpcId, 0, 50)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if total > len(networks) {
|
||||
networks, _, err = self.region.GetNetworks(nil, self.VpcId, 0, total)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
for i := 0; i < len(networks); i += 1 {
|
||||
wire := self.getWireByZoneId(networks[i].Zone)
|
||||
networks[i].wire = wire
|
||||
wire.addNetwork(&networks[i])
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (self *SVpc) GetIWireById(wireId string) (cloudprovider.ICloudWire, error) {
|
||||
if self.iwires == nil {
|
||||
err := self.fetchNetworks()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
wires, err := self.GetIWires()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
for i := 0; i < len(self.iwires); i += 1 {
|
||||
if self.iwires[i].GetGlobalId() == wireId {
|
||||
return self.iwires[i], nil
|
||||
for i := 0; i < len(wires); i += 1 {
|
||||
if wires[i].GetGlobalId() == wireId {
|
||||
return wires[i], nil
|
||||
}
|
||||
}
|
||||
return nil, cloudprovider.ErrNotFound
|
||||
}
|
||||
|
||||
func (self *SVpc) GetIWires() ([]cloudprovider.ICloudWire, error) {
|
||||
if self.iwires == nil {
|
||||
err := self.fetchNetworks()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
zones, err := self.region.GetZones()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return self.iwires, nil
|
||||
ret := []cloudprovider.ICloudWire{}
|
||||
for i := range zones {
|
||||
wire := &SWire{zone: &zones[i], vpc: self}
|
||||
ret = append(ret, wire)
|
||||
}
|
||||
return ret, nil
|
||||
}
|
||||
|
||||
func (self *SVpc) GetRegion() cloudprovider.ICloudRegion {
|
||||
@@ -195,18 +165,11 @@ func (self *SVpc) GetRegion() cloudprovider.ICloudRegion {
|
||||
}
|
||||
|
||||
func (self *SVpc) Refresh() error {
|
||||
new, err := self.region.getVpc(self.VpcId)
|
||||
vpc, err := self.region.GetVpc(self.VpcId)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return jsonutils.Update(self, new)
|
||||
}
|
||||
|
||||
func (self *SVpc) addWire(wire *SWire) {
|
||||
if self.iwires == nil {
|
||||
self.iwires = make([]cloudprovider.ICloudWire, 0)
|
||||
}
|
||||
self.iwires = append(self.iwires, wire)
|
||||
return jsonutils.Update(self, vpc)
|
||||
}
|
||||
|
||||
func (self *SVpc) GetAuthorityOwnerId() string {
|
||||
|
||||
+18
-71
@@ -17,7 +17,7 @@ package qcloud
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"yunion.io/x/log"
|
||||
"yunion.io/x/pkg/errors"
|
||||
|
||||
api "yunion.io/x/cloudmux/pkg/apis/compute"
|
||||
"yunion.io/x/cloudmux/pkg/cloudprovider"
|
||||
@@ -29,8 +29,6 @@ type SWire struct {
|
||||
QcloudTags
|
||||
zone *SZone
|
||||
vpc *SVpc
|
||||
|
||||
inetworks []cloudprovider.ICloudNetwork
|
||||
}
|
||||
|
||||
func (self *SWire) GetId() string {
|
||||
@@ -69,88 +67,37 @@ func (self *SWire) GetBandwidth() int {
|
||||
return 10000
|
||||
}
|
||||
|
||||
func (self *SWire) GetNetworkById(networkId string) *SNetwork {
|
||||
networks, err := self.GetINetworks()
|
||||
if err != nil {
|
||||
return nil
|
||||
}
|
||||
log.Debugf("search for networks %d", len(networks))
|
||||
for i := 0; i < len(networks); i += 1 {
|
||||
log.Debugf("search %s", networks[i].GetName())
|
||||
network := networks[i].(*SNetwork)
|
||||
if network.SubnetId == networkId {
|
||||
return network
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (self *SWire) CreateINetwork(opts *cloudprovider.SNetworkCreateOptions) (cloudprovider.ICloudNetwork, error) {
|
||||
networkId, err := self.zone.region.CreateNetwork(self.zone.Zone, self.vpc.VpcId, opts.Name, opts.Cidr, opts.Desc)
|
||||
if err != nil {
|
||||
log.Errorf("CreateNetwork error %s", err)
|
||||
return nil, err
|
||||
return nil, errors.Wrapf(err, "CreateNetwork")
|
||||
}
|
||||
self.inetworks = nil
|
||||
network := self.GetNetworkById(networkId)
|
||||
if network == nil {
|
||||
log.Errorf("cannot find vswitch after create????")
|
||||
return nil, cloudprovider.ErrNotFound
|
||||
network, err := self.vpc.region.GetNetwork(networkId)
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(err, "GetNetwork")
|
||||
}
|
||||
network.wire = self
|
||||
return network, nil
|
||||
}
|
||||
|
||||
func (self *SWire) GetINetworkById(netid string) (cloudprovider.ICloudNetwork, error) {
|
||||
networks, err := self.GetINetworks()
|
||||
network, err := self.zone.region.GetNetwork(netid)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
for i := 0; i < len(networks); i += 1 {
|
||||
if networks[i].GetGlobalId() == netid {
|
||||
return networks[i], nil
|
||||
}
|
||||
}
|
||||
return nil, cloudprovider.ErrNotFound
|
||||
}
|
||||
|
||||
func (self *SWire) getNetworkById(networkId string) *SNetwork {
|
||||
networks, err := self.GetINetworks()
|
||||
if err != nil {
|
||||
return nil
|
||||
}
|
||||
log.Debugf("search for networks %d", len(networks))
|
||||
for i := 0; i < len(networks); i += 1 {
|
||||
log.Debugf("search %s", networks[i].GetName())
|
||||
network := networks[i].(*SNetwork)
|
||||
if network.SubnetId == networkId {
|
||||
return network
|
||||
}
|
||||
}
|
||||
return nil
|
||||
network.wire = self
|
||||
return network, nil
|
||||
}
|
||||
|
||||
func (self *SWire) GetINetworks() ([]cloudprovider.ICloudNetwork, error) {
|
||||
if self.inetworks == nil {
|
||||
err := self.vpc.fetchNetworks()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
return self.inetworks, nil
|
||||
}
|
||||
|
||||
func (self *SWire) addNetwork(network *SNetwork) {
|
||||
if self.inetworks == nil {
|
||||
self.inetworks = make([]cloudprovider.ICloudNetwork, 0)
|
||||
}
|
||||
find := false
|
||||
for i := 0; i < len(self.inetworks); i += 1 {
|
||||
if self.inetworks[i].GetId() == network.SubnetId {
|
||||
find = true
|
||||
break
|
||||
}
|
||||
}
|
||||
if !find {
|
||||
self.inetworks = append(self.inetworks, network)
|
||||
networks, err := self.zone.region.GetNetworks(nil, self.vpc.VpcId, self.zone.Zone)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
ret := []cloudprovider.ICloudNetwork{}
|
||||
for i := range networks {
|
||||
networks[i].wire = self
|
||||
ret = append(ret, &networks[i])
|
||||
}
|
||||
return ret, nil
|
||||
}
|
||||
|
||||
+9
-22
@@ -42,8 +42,6 @@ type SZone struct {
|
||||
QcloudTags
|
||||
region *SRegion
|
||||
|
||||
iwires []cloudprovider.ICloudWire
|
||||
|
||||
host *SHost
|
||||
|
||||
istorages []cloudprovider.ICloudStorage
|
||||
@@ -247,28 +245,17 @@ func (self *SZone) GetIStorageById(id string) (cloudprovider.ICloudStorage, erro
|
||||
return nil, cloudprovider.ErrNotFound
|
||||
}
|
||||
|
||||
func (self *SZone) addWire(wire *SWire) {
|
||||
if self.iwires == nil {
|
||||
self.iwires = make([]cloudprovider.ICloudWire, 0)
|
||||
}
|
||||
self.iwires = append(self.iwires, wire)
|
||||
}
|
||||
|
||||
func (self *SZone) GetIWires() ([]cloudprovider.ICloudWire, error) {
|
||||
return self.iwires, nil
|
||||
}
|
||||
|
||||
func (self *SZone) getNetworkById(networkId string) *SNetwork {
|
||||
log.Debugf("Search in wires %d", len(self.iwires))
|
||||
for i := 0; i < len(self.iwires); i += 1 {
|
||||
log.Debugf("Search in wire %s", self.iwires[i].GetName())
|
||||
wire := self.iwires[i].(*SWire)
|
||||
net := wire.getNetworkById(networkId)
|
||||
if net != nil {
|
||||
return net
|
||||
}
|
||||
vpcs, err := self.region.GetVpcs(nil)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return nil
|
||||
ret := []cloudprovider.ICloudWire{}
|
||||
for i := range vpcs {
|
||||
wire := &SWire{vpc: &vpcs[i], zone: self}
|
||||
ret = append(ret, wire)
|
||||
}
|
||||
return ret, nil
|
||||
}
|
||||
|
||||
func (self *SZone) fetchInstanceTypes() {
|
||||
|
||||
+1
-1
@@ -110,7 +110,7 @@ func normalizeOsDistribution(osDist string, imageName string) string {
|
||||
return "Fedora"
|
||||
} else if strings.Contains(osDist, "alma") {
|
||||
return "AlmaLinux"
|
||||
} else if strings.Contains(osDist, "amazon linux") {
|
||||
} else if strings.Contains(osDist, "amazon") && strings.Contains(osDist, "linux") {
|
||||
return "Amazon Linux"
|
||||
} else if strings.Contains(osDist, "windows") {
|
||||
for _, ver := range []string{"2003", "2008", "2012", "2016", "2019", "2022"} {
|
||||
|
||||
Reference in New Issue
Block a user