mirror of
https://github.com/yunionio/cloudpods.git
synced 2026-09-19 10:46:58 +08:00
Merge pull request #699 in YUNIONIO/onecloud from ~QUXUAN/onecloud:hotfix/qx-resolve-conflict-2.4.0 to release/2.4.0
* commit '43decfbc5f3be9b5f919bdb3be0e4a69ca8549f7': 验证eip更改带宽 验证eip更改带宽
This commit is contained in:
@@ -4,6 +4,7 @@ import (
|
||||
"fmt"
|
||||
|
||||
"errors"
|
||||
|
||||
"yunion.io/x/jsonutils"
|
||||
"yunion.io/x/log"
|
||||
)
|
||||
@@ -15,6 +16,7 @@ var (
|
||||
type ICloudProviderFactory interface {
|
||||
GetProvider(providerId, providerName, url, account, secret string) (ICloudProvider, error)
|
||||
GetId() string
|
||||
ValidateChangeBandwidth(instanceId string, bandwidth int64) error
|
||||
}
|
||||
|
||||
type ICloudProvider interface {
|
||||
@@ -49,10 +51,10 @@ func RegisterFactory(factory ICloudProviderFactory) {
|
||||
providerTable[factory.GetId()] = factory
|
||||
}
|
||||
|
||||
func GetProvider(providerId, providerName, accessUrl, account, secret, provider string) (ICloudProvider, error) {
|
||||
func GetProviderDriver(provider string) (ICloudProviderFactory, error) {
|
||||
factory, ok := providerTable[provider]
|
||||
if ok {
|
||||
return factory.GetProvider(providerId, providerName, accessUrl, account, secret)
|
||||
return factory, nil
|
||||
}
|
||||
log.Errorf("Provider %s not registerd", provider)
|
||||
return nil, fmt.Errorf("No such provider %s", provider)
|
||||
@@ -67,6 +69,14 @@ func GetRegistedProviderIds() []string {
|
||||
return providers
|
||||
}
|
||||
|
||||
func GetProvider(providerId, providerName, accessUrl, account, secret, provider string) (ICloudProvider, error) {
|
||||
driver, err := GetProviderDriver(provider)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return driver.GetProvider(providerId, providerName, accessUrl, account, secret)
|
||||
}
|
||||
|
||||
func IsSupported(provider string) bool {
|
||||
_, ok := providerTable[provider]
|
||||
return ok
|
||||
|
||||
@@ -404,6 +404,10 @@ func (self *SCloudprovider) MarkStartSync(userCred mcclient.TokenCredential) {
|
||||
self.SetStatus(userCred, CLOUD_PROVIDER_START_SYNC, "")
|
||||
}
|
||||
|
||||
func (self *SCloudprovider) GetProviderDriver() (cloudprovider.ICloudProviderFactory, error) {
|
||||
return cloudprovider.GetProviderDriver(self.Provider)
|
||||
}
|
||||
|
||||
func (self *SCloudprovider) GetDriver() (cloudprovider.ICloudProvider, error) {
|
||||
if !self.Enabled {
|
||||
return nil, fmt.Errorf("Cloud provider is not enabled")
|
||||
|
||||
@@ -746,6 +746,13 @@ func (self *SElasticip) AllowPerformChangeBandwidth(ctx context.Context, userCre
|
||||
return self.IsOwner(userCred) || db.IsAdminAllowPerform(userCred, self, "change-bandwidth")
|
||||
}
|
||||
|
||||
func (self *SElasticip) GetProviderDriver() (cloudprovider.ICloudProviderFactory, error) {
|
||||
if provider := self.GetCloudprovider(); provider != nil {
|
||||
return provider.GetProviderDriver()
|
||||
}
|
||||
return nil, fmt.Errorf("failed to find provider for eip %s", self.Name)
|
||||
}
|
||||
|
||||
func (self *SElasticip) PerformChangeBandwidth(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject, data jsonutils.JSONObject) (jsonutils.JSONObject, error) {
|
||||
if self.Status != EIP_STATUS_READY {
|
||||
return nil, httperrors.NewInvalidStatusError("cannot change bandwidth in status %s", self.Status)
|
||||
@@ -755,6 +762,16 @@ func (self *SElasticip) PerformChangeBandwidth(ctx context.Context, userCred mcc
|
||||
if err != nil || bandwidth <= 0 {
|
||||
return nil, httperrors.NewInputParameterError("Invalid bandwidth")
|
||||
}
|
||||
|
||||
dirver, err := self.GetProviderDriver()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if err := dirver.ValidateChangeBandwidth(self.AssociateId, bandwidth); err != nil {
|
||||
return nil, httperrors.NewInputParameterError(err.Error())
|
||||
}
|
||||
|
||||
err = self.StartEipChangeBandwidthTask(ctx, userCred, bandwidth)
|
||||
if err != nil {
|
||||
return nil, httperrors.NewGeneralError(err)
|
||||
|
||||
@@ -15,6 +15,10 @@ func (self *SAliyunProviderFactory) GetId() string {
|
||||
return aliyun.CLOUD_PROVIDER_ALIYUN
|
||||
}
|
||||
|
||||
func (self *SAliyunProviderFactory) ValidateChangeBandwidth(instanceId string, bandwidth int64) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (self *SAliyunProviderFactory) GetProvider(providerId, providerName, url, account, secret string) (cloudprovider.ICloudProvider, error) {
|
||||
/* provider, ok := self.providerTable[providerId]
|
||||
if ok {
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
package provider
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"yunion.io/x/jsonutils"
|
||||
"yunion.io/x/onecloud/pkg/cloudprovider"
|
||||
"yunion.io/x/onecloud/pkg/util/azure"
|
||||
@@ -14,6 +16,10 @@ func (self *SAzureProviderFactory) GetId() string {
|
||||
return azure.CLOUD_PROVIDER_AZURE
|
||||
}
|
||||
|
||||
func (self *SAzureProviderFactory) ValidateChangeBandwidth(instanceId string, bandwidth int64) error {
|
||||
return fmt.Errorf("Changing %s bandwidth is not supported", azure.CLOUD_PROVIDER_AZURE)
|
||||
}
|
||||
|
||||
func (self *SAzureProviderFactory) GetProvider(providerId, providerName, url, account, secret string) (cloudprovider.ICloudProvider, error) {
|
||||
if client, err := azure.NewAzureClient(providerId, providerName, account, secret, url); err != nil {
|
||||
return nil, err
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package provider
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"net/url"
|
||||
"strconv"
|
||||
"strings"
|
||||
@@ -19,6 +20,10 @@ func (self *SESXiProviderFactory) GetId() string {
|
||||
return esxi.CLOUD_PROVIDER_VMWARE
|
||||
}
|
||||
|
||||
func (self *SESXiProviderFactory) ValidateChangeBandwidth(instanceId string, bandwidth int64) error {
|
||||
return fmt.Errorf("Changing %s bandwidth is not supported", esxi.CLOUD_PROVIDER_VMWARE)
|
||||
}
|
||||
|
||||
func parseHostPort(host string, defPort int) (string, int, error) {
|
||||
colonPos := strings.IndexByte(host, ':')
|
||||
if colonPos > 0 {
|
||||
|
||||
Reference in New Issue
Block a user