mirror of
https://github.com/yunionio/cloudpods.git
synced 2026-10-30 18:23:35 +08:00
fix(region): vendor update for lb multi eip sync (#22719)
This commit is contained in:
@@ -278,8 +278,8 @@ RELEASE_BRANCH:=master
|
||||
GOPROXY ?= direct
|
||||
|
||||
mod:
|
||||
GOPROXY=$(GOPROXY) GONOSUMDB=yunion.io/x go get -d yunion.io/x/cloudmux@$(RELEASE_BRANCH)
|
||||
GOPROXY=$(GOPROXY) GONOSUMDB=yunion.io/x go get -d $(patsubst %,%@master,$(shell GO111MODULE=on go mod edit -print | sed -n -e 's|.*\(yunion.io/x/[a-z].*\) v.*|\1|p' | grep -v '/cloudmux$$'))
|
||||
GOPROXY=$(GOPROXY) GONOSUMDB=yunion.io/x go get yunion.io/x/cloudmux@$(RELEASE_BRANCH)
|
||||
GOPROXY=$(GOPROXY) GONOSUMDB=yunion.io/x go get $(patsubst %,%@master,$(shell GO111MODULE=on go mod edit -print | sed -n -e 's|.*\(yunion.io/x/[a-z].*\) v.*|\1|p' | grep -v '/cloudmux$$'))
|
||||
GOPROXY=$(GOPROXY) GONOSUMDB=yunion.io/x go mod tidy
|
||||
GOPROXY=$(GOPROXY) GONOSUMDB=yunion.io/x go mod vendor -v
|
||||
|
||||
|
||||
@@ -95,7 +95,7 @@ require (
|
||||
k8s.io/cri-api v0.22.17
|
||||
k8s.io/klog/v2 v2.20.0
|
||||
moul.io/http2curl/v2 v2.3.0
|
||||
yunion.io/x/cloudmux v0.3.10-0-alpha.1.0.20250606110734-0a60d09de2c5
|
||||
yunion.io/x/cloudmux v0.3.10-0-alpha.1.0.20250613110939-e90f66e6775d
|
||||
yunion.io/x/executor v0.0.0-20250518005516-5402e9e0bed0
|
||||
yunion.io/x/jsonutils v1.0.1-0.20250507052344-1abcf4f443b1
|
||||
yunion.io/x/log v1.0.1-0.20240305175729-7cf2d6cd5a91
|
||||
|
||||
@@ -1410,8 +1410,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.20250606110734-0a60d09de2c5 h1:O76RBJit7vZ42bJdNqpYY5Px21g9jYQSODM5zuCaVrw=
|
||||
yunion.io/x/cloudmux v0.3.10-0-alpha.1.0.20250606110734-0a60d09de2c5/go.mod h1:FXxAEbdNfWXX9gjME3K2nJhkydHY5EKEUZb+RLEzVwQ=
|
||||
yunion.io/x/cloudmux v0.3.10-0-alpha.1.0.20250613110939-e90f66e6775d h1:yJLYt+0JEJIvhfgoZCx19SkzGirH/SYcjnLLQzAQHcg=
|
||||
yunion.io/x/cloudmux v0.3.10-0-alpha.1.0.20250613110939-e90f66e6775d/go.mod h1:FXxAEbdNfWXX9gjME3K2nJhkydHY5EKEUZb+RLEzVwQ=
|
||||
yunion.io/x/executor v0.0.0-20250518005516-5402e9e0bed0 h1:msG4SiDSVU7CrXH06WuHlNEZXIooTcmNbfrIGHuIHBU=
|
||||
yunion.io/x/executor v0.0.0-20250518005516-5402e9e0bed0/go.mod h1:Uxuou9WQIeJXNpy7t2fPLL0BYLvLiMvGQwY7Qc6aSws=
|
||||
yunion.io/x/jsonutils v0.0.0-20190625054549-a964e1e8a051/go.mod h1:4N0/RVzsYL3kH3WE/H1BjUQdFiWu50JGCFQuuy+Z634=
|
||||
|
||||
@@ -67,6 +67,17 @@ type LoadbalancerListInput struct {
|
||||
UsableLoadbalancerForEip string `json:"usable_loadbalancer_for_eip"`
|
||||
}
|
||||
|
||||
type LbEip struct {
|
||||
// 公网IP地址
|
||||
Eip string `json:"eip"`
|
||||
|
||||
EipId string `json:"eip_id"`
|
||||
|
||||
// 公网IP地址类型: 弹性、非弹性
|
||||
// example: public_ip
|
||||
EipMode string `json:"eip_mode"`
|
||||
}
|
||||
|
||||
type LoadbalancerDetails struct {
|
||||
apis.VirtualResourceDetails
|
||||
|
||||
@@ -82,14 +93,9 @@ type LoadbalancerDetails struct {
|
||||
|
||||
SLoadbalancer
|
||||
|
||||
// 公网IP地址
|
||||
Eip string `json:"eip"`
|
||||
LbEip
|
||||
|
||||
EipId string `json:"eip_id"`
|
||||
|
||||
// 公网IP地址类型: 弹性、非弹性
|
||||
// example: public_ip
|
||||
EipMode string `json:"eip_mode"`
|
||||
Eips []LbEip `json:"eips"`
|
||||
|
||||
// 后端服务器组名称
|
||||
BackendGroup string `json:"backend_group"`
|
||||
|
||||
@@ -136,9 +136,9 @@ func syncRegionLoadbalancers(
|
||||
}
|
||||
|
||||
func syncLbPeripherals(ctx context.Context, userCred mcclient.TokenCredential, provider *SCloudprovider, local *SLoadbalancer, remote cloudprovider.ICloudLoadbalancer) {
|
||||
err := syncLoadbalancerEip(ctx, userCred, provider, local, remote)
|
||||
err := syncLoadbalancerEips(ctx, userCred, provider, local, remote)
|
||||
if err != nil {
|
||||
log.Errorf("syncLoadbalancerEip error %s", err)
|
||||
log.Errorf("syncLoadbalancerEips error %s", err)
|
||||
}
|
||||
err = syncLoadbalancerBackendgroups(ctx, userCred, SSyncResultSet{}, provider, local, remote)
|
||||
if err != nil {
|
||||
@@ -169,14 +169,14 @@ func syncLoadbalancerSecurityGroups(ctx context.Context, userCred mcclient.Token
|
||||
return nil
|
||||
}
|
||||
|
||||
func syncLoadbalancerEip(ctx context.Context, userCred mcclient.TokenCredential, provider *SCloudprovider, localLb *SLoadbalancer, remoteLb cloudprovider.ICloudLoadbalancer) error {
|
||||
eip, err := remoteLb.GetIEIP()
|
||||
func syncLoadbalancerEips(ctx context.Context, userCred mcclient.TokenCredential, provider *SCloudprovider, localLb *SLoadbalancer, remoteLb cloudprovider.ICloudLoadbalancer) error {
|
||||
eips, err := remoteLb.GetIEIPs()
|
||||
if err != nil {
|
||||
return errors.Wrapf(err, "GetIEIP")
|
||||
return errors.Wrapf(err, "GetIEIPs")
|
||||
}
|
||||
result := localLb.SyncLoadbalancerEip(ctx, userCred, provider, eip)
|
||||
result := localLb.SyncLoadbalancerEips(ctx, userCred, provider, eips)
|
||||
msg := result.Result()
|
||||
log.Infof("SyncEip for Loadbalancer %s result: %s", localLb.Name, msg)
|
||||
log.Infof("SyncEips for Loadbalancer %s result: %s", localLb.Name, msg)
|
||||
if result.IsError() {
|
||||
return result.AllError()
|
||||
}
|
||||
|
||||
@@ -1323,8 +1323,8 @@ func (self *SElasticip) PerformAssociate(ctx context.Context, userCred mcclient.
|
||||
if lb.PendingDeleted {
|
||||
return input, httperrors.NewInvalidStatusError("cannot associate with pending deleted loadbalancer")
|
||||
}
|
||||
seip, _ := lb.GetEip()
|
||||
if seip != nil {
|
||||
eips, _ := lb.GetEips()
|
||||
if len(eips) > 0 {
|
||||
return input, httperrors.NewInvalidStatusError("loadbalancer is already associated with eip")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -847,9 +847,18 @@ func (man *SLoadbalancerManager) FetchCustomizeColumns(
|
||||
log.Errorf("Fetch eips error: %v", err)
|
||||
return rows
|
||||
}
|
||||
eipMap := map[string]*SElasticip{}
|
||||
eipMap := map[string][]api.LbEip{}
|
||||
for i := range eips {
|
||||
eipMap[eips[i].AssociateId] = &eips[i]
|
||||
associateId := eips[i].AssociateId
|
||||
_, ok := eipMap[associateId]
|
||||
if !ok {
|
||||
eipMap[associateId] = []api.LbEip{}
|
||||
}
|
||||
eipMap[associateId] = append(eipMap[associateId], api.LbEip{
|
||||
Eip: eips[i].IpAddr,
|
||||
EipId: eips[i].Id,
|
||||
EipMode: eips[i].Mode,
|
||||
})
|
||||
}
|
||||
|
||||
bgMap, err := db.FetchIdNameMap2(LoadbalancerBackendGroupManager, backendGroupIds)
|
||||
@@ -898,11 +907,10 @@ func (man *SLoadbalancerManager) FetchCustomizeColumns(
|
||||
}
|
||||
|
||||
for i := range rows {
|
||||
eip, ok := eipMap[lbIds[i]]
|
||||
eips, ok := eipMap[lbIds[i]]
|
||||
if ok {
|
||||
rows[i].Eip = eip.IpAddr
|
||||
rows[i].EipMode = eip.Mode
|
||||
rows[i].EipId = eip.Id
|
||||
rows[i].Eips = eips
|
||||
rows[i].Eip = eips[0].Eip
|
||||
}
|
||||
bg, ok := bgMap[backendGroupIds[i]]
|
||||
if ok {
|
||||
@@ -1239,56 +1247,82 @@ func (lb *SLoadbalancer) syncLoadbalancerNetwork(ctx context.Context, userCred m
|
||||
}
|
||||
|
||||
func (self *SLoadbalancer) DeleteEip(ctx context.Context, userCred mcclient.TokenCredential, autoDelete bool) error {
|
||||
eip, err := self.GetEip()
|
||||
eips, err := self.GetEips()
|
||||
if err != nil {
|
||||
log.Errorf("Delete eip fail for get Eip %s", err)
|
||||
return err
|
||||
}
|
||||
if eip == nil {
|
||||
return nil
|
||||
}
|
||||
if eip.Mode == api.EIP_MODE_INSTANCE_PUBLICIP {
|
||||
err = eip.RealDelete(ctx, userCred)
|
||||
if err != nil {
|
||||
log.Errorf("Delete eip on delete server fail %s", err)
|
||||
return errors.Wrap(err, "RealDelete")
|
||||
}
|
||||
} else {
|
||||
err = eip.Dissociate(ctx, userCred)
|
||||
if err != nil {
|
||||
log.Errorf("Dissociate eip on delete server fail %s", err)
|
||||
return errors.Wrap(err, "Dissociate")
|
||||
}
|
||||
if autoDelete {
|
||||
for _, eip := range eips {
|
||||
if eip.Mode == api.EIP_MODE_INSTANCE_PUBLICIP {
|
||||
err = eip.RealDelete(ctx, userCred)
|
||||
if err != nil {
|
||||
log.Errorf("Delete eip on delete server fail %s", err)
|
||||
return errors.Wrap(err, "RealDelete")
|
||||
}
|
||||
} else {
|
||||
err = eip.Dissociate(ctx, userCred)
|
||||
if err != nil {
|
||||
log.Errorf("Dissociate eip on delete server fail %s", err)
|
||||
return errors.Wrap(err, "Dissociate")
|
||||
}
|
||||
if autoDelete {
|
||||
err = eip.RealDelete(ctx, userCred)
|
||||
if err != nil {
|
||||
log.Errorf("Delete eip on delete server fail %s", err)
|
||||
return errors.Wrap(err, "RealDelete")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (self *SLoadbalancer) GetEip() (*SElasticip, error) {
|
||||
return ElasticipManager.getEip(api.EIP_ASSOCIATE_TYPE_LOADBALANCER, self.Id, "")
|
||||
func (self *SLoadbalancer) GetEips() ([]SElasticip, error) {
|
||||
q := ElasticipManager.Query().Equals("associate_id", self.Id).Equals("associate_type", api.EIP_ASSOCIATE_TYPE_LOADBALANCER)
|
||||
ret := []SElasticip{}
|
||||
err := db.FetchModelObjects(ElasticipManager, q, &ret)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return ret, nil
|
||||
}
|
||||
|
||||
func (self *SLoadbalancer) SyncLoadbalancerEip(ctx context.Context, userCred mcclient.TokenCredential, provider *SCloudprovider, extEip cloudprovider.ICloudEIP) compare.SyncResult {
|
||||
func (self *SLoadbalancer) SyncLoadbalancerEips(ctx context.Context, userCred mcclient.TokenCredential, provider *SCloudprovider, extEips []cloudprovider.ICloudEIP) compare.SyncResult {
|
||||
result := compare.SyncResult{}
|
||||
|
||||
eip, err := self.GetEip()
|
||||
eips, err := self.GetEips()
|
||||
if err != nil {
|
||||
result.Error(fmt.Errorf("getEip error %s", err))
|
||||
return result
|
||||
}
|
||||
|
||||
if eip == nil && extEip == nil {
|
||||
// do nothing
|
||||
} else if eip == nil && extEip != nil {
|
||||
// add
|
||||
removed := []SElasticip{}
|
||||
commondb := []SElasticip{}
|
||||
commonext := []cloudprovider.ICloudEIP{}
|
||||
added := []cloudprovider.ICloudEIP{}
|
||||
|
||||
err = compare.CompareSets(eips, extEips, &removed, &commondb, &commonext, &added)
|
||||
if err != nil {
|
||||
result.Error(err)
|
||||
return result
|
||||
}
|
||||
|
||||
for i := 0; i < len(removed); i++ {
|
||||
err = removed[i].Dissociate(ctx, userCred)
|
||||
if err != nil {
|
||||
result.DeleteError(err)
|
||||
} else {
|
||||
result.Delete()
|
||||
}
|
||||
}
|
||||
|
||||
for i := 0; i < len(commondb); i++ {
|
||||
result.Update()
|
||||
}
|
||||
for i := 0; i < len(added); i++ {
|
||||
region, _ := self.GetRegion()
|
||||
neip, err := ElasticipManager.getEipByExtEip(ctx, userCred, extEip, provider, region, provider.GetOwnerId())
|
||||
neip, err := ElasticipManager.getEipByExtEip(ctx, userCred, added[i], provider, region, provider.GetOwnerId())
|
||||
if err != nil {
|
||||
log.Errorf("getEipByExtEip error %v", err)
|
||||
result.AddError(err)
|
||||
@@ -1301,46 +1335,6 @@ func (self *SLoadbalancer) SyncLoadbalancerEip(ctx context.Context, userCred mcc
|
||||
result.Add()
|
||||
}
|
||||
}
|
||||
} else if eip != nil && extEip == nil {
|
||||
// remove
|
||||
err = eip.Dissociate(ctx, userCred)
|
||||
if err != nil {
|
||||
result.DeleteError(err)
|
||||
} else {
|
||||
result.Delete()
|
||||
}
|
||||
} else {
|
||||
// sync
|
||||
if eip.IpAddr != extEip.GetIpAddr() {
|
||||
// remove then add
|
||||
err = eip.Dissociate(ctx, userCred)
|
||||
if err != nil {
|
||||
// fail to remove
|
||||
result.DeleteError(err)
|
||||
} else {
|
||||
result.Delete()
|
||||
region, _ := self.GetRegion()
|
||||
neip, err := ElasticipManager.getEipByExtEip(ctx, userCred, extEip, provider, region, provider.GetOwnerId())
|
||||
if err != nil {
|
||||
result.AddError(err)
|
||||
} else {
|
||||
err = neip.AssociateLoadbalancer(ctx, userCred, self)
|
||||
if err != nil {
|
||||
result.AddError(err)
|
||||
} else {
|
||||
result.Add()
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// do nothing
|
||||
err := eip.SyncWithCloudEip(ctx, userCred, provider, extEip, provider.GetOwnerId())
|
||||
if err != nil {
|
||||
result.UpdateError(err)
|
||||
} else {
|
||||
result.Update()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return result
|
||||
@@ -1666,11 +1660,11 @@ func (lb *SLoadbalancer) IsEipAssociable() error {
|
||||
return errors.Wrap(err, "ValidateAssociateEip")
|
||||
}
|
||||
|
||||
eip, err := lb.GetEip()
|
||||
eips, err := lb.GetEips()
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "GetElasticIp")
|
||||
}
|
||||
if eip != nil {
|
||||
if len(eips) > 0 {
|
||||
return httperrors.NewInvalidStatusError("already associate with eip")
|
||||
}
|
||||
return nil
|
||||
@@ -1765,16 +1759,16 @@ func (lb *SLoadbalancer) PerformDissociateEip(ctx context.Context, userCred mccl
|
||||
return nil, httperrors.NewUnsupportOperationError("not support managed lb")
|
||||
}
|
||||
|
||||
eip, err := lb.GetEip()
|
||||
eips, err := lb.GetEips()
|
||||
if err != nil {
|
||||
log.Errorf("Fail to get Eip %s", err)
|
||||
return nil, httperrors.NewGeneralError(err)
|
||||
}
|
||||
if eip == nil {
|
||||
if len(eips) == 0 {
|
||||
return nil, httperrors.NewInvalidStatusError("No eip to dissociate")
|
||||
}
|
||||
|
||||
err = db.IsObjectRbacAllowed(ctx, eip, userCred, policy.PolicyActionGet)
|
||||
err = db.IsObjectRbacAllowed(ctx, &eips[0], userCred, policy.PolicyActionGet)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "eip is not accessible")
|
||||
}
|
||||
|
||||
Vendored
+1
-1
@@ -1849,7 +1849,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.20250606110734-0a60d09de2c5
|
||||
# yunion.io/x/cloudmux v0.3.10-0-alpha.1.0.20250613110939-e90f66e6775d
|
||||
## explicit; go 1.21
|
||||
yunion.io/x/cloudmux/pkg/apis
|
||||
yunion.io/x/cloudmux/pkg/apis/billing
|
||||
|
||||
+1
-1
@@ -722,7 +722,7 @@ type ICloudLoadbalancer interface {
|
||||
GetChargeType() string
|
||||
GetEgressMbps() int
|
||||
|
||||
GetIEIP() (ICloudEIP, error)
|
||||
GetIEIPs() ([]ICloudEIP, error)
|
||||
|
||||
Delete(ctx context.Context) error
|
||||
|
||||
|
||||
+8
-7
@@ -297,7 +297,7 @@ func (lb *SLoadbalancer) GetILoadBalancerBackendGroupById(groupId string) (cloud
|
||||
return nil, cloudprovider.ErrNotFound
|
||||
}
|
||||
|
||||
func (lb *SLoadbalancer) GetIEIP() (cloudprovider.ICloudEIP, error) {
|
||||
func (lb *SLoadbalancer) GetIEIPs() ([]cloudprovider.ICloudEIP, error) {
|
||||
if lb.AddressType == "internet" {
|
||||
eip := SEipAddress{
|
||||
region: lb.region,
|
||||
@@ -315,17 +315,18 @@ func (lb *SLoadbalancer) GetIEIP() (cloudprovider.ICloudEIP, error) {
|
||||
case api.LB_CHARGE_TYPE_BY_TRAFFIC:
|
||||
eip.InternetChargeType = InternetChargeByTraffic
|
||||
}
|
||||
return &eip, nil
|
||||
return []cloudprovider.ICloudEIP{&eip}, nil
|
||||
}
|
||||
eips, total, err := lb.region.GetEips("", lb.LoadBalancerId, "", 0, 1)
|
||||
eips, _, err := lb.region.GetEips("", lb.LoadBalancerId, "", 0, 1)
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(err, "lb.region.GetEips(%s)", lb.LoadBalancerId)
|
||||
}
|
||||
if total != 1 {
|
||||
return nil, cloudprovider.ErrNotFound
|
||||
ret := []cloudprovider.ICloudEIP{}
|
||||
for i := range eips {
|
||||
eips[i].region = lb.region
|
||||
ret = append(ret, &eips[i])
|
||||
}
|
||||
eips[0].region = lb.region
|
||||
return &eips[0], nil
|
||||
return ret, nil
|
||||
}
|
||||
|
||||
func (region *SRegion) loadbalancerOperation(loadbalancerId, status string) error {
|
||||
|
||||
+1
-1
@@ -41,7 +41,7 @@ func (backend *SLoadbalancerBackend) GetName() string {
|
||||
}
|
||||
|
||||
func (backend *SLoadbalancerBackend) GetId() string {
|
||||
return fmt.Sprintf("%s/%s", backend.lbbg.VServerGroupId, backend.ServerId)
|
||||
return fmt.Sprintf("%s/%s/%s/%d", backend.lbbg.VServerGroupId, backend.ServerId, backend.ServerIp, backend.Port)
|
||||
}
|
||||
|
||||
func (backend *SLoadbalancerBackend) GetGlobalId() string {
|
||||
|
||||
+8
-7
@@ -300,7 +300,7 @@ func (lb *SLoadbalancer) GetILoadBalancerBackendGroupById(groupId string) (cloud
|
||||
return nil, cloudprovider.ErrNotFound
|
||||
}
|
||||
|
||||
func (lb *SLoadbalancer) GetIEIP() (cloudprovider.ICloudEIP, error) {
|
||||
func (lb *SLoadbalancer) GetIEIPs() ([]cloudprovider.ICloudEIP, error) {
|
||||
if lb.AddressType == "internet" {
|
||||
eip := SEipAddress{
|
||||
region: lb.region,
|
||||
@@ -313,17 +313,18 @@ func (lb *SLoadbalancer) GetIEIP() (cloudprovider.ICloudEIP, error) {
|
||||
Bandwidth: lb.Bandwidth,
|
||||
InternetChargeType: lb.InternetChargeType,
|
||||
}
|
||||
return &eip, nil
|
||||
return []cloudprovider.ICloudEIP{&eip}, nil
|
||||
}
|
||||
eips, total, err := lb.region.GetEips("", lb.LoadBalancerId, 0, 1)
|
||||
eips, _, err := lb.region.GetEips("", lb.LoadBalancerId, 0, 1)
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(err, "lb.region.GetEips(%s)", lb.LoadBalancerId)
|
||||
}
|
||||
if total != 1 {
|
||||
return nil, cloudprovider.ErrNotFound
|
||||
ret := []cloudprovider.ICloudEIP{}
|
||||
for i := range eips {
|
||||
eips[i].region = lb.region
|
||||
ret = append(ret, &eips[i])
|
||||
}
|
||||
eips[0].region = lb.region
|
||||
return &eips[0], nil
|
||||
return ret, nil
|
||||
}
|
||||
|
||||
func (region *SRegion) loadbalancerOperation(loadbalancerId, status string) error {
|
||||
|
||||
+2
@@ -113,6 +113,8 @@ func (self *SEipAddress) GetAssociationType() string {
|
||||
switch net.InterfaceType {
|
||||
case "nat_gateway":
|
||||
return api.EIP_ASSOCIATE_TYPE_NAT_GATEWAY
|
||||
case "network_load_balancer":
|
||||
return api.EIP_ASSOCIATE_TYPE_LOADBALANCER
|
||||
default:
|
||||
return net.InterfaceType
|
||||
}
|
||||
|
||||
+14
-2
@@ -284,8 +284,20 @@ func (self *SElb) GetILoadBalancerListenerById(listenerId string) (cloudprovider
|
||||
return lis, nil
|
||||
}
|
||||
|
||||
func (self *SElb) GetIEIP() (cloudprovider.ICloudEIP, error) {
|
||||
return nil, nil
|
||||
func (self *SElb) GetIEIPs() ([]cloudprovider.ICloudEIP, error) {
|
||||
ret := []cloudprovider.ICloudEIP{}
|
||||
for _, zone := range self.AvailabilityZones {
|
||||
for _, addr := range zone.LoadBalancerAddresses {
|
||||
if len(addr.IPAddress) > 0 && strings.Contains(addr.AllocationID, "eip") {
|
||||
eip, err := self.region.GetEipByIpAddress(addr.IPAddress)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
ret = append(ret, eip)
|
||||
}
|
||||
}
|
||||
}
|
||||
return ret, nil
|
||||
}
|
||||
|
||||
func (self *SRegion) DeleteElb(id string) error {
|
||||
|
||||
+4
-3
@@ -188,21 +188,22 @@ func (self *SLoadbalancer) GetEgressMbps() int {
|
||||
return 0
|
||||
}
|
||||
|
||||
func (self *SLoadbalancer) GetIEIP() (cloudprovider.ICloudEIP, error) {
|
||||
func (self *SLoadbalancer) GetIEIPs() ([]cloudprovider.ICloudEIP, error) {
|
||||
properties, err := self.GetProperties()
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(err, "GetProperties")
|
||||
}
|
||||
ret := []cloudprovider.ICloudEIP{}
|
||||
for _, front := range properties.FrontendIPConfigurations {
|
||||
if len(front.Properties.PublicIPAddress.ID) > 0 {
|
||||
eip, err := self.region.GetEip(front.Properties.PublicIPAddress.ID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return eip, nil
|
||||
ret = append(ret, eip)
|
||||
}
|
||||
}
|
||||
return nil, cloudprovider.ErrNotFound
|
||||
return ret, nil
|
||||
}
|
||||
|
||||
func (self *SLoadbalancer) Delete(ctx context.Context) error {
|
||||
|
||||
+3
-3
@@ -50,11 +50,11 @@ type SAddress struct {
|
||||
func (region *SRegion) GetEips(address string, maxResults int, pageToken string) ([]SAddress, error) {
|
||||
eips := []SAddress{}
|
||||
params := map[string]string{}
|
||||
filters := []string{"addressType=EXTERNAL"}
|
||||
filters := []string{`(addressType eq "EXTERNAL")`}
|
||||
if len(address) > 0 {
|
||||
filters = append(filters, fmt.Sprintf(`address="%s"`, address))
|
||||
filters = append(filters, fmt.Sprintf(`(address eq "%s")`, address))
|
||||
}
|
||||
params["filter"] = strings.Join(filters, " ADN ")
|
||||
params["filter"] = strings.Join(filters, "")
|
||||
resource := fmt.Sprintf("regions/%s/addresses", region.Name)
|
||||
return eips, region.List(resource, params, maxResults, pageToken, &eips)
|
||||
}
|
||||
|
||||
+6
-6
@@ -107,12 +107,12 @@ func (self *SGlobalLoadbalancer) GetProjectId() string {
|
||||
return ""
|
||||
}
|
||||
|
||||
func (self *SGlobalLoadbalancer) GetIEIP() (cloudprovider.ICloudEIP, error) {
|
||||
func (self *SGlobalLoadbalancer) GetIEIPs() ([]cloudprovider.ICloudEIP, error) {
|
||||
frs, err := self.GetForwardingRules()
|
||||
if err != nil {
|
||||
log.Errorf("GetAddress.GetForwardingRules %s", err)
|
||||
}
|
||||
|
||||
ret := []cloudprovider.ICloudEIP{}
|
||||
for i := range frs {
|
||||
if strings.ToLower(frs[i].LoadBalancingScheme) == "external" {
|
||||
eips, err := self.region.GetEips(frs[i].IPAddress)
|
||||
@@ -120,13 +120,13 @@ func (self *SGlobalLoadbalancer) GetIEIP() (cloudprovider.ICloudEIP, error) {
|
||||
log.Errorf("GetEips %s", err)
|
||||
}
|
||||
|
||||
if len(eips) > 0 {
|
||||
return &eips[0], nil
|
||||
for j := range eips {
|
||||
eips[j].region = self.region
|
||||
ret = append(ret, &eips[j])
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return nil, nil
|
||||
return ret, nil
|
||||
}
|
||||
|
||||
func (self *SGlobalLoadbalancer) GetAddress() string {
|
||||
|
||||
+6
-5
@@ -242,26 +242,27 @@ func (self *SLoadbalancer) GetEgressMbps() int {
|
||||
return 0
|
||||
}
|
||||
|
||||
func (self *SLoadbalancer) GetIEIP() (cloudprovider.ICloudEIP, error) {
|
||||
func (self *SLoadbalancer) GetIEIPs() ([]cloudprovider.ICloudEIP, error) {
|
||||
frs, err := self.GetForwardingRules()
|
||||
if err != nil {
|
||||
log.Errorf("GetAddress.GetForwardingRules %s", err)
|
||||
}
|
||||
|
||||
ret := []cloudprovider.ICloudEIP{}
|
||||
for i := range frs {
|
||||
if strings.ToLower(frs[i].LoadBalancingScheme) == "external" {
|
||||
eips, err := self.region.GetEips(frs[i].IPAddress, 0, "")
|
||||
if err != nil {
|
||||
log.Errorf("GetEips %s", err)
|
||||
}
|
||||
|
||||
if len(eips) > 0 {
|
||||
return &eips[0], nil
|
||||
for j := range eips {
|
||||
eips[j].region = self.region
|
||||
ret = append(ret, &eips[j])
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return nil, nil
|
||||
return ret, nil
|
||||
}
|
||||
|
||||
func (self *SLoadbalancer) Delete(ctx context.Context) error {
|
||||
|
||||
+2
-2
@@ -86,12 +86,12 @@ type Pool struct {
|
||||
ID string `json:"id"`
|
||||
}
|
||||
|
||||
func (self *SLoadbalancer) GetIEIP() (cloudprovider.ICloudEIP, error) {
|
||||
func (self *SLoadbalancer) GetIEIPs() ([]cloudprovider.ICloudEIP, error) {
|
||||
if self.GetEip() == nil {
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
return self.eip, nil
|
||||
return []cloudprovider.ICloudEIP{self.eip}, nil
|
||||
}
|
||||
|
||||
func (self *SLoadbalancer) GetId() string {
|
||||
|
||||
+4
-20
@@ -93,7 +93,8 @@ type Pool struct {
|
||||
Id string `json:"id"`
|
||||
}
|
||||
|
||||
func (self *SLoadbalancer) GetEip() (*SEipAddress, error) {
|
||||
func (self *SLoadbalancer) GetIEIPs() ([]cloudprovider.ICloudEIP, error) {
|
||||
ret := []cloudprovider.ICloudEIP{}
|
||||
for _, ip := range self.Publicips {
|
||||
if ip.IpVersion != "4" {
|
||||
continue
|
||||
@@ -102,17 +103,9 @@ func (self *SLoadbalancer) GetEip() (*SEipAddress, error) {
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return eip, nil
|
||||
ret = append(ret, eip)
|
||||
}
|
||||
return nil, cloudprovider.ErrNotFound
|
||||
}
|
||||
|
||||
func (self *SLoadbalancer) GetIEIP() (cloudprovider.ICloudEIP, error) {
|
||||
eip, err := self.GetEip()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return eip, nil
|
||||
return ret, nil
|
||||
}
|
||||
|
||||
func (self *SLoadbalancer) GetId() string {
|
||||
@@ -212,19 +205,10 @@ func (self *SLoadbalancer) GetLoadbalancerSpec() string {
|
||||
}
|
||||
|
||||
func (self *SLoadbalancer) GetChargeType() string {
|
||||
eip, _ := self.GetEip()
|
||||
if eip != nil {
|
||||
return eip.GetInternetChargeType()
|
||||
}
|
||||
return api.EIP_CHARGE_TYPE_BY_TRAFFIC
|
||||
}
|
||||
|
||||
func (self *SLoadbalancer) GetEgressMbps() int {
|
||||
eip, _ := self.GetEip()
|
||||
if eip != nil {
|
||||
return eip.GetBandwidth()
|
||||
}
|
||||
|
||||
return 0
|
||||
}
|
||||
|
||||
|
||||
+1
-1
@@ -23,7 +23,7 @@ type SLoadbalancerBase struct {
|
||||
SVirtualResourceBase
|
||||
}
|
||||
|
||||
func (lb *SLoadbalancerBase) GetIEIP() (cloudprovider.ICloudEIP, error) {
|
||||
func (lb *SLoadbalancerBase) GetIEIPs() ([]cloudprovider.ICloudEIP, error) {
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
|
||||
+3
-3
@@ -828,7 +828,7 @@ func (region *SRegion) LiveMigrateVM(instanceId string, hostName string) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
//仅live-migration
|
||||
// 仅live-migration
|
||||
func (region *SRegion) ListServerMigration(instanceId string) error {
|
||||
resource := fmt.Sprintf("/servers/%s/migrations", instanceId)
|
||||
_, err := region.ecsGet(resource)
|
||||
@@ -838,7 +838,7 @@ func (region *SRegion) ListServerMigration(instanceId string) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
//仅live-migration
|
||||
// 仅live-migration
|
||||
func (region *SRegion) DeleteMigration(instanceId string, migrationId string) error {
|
||||
resource := fmt.Sprintf("/servers/%s/migrations/%s", instanceId, migrationId)
|
||||
_, err := region.ecsDelete(resource)
|
||||
@@ -848,7 +848,7 @@ func (region *SRegion) DeleteMigration(instanceId string, migrationId string) er
|
||||
return nil
|
||||
}
|
||||
|
||||
//仅live-migration
|
||||
// 仅live-migration
|
||||
func (region *SRegion) ForceCompleteMigration(instanceId string, migrationId string) error {
|
||||
params := jsonutils.NewDict()
|
||||
params.Add(jsonutils.JSONNull, "force_complete")
|
||||
|
||||
+4
-7
@@ -182,7 +182,7 @@ func (lb *SLoadbalancer) GetAddress() string {
|
||||
}
|
||||
|
||||
func (lb *SLoadbalancer) GetAddressType() string {
|
||||
eip, err := lb.GetIEIP()
|
||||
eip, err := lb.GetIEIPs()
|
||||
if err != nil {
|
||||
return api.LB_ADDR_TYPE_INTRANET
|
||||
}
|
||||
@@ -368,13 +368,10 @@ func (lb *SLoadbalancer) GetLoadbalancerSpec() string {
|
||||
}
|
||||
|
||||
func (lb *SLoadbalancer) GetChargeType() string {
|
||||
eip, err := lb.GetIEIP()
|
||||
_, err := lb.GetIEIPs()
|
||||
if err != nil {
|
||||
log.Errorf("lb.GetIEIP(): %s", err)
|
||||
}
|
||||
if err != nil {
|
||||
return eip.GetInternetChargeType()
|
||||
}
|
||||
|
||||
return api.EIP_CHARGE_TYPE_BY_TRAFFIC
|
||||
}
|
||||
@@ -407,14 +404,14 @@ func (lb *SLoadbalancer) GetILoadBalancerBackendGroupById(poolId string) (cloudp
|
||||
return spool, nil
|
||||
}
|
||||
|
||||
func (lb *SLoadbalancer) GetIEIP() (cloudprovider.ICloudEIP, error) {
|
||||
func (lb *SLoadbalancer) GetIEIPs() ([]cloudprovider.ICloudEIP, error) {
|
||||
eips, err := lb.region.GetEips("")
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(err, "lb.region.GetEips()")
|
||||
}
|
||||
for _, eip := range eips {
|
||||
if eip.PortId == lb.VipPortID {
|
||||
return &eip, nil
|
||||
return []cloudprovider.ICloudEIP{&eip}, nil
|
||||
}
|
||||
}
|
||||
return nil, nil
|
||||
|
||||
+3
-3
@@ -309,16 +309,16 @@ func (self *SLoadbalancer) GetILoadBalancerBackendGroups() ([]cloudprovider.IClo
|
||||
return ret, nil
|
||||
}
|
||||
|
||||
func (self *SLoadbalancer) GetIEIP() (cloudprovider.ICloudEIP, error) {
|
||||
func (self *SLoadbalancer) GetIEIPs() ([]cloudprovider.ICloudEIP, error) {
|
||||
if self.LoadBalancerType == "OPEN" && len(self.LoadBalancerVips) > 0 {
|
||||
return &SEipAddress{
|
||||
return []cloudprovider.ICloudEIP{&SEipAddress{
|
||||
region: self.region,
|
||||
AddressId: self.LoadBalancerId,
|
||||
AddressIp: self.LoadBalancerVips[0],
|
||||
AddressType: EIP_STATUS_BIND,
|
||||
InstanceId: self.LoadBalancerId,
|
||||
CreatedTime: self.CreateTime,
|
||||
}, nil
|
||||
}}, nil
|
||||
}
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
+1
-1
@@ -79,7 +79,7 @@ func (self *SLoadbalancer) GetEgressMbps() int {
|
||||
return self.Bandwidth
|
||||
}
|
||||
|
||||
func (self *SLoadbalancer) GetIEIP() (cloudprovider.ICloudEIP, error) {
|
||||
func (self *SLoadbalancer) GetIEIPs() ([]cloudprovider.ICloudEIP, error) {
|
||||
return nil, cloudprovider.ErrNotImplemented
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user