mirror of
https://github.com/yunionio/cloudpods.git
synced 2026-10-24 12:32:55 +08:00
zstack: use ZstackClientConfig
This commit is contained in:
@@ -89,7 +89,13 @@ func newClient(options *BaseOptions) (*zstack.SRegion, error) {
|
||||
return nil, fmt.Errorf("Missing Password")
|
||||
}
|
||||
|
||||
cli, err := zstack.NewZStackClient("", "", options.AuthURL, options.Username, options.Password, options.Debug)
|
||||
cli, err := zstack.NewZStackClient(
|
||||
zstack.NewZstackClientConfig(
|
||||
options.AuthURL,
|
||||
options.Username,
|
||||
options.Password,
|
||||
).Debug(options.Debug),
|
||||
)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
@@ -77,7 +77,11 @@ func (self *SZStackProviderFactory) ValidateUpdateCloudaccountCredential(ctx con
|
||||
}
|
||||
|
||||
func (self *SZStackProviderFactory) GetProvider(cfg cloudprovider.ProviderConfig) (cloudprovider.ICloudProvider, error) {
|
||||
client, err := zstack.NewZStackClient(cfg.Id, cfg.Name, cfg.URL, cfg.Account, cfg.Secret, false)
|
||||
client, err := zstack.NewZStackClient(
|
||||
zstack.NewZstackClientConfig(
|
||||
cfg.URL, cfg.Account, cfg.Secret,
|
||||
).CloudproviderConfig(cfg),
|
||||
)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
@@ -58,11 +58,11 @@ func (region *SRegion) GetId() string {
|
||||
}
|
||||
|
||||
func (region *SRegion) GetName() string {
|
||||
return region.client.providerName
|
||||
return region.client.cpcfg.Name
|
||||
}
|
||||
|
||||
func (region *SRegion) GetGlobalId() string {
|
||||
return fmt.Sprintf("%s/%s", CLOUD_PROVIDER_ZSTACK, region.client.providerID)
|
||||
return fmt.Sprintf("%s/%s", CLOUD_PROVIDER_ZSTACK, region.client.cpcfg.Id)
|
||||
}
|
||||
|
||||
func (region *SRegion) IsEmulated() bool {
|
||||
|
||||
@@ -41,11 +41,11 @@ func (scache *SStoragecache) GetMetadata() *jsonutils.JSONDict {
|
||||
}
|
||||
|
||||
func (scache *SStoragecache) GetId() string {
|
||||
return fmt.Sprintf("%s-%s/%s", scache.region.client.providerID, scache.region.GetId(), scache.ZoneId)
|
||||
return fmt.Sprintf("%s-%s/%s", scache.region.client.cpcfg.Id, scache.region.GetId(), scache.ZoneId)
|
||||
}
|
||||
|
||||
func (scache *SStoragecache) GetName() string {
|
||||
return fmt.Sprintf("%s-%s/%s", scache.region.client.providerName, scache.region.GetId(), scache.ZoneId)
|
||||
return fmt.Sprintf("%s-%s/%s", scache.region.client.cpcfg.Name, scache.region.GetId(), scache.ZoneId)
|
||||
}
|
||||
|
||||
func (scache *SStoragecache) GetStatus() string {
|
||||
|
||||
@@ -41,7 +41,7 @@ func (vpc *SVpc) GetId() string {
|
||||
}
|
||||
|
||||
func (vpc *SVpc) GetName() string {
|
||||
return fmt.Sprintf("%s-VPC", vpc.region.client.providerName)
|
||||
return fmt.Sprintf("%s-VPC", vpc.region.client.cpcfg.Name)
|
||||
}
|
||||
|
||||
func (vpc *SVpc) GetGlobalId() string {
|
||||
|
||||
@@ -46,18 +46,41 @@ var (
|
||||
SkipEsxi bool = true
|
||||
)
|
||||
|
||||
type SZStackClient struct {
|
||||
providerID string
|
||||
providerName string
|
||||
username string
|
||||
password string
|
||||
authURL string
|
||||
type ZstackClientConfig struct {
|
||||
cpcfg cloudprovider.ProviderConfig
|
||||
|
||||
iregions []cloudprovider.ICloudRegion
|
||||
authURL string
|
||||
username string
|
||||
password string
|
||||
|
||||
debug bool
|
||||
}
|
||||
|
||||
func NewZstackClientConfig(authURL, username, password string) *ZstackClientConfig {
|
||||
cfg := &ZstackClientConfig{
|
||||
authURL: authURL,
|
||||
username: username,
|
||||
password: password,
|
||||
}
|
||||
return cfg
|
||||
}
|
||||
|
||||
func (cfg *ZstackClientConfig) CloudproviderConfig(cpcfg cloudprovider.ProviderConfig) *ZstackClientConfig {
|
||||
cfg.cpcfg = cpcfg
|
||||
return cfg
|
||||
}
|
||||
|
||||
func (cfg *ZstackClientConfig) Debug(debug bool) *ZstackClientConfig {
|
||||
cfg.debug = debug
|
||||
return cfg
|
||||
}
|
||||
|
||||
type SZStackClient struct {
|
||||
*ZstackClientConfig
|
||||
|
||||
iregions []cloudprovider.ICloudRegion
|
||||
}
|
||||
|
||||
func getTime() string {
|
||||
return time.Now().Format("Mon, 02 Jan 2006 15:04:05 MST")
|
||||
}
|
||||
@@ -76,14 +99,9 @@ func getSignUrl(uri string) (string, error) {
|
||||
return strings.TrimPrefix(u.Path, "/zstack"), nil
|
||||
}
|
||||
|
||||
func NewZStackClient(providerID string, providerName string, authURL string, username string, password string, isDebug bool) (*SZStackClient, error) {
|
||||
func NewZStackClient(cfg *ZstackClientConfig) (*SZStackClient, error) {
|
||||
cli := &SZStackClient{
|
||||
providerID: providerID,
|
||||
providerName: providerName,
|
||||
authURL: authURL,
|
||||
username: username,
|
||||
password: password,
|
||||
debug: isDebug,
|
||||
ZstackClientConfig: cfg,
|
||||
}
|
||||
if err := cli.connect(); err != nil {
|
||||
return nil, err
|
||||
@@ -93,13 +111,13 @@ func NewZStackClient(providerID string, providerName string, authURL string, use
|
||||
}
|
||||
|
||||
func (cli *SZStackClient) GetCloudRegionExternalIdPrefix() string {
|
||||
return fmt.Sprintf("%s/%s", CLOUD_PROVIDER_ZSTACK, cli.providerID)
|
||||
return fmt.Sprintf("%s/%s", CLOUD_PROVIDER_ZSTACK, cli.cpcfg.Id)
|
||||
}
|
||||
|
||||
func (cli *SZStackClient) GetSubAccounts() ([]cloudprovider.SSubAccount, error) {
|
||||
subAccount := cloudprovider.SSubAccount{
|
||||
Account: cli.username,
|
||||
Name: cli.providerName,
|
||||
Name: cli.cpcfg.Name,
|
||||
HealthStatus: api.CLOUD_PROVIDER_HEALTH_NORMAL,
|
||||
}
|
||||
return []cloudprovider.SSubAccount{subAccount}, nil
|
||||
|
||||
Reference in New Issue
Block a user