| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286 |
- // 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 apis
- import (
- "strings"
- "time"
- "yunion.io/x/onecloud/pkg/httperrors"
- )
- const (
- EXTERNAL_RESOURCE_SOURCE_LOCAL = "local"
- EXTERNAL_RESOURCE_SOURCE_CLOUD = "cloud"
- )
- type ModelBaseDetails struct {
- Meta
- // 资源是否可以删除, 若为flase, delete_fail_reason会返回不能删除的原因
- // example: true
- CanDelete bool `json:"can_delete"`
- // 资源不能删除的原因
- DeleteFailReason httperrors.Error `json:"delete_fail_reason"`
- // 资源是否可以更新, 若为false,update_fail_reason会返回资源不能删除的原因
- // example: true
- CanUpdate bool `json:"can_update"`
- // 资源不能更新的原因
- UpdateFailReason httperrors.Error `json:"update_fail_reason"`
- }
- type ModelBaseShortDescDetail struct {
- ResName string `json:"res_name"`
- }
- type SharedProject struct {
- Id string `json:"id"`
- Name string `json:"name"`
- DomainId string `json:"domain_id"`
- Domain string `json:"domain"`
- }
- type SharedDomain struct {
- Id string `json:"id"`
- Name string `json:"name"`
- }
- type SharableResourceBaseInfo struct {
- // 共享的项目列表
- SharedProjects []SharedProject `json:"shared_projects"`
- // 共享的域列表
- SharedDomains []SharedDomain `json:"shared_domains"`
- }
- type SharableVirtualResourceDetails struct {
- VirtualResourceDetails
- SharableResourceBaseInfo
- }
- type AdminSharableVirtualResourceDetails struct {
- SharableVirtualResourceDetails
- }
- type StandaloneAnonResourceShortDescDetail struct {
- ModelBaseShortDescDetail
- Id string `json:"id"`
- }
- type StandaloneResourceShortDescDetail struct {
- StandaloneAnonResourceShortDescDetail
- Name string `json:"name"`
- }
- type EnabledStatusDomainLevelResourceDetails struct {
- StatusDomainLevelResourceDetails
- }
- type StatusDomainLevelResourceDetails struct {
- DomainLevelResourceDetails
- }
- type DomainLevelResourceDetails struct {
- StandaloneResourceDetails
- DomainizedResourceInfo
- }
- type VirtualResourceDetails struct {
- StatusStandaloneResourceDetails
- ProjectizedResourceInfo
- }
- type VirtualJointResourceBaseDetails struct {
- JointResourceBaseDetails
- }
- type JointResourceBaseDetails struct {
- ResourceBaseDetails
- }
- type ResourceBaseDetails struct {
- ModelBaseDetails
- }
- type EnabledStatusStandaloneResourceDetails struct {
- StatusStandaloneResourceDetails
- }
- type StatusStandaloneResourceDetails struct {
- StandaloneResourceDetails
- }
- type MetadataResourceInfo struct {
- // 标签
- Metadata map[string]string `json:"metadata"`
- }
- func (self MetadataResourceInfo) GetMetricTags() map[string]string {
- ret := map[string]string{}
- for k, v := range self.Metadata {
- if strings.HasPrefix(k, "user:") {
- if strings.Contains(k, "login_key") || strings.Contains(v, "=") {
- continue
- }
- ret[k] = v
- }
- }
- return ret
- }
- type StatusDomainLevelUserResourceDetails struct {
- StatusDomainLevelResourceDetails
- // 用户名称
- OwnerName string `json:"owner_name"`
- }
- type UserResourceDetails struct {
- StandaloneResourceDetails
- // 用户名称
- OwnerName string `json:"owner_name"`
- }
- type StandaloneAnonResourceDetails struct {
- ResourceBaseDetails
- MetadataResourceInfo
- }
- type StandaloneResourceDetails struct {
- StandaloneAnonResourceDetails
- }
- type DomainizedResourceInfo struct {
- // 资源归属项目的域名称
- ProjectDomain string `json:"project_domain"`
- }
- type ProjectizedResourceInfo struct {
- DomainizedResourceInfo
- // 资源归属项目的名称
- // alias:project
- Project string `json:"tenant"`
- // 资源归属项目的ID(向后兼容别名)
- // Deprecated
- TenantId string `json:"project_id" yunion-deprecated-by:"tenant_id"`
- // 资源归属项目的名称(向后兼容别名)
- // Deprecated
- Tenant string `json:"project" yunion-deprecated-by:"tenant"`
- ProjectMetadata map[string]string `json:"project_metadata"`
- }
- func (self ProjectizedResourceInfo) GetMetricTags() map[string]string {
- ret := map[string]string{}
- for k, v := range self.ProjectMetadata {
- if strings.HasPrefix(k, "user:") || strings.HasPrefix(k, "org:") {
- if strings.Contains(v, "=") {
- continue
- }
- ret["project:"+k] = v
- }
- }
- return ret
- }
- type ScopedResourceBaseInfo struct {
- ProjectizedResourceInfo
- Scope string `json:"scope"`
- }
- type InfrasResourceBaseDetails struct {
- DomainLevelResourceDetails
- SharableResourceBaseInfo
- }
- type StatusInfrasResourceBaseDetails struct {
- InfrasResourceBaseDetails
- }
- type EnabledStatusInfrasResourceBaseDetails struct {
- StatusInfrasResourceBaseDetails
- }
- type ChangeOwnerCandidateDomainsOutput struct {
- Candidates []SharedDomain `json:"candidates"`
- }
- type OpsLogDetails struct {
- ModelBaseDetails
- Id int64 `json:"id"`
- ObjType string `json:"obj_type"`
- ObjId string `json:"obj_id"`
- ObjName string `json:"obj_name"`
- Action string `json:"action"`
- Notes string `json:"notes"`
- ProjectId string `json:"tenant_id"`
- Project string `json:"tenant"`
- ProjectDomainId string `json:"project_domain_id"`
- ProjectDomain string `json:"project_domain"`
- UserId string `json:"user_id"`
- User string `json:"user"`
- DomainId string `json:"domain_id"`
- Domain string `json:"domain"`
- Roles string `json:"roles"`
- OpsTime time.Time `json:"ops_time"`
- OwnerDomainId string `json:"owner_domain_id"`
- OwnerProjectId string `json:"owner_project_id"`
- OwnerDomain string `json:"owner_domain"`
- OwnerProject string `json:"owner_tenant"`
- }
- type StatusStatisticStatusInfo struct {
- Status string `json:"status"`
- // 资源总数
- TotalCount int64 `json:"total_count"`
- // 回收站数量
- // 需要指定pending_delete=all
- PendingDeletedCount int64 `json:"pending_deleted_count"`
- }
- type StatusStatistic struct {
- StatusInfo []StatusStatisticStatusInfo `json:"status_info,allowempty"`
- // CPU总量
- TotalCpuCount int `json:"total_cpu_count"`
- // 内存总量
- TotalMemSizeMb int `json:"total_mem_size_mb"`
- // 存储总量
- TotalDiskSizeMb int `json:"total_disk_size_mb"`
- }
- type ProjectStatistic struct {
- Count int `json:"count"`
- Id string `json:"id"`
- Name string `json:"name"`
- }
|