mirror of
https://github.com/yunionio/cloudpods.git
synced 2026-09-19 10:46:58 +08:00
Merge pull request #4946 from ioito/hotfix/qx-qcloud-eip-bandwidth
fix: 腾讯云主机带宽跟随eip带宽变化而变化
This commit is contained in:
@@ -22,3 +22,9 @@ type SEip struct {
|
||||
NetworkExternalId string
|
||||
IP string
|
||||
}
|
||||
|
||||
type AssociateConfig struct {
|
||||
InstanceId string
|
||||
AssociateType string
|
||||
Bandwidth int
|
||||
}
|
||||
|
||||
@@ -328,7 +328,7 @@ type ICloudEIP interface {
|
||||
|
||||
Delete() error
|
||||
|
||||
Associate(instanceId string) error
|
||||
Associate(conf *AssociateConfig) error
|
||||
Dissociate() error
|
||||
|
||||
ChangeBandwidth(bw int) error
|
||||
|
||||
@@ -202,7 +202,13 @@ func (self *SAwsGuestDriver) RequestAssociateEip(ctx context.Context, userCred m
|
||||
return nil, fmt.Errorf("SAwsGuestDriver.RequestAssociateEip fail to find iEIP for eip %s", err)
|
||||
}
|
||||
|
||||
err = extEip.Associate(server.ExternalId)
|
||||
conf := &cloudprovider.AssociateConfig{
|
||||
InstanceId: server.ExternalId,
|
||||
Bandwidth: eip.Bandwidth,
|
||||
AssociateType: api.EIP_ASSOCIATE_TYPE_SERVER,
|
||||
}
|
||||
|
||||
err = extEip.Associate(conf)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("SAwsGuestDriver.RequestAssociateEip fail to remote associate EIP %s", err)
|
||||
}
|
||||
|
||||
@@ -1010,7 +1010,13 @@ func (self *SManagedVirtualizedGuestDriver) RequestAssociateEip(ctx context.Cont
|
||||
return nil, fmt.Errorf("ManagedVirtualizedGuestDriver.RequestAssociateEip fail to find iEIP for eip %s", err)
|
||||
}
|
||||
|
||||
err = extEip.Associate(server.ExternalId)
|
||||
conf := &cloudprovider.AssociateConfig{
|
||||
InstanceId: server.ExternalId,
|
||||
Bandwidth: eip.Bandwidth,
|
||||
AssociateType: api.EIP_ASSOCIATE_TYPE_SERVER,
|
||||
}
|
||||
|
||||
err = extEip.Associate(conf)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("ManagedVirtualizedGuestDriver.RequestAssociateEip fail to remote associate EIP %s", err)
|
||||
}
|
||||
|
||||
@@ -237,7 +237,11 @@ func (self *SOpenStackGuestDriver) RemoteDeployGuestForRebuildRoot(ctx context.C
|
||||
if err != nil {
|
||||
return "", errors.Wrap(err, "ieip.Dissociate")
|
||||
}
|
||||
defer ieip.Associate(instanceId)
|
||||
conf := &cloudprovider.AssociateConfig{
|
||||
InstanceId: instanceId,
|
||||
AssociateType: api.EIP_ASSOCIATE_TYPE_SERVER,
|
||||
}
|
||||
defer ieip.Associate(conf)
|
||||
}
|
||||
err = iVM.DeleteVM(ctx)
|
||||
if err != nil {
|
||||
|
||||
@@ -343,7 +343,9 @@ func (self *SElasticip) SyncWithCloudEip(ctx context.Context, userCred mcclient.
|
||||
diff, err := db.UpdateWithLock(ctx, self, func() error {
|
||||
|
||||
// self.Name = ext.GetName()
|
||||
self.Bandwidth = ext.GetBandwidth()
|
||||
if bandwidth := ext.GetBandwidth(); bandwidth != 0 {
|
||||
self.Bandwidth = bandwidth
|
||||
}
|
||||
self.IpAddr = ext.GetIpAddr()
|
||||
self.Mode = ext.GetMode()
|
||||
self.Status = ext.GetStatus()
|
||||
|
||||
@@ -888,7 +888,12 @@ func (self *SAliyunRegionDriver) RequestBindIPToNatgateway(ctx context.Context,
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "fetch eip failed")
|
||||
}
|
||||
err = ieip.Associate(natgateway.GetExternalId())
|
||||
conf := &cloudprovider.AssociateConfig{
|
||||
InstanceId: natgateway.GetExternalId(),
|
||||
Bandwidth: eip.Bandwidth,
|
||||
AssociateType: api.EIP_ASSOCIATE_TYPE_NAT_GATEWAY,
|
||||
}
|
||||
err = ieip.Associate(conf)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "fail to bind eip to natgateway")
|
||||
}
|
||||
|
||||
@@ -1870,7 +1870,12 @@ func (self *SHuaWeiRegionDriver) RequestCreateLoadbalancer(ctx context.Context,
|
||||
return nil, err
|
||||
}
|
||||
|
||||
err = ieip.Associate(iLoadbalancer.GetGlobalId())
|
||||
conf := &cloudprovider.AssociateConfig{
|
||||
InstanceId: iLoadbalancer.GetGlobalId(),
|
||||
AssociateType: api.EIP_ASSOCIATE_TYPE_LOADBALANCER,
|
||||
}
|
||||
|
||||
err = ieip.Associate(conf)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
@@ -203,9 +203,9 @@ func (self *SEipAddress) GetInternetChargeType() string {
|
||||
}
|
||||
}
|
||||
|
||||
func (self *SEipAddress) Associate(instanceId string) error {
|
||||
func (self *SEipAddress) Associate(conf *cloudprovider.AssociateConfig) error {
|
||||
err := cloudprovider.Wait(20*time.Second, 60*time.Second, func() (bool, error) {
|
||||
err := self.region.AssociateEip(self.AllocationId, instanceId)
|
||||
err := self.region.AssociateEip(self.AllocationId, conf.InstanceId)
|
||||
if err != nil {
|
||||
if isError(err, "IncorrectInstanceStatus") {
|
||||
return false, nil
|
||||
|
||||
@@ -137,8 +137,8 @@ func (self *SEipAddress) Delete() error {
|
||||
return self.region.DeallocateEIP(self.AllocationId)
|
||||
}
|
||||
|
||||
func (self *SEipAddress) Associate(instanceId string) error {
|
||||
err := self.region.AssociateEip(self.AllocationId, instanceId)
|
||||
func (self *SEipAddress) Associate(conf *cloudprovider.AssociateConfig) error {
|
||||
err := self.region.AssociateEip(self.AllocationId, conf.InstanceId)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -45,7 +45,7 @@ type SClassicEipAddress struct {
|
||||
Type string
|
||||
}
|
||||
|
||||
func (self *SClassicEipAddress) Associate(instanceId string) error {
|
||||
func (self *SClassicEipAddress) Associate(conf *cloudprovider.AssociateConfig) error {
|
||||
return cloudprovider.ErrNotImplemented
|
||||
}
|
||||
|
||||
|
||||
@@ -86,8 +86,8 @@ func (region *SRegion) GetEip(eipId string) (*SEipAddress, error) {
|
||||
return &eip, region.client.Get(eipId, []string{}, &eip)
|
||||
}
|
||||
|
||||
func (self *SEipAddress) Associate(instanceId string) error {
|
||||
return self.region.AssociateEip(self.ID, instanceId)
|
||||
func (self *SEipAddress) Associate(conf *cloudprovider.AssociateConfig) error {
|
||||
return self.region.AssociateEip(self.ID, conf.InstanceId)
|
||||
}
|
||||
|
||||
func (region *SRegion) AssociateEip(eipId string, instanceId string) error {
|
||||
|
||||
@@ -190,8 +190,8 @@ func (self *SEip) Delete() error {
|
||||
return self.region.DeleteEip(self.GetId())
|
||||
}
|
||||
|
||||
func (self *SEip) Associate(instanceId string) error {
|
||||
nics, err := self.region.GetNics(instanceId)
|
||||
func (self *SEip) Associate(conf *cloudprovider.AssociateConfig) error {
|
||||
nics, err := self.region.GetNics(conf.InstanceId)
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "Eip.Associate.GetNics")
|
||||
}
|
||||
|
||||
@@ -149,8 +149,8 @@ func (addr *SAddress) Delete() error {
|
||||
return addr.region.Delete(addr.SelfLink)
|
||||
}
|
||||
|
||||
func (addr *SAddress) Associate(instanceId string) error {
|
||||
return addr.region.AssociateInstanceEip(instanceId, addr.Address)
|
||||
func (addr *SAddress) Associate(conf *cloudprovider.AssociateConfig) error {
|
||||
return addr.region.AssociateInstanceEip(conf.InstanceId, addr.Address)
|
||||
}
|
||||
|
||||
func (addr *SAddress) Dissociate() error {
|
||||
|
||||
@@ -229,8 +229,8 @@ func (self *SEipAddress) Delete() error {
|
||||
return self.region.DeallocateEIP(self.ID)
|
||||
}
|
||||
|
||||
func (self *SEipAddress) Associate(instanceId string) error {
|
||||
portId, err := self.region.GetInstancePortId(instanceId)
|
||||
func (self *SEipAddress) Associate(conf *cloudprovider.AssociateConfig) error {
|
||||
portId, err := self.region.GetInstancePortId(conf.InstanceId)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -232,8 +232,8 @@ func (eip *SEipAddress) GetInternetChargeType() string {
|
||||
return api.EIP_CHARGE_TYPE_BY_TRAFFIC
|
||||
}
|
||||
|
||||
func (eip *SEipAddress) Associate(instanceId string) error {
|
||||
return eip.region.AssociateEip(instanceId, eip.ID)
|
||||
func (eip *SEipAddress) Associate(conf *cloudprovider.AssociateConfig) error {
|
||||
return eip.region.AssociateEip(conf.InstanceId, eip.ID)
|
||||
}
|
||||
|
||||
func (eip *SEipAddress) Dissociate() error {
|
||||
|
||||
@@ -203,12 +203,18 @@ func (self *SEipAddress) GetInternetChargeType() string {
|
||||
return api.EIP_CHARGE_TYPE_BY_TRAFFIC
|
||||
}
|
||||
|
||||
func (self *SEipAddress) Associate(instanceId string) error {
|
||||
err := self.region.AssociateEip(self.AddressId, instanceId)
|
||||
func (self *SEipAddress) Associate(conf *cloudprovider.AssociateConfig) error {
|
||||
err := self.region.AssociateEip(self.AddressId, conf.InstanceId)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return cloudprovider.WaitStatus(self, api.EIP_STATUS_READY, 10*time.Second, 180*time.Second)
|
||||
if conf.Bandwidth > 0 {
|
||||
err = self.region.UpdateInstanceBandwidth(conf.InstanceId, conf.Bandwidth)
|
||||
if err != nil {
|
||||
log.Warningf("failed to change instance %s bandwidth -> %d error: %v", conf.InstanceId, conf.Bandwidth, err)
|
||||
}
|
||||
}
|
||||
return cloudprovider.WaitStatusWithDelay(self, api.EIP_STATUS_READY, 5*time.Second, 10*time.Second, 180*time.Second)
|
||||
}
|
||||
|
||||
func (self *SEipAddress) Dissociate() error {
|
||||
@@ -216,16 +222,14 @@ func (self *SEipAddress) Dissociate() error {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return cloudprovider.WaitStatus(self, api.EIP_STATUS_READY, 10*time.Second, 180*time.Second)
|
||||
return cloudprovider.WaitStatusWithDelay(self, api.EIP_STATUS_READY, 5*time.Second, 10*time.Second, 180*time.Second)
|
||||
}
|
||||
|
||||
func (self *SEipAddress) ChangeBandwidth(bw int) error {
|
||||
if self.GetInternetChargeType() == api.EIP_CHARGE_TYPE_BY_TRAFFIC {
|
||||
if len(self.InstanceId) > 0 {
|
||||
return self.region.UpdateInstanceBandwidth(self.InstanceId, bw)
|
||||
}
|
||||
if len(self.InstanceId) > 0 {
|
||||
return self.region.UpdateInstanceBandwidth(self.InstanceId, bw)
|
||||
}
|
||||
return cloudprovider.ErrNotSupported
|
||||
return nil
|
||||
}
|
||||
|
||||
func (region *SRegion) GetEips(eipId string, instanceId string, offset int, limit int) ([]SEipAddress, int, error) {
|
||||
|
||||
@@ -504,6 +504,7 @@ func (self *SRegion) CreateInstance(name string, imageId string, instanceType st
|
||||
params["Placement.Zone"] = zoneId
|
||||
params["InstanceName"] = name
|
||||
|
||||
params["InternetAccessible.InternetMaxBandwidthOut"] = "1"
|
||||
params["InternetAccessible.PublicIpAssigned"] = "FALSE"
|
||||
//params["HostName"] = name
|
||||
if len(keypair) > 0 {
|
||||
|
||||
@@ -196,8 +196,8 @@ func (self *SEip) Delete() error {
|
||||
return self.region.DeallocateEIP(self.GetId())
|
||||
}
|
||||
|
||||
func (self *SEip) Associate(instanceId string) error {
|
||||
return self.region.AssociateEip(self.GetId(), instanceId)
|
||||
func (self *SEip) Associate(conf *cloudprovider.AssociateConfig) error {
|
||||
return self.region.AssociateEip(self.GetId(), conf.InstanceId)
|
||||
}
|
||||
|
||||
func (self *SEip) Dissociate() error {
|
||||
|
||||
@@ -147,8 +147,8 @@ func (eip *SEipAddress) GetInternetChargeType() string {
|
||||
return api.EIP_CHARGE_TYPE_BY_TRAFFIC
|
||||
}
|
||||
|
||||
func (eip *SEipAddress) Associate(instanceId string) error {
|
||||
return eip.region.AssociateEip(instanceId, eip.UUID)
|
||||
func (eip *SEipAddress) Associate(conf *cloudprovider.AssociateConfig) error {
|
||||
return eip.region.AssociateEip(conf.InstanceId, eip.UUID)
|
||||
}
|
||||
|
||||
func (eip *SEipAddress) Dissociate() error {
|
||||
|
||||
Reference in New Issue
Block a user