yunion.io/x/cloudmux@v0.3.10-0-alpha.1/pkg/cloudprovider/cloudprovider.go (about) 1 // Copyright 2019 Yunion 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 package cloudprovider 16 17 import ( 18 "context" 19 "fmt" 20 "net/http" 21 22 "yunion.io/x/jsonutils" 23 "yunion.io/x/pkg/errors" 24 "yunion.io/x/pkg/utils" 25 26 "yunion.io/x/onecloud/pkg/httperrors" 27 "yunion.io/x/onecloud/pkg/mcclient" 28 "yunion.io/x/onecloud/pkg/util/httputils" 29 ) 30 31 const ( 32 ErrNoSuchProvder = errors.Error("no such provider") 33 ) 34 35 type SCloudaccountCredential struct { 36 // 账号所在的项目 (openstack) 37 ProjectName string `json:"project_name"` 38 39 // 账号所在的域 (openstack) 40 // default: Default 41 DomainName string `json:"domain_name"` 42 43 // 用户名 (openstack, zstack, esxi) 44 Username string `json:"username"` 45 46 // 密码 (openstack, zstack, esxi) 47 Password string `json:"password"` 48 49 // 认证地址 (openstack,zstack) 50 AuthUrl string `json:"auto_url"` 51 52 // 秘钥id (Aliyun, Aws, huawei, ucloud, ctyun, zstack, s3) 53 AccessKeyId string `json:"access_key_id"` 54 55 // 秘钥key (Aliyun, Aws, huawei, ucloud, ctyun, zstack, s3) 56 AccessKeySecret string `json:"access_key_secret"` 57 58 // 环境 (Azure, Aws, huawei, ctyun, aliyun) 59 Environment string `json:"environment"` 60 61 // 目录ID (Azure) 62 DirectoryId string `json:"directory_id"` 63 64 // 客户端ID (Azure) 65 ClientId string `json:"client_id"` 66 67 // 客户端秘钥 (Azure) 68 ClientSecret string `json:"client_secret"` 69 70 // 主机IP (esxi) 71 Host string `json:"host"` 72 73 // 主机端口 (esxi) 74 Port int `json:"port"` 75 76 // 端点 (s3) 或 Apsara(飞天) 77 Endpoint string `json:"endpoint"` 78 79 // app id (Qcloud) 80 AppId string `json:"app_id"` 81 82 //秘钥ID (Qcloud) 83 SecretId string `json:"secret_id"` 84 85 //秘钥key (Qcloud) 86 SecretKey string `json:"secret_key"` 87 88 // 飞天允许的最高组织id, 默认为1 89 OrganizationId int `json:"organization_id"` 90 91 // Google服务账号email (gcp) 92 GCPClientEmail string `json:"gcp_client_email"` 93 // Google服务账号project id (gcp) 94 GCPProjectId string `json:"gcp_project_id"` 95 // Google服务账号秘钥id (gcp) 96 GCPPrivateKeyId string `json:"gcp_private_key_id"` 97 // Google服务账号秘钥 (gcp) 98 GCPPrivateKey string `json:"gcp_private_key"` 99 100 // 默认区域Id, Apara及HCSO需要此参数 101 // example: cn-north-2 102 // required: true 103 DefaultRegion string `default:"$DEFAULT_REGION" metavar:"$DEFAULT_REGION"` 104 105 // Huawei Cloud Stack Online 106 *SHCSOEndpoints 107 108 // ctyun crm account extra info 109 *SCtyunExtraOptions 110 } 111 112 type SCloudaccount struct { 113 // 账号信息,各个平台字段不尽相同,以下是各个平台账号创建所需要的字段 114 // 115 // 116 // 117 // | 云平台 |字段 | 翻译 | 是否必传 | 默认值 | 可否更新 | 获取方式 | 118 // | ------ |------ | ------ | --------- | -------- |-------- |-------- | 119 // |Aliyun |access_key_id |秘钥ID | 是 | | 是 | | 120 // |Aliyun |access_key_secret |秘钥Key | 是 | | 是 | | 121 // |Qcloud |app_id |APP ID | 是 | | 否 | | 122 // |Qcloud |secret_id |秘钥ID | 是 | | 是 | | 123 // |Qcloud |secret_key |秘钥Key | 是 | | 是 | | 124 // |OpenStack |project_name |用户所在项目 | 是 | | 是 | | 125 // |OpenStack |username |用户名 | 是 | | 是 | | 126 // |OpenStack |password |用户密码 | 是 | | 是 | | 127 // |OpenStack |auth_url |认证地址 | 是 | | 否 | | 128 // |OpenStack |domain_name |用户所在的域 | 否 |Default | 是 | | 129 // |VMware |username |用户名 | 是 | | 是 | | 130 // |VMware |password |密码 | 是 | | 是 | | 131 // |VMware |host |主机IP或域名 | 是 | | 否 | | 132 // |VMware |port |主机端口 | 否 |443 | 否 | | 133 // |Azure |directory_id |目录ID | 是 | | 否 | | 134 // |Azure |environment |区域 | 是 | | 否 | | 135 // |Azure |client_id |客户端ID | 是 | | 是 | | 136 // |Azure |client_secret |客户端密码 | 是 | | 是 | | 137 // |Huawei |access_key_id |秘钥ID | 是 | | 是 | | 138 // |Huawei |access_key_secret |秘钥 | 是 | | 是 | | 139 // |Huawei |environment |区域 | 是 | | 否 | | 140 // |Aws |access_key_id |秘钥ID | 是 | | 是 | | 141 // |Aws |access_key_secret |秘钥 | 是 | | 是 | | 142 // |Aws |environment |区域 | 是 | | 否 | | 143 // |Ucloud |access_key_id |秘钥ID | 是 | | 是 | | 144 // |Ucloud |access_key_secret |秘钥 | 是 | | 是 | | 145 // |Google |project_id |项目ID | 是 | | 否 | | 146 // |Google |client_email |客户端email | 是 | | 否 | | 147 // |Google |private_key_id |秘钥ID | 是 | | 是 | | 148 // |Google |private_key |秘钥Key | 是 | | 是 | | 149 Account string `json:"account"` 150 151 // swagger:ignore 152 Secret string 153 154 // 认证地址 155 AccessUrl string `json:"access_url"` 156 } 157 158 type ProviderConfig struct { 159 // Id, Name are properties of Cloudprovider object 160 Id string 161 Name string 162 163 // Vendor are names like Aliyun, OpenStack, etc. 164 Vendor string 165 URL string 166 Account string 167 Secret string 168 169 ReadOnly bool 170 171 AccountId string 172 173 Options *jsonutils.JSONDict 174 175 DefaultRegion string 176 ProxyFunc httputils.TransportProxyFunc 177 Debug bool 178 179 UpdatePermission func(service, permission string) 180 } 181 182 func (cp *ProviderConfig) AdaptiveTimeoutHttpClient() *http.Client { 183 client := httputils.GetAdaptiveTimeoutClient() 184 httputils.SetClientProxyFunc(client, cp.ProxyFunc) 185 return client 186 } 187 188 type SProviderInfo struct { 189 Name string 190 Url string 191 Account string 192 Secret string 193 Options *jsonutils.JSONDict 194 } 195 196 type ICloudProviderFactory interface { 197 GetProvider(cfg ProviderConfig) (ICloudProvider, error) 198 199 GetClientRC(SProviderInfo) (map[string]string, error) 200 201 GetId() string 202 GetName() string 203 204 ValidateChangeBandwidth(instanceId string, bandwidth int64) error 205 ValidateCreateCloudaccountData(ctx context.Context, userCred mcclient.TokenCredential, input SCloudaccountCredential) (SCloudaccount, error) 206 ValidateUpdateCloudaccountCredential(ctx context.Context, userCred mcclient.TokenCredential, input SCloudaccountCredential, cloudaccount string) (SCloudaccount, error) 207 GetSupportedBrands() []string 208 209 IsPublicCloud() bool 210 IsOnPremise() bool 211 IsMultiTenant() bool 212 IsSupportPrepaidResources() bool 213 NeedSyncSkuFromCloud() bool 214 215 IsCloudeventRegional() bool 216 GetMaxCloudEventSyncDays() int 217 GetMaxCloudEventKeepDays() int 218 219 IsNeedForceAutoCreateProject() bool 220 221 IsCloudpolicyWithSubscription() bool // 自定义权限属于订阅级别资源 222 IsClouduserpolicyWithSubscription() bool // 绑定用户权限需要指定订阅 223 224 IsSupportCloudIdService() bool 225 IsSupportClouduserPolicy() bool 226 IsSupportResetClouduserPassword() bool 227 GetClouduserMinPolicyCount() int 228 IsClouduserNeedInitPolicy() bool 229 IsSupportCreateCloudgroup() bool 230 231 IsSystemCloudpolicyUnified() bool // 国内国外权限是否一致 232 233 IsSupportCrossCloudEnvVpcPeering() bool 234 IsSupportCrossRegionVpcPeering() bool 235 IsSupportVpcPeeringVpcCidrOverlap() bool 236 ValidateCrossRegionVpcPeeringBandWidth(bandwidth int) error 237 238 IsSupportModifyRouteTable() bool 239 240 GetSupportedDnsZoneTypes() []TDnsZoneType 241 GetSupportedDnsTypes() map[TDnsZoneType][]TDnsType 242 GetSupportedDnsPolicyTypes() map[TDnsZoneType][]TDnsPolicyType 243 GetSupportedDnsPolicyValues() map[TDnsPolicyType][]TDnsPolicyValue 244 GetTTLRange(zoneType TDnsZoneType, productType TDnsProductType) TTlRange 245 246 IsSupportSAMLAuth() bool 247 248 GetAccountIdEqualizer() func(origin, now string) bool 249 } 250 251 type ICloudProvider interface { 252 GetFactory() ICloudProviderFactory 253 254 GetSysInfo() (jsonutils.JSONObject, error) 255 GetVersion() string 256 GetIamLoginUrl() string 257 258 GetIRegions() []ICloudRegion 259 GetIProjects() ([]ICloudProject, error) 260 CreateIProject(name string) (ICloudProject, error) 261 GetIRegionById(id string) (ICloudRegion, error) 262 263 GetOnPremiseIRegion() (ICloudRegion, error) 264 265 GetBalance() (float64, string, error) 266 267 GetSubAccounts() ([]SSubAccount, error) 268 GetAccountId() string 269 270 // region external id 是以provider 做为前缀.因此可以通过该判断条件过滤出同一个provider的regions列表 271 // 但是华为云有点特殊一个provider只对应一个region,因此需要进一步指定region名字,才能找到provider对应的region 272 GetCloudRegionExternalIdPrefix() string 273 274 GetStorageClasses(regionId string) []string 275 GetBucketCannedAcls(regionId string) []string 276 GetObjectCannedAcls(regionId string) []string 277 278 GetCapabilities() []string 279 280 IsClouduserSupportPassword() bool 281 GetICloudusers() ([]IClouduser, error) 282 GetISystemCloudpolicies() ([]ICloudpolicy, error) 283 GetICustomCloudpolicies() ([]ICloudpolicy, error) 284 GetICloudgroups() ([]ICloudgroup, error) 285 GetICloudgroupByName(name string) (ICloudgroup, error) 286 CreateICloudgroup(name, desc string) (ICloudgroup, error) 287 GetIClouduserByName(name string) (IClouduser, error) 288 CreateIClouduser(conf *SClouduserCreateConfig) (IClouduser, error) 289 CreateICloudSAMLProvider(opts *SAMLProviderCreateOptions) (ICloudSAMLProvider, error) 290 GetICloudSAMLProviders() ([]ICloudSAMLProvider, error) 291 GetICloudroles() ([]ICloudrole, error) 292 GetICloudroleById(id string) (ICloudrole, error) 293 GetICloudroleByName(name string) (ICloudrole, error) 294 CreateICloudrole(opts *SRoleCreateOptions) (ICloudrole, error) 295 296 CreateICloudpolicy(opts *SCloudpolicyCreateOptions) (ICloudpolicy, error) 297 298 GetEnrollmentAccounts() ([]SEnrollmentAccount, error) 299 CreateSubscription(SubscriptionCreateInput) error 300 301 GetSamlEntityId() string 302 303 GetICloudDnsZones() ([]ICloudDnsZone, error) 304 GetICloudDnsZoneById(id string) (ICloudDnsZone, error) 305 CreateICloudDnsZone(opts *SDnsZoneCreateOptions) (ICloudDnsZone, error) 306 307 GetICloudGlobalVpcs() ([]ICloudGlobalVpc, error) 308 CreateICloudGlobalVpc(opts *GlobalVpcCreateOptions) (ICloudGlobalVpc, error) 309 GetICloudGlobalVpcById(id string) (ICloudGlobalVpc, error) 310 311 GetICloudInterVpcNetworks() ([]ICloudInterVpcNetwork, error) 312 GetICloudInterVpcNetworkById(id string) (ICloudInterVpcNetwork, error) 313 CreateICloudInterVpcNetwork(opts *SInterVpcNetworkCreateOptions) (ICloudInterVpcNetwork, error) 314 315 GetICloudCDNDomains() ([]ICloudCDNDomain, error) 316 GetICloudCDNDomainByName(name string) (ICloudCDNDomain, error) 317 CreateICloudCDNDomain(opts *CdnCreateOptions) (ICloudCDNDomain, error) 318 319 GetMetrics(opts *MetricListOptions) ([]MetricValues, error) 320 } 321 322 func IsSupportCapability(prod ICloudProvider, capa string) bool { 323 return utils.IsInStringArray(capa, prod.GetCapabilities()) || utils.IsInStringArray(capa+READ_ONLY_SUFFIX, prod.GetCapabilities()) 324 } 325 326 func IsSupportCDN(prod ICloudProvider) bool { 327 return IsSupportCapability(prod, CLOUD_CAPABILITY_CDN) 328 } 329 330 func IsSupportProject(prod ICloudProvider) bool { 331 return IsSupportCapability(prod, CLOUD_CAPABILITY_PROJECT) 332 } 333 334 func IsSupportQuota(prod ICloudProvider) bool { 335 return IsSupportCapability(prod, CLOUD_CAPABILITY_QUOTA) 336 } 337 338 func IsSupportDnsZone(prod ICloudProvider) bool { 339 return IsSupportCapability(prod, CLOUD_CAPABILITY_DNSZONE) 340 } 341 342 func IsSupportInterVpcNetwork(prod ICloudProvider) bool { 343 return IsSupportCapability(prod, CLOUD_CAPABILITY_INTERVPCNETWORK) 344 } 345 346 func IsSupportCompute(prod ICloudProvider) bool { 347 return IsSupportCapability(prod, CLOUD_CAPABILITY_COMPUTE) 348 } 349 350 func IsSupportLoadbalancer(prod ICloudProvider) bool { 351 return IsSupportCapability(prod, CLOUD_CAPABILITY_LOADBALANCER) 352 } 353 354 func IsSupportObjectstore(prod ICloudProvider) bool { 355 return IsSupportCapability(prod, CLOUD_CAPABILITY_OBJECTSTORE) 356 } 357 358 func IsSupportRds(prod ICloudProvider) bool { 359 return IsSupportCapability(prod, CLOUD_CAPABILITY_RDS) 360 } 361 362 func IsSupportNAS(prod ICloudProvider) bool { 363 return IsSupportCapability(prod, CLOUD_CAPABILITY_NAS) 364 } 365 366 func IsSupportNAT(prod ICloudProvider) bool { 367 return IsSupportCapability(prod, CLOUD_CAPABILITY_NAT) 368 } 369 370 func IsSupportElasticCache(prod ICloudProvider) bool { 371 return IsSupportCapability(prod, CLOUD_CAPABILITY_CACHE) 372 } 373 374 func IsSupportWaf(prod ICloudProvider) bool { 375 return IsSupportCapability(prod, CLOUD_CAPABILITY_WAF) 376 } 377 378 func IsSupportMongoDB(prod ICloudProvider) bool { 379 return IsSupportCapability(prod, CLOUD_CAPABILITY_MONGO_DB) 380 } 381 382 func IsSupportElasticSearch(prod ICloudProvider) bool { 383 return IsSupportCapability(prod, CLOUD_CAPABILITY_ES) 384 } 385 386 func IsSupportKafka(prod ICloudProvider) bool { 387 return IsSupportCapability(prod, CLOUD_CAPABILITY_KAFKA) 388 } 389 390 func IsSupportApp(prod ICloudProvider) bool { 391 return IsSupportCapability(prod, CLOUD_CAPABILITY_APP) 392 } 393 394 func IsSupportContainer(prod ICloudProvider) bool { 395 return IsSupportCapability(prod, CLOUD_CAPABILITY_CONTAINER) 396 } 397 398 func IsSupportTablestore(prod ICloudProvider) bool { 399 return IsSupportCapability(prod, CLOUD_CAPABILITY_TABLESTORE) 400 } 401 402 func IsSupportModelartsPool(prod ICloudProvider) bool { 403 return IsSupportCapability(prod, CLOUD_CAPABILITY_MODELARTES) 404 } 405 406 func IsSupportMiscResources(prod ICloudProvider) bool { 407 return IsSupportCapability(prod, CLOUD_CAPABILITY_MISC) 408 } 409 410 var providerTable map[string]ICloudProviderFactory 411 412 func init() { 413 providerTable = make(map[string]ICloudProviderFactory) 414 } 415 416 func RegisterFactory(factory ICloudProviderFactory) { 417 providerTable[factory.GetId()] = factory 418 } 419 420 func GetProviderFactory(provider string) (ICloudProviderFactory, error) { 421 factory, ok := providerTable[provider] 422 if ok { 423 return factory, nil 424 } 425 return nil, fmt.Errorf("No such provider %s", provider) 426 } 427 428 func GetRegistedProviderIds() []string { 429 providers := []string{} 430 for id := range providerTable { 431 providers = append(providers, id) 432 } 433 return providers 434 } 435 436 func GetProvider(cfg ProviderConfig) (ICloudProvider, error) { 437 driver, err := GetProviderFactory(cfg.Vendor) 438 if err != nil { 439 return nil, errors.Wrap(err, "GetProviderFactory") 440 } 441 return driver.GetProvider(cfg) 442 } 443 444 func GetClientRC(name, accessUrl, account, secret, provider string, options *jsonutils.JSONDict) (map[string]string, error) { 445 driver, err := GetProviderFactory(provider) 446 if err != nil { 447 return nil, errors.Wrap(err, "GetProviderFactory") 448 } 449 info := SProviderInfo{ 450 Name: name, 451 Url: accessUrl, 452 Account: account, 453 Secret: secret, 454 Options: options, 455 } 456 return driver.GetClientRC(info) 457 } 458 459 func IsSupported(provider string) bool { 460 _, ok := providerTable[provider] 461 return ok 462 } 463 464 func IsValidCloudAccount(cfg ProviderConfig) (ICloudProvider, string, error) { 465 factory, ok := providerTable[cfg.Vendor] 466 if ok { 467 provider, err := factory.GetProvider(cfg) 468 if err != nil { 469 return nil, "", err 470 } 471 return provider, provider.GetAccountId(), nil 472 } 473 return nil, "", ErrNoSuchProvder 474 } 475 476 type SBaseProvider struct { 477 factory ICloudProviderFactory 478 } 479 480 func (provider *SBaseProvider) GetFactory() ICloudProviderFactory { 481 return provider.factory 482 } 483 484 func (self *SBaseProvider) GetOnPremiseIRegion() (ICloudRegion, error) { 485 return nil, ErrNotImplemented 486 } 487 488 func (self *SBaseProvider) GetIamLoginUrl() string { 489 return "" 490 } 491 492 func (self *SBaseProvider) IsClouduserSupportPassword() bool { 493 return true 494 } 495 496 func (self *SBaseProvider) GetICloudusers() ([]IClouduser, error) { 497 return nil, ErrNotImplemented 498 } 499 500 func (self *SBaseProvider) GetICloudgroups() ([]ICloudgroup, error) { 501 return nil, ErrNotImplemented 502 } 503 504 func (self *SBaseProvider) GetICloudgroupByName(name string) (ICloudgroup, error) { 505 return nil, ErrNotImplemented 506 } 507 508 func (self *SBaseProvider) CreateICloudgroup(name, desc string) (ICloudgroup, error) { 509 return nil, ErrNotImplemented 510 } 511 512 func (self *SBaseProvider) GetISystemCloudpolicies() ([]ICloudpolicy, error) { 513 return nil, ErrNotImplemented 514 } 515 516 func (self *SBaseProvider) GetICustomCloudpolicies() ([]ICloudpolicy, error) { 517 return nil, ErrNotImplemented 518 } 519 520 func (self *SBaseProvider) GetIClouduserByName(name string) (IClouduser, error) { 521 return nil, ErrNotImplemented 522 } 523 524 func (self *SBaseProvider) CreateIClouduser(conf *SClouduserCreateConfig) (IClouduser, error) { 525 return nil, ErrNotImplemented 526 } 527 528 func (self *SBaseProvider) GetICloudSAMLProviders() ([]ICloudSAMLProvider, error) { 529 return nil, errors.Wrapf(ErrNotImplemented, "GetICloudSAMLProviders") 530 } 531 532 func (self *SBaseProvider) GetICloudroles() ([]ICloudrole, error) { 533 return nil, errors.Wrapf(ErrNotImplemented, "GetICloudroles") 534 } 535 536 func (self *SBaseProvider) GetICloudroleById(id string) (ICloudrole, error) { 537 return nil, errors.Wrapf(ErrNotImplemented, "GetICloudroleById") 538 } 539 540 func (self *SBaseProvider) GetICloudroleByName(name string) (ICloudrole, error) { 541 return nil, errors.Wrapf(ErrNotImplemented, "GetICloudroleByName") 542 } 543 544 func (self *SBaseProvider) CreateICloudrole(opts *SRoleCreateOptions) (ICloudrole, error) { 545 return nil, errors.Wrapf(ErrNotImplemented, "CreateICloudrole") 546 } 547 548 func (self *SBaseProvider) CreateICloudSAMLProvider(opts *SAMLProviderCreateOptions) (ICloudSAMLProvider, error) { 549 return nil, errors.Wrapf(ErrNotImplemented, "CreateICloudSAMLProvider") 550 } 551 552 func (self *SBaseProvider) CreateICloudpolicy(opts *SCloudpolicyCreateOptions) (ICloudpolicy, error) { 553 return nil, ErrNotImplemented 554 } 555 556 func (self *SBaseProvider) GetEnrollmentAccounts() ([]SEnrollmentAccount, error) { 557 return nil, ErrNotImplemented 558 } 559 560 func (self *SBaseProvider) CreateSubscription(SubscriptionCreateInput) error { 561 return ErrNotImplemented 562 } 563 564 func (self *SBaseProvider) GetICloudDnsZones() ([]ICloudDnsZone, error) { 565 return nil, ErrNotImplemented 566 } 567 568 func (self *SBaseProvider) GetICloudDnsZoneById(id string) (ICloudDnsZone, error) { 569 return nil, ErrNotImplemented 570 } 571 572 func (self *SBaseProvider) CreateICloudDnsZone(opts *SDnsZoneCreateOptions) (ICloudDnsZone, error) { 573 return nil, ErrNotImplemented 574 } 575 576 func (self *SBaseProvider) GetCloudRegionExternalIdPrefix() string { 577 return self.factory.GetId() 578 } 579 580 func (self *SBaseProvider) CreateIProject(name string) (ICloudProject, error) { 581 return nil, ErrNotImplemented 582 } 583 584 func (self *SBaseProvider) GetSamlEntityId() string { 585 return "" 586 } 587 588 func (self *SBaseProvider) GetSamlSpInitiatedLoginUrl(idpName string) string { 589 return "" 590 } 591 592 func (self *SBaseProvider) GetICloudInterVpcNetworks() ([]ICloudInterVpcNetwork, error) { 593 return nil, ErrNotImplemented 594 } 595 596 func (self *SBaseProvider) GetICloudInterVpcNetworkById(id string) (ICloudInterVpcNetwork, error) { 597 return nil, ErrNotImplemented 598 } 599 600 func (self *SBaseProvider) CreateICloudInterVpcNetwork(opts *SInterVpcNetworkCreateOptions) (ICloudInterVpcNetwork, error) { 601 return nil, ErrNotImplemented 602 } 603 604 func (self *SBaseProvider) GetICloudGlobalVpcs() ([]ICloudGlobalVpc, error) { 605 return nil, errors.Wrapf(ErrNotImplemented, "GetICloudGlobalVpcs") 606 } 607 608 func (self *SBaseProvider) GetICloudGlobalVpcById(id string) (ICloudGlobalVpc, error) { 609 return nil, errors.Wrapf(ErrNotImplemented, "GetICloudGlobalVpcById") 610 } 611 612 func (self *SBaseProvider) CreateICloudGlobalVpc(opts *GlobalVpcCreateOptions) (ICloudGlobalVpc, error) { 613 return nil, errors.Wrapf(ErrNotImplemented, "CreateICloudGlobalVpc") 614 } 615 616 func (self *SBaseProvider) GetICloudCDNDomains() ([]ICloudCDNDomain, error) { 617 return nil, errors.Wrapf(ErrNotImplemented, "GetICloudCDNDomains") 618 } 619 620 func (self *SBaseProvider) GetICloudCDNDomainByName(name string) (ICloudCDNDomain, error) { 621 return nil, errors.Wrapf(ErrNotImplemented, "GetICloudCDNDomainByName") 622 } 623 624 func (self *SBaseProvider) CreateICloudCDNDomain(opts *CdnCreateOptions) (ICloudCDNDomain, error) { 625 return nil, errors.Wrapf(ErrNotImplemented, "CreateICloudCDNDomain") 626 } 627 628 func (self *SBaseProvider) GetMetrics(opts *MetricListOptions) ([]MetricValues, error) { 629 return nil, errors.Wrapf(ErrNotImplemented, "GetMetric") 630 } 631 632 func (self *SBaseProvider) GetIModelartsPools() ([]ICloudModelartsPool, error) { 633 return nil, errors.Wrapf(ErrNotImplemented, "GetIModelartsPools") 634 } 635 636 func (self *SBaseProvider) GetIModelartsPoolById(id string) (ICloudModelartsPool, error) { 637 return nil, errors.Wrapf(ErrNotImplemented, "GetIModelartsPoolDetail") 638 } 639 640 func (self *SBaseProvider) CreateIModelartsPool(pool *ModelartsPoolCreateOption) (ICloudModelartsPool, error) { 641 return nil, errors.Wrapf(ErrNotImplemented, "CreateIModelartsPool") 642 } 643 644 func (self *SBaseProvider) GetIModelartsPoolSku() ([]ICloudModelartsPoolSku, error) { 645 return nil, errors.Wrapf(ErrNotImplemented, "GetIModelartsPoolSku") 646 } 647 648 func NewBaseProvider(factory ICloudProviderFactory) SBaseProvider { 649 return SBaseProvider{factory: factory} 650 } 651 652 func GetPublicProviders() []string { 653 providers := make([]string, 0) 654 for p, d := range providerTable { 655 if d.IsPublicCloud() { 656 providers = append(providers, p) 657 } 658 } 659 return providers 660 } 661 662 func GetPrivateProviders() []string { 663 providers := make([]string, 0) 664 for p, d := range providerTable { 665 if !d.IsPublicCloud() && !d.IsOnPremise() { 666 providers = append(providers, p) 667 } 668 } 669 return providers 670 } 671 672 func GetSupportCloudgroupProviders() []string { 673 providers := []string{} 674 for p, d := range providerTable { 675 if d.IsSupportCreateCloudgroup() { 676 providers = append(providers, p) 677 } 678 } 679 return providers 680 } 681 682 func GetOnPremiseProviders() []string { 683 providers := make([]string, 0) 684 for p, d := range providerTable { 685 if !d.IsPublicCloud() && d.IsOnPremise() { 686 providers = append(providers, p) 687 } 688 } 689 return providers 690 } 691 692 func GetSupportCloudIdProvider() []string { 693 providers := []string{} 694 for p, d := range providerTable { 695 if d.IsSupportCloudIdService() { 696 providers = append(providers, p) 697 } 698 } 699 return providers 700 } 701 702 func GetClouduserpolicyWithSubscriptionProviders() []string { 703 providers := []string{} 704 for p, d := range providerTable { 705 if d.IsClouduserpolicyWithSubscription() { 706 providers = append(providers, p) 707 } 708 } 709 return providers 710 } 711 712 func GetProviderCloudEnv(provider string) string { 713 p, err := GetProviderFactory(provider) 714 if err != nil { 715 return "" 716 } 717 if p.IsPublicCloud() { 718 return CLOUD_ENV_PUBLIC_CLOUD 719 } 720 if p.IsOnPremise() { 721 return CLOUD_ENV_ON_PREMISE 722 } 723 return CLOUD_ENV_PRIVATE_CLOUD 724 } 725 726 type baseProviderFactory struct { 727 } 728 729 func (factory *baseProviderFactory) ValidateChangeBandwidth(instanceId string, bandwidth int64) error { 730 return nil 731 } 732 733 func (factory *baseProviderFactory) GetSupportedBrands() []string { 734 return []string{} 735 } 736 737 func (factory *baseProviderFactory) IsSupportSAMLAuth() bool { 738 return false 739 } 740 741 func (factory *baseProviderFactory) GetProvider(providerId, providerName, url, username, password string) (ICloudProvider, error) { 742 return nil, httperrors.NewNotImplementedError("Not Implemented GetProvider") 743 } 744 745 func (factory *baseProviderFactory) IsOnPremise() bool { 746 return false 747 } 748 749 func (factory *baseProviderFactory) IsMultiTenant() bool { 750 return false 751 } 752 753 func (factory *baseProviderFactory) IsCloudeventRegional() bool { 754 return false 755 } 756 757 func (factory *baseProviderFactory) GetMaxCloudEventSyncDays() int { 758 return 7 759 } 760 761 func (factory *baseProviderFactory) GetMaxCloudEventKeepDays() int { 762 return 7 763 } 764 765 func (factory *baseProviderFactory) IsNeedForceAutoCreateProject() bool { 766 return false 767 } 768 769 func (factory *baseProviderFactory) IsCloudpolicyWithSubscription() bool { 770 return false 771 } 772 773 func (factory *baseProviderFactory) IsClouduserpolicyWithSubscription() bool { 774 return false 775 } 776 777 func (factory *baseProviderFactory) IsSupportCloudIdService() bool { 778 return false 779 } 780 781 func (factory *baseProviderFactory) IsSupportClouduserPolicy() bool { 782 return true 783 } 784 785 func (factory *baseProviderFactory) IsSupportResetClouduserPassword() bool { 786 return true 787 } 788 789 func (factory *baseProviderFactory) IsClouduserNeedInitPolicy() bool { 790 return false 791 } 792 793 func (factory *baseProviderFactory) GetClouduserMinPolicyCount() int { 794 // unlimited 795 return -1 796 } 797 798 func (factory *baseProviderFactory) IsSupportCreateCloudgroup() bool { 799 return false 800 } 801 802 func (factory *baseProviderFactory) IsSystemCloudpolicyUnified() bool { 803 return true 804 } 805 806 func (factory *baseProviderFactory) IsSupportCrossCloudEnvVpcPeering() bool { 807 return false 808 } 809 810 func (factory *baseProviderFactory) IsSupportCrossRegionVpcPeering() bool { 811 return false 812 } 813 814 func (factory *baseProviderFactory) IsSupportVpcPeeringVpcCidrOverlap() bool { 815 return false 816 } 817 818 func (factory *baseProviderFactory) ValidateCrossRegionVpcPeeringBandWidth(bandwidth int) error { 819 return nil 820 } 821 822 func (factory *baseProviderFactory) IsSupportModifyRouteTable() bool { 823 return false 824 } 825 826 func (factory *baseProviderFactory) GetSupportedDnsZoneTypes() []TDnsZoneType { 827 return []TDnsZoneType{} 828 } 829 830 func (factory *baseProviderFactory) GetSupportedDnsTypes() map[TDnsZoneType][]TDnsType { 831 return map[TDnsZoneType][]TDnsType{} 832 } 833 834 func (factory *baseProviderFactory) GetSupportedDnsPolicyTypes() map[TDnsZoneType][]TDnsPolicyType { 835 return map[TDnsZoneType][]TDnsPolicyType{} 836 } 837 838 func (factory *baseProviderFactory) GetSupportedDnsPolicyValues() map[TDnsPolicyType][]TDnsPolicyValue { 839 return map[TDnsPolicyType][]TDnsPolicyValue{} 840 } 841 842 func (factory *baseProviderFactory) GetTTLRange(zoneType TDnsZoneType, productType TDnsProductType) TTlRange { 843 return TTlRange{} 844 } 845 846 func (factory *baseProviderFactory) GetAccountIdEqualizer() func(origin, now string) bool { 847 return func(origin, now string) bool { 848 if len(now) > 0 && now != origin { 849 return false 850 } 851 return true 852 } 853 } 854 855 type SDnsCapability struct { 856 ZoneTypes []TDnsZoneType 857 DnsTypes map[TDnsZoneType][]TDnsType 858 PolicyTypes map[TDnsZoneType][]TDnsPolicyType 859 PolicyValues map[TDnsPolicyType][]TDnsPolicyValue 860 } 861 862 func GetDnsCapabilities() map[string]SDnsCapability { 863 capabilities := map[string]SDnsCapability{} 864 for provider, driver := range providerTable { 865 capabilities[provider] = SDnsCapability{ 866 ZoneTypes: driver.GetSupportedDnsZoneTypes(), 867 DnsTypes: driver.GetSupportedDnsTypes(), 868 PolicyTypes: driver.GetSupportedDnsPolicyTypes(), 869 PolicyValues: driver.GetSupportedDnsPolicyValues(), 870 } 871 } 872 return capabilities 873 } 874 875 type SPremiseBaseProviderFactory struct { 876 baseProviderFactory 877 } 878 879 func (factory *SPremiseBaseProviderFactory) IsPublicCloud() bool { 880 return false 881 } 882 883 func (factory *SPremiseBaseProviderFactory) IsSupportPrepaidResources() bool { 884 return false 885 } 886 887 func (factory *SPremiseBaseProviderFactory) IsOnPremise() bool { 888 return true 889 } 890 891 func (factory *SPremiseBaseProviderFactory) IsMultiTenant() bool { 892 return false 893 } 894 895 func (factory *SPremiseBaseProviderFactory) NeedSyncSkuFromCloud() bool { 896 return false 897 } 898 899 type SPublicCloudBaseProviderFactory struct { 900 baseProviderFactory 901 } 902 903 func (factory *SPublicCloudBaseProviderFactory) IsMultiTenant() bool { 904 return true 905 } 906 907 func (factory *SPublicCloudBaseProviderFactory) IsPublicCloud() bool { 908 return true 909 } 910 911 func (factory *SPublicCloudBaseProviderFactory) IsSupportPrepaidResources() bool { 912 return true 913 } 914 915 func (factory *SPublicCloudBaseProviderFactory) NeedSyncSkuFromCloud() bool { 916 return false 917 } 918 919 type SPrivateCloudBaseProviderFactory struct { 920 baseProviderFactory 921 } 922 923 func (factory *SPrivateCloudBaseProviderFactory) IsMultiTenant() bool { 924 return false 925 } 926 927 func (factory *SPrivateCloudBaseProviderFactory) IsPublicCloud() bool { 928 return false 929 } 930 931 func (factory *SPrivateCloudBaseProviderFactory) IsSupportPrepaidResources() bool { 932 return false 933 } 934 935 func (factory *SPrivateCloudBaseProviderFactory) NeedSyncSkuFromCloud() bool { 936 return true 937 } 938 939 type ICloudModelartsPool interface { 940 ICloudResource 941 IBillingResource 942 943 Delete() error 944 GetProjectId() string 945 GetInstanceType() string 946 GetWorkType() string 947 GetNodeCount() int 948 ChangeConfig(opts *ModelartsPoolChangeConfigOptions) error 949 } 950 951 type ICloudModelartsPoolSku interface { 952 ICloudResource 953 954 GetCpuCoreCount() int 955 GetCpuArch() string 956 GetStatus() string 957 GetMemorySizeMB() int 958 GetPoolType() string 959 GetGpuSize() int 960 GetGpuType() string 961 GetNpuSize() int 962 GetNpuType() string 963 }