Skip to content

Commit

Permalink
elasticips: onecloud: support changing bandwidth
Browse files Browse the repository at this point in the history
  • Loading branch information
yousong committed May 28, 2020
1 parent 91defab commit df3c337
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 23 deletions.
14 changes: 8 additions & 6 deletions pkg/compute/models/elasticips.go
Expand Up @@ -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)
Expand Down
33 changes: 16 additions & 17 deletions pkg/compute/tasks/eip_change_bandwidth_task.go
Expand Up @@ -44,37 +44,36 @@ 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)
self.TaskFail(ctx, eip, msg)
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
}

if err != nil {
msg := fmt.Sprintf("fail to find iEip %s", err)
self.TaskFail(ctx, eip, msg)
return
}
err = extEip.ChangeBandwidth(int(bandwidth))

err = eip.DoChangeBandwidth(self.UserCred, int(bandwidth))
if err != nil {
msg := fmt.Sprintf("fail to find iEip %s", err)
self.TaskFail(ctx, eip, msg)
return
}

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)
}

0 comments on commit df3c337

Please sign in to comment.