mirror of
https://github.com/yunionio/cloudpods.git
synced 2026-09-24 16:03:43 +08:00
Merge pull request #3806 from tb365/bugfix/tb-bugfix-112001
Bugfix/tb bugfix 112001
This commit is contained in:
@@ -18,6 +18,7 @@ import (
|
||||
"context"
|
||||
"fmt"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"yunion.io/x/jsonutils"
|
||||
"yunion.io/x/pkg/errors"
|
||||
@@ -186,6 +187,11 @@ func (self *SAwsGuestDriver) RequestAssociateEip(ctx context.Context, userCred m
|
||||
return nil, fmt.Errorf("SAwsGuestDriver.RequestAssociateEip fail to remote associate EIP %s", err)
|
||||
}
|
||||
|
||||
err = cloudprovider.WaitStatus(extEip, api.EIP_STATUS_READY, 3*time.Second, 60*time.Second)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "SAwsGuestDriver.RequestAssociateEip.WaitStatus")
|
||||
}
|
||||
|
||||
err = eip.AssociateVM(ctx, userCred, server)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("SAwsGuestDriver.RequestAssociateEip fail to local associate EIP %s", err)
|
||||
|
||||
@@ -984,6 +984,11 @@ func (self *SManagedVirtualizedGuestDriver) RequestAssociateEip(ctx context.Cont
|
||||
return nil, fmt.Errorf("ManagedVirtualizedGuestDriver.RequestAssociateEip fail to remote associate EIP %s", err)
|
||||
}
|
||||
|
||||
err = cloudprovider.WaitStatus(extEip, api.EIP_STATUS_READY, 3*time.Second, 60*time.Second)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "ManagedVirtualizedGuestDriver.RequestAssociateEip.WaitStatus")
|
||||
}
|
||||
|
||||
err = eip.AssociateVM(ctx, userCred, server)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("ManagedVirtualizedGuestDriver.RequestAssociateEip fail to local associate EIP %s", err)
|
||||
|
||||
@@ -256,12 +256,19 @@ func (self *SElasticcacheAcl) ValidateUpdateData(ctx context.Context, userCred m
|
||||
}
|
||||
|
||||
ipV := validators.NewIPv4AddrValidator("ip")
|
||||
cidrV := validators.NewIPv4PrefixValidator("ip")
|
||||
_ips := strings.Split(ips, ",")
|
||||
for _, ip := range _ips {
|
||||
params := jsonutils.NewDict()
|
||||
params.Set("ip", jsonutils.NewString(ip))
|
||||
if err := ipV.Validate(params); err != nil {
|
||||
return nil, err
|
||||
if strings.Contains(ip, "/") {
|
||||
if err := cidrV.Validate(params); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
} else {
|
||||
if err := ipV.Validate(params); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -106,19 +106,7 @@ func (self *SElasticcache) getCloudProviderInfo() SCloudProviderInfo {
|
||||
return MakeCloudProviderInfo(region, zone, provider)
|
||||
}
|
||||
|
||||
func (self *SElasticcache) GetExtraDetails(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject) (*jsonutils.JSONDict, error) {
|
||||
extra, err := self.SStatusStandaloneResourceBase.GetExtraDetails(ctx, userCred, query)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
info := self.getCloudProviderInfo()
|
||||
extra.Update(jsonutils.Marshal(&info))
|
||||
return extra, nil
|
||||
}
|
||||
|
||||
func (self *SElasticcache) GetCustomizeColumns(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject) *jsonutils.JSONDict {
|
||||
extra := self.SStatusStandaloneResourceBase.GetCustomizeColumns(ctx, userCred, query)
|
||||
func (self *SElasticcache) updateExtraDetails(ctx context.Context, userCred mcclient.TokenCredential, extra *jsonutils.JSONDict) *jsonutils.JSONDict {
|
||||
info := self.getCloudProviderInfo()
|
||||
extra.Update(jsonutils.Marshal(&info))
|
||||
|
||||
@@ -131,9 +119,25 @@ func (self *SElasticcache) GetCustomizeColumns(ctx context.Context, userCred mcc
|
||||
if err == nil {
|
||||
extra.Set("network", jsonutils.NewString(network.GetName()))
|
||||
}
|
||||
|
||||
return extra
|
||||
}
|
||||
|
||||
func (self *SElasticcache) GetExtraDetails(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject) (*jsonutils.JSONDict, error) {
|
||||
extra, err := self.SStatusStandaloneResourceBase.GetExtraDetails(ctx, userCred, query)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return self.updateExtraDetails(ctx, userCred, extra), nil
|
||||
}
|
||||
|
||||
func (self *SElasticcache) GetCustomizeColumns(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject) *jsonutils.JSONDict {
|
||||
extra := self.SStatusStandaloneResourceBase.GetCustomizeColumns(ctx, userCred, query)
|
||||
|
||||
return self.updateExtraDetails(ctx, userCred, extra)
|
||||
}
|
||||
|
||||
func (self *SElasticcache) GetElasticcacheParameters() ([]SElasticcacheParameter, error) {
|
||||
ret := []SElasticcacheParameter{}
|
||||
q := ElasticcacheParameterManager.Query().Equals("elasticcache_id", self.Id)
|
||||
|
||||
@@ -733,11 +733,11 @@ func (self *SElasticip) PostCreate(ctx context.Context, userCred mcclient.TokenC
|
||||
log.Errorf("SElasticip CancelPendingUsage error: %s", err)
|
||||
}
|
||||
|
||||
self.startEipAllocateTask(ctx, userCred, data.(*jsonutils.JSONDict))
|
||||
self.startEipAllocateTask(ctx, userCred, data.(*jsonutils.JSONDict), "")
|
||||
}
|
||||
|
||||
func (self *SElasticip) startEipAllocateTask(ctx context.Context, userCred mcclient.TokenCredential, params *jsonutils.JSONDict) error {
|
||||
task, err := taskman.TaskManager.NewTask(ctx, "EipAllocateTask", self, userCred, params, "", "", nil)
|
||||
func (self *SElasticip) startEipAllocateTask(ctx context.Context, userCred mcclient.TokenCredential, params *jsonutils.JSONDict, parentTaskId string) error {
|
||||
task, err := taskman.TaskManager.NewTask(ctx, "EipAllocateTask", self, userCred, params, parentTaskId, "", nil)
|
||||
if err != nil {
|
||||
log.Errorf("newtask EipAllocateTask fail %s", err)
|
||||
return err
|
||||
@@ -1068,7 +1068,7 @@ func (manager *SElasticipManager) NewEipForVMOnHost(ctx context.Context, userCre
|
||||
return &eip, nil
|
||||
}
|
||||
|
||||
func (eip *SElasticip) AllocateAndAssociateVM(ctx context.Context, userCred mcclient.TokenCredential, vm *SGuest) error {
|
||||
func (eip *SElasticip) AllocateAndAssociateVM(ctx context.Context, userCred mcclient.TokenCredential, vm *SGuest, parentTaskId string) error {
|
||||
params := jsonutils.NewDict()
|
||||
params.Add(jsonutils.NewString(vm.ExternalId), "instance_external_id")
|
||||
params.Add(jsonutils.NewString(vm.Id), "instance_id")
|
||||
@@ -1076,7 +1076,7 @@ func (eip *SElasticip) AllocateAndAssociateVM(ctx context.Context, userCred mccl
|
||||
|
||||
vm.SetStatus(userCred, api.VM_ASSOCIATE_EIP, "allocate and associate EIP")
|
||||
|
||||
return eip.startEipAllocateTask(ctx, userCred, params)
|
||||
return eip.startEipAllocateTask(ctx, userCred, params, parentTaskId)
|
||||
}
|
||||
|
||||
func (self *SElasticip) AllowPerformChangeBandwidth(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject, data jsonutils.JSONObject) bool {
|
||||
|
||||
@@ -2833,7 +2833,7 @@ func (self *SGuest) PerformCreateEip(ctx context.Context, userCred mcclient.Toke
|
||||
return nil, httperrors.NewGeneralError(err)
|
||||
}
|
||||
|
||||
err = eip.AllocateAndAssociateVM(ctx, userCred, self)
|
||||
err = eip.AllocateAndAssociateVM(ctx, userCred, self, "")
|
||||
if err != nil {
|
||||
return nil, httperrors.NewGeneralError(err)
|
||||
}
|
||||
|
||||
@@ -2535,6 +2535,15 @@ func (self *SManagedVirtualizationRegionDriver) RequestElasticcacheBackupRestore
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "managedVirtualizationRegionDriver.RequestElasticcacheBackupRestoreInstance.WaitStatusWithDelay")
|
||||
}
|
||||
|
||||
_, err = db.Update(ec, func() error {
|
||||
ec.Status = api.ELASTIC_CACHE_STATUS_RUNNING
|
||||
return nil
|
||||
})
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "managedVirtualizationRegionDriver.RequestElasticcacheBackupRestoreInstance.UpdateStatus")
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
|
||||
@@ -133,7 +133,7 @@ func (self *EipAllocateTask) OnInit(ctx context.Context, obj db.IStandaloneModel
|
||||
|
||||
if self.Params != nil && self.Params.Contains("instance_id") {
|
||||
self.SetStage("on_eip_associate_complete", nil)
|
||||
err = eip.StartEipAssociateTask(ctx, self.UserCred, self.Params, "")
|
||||
err = eip.StartEipAssociateTask(ctx, self.UserCred, self.Params, self.GetId())
|
||||
if err != nil {
|
||||
msg := fmt.Sprintf("start associate task fail %s", err)
|
||||
self.SetStageFailed(ctx, msg)
|
||||
|
||||
@@ -126,10 +126,10 @@ func (self *GuestCreateTask) OnDeployGuestDescComplete(ctx context.Context, obj
|
||||
eipBw, _ := self.Params.Int("eip_bw")
|
||||
if eipBw > 0 {
|
||||
// newly allocated eip, need allocation and associate
|
||||
eip.AllocateAndAssociateVM(ctx, self.UserCred, guest)
|
||||
eip.AllocateAndAssociateVM(ctx, self.UserCred, guest, self.GetId())
|
||||
} else {
|
||||
// existing eip, association only
|
||||
eip.StartEipAssociateInstanceTask(ctx, self.UserCred, guest, "")
|
||||
eip.StartEipAssociateInstanceTask(ctx, self.UserCred, guest, self.GetId())
|
||||
}
|
||||
|
||||
return
|
||||
|
||||
Reference in New Issue
Block a user