mirror of
https://github.com/yunionio/cloudpods.git
synced 2026-09-24 16:03:43 +08:00
Merge pull request #5131 from tb365/automated-cherry-pick-of-#5130-upstream-release-3.1
Automated cherry pick of #5130: huawei sync fix
This commit is contained in:
@@ -221,7 +221,7 @@ func (self *SManagedVirtualizedGuestDriver) RequestAttachDisk(ctx context.Contex
|
||||
return nil, errors.Wrapf(err, "iVM.AttachDisk")
|
||||
}
|
||||
|
||||
err = cloudprovider.Wait(time.Second*5, time.Minute*3, func() (bool, error) {
|
||||
err = cloudprovider.Wait(time.Second*10, time.Minute*6, func() (bool, error) {
|
||||
err := iVM.Refresh()
|
||||
if err != nil {
|
||||
return false, errors.Wrapf(err, "iVM.Refresh")
|
||||
|
||||
@@ -4377,8 +4377,8 @@ func (self *SGuest) getSecgroupExternalIds(provider *SCloudprovider) []string {
|
||||
return externalIds
|
||||
}
|
||||
|
||||
func (self *SGuest) getSecgroupByCache(provider *SCloudprovider, externalId string) (*SSecurityGroup, error) {
|
||||
q := SecurityGroupCacheManager.Query().Equals("manager_id", provider.Id).Equals("external_id", externalId)
|
||||
func (self *SGuest) getSecgroupByCache(provider *SCloudprovider, vpcId string, externalId string) (*SSecurityGroup, error) {
|
||||
q := SecurityGroupCacheManager.Query().Equals("manager_id", provider.Id).Equals("external_id", externalId).Equals("vpc_id", vpcId)
|
||||
cache := SSecurityGroupCache{}
|
||||
cache.SetModelManager(SecurityGroupCacheManager, &cache)
|
||||
count, err := q.CountWithError()
|
||||
@@ -4412,11 +4412,17 @@ func (self *SGuest) setSecgroupPublicScope(secgroup *SSecurityGroup) error {
|
||||
func (self *SGuest) SyncVMSecgroups(ctx context.Context, userCred mcclient.TokenCredential, provider *SCloudprovider, secgroupIds []string) compare.SyncResult {
|
||||
syncResult := compare.SyncResult{}
|
||||
|
||||
vpc, err := self.GetVpc()
|
||||
if err != nil {
|
||||
syncResult.AddError(err)
|
||||
return syncResult
|
||||
}
|
||||
|
||||
secgroupExternalIds := self.getSecgroupExternalIds(provider)
|
||||
|
||||
_secgroupIds := []string{}
|
||||
for _, secgroupId := range secgroupIds {
|
||||
secgroup, err := self.getSecgroupByCache(provider, secgroupId)
|
||||
secgroup, err := self.getSecgroupByCache(provider, vpc.GetId(), secgroupId)
|
||||
if err != nil {
|
||||
syncResult.AddError(err)
|
||||
continue
|
||||
|
||||
@@ -134,6 +134,11 @@ func (self *SEip) GetINetworkId() string {
|
||||
func (self *SEip) GetAssociationType() string {
|
||||
orders, err := self.region.GetOrder(self.WorkOrderResourceID)
|
||||
if err != nil {
|
||||
// bugfix: 由于没有接口可以返向查询出关联的device,这里默认关联的是server?
|
||||
if len(self.PortID) > 0 || len(self.PrivateIPAddress) > 0 {
|
||||
return api.EIP_ASSOCIATE_TYPE_SERVER
|
||||
}
|
||||
|
||||
log.Errorf("SEip.GetAssociationType %s", err)
|
||||
return ""
|
||||
}
|
||||
|
||||
@@ -41,6 +41,11 @@ func (self *SStoragecache) DownloadImage(userCred mcclient.TokenCredential, imag
|
||||
}
|
||||
|
||||
func (self *SStoragecache) UploadImage(ctx context.Context, userCred mcclient.TokenCredential, image *cloudprovider.SImageCreateOption, isForce bool) (string, error) {
|
||||
img, err := self.region.GetImage(image.ExternalId)
|
||||
if err == nil {
|
||||
return img.GetGlobalId(), nil
|
||||
}
|
||||
|
||||
return "", cloudprovider.ErrNotSupported
|
||||
}
|
||||
|
||||
|
||||
@@ -16,7 +16,6 @@ package huawei
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"yunion.io/x/jsonutils"
|
||||
@@ -165,15 +164,10 @@ func (self *SEipAddress) GetPort() *Port {
|
||||
func (self *SEipAddress) GetAssociationType() string {
|
||||
port := self.GetPort()
|
||||
if port != nil {
|
||||
return port.DeviceID
|
||||
return port.GetAssociateType()
|
||||
}
|
||||
|
||||
owner := port.DeviceOwner
|
||||
if strings.Contains(owner, "LOADBALANCER") {
|
||||
return api.EIP_ASSOCIATE_TYPE_ELB
|
||||
} else {
|
||||
return api.EIP_ASSOCIATE_TYPE_SERVER
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
func (self *SEipAddress) GetAssociationExternalId() string {
|
||||
|
||||
@@ -15,6 +15,8 @@
|
||||
package huawei
|
||||
|
||||
import (
|
||||
"strings"
|
||||
|
||||
"yunion.io/x/pkg/utils"
|
||||
|
||||
api "yunion.io/x/onecloud/pkg/apis/compute"
|
||||
@@ -80,6 +82,7 @@ func (port *Port) GetMacAddress() string {
|
||||
return port.MACAddress
|
||||
}
|
||||
|
||||
// https://support.huaweicloud.com/api-vpc/zh-cn_topic_0133195888.html
|
||||
func (port *Port) GetAssociateType() string {
|
||||
switch port.DeviceOwner {
|
||||
case "compute:nova":
|
||||
@@ -92,6 +95,10 @@ func (port *Port) GetAssociateType() string {
|
||||
return api.NETWORK_INTERFACE_ASSOCIATE_TYPE_LOADBALANCER
|
||||
case "neutron:VIP_PORT":
|
||||
return api.NETWORK_INTERFACE_ASSOCIATE_TYPE_VIP
|
||||
default:
|
||||
if strings.HasPrefix(port.DeviceOwner, "compute:") {
|
||||
return api.NETWORK_INTERFACE_ASSOCIATE_TYPE_SERVER
|
||||
}
|
||||
}
|
||||
return port.DeviceOwner
|
||||
}
|
||||
|
||||
@@ -145,6 +145,10 @@ func (self *SRegion) fetchIVpcs() error {
|
||||
}
|
||||
|
||||
func (self *SRegion) GetIVMById(id string) (cloudprovider.ICloudVM, error) {
|
||||
if len(id) == 0 {
|
||||
return nil, errors.Wrap(cloudprovider.ErrNotFound, "SRegion.GetIVMById")
|
||||
}
|
||||
|
||||
instance, err := self.GetInstanceByID(id)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
||||
Reference in New Issue
Block a user