mirror of
https://github.com/yunionio/cloudpods.git
synced 2026-09-19 10:46:58 +08:00
elasticips: onecloud: support changing bandwidth
This commit is contained in:
@@ -1312,13 +1312,15 @@ func (self *SElasticip) PerformChangeBandwidth(ctx context.Context, userCred mcc
|
||||
return nil, httperrors.NewInputParameterError("Invalid bandwidth")
|
||||
}
|
||||
|
||||
factory, err := self.GetProviderFactory()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if self.IsManaged() {
|
||||
factory, err := self.GetProviderFactory()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if err := factory.ValidateChangeBandwidth(self.AssociateId, bandwidth); err != nil {
|
||||
return nil, httperrors.NewInputParameterError(err.Error())
|
||||
if err := factory.ValidateChangeBandwidth(self.AssociateId, bandwidth); err != nil {
|
||||
return nil, httperrors.NewInputParameterError(err.Error())
|
||||
}
|
||||
}
|
||||
|
||||
err = self.StartEipChangeBandwidthTask(ctx, userCred, bandwidth)
|
||||
|
||||
@@ -44,14 +44,6 @@ func (self *EipChangeBandwidthTask) TaskFail(ctx context.Context, eip *models.SE
|
||||
|
||||
func (self *EipChangeBandwidthTask) OnInit(ctx context.Context, obj db.IStandaloneModel, data jsonutils.JSONObject) {
|
||||
eip := obj.(*models.SElasticip)
|
||||
|
||||
extEip, err := eip.GetIEip()
|
||||
if err != nil {
|
||||
msg := fmt.Sprintf("fail to find iEip %s", err)
|
||||
self.TaskFail(ctx, eip, msg)
|
||||
return
|
||||
}
|
||||
|
||||
bandwidth, _ := self.Params.Int("bandwidth")
|
||||
if bandwidth <= 0 {
|
||||
msg := fmt.Sprintf("invalid bandwidth %d", bandwidth)
|
||||
@@ -59,22 +51,29 @@ func (self *EipChangeBandwidthTask) OnInit(ctx context.Context, obj db.IStandalo
|
||||
return
|
||||
}
|
||||
|
||||
err = extEip.ChangeBandwidth(int(bandwidth))
|
||||
if eip.IsManaged() {
|
||||
extEip, err := eip.GetIEip()
|
||||
if err != nil {
|
||||
msg := fmt.Sprintf("fail to find iEip %s", err)
|
||||
self.TaskFail(ctx, eip, msg)
|
||||
return
|
||||
}
|
||||
|
||||
err = extEip.ChangeBandwidth(int(bandwidth))
|
||||
|
||||
if err != nil {
|
||||
msg := fmt.Sprintf("fail to find iEip %s", err)
|
||||
self.TaskFail(ctx, eip, msg)
|
||||
return
|
||||
}
|
||||
|
||||
if err != nil {
|
||||
msg := fmt.Sprintf("fail to find iEip %s", err)
|
||||
self.TaskFail(ctx, eip, msg)
|
||||
return
|
||||
}
|
||||
|
||||
err = eip.DoChangeBandwidth(self.UserCred, int(bandwidth))
|
||||
|
||||
if err != nil {
|
||||
if err := eip.DoChangeBandwidth(self.UserCred, int(bandwidth)); err != nil {
|
||||
msg := fmt.Sprintf("fail to synchronize iEip bandwidth %s", err)
|
||||
self.TaskFail(ctx, eip, msg)
|
||||
return
|
||||
}
|
||||
|
||||
logclient.AddActionLogWithStartable(self, eip, logclient.ACT_CHANGE_BANDWIDTH, nil, self.UserCred, true)
|
||||
self.SetStageComplete(ctx, nil)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user