| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630 |
- // Copyright 2019 Yunion
- //
- // Licensed under the Apache License, Version 2.0 (the "License");
- // you may not use this file except in compliance with the License.
- // You may obtain a copy of the License at
- //
- // http://www.apache.org/licenses/LICENSE-2.0
- //
- // Unless required by applicable law or agreed to in writing, software
- // distributed under the License is distributed on an "AS IS" BASIS,
- // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- // See the License for the specific language governing permissions and
- // limitations under the License.
- package compute
- import (
- "fmt"
- "reflect"
- "yunion.io/x/cloudmux/pkg/cloudprovider"
- "yunion.io/x/jsonutils"
- "yunion.io/x/pkg/gotypes"
- "yunion.io/x/pkg/utils"
- "yunion.io/x/onecloud/pkg/apis"
- proxyapi "yunion.io/x/onecloud/pkg/apis/cloudcommon/proxy"
- "yunion.io/x/onecloud/pkg/httperrors"
- )
- type CloudenvResourceInfo struct {
- // 云平台名称
- // example: Google
- Provider string `json:"provider,omitempty"`
- // 云平台品牌
- // example: Google
- Brand string `json:"brand,omitempty"`
- // 云环境
- // example: public
- CloudEnv string `json:"cloud_env,omitempty"`
- // Environment
- Environment string `json:"environment,omitempty"`
- }
- type CloudenvResourceListInput struct {
- // 列出指定云平台的资源,支持的云平台如下
- //
- // | Provider | 开始支持版本 | 平台 |
- // |-----------|------------|-------------------------------------|
- // | OneCloud | 0.0 | OneCloud内置私有云,包括KVM和裸金属管理 |
- // | VMware | 1.2 | VMware vCenter |
- // | OpenStack | 2.6 | OpenStack M版本以上私有云 |
- // | ZStack | 2.10 | ZStack私有云 |
- // | Aliyun | 2.0 | 阿里云 |
- // | Aws | 2.3 | Amazon AWS |
- // | Azure | 2.2 | Microsoft Azure |
- // | Google | 2.13 | Google Cloud Platform |
- // | Qcloud | 2.3 | 腾讯云 |
- // | Huawei | 2.5 | 华为公有云 |
- // | Ucloud | 2.7 | UCLOUD |
- // | Ctyun | 2.13 | 天翼云 |
- // | S3 | 2.11 | 通用s3对象存储 |
- // | Ceph | 2.11 | Ceph对象存储 |
- // | Xsky | 2.11 | XSKY启明星辰Ceph对象存储 |
- //
- // enum: ["OneCloud","VMware","Aliyun","Qcloud","Azure","Aws","Huawei","OpenStack","Ucloud","ZStack","Google","Ctyun","S3","Ceph","Xsky"]
- Providers []string `json:"providers"`
- // swagger:ignore
- // Deprecated
- Provider []string `json:"provider" yunion-deprecated-by:"providers"`
- Brands []string `json:"brands"`
- // swagger:ignore
- // Deprecated
- Brand []string `json:"brand" yunion-deprecated-by:"brands"`
- // 列出指定云环境的资源,支持云环境如下:
- //
- // | CloudEnv | 说明 |
- // |-----------|--------|
- // | public | 公有云 |
- // | private | 私有云 |
- // | onpremise | 本地IDC |
- //
- // enum: ["public","private","onpremise"]
- CloudEnv string `json:"cloud_env"`
- // swagger:ignore
- // Deprecated
- // description: this param will be deprecate at 3.0
- PublicCloud *bool `json:"public_cloud"`
- // swagger:ignore
- // Deprecated
- // description: this param will be deprecate at 3.0
- IsPublic *bool `json:"is_public"`
- // swagger:ignore
- // Deprecated
- // description: this param will be deprecate at 3.0
- PrivateCloud *bool `json:"private_cloud"`
- // swagger:ignore
- // Deprecated
- // description: this param will be deprecate at 3.0
- IsPrivate *bool `json:"is_private"`
- // swagger:ignore
- // Deprecated
- // description: this param will be deprecate at 3.0
- IsOnPremise *bool `json:"is_on_premise"`
- // 以平台名称排序
- // pattern:asc|desc
- OrderByProvider string `json:"order_by_provider"`
- // 以平台品牌排序
- // pattern:asc|desc
- OrderByBrand string `json:"order_by_brand"`
- }
- type CloudaccountResourceInfo struct {
- CloudenvResourceInfo
- // 云账号名称
- // example: google-account
- Account string `json:"account,omitempty"`
- // 云账号状态
- AccountStatus string `json:"account_status,omitempty"`
- // 云账号监控状态
- AccountHealthStatus string `json:"account_health_status,omitempty"`
- AccountReadOnly bool `json:"account_read_only,omitempty"`
- }
- type CloudaccountCreateInput struct {
- apis.EnabledStatusInfrasResourceBaseCreateInput
- // 指定云平台
- // Qcloud: 腾讯云
- // Ctyun: 天翼云
- // enum: ["VMware", "Aliyun", "Qcloud", "Azure", "Aws", "Huawei", "OpenStack", "Ucloud", "ZStack", "Google", "Ctyun", "JDcloud"]
- Provider string `json:"provider"`
- // swagger:ignore
- AccountId string `json:"account_id"`
- // 跳过重复账号注册检查
- SkipDuplicateAccountCheck bool `json:"skip_duplicate_account_check"`
- // 指定云平台品牌, 此参数默认和provider相同
- // requried: false
- //
- //
- //
- // | provider | 支持的参数 |
- // | -------- | ---------- |
- // | VMware | VMware |
- // | Aliyun | Aliyun |
- // | Qcloud | Qcloud |
- // | Azure | Azure |
- // | Aws | Aws |
- // | Huawei | Huawei |
- // | OpenStack | OpenStack |
- // | Ucloud | Ucloud |
- // | ZStack | ZStack |
- // | Google | Google |
- // | Ctyun | Ctyun |
- Brand string `json:"brand"`
- // swagger:ignore
- IsPublicCloud bool `json:"is_public_cloud"`
- // swagger:ignore
- IsOnPremise bool `json:"is_on_premise"`
- // 指定云账号所属的项目
- // Tenant string `json:"tenant"`
- // swagger:ignore
- // TenantId string
- apis.ProjectizedResourceInput
- // 自动根据云上项目或订阅创建本地项目, OpenStack此参数为true
- // default: false
- AutoCreateProject *bool `json:"auto_create_project"`
- // 额外信息,例如账单的access key
- Options *jsonutils.JSONDict `json:"options"`
- proxyapi.ProxySettingResourceInput
- cloudprovider.SCloudaccount
- cloudprovider.SCloudaccountCredential
- // 是否启用SAML认证
- // default: false
- SAMLAuth *bool `json:"saml_auth"`
- // VMware 账号有zone属性
- Zone string `json:"zone"`
- // 仅当show_sub_accounts=true并且dry_run=true时才返回sub accounts 信息, 且不会创建云账号
- ShowSubAccounts bool `json:"show_sub_accounts"`
- // swagger:ignore
- SubAccounts *cloudprovider.SubAccounts
- ReadOnly bool `json:"read_only"`
- SProjectMappingResourceInput
- // 是否立即开始同步资源
- StartSync *bool `json:"start_sync"`
- // 跳过指定资源同步
- SkipSyncResources SkipSyncResources `json:"skip_sync_resources"`
- // 货币类型
- // enmu: CNY, USD
- Currency string `json:"currency"`
- EnableAutoSyncResource *bool `json:"enable_auto_sync_resource"`
- }
- type SProjectMappingResourceInput struct {
- ProjectMappingId string `json:"project_mapping_id"`
- EnableProjectSync bool `json:"enable_project_sync"`
- EnableResourceSync bool `json:"enable_resource_sync"`
- }
- type CloudaccountShareModeInput struct {
- apis.Meta
- ShareMode string `json:"share_mode"`
- }
- func (i CloudaccountShareModeInput) Validate() error {
- if len(i.ShareMode) == 0 {
- return httperrors.NewMissingParameterError("share_mode")
- }
- if !utils.IsInStringArray(i.ShareMode, CLOUD_ACCOUNT_SHARE_MODES) {
- return httperrors.NewInputParameterError("invalid share_mode %s", i.ShareMode)
- }
- return nil
- }
- type CloudaccountListInput struct {
- apis.EnabledStatusInfrasResourceBaseListInput
- ManagedResourceListInput
- CapabilityListInput
- SyncableBaseResourceListInput
- // 账号健康状态
- HealthStatus []string `json:"health_status"`
- ReadOnly *bool `json:"read_only"`
- // 共享模式
- ShareMode []string `json:"share_mode"`
- // 代理
- ProxySetting string `json:"proxy_setting"`
- // swagger:ignore
- ProxySettingId string `json:"proxy_setting_id" yunion-deprecated-by:"proxy_setting"`
- // 按宿主机数量排序
- // pattern:asc|desc
- OrderByHostCount string `json:"order_by_host_count"`
- // 按虚拟机数量排序
- // pattern:asc|desc
- OrderByGuestCount string `json:"order_by_guest_count"`
- }
- type ProviderProject struct {
- // 子订阅项目名称
- // example: system
- Tenant string `json:"tenant"`
- // 子订阅项目Id
- // 9a48383a-467a-4542-8b50-4e15b0a8715f
- TenantId string `json:"tenant_id"`
- }
- type SAccountUsage struct {
- // 弹性公网Ip数量
- // example: 2
- EipCount int `json:"eip_count,allowempty"`
- // 虚拟私有网络数量
- // example: 4
- VpcCount int `json:"vpc_count,allowempty"`
- // 云盘数量
- // example: 12
- DiskCount int `json:"disk_count,allowempty"`
- // 宿主机数量(不计算虚拟机宿主机数量)
- // example: 0
- HostCount int `json:"host_count,allowempty"`
- // 云主机数量
- // example: 4
- GuestCount int `json:"guest_count,allowempty"`
- // 块存储数量
- // example: 12
- StorageCount int `json:"storage_count,allowempty"`
- // 子订阅数量
- // example: 1
- ProviderCount int `json:"provider_count,allowempty"`
- // 启用的子订阅数量
- // example: 1
- EnabledProviderCount int `json:"enabled_provider_count,allowempty"`
- // 路由表数量
- // example: 0
- RoutetableCount int `json:"routetable_count,allowempty"`
- // 存储缓存数量
- // example: 10
- StoragecacheCount int `json:"storagecache_count,allowempty"`
- // 并发同步数量
- SyncCount int `json:"sync_count,allowempty"`
- }
- type CloudaccountDetail struct {
- apis.EnabledStatusInfrasResourceBaseDetails
- SCloudaccount
- // 同步时间间隔
- // example: 3600
- SyncIntervalSeconds int `json:"sync_interval_seconds"`
- // 同步状态
- SyncStatus2 string `json:"sync_status2"`
- // 云账号环境类型
- // public: 公有云
- // private: 私有云
- // onpremise: 本地IDC
- // example: public
- CloudEnv string `json:"cloud_env"`
- apis.ProjectizedResourceInfo
- SAccountUsage
- ProxySetting proxyapi.SProxySetting `json:"proxy_setting"`
- ProjectMappingResourceInfo
- // 上次同步耗时
- LastSyncCost string `json:"last_sync_cost"`
- }
- func (self CloudaccountDetail) GetMetricTags() map[string]string {
- ret := map[string]string{
- "id": self.Id,
- "cloudaccount_id": self.Id,
- "cloudaccount_name": self.Name,
- "brand": self.Brand,
- "domain_id": self.DomainId,
- "project_domain": self.ProjectDomain,
- "currency": self.Currency,
- "tenant_id": self.ProjectId,
- "tenant": self.Project,
- "status": self.Status,
- }
- return AppendMetricTags(ret, self.MetadataResourceInfo, self.ProjectizedResourceInfo)
- }
- func (self CloudaccountDetail) GetMetricPairs() map[string]string {
- ret := map[string]string{
- "balance": fmt.Sprintf("%.2f", self.Balance),
- }
- return ret
- }
- type CloudaccountUpdateInput struct {
- apis.EnabledStatusInfrasResourceBaseUpdateInput
- // 待更新的options key/value
- Options *jsonutils.JSONDict `json:"options"`
- // 带删除的options key
- RemoveOptions []string `json:"remove_options"`
- SAMLAuth *bool `json:"saml_auth"`
- proxyapi.ProxySettingResourceInput
- // 临时清除缺失的权限提示,云账号权限缺失依然会自动刷新
- CleanLakeOfPermissions bool `json:"clean_lake_of_permissions"`
- SkipSyncResources *SkipSyncResources `json:"skip_sync_resources"`
- AddSkipSyncResources []string `json:"add_skip_sync_resources"`
- RemoveSkipSyncResources []string `json:"remove_skip_sync_resources"`
- ReadOnly bool `json:"read_only"`
- Currency string `json:"currency"`
- EnableAutoSyncResource *bool `json:"enable_auto_sync_resource"`
- }
- type CloudaccountPerformPublicInput struct {
- apis.PerformPublicDomainInput
- // 共享模式,可能值为provider_domain, system
- // example: provider_domain
- ShareMode string `json:"share_mode"`
- }
- type CloudaccountPerformPrepareNetsInput struct {
- CloudaccountCreateInput
- WireLevelForVmware string `json:"wire_level_for_vmware"`
- Dvs bool `json:"dvs"`
- }
- type CloudaccountPerformPrepareNetsOutput struct {
- CAWireNets []CAWireNet `json:"wire_networks"`
- Hosts []CAGuestNet `json:"hosts"`
- // Guests []CAGuestNet `json:"guests"`
- Wires []CAPWire `json:"wires"`
- VSwitchs []VSwitch `json:"vswitchs"`
- }
- type CloudaccountSyncVMwareNetworkInput struct {
- Zone string `help:"zone Id or Name" json:"zone"`
- }
- type CAPWire struct {
- Id string `json:"id"`
- Name string `json:"name"`
- Distributed bool `json:"distributed"`
- Hosts []SimpleHost `json:"hosts"`
- HostNetworks []CANetConf `json:"host_networks"`
- GuestNetworks []CANetConf `json:"guest_networks"`
- }
- type VSwitch struct {
- Id string `json:"id"`
- Name string `json:"name"`
- Distributed bool `json:"distributed"`
- Hosts []SimpleHost `json:"hosts"`
- HostNetworks []CANetConf `json:"host_networks"`
- GuestNetworks []CANetConf `json:"guest_networks"`
- }
- type SimpleHost struct {
- Id string `json:"id"`
- Name string `json:"name"`
- }
- type CAWireNet struct {
- SuggestedWire CAWireConf `json:"suggested_wire"`
- SuitableWire string `json:"suitable_wire,allowempty"`
- Hosts []CAHostNet `json:"hosts"`
- // description: 没有合适的已有网络,推荐的网络配置
- HostSuggestedNetworks []CANetConf `json:"host_suggested_networks"`
- // Guests []CAGuestNet `json:"guests"`
- // description: 没有合适的已有网络,推荐的网络配置
- // GuestSuggestedNetworks []CANetConf `json:"guest_suggested_networks"`
- }
- type CAWireConf struct {
- // Zoneids to be selected
- ZoneIds []string `json:"zone_ids"`
- // description: wire name
- Name string `json:"name"`
- // description: wire description
- Description string `json:"description"`
- }
- type CAHostNet struct {
- // description: Host 的 Name
- Name string `json:"name"`
- // description: IP
- IP string `json:"ip"`
- // description: 合适的已有网络
- SuitableNetwork string `json:"suitable_network,allowempty"`
- }
- type CAGuestNet struct {
- // description: Host 的 Name
- Name string `json:"name"`
- IPNets []CAIPNet `json:"ip_nets"`
- }
- type CAIPNet struct {
- // description: IP
- IP string `json:"ip"`
- VlanID int32 `json:"vlan_id"`
- // description: 合适的已有网络
- SuitableNetwork string `json:"suitable_network,allowempty"`
- }
- type CASimpleNetConf struct {
- GuestIpStart string `json:"guest_ip_start"`
- GuestIpEnd string `json:"guest_ip_end"`
- GuestIpMask int8 `json:"guest_ip_mask"`
- GuestGateway string `json:"guest_gateway"`
- VlanID int32 `json:"vlan_id"`
- }
- type CANetConf struct {
- Name string `json:"name"`
- Description string `json:"description"`
- CASimpleNetConf
- }
- type SubscriptonCreateInput struct {
- // EA 账号id, 可通过 cloud-account-enrollment-accounts接口获取里面的id字段
- EnrollmentAccountId string `json:"enrollment_account_id"`
- // 订阅名称
- Name string `json:"name"`
- // 可选值: MS-AZR-0017P(生产用途), MS-AZR-0148P(开发测试)
- OfferType string `json:"offer_type"`
- }
- type EnrollmentAccountQuery struct {
- }
- type CloudaccountSyncSkusInput struct {
- Resource string `json:"resource"`
- Force bool `json:"force"`
- CloudregionResourceInput
- CloudproviderResourceInput
- }
- type CloudaccountProjectMappingInput struct {
- AutoCreateProject bool `json:"auto_create_project"`
- AutoCreateProjectForProvider bool `json:"auto_create_project_for_provider"`
- ProjectId string `json:"project_id"`
- // 同步策略Id, 若不传此参数则解绑
- // 绑定同步策略要求当前云账号此刻未绑定其他同步策略
- ProjectMappingId string `json:"project_mapping_id"`
- EnableProjectSync *bool `json:"enable_project_sync"`
- EnableResourceSync *bool `json:"enable_resource_sync"`
- }
- type SyncRangeInput struct {
- Force bool `json:"force"`
- FullSync bool `json:"full_sync"`
- DeepSync bool `json:"deep_sync"`
- // 极速模式(差量更新)
- Xor bool `json:"xor"`
- Region []string `json:"region"`
- Zone []string `json:"zone"`
- Host []string `json:"host"`
- // swagger:ignore
- SkipSyncResources []string `json:"skip_sync_resources"`
- // 按资源类型同步,可输入多个
- // enmu: project, compute, network, eip, loadbalancer, objectstore, rds, cache, event, cloudid, dnszone, public_ip, intervpcnetwork, saml_auth, quota, nat, nas, waf, mongodb, es, kafka, app, cdn, container, ipv6_gateway, tablestore, modelarts, vpcpeer, misc
- Resources []string `json:"resources" choices:"project|compute|network|eip|loadbalancer|objectstore|rds|cache|event|cloudid|dnszone|public_ip|intervpcnetwork|saml_auth|quota|nat|nas|waf|mongodb|es|kafka|app|cdn|container|ipv6_gateway|tablestore|modelarts|vpcpeer|misc|image"`
- }
- type iRes interface {
- Keyword() string
- }
- func (self *SyncRangeInput) IsNotSkipSyncResource(res iRes) bool {
- return !utils.IsInStringArray(res.Keyword(), self.SkipSyncResources)
- }
- type SAccountPermission struct {
- Permissions []string `json:"permissions"`
- }
- type SkipSyncResources []string
- func (s SkipSyncResources) String() string {
- return jsonutils.Marshal(s).String()
- }
- func (s *SkipSyncResources) Add(res string) {
- if !utils.IsInStringArray(res, *s) {
- *s = append(*s, res)
- }
- }
- func (s *SkipSyncResources) Remove(res string) {
- ret := []string{}
- for _, r := range *s {
- if r != res {
- ret = append(ret, r)
- }
- }
- *s = ret
- }
- func (s SkipSyncResources) IsZero() bool {
- return len(s) == 0
- }
- type SAccountPermissions map[string]SAccountPermission
- func (s SAccountPermissions) String() string {
- return jsonutils.Marshal(s).String()
- }
- func (s SAccountPermissions) IsZero() bool {
- return len(s) == 0
- }
- func init() {
- gotypes.RegisterSerializable(reflect.TypeOf(&SAccountPermissions{}), func() gotypes.ISerializable {
- return &SAccountPermissions{}
- })
- gotypes.RegisterSerializable(reflect.TypeOf(&SkipSyncResources{}), func() gotypes.ISerializable {
- return &SkipSyncResources{}
- })
- }
|