diff --git a/pkg/apis/compute/baremetalagent.go b/pkg/apis/compute/baremetalagent.go new file mode 100644 index 0000000000..69de0cbf23 --- /dev/null +++ b/pkg/apis/compute/baremetalagent.go @@ -0,0 +1,26 @@ +// 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 "yunion.io/x/onecloud/pkg/apis" + +type BaremetalagentDetails struct { + apis.StandaloneResourceDetails + SBaremetalagent + + // 裸金属代理程序所在的可用区 + // example: zone1 + Zone string `json:"zone"` +} diff --git a/pkg/apis/compute/bucket.go b/pkg/apis/compute/bucket.go index 2eecdf2c33..b9110d194c 100644 --- a/pkg/apis/compute/bucket.go +++ b/pkg/apis/compute/bucket.go @@ -49,10 +49,13 @@ type BucketCreateInput struct { StorageClass string `json:"storage_class"` } -type BucketDetail struct { - apis.Meta +type BucketDetails struct { + apis.VirtualResourceDetails SBucket - CloudproviderDetails + + CloudproviderInfo + + AccessUrls []cloudprovider.SBucketAccessUrl `json:"access_urls"` } type BucketObjectsActionInput struct { diff --git a/pkg/apis/compute/cachedimage.go b/pkg/apis/compute/cachedimage.go index 51142bd8ec..3e505a3a0c 100644 --- a/pkg/apis/compute/cachedimage.go +++ b/pkg/apis/compute/cachedimage.go @@ -14,6 +14,8 @@ package compute +import "yunion.io/x/onecloud/pkg/apis" + type CachedImageUncacheImageInput struct { // 存储缓存名Id // required: true @@ -23,3 +25,31 @@ type CachedImageUncacheImageInput struct { // default: false IsForce bool `json:"is_force"` } + +type CachedimageDetails struct { + apis.StandaloneResourceDetails + SCachedimage + + // 镜像状态, 和info里面的status一致 + // example: active + Status string `json:"status"` + + // 操作系统类型 + // example: FreeBSD + OsType string `json:"os_type"` + + // 操作系统发行版 + // example: FreeBSD + OsDistribution string `json:"os_distribution"` + + // 操作系统版本 + // example: 11 + OsVersion string `json:"os_version"` + + // 虚拟化类型 + Hypervisor string `json:"hypervisor"` + + // 此镜像被使用次数 + // example: 0 + CachedCount int `json:"cached_count"` +} diff --git a/pkg/apis/compute/cachedloadbalanceracl.go b/pkg/apis/compute/cachedloadbalanceracl.go new file mode 100644 index 0000000000..4ef1bda3c0 --- /dev/null +++ b/pkg/apis/compute/cachedloadbalanceracl.go @@ -0,0 +1,24 @@ +// 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 "yunion.io/x/onecloud/pkg/apis" + +type CachedLoadbalancerAclDetails struct { + apis.SharableVirtualResourceDetails + SCachedLoadbalancerAcl + + CloudproviderInfo +} diff --git a/pkg/apis/compute/cachedloadbalancercertificate.go b/pkg/apis/compute/cachedloadbalancercertificate.go new file mode 100644 index 0000000000..15034e2361 --- /dev/null +++ b/pkg/apis/compute/cachedloadbalancercertificate.go @@ -0,0 +1,24 @@ +// 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 "yunion.io/x/onecloud/pkg/apis" + +type CachedLoadbalancerCertificateDetails struct { + apis.VirtualResourceDetails + SCachedLoadbalancerCertificate + + CloudproviderInfo +} diff --git a/pkg/apis/compute/cloudaccount.go b/pkg/apis/compute/cloudaccount.go index 3f1c9526b1..f66cd08cad 100644 --- a/pkg/apis/compute/cloudaccount.go +++ b/pkg/apis/compute/cloudaccount.go @@ -106,3 +106,75 @@ type CloudaccountListInput struct { CapabilityListInput } + +type ProviderProject struct { + // 子订阅项目名称 + // example: system + Tenant string `json:"tenant"` + + // 子订阅项目Id + // 9a48383a-467a-4542-8b50-4e15b0a8715f + TenantId string `json:"tenant_id"` +} + +type CloudaccountDetail struct { + apis.StandaloneResourceDetails + SCloudaccount + + // 子订阅项目信息 + Projects []ProviderProject `json:"projects"` + + // 同步时间间隔 + // example: 3600 + SyncIntervalSeconds int `json:"sync_interval_seconds"` + + // 同步状态 + SyncStatus2 string `json:"sync_stauts2"` + + // 云账号环境类型 + // public: 公有云 + // private: 私有云 + // onpremise: 本地IDC + // example: public + CloudEnv string `json:"cloud_env"` + + // 云账号项目名称 + // example: system + Tenant string `json:"tenant"` + + // 弹性公网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: 0 + RoutetableCount int `json:"routetable_count,allowempty"` + + // 存储缓存数量 + // example: 10 + StoragecacheCount int `json:"storagecache_count,allowempty"` +} diff --git a/pkg/apis/compute/cloudprovider.go b/pkg/apis/compute/cloudprovider.go index 233fc48178..cfbe6f9ea1 100644 --- a/pkg/apis/compute/cloudprovider.go +++ b/pkg/apis/compute/cloudprovider.go @@ -21,26 +21,120 @@ import ( "yunion.io/x/onecloud/pkg/cloudprovider" ) -type CloudproviderDetails struct { - Provider string `json:"provider,omitempty"` - Brand string `json:"brand,omitempty"` - Account string `json:"account,omitempty"` - AccountId string `json:"account_id,omitempty"` - Manager string `json:"manager,omitempty"` - ManagerId string `json:"manager_id,omitempty"` - ManagerProject string `json:"manager_project,omitempty"` +type CloudproviderInfo struct { + // 云平台 + // example: Google + Provider string `json:"provider,omitempty"` + + // 云平台品牌 + // example: Google + Brand string `json:"brand,omitempty"` + + // 云账号名称 + // example: google-account + Account string `json:"account,omitempty"` + + // 云账号Id + // example: 4d3c8979-9dd0-439b-8d78-36fe1ab1666c + AccountId string `json:"account_id,omitempty"` + + // 子订阅名称 + // example: google-account + Manager string `json:"manager,omitempty"` + + // 子订阅Id + // example: fa4aaf88-aed8-422d-84e7-56dea533b364 + ManagerId string `json:"manager_id,omitempty"` + + // 子订阅所在项目名称 + // example: system + ManagerProject string `json:"manager_project,omitempty"` + // 子订阅所在项目Id + // example: 4d3c8979-9dd0-439b-8d78-36fe1ab1666c ManagerProjectId string `json:"manager_project_id,omitempty"` - ManagerDomain string `json:"manager_domain,omitempty"` - ManagerDomainId string `json:"manager_domain_id,omitempty"` - Region string `json:"region,omitempty"` - RegionId string `json:"region_id,omitempty"` - CloudregionId string `json:"cloudregion_id,omitempty"` + + // 子订阅所在域名称 + // example: Default + ManagerDomain string `json:"manager_domain,omitempty"` + + // 子订阅所在域Id + // example: default + ManagerDomainId string `json:"manager_domain_id,omitempty"` + + // 区域名称 + // example: 腾讯云 华南地区(广州) + Region string `json:"region,omitempty"` + // 区域Id + // example: 6151c89b-77f2-4d43-8ef9-cd03d604a16b + RegionId string `json:"region_id,omitempty"` + // 区域Id + // example: 6151c89b-77f2-4d43-8ef9-cd03d604a16b + CloudregionId string `json:"cloudregion_id,omitempty"` + // 区域外部Id + // Qcloud/ap-guangzhou RegionExternalId string `json:"region_external_id,omitempty"` - RegionExtId string `json:"region_ext_id,omitempty"` - Zone string `json:"zone,omitempty"` - ZoneId string `json:"zone_id,omitempty"` - ZoneExtId string `json:"zone_ext_id,omitempty"` - CloudEnv string `json:"cloud_env,omitempty"` + // 区域外部Id(不携带平台信息) + // example: ap-guangzhou + RegionExtId string `json:"region_ext_id,omitempty"` + + // 可用区名称 + // example: 腾讯云 广州四区 + Zone string `json:"zone,omitempty"` + // 可用区Id + // example: 336ac6d2-b80d-43bb-86d5-1ebf474da8d4 + ZoneId string `json:"zone_id,omitempty"` + // 可用区外部Id + // example: ap-guangzhou-4 + ZoneExtId string `json:"zone_ext_id,omitempty"` + + // 云环境 + // example: public + CloudEnv string `json:"cloud_env,omitempty"` +} + +type CloudproviderDetails struct { + apis.StandaloneResourceDetails + SCloudprovider + + // 云账号名称 + // example: google-account + Cloudaccount string `json:"cloudaccount"` + // 子订阅同步状态 + SyncStatus2 string `json:"sync_status2"` + // 支持服务列表 + Capabilities []string `json:"capabilities"` + + // 云主机数量 + // example: 1 + GuestCount int `json:"guest_count"` + // 宿主机数量 + // example: 2 + HostCount int `json:"host_count"` + // 虚拟私有网络数量 + // example: 4 + VpcCount int `json:"vpc_count"` + // 块存储梳理 + // example: 4 + StorageCount int `json:"storage_count"` + // 存储缓存数量 + // example: 1 + StorageCacheCount int `json:"storagecache_count"` + // 弹性公网IP数量 + // example: 12 + EipCount int `json:"eip_count"` + // 快照数量 + // example: 0 + SnapshotCount int `json:"snapshot_count"` + // 负载均衡器数量 + // example: 2 + LoadbalancerCount int `json:"loadbalancer_count"` + // 项目数量 + ProjectCount int `json:"project_count"` + // 同步区域数量 + SyncRegionCount int `json:"sync_region_count"` + + // 子订阅品牌信息 + Brand string `json:"brand"` } type ManagedResourceListInput struct { diff --git a/pkg/apis/compute/cloudproviderregion.go b/pkg/apis/compute/cloudproviderregion.go new file mode 100644 index 0000000000..2be032a818 --- /dev/null +++ b/pkg/apis/compute/cloudproviderregion.go @@ -0,0 +1,41 @@ +// 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 "yunion.io/x/onecloud/pkg/apis" + +type CloudproviderregionDetails struct { + apis.JoinModelBaseDetails + + Cloudprovider string + Cloudregion string + + // 云账号Id + // example: fa4aaf88-aed8-422d-84e7-56dea533b364 + CloudaccountId string `json:"cloudaccount_id"` + // 云账号名称 + // example: googl-account + Cloudaccount string `json:"cloudaccount"` + + // 云账号所在域Id + // example: 0df40413-eb69-49c7-895e-618ddeb80f55 + CloudaccountDomainId string `json:"cloudaccount_domain_id"` + // 是否开启自动同步 + // example: false + EnableAutoSync bool `json:"enable_auto_sync"` + // 自动同步周期 + // example: 300 + SyncIntervalSeconds int `json:"sync_interval_seconds"` +} diff --git a/pkg/apis/compute/cloudregion.go b/pkg/apis/compute/cloudregion.go new file mode 100644 index 0000000000..a00e77fef2 --- /dev/null +++ b/pkg/apis/compute/cloudregion.go @@ -0,0 +1,56 @@ +// 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 "yunion.io/x/onecloud/pkg/apis" + +type CloudregionDetails struct { + apis.StandaloneResourceDetails + SCloudregion + + // 虚拟私有网络数量 + // example: 2 + VpcCount int `json:"vpc_count,allowempty"` + // 可用区数量 + // example: 3 + ZoneCount int `json:"zone_count,allowempty"` + // 云主机梳理 + // example: 2 + GuestCount int `json:"guest_count,allowempty"` + // IP子网数量 + // example: 12 + NetworkCount int `json:"network_count,allowempty"` + // 距离前天0点新增云主机数量 + // example: 0 + GuestIncrementCount int `json:"guest_increment_count,allowempty"` +} + +type CloudregionInfo struct { + // 区域的名称 + // example: Default + Region string `json:"region"` + + // 区域的Id + // example: default + RegionId string `json:"region_id"` + + // 纳管云区域的组合Id(平台+Id) + // example: ZStack/59e7bc87-a6b3-4c39-8f02-c68e8243d4e4 + RegionExternalId string `json:"region_external_id"` + + // 纳管云区域的Id + // example: 59e7bc87-a6b3-4c39-8f02-c68e8243d4e4 + RegionExtId string `json:"region_ext_id"` +} diff --git a/pkg/apis/compute/dbinstance.go b/pkg/apis/compute/dbinstance.go index 60c19c8d11..c2214d2d38 100644 --- a/pkg/apis/compute/dbinstance.go +++ b/pkg/apis/compute/dbinstance.go @@ -214,3 +214,24 @@ type DbinstanceFilterListInput struct { // filter by dbinstance_id DbinstanceId string `json:"dbinstance_id" deprecated-by:"dbinstance"` } + +type DBInstanceDetails struct { + apis.VirtualResourceDetails + SDBInstance + + CloudproviderInfo + // 虚拟私有网络名称 + // example: test-vpc + Vpc string `json:"vpc"` + // 安全组名称 + // example: Default + Secgroup string `json:"secgroup"` + // iops + // example: 0 + Iops int `json:"iops"` + // IP子网名称 + // example: test-network + Network string `json:"network"` + // 标签信息 + Metadata map[string]string `json:"metadata"` +} diff --git a/pkg/apis/compute/dbinstance_account.go b/pkg/apis/compute/dbinstance_account.go index 2781ba8e06..1f6282cb0d 100644 --- a/pkg/apis/compute/dbinstance_account.go +++ b/pkg/apis/compute/dbinstance_account.go @@ -67,3 +67,22 @@ type DBInstanceAccountCreateInput struct { type SDBInstanceSetPrivilegesInput struct { Privileges []SDBInstanceAccountPrivilege `json:"privileges"` } + +type DBInstancePrivilege struct { + // 数据库名称 + Database string + // 账号名称 + Account string + // 数据库Id + DBInstancedatabaseId string + // 权限 + Privileges string +} + +type DBInstanceAccountDetails struct { + apis.StandaloneResourceDetails + SDBInstanceAccount + + // 账号权限列表 + DBInstanceprivileges []DBInstancePrivilege `json:"dbinstanceprivileges,allowempty"` +} diff --git a/pkg/apis/compute/dbinstance_backup.go b/pkg/apis/compute/dbinstance_backup.go index 8f122ddfdc..706ec4bdb6 100644 --- a/pkg/apis/compute/dbinstance_backup.go +++ b/pkg/apis/compute/dbinstance_backup.go @@ -42,3 +42,13 @@ type DBInstanceBackupCreateInput struct { // swagger:ignore ManagerId string } + +type DBInstanceBackupDetails struct { + apis.VirtualResourceDetails + SDBInstanceBackup + + // RDS实例名称 + DBInstance string `json:"dbinstance"` + + CloudproviderInfo +} diff --git a/pkg/apis/compute/dbinstance_database.go b/pkg/apis/compute/dbinstance_database.go index b7d0a93d5d..640948678e 100644 --- a/pkg/apis/compute/dbinstance_database.go +++ b/pkg/apis/compute/dbinstance_database.go @@ -60,3 +60,11 @@ type DBInstanceDatabaseCreateInput struct { // required: false Accounts []SDBInstanceDatabasePrivilege `json:"accounts"` } + +type DBInstancedatabaseDetails struct { + apis.StandaloneResourceDetails + SDBInstanceDatabase + + // 数据库权限 + DBInstanceprivileges []DBInstancePrivilege `json:"dbinstanceprivileges"` +} diff --git a/pkg/apis/compute/disk.go b/pkg/apis/compute/disk.go index d2b99f41b4..d4a122dfbd 100644 --- a/pkg/apis/compute/disk.go +++ b/pkg/apis/compute/disk.go @@ -15,6 +15,8 @@ package compute import ( + "time" + "yunion.io/x/onecloud/pkg/apis" ) @@ -128,3 +130,51 @@ type DiskFilterListInput struct { // filter by disk_id DiskId string `json:"disk_id" deprecated-by:"disk"` } + +type SimpleGuest struct { + Name string `json:"name"` + Id string `json:"id"` + Status string `json:"status"` +} + +type SimpleSnapshotPolicy struct { + RepeatWeekdays []int `json:"repeat_weekdays"` + TimePoints []int `json:"time_points"` +} + +type DiskDetails struct { + apis.VirtualResourceDetails + SDisk + CloudproviderInfo + + // 云平台 + Provider string `json:"provider"` + // 存储名称 + Storage string `json:"storage"` + // 存储类型 + StorageType string `json:"storage_type"` + // 介质类型 + MediumType string `json:"medium_type"` + + // 所挂载的虚拟机 + Guests []SimpleGuest `json:"guests"` + // 所挂载的虚拟机 + Guest string `json:"guest"` + // 所挂载虚拟机的数量 + GuestCount int `json:"guest_count"` + // 所挂载虚拟机状态 + GuestStatus string `json:"guest_status"` + + // 自动清理时间 + AutoDeleteAt time.Time `json:"auto_delete_at"` + // 自动快照策略状态 + SnapshotpolicyStatus string `json:"snapshotpolicy_status,allowempty"` + + // 自动快照策略 + Snapshotpolicies []SimpleSnapshotPolicy `json:"snapshotpolicies"` + + // 手动快照数量 + ManualSnapshotCount int `json:"manual_snapshot_count"` + // 最多可创建手动快照数量 + MaxManualSnapshotCount int `json:"max_manual_snapshot_count"` +} diff --git a/pkg/apis/compute/dynamicschedtag.go b/pkg/apis/compute/dynamicschedtag.go new file mode 100644 index 0000000000..f29cdbca51 --- /dev/null +++ b/pkg/apis/compute/dynamicschedtag.go @@ -0,0 +1,25 @@ +// 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 "yunion.io/x/onecloud/pkg/apis" + +type DynamicschedtagDetails struct { + apis.StandaloneResourceDetails + SDynamicschedtag + + Schedtag string `json:"schedtag"` + ResourceType string `json:"resource_type"` +} diff --git a/pkg/apis/virtualresource.go b/pkg/apis/compute/elasticcache.go similarity index 51% rename from pkg/apis/virtualresource.go rename to pkg/apis/compute/elasticcache.go index 01f4bbb683..ffa08568f7 100644 --- a/pkg/apis/virtualresource.go +++ b/pkg/apis/compute/elasticcache.go @@ -12,22 +12,19 @@ // See the License for the specific language governing permissions and // limitations under the License. -package apis +package compute -type VirtualResourceDetails struct { - ModelBaseDetails -} +import "yunion.io/x/onecloud/pkg/apis" -type VirtualResourceListInput struct { - StatusStandaloneResourceListInput +type ElasticcacheDetails struct { + apis.VirtualResourceDetails - ProjectizedResourceListInput + SElasticcache - // 列表中包含标记为"系统资源"的资源 - System *bool `json:"system"` - // 是否显示回收站内的资源,默认不显示(对实现了回收站的资源有效,例如主机,磁盘,镜像) - PendingDelete *bool `json:"pending_delete"` - // 是否显示所有资源,包括回收站和不再回收站的资源 - // TODO: fix this??? - PendingDeleteAll *bool `json:"-"` + CloudproviderInfo + + // 虚拟私有网络名称 + Vpc string `json:"vpc"` + // IP子网名称 + Network string `json:"network"` } diff --git a/pkg/apis/compute/elasticcachebackup.go b/pkg/apis/compute/elasticcachebackup.go new file mode 100644 index 0000000000..938d13eb27 --- /dev/null +++ b/pkg/apis/compute/elasticcachebackup.go @@ -0,0 +1,29 @@ +// 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 "yunion.io/x/onecloud/pkg/apis" + +type ElasticcacheBackupDetails struct { + apis.StandaloneResourceDetails + SElasticcacheBackup + + CloudproviderInfo + + // 引擎 + Engine string `json:"engine"` + // 引擎版本 + EngineVersion string `json:"engine_version"` +} diff --git a/pkg/apis/compute/elasticcachesku.go b/pkg/apis/compute/elasticcachesku.go new file mode 100644 index 0000000000..4aa40901ac --- /dev/null +++ b/pkg/apis/compute/elasticcachesku.go @@ -0,0 +1,22 @@ +// 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 "yunion.io/x/onecloud/pkg/apis" + +type ElasticcacheSkuDetails struct { + apis.StandaloneResourceDetails + SElasticcacheSku +} diff --git a/pkg/apis/compute/elasticip.go b/pkg/apis/compute/elasticip.go index 33e9c19301..b605e24464 100644 --- a/pkg/apis/compute/elasticip.go +++ b/pkg/apis/compute/elasticip.go @@ -67,3 +67,13 @@ type SElasticipCreateInput struct { // swagger:ignore NetworkId string } + +type ElasticipDetails struct { + apis.VirtualResourceDetails + SElasticip + + CloudproviderInfo + + // 绑定资源名称 + AssociateName string `json:"associate_name"` +} diff --git a/pkg/apis/compute/externalproject.go b/pkg/apis/compute/externalproject.go new file mode 100644 index 0000000000..6de2f4d171 --- /dev/null +++ b/pkg/apis/compute/externalproject.go @@ -0,0 +1,26 @@ +// 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 "yunion.io/x/onecloud/pkg/apis" + +type ExternalProjectDetails struct { + apis.StandaloneResourceDetails + + SExternalProject + CloudproviderInfo + + Tenant string `json:"tenant"` +} diff --git a/pkg/apis/compute/globalvpc.go b/pkg/apis/compute/globalvpc.go index b26efe305e..132985e715 100644 --- a/pkg/apis/compute/globalvpc.go +++ b/pkg/apis/compute/globalvpc.go @@ -21,3 +21,8 @@ import ( type GlobalVpcCreateInput struct { apis.EnabledStatusStandaloneResourceCreateInput } + +type GlobalVpcDetails struct { + apis.StandaloneResourceDetails + SGlobalVpc +} diff --git a/pkg/apis/compute/groupguest.go b/pkg/apis/compute/groupguest.go new file mode 100644 index 0000000000..ce7b0dcd03 --- /dev/null +++ b/pkg/apis/compute/groupguest.go @@ -0,0 +1,29 @@ +// 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 ( + "yunion.io/x/onecloud/pkg/apis" +) + +type GroupguestDetails struct { + apis.JoinModelBaseDetails + + Instancegroup string + Server string + Guest string + + SGroupguest +} diff --git a/pkg/apis/compute/groupnetwork.go b/pkg/apis/compute/groupnetwork.go new file mode 100644 index 0000000000..33115ec6e1 --- /dev/null +++ b/pkg/apis/compute/groupnetwork.go @@ -0,0 +1,29 @@ +// 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 ( + "yunion.io/x/onecloud/pkg/apis" +) + +type GroupnetworkDetails struct { + apis.JoinModelBaseDetails + SGroupnetwork + + // 主机组名称 + Instancegroup string + // IP子网名称 + Network string +} diff --git a/pkg/apis/compute/guest_disk.go b/pkg/apis/compute/guest_disk.go new file mode 100644 index 0000000000..1599d3318a --- /dev/null +++ b/pkg/apis/compute/guest_disk.go @@ -0,0 +1,45 @@ +// 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 "yunion.io/x/onecloud/pkg/apis" + +type GuestDiskDetails struct { + apis.JoinModelBaseDetails + SGuestdisk + + // 云主机名称 + Guest string + // 云主机名称 + Server string + // 磁盘名称 + Disk string + + // 存储类型 + // example: local + StorageType string `json:"storage_type"` + // 磁盘大小, 单位Mb + // example: 10240 + DiskSize int `json:"disk_size"` + // 磁盘状态 + // example: ready + Status string `json:"status"` + // 磁盘类型 + // example: data + DiskType string `json:"disk_type"` + // 介质类型 + // example: ssd + MediumType string `json:"medium_type"` +} diff --git a/pkg/apis/compute/guestnetwork.go b/pkg/apis/compute/guestnetwork.go new file mode 100644 index 0000000000..ac9d396609 --- /dev/null +++ b/pkg/apis/compute/guestnetwork.go @@ -0,0 +1,29 @@ +// 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 "yunion.io/x/onecloud/pkg/apis" + +type GuestnetworkDetails struct { + apis.JoinModelBaseDetails + SGuestnetwork + + // 云主机名称 + Guest string + // 云主机名称 + Server string + // IP子网名称 + Network string +} diff --git a/pkg/apis/compute/guests.go b/pkg/apis/compute/guests.go index 5aefb71511..d6a4fa37ee 100644 --- a/pkg/apis/compute/guests.go +++ b/pkg/apis/compute/guests.go @@ -15,6 +15,10 @@ package compute import ( + "time" + + "yunion.io/x/jsonutils" + "yunion.io/x/onecloud/pkg/apis" ) @@ -123,3 +127,51 @@ func (i ServerRebuildRootInput) GetKeypairName() string { type ServerResumeInput struct { apis.Meta } + +type ServerDetails struct { + apis.VirtualResourceDetails + SGuest + CloudproviderInfo + + // details + // 网络概要 + Networks string `json:"networks"` + // 磁盘概要 + Disks string `json:"disks"` + // 磁盘详情 + DisksInfo *jsonutils.JSONArray `json:"disk_info"` + // 虚拟机Ip列表 + VirtualIps string `json:"virtual_ips"` + // 安全组规则 + SecurityRules string `json:"security_rules"` + // 操作系统名称 + OsName string `json:"os_name"` + // 操作系统类型 + OsType string `json:"os_type"` + // 系统管理员可见的安全组规则 + AdminSecurityRules string `json:"admin_security_rules"` + + // list + AttachTime time.Time `attach_time` + + // common + IsPrepaidRecycle bool `json:"is_prepaid_recycle"` + + // 备机所在宿主机名称 + BackupHostName string `json:"backup_host_name"` + // 北京所在宿主机状态 + BackupHostStatus string `json:"backup_host_status"` + // 宿主机名称 + Host string `json:"host"` + // 宿主机SN + HostSN string `json:"host_sn"` + CanRecycle bool `json:"can_recycle"` + // 自动释放时间 + AutoDeleteAt time.Time `json:"auto_delete_at"` + // 标签 + Metadata map[string]string `json:"metadata"` + // 磁盘数量 + DiskCount int `json:"disk_count"` + // 是否支持ISO启动 + CdromSupport bool `json:"cdrom_support"` +} diff --git a/pkg/apis/compute/guesttemplate.go b/pkg/apis/compute/guesttemplate.go index 0ae0750101..c233b1faae 100644 --- a/pkg/apis/compute/guesttemplate.go +++ b/pkg/apis/compute/guesttemplate.go @@ -36,7 +36,6 @@ type GuesttemplateCreateInput struct { } type GuesttemplateDetails struct { - apis.Meta apis.SharableVirtualResourceDetails SGuestTemplate diff --git a/pkg/apis/compute/host.go b/pkg/apis/compute/host.go index 22983589c0..1a1eaced6b 100644 --- a/pkg/apis/compute/host.go +++ b/pkg/apis/compute/host.go @@ -15,6 +15,8 @@ package compute import ( + "yunion.io/x/jsonutils" + "yunion.io/x/onecloud/pkg/apis" ) @@ -69,3 +71,53 @@ type HostListInput struct { // filter host that is baremetal Baremetal *bool `json:"baremetal"` } + +type HostDetails struct { + apis.StandaloneResourceDetails + SHost + + CloudproviderInfo + + Schedtags []SchedtagShortDescDetails `json:"schedtags"` + + ServerId string `json:"server_id"` + Server string `json:"server"` + ServerIps string `json:"server_ips"` + // 网卡数量 + NicCount int `json:"nic_count"` + // 网卡详情 + NicInfo []jsonutils.JSONObject `json:"nic_info"` + // CPU超分比 + CpuCommit int `json:"cpu_commit"` + // 内存超分比 + MemCommit int `json:"mem_commit"` + // 云主机数量 + // example: 10 + Guests int `json:"guests"` + // 非系统云主机数量 + // example: 0 + NonsystemGuests int `json:"nonsystem_guests"` + // 运行中云主机数量 + // example: 2 + RunningGuests int `json:"running_geusts"` + // CPU超分率 + CpuCommitRate float64 `json:"cpu_commit_rate"` + // 内存超分率 + MemCommitRate float64 `json:"mem_commit_rate"` + // 存储大小 + Storage int64 `json:"storage"` + // 已使用存储大小 + StorageUsed int64 `json:"storage_used"` + // 浪费存储大小(异常磁盘存储大小) + StorageWaste int64 `json:"storage_waste"` + // 虚拟存储大小 + StorageVirtual int64 `json:"storage_virtual"` + // 可用存储大小 + StorageFree int64 `json:"storage_free"` + // 存储超分率 + StorageCommitRate float64 `json:"storage_commit_rate"` + Spec *jsonutils.JSONDict `json:"spec"` + IsPrepaidRecycle bool `json:"is_prepaid_recycle"` + CanPrepare bool `json:"can_prepare"` + PrepareFailReason string `json:"prepare_fail_reason"` +} diff --git a/pkg/apis/compute/hostjoin.go b/pkg/apis/compute/hostjoin.go new file mode 100644 index 0000000000..6a6bbfb650 --- /dev/null +++ b/pkg/apis/compute/hostjoin.go @@ -0,0 +1,22 @@ +// 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 + +type HostJointsDetails struct { + // 宿主机名称 + Host string `json:"host"` + // 裸金属服务器名称 + Baremetal string `json:"baremetal"` +} diff --git a/pkg/apis/compute/hostnetwork.go b/pkg/apis/compute/hostnetwork.go new file mode 100644 index 0000000000..77032ca984 --- /dev/null +++ b/pkg/apis/compute/hostnetwork.go @@ -0,0 +1,28 @@ +// 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 "yunion.io/x/onecloud/pkg/apis" + +type HostnetworkDetails struct { + apis.JoinModelBaseDetails + HostJointsDetails + SHostwire + + // IP子网名称 + Network string `json:"network"` + + NicType string `json:"nic_type"` +} diff --git a/pkg/apis/compute/hostschedtag.go b/pkg/apis/compute/hostschedtag.go new file mode 100644 index 0000000000..b1b8b53999 --- /dev/null +++ b/pkg/apis/compute/hostschedtag.go @@ -0,0 +1,25 @@ +// 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 "yunion.io/x/onecloud/pkg/apis" + +type HostschedtagDetails struct { + apis.JoinModelBaseDetails + HostJointsDetails + SHostschedtag + + Schedtag string `json:"string"` +} diff --git a/pkg/apis/compute/hoststorage.go b/pkg/apis/compute/hoststorage.go new file mode 100644 index 0000000000..9b4db63c64 --- /dev/null +++ b/pkg/apis/compute/hoststorage.go @@ -0,0 +1,57 @@ +// 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 ( + "yunion.io/x/jsonutils" + + "yunion.io/x/onecloud/pkg/apis" +) + +type HoststorageDetails struct { + apis.JoinModelBaseDetails + HostJointsDetails + + SHoststorage + + // 存储名称 + Storage string `json:"storage"` + // 存储大小 + Capacity int64 `json:"capacity"` + // 存储配置信息 + StorageConf jsonutils.JSONObject `json:"storage_conf"` + // 已使用存储大小 + UsedCapacity int64 `json:"used_capacity"` + // 浪费存储大小(异常磁盘总大小) + WasteCapacity int64 `json:"waste_capacity"` + // 可用存储大小 + FreeCapacity int64 `json:"free_capacity"` + // 存储类型 + // example: local + StorageType string `json:"storage_type"` + // 介质类型 + // example: ssd + MediumType string `json:"medium_type"` + // 是否启用 + Enabled bool `json:"enabled"` + // 超售比 + Cmtbound float32 `json:"cmtbound"` + // 镜像缓存路径 + ImagecachePath string `json:"imagecache_path"` + // 存储缓存Id + StoragecacheId string `json:"storagecached_id"` + + GuestDiskCount int `json:"guest_disk_count,allowempty"` +} diff --git a/pkg/apis/compute/hostwire.go b/pkg/apis/compute/hostwire.go new file mode 100644 index 0000000000..2564328123 --- /dev/null +++ b/pkg/apis/compute/hostwire.go @@ -0,0 +1,29 @@ +// 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 "yunion.io/x/onecloud/pkg/apis" + +type HostwireDetails struct { + apis.JoinModelBaseDetails + HostJointsDetails + SHostwire + + // 二层网络名称 + Wire string `json:"wire"` + + // 带宽大小 + Bandwidth int `json:"bandwidth"` +} diff --git a/pkg/apis/compute/instance_group.go b/pkg/apis/compute/instance_group.go index 0c2e73509b..157fb3b5cd 100644 --- a/pkg/apis/compute/instance_group.go +++ b/pkg/apis/compute/instance_group.go @@ -28,9 +28,11 @@ type InstanceGroupListInput struct { } type InstanceGroupDetail struct { - apis.Meta + apis.VirtualResourceDetails SGroup - GuestCount int64 `json:"guest_count"` + + // 云主机数量 + GuestCount int `json:"guest_count"` } type GroupFilterListInput struct { diff --git a/pkg/apis/compute/instance_snapshot.go b/pkg/apis/compute/instance_snapshot.go new file mode 100644 index 0000000000..7456f8641a --- /dev/null +++ b/pkg/apis/compute/instance_snapshot.go @@ -0,0 +1,47 @@ +// 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 "yunion.io/x/onecloud/pkg/apis" + +type SimpleSnapshot struct { + // 快照Id + Id string `json:"id"` + // 快照名称 + Name string `json:"name"` + // 存储Id + StorageId string `json:"storage_id"` + // 磁盘类型 + DiskType string `json:"disk_type"` + // 区域Id + CloudregionId string `json:"cloudregion_id"` +} + +type InstnaceSnapshotDetails struct { + apis.VirtualResourceDetails + SInstanceSnapshot + + // 云主机状态 + GuestStatus string `json:"guest_status"` + // 云主机名称 + Guest string `json:"guest"` + + // 存储类型 + StorageType string `json:"storage_type"` + + // 快照列表 + Snapshots []SimpleSnapshot `json:"snapshots"` + Properties map[string]string `json:"properties"` +} diff --git a/pkg/apis/compute/isolated_device.go b/pkg/apis/compute/isolated_device.go new file mode 100644 index 0000000000..a834dc62c5 --- /dev/null +++ b/pkg/apis/compute/isolated_device.go @@ -0,0 +1,29 @@ +// 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 "yunion.io/x/onecloud/pkg/apis" + +type IsolateDeviceDetails struct { + apis.StandaloneResourceDetails + SIsolatedDevice + + // 宿主机名称 + Host string `json:"host"` + // 云主机名称 + Guest string `json:"guest"` + // 云主机状态 + GuestStatus string `json:"guest_status"` +} diff --git a/pkg/apis/compute/keypair.go b/pkg/apis/compute/keypair.go index ef4836e73a..8adbfc2382 100644 --- a/pkg/apis/compute/keypair.go +++ b/pkg/apis/compute/keypair.go @@ -40,3 +40,18 @@ type KeypairCreateInput struct { // default: RSA Scheme string `json:"scheme"` } + +type KeypairDetails struct { + apis.StandaloneResourceDetails + SKeypair + + // 私钥长度 + PrivateKeyLen int `json:"private_key_len"` + // 关联云主机次数 + LinkedGuestCount int `json:"linked_guest_count"` + + // 用户Id + OwnerId string `json:"owner_id"` + // 用户名称 + OwnerName string `json:"owner_name"` +} diff --git a/pkg/apis/compute/loadbalancer.go b/pkg/apis/compute/loadbalancer.go index 6dbcd13535..d4ad21ed0c 100644 --- a/pkg/apis/compute/loadbalancer.go +++ b/pkg/apis/compute/loadbalancer.go @@ -114,3 +114,20 @@ type LoadbalancerClusterListInput struct { type LoadbalancerAclListInput struct { apis.SharableVirtualResourceListInput } + +type LoadbalancerDetails struct { + apis.VirtualResourceDetails + SLoadbalancer + + CloudproviderInfo + + // 公网IP地址 + Eip string `json:"eip"` + // 公网IP地址类型: 弹性、非弹性 + // example: public_ip + EipMode string `json:"eip_mode"` + // 虚拟私有网络名称 + Vpc string `json:"vpc"` + // 后端服务器组名称 + BackendGroup string `json:"backend_group"` +} diff --git a/pkg/apis/compute/loadbalanceracl.go b/pkg/apis/compute/loadbalanceracl.go new file mode 100644 index 0000000000..66a23b36b9 --- /dev/null +++ b/pkg/apis/compute/loadbalanceracl.go @@ -0,0 +1,22 @@ +// 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 "yunion.io/x/onecloud/pkg/apis" + +type LoadbalancerAclDetails struct { + apis.SharableVirtualResourceDetails + SLoadbalancerAcl +} diff --git a/pkg/apis/compute/loadbalanceragent.go b/pkg/apis/compute/loadbalanceragent.go new file mode 100644 index 0000000000..879adf125a --- /dev/null +++ b/pkg/apis/compute/loadbalanceragent.go @@ -0,0 +1,25 @@ +// 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 "yunion.io/x/onecloud/pkg/apis" + +type LoadbalancerAgentDetails struct { + apis.StandaloneResourceDetails + SLoadbalancerAgent + + ZoneInfo ZoneInfo + Cluster string `json:"cluster"` +} diff --git a/pkg/apis/compute/loadbalancerbackend.go b/pkg/apis/compute/loadbalancerbackend.go new file mode 100644 index 0000000000..7b47b92924 --- /dev/null +++ b/pkg/apis/compute/loadbalancerbackend.go @@ -0,0 +1,26 @@ +// 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 "yunion.io/x/onecloud/pkg/apis" + +type LoadbalancerBackendDetails struct { + apis.VirtualResourceDetails + SLoadbalancerBackend + + CloudproviderInfo + + VpcId string `json:"vpc_id"` +} diff --git a/pkg/apis/compute/loadbalancerbackendgroup.go b/pkg/apis/compute/loadbalancerbackendgroup.go new file mode 100644 index 0000000000..7f26a6db40 --- /dev/null +++ b/pkg/apis/compute/loadbalancerbackendgroup.go @@ -0,0 +1,25 @@ +// 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 "yunion.io/x/onecloud/pkg/apis" + +type LoadbalancerBackendGroupDetails struct { + apis.VirtualResourceDetails + SLoadbalancerBackendGroup + + Loadbalancer string `json:"loadbalancer"` + CloudregionInfo +} diff --git a/pkg/apis/compute/loadbalancercertificate.go b/pkg/apis/compute/loadbalancercertificate.go new file mode 100644 index 0000000000..c7dba5dfbd --- /dev/null +++ b/pkg/apis/compute/loadbalancercertificate.go @@ -0,0 +1,22 @@ +// 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 "yunion.io/x/onecloud/pkg/apis" + +type LoadbalancerCertificateDetails struct { + apis.VirtualResourceDetails + SLoadbalancerCertificate +} diff --git a/pkg/apis/compute/loadbalancercluster.go b/pkg/apis/compute/loadbalancercluster.go new file mode 100644 index 0000000000..5c76a8732e --- /dev/null +++ b/pkg/apis/compute/loadbalancercluster.go @@ -0,0 +1,24 @@ +// 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 "yunion.io/x/onecloud/pkg/apis" + +type LoadbalancerCusterDetails struct { + apis.StandaloneResourceDetails + SLoadbalancerCluster + + ZoneInfo +} diff --git a/pkg/apis/compute/loadbalancerlistener.go b/pkg/apis/compute/loadbalancerlistener.go new file mode 100644 index 0000000000..7ba7e0dc7c --- /dev/null +++ b/pkg/apis/compute/loadbalancerlistener.go @@ -0,0 +1,30 @@ +// 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 "yunion.io/x/onecloud/pkg/apis" + +type LoadbalancerListenerDetails struct { + apis.VirtualResourceDetails + SLoadbalancerListener + + BackendGroup string `json:"backend_group"` + Loadbalancer string `json:"loadbalancer"` + AclName string `json:"acl_name"` + CertificateName string `json:"certificate_name"` + OriginCertificateId string `json:"origin_certificate_id"` + + CloudregionInfo +} diff --git a/pkg/apis/compute/loadbalancerlistenerrule.go b/pkg/apis/compute/loadbalancerlistenerrule.go new file mode 100644 index 0000000000..8727d5131d --- /dev/null +++ b/pkg/apis/compute/loadbalancerlistenerrule.go @@ -0,0 +1,26 @@ +// 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 "yunion.io/x/onecloud/pkg/apis" + +type LoadbalancerListenerRuleDetails struct { + apis.VirtualResourceDetails + SLoadbalancerListenerRule + + BackendGroup string `json:"backend_group"` + + CloudregionInfo +} diff --git a/pkg/apis/compute/loadbalancernetwork.go b/pkg/apis/compute/loadbalancernetwork.go new file mode 100644 index 0000000000..d18c2fbe50 --- /dev/null +++ b/pkg/apis/compute/loadbalancernetwork.go @@ -0,0 +1,27 @@ +// 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 "yunion.io/x/onecloud/pkg/apis" + +type LoadbalancernetworkDetails struct { + apis.JoinModelBaseDetails + SLoadbalancerNetwork + + // 负载均衡器名称 + Loadbalancer string `json:"loadbalancer"` + // IP子网名称 + Network string `json:"network"` +} diff --git a/pkg/apis/compute/nat.go b/pkg/apis/compute/nat.go index e14e64d39d..0406606e0f 100644 --- a/pkg/apis/compute/nat.go +++ b/pkg/apis/compute/nat.go @@ -39,3 +39,35 @@ type SNatDCreateInput struct { ExternalPort int IpProtocol string } + +type NatDEntryDetails struct { + apis.StandaloneResourceDetails + // SNatDEntry + + Natgateway string `json:"natgateway"` + RealName string `json:"real_name"` +} + +type NatSEntryDetails struct { + apis.StandaloneResourceDetails + // SNatSEntry + + Natgateway string `json:"natgateway"` + RealName string `json:"real_name"` + Network SimpleNetwork `json:"network"` +} + +type SimpleNetwork struct { + Id string `json:"id"` + Name string `json:"name"` +} + +type NatgatewayDetails struct { + apis.StandaloneResourceDetails + SNatGateway + + CloudproviderInfo + Vpc string `json:"vpc"` + + NatSpec string `json:"nat_spec"` +} diff --git a/pkg/apis/compute/network.go b/pkg/apis/compute/network.go index 4609761fb6..42f35b6167 100644 --- a/pkg/apis/compute/network.go +++ b/pkg/apis/compute/network.go @@ -115,25 +115,38 @@ type NetworkCreateInput struct { } type NetworkDetails struct { - apis.Meta apis.SharableVirtualResourceDetails - CloudproviderDetails + CloudproviderInfo SNetwork - Wire string `json:"wire"` - Exit bool `json:"exit"` - Ports int `json:"ports"` - PortsUsed int `json:"ports_used"` - Vnics int `json:"vnics"` - BmVnics int `json:"bm_nics"` - LbVnics int `json:"lb_vnics"` - EipVnics int `json:"eip_vnics"` - GroupVnics int `json:"group_vnics"` - ReserveVnics int `json:"reserve_vnics"` - Vpc string `json:"vpc"` - VpcId string `json:"vpc_id"` - VpcExtId string `json:"vpc_ext_id"` + // 二层网络名称 + Wire string `json:"wire"` + // 是否是内网 + Exit bool `json:"exit"` + // 端口数量 + Ports int `json:"ports"` + // 已使用端口数量 + PortsUsed int `json:"ports_used"` + // 网卡数量 + Vnics int `json:"vnics"` + // 裸金属网卡数量 + BmVnics int `json:"bm_nics"` + // 负载均衡网卡数量 + LbVnics int `json:"lb_vnics"` + // 浮动Ip网卡数量 + EipVnics int `json:"eip_vnics"` + GroupVnics int `json:"group_vnics"` + // 预留IP数量 + ReserveVnics int `json:"reserve_vnics"` + // 虚拟私有网络名称 + Vpc string `json:"vpc"` + // 虚拟私有网络Id + VpcId string `json:"vpc_id"` + // 虚拟私有网络外部Id + VpcExtId string `json:"vpc_ext_id"` + + // 路由信息 Routes [][]string `json:"routes"` Schedtags []SchedtagShortDescDetails `json:"schedtags"` } diff --git a/pkg/apis/compute/networkinterface.go b/pkg/apis/compute/networkinterface.go new file mode 100644 index 0000000000..7bc3039494 --- /dev/null +++ b/pkg/apis/compute/networkinterface.go @@ -0,0 +1,40 @@ +// 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 "yunion.io/x/onecloud/pkg/apis" + +type NetworkInterfaceNetworkInfo struct { + // Ip子网Id + NetworkId string `json:"network_id"` + // IP地址 + IpAddr string `json:"ip_addr"` + // 是否是主ip地址 + Primary bool `json:"primary"` + // 弹性网卡id + NetworkinterfaceId string `json:"networkinterface_id"` + // IP子网名称 + Network string `json:"network"` +} + +type NetworkInterfaceDetails struct { + apis.StandaloneResourceDetails + SNetworkInterface + + CloudproviderInfo + + // 弹性网卡网络信息 + Networks []NetworkInterfaceNetworkInfo `json:"networks"` +} diff --git a/pkg/apis/compute/networkschedtag.go b/pkg/apis/compute/networkschedtag.go new file mode 100644 index 0000000000..8157b92a61 --- /dev/null +++ b/pkg/apis/compute/networkschedtag.go @@ -0,0 +1,26 @@ +// 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 "yunion.io/x/onecloud/pkg/apis" + +type NetworkschedtagDetails struct { + apis.JoinModelBaseDetails + SNetworkschedtag + + // IP子网名称 + Network string `json:"network"` + Schedtag string `json:"schedtag"` +} diff --git a/pkg/apis/compute/reservedip.go b/pkg/apis/compute/reservedip.go index 046ce0c83f..307f816b13 100644 --- a/pkg/apis/compute/reservedip.go +++ b/pkg/apis/compute/reservedip.go @@ -36,3 +36,13 @@ type ReservedipListInput struct { // list all reserved ips, including expired ones All *bool `json:"all"` } + +type ReservedipDetails struct { + apis.ModelBaseDetails + SReservedip + + // IP子网名称 + Network string `json:"network"` + // 是否过期 + Expired bool `json:"expired"` +} diff --git a/pkg/apis/compute/routetable.go b/pkg/apis/compute/routetable.go new file mode 100644 index 0000000000..cb5f97f41c --- /dev/null +++ b/pkg/apis/compute/routetable.go @@ -0,0 +1,28 @@ +// 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 "yunion.io/x/onecloud/pkg/apis" + +type RouteTableDetails struct { + apis.VirtualResourceDetails + SRouteTable + CloudproviderInfo + + // 虚拟私有网络名称 + Vpc string `json:"vpc"` + // 区域名称 + Cloudregion string `json:"cloudregion"` +} diff --git a/pkg/apis/compute/schedpolicy.go b/pkg/apis/compute/schedpolicy.go new file mode 100644 index 0000000000..1877230e98 --- /dev/null +++ b/pkg/apis/compute/schedpolicy.go @@ -0,0 +1,25 @@ +// 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 "yunion.io/x/onecloud/pkg/apis" + +type SchedpolicyDetails struct { + apis.StandaloneResourceDetails + SSchedpolicy + + Schedtag string `json:"schedtag"` + ResourceType string `json:"resource_type"` +} diff --git a/pkg/apis/compute/schedtag.go b/pkg/apis/compute/schedtag.go index 263a0166d0..75d8a46b2c 100644 --- a/pkg/apis/compute/schedtag.go +++ b/pkg/apis/compute/schedtag.go @@ -58,3 +58,16 @@ type SchedtagListInput struct { // filter by type, alias for resource_type Type string `json:"type" deprecated-by:"resource_type"` } + +type SchedtagDetails struct { + apis.StandaloneResourceDetails + SSchedtag + + DynamicSchedtagCount int `json:"dynamic_schedtag_count"` + SchedpolicyCount int `json:"schedpolicy_count"` + ProjectId string `json:"project_id"` + HostCount int `json:"host_count"` + ServerCount int `json:"server_count"` + OtherCount int `json:"other_count"` + JoinModelKeyword string `json:"join_model_keyword"` +} diff --git a/pkg/apis/compute/secgroup.go b/pkg/apis/compute/secgroup.go index b5659876ff..9354dce306 100644 --- a/pkg/apis/compute/secgroup.go +++ b/pkg/apis/compute/secgroup.go @@ -164,3 +164,19 @@ type SecgroupFilterListInput struct { // filter by secgroup_id SecgroupId string `json:"secgroup_id" deprecated-by:"secgroup"` } + +type SecgroupDetails struct { + apis.SharableVirtualResourceDetails + SSecurityGroup + + // 关联云主机数量 + GuestCnt int `json:"guest_cnt"` + // 安全组缓存数量 + CacheCnt int `json:"cache_cnt"` + // 规则信息 + Rules string `json:"rules"` + // 入方向规则信息 + InRules string `json:"in_rules"` + // 出方向规则信息 + OutRules string `json:"out_rules"` +} diff --git a/pkg/apis/compute/secgroupcache.go b/pkg/apis/compute/secgroupcache.go new file mode 100644 index 0000000000..87da42c0a6 --- /dev/null +++ b/pkg/apis/compute/secgroupcache.go @@ -0,0 +1,27 @@ +// 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 "yunion.io/x/onecloud/pkg/apis" + +type SecurityGroupCacheDetails struct { + apis.StandaloneResourceDetails + SSecurityGroupCache + + CloudproviderInfo + + // 虚拟私有网络名称 + Vpc string `json:"vpc"` +} diff --git a/pkg/apis/compute/serversku.go b/pkg/apis/compute/serversku.go index d16bad57f5..825bfc863b 100644 --- a/pkg/apis/compute/serversku.go +++ b/pkg/apis/compute/serversku.go @@ -128,3 +128,23 @@ type ServerSkuCreateInput struct { // swagger:ignore Provider string } + +type ServerSkuDetails struct { + apis.StandaloneResourceDetails + SServerSku + + // 绑定云主机数量 + TotalGuestCount int `json:"total_guest_count"` + // 可用区名称 + Zone string `json:"zone"` + // 可用区外部Id + ZoneExtId string `json:"zone_ext_id"` + // 区域名称 + Region string `json:"region"` + // 区域Id + RegionId string `json:"region_id"` + // 区域外部Id + RegionExternalId string `json:"region_external_id"` + // 区域外部Id(不携带平台信息) + RegionExtId string `json:"region_ext_id"` +} diff --git a/pkg/apis/compute/snapshot.go b/pkg/apis/compute/snapshot.go index 13f2b90383..bf44f817e1 100644 --- a/pkg/apis/compute/snapshot.go +++ b/pkg/apis/compute/snapshot.go @@ -86,3 +86,25 @@ type InstanceSnapshotListInput struct { ServerFilterListInput } + +type SnapshotDetails struct { + apis.VirtualResourceDetails + SSnapshot + + CloudproviderInfo + + // 存储类型 + StorageType string `json:"storage_type"` + // 磁盘状态 + DiskStatus string `json:"disk_status"` + // 云主机名称 + Guest string `json:"guest"` + // 云主机Id + GuestId string `json:"guest_id"` + // 云主机状态 + GuestStatus string `json:"guest_status"` + // 磁盘名称 + DiskName string `json:"disk_name"` + // 是否是子快照 + IsSubSnapshot bool `json:"is_sub_snapshot,allowempty"` +} diff --git a/pkg/apis/compute/snapshotpolicy.go b/pkg/apis/compute/snapshotpolicy.go new file mode 100644 index 0000000000..b2ca569ba5 --- /dev/null +++ b/pkg/apis/compute/snapshotpolicy.go @@ -0,0 +1,29 @@ +// 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 "yunion.io/x/onecloud/pkg/apis" + +type SnapshotPolicyDetails struct { + apis.VirtualResourceDetails + //SSnapshotPolicy + apis.SVirtualResourceBase + RetentionDays int `json:"retention_days"` + RepeatWeekdays []int `json:"repeat_weekdays"` + TimePoints []int `json:"time_points"` + IsActivated *bool `json:"is_activated,omitempty"` + + BindingDiskCount int `json:"binding_disk_count"` +} diff --git a/pkg/apis/compute/snapshotpolicycache.go b/pkg/apis/compute/snapshotpolicycache.go new file mode 100644 index 0000000000..4a24b2e9e3 --- /dev/null +++ b/pkg/apis/compute/snapshotpolicycache.go @@ -0,0 +1,24 @@ +// 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 "yunion.io/x/onecloud/pkg/apis" + +type SnapshotPolicyCacheDetails struct { + apis.StandaloneResourceDetails + SSnapshotPolicyCache + + CloudproviderInfo +} diff --git a/pkg/apis/compute/snapshotpolicydisk.go b/pkg/apis/compute/snapshotpolicydisk.go new file mode 100644 index 0000000000..17b7f7963e --- /dev/null +++ b/pkg/apis/compute/snapshotpolicydisk.go @@ -0,0 +1,27 @@ +// 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 ( + "yunion.io/x/onecloud/pkg/apis" +) + +type SnapshotPolicyDiskDetails struct { + apis.JoinModelBaseDetails + + // 快照策略名称 + Snapshotpolicy string `json:"snapshotpolicy"` + Disk DiskDetails `json:"disk"` +} diff --git a/pkg/apis/compute/storage.go b/pkg/apis/compute/storage.go index a885b65907..3c8da6f9c7 100644 --- a/pkg/apis/compute/storage.go +++ b/pkg/apis/compute/storage.go @@ -111,3 +111,27 @@ type StorageCreateInput struct { // example: /nfs_root/ NfsSharedDir string `json:"nfs_shared_dir"` } + +type StorageDetails struct { + apis.StandaloneResourceDetails + SStorage + + // 容量大小, 单位Mb + Capacity int64 `json:"capacity"` + // 已使用容量大小 + Used int64 `json:"used"` + // 浪费容量大小(异常磁盘大小总和) + Wasted int64 `json:"wasted"` + // 虚拟容量大小 + VCapacity int64 `json:"vcapacity"` + // 超分率 + CommitRate float64 `json:"commit_rate"` + // 可使用容量 + FreeCapacity int64 `json:"free_capacity"` + + CloudproviderInfo + Schedtags []SchedtagShortDescDetails `json:"schedtags"` + + // 超分比 + CommitBound float32 `json:"commit_bound"` +} diff --git a/pkg/apis/compute/storagecache.go b/pkg/apis/compute/storagecache.go new file mode 100644 index 0000000000..2c055e32dc --- /dev/null +++ b/pkg/apis/compute/storagecache.go @@ -0,0 +1,35 @@ +// 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 ( + "yunion.io/x/jsonutils" + + "yunion.io/x/onecloud/pkg/apis" +) + +type StoragecacheDetails struct { + apis.StandaloneResourceDetails + SStoragecache + + // 存储列表 + Storages []string `json:"storages"` + // 缓存镜像总大小 + Size int64 `json:"size"` + // 缓存镜像个数 + Count int `json:"count"` + // 通过一致性哈希获取的一个管理宿主机信息 + Host *jsonutils.JSONDict `json:"host"` +} diff --git a/pkg/apis/compute/storagecachedimage.go b/pkg/apis/compute/storagecachedimage.go new file mode 100644 index 0000000000..1635373e2a --- /dev/null +++ b/pkg/apis/compute/storagecachedimage.go @@ -0,0 +1,41 @@ +// 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 ( + "yunion.io/x/jsonutils" + + "yunion.io/x/onecloud/pkg/apis" +) + +type StoragecachedimageDetails struct { + apis.JoinModelBaseDetails + + // 存储缓存名称 + Storagecache string `json:"storagecache"` + // 缓存镜像名称 + Cachedimage string `json:"cachedimage"` + + // 存储列表 + Storages []string `json:"storages"` + // 通过一致性哈希获取的一个宿主机详情 + Host *jsonutils.JSONDict `json:"host"` + // 镜像名称 + Image string `json:"image"` + // 镜像大小 + Size int64 `json:"size"` + // 引用次数 + Reference int `json:"reference"` +} diff --git a/pkg/apis/compute/storageschedtag.go b/pkg/apis/compute/storageschedtag.go new file mode 100644 index 0000000000..7b8e07199a --- /dev/null +++ b/pkg/apis/compute/storageschedtag.go @@ -0,0 +1,26 @@ +// 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 "yunion.io/x/onecloud/pkg/apis" + +type StorageschedtagDetails struct { + apis.JoinModelBaseDetails + SStorageschedtag + + // 存储名称 + Storage string `json:"storage"` + Schedtag string `json:"schedtag"` +} diff --git a/pkg/apis/compute/vpc.go b/pkg/apis/compute/vpc.go new file mode 100644 index 0000000000..68630c206d --- /dev/null +++ b/pkg/apis/compute/vpc.go @@ -0,0 +1,36 @@ +// 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 "yunion.io/x/onecloud/pkg/apis" + +type VpcDetails struct { + apis.StandaloneResourceDetails + SVpc + CloudproviderInfo + + // 二层网络数量 + // example: 1 + WireCount int `json:"wire_count"` + // IP子网个数 + // example: 2 + NetworkCount int `json:"network_count"` + // 路由表个数 + // example: 0 + RoutetableCount int `json:"routetable_count"` + // NAT网关个数 + // example: 0 + NatgatewayCount int `json:"natgateway_count"` +} diff --git a/pkg/apis/compute/wire.go b/pkg/apis/compute/wire.go index 8d04ac7ac7..cb50903fac 100644 --- a/pkg/apis/compute/wire.go +++ b/pkg/apis/compute/wire.go @@ -41,3 +41,21 @@ type WireCreateInput struct { // swagger:ignore ZoneId string } + +type WireDetails struct { + apis.StandaloneResourceDetails + SWire + + // 可用区Id + // exampe: zone1 + Zone string `json:"zone"` + // IP子网数量 + // example: 1 + Networks int `json:"networks"` + // VPC名称 + Vpc string `json:"vpc'` + // VPC外部Id + VpcExtId string `json:"vpc_ext_id"` + + CloudproviderInfo +} diff --git a/pkg/apis/compute/zone.go b/pkg/apis/compute/zone.go index 488d580d27..6712b2f0e5 100644 --- a/pkg/apis/compute/zone.go +++ b/pkg/apis/compute/zone.go @@ -29,3 +29,52 @@ type ZoneCreateInput struct { // swagger:ignore CloudregionId string } + +type ZoneDetails struct { + apis.StandaloneResourceDetails + SZone + + // 区域名称 + Cloudregion string `json:"cloudregion"` + // 平台 + // example: OneCloud + Provider string `json:"provider"` + + // 可用区底下的宿主机数量 + // example: 3 + Hosts int `json:"hosts"` + + // 可用区底下启用的宿主机数量 + // example: 2 + HostsEnabled int `json:"host_enabled"` + + // 可用区底下的裸金属服务器数量 + // example: 1 + Baremetals int `json:"baremetals"` + + // 可用区底下启用的裸金属服务器数量 + // example: 1 + BaremetalsEnabled int `json:"baremetals_enabled"` + + // 可用区底下的二层网络数量 + // example: 3 + Wires int `json:"wires"` + + // 可用区底下的子网数量 + // example: 1 + Networks int `json:"networks"` + + // 可用区底下的块存储数量 + // example: 1 + Storages int `json:"storages"` +} + +type ZoneInfo struct { + // 可用区名称 + // example: zone1 + Zone string `json:"zone"` + + // 纳管云的zoneId + ZoneExtId string `json:"zone_ext_id"` + CloudregionInfo +} diff --git a/pkg/apis/identity/credential.go b/pkg/apis/identity/credential.go new file mode 100644 index 0000000000..5279a0ed08 --- /dev/null +++ b/pkg/apis/identity/credential.go @@ -0,0 +1,27 @@ +// 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 identity + +import "yunion.io/x/onecloud/pkg/apis" + +type CredentialDetails struct { + apis.StandaloneResourceDetails + SCredential + + Blob string `json:"blob"` + User string `json:"user"` + Domain string `json:"domain"` + DomainId string `json:"domain_id"` +} diff --git a/pkg/apis/identity/domain.go b/pkg/apis/identity/domain.go new file mode 100644 index 0000000000..c6291dff55 --- /dev/null +++ b/pkg/apis/identity/domain.go @@ -0,0 +1,29 @@ +// 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 identity + +import "yunion.io/x/onecloud/pkg/apis" + +type DomainDetails struct { + apis.StandaloneResourceDetails + SDomain + + UserCout int `json:"user_count"` + GroupCount int `json:"group_count"` + ProjectCout int `json:"project_count"` + RoleCount int `json:"role_count"` + PolicyCount int `json:"policy_count"` + IdpCount int `json:"idp_count"` +} diff --git a/pkg/apis/identity/endpoint.go b/pkg/apis/identity/endpoint.go new file mode 100644 index 0000000000..d80854ce06 --- /dev/null +++ b/pkg/apis/identity/endpoint.go @@ -0,0 +1,22 @@ +// 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 identity + +import "yunion.io/x/onecloud/pkg/apis" + +type EndpointDetails struct { + apis.StandaloneResourceDetails + SEndpoint +} diff --git a/pkg/apis/identity/group.go b/pkg/apis/identity/group.go new file mode 100644 index 0000000000..765167b96d --- /dev/null +++ b/pkg/apis/identity/group.go @@ -0,0 +1,27 @@ +// 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 identity + +import "yunion.io/x/onecloud/pkg/apis" + +type GroupDetails struct { + apis.StandaloneResourceDetails + SGroup + + // 用户数量 + UserCount int `json:"user_count"` + // 项目数量 + ProjectCount int `json:"project_count"` +} diff --git a/pkg/apis/identity/identityprovider.go b/pkg/apis/identity/identityprovider.go new file mode 100644 index 0000000000..e991796105 --- /dev/null +++ b/pkg/apis/identity/identityprovider.go @@ -0,0 +1,31 @@ +// 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 identity + +import "yunion.io/x/onecloud/pkg/apis" + +type IdentityProviderDetails struct { + apis.StandaloneResourceDetails + + SyncIntervalSeconds int `json:"sync_interval_seconds"` + TargetDomain string `json:"target_domain"` + + RoleCount int `json:"role_count,allowempty"` + UserCount int `json:"user_count,allowempty"` + PolicyCount int `json:"policy_count,allowempty"` + DomainCount int `json:"domain_count,allowempty"` + ProjectCount int `json:"project_count,allowempty"` + GroupCount int `json:"group_count,allowempty"` +} diff --git a/pkg/apis/identity/policy.go b/pkg/apis/identity/policy.go new file mode 100644 index 0000000000..afb88ec6b5 --- /dev/null +++ b/pkg/apis/identity/policy.go @@ -0,0 +1,22 @@ +// 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 identity + +import "yunion.io/x/onecloud/pkg/apis" + +type PolicyDetails struct { + apis.StandaloneResourceDetails + SPolicy +} diff --git a/pkg/apis/identity/project.go b/pkg/apis/identity/project.go new file mode 100644 index 0000000000..9a2c47240f --- /dev/null +++ b/pkg/apis/identity/project.go @@ -0,0 +1,34 @@ +// 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 identity + +import ( + "time" + + "yunion.io/x/jsonutils" + + "yunion.io/x/onecloud/pkg/apis" +) + +type ProjectDetails struct { + apis.StandaloneResourceDetails + SProject + + GroupCount int `json:"group_count"` + UserCount int `json:"user_count"` + ExtResource jsonutils.JSONObject `json:"ext_resource"` + ExtResourcesLastUpdate time.Time `json:"ext_resources_last_update"` + ExtResourcesNextUpdate time.Time `json:"ext_resources_next_update"` +} diff --git a/pkg/apis/identity/region.go b/pkg/apis/identity/region.go new file mode 100644 index 0000000000..a791728a2e --- /dev/null +++ b/pkg/apis/identity/region.go @@ -0,0 +1,24 @@ +// 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 identity + +import "yunion.io/x/onecloud/pkg/apis" + +type RegionDetails struct { + apis.StandaloneResourceDetails + SRegion + + EndpointCount int `json:"endpoint_count"` +} diff --git a/pkg/apis/identity/role.go b/pkg/apis/identity/role.go new file mode 100644 index 0000000000..c0d2c87500 --- /dev/null +++ b/pkg/apis/identity/role.go @@ -0,0 +1,27 @@ +// 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 identity + +import "yunion.io/x/onecloud/pkg/apis" + +type RoleDetails struct { + apis.StandaloneResourceDetails + SRole + + UserCount int `json:"user_count"` + GroupCount int `json:"group_count"` + ProjectCount int `json:"project_count"` + MatchPolicies []string `json:"match_policies"` +} diff --git a/pkg/apis/identity/service.go b/pkg/apis/identity/service.go new file mode 100644 index 0000000000..56dc29af98 --- /dev/null +++ b/pkg/apis/identity/service.go @@ -0,0 +1,24 @@ +// 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 identity + +import "yunion.io/x/onecloud/pkg/apis" + +type ServiceDetails struct { + apis.StandaloneResourceDetails + SService + + EndpointCount int `json:"endpoint_count"` +} diff --git a/pkg/apis/identity/user.go b/pkg/apis/identity/user.go new file mode 100644 index 0000000000..02b104c569 --- /dev/null +++ b/pkg/apis/identity/user.go @@ -0,0 +1,33 @@ +// 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 identity + +import ( + "time" + + "yunion.io/x/onecloud/pkg/apis" +) + +type UserDetails struct { + apis.StandaloneResourceDetails + SUser + + GroupCount int `json:"group_count"` + ProjectCount int `json:"project_count"` + CredentialCount int `json:"credential_count"` + FailedAuthCount int `json:"failed_auth_count"` + FailedAuthAt time.Time `json:"failed_auth_at"` + PasswordExpiresAt time.Time `json:"password_expires_at"` +} diff --git a/pkg/apis/identity/zz_generated.model.go b/pkg/apis/identity/zz_generated.model.go index 280a4ecb68..345c8dbfdf 100644 --- a/pkg/apis/identity/zz_generated.model.go +++ b/pkg/apis/identity/zz_generated.model.go @@ -91,6 +91,12 @@ type SFederatedUser struct { DisplayName string `json:"display_name"` } +// SGroup is an autogenerated struct via yunion.io/x/onecloud/pkg/keystone/models.SGroup. +type SGroup struct { + SIdentityBaseResource + Displayname string `json:"displayname"` +} + // SIdentityBaseResource is an autogenerated struct via yunion.io/x/onecloud/pkg/keystone/models.SIdentityBaseResource. type SIdentityBaseResource struct { apis.SStandaloneResourceBase @@ -153,6 +159,13 @@ type SPolicy struct { Blob interface{} `json:"blob"` } +// SProject is an autogenerated struct via yunion.io/x/onecloud/pkg/keystone/models.SProject. +type SProject struct { + SIdentityBaseResource + ParentId string `json:"parent_id"` + IsDomain *bool `json:"is_domain,omitempty"` +} + // SRegion is an autogenerated struct via yunion.io/x/onecloud/pkg/keystone/models.SRegion. type SRegion struct { apis.SStandaloneResourceBase @@ -174,6 +187,21 @@ type SService struct { Extra interface{} `json:"extra"` } +// SUser is an autogenerated struct via yunion.io/x/onecloud/pkg/keystone/models.SUser. +type SUser struct { + SEnabledIdentityBaseResource + Email string `json:"email"` + Mobile string `json:"mobile"` + Displayname string `json:"displayname"` + LastActiveAt time.Time `json:"last_active_at"` + LastLoginIp string `json:"last_login_ip"` + LastLoginSource string `json:"last_login_source"` + IsSystemAccount *bool `json:"is_system_account,omitempty"` + DefaultProjectId string `json:"default_project_id"` + AllowWebConsole *bool `json:"allow_web_console,omitempty"` + EnableMfa *bool `json:"enable_mfa,omitempty"` +} + // SUsergroupMembership is an autogenerated struct via yunion.io/x/onecloud/pkg/keystone/models.SUsergroupMembership. type SUsergroupMembership struct { apis.SResourceBase diff --git a/pkg/apis/image/guestimage.go b/pkg/apis/image/guestimage.go new file mode 100644 index 0000000000..81086016fd --- /dev/null +++ b/pkg/apis/image/guestimage.go @@ -0,0 +1,39 @@ +// 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 image + +import ( + "yunion.io/x/jsonutils" + + "yunion.io/x/onecloud/pkg/apis" +) + +type GuestImageDetails struct { + apis.SharableVirtualResourceDetails + SGuestImage + + ImageIds jsonutils.JSONObject `json:"image_ids"` + + //Status string `json:"status"` + Size int64 `json:"size"` + MinRamMb int32 `json:"min_ram_mb"` + DiskFormat string `json:"disk_format"` + RootImage jsonutils.JSONObject `json:"root_image"` + DataImages jsonutils.JSONObject `json:"data_images"` + + Properties *jsonutils.JSONDict `json:"properties"` + + DisableDelete bool `json:"disable_delete"` +} diff --git a/pkg/apis/image/image.go b/pkg/apis/image/image.go index 58874a1c66..0bdc180052 100644 --- a/pkg/apis/image/image.go +++ b/pkg/apis/image/image.go @@ -15,6 +15,10 @@ package image import ( + "time" + + "yunion.io/x/jsonutils" + "yunion.io/x/onecloud/pkg/apis" ) @@ -30,3 +34,17 @@ type ImageListInput struct { type GuestImageListInput struct { apis.SharableVirtualResourceListInput } + +type ImageDetails struct { + apis.SharableVirtualResourceDetails + SImage + + // 镜像属性信息 + Properties *jsonutils.JSONDict `json:"properties"` + + // 自动清除时间 + AutoDeleteAt time.Time `json:"auto_delete_at"` + // 删除保护 + DisableDelete bool `json:"disable_delete"` + //OssChecksum string `json:"oss_checksum"` +} diff --git a/pkg/apis/modelbase.go b/pkg/apis/list.go similarity index 72% rename from pkg/apis/modelbase.go rename to pkg/apis/list.go index 9e402df429..ed93ba78f6 100644 --- a/pkg/apis/modelbase.go +++ b/pkg/apis/list.go @@ -14,17 +14,6 @@ package apis -type ModelBaseDetails struct { - CanDelete bool `json:"can_delete"` - DeleteFailReason string `json:"delete_fail_reason"` - CanUpdate bool `json:"can_update"` - UpdateFailReason string `json:"update_fail_reason"` -} - -type ModelBaseShortDescDetail struct { - ResName string `json:"res_name"` -} - type ModelBaseListInput struct { Meta @@ -88,3 +77,76 @@ type IncrementalListInput struct { // 用于指定增量加载的标记 PagingMarker string `json:"paging_marker"` } + +type VirtualResourceListInput struct { + StatusStandaloneResourceListInput + + ProjectizedResourceListInput + + // 列表中包含标记为"系统资源"的资源 + System *bool `json:"system"` + // 是否显示回收站内的资源,默认不显示(对实现了回收站的资源有效,例如主机,磁盘,镜像) + PendingDelete *bool `json:"pending_delete"` + // 是否显示所有资源,包括回收站和不再回收站的资源 + // TODO: fix this??? + PendingDeleteAll *bool `json:"-"` +} + +type ResourceBaseListInput struct { + ModelBaseListInput +} + +type SharableResourceListInput struct { + // 根据资源是否共享过滤列表 + IsPublic *bool `json:"is_public"` +} + +type SharableVirtualResourceListInput struct { + VirtualResourceListInput + + // 根据资源的共享范围过滤列表,可能值为:system, domain, project + PublicScope string `json:"public_scope"` +} + +type AdminSharableVirtualResourceListInput struct { + SharableVirtualResourceListInput +} + +type STag struct { + // 标签key + Key string + // 标签Value + Value string +} + +type StandaloneResourceListInput struct { + ResourceBaseListInput + + // 通过标签过滤 + Tags []STag `json:"tags"` + // 返回资源的标签不包含特定的用户标签 + WithoutUserMeta bool `json:"without_user_meta"` + // 返回列表数据中包含资源的标签数据(Metadata) + WithMeta *bool `json:"with_meta"` + // 显示所有的资源,包括模拟的资源 + ShowEmulated *bool `json:"show_emulated"` + + // 以资源名称过滤列表 + Names []string `json:"name"` + // 以资源ID过滤列表 + Ids []string `json:"id"` +} + +type StatusStandaloneResourceListInput struct { + StandaloneResourceListInput + + // 以资源的状态过滤列表 + Status []string `json:"status"` +} + +type EnabledStatusStandaloneResourceListInput struct { + StatusStandaloneResourceListInput + + // 以资源是否启用/禁用过滤列表 + Enabled *bool `json:"enabled"` +} diff --git a/pkg/apis/notify/contact.go b/pkg/apis/notify/contact.go new file mode 100644 index 0000000000..b30695d6ca --- /dev/null +++ b/pkg/apis/notify/contact.go @@ -0,0 +1,25 @@ +// 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 notify + +import "yunion.io/x/onecloud/pkg/apis" + +type ContactDetails struct { + apis.ModelBaseDetails + + Id string `json:"id"` + Name string `json:"name"` + Details string `json:"details"` +} diff --git a/pkg/apis/resourcebase.go b/pkg/apis/notify/doc.go similarity index 89% rename from pkg/apis/resourcebase.go rename to pkg/apis/notify/doc.go index c569309f20..b253d2aee0 100644 --- a/pkg/apis/resourcebase.go +++ b/pkg/apis/notify/doc.go @@ -12,8 +12,4 @@ // See the License for the specific language governing permissions and // limitations under the License. -package apis - -type ResourceBaseListInput struct { - ModelBaseListInput -} +package notify // import "yunion.io/x/onecloud/pkg/apis/notify" diff --git a/pkg/apis/sharablevirtualresource.go b/pkg/apis/notify/notification.go similarity index 50% rename from pkg/apis/sharablevirtualresource.go rename to pkg/apis/notify/notification.go index 640c3e2370..2400807f08 100644 --- a/pkg/apis/sharablevirtualresource.go +++ b/pkg/apis/notify/notification.go @@ -12,30 +12,18 @@ // See the License for the specific language governing permissions and // limitations under the License. -package apis +package notify + +import ( + "yunion.io/x/jsonutils" + + "yunion.io/x/onecloud/pkg/apis" +) + +type NotificationDetails struct { + apis.ModelBaseDetails -type SharedProject struct { - Id string `json:"id"` Name string `json:"name"` -} -type SharableVirtualResourceDetails struct { - SharedProjects []SharedProject `json:"shared_projects"` - VirtualResourceDetails -} - -type SharableResourceListInput struct { - // 根据资源是否共享过滤列表 - IsPublic *bool `json:"is_public"` -} - -type SharableVirtualResourceListInput struct { - VirtualResourceListInput - - // 根据资源的共享范围过滤列表,可能值为:system, domain, project - PublicScope string `json:"public_scope"` -} - -type AdminSharableVirtualResourceListInput struct { - SharableVirtualResourceListInput + UserList jsonutils.JSONObject `json:"user_list"` } diff --git a/pkg/apis/notify/notify.go b/pkg/apis/notify/notify.go new file mode 100644 index 0000000000..dfa0dc05f3 --- /dev/null +++ b/pkg/apis/notify/notify.go @@ -0,0 +1,15 @@ +// 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 notify diff --git a/pkg/apis/output.go b/pkg/apis/output.go new file mode 100644 index 0000000000..132521ff29 --- /dev/null +++ b/pkg/apis/output.go @@ -0,0 +1,67 @@ +// 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 + +type ModelBaseDetails struct { + Meta + + // 资源是否可以删除, 若为flase, delete_fail_reason会返回不能删除的原因 + // example: true + CanDelete bool `json:"can_delete"` + + // 资源不能删除的原因 + DeleteFailReason string `json:"delete_fail_reason"` + + // 资源是否可以更新, 若为false,update_fail_reason会返回资源不能删除的原因 + // example: true + CanUpdate bool `json:"can_update"` + + // 资源不能删除的原因 + UpdateFailReason string `json:"update_fail_reason"` +} + +type JoinModelBaseDetails struct { + ModelBaseDetails +} + +type ModelBaseShortDescDetail struct { + ResName string `json:"res_name"` +} + +type SharedProject struct { + Id string `json:"id"` + Name string `json:"name"` +} + +type SharableVirtualResourceDetails struct { + VirtualResourceDetails + + SharedProjects []SharedProject `json:"shared_projects"` +} + +type StandaloneResourceShortDescDetail struct { + ModelBaseShortDescDetail + + Id string `json:"id"` + Name string `json:"name"` +} + +type VirtualResourceDetails struct { + StandaloneResourceDetails +} + +type StandaloneResourceDetails struct { + ModelBaseDetails +} diff --git a/pkg/apis/standaloneresource.go b/pkg/apis/standaloneresource.go deleted file mode 100644 index c607421907..0000000000 --- a/pkg/apis/standaloneresource.go +++ /dev/null @@ -1,61 +0,0 @@ -// 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 - -type StandaloneResourceShortDescDetail struct { - ModelBaseShortDescDetail - - Id string `json:"id"` - Name string `json:"name"` -} - -type STag struct { - // 标签key - Key string - // 标签Value - Value string -} - -type StandaloneResourceListInput struct { - ResourceBaseListInput - - // 通过标签过滤 - Tags []STag `json:"tags"` - // 返回资源的标签不包含特定的用户标签 - WithoutUserMeta bool `json:"without_user_meta"` - // 返回列表数据中包含资源的标签数据(Metadata) - WithMeta *bool `json:"with_meta"` - // 显示所有的资源,包括模拟的资源 - ShowEmulated *bool `json:"show_emulated"` - - // 以资源名称过滤列表 - Names []string `json:"name"` - // 以资源ID过滤列表 - Ids []string `json:"id"` -} - -type StatusStandaloneResourceListInput struct { - StandaloneResourceListInput - - // 以资源的状态过滤列表 - Status []string `json:"status"` -} - -type EnabledStatusStandaloneResourceListInput struct { - StatusStandaloneResourceListInput - - // 以资源是否启用/禁用过滤列表 - Enabled *bool `json:"enabled"` -} diff --git a/pkg/cloudcommon/db/caller.go b/pkg/cloudcommon/db/caller.go index a62eec1a09..8d937f6df3 100644 --- a/pkg/cloudcommon/db/caller.go +++ b/pkg/cloudcommon/db/caller.go @@ -172,8 +172,8 @@ func ListItemFilter(manager IModelManager, ctx context.Context, q *sqlchemy.SQue return ret[0].Interface().(*sqlchemy.SQuery), nil } -func GetExtraDetails(model IModel, ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject) (*jsonutils.JSONDict, error) { - ret, err := call(model, "GetExtraDetails", ctx, userCred, query) +func GetExtraDetails(model IModel, ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject, details bool) (*jsonutils.JSONDict, error) { + ret, err := call(model, "GetExtraDetails", ctx, userCred, query, details) if err != nil { return nil, httperrors.NewGeneralError(err) } diff --git a/pkg/cloudcommon/db/count.go b/pkg/cloudcommon/db/count.go deleted file mode 100644 index a78bdd2013..0000000000 --- a/pkg/cloudcommon/db/count.go +++ /dev/null @@ -1,46 +0,0 @@ -// 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 db - -import ( - "reflect" - "strings" - - "yunion.io/x/jsonutils" - "yunion.io/x/pkg/utils" -) - -func FetchModelExtraCountProperties(model IModel, extra *jsonutils.JSONDict) *jsonutils.JSONDict { - selfValue := reflect.ValueOf(model) - selfType := reflect.TypeOf(model) - for i := 0; i < selfValue.NumMethod(); i += 1 { - methodValue := selfValue.Method(i) - methodType := methodValue.Type() - if methodType.NumIn() != 0 || methodType.NumOut() != 2 { - continue - } - methodName := selfType.Method(i).Name - tokens := utils.CamelSplitTokens(methodName) - if len(tokens) < 3 { - continue - } - if strings.EqualFold(tokens[0], "get") && strings.EqualFold(tokens[len(tokens)-1], "count") { - resName := strings.ToLower(strings.Join(tokens[1:], "_")) - outs := methodValue.Call([]reflect.Value{}) - extra.Add(jsonutils.NewInt(outs[0].Int()), resName) - } - } - return extra -} diff --git a/pkg/cloudcommon/db/db_dispatcher.go b/pkg/cloudcommon/db/db_dispatcher.go index 91b6f38232..034d13ea7f 100644 --- a/pkg/cloudcommon/db/db_dispatcher.go +++ b/pkg/cloudcommon/db/db_dispatcher.go @@ -30,6 +30,7 @@ import ( "yunion.io/x/pkg/utils" "yunion.io/x/sqlchemy" + "yunion.io/x/onecloud/pkg/apis" "yunion.io/x/onecloud/pkg/appsrv" "yunion.io/x/onecloud/pkg/appsrv/dispatcher" "yunion.io/x/onecloud/pkg/cloudcommon/consts" @@ -375,7 +376,7 @@ func Query2List(manager IModelManager, ctx context.Context, userCred mcclient.To jsonDict = jsonDict.CopyIncludes([]string(listF)...) jsonDict.Update(extraData) if showDetails && !query.Contains("export_keys") { - extraDict := item.GetCustomizeColumns(ctx, userCred, query) + extraDict, _ := GetExtraDetails(item, ctx, userCred, query, false) if extraDict != nil { // Fix for Now extraDict.Update(jsonDict) @@ -709,22 +710,22 @@ func (dispatcher *DBModelDispatcher) List(ctx context.Context, query jsonutils.J return items, nil } -func getModelExtraDetails(item IModel, ctx context.Context, extra *jsonutils.JSONDict) *jsonutils.JSONDict { +func getModelExtraDetails(item IModel, ctx context.Context) apis.ModelBaseDetails { + out := apis.ModelBaseDetails{ + CanDelete: true, + CanUpdate: true, + } err := item.ValidateDeleteCondition(ctx) if err != nil { - extra.Add(jsonutils.JSONFalse, "can_delete") - extra.Add(jsonutils.NewString(err.Error()), "delete_fail_reason") - } else { - extra.Add(jsonutils.JSONTrue, "can_delete") + out.CanDelete = false + out.DeleteFailReason = err.Error() } err = item.ValidateUpdateCondition(ctx) if err != nil { - extra.Add(jsonutils.JSONFalse, "can_update") - extra.Add(jsonutils.NewString(err.Error()), "update_fail_reason") - } else { - extra.Add(jsonutils.JSONTrue, "can_update") + out.CanUpdate = false + out.UpdateFailReason = err.Error() } - return extra + return out } func getModelItemDetails(manager IModelManager, item IModel, ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject, isHead bool) (jsonutils.JSONObject, error) { @@ -752,7 +753,7 @@ func getModelItemDetails(manager IModelManager, item IModel, ctx context.Context } func getItemDetails(manager IModelManager, item IModel, ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject) (jsonutils.JSONObject, error) { - extraDict, err := GetExtraDetails(item, ctx, userCred, query) + extraDict, err := GetExtraDetails(item, ctx, userCred, query, true) if err != nil { return nil, httperrors.NewGeneralError(err) } diff --git a/pkg/cloudcommon/db/domain.go b/pkg/cloudcommon/db/domain.go index 9181eb6d1f..9418bf6d5a 100644 --- a/pkg/cloudcommon/db/domain.go +++ b/pkg/cloudcommon/db/domain.go @@ -31,6 +31,7 @@ type SDomainizedResourceBaseManager struct { } type SDomainizedResourceBase struct { + // 域Id DomainId string `width:"64" charset:"ascii" default:"default" nullable:"false" index:"true" list:"user"` } diff --git a/pkg/cloudcommon/db/external.go b/pkg/cloudcommon/db/external.go index 88516cd218..7efb8c60a8 100644 --- a/pkg/cloudcommon/db/external.go +++ b/pkg/cloudcommon/db/external.go @@ -23,6 +23,7 @@ import ( ) type SExternalizedResourceBase struct { + // 外部Id, 对用公有云私有资源自身的Id ExternalId string `width:"256" charset:"utf8" index:"true" list:"user" create:"admin_optional" update:"admin"` } diff --git a/pkg/cloudcommon/db/interface.go b/pkg/cloudcommon/db/interface.go index 308afbd97c..9ee24e792d 100644 --- a/pkg/cloudcommon/db/interface.go +++ b/pkg/cloudcommon/db/interface.go @@ -144,7 +144,7 @@ type IModel interface { GetShortDesc(ctx context.Context) *jsonutils.JSONDict // list hooks - GetCustomizeColumns(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject) *jsonutils.JSONDict + //GetCustomizeColumns(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject) *jsonutils.JSONDict // get hooks AllowGetDetails(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject) bool diff --git a/pkg/cloudcommon/db/jointbase.go b/pkg/cloudcommon/db/jointbase.go index a4ac7c82c8..fe1ad9a17a 100644 --- a/pkg/cloudcommon/db/jointbase.go +++ b/pkg/cloudcommon/db/jointbase.go @@ -103,24 +103,17 @@ func (manager *SJointResourceBaseManager) AllowAttach(ctx context.Context, userC return IsAllowCreate(rbacutils.ScopeSystem, userCred, manager) } -func JointModelExtra(jointModel IJointModel, extra *jsonutils.JSONDict) *jsonutils.JSONDict { +func JointModelExtra(jointModel IJointModel) (string, string) { + masterName, slaveName := "", "" master := jointModel.Master() if master != nil { - extra.Add(jsonutils.NewString(master.GetName()), master.GetModelManager().Keyword()) - alias := master.GetModelManager().Alias() - if len(alias) > 0 { - extra.Add(jsonutils.NewString(master.GetName()), alias) - } + masterName = master.GetName() } slave := jointModel.Slave() if slave != nil { - extra.Add(jsonutils.NewString(slave.GetName()), slave.GetModelManager().Keyword()) - alias := slave.GetModelManager().Alias() - if len(alias) > 0 { - extra.Add(jsonutils.NewString(slave.GetName()), alias) - } + slaveName = slave.GetName() } - return extra + return masterName, slaveName } func (joint *SJointResourceBase) GetJointModelManager() IJointModelManager { @@ -213,11 +206,6 @@ func (self *SJointResourceBase) AllowDetach(ctx context.Context, userCred mcclie } /* -func (joint *SJointResourceBase) GetCustomizeColumns(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject) *jsonutils.JSONDict { - extra := joint.SResourceBase.GetCustomizeColumns(ctx, userCred, query) - return JointModelExtra(joint, extra) -} - func (joint *SJointResourceBase) GetExtraDetails(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject) *jsonutils.JSONDict { extra := joint.SResourceBase.GetCustomizeColumns(ctx, userCred, query) return JointModelExtra(joint, extra) diff --git a/pkg/cloudcommon/db/modelbase.go b/pkg/cloudcommon/db/modelbase.go index a4dcf595ca..66b0208c77 100644 --- a/pkg/cloudcommon/db/modelbase.go +++ b/pkg/cloudcommon/db/modelbase.go @@ -451,36 +451,13 @@ func (model *SModelBase) GetShortDescV2(ctx context.Context) *apis.ModelBaseShor return &apis.ModelBaseShortDescDetail{ResName: model.Keyword()} } -// list hooks -func (model *SModelBase) GetCustomizeColumns(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject) *jsonutils.JSONDict { - extra := jsonutils.NewDict() - return getModelExtraDetails(model.GetIModel(), ctx, extra) -} - // get hooks func (model *SModelBase) AllowGetDetails(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject) bool { return false } -func (model *SModelBase) GetExtraDetailsV2(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject, out *apis.ModelBaseDetails) error { - out.CanDelete = true - out.CanUpdate = true - err := model.GetIModel().ValidateDeleteCondition(ctx) - if err != nil { - out.CanDelete = false - out.DeleteFailReason = err.Error() - } - err = model.GetIModel().ValidateUpdateCondition(ctx) - if err != nil { - out.CanUpdate = false - out.UpdateFailReason = err.Error() - } - return nil -} - -func (model *SModelBase) GetExtraDetails(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject) (*jsonutils.JSONDict, error) { - extra := jsonutils.NewDict() - return getModelExtraDetails(model.GetIModel(), ctx, extra), nil +func (model *SModelBase) GetExtraDetails(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject, details bool) (apis.ModelBaseDetails, error) { + return getModelExtraDetails(model.GetIModel(), ctx), nil } func (model *SModelBase) GetExtraDetailsHeaders(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject) map[string]string { diff --git a/pkg/cloudcommon/db/project.go b/pkg/cloudcommon/db/project.go index b2841bcd30..26aaef7b65 100644 --- a/pkg/cloudcommon/db/project.go +++ b/pkg/cloudcommon/db/project.go @@ -31,6 +31,7 @@ type SProjectizedResourceBaseManager struct { type SProjectizedResourceBase struct { SDomainizedResourceBase + // 项目Id ProjectId string `name:"tenant_id" width:"128" charset:"ascii" nullable:"false" index:"true" list:"user"` } diff --git a/pkg/cloudcommon/db/resourcebase.go b/pkg/cloudcommon/db/resourcebase.go index cf9a22bdf3..e480a4c4e5 100644 --- a/pkg/cloudcommon/db/resourcebase.go +++ b/pkg/cloudcommon/db/resourcebase.go @@ -30,11 +30,16 @@ import ( type SResourceBase struct { SModelBase - CreatedAt time.Time `nullable:"false" created_at:"true" index:"true" get:"user" list:"user"` - UpdatedAt time.Time `nullable:"false" updated_at:"true" list:"user"` - UpdateVersion int `default:"0" nullable:"false" auto_version:"true" list:"user"` - DeletedAt time.Time `` - Deleted bool `nullable:"false" default:"false" list:"admin"` + // 资源创建时间 + CreatedAt time.Time `nullable:"false" created_at:"true" index:"true" get:"user" list:"user"` + // 资源更新时间 + UpdatedAt time.Time `nullable:"false" updated_at:"true" list:"user"` + // 资源被更新次数 + UpdateVersion int `default:"0" nullable:"false" auto_version:"true" list:"user"` + // 资源删除时间 + DeletedAt time.Time `` + // 资源是否被删除 + Deleted bool `nullable:"false" default:"false"` } type SResourceBaseManager struct { @@ -74,17 +79,7 @@ func (model *SResourceBase) GetIResourceModel() IResourceModel { return model.GetVirtualObject().(IResourceModel) } -/*func (model *SResourceBase) GetCustomizeColumns(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject) *jsonutils.JSONDict { - extra := model.SModelBase.GetCustomizeColumns(ctx, userCred, query) - canDelete := CanDelete(model, ctx) - if canDelete { - extra.Add(jsonutils.JSONTrue, "can_delete") - } else { - extra.Add(jsonutils.JSONFalse, "can_delete") - } - return extra -} - +/* func (model *SResourceBase) GetExtraDetails(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject) *jsonutils.JSONDict { extra := model.SModelBase.GetExtraDetails(ctx, userCred, query) canDelete := CanDelete(model, ctx) diff --git a/pkg/cloudcommon/db/sharablevirtual.go b/pkg/cloudcommon/db/sharablevirtual.go index 5509c9e936..fd0999d780 100644 --- a/pkg/cloudcommon/db/sharablevirtual.go +++ b/pkg/cloudcommon/db/sharablevirtual.go @@ -259,8 +259,8 @@ func (model *SSharableVirtualResourceBase) GetSharedProjects() []string { return res } -func (model *SSharableVirtualResourceBase) getMoreDetails(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject, extra *jsonutils.JSONDict) *jsonutils.JSONDict { - sharedProjects := jsonutils.NewArray() +func (model *SSharableVirtualResourceBase) getMoreDetails(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject, out apis.SharableVirtualResourceDetails) apis.SharableVirtualResourceDetails { + out.SharedProjects = []apis.SharedProject{} projects := model.GetSharedProjects() for i := 0; i < len(projects); i++ { tenant, err := TenantCacheManager.FetchTenantByIdOrName(ctx, projects[i]) @@ -268,50 +268,23 @@ func (model *SSharableVirtualResourceBase) getMoreDetails(ctx context.Context, u log.Errorf("failed fetch tenant by id %s", projects[i]) continue } - p := jsonutils.NewDict() - p.Set("id", jsonutils.NewString(tenant.GetId())) - p.Set("name", jsonutils.NewString(tenant.GetName())) - sharedProjects.Add(p) - } - if sharedProjects.Length() > 0 { - extra.Set("shared_projects", sharedProjects) - } - return extra -} - -func (model *SSharableVirtualResourceBase) getMoreDetailsV2(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject) []apis.SharedProject { - out := []apis.SharedProject{} - for _, project := range model.GetSharedProjects() { - tenant, err := TenantCacheManager.FetchTenantByIdOrName(ctx, project) - if err != nil { - log.Errorf("failed fetch tenant by id %s", project) - continue + project := apis.SharedProject{ + Id: tenant.GetId(), + Name: tenant.GetName(), } - out = append(out, apis.SharedProject{Id: tenant.GetId(), Name: tenant.GetName()}) + out.SharedProjects = append(out.SharedProjects, project) } return out } -func (model *SSharableVirtualResourceBase) GetCustomizeColumns(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject) *jsonutils.JSONDict { - extra := model.SVirtualResourceBase.GetCustomizeColumns(ctx, userCred, query) - return model.getMoreDetails(ctx, userCred, query, extra) -} - -func (model *SSharableVirtualResourceBase) GetExtraDetailsV2(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject, out *apis.SharableVirtualResourceDetails) error { - err := model.SVirtualResourceBase.GetExtraDetailsV2(ctx, userCred, query, &out.VirtualResourceDetails) +func (model *SSharableVirtualResourceBase) GetExtraDetails(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject, details bool) (apis.SharableVirtualResourceDetails, error) { + var err error + out := apis.SharableVirtualResourceDetails{} + out.VirtualResourceDetails, err = model.SVirtualResourceBase.GetExtraDetails(ctx, userCred, query, details) if err != nil { - return err + return out, err } - out.SharedProjects = model.getMoreDetailsV2(ctx, userCred, query) - return nil -} - -func (model *SSharableVirtualResourceBase) GetExtraDetails(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject) (*jsonutils.JSONDict, error) { - extra, err := model.SVirtualResourceBase.GetExtraDetails(ctx, userCred, query) - if err != nil { - return nil, err - } - return model.getMoreDetails(ctx, userCred, query, extra), nil + return model.getMoreDetails(ctx, userCred, query, out), nil } func (manager *SSharableVirtualResourceBaseManager) ValidateCreateData(ctx context.Context, userCred mcclient.TokenCredential, ownerId mcclient.IIdentityProvider, query jsonutils.JSONObject, input apis.SharableVirtualResourceCreateInput) (apis.SharableVirtualResourceCreateInput, error) { diff --git a/pkg/cloudcommon/db/standalone.go b/pkg/cloudcommon/db/standalone.go index 15fecfe116..e8e5237fe3 100644 --- a/pkg/cloudcommon/db/standalone.go +++ b/pkg/cloudcommon/db/standalone.go @@ -20,7 +20,6 @@ import ( "strings" "yunion.io/x/jsonutils" - "yunion.io/x/log" "yunion.io/x/pkg/errors" "yunion.io/x/pkg/util/regutils" "yunion.io/x/pkg/util/stringutils" @@ -44,11 +43,16 @@ var ( type SStandaloneResourceBase struct { SResourceBase - Id string `width:"128" charset:"ascii" primary:"true" list:"user"` + // 资源UUID + Id string `width:"128" charset:"ascii" primary:"true" list:"user"` + // 资源名称 Name string `width:"128" charset:"utf8" nullable:"false" index:"true" list:"user" update:"user" create:"required"` + // 资源描述信息 Description string `width:"256" charset:"utf8" get:"user" list:"user" update:"user" create:"optional"` + // 是否是模拟资源, 部分从公有云上同步的资源并不真实存在, 例如宿主机 + // list 接口默认不会返回这类资源,除非显示指定 is_emulate=true 过滤参数 IsEmulated bool `nullable:"false" default:"false" list:"admin" create:"admin_optional"` } @@ -235,6 +239,16 @@ func (model *SStandaloneResourceBase) GetShortDescV2(ctx context.Context) *apis. return desc } +func (model *SStandaloneResourceBase) GetExtraDetails(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject, details bool) (apis.StandaloneResourceDetails, error) { + var err error + out := apis.StandaloneResourceDetails{} + out.ModelBaseDetails, err = model.SResourceBase.GetExtraDetails(ctx, userCred, query, details) + if err != nil { + return out, err + } + return out, nil +} + /* * userCred: optional */ @@ -358,20 +372,6 @@ func (model *SStandaloneResourceBase) PerformSetUserMetadata(ctx context.Context return nil, err } -func (model *SStandaloneResourceBase) GetCustomizeColumns(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject) *jsonutils.JSONDict { - extra := model.SResourceBase.GetCustomizeColumns(ctx, userCred, query) - withMeta, _ := query.GetString("with_meta") - if utils.ToBool(withMeta) { - jsonMeta, err := Metadata.GetAll(model, nil, userCred) - if err == nil { - extra.Add(jsonutils.Marshal(jsonMeta), "metadata") - } else { - log.Errorf("metadata GetAll fail: %s", err) - } - } - return extra -} - func (model *SStandaloneResourceBase) PostUpdate(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject, data jsonutils.JSONObject) { model.SResourceBase.PostUpdate(ctx, userCred, query, data) diff --git a/pkg/cloudcommon/db/statusstandalone.go b/pkg/cloudcommon/db/statusstandalone.go index c8c3ac89ea..4ab3d5c7ec 100644 --- a/pkg/cloudcommon/db/statusstandalone.go +++ b/pkg/cloudcommon/db/statusstandalone.go @@ -32,6 +32,7 @@ import ( type SStatusStandaloneResourceBase struct { SStandaloneResourceBase + // 资源状态 Status string `width:"36" charset:"ascii" nullable:"false" default:"init" list:"user" create:"optional"` } diff --git a/pkg/cloudcommon/db/virtualresource.go b/pkg/cloudcommon/db/virtualresource.go index 163630eb8e..5dcd562510 100644 --- a/pkg/cloudcommon/db/virtualresource.go +++ b/pkg/cloudcommon/db/virtualresource.go @@ -59,12 +59,16 @@ type SVirtualResourceBase struct { SStatusStandaloneResourceBase SProjectizedResourceBase + // 云上同步资源是否在本地被更改过配置, local: 更改过, cloud: 未更改过 + // example: local ProjectSrc string `width:"10" charset:"ascii" nullable:"false" list:"user" default:""` + // 是否是系统资源 IsSystem bool `nullable:"true" default:"false" list:"admin" create:"optional"` PendingDeletedAt time.Time `` - PendingDeleted bool `nullable:"false" default:"false" index:"true" get:"user"` + // 资源是否处于回收站中 + PendingDeleted bool `nullable:"false" default:"false" index:"true" get:"user" list:"user"` } func (model *SVirtualResourceBase) IsOwner(userCred mcclient.TokenCredential) bool { @@ -292,43 +296,14 @@ func (model *SVirtualResourceBase) GetTenantCache(ctx context.Context) (*STenant return TenantCacheManager.FetchTenantById(ctx, model.ProjectId) } -func (model *SVirtualResourceBase) getMoreDetails(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject, extra *jsonutils.JSONDict) *jsonutils.JSONDict { - //if IsAdminAllowGet(userCred, model) { - // log.Debugf("GetCustomizeColumns") - // tobj, err := model.GetTenantCache(ctx) - // if err == nil { - // log.Debugf("GetTenantFromCache %s", jsonutils.Marshal(tobj)) - // extra.Add(jsonutils.NewString(tobj.GetName()), "tenant") - // } else { - // log.Errorf("GetTenantCache fail %s", err) - // } - // } - admin, _ := query.GetString("admin") - if utils.ToBool(admin) { // admin - pendingDelete, _ := query.GetString("pending_delete") - pendingDeleteLower := strings.ToLower(pendingDelete) - if pendingDeleteLower == "all" || pendingDeleteLower == "any" { - extra.Set("pending_deleted", jsonutils.NewBool(model.PendingDeleted)) - } - } - return extra -} - -func (model *SVirtualResourceBase) GetCustomizeColumns(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject) *jsonutils.JSONDict { - extra := model.SStandaloneResourceBase.GetCustomizeColumns(ctx, userCred, query) - return model.getMoreDetails(ctx, userCred, query, extra) -} - -func (model *SVirtualResourceBase) GetExtraDetailsV2(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject, out *apis.VirtualResourceDetails) error { - return model.SStandaloneResourceBase.GetExtraDetailsV2(ctx, userCred, query, &out.ModelBaseDetails) -} - -func (model *SVirtualResourceBase) GetExtraDetails(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject) (*jsonutils.JSONDict, error) { - extra, err := model.SStandaloneResourceBase.GetExtraDetails(ctx, userCred, query) +func (model *SVirtualResourceBase) GetExtraDetails(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject, details bool) (apis.VirtualResourceDetails, error) { + var err error + out := apis.VirtualResourceDetails{} + out.StandaloneResourceDetails, err = model.SStandaloneResourceBase.GetExtraDetails(ctx, userCred, query, details) if err != nil { - return nil, err + return out, err } - return model.getMoreDetails(ctx, userCred, query, extra), nil + return out, nil } func (model *SVirtualResourceBase) AllowPerformChangeOwner(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject, data jsonutils.JSONObject) bool { diff --git a/pkg/cloudevent/models/cloudevents.go b/pkg/cloudevent/models/cloudevents.go index 3158bcec28..7c7c48332a 100644 --- a/pkg/cloudevent/models/cloudevents.go +++ b/pkg/cloudevent/models/cloudevents.go @@ -117,10 +117,6 @@ func (manager *SCloudeventManager) ListItemFilter(ctx context.Context, q *sqlche return q, nil } -func (self *SCloudevent) GetCustomizeColumns(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject) *jsonutils.JSONDict { - return self.SModelBase.GetCustomizeColumns(ctx, userCred, query) -} - func (manager *SCloudeventManager) SyncCloudevent(ctx context.Context, userCred mcclient.TokenCredential, cloudprovider *SCloudprovider, iEvents []cloudprovider.ICloudEvent) int { count := 0 for _, iEvent := range iEvents { diff --git a/pkg/cloudprovider/geoinfo.go b/pkg/cloudprovider/geoinfo.go index 00a23c4ec2..1fb40a14e3 100644 --- a/pkg/cloudprovider/geoinfo.go +++ b/pkg/cloudprovider/geoinfo.go @@ -16,9 +16,17 @@ package cloudprovider // +onecloud:model-api-gen type SGeographicInfo struct { - Latitude float32 `list:"user" update:"admin" create:"admin_optional"` + // 纬度 + // example: 26.647003 + Latitude float32 `list:"user" update:"admin" create:"admin_optional"` + // 经度 + // example: 106.630211 Longitude float32 `list:"user" update:"admin" create:"admin_optional"` - City string `list:"user" width:"32" update:"admin" create:"admin_optional"` + // 城市 + // example: Guiyang + City string `list:"user" width:"32" update:"admin" create:"admin_optional"` + // 国家代码 + // example: CN CountryCode string `list:"user" width:"4" update:"admin" create:"admin_optional"` } diff --git a/pkg/compute/models/baremetalagents.go b/pkg/compute/models/baremetalagents.go index a30215a8e8..29163b83f8 100644 --- a/pkg/compute/models/baremetalagents.go +++ b/pkg/compute/models/baremetalagents.go @@ -200,25 +200,22 @@ func (self *SBaremetalagent) GetZone() *SZone { return nil } -func (self *SBaremetalagent) getMoreDetails(ctx context.Context, extra *jsonutils.JSONDict) *jsonutils.JSONDict { +func (self *SBaremetalagent) getMoreDetails(ctx context.Context, out api.BaremetalagentDetails) api.BaremetalagentDetails { zone := self.GetZone() if zone != nil { - extra.Set("zone", jsonutils.NewString(zone.GetName())) + out.Zone = zone.GetName() } - return extra + return out } -func (self *SBaremetalagent) GetCustomizeColumns(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject) *jsonutils.JSONDict { - extra := self.SStandaloneResourceBase.GetCustomizeColumns(ctx, userCred, query) - return self.getMoreDetails(ctx, extra) -} - -func (self *SBaremetalagent) GetExtraDetails(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject) (*jsonutils.JSONDict, error) { - extra, err := self.SStandaloneResourceBase.GetExtraDetails(ctx, userCred, query) +func (self *SBaremetalagent) GetExtraDetails(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject, details bool) (api.BaremetalagentDetails, error) { + var err error + out := api.BaremetalagentDetails{} + out.StandaloneResourceDetails, err = self.SStandaloneResourceBase.GetExtraDetails(ctx, userCred, query, details) if err != nil { - return nil, err + return out, err } - return self.getMoreDetails(ctx, extra), nil + return self.getMoreDetails(ctx, out), nil } func (manager *SBaremetalagentManager) GetAgent(agentType api.TAgentType, zoneId string) *SBaremetalagent { diff --git a/pkg/compute/models/billingresource.go b/pkg/compute/models/billingresource.go index 8002782004..6bb5862d01 100644 --- a/pkg/compute/models/billingresource.go +++ b/pkg/compute/models/billingresource.go @@ -18,12 +18,17 @@ import ( "time" api "yunion.io/x/onecloud/pkg/apis/billing" + "yunion.io/x/onecloud/pkg/apis/compute" ) type SBillingResourceBase struct { - BillingType string `width:"36" charset:"ascii" nullable:"true" default:"postpaid" list:"user" create:"optional"` - ExpiredAt time.Time `nullable:"true" list:"user" create:"optional"` - BillingCycle string `width:"10" charset:"ascii" nullable:"true" list:"user" create:"optional"` + // 计费类型, 按量、包年包月 + // example: postpaid + BillingType string `width:"36" charset:"ascii" nullable:"true" default:"postpaid" list:"user" create:"optional"` + // 过期时间 + ExpiredAt time.Time `nullable:"true" list:"user" create:"optional"` + // 计费周期 + BillingCycle string `width:"10" charset:"ascii" nullable:"true" list:"user" create:"optional"` } func (self *SBillingResourceBase) GetChargeType() string { @@ -71,7 +76,7 @@ type SBillingBaseInfo struct { } type SCloudBillingInfo struct { - SCloudProviderInfo + compute.CloudproviderInfo SBillingBaseInfo diff --git a/pkg/compute/models/buckets.go b/pkg/compute/models/buckets.go index 97faafe9c0..916c9dbaf5 100644 --- a/pkg/compute/models/buckets.go +++ b/pkg/compute/models/buckets.go @@ -518,29 +518,22 @@ func (bucket *SBucket) RemoteCreate(ctx context.Context, userCred mcclient.Token return nil } -func (bucket *SBucket) GetCustomizeColumns(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject) *jsonutils.JSONDict { - extra := bucket.SVirtualResourceBase.GetCustomizeColumns(ctx, userCred, query) - return bucket.getMoreDetails(extra) -} - -func (bucket *SBucket) GetExtraDetails(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject) (*api.BucketDetail, error) { - extra, err := bucket.SVirtualResourceBase.GetExtraDetails(ctx, userCred, query) +func (bucket *SBucket) GetExtraDetails(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject, details bool) (api.BucketDetails, error) { + var err error + out := api.BucketDetails{} + out.VirtualResourceDetails, err = bucket.SVirtualResourceBase.GetExtraDetails(ctx, userCred, query, details) if err != nil { - return nil, err + return out, err } - ret := bucket.getMoreDetails(extra) - out := new(api.BucketDetail) - err = ret.Unmarshal(out) - return out, err + return bucket.getMoreDetails(out), nil } func joinPath(ep, path string) string { return strings.TrimRight(ep, "/") + "/" + strings.TrimLeft(path, "/") } -func (bucket *SBucket) getMoreDetails(extra *jsonutils.JSONDict) *jsonutils.JSONDict { - info := bucket.getCloudProviderInfo() - extra.Update(jsonutils.Marshal(&info)) +func (bucket *SBucket) getMoreDetails(out api.BucketDetails) api.BucketDetails { + out.CloudproviderInfo = bucket.getCloudProviderInfo() s3gwUrl, _ := auth.GetServiceURL("s3gateway", options.Options.Region, "", "public") if len(s3gwUrl) > 0 { @@ -563,14 +556,14 @@ func (bucket *SBucket) getMoreDetails(extra *jsonutils.JSONDict) *jsonutils.JSON Url: joinPath(s3gwUrl, bucket.Name), Description: "s3gateway", }) - extra.Set("access_urls", jsonutils.Marshal(accessUrls)) + out.AccessUrls = accessUrls } } - return extra + return out } -func (bucket *SBucket) getCloudProviderInfo() SCloudProviderInfo { +func (bucket *SBucket) getCloudProviderInfo() api.CloudproviderInfo { region, _ := bucket.GetRegion() provider := bucket.GetCloudprovider() return MakeCloudProviderInfo(region, nil, provider) diff --git a/pkg/compute/models/cachedimages.go b/pkg/compute/models/cachedimages.go index c5f106915b..f605d1a981 100644 --- a/pkg/compute/models/cachedimages.go +++ b/pkg/compute/models/cachedimages.go @@ -58,17 +58,30 @@ func init() { type SCachedimage struct { db.SStandaloneResourceBase - // SManagedResourceBase db.SExternalizedResourceBase - Size int64 `nullable:"false" list:"user" update:"admin" create:"admin_required"` // = Column(BigInteger, nullable=False) # in Byte - // virtual_size = Column(BigInteger, nullable=False) # in Byte - Info jsonutils.JSONObject `nullable:"true" list:"user" update:"admin" create:"admin_required"` // Column(JSONEncodedDict, nullable=True) + // 镜像大小单位: Byte + // example: 53687091200 + Size int64 `nullable:"false" list:"user" update:"admin" create:"admin_required"` - LastSync time.Time `list:"admin"` // = Column(DateTime) - LastRef time.Time `list:"admin"` // = Column(DateTime) - RefCount int `default:"0" list:"user"` // = Column(Integer, default=0, server_default='0') + // 镜像详情信息 + // example: {"deleted":false,"disk_format":"qcow2","id":"img-a6uucnfl","is_public":true,"min_disk":51200,"min_ram":0,"name":"FreeBSD 11.1 64bit","properties":{"os_arch":"x86_64","os_distribution":"FreeBSD","os_type":"FreeBSD","os_version":"11"},"protected":true,"size":53687091200,"status":"active"} + Info jsonutils.JSONObject `nullable:"true" list:"user" update:"admin" create:"admin_required"` + // 上此同步时间 + // example: 2020-01-17T05:28:54.000000Z + LastSync time.Time `list:"admin"` + + // 最近一次缓存引用时间 + // 2020-01-17T05:20:54.000000Z + LastRef time.Time `list:"admin"` + + // 引用次数 + // example: 0 + RefCount int `default:"0" list:"user"` + + // 镜像类型, system: 公有云镜像, customized: 自定义镜像 + // example: system ImageType string `width:"16" default:"customized" list:"user"` } @@ -293,35 +306,24 @@ func (manager *SCachedimageManager) getImageInfo(ctx context.Context, userCred m return manager.getImageByName(ctx, userCred, imageId, refresh) } -func (self *SCachedimage) GetExtraDetails(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject) (*jsonutils.JSONDict, error) { - extra, err := self.SStandaloneResourceBase.GetExtraDetails(ctx, userCred, query) +func (self *SCachedimage) GetExtraDetails(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject, details bool) (api.CachedimageDetails, error) { + var err error + out := api.CachedimageDetails{} + out.StandaloneResourceDetails, err = self.SStandaloneResourceBase.GetExtraDetails(ctx, userCred, query, details) if err != nil { - return nil, err + return out, err } - extra = self.getMoreDetails(extra) - return extra, nil + return self.getMoreDetails(out), nil } -func (self *SCachedimage) GetCustomizeColumns(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject) *jsonutils.JSONDict { - extra := self.SStandaloneResourceBase.GetCustomizeColumns(ctx, userCred, query) - extra = self.getMoreDetails(extra) - return extra -} - -func (self *SCachedimage) getMoreDetails(extra *jsonutils.JSONDict) *jsonutils.JSONDict { - // extra.Add(jsonutils.NewString(self.GetName()), "name") - //extra.Add(jsonutils.NewString(self.GetOwner()), "owner") - //extra.Add(jsonutils.NewString(self.GetFormat()), "format") - extra.Add(jsonutils.NewString(self.GetStatus()), "status") - for _, k := range []string{"os_type", "os_distribution", "os_version", "hypervisor"} { - val, _ := self.Info.GetString("properties", k) - if len(val) > 0 { - extra.Add(jsonutils.NewString(val), k) - } +func (self *SCachedimage) getMoreDetails(out api.CachedimageDetails) api.CachedimageDetails { + out.Status = self.GetStatus() + properties, _ := self.Info.Get("properties") + if properties != nil { + jsonutils.Update(&out, properties) } - cachedCnt, _ := self.getStoragecacheCount() - extra.Add(jsonutils.NewInt(int64(cachedCnt)), "cached_count") - return extra + out.CachedCount, _ = self.getStoragecacheCount() + return out } func (self *SCachedimage) AllowPerformRefresh(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject, data jsonutils.JSONObject) bool { diff --git a/pkg/compute/models/cloudaccounts.go b/pkg/compute/models/cloudaccounts.go index be9596a4be..eedcfa6f2f 100644 --- a/pkg/compute/models/cloudaccounts.go +++ b/pkg/compute/models/cloudaccounts.go @@ -75,40 +75,73 @@ type SCloudaccount struct { db.SDomainizedResourceBase SSyncableBaseResource + // 上此同步时间 LastAutoSync time.Time `list:"domain"` + // 项目Id ProjectId string `name:"tenant_id" width:"128" charset:"ascii" list:"user" create:"domain_optional"` + // 云环境连接地址 AccessUrl string `width:"64" charset:"ascii" nullable:"true" list:"domain" update:"domain" create:"domain_optional"` - Account string `width:"128" charset:"ascii" nullable:"false" list:"domain" create:"domain_required"` // Column(VARCHAR(64, charset='ascii'), nullable=False) - Secret string `length:"0" charset:"ascii" nullable:"false" list:"domain" create:"domain_required"` // Google需要秘钥认证,需要此字段比较长 + // 云账号 + Account string `width:"128" charset:"ascii" nullable:"false" list:"domain" create:"domain_required"` - // BalanceKey string `width:"256" charset:"ascii" nullable:"true" list:"domain" update:"domain" create:"domain_optional"` + // 云账号密码 + Secret string `length:"0" charset:"ascii" nullable:"false" list:"domain" create:"domain_required"` + // 云环境唯一标识 AccountId string `width:"128" charset:"utf8" nullable:"true" list:"domain" create:"domain_optional"` + // 是否是公有云账号 + // example: true IsPublicCloud tristate.TriState `nullable:"false" get:"user" create:"optional" list:"user" default:"true"` - IsOnPremise bool `nullable:"false" get:"user" create:"optional" list:"user" default:"false"` + // 是否是本地IDC账号 + // example: false + IsOnPremise bool `nullable:"false" get:"user" create:"optional" list:"user" default:"false"` + + // 云平台类型 + // example: google Provider string `width:"64" charset:"ascii" list:"domain" create:"domain_required"` - EnableAutoSync bool `default:"false" create:"domain_optional" list:"domain"` - SyncIntervalSeconds int `create:"domain_optional" list:"domain" update:"domain"` + // 是否启用自动同步 + // example: false + EnableAutoSync bool `default:"false" create:"domain_optional" list:"domain"` - Balance float64 `list:"domain"` - ProbeAt time.Time `list:"domain"` - HealthStatus string `width:"16" charset:"ascii" default:"normal" nullable:"false" list:"domain"` + // 自动同步周期 + // example: 300 + SyncIntervalSeconds int `create:"domain_optional" list:"domain" update:"domain"` + // 账户余额 + // example: 124.2 + Balance float64 `list:"domain"` + + // 上次账号探测时间 + ProbeAt time.Time `list:"domain"` + + // 账号健康状态 + // example: normal + HealthStatus string `width:"16" charset:"ascii" default:"normal" nullable:"false" list:"domain"` + + // 账号探测异常错误次数 ErrorCount int `list:"domain"` + // 是否根据云上项目自动在本地创建对应项目 + // example: false AutoCreateProject bool `list:"domain" create:"domain_optional"` - Version string `width:"32" charset:"ascii" nullable:"true" list:"domain"` // Column(VARCHAR(32, charset='ascii'), nullable=True) - Sysinfo jsonutils.JSONObject `get:"domain"` // Column(JSONEncodedDict, nullable=True) + // 云API版本 + Version string `width:"32" charset:"ascii" nullable:"true" list:"domain"` + // 云系统信息 + Sysinfo jsonutils.JSONObject `get:"domain"` + + // 品牌信息, 一般和provider相同 + // example: DStack Brand string `width:"64" charset:"utf8" nullable:"true" list:"domain" create:"optional"` + // 额外信息 Options *jsonutils.JSONDict `get:"domain" create:"domain_optional" update:"domain"` // for backward compatiblity, keep is_public field, but not usable @@ -867,46 +900,46 @@ func (self *SCloudaccount) GetCloudEnv() string { } } -func (self *SCloudaccount) getMoreDetails(extra *jsonutils.JSONDict) *jsonutils.JSONDict { - extra = db.FetchModelExtraCountProperties(self, extra) - // cnt, _ := self.getProviderCount() - // int64(cnt)), "provider_count") - // extra.Add(jsonutils.NewInt(int64(self.getHostCount())), "host_count") - // extra.Add(jsonutils.NewInt(int64(self.getGuestCount())), "guest_count") - // extra.Add(jsonutils.NewInt(int64(self.getDiskCount())), "disk_count") - // extra.Add(jsonutils.NewString(self.getVersion()), "version") - projects := jsonutils.NewArray() +func (self *SCloudaccount) getMoreDetails(out api.CloudaccountDetail) api.CloudaccountDetail { + out.EipCount, _ = self.GetEipCount() + out.VpcCount, _ = self.GetVpcCount() + out.DiskCount, _ = self.GetDiskCount() + out.HostCount, _ = self.GetHostCount() + out.GuestCount, _ = self.GetGuestCount() + out.StorageCount, _ = self.GetStorageCount() + out.ProviderCount, _ = self.GetProviderCount() + out.RoutetableCount, _ = self.GetRoutetableCount() + out.StoragecacheCount, _ = self.GetStoragecacheCount() + + out.Projects = []api.ProviderProject{} for _, projectId := range self.getProjectIds() { if proj, _ := db.TenantCacheManager.FetchTenantById(context.Background(), projectId); proj != nil { - projJson := jsonutils.NewDict() - projJson.Add(jsonutils.NewString(proj.Name), "tenant") - projJson.Add(jsonutils.NewString(proj.Id), "tenant_id") - projects.Add(projJson) + project := api.ProviderProject{ + Tenant: proj.Name, + TenantId: proj.Id, + } + out.Projects = append(out.Projects, project) } } - extra.Add(projects, "projects") - extra.Set("sync_interval_seconds", jsonutils.NewInt(int64(self.getSyncIntervalSeconds()))) - extra.Set("sync_status2", jsonutils.NewString(self.getSyncStatus2())) - extra.Set("cloud_env", jsonutils.NewString(self.GetCloudEnv())) + out.SyncIntervalSeconds = self.getSyncIntervalSeconds() + out.SyncStatus2 = self.getSyncStatus2() + out.CloudEnv = self.GetCloudEnv() if len(self.ProjectId) > 0 { if proj, _ := db.TenantCacheManager.FetchTenantById(context.Background(), self.ProjectId); proj != nil { - extra.Add(jsonutils.NewString(proj.Name), "tenant") + out.Tenant = proj.Name } } - return extra + return out } -func (self *SCloudaccount) GetCustomizeColumns(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject) *jsonutils.JSONDict { - extra := self.SEnabledStatusStandaloneResourceBase.GetCustomizeColumns(ctx, userCred, query) - return self.getMoreDetails(extra) -} - -func (self *SCloudaccount) GetExtraDetails(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject) (*jsonutils.JSONDict, error) { - extra, err := self.SEnabledStatusStandaloneResourceBase.GetExtraDetails(ctx, userCred, query) +func (self *SCloudaccount) GetExtraDetails(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject, details bool) (api.CloudaccountDetail, error) { + var err error + out := api.CloudaccountDetail{} + out.StandaloneResourceDetails, err = self.SEnabledStatusStandaloneResourceBase.GetExtraDetails(ctx, userCred, query, details) if err != nil { - return nil, err + return out, err } - return self.getMoreDetails(extra), nil + return self.getMoreDetails(out), nil } func migrateCloudprovider(cloudprovider *SCloudprovider) error { diff --git a/pkg/compute/models/cloudproviderregions.go b/pkg/compute/models/cloudproviderregions.go index c3285a70bb..aff45ef6a1 100644 --- a/pkg/compute/models/cloudproviderregions.go +++ b/pkg/compute/models/cloudproviderregions.go @@ -114,19 +114,15 @@ func (self *SCloudproviderregion) GetRegion() *SCloudregion { return regionObj.(*SCloudregion) } -func (self *SCloudproviderregion) GetCustomizeColumns(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject) *jsonutils.JSONDict { - extra := self.SJointResourceBase.GetCustomizeColumns(ctx, userCred, query) - extra = db.JointModelExtra(self, extra) - return self.getExtraDetails(extra) -} - -func (self *SCloudproviderregion) GetExtraDetails(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject) (*jsonutils.JSONDict, error) { - extra, err := self.SJointResourceBase.GetExtraDetails(ctx, userCred, query) +func (self *SCloudproviderregion) GetExtraDetails(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject, details bool) (api.CloudproviderregionDetails, error) { + var err error + out := api.CloudproviderregionDetails{} + out.ModelBaseDetails, err = self.SJointResourceBase.GetExtraDetails(ctx, userCred, query, details) if err != nil { - return nil, err + return out, err } - extra = db.JointModelExtra(self, extra) - return self.getExtraDetails(extra), nil + out.Cloudprovider, out.Cloudregion = db.JointModelExtra(self) + return self.getExtraDetails(out), nil } func (self *SCloudproviderregion) getSyncIntervalSeconds(account *SCloudaccount) int { @@ -136,20 +132,19 @@ func (self *SCloudproviderregion) getSyncIntervalSeconds(account *SCloudaccount) return account.getSyncIntervalSeconds() } -func (self *SCloudproviderregion) getExtraDetails(extra *jsonutils.JSONDict) *jsonutils.JSONDict { +func (self *SCloudproviderregion) getExtraDetails(out api.CloudproviderregionDetails) api.CloudproviderregionDetails { account := self.GetAccount() if account != nil { - extra.Add(jsonutils.NewString(account.Id), "cloudaccount_id") - extra.Add(jsonutils.NewString(account.Name), "cloudaccount") - extra.Add(jsonutils.NewString(account.DomainId), "cloudaccount_domain_id") + out.CloudaccountId = account.Id + out.Cloudaccount = account.Name + out.CloudaccountDomainId = account.DomainId + out.EnableAutoSync = false if account.Enabled && account.EnableAutoSync { - extra.Add(jsonutils.JSONTrue, "enable_auto_sync") - } else { - extra.Add(jsonutils.JSONFalse, "enable_auto_sync") + out.EnableAutoSync = true } - extra.Add(jsonutils.NewInt(int64(self.getSyncIntervalSeconds(account))), "sync_interval_seconds") + out.SyncIntervalSeconds = self.getSyncIntervalSeconds(account) } - return extra + return out } func (manager *SCloudproviderregion) ValidateCreateData(ctx context.Context, userCred mcclient.TokenCredential, ownerId mcclient.IIdentityProvider, query jsonutils.JSONObject, data *jsonutils.JSONDict) (*jsonutils.JSONDict, error) { diff --git a/pkg/compute/models/cloudproviders.go b/pkg/compute/models/cloudproviders.go index c384bcc51e..527b63af9d 100644 --- a/pkg/compute/models/cloudproviders.go +++ b/pkg/compute/models/cloudproviders.go @@ -862,37 +862,30 @@ func (self *SCloudprovider) getProject(ctx context.Context) *db.STenant { return proj } -func (self *SCloudprovider) getMoreDetails(ctx context.Context, extra *jsonutils.JSONDict) *jsonutils.JSONDict { - extra.Update(jsonutils.Marshal(self.getUsage())) - // project := self.getProject(ctx) - // if project != nil { - // extra.Add(jsonutils.NewString(project.Name), "tenant") - // } +func (self *SCloudprovider) getMoreDetails(ctx context.Context, out api.CloudproviderDetails) api.CloudproviderDetails { + jsonutils.Update(&out, self.getUsage()) account := self.GetCloudaccount() if account != nil { - extra.Add(jsonutils.NewString(account.GetName()), "cloudaccount") // 此字段不能删除,公有云日志同步需要这个字段 - extra.Add(jsonutils.NewString(account.Brand), "brand") + out.Brand = account.Brand + out.Cloudaccount = account.GetName() } - extra.Set("sync_status2", jsonutils.NewString(self.getSyncStatus2())) + out.SyncStatus2 = self.getSyncStatus2() capabilities, _ := CloudproviderCapabilityManager.getCapabilities(self.Id) if len(capabilities) > 0 { - extra.Add(jsonutils.NewStringArray(capabilities), "capabilities") + out.Capabilities = capabilities } - return extra + return out } -func (self *SCloudprovider) GetCustomizeColumns(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject) *jsonutils.JSONDict { - extra := self.SEnabledStatusStandaloneResourceBase.GetCustomizeColumns(ctx, userCred, query) - return self.getMoreDetails(ctx, extra) -} - -func (self *SCloudprovider) GetExtraDetails(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject) (*jsonutils.JSONDict, error) { - extra, err := self.SEnabledStatusStandaloneResourceBase.GetExtraDetails(ctx, userCred, query) +func (self *SCloudprovider) GetExtraDetails(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject, details bool) (api.CloudproviderDetails, error) { + var err error + out := api.CloudproviderDetails{} + out.StandaloneResourceDetails, err = self.SEnabledStatusStandaloneResourceBase.GetExtraDetails(ctx, userCred, query, details) if err != nil { - return nil, err + return out, err } - return self.getMoreDetails(ctx, extra), nil + return self.getMoreDetails(ctx, out), nil } func (manager *SCloudproviderManager) InitializeData() error { diff --git a/pkg/compute/models/cloudregionresource.go b/pkg/compute/models/cloudregionresource.go index d99444cc47..d3f9c96c73 100644 --- a/pkg/compute/models/cloudregionresource.go +++ b/pkg/compute/models/cloudregionresource.go @@ -20,6 +20,7 @@ import ( "yunion.io/x/jsonutils" "yunion.io/x/log" + api "yunion.io/x/onecloud/pkg/apis/compute" "yunion.io/x/onecloud/pkg/mcclient" ) @@ -36,18 +37,11 @@ func (self *SCloudregionResourceBase) GetRegion() *SCloudregion { return region.(*SCloudregion) } -func (self *SCloudregionResourceBase) GetCustomizeColumns(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject) *jsonutils.JSONDict { +func (self *SCloudregionResourceBase) GetExtraDetails(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject) api.CloudregionInfo { + out := api.CloudregionInfo{} region := self.GetRegion() if region == nil { - return nil + return out } - info := map[string]string{ - "region": region.GetName(), - "region_id": region.GetId(), - } - if len(region.ExternalId) > 0 { - info["region_external_id"] = region.ExternalId - info["region_ext_id"] = fetchExternalId(region.ExternalId) - } - return jsonutils.Marshal(info).(*jsonutils.JSONDict) + return region.GetRegionInfo() } diff --git a/pkg/compute/models/cloudregions.go b/pkg/compute/models/cloudregions.go index 6aedc27357..80ed4bca34 100644 --- a/pkg/compute/models/cloudregions.go +++ b/pkg/compute/models/cloudregions.go @@ -60,8 +60,12 @@ type SCloudregion struct { cloudprovider.SGeographicInfo + // 云环境 + // example: ChinaCloud Environment string `width:"32" charset:"ascii" list:"user"` - Provider string `width:"64" charset:"ascii" list:"user" nullable:"false" default:"OneCloud"` + // 云平台 + // example: Huawei + Provider string `width:"64" charset:"ascii" list:"user" nullable:"false" default:"OneCloud"` } func (manager *SCloudregionManager) AllowListItems(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject) bool { @@ -238,21 +242,23 @@ func (self *SCloudregion) GetDriver() IRegionDriver { return GetRegionDriver(provider) } -func (self *SCloudregion) getMoreDetails(extra *jsonutils.JSONDict) *jsonutils.JSONDict { - return db.FetchModelExtraCountProperties(self, extra) +func (self *SCloudregion) getMoreDetails(out api.CloudregionDetails) api.CloudregionDetails { + out.VpcCount, _ = self.GetVpcCount() + out.ZoneCount, _ = self.GetZoneCount() + out.GuestCount, _ = self.GetGuestCount() + out.NetworkCount, _ = self.GetNetworkCount() + out.GuestIncrementCount, _ = self.GetGuestIncrementCount() + return out } -func (self *SCloudregion) GetCustomizeColumns(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject) *jsonutils.JSONDict { - extra := self.SEnabledStatusStandaloneResourceBase.GetCustomizeColumns(ctx, userCred, query) - return self.getMoreDetails(extra) -} - -func (self *SCloudregion) GetExtraDetails(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject) (*jsonutils.JSONDict, error) { - extra, err := self.SEnabledStatusStandaloneResourceBase.GetExtraDetails(ctx, userCred, query) +func (self *SCloudregion) GetExtraDetails(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject, details bool) (api.CloudregionDetails, error) { + var err error + out := api.CloudregionDetails{} + out.StandaloneResourceDetails, err = self.SEnabledStatusStandaloneResourceBase.GetExtraDetails(ctx, userCred, query, details) if err != nil { - return nil, err + return out, err } - return self.getMoreDetails(extra), nil + return self.getMoreDetails(out), nil } func (self *SCloudregion) GetSkus() ([]SServerSku, error) { @@ -718,6 +724,15 @@ func (self *SCloudregion) isManaged() bool { } } +func (self *SCloudregion) GetRegionInfo() api.CloudregionInfo { + return api.CloudregionInfo{ + Region: self.Name, + RegionId: self.Id, + RegionExtId: fetchExternalId(self.ExternalId), + RegionExternalId: self.ExternalId, + } +} + func (self *SCloudregion) ValidateUpdateCondition(ctx context.Context) error { if len(self.ExternalId) > 0 && len(self.ManagerId) == 0 { return httperrors.NewConflictError("Cannot update external resource") diff --git a/pkg/compute/models/dbinstance_accounts.go b/pkg/compute/models/dbinstance_accounts.go index 41fe386532..b30ea31277 100644 --- a/pkg/compute/models/dbinstance_accounts.go +++ b/pkg/compute/models/dbinstance_accounts.go @@ -59,7 +59,9 @@ type SDBInstanceAccount struct { db.SStatusStandaloneResourceBase db.SExternalizedResourceBase - Secret string `width:"256" charset:"ascii" nullable:"false" list:"domain" create:"optional"` + // 数据库密码 + Secret string `width:"256" charset:"ascii" nullable:"false" list:"domain" create:"optional"` + // RDS实例Id DBInstanceId string `width:"36" charset:"ascii" name:"dbinstance_id" nullable:"false" list:"user" create:"required" index:"true"` } @@ -132,43 +134,39 @@ func (self *SDBInstanceAccount) AllowDeleteItem(ctx context.Context, userCred mc return db.IsAdminAllowDelete(userCred, self) } -func (self *SDBInstanceAccount) getPrivilegesDetails() (*jsonutils.JSONArray, error) { - result := jsonutils.NewArray() +func (self *SDBInstanceAccount) getPrivilegesDetails() ([]api.DBInstancePrivilege, error) { + out := []api.DBInstancePrivilege{} privileges, err := self.GetDBInstancePrivileges() if err != nil { return nil, errors.Wrap(err, "GetDBInstancePrivileges") } for _, privilege := range privileges { - detail, err := privilege.GetDetailedJson() + detail, err := privilege.GetPrivilege() if err != nil { return nil, errors.Wrap(err, "GetDetailedJson") } - result.Add(detail) + out = append(out, detail) } - return result, nil + return out, nil } -func (self *SDBInstanceAccount) GetCustomizeColumns(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject) *jsonutils.JSONDict { - extra := self.SStatusStandaloneResourceBase.GetCustomizeColumns(ctx, userCred, query) - extra, _ = self.getMoreDetails(ctx, userCred, extra) - return extra -} - -func (self *SDBInstanceAccount) getMoreDetails(ctx context.Context, userCred mcclient.TokenCredential, extra *jsonutils.JSONDict) (*jsonutils.JSONDict, error) { +func (self *SDBInstanceAccount) getMoreDetails(ctx context.Context, userCred mcclient.TokenCredential, out api.DBInstanceAccountDetails) (api.DBInstanceAccountDetails, error) { privileges, err := self.getPrivilegesDetails() if err != nil { - return extra, err + return out, err } - extra.Add(privileges, "dbinstanceprivileges") - return extra, nil + out.DBInstanceprivileges = privileges + return out, nil } -func (self *SDBInstanceAccount) GetExtraDetails(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject) (*jsonutils.JSONDict, error) { - extra, err := self.SStatusStandaloneResourceBase.GetExtraDetails(ctx, userCred, query) +func (self *SDBInstanceAccount) GetExtraDetails(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject, details bool) (api.DBInstanceAccountDetails, error) { + var err error + out := api.DBInstanceAccountDetails{} + out.StandaloneResourceDetails, err = self.SStatusStandaloneResourceBase.GetExtraDetails(ctx, userCred, query, details) if err != nil { - return nil, err + return out, err } - return self.getMoreDetails(ctx, userCred, extra) + return self.getMoreDetails(ctx, userCred, out) } // RDS账号列表 diff --git a/pkg/compute/models/dbinstance_backups.go b/pkg/compute/models/dbinstance_backups.go index aa7c60c529..3e27f96510 100644 --- a/pkg/compute/models/dbinstance_backups.go +++ b/pkg/compute/models/dbinstance_backups.go @@ -61,14 +61,26 @@ type SDBInstanceBackup struct { SManagedResourceBase db.SExternalizedResourceBase - Engine string `width:"16" charset:"ascii" nullable:"false" list:"user" create:"required"` - EngineVersion string `width:"16" charset:"ascii" nullable:"false" list:"user" create:"required"` - StartTime time.Time `list:"user"` - EndTime time.Time `list:"user"` - BackupMode string `width:"32" charset:"ascii" nullable:"true" list:"user" create:"optional"` - DBNames string `width:"512" charset:"ascii" nullable:"true" list:"user" create:"optional"` - BackupSizeMb int `nullable:"false" list:"user"` - DBInstanceId string `width:"36" charset:"ascii" name:"dbinstance_id" nullable:"false" list:"user" create:"required" index:"true"` + // RDS引擎 + // example: MySQL + Engine string `width:"16" charset:"ascii" nullable:"false" list:"user" create:"required"` + // RDS引擎版本 + // example: 5.7 + EngineVersion string `width:"16" charset:"ascii" nullable:"false" list:"user" create:"required"` + // 备份开始时间 + StartTime time.Time `list:"user"` + // 备份结束时间 + EndTime time.Time `list:"user"` + // 备份模式 + BackupMode string `width:"32" charset:"ascii" nullable:"true" list:"user" create:"optional"` + // 备份数据库名称 + DBNames string `width:"512" charset:"ascii" nullable:"true" list:"user" create:"optional"` + // 备份大小 + // example: 32 + BackupSizeMb int `nullable:"false" list:"user"` + // RDS实例Id + // example: 239b9663-6d06-4ef4-8cfc-320a7fb6660d + DBInstanceId string `width:"36" charset:"ascii" name:"dbinstance_id" nullable:"false" list:"user" create:"required" index:"true"` } func (manager *SDBInstanceBackupManager) GetContextManagers() [][]db.IModelManager { @@ -232,23 +244,22 @@ func (self *SDBInstanceBackup) GetDBInstance() (*SDBInstance, error) { return nil, fmt.Errorf("empty dbinstance id") } -func (self *SDBInstanceBackup) GetCustomizeColumns(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject) *jsonutils.JSONDict { - extra := self.SVirtualResourceBase.GetCustomizeColumns(ctx, userCred, query) +func (self *SDBInstanceBackup) GetExtraDetails(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject, isList bool) (api.DBInstanceBackupDetails, error) { + var err error + out := api.DBInstanceBackupDetails{} + out.VirtualResourceDetails, err = self.SVirtualResourceBase.GetExtraDetails(ctx, userCred, query, isList) + if err != nil { + return out, err + } dbinstance, err := self.GetDBInstance() if err == nil { - extra.Add(jsonutils.NewString(dbinstance.Name), "dbinstance") - } - cloudregionInfo := self.SCloudregionResourceBase.GetCustomizeColumns(ctx, userCred, query) - if cloudregionInfo != nil { - extra.Update(cloudregionInfo) + out.DBInstance = dbinstance.Name } + region := self.GetRegion() + provider := self.GetCloudprovider() + out.CloudproviderInfo = MakeCloudProviderInfo(region, nil, provider) - accountInfo := self.SManagedResourceBase.GetCustomizeColumns(ctx, userCred, query) - if accountInfo != nil { - extra.Update(accountInfo) - } - - return extra + return out, nil } func (manager *SDBInstanceBackupManager) SyncDBInstanceBackups(ctx context.Context, userCred mcclient.TokenCredential, provider *SCloudprovider, instance *SDBInstance, region *SCloudregion, cloudBackups []cloudprovider.ICloudDBInstanceBackup) compare.SyncResult { diff --git a/pkg/compute/models/dbinstance_databases.go b/pkg/compute/models/dbinstance_databases.go index de31830fc3..2dbfdeddec 100644 --- a/pkg/compute/models/dbinstance_databases.go +++ b/pkg/compute/models/dbinstance_databases.go @@ -57,7 +57,11 @@ type SDBInstanceDatabase struct { db.SStatusStandaloneResourceBase db.SExternalizedResourceBase + // 字符集 + // example: utf-8 CharacterSet string `width:"32" charset:"ascii" nullable:"true" list:"user" create:"optional"` + // RDS实例Id + // example: 7d07e867-37d1-4754-865d-80f88ad0f982 DBInstanceId string `width:"36" charset:"ascii" name:"dbinstance_id" nullable:"false" list:"user" create:"required" index:"true"` } @@ -240,44 +244,40 @@ func (self *SDBInstanceDatabase) GetDBInstance() (*SDBInstance, error) { return instance.(*SDBInstance), nil } -func (self *SDBInstanceDatabase) GetExtraDetails(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject) (*jsonutils.JSONDict, error) { - extra, err := self.SStatusStandaloneResourceBase.GetExtraDetails(ctx, userCred, query) +func (self *SDBInstanceDatabase) GetExtraDetails(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject, details bool) (api.DBInstancedatabaseDetails, error) { + var err error + out := api.DBInstancedatabaseDetails{} + out.StandaloneResourceDetails, err = self.SStatusStandaloneResourceBase.GetExtraDetails(ctx, userCred, query, details) if err != nil { - return nil, err + return out, err } - return self.getMoreDetails(ctx, userCred, extra) + return self.getMoreDetails(ctx, userCred, out) } -func (self *SDBInstanceDatabase) GetCustomizeColumns(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject) *jsonutils.JSONDict { - extra := self.SStatusStandaloneResourceBase.GetCustomizeColumns(ctx, userCred, query) - extra, _ = self.getMoreDetails(ctx, userCred, extra) - return extra -} - -func (self *SDBInstanceDatabase) getPrivilegesDetails() (*jsonutils.JSONArray, error) { - result := jsonutils.NewArray() +func (self *SDBInstanceDatabase) getPrivilegesDetails() ([]api.DBInstancePrivilege, error) { + out := []api.DBInstancePrivilege{} privileges, err := self.GetDBInstancePrivileges() if err != nil { - return nil, errors.Wrap(err, "GetDBInstancePrivileges") + return out, errors.Wrap(err, "GetDBInstancePrivileges") } for _, privilege := range privileges { - detail, err := privilege.GetDetailedJson() + detail, err := privilege.GetPrivilege() if err != nil { return nil, errors.Wrap(err, "GetDetailedJson") } - result.Add(detail) + out = append(out, detail) } - return result, nil + return out, nil } -func (self *SDBInstanceDatabase) getMoreDetails(ctx context.Context, userCred mcclient.TokenCredential, extra *jsonutils.JSONDict) (*jsonutils.JSONDict, error) { +func (self *SDBInstanceDatabase) getMoreDetails(ctx context.Context, userCred mcclient.TokenCredential, out api.DBInstancedatabaseDetails) (api.DBInstancedatabaseDetails, error) { privileges, err := self.getPrivilegesDetails() if err != nil { - return extra, err + return out, err } - extra.Add(privileges, "dbinstanceprivileges") - return extra, nil + out.DBInstanceprivileges = privileges + return out, nil } func (manager *SDBInstanceDatabaseManager) SyncDBInstanceDatabases(ctx context.Context, userCred mcclient.TokenCredential, instance *SDBInstance, cloudDatabases []cloudprovider.ICloudDBInstanceDatabase) compare.SyncResult { diff --git a/pkg/compute/models/dbinstance_privileges.go b/pkg/compute/models/dbinstance_privileges.go index 5b84cef0c1..a56a2db2ac 100644 --- a/pkg/compute/models/dbinstance_privileges.go +++ b/pkg/compute/models/dbinstance_privileges.go @@ -107,21 +107,21 @@ func (self *SDBInstancePrivilege) GetDBInstanceDatabase() (*SDBInstanceDatabase, return database.(*SDBInstanceDatabase), nil } -func (self *SDBInstancePrivilege) GetDetailedJson() (*jsonutils.JSONDict, error) { - result := jsonutils.NewDict() +func (self *SDBInstancePrivilege) GetPrivilege() (api.DBInstancePrivilege, error) { + out := api.DBInstancePrivilege{} database, err := self.GetDBInstanceDatabase() if err != nil { - return nil, err + return out, err } + out.Database = database.Name + out.DBInstancedatabaseId = database.Id account, err := self.GetDBInstanceAccount() if err != nil { - return nil, err + return out, err } - result.Add(jsonutils.NewString(database.Name), "database") - result.Add(jsonutils.NewString(account.Name), "account") - result.Add(jsonutils.NewString(database.Id), "dbinstancedatabase_id") - result.Add(jsonutils.NewString(self.Privilege), "privileges") - return result, nil + out.Account = account.Name + out.Privileges = self.Privilege + return out, nil } func (manager *SDBInstancePrivilegeManager) ListItemFilter(ctx context.Context, q *sqlchemy.SQuery, userCred mcclient.TokenCredential, query api.DBInstancePrivilegeListInput) (*sqlchemy.SQuery, error) { diff --git a/pkg/compute/models/dbinstances.go b/pkg/compute/models/dbinstances.go index de09bdf700..c9afd770f1 100644 --- a/pkg/compute/models/dbinstances.go +++ b/pkg/compute/models/dbinstances.go @@ -72,29 +72,59 @@ type SDBInstance struct { SCloudregionResourceBase SDeletePreventableResourceBase + // 主实例Id MasterInstanceId string `width:"128" charset:"ascii" list:"user" create:"optional"` - VcpuCount int `nullable:"false" default:"1" list:"user" create:"optional"` - VmemSizeMb int `nullable:"false" list:"user" create:"required"` - StorageType string `nullable:"false" list:"user" create:"required"` //存储类型 - DiskSizeGB int `nullable:"false" list:"user" create:"required"` - Port int `nullable:"false" list:"user" create:"optional"` - Category string `nullable:"false" list:"user" create:"optional"` //实例类别,单机,高可用,只读 + // CPU数量 + // example: 1 + VcpuCount int `nullable:"false" default:"1" list:"user" create:"optional"` + // 内存大小 + // example: 1024 + VmemSizeMb int `nullable:"false" list:"user" create:"required"` + // 存储类型 + // example: local_ssd + StorageType string `nullable:"false" list:"user" create:"required"` + // 存储大小 + // example: 10240 + DiskSizeGB int `nullable:"false" list:"user" create:"required"` + // 端口 + // example: 3306 + Port int `nullable:"false" list:"user" create:"optional"` + // 实例类型 + // example: ha + Category string `nullable:"false" list:"user" create:"optional"` - Engine string `width:"16" charset:"ascii" nullable:"false" list:"user" create:"required"` + // 引擎 + // example: MySQL + Engine string `width:"16" charset:"ascii" nullable:"false" list:"user" create:"required"` + // 引擎版本 + // example: 5.7 EngineVersion string `width:"16" charset:"ascii" nullable:"false" list:"user" create:"required"` - InstanceType string `width:"64" charset:"ascii" nullable:"true" list:"user" create:"optional"` + // 套餐名称 + // example: mysql.x4.large.2c + InstanceType string `width:"64" charset:"ascii" nullable:"true" list:"user" create:"optional"` + // 维护时间 MaintainTime string `width:"64" charset:"ascii" nullable:"true" list:"user" create:"optional"` - SecgroupId string `width:"128" charset:"ascii" list:"user" default:"default" create:"optional"` - VpcId string `width:"36" charset:"ascii" nullable:"false" list:"user" create:"optional"` - ConnectionStr string `width:"256" charset:"ascii" nullable:"false" list:"user" create:"optional"` + // 安全组Id + // example: default + SecgroupId string `width:"128" charset:"ascii" list:"user" default:"default" create:"optional"` + // 虚拟私有网络Id + // example: ed20d84e-3158-41b1-870c-1725e412e8b6 + VpcId string `width:"36" charset:"ascii" nullable:"false" list:"user" create:"optional"` + // 外部连接地址 + ConnectionStr string `width:"256" charset:"ascii" nullable:"false" list:"user" create:"optional"` + // 内部连接地址 InternalConnectionStr string `width:"256" charset:"ascii" nullable:"false" list:"user" create:"optional"` + // 可用区1 Zone1 string `width:"36" charset:"ascii" nullable:"false" create:"optional" list:"user"` + // 可用区2 Zone2 string `width:"36" charset:"ascii" nullable:"false" create:"optional" list:"user"` + // 可用区3 Zone3 string `width:"36" charset:"ascii" nullable:"false" create:"optional" list:"user"` + // 可用区Id(对应公有云的可用区Id) ZoneId string `width:"36" charset:"ascii" nullable:"false" create:"optional"` } @@ -335,12 +365,14 @@ func (self *SDBInstance) PostCreate(ctx context.Context, userCred mcclient.Token task.ScheduleRun(nil) } -func (self *SDBInstance) GetExtraDetails(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject) (*jsonutils.JSONDict, error) { - extra, err := self.SVirtualResourceBase.GetExtraDetails(ctx, userCred, query) +func (self *SDBInstance) GetExtraDetails(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject, details bool) (api.DBInstanceDetails, error) { + var err error + out := api.DBInstanceDetails{} + out.VirtualResourceDetails, err = self.SVirtualResourceBase.GetExtraDetails(ctx, userCred, query, details) if err != nil { - return nil, err + return out, err } - return self.getMoreDetails(ctx, userCred, query, extra), nil + return self.getMoreDetails(ctx, userCred, query, out), nil } func (self *SDBInstance) GetVpc() (*SVpc, error) { @@ -446,39 +478,35 @@ func (manager *SDBInstanceManager) FetchCustomizeColumns(ctx context.Context, us return rows } -func (self *SDBInstance) getMoreDetails(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject, extra *jsonutils.JSONDict) *jsonutils.JSONDict { - accountInfo := self.SManagedResourceBase.GetCustomizeColumns(ctx, userCred, query) - if accountInfo != nil { - extra.Update(accountInfo) - } - regionInfo := self.SCloudregionResourceBase.GetCustomizeColumns(ctx, userCred, query) - if regionInfo != nil { - extra.Update(regionInfo) - } +func (self *SDBInstance) getProviderInfo() api.CloudproviderInfo { + provider := self.GetCloudprovider() + region := self.GetRegion() + return MakeCloudProviderInfo(region, nil, provider) +} + +func (self *SDBInstance) getMoreDetails(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject, out api.DBInstanceDetails) api.DBInstanceDetails { + out.CloudproviderInfo = self.getProviderInfo() vpc, _ := self.GetVpc() if vpc != nil { - extra.Add(jsonutils.NewString(vpc.Name), "vpc") + out.Vpc = vpc.Name } if len(self.SecgroupId) > 0 { if secgroup, _ := self.GetSecgroup(); secgroup != nil { - extra.Add(jsonutils.NewString(secgroup.Name), "secgroup") + out.Secgroup = secgroup.Name } } if skus, _ := self.GetDBInstanceSkus(); len(skus) > 0 { - extra.Add(jsonutils.NewInt(int64(skus[0].IOPS)), "iops") + out.Iops = skus[0].IOPS } network, _ := self.GetNetwork() if network != nil { - extra.Add(jsonutils.NewString(network.Name), "network") + out.Network = network.Name } - if metaData, err := self.GetAllMetadata(userCred); err == nil { - extra.Add(jsonutils.Marshal(metaData), "metadata") - } - - return extra + out.Metadata, _ = self.GetAllMetadata(userCred) + return out } func (self *SDBInstance) GetSecgroup() (*SSecurityGroup, error) { @@ -827,11 +855,6 @@ func (self *SDBInstance) StartDBInstanceSyncStatusTask(ctx context.Context, user return nil } -func (self *SDBInstance) GetCustomizeColumns(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject) *jsonutils.JSONDict { - extra := self.SStatusStandaloneResourceBase.GetCustomizeColumns(ctx, userCred, query) - return self.getMoreDetails(ctx, userCred, query, extra) -} - func (manager *SDBInstanceManager) getDBInstancesByProviderId(providerId string) ([]SDBInstance, error) { instances := []SDBInstance{} err := fetchByManagerId(manager, providerId, &instances) diff --git a/pkg/compute/models/deletepreventableresource.go b/pkg/compute/models/deletepreventableresource.go index 9a7997114a..52bd51359f 100644 --- a/pkg/compute/models/deletepreventableresource.go +++ b/pkg/compute/models/deletepreventableresource.go @@ -22,6 +22,8 @@ import ( ) type SDeletePreventableResourceBase struct { + // 是否开启删除保护 + // example: true DisableDelete tristate.TriState `nullable:"false" default:"true" list:"user" update:"user" create:"optional"` } diff --git a/pkg/compute/models/disks.go b/pkg/compute/models/disks.go index 7f230d03ab..3d63d33b5e 100644 --- a/pkg/compute/models/disks.go +++ b/pkg/compute/models/disks.go @@ -28,7 +28,6 @@ import ( "yunion.io/x/pkg/tristate" "yunion.io/x/pkg/util/compare" "yunion.io/x/pkg/util/fileutils" - "yunion.io/x/pkg/util/timeutils" "yunion.io/x/pkg/utils" "yunion.io/x/sqlchemy" @@ -76,26 +75,38 @@ type SDisk struct { SBillingResourceBase - DiskFormat string `width:"32" charset:"ascii" nullable:"false" default:"qcow2" list:"user"` // Column(VARCHAR(32, charset='ascii'), nullable=False, default='qcow2') - DiskSize int `nullable:"false" list:"user"` // Column(Integer, nullable=False) # in MB - AccessPath string `width:"256" charset:"ascii" nullable:"true" get:"user"` // = Column(VARCHAR(256, charset='ascii'), nullable=True) + // 磁盘存储类型 + // example: qcow2 + DiskFormat string `width:"32" charset:"ascii" nullable:"false" default:"qcow2" list:"user"` + // 磁盘大小, 单位Mb + // example: 10240 + DiskSize int `nullable:"false" list:"user"` + // 磁盘路径 + AccessPath string `width:"256" charset:"ascii" nullable:"true" get:"user"` - AutoDelete bool `nullable:"false" default:"false" get:"user" update:"user"` // Column(Boolean, nullable=False, default=False) + // 是否跟随云主机自动删除, 仅绑定到云主机时才生效 + // example: false + AutoDelete bool `nullable:"false" default:"false" get:"user" update:"user"` - StorageId string `width:"128" charset:"ascii" nullable:"true" list:"admin" create:"optional"` // Column(VARCHAR(ID_LENGTH, charset='ascii'), nullable=False) + // 存储Id + StorageId string `width:"128" charset:"ascii" nullable:"true" list:"admin" create:"optional"` BackupStorageId string `width:"128" charset:"ascii" nullable:"true" list:"admin"` - // # backing template id and type - TemplateId string `width:"256" charset:"ascii" nullable:"true" list:"user"` // Column(VARCHAR(ID_LENGTH, charset='ascii'), nullable=True) - // backing snapshot id + // 镜像Id + TemplateId string `width:"256" charset:"ascii" nullable:"true" list:"user"` + // 快照Id SnapshotId string `width:"256" charset:"ascii" nullable:"true" list:"user"` - // # file system - FsFormat string `width:"32" charset:"ascii" nullable:"true" list:"user"` // Column(VARCHAR(32, charset='ascii'), nullable=True) - // # disk type, OS, SWAP, DAT, VOLUME - DiskType string `width:"32" charset:"ascii" nullable:"true" list:"user" update:"admin"` // Column(VARCHAR(32, charset='ascii'), nullable=True) + // 文件系统 + FsFormat string `width:"32" charset:"ascii" nullable:"true" list:"user"` + // 磁盘类型 + // sys: 系统盘 + // data: 数据盘 + // swap: 交换盘 + // example: sys + DiskType string `width:"32" charset:"ascii" nullable:"true" list:"user" update:"admin"` // # is persistent - Nonpersistent bool `default:"false" list:"user"` // Column(Boolean, default=False) + Nonpersistent bool `default:"false" list:"user"` } func (manager *SDiskManager) GetContextManagers() [][]db.IModelManager { @@ -1733,48 +1744,37 @@ func (self *SDisk) CustomizeDelete(ctx context.Context, userCred mcclient.TokenC jsonutils.QueryBoolean(query, "delete_snapshots", false)) } -func (self *SDisk) getMoreDetails(ctx context.Context, userCred mcclient.TokenCredential, - extra *jsonutils.JSONDict) *jsonutils. - JSONDict { - if cloudprovider := self.GetCloudprovider(); cloudprovider != nil { - extra.Add(jsonutils.NewString(cloudprovider.Provider), "provider") - } +func (self *SDisk) getMoreDetails(ctx context.Context, userCred mcclient.TokenCredential, out api.DiskDetails) api.DiskDetails { if storage := self.GetStorage(); storage != nil { - extra.Add(jsonutils.NewString(storage.GetName()), "storage") - extra.Add(jsonutils.NewString(storage.StorageType), "storage_type") - extra.Add(jsonutils.NewString(storage.MediumType), "medium_type") - /*extra.Add(jsonutils.NewString(storage.ZoneId), "zone_id") - if zone := storage.getZone(); zone != nil { - extra.Add(jsonutils.NewString(zone.Name), "zone") - extra.Add(jsonutils.NewString(zone.CloudregionId), "region_id") - if region := zone.GetRegion(); region != nil { - extra.Add(jsonutils.NewString(region.Name), "region") - } - }*/ - - info := storage.getCloudProviderInfo() - extra.Update(jsonutils.Marshal(&info)) + out.Storage = storage.Name + out.StorageType = storage.StorageType + out.MediumType = storage.MediumType + out.CloudproviderInfo = storage.getCloudProviderInfo() } - guestArray := jsonutils.NewArray() - guests, guest_status := []string{}, []string{} + + out.Guests = []api.SimpleGuest{} + guests, guestStatus := []string{}, []string{} for _, guest := range self.GetGuests() { guests = append(guests, guest.Name) - guest_status = append(guest_status, guest.Status) - guestArray.Add(jsonutils.Marshal(map[string]string{"name": guest.Name, "id": guest.Id, "status": guest.Status})) + guestStatus = append(guestStatus, guest.Status) + out.Guests = append(out.Guests, api.SimpleGuest{ + Name: guest.Name, + Id: guest.Id, + Status: guest.Status, + }) } - extra.Add(guestArray, "guests") - extra.Add(jsonutils.NewString(strings.Join(guests, ",")), "guest") - extra.Add(jsonutils.NewInt(int64(len(guests))), "guest_count") - extra.Add(jsonutils.NewString(strings.Join(guest_status, ",")), "guest_status") + out.Guest = strings.Join(guests, ",") + out.GuestCount = len(guests) + out.GuestStatus = strings.Join(guestStatus, ",") if self.PendingDeleted { pendingDeletedAt := self.PendingDeletedAt.Add(time.Second * time.Duration(options.Options.PendingDeleteExpireSeconds)) - extra.Add(jsonutils.NewString(timeutils.FullIsoTime(pendingDeletedAt)), "auto_delete_at") + out.AutoDeleteAt = pendingDeletedAt } // the binded snapshot policy list sds, err := SnapshotPolicyDiskManager.FetchAllByDiskID(ctx, userCred, self.Id) if err != nil { - return extra + return out } spIds := make([]string, len(sds)) for i := range sds { @@ -1782,51 +1782,41 @@ func (self *SDisk) getMoreDetails(ctx context.Context, userCred mcclient.TokenCr } sps, err := SnapshotPolicyManager.FetchAllByIds(spIds) if err != nil { - return extra + return out } - if len(sps) == 0 { - extra.Add(jsonutils.NewString(""), "snapshotpolicy_status") - } else { - extra.Add(jsonutils.NewString(sds[0].Status), "snapshotpolicy_status") + if len(sps) > 0 { + out.SnapshotpolicyStatus = sds[0].Status } + // check status // construction for snapshotpolicies attached to disk - snapshotpoliciesJson := jsonutils.NewArray() + out.Snapshotpolicies = []api.SimpleSnapshotPolicy{} for i := range sps { - spsJson := jsonutils.Marshal(sps[i]) - spsDict := spsJson.(*jsonutils.JSONDict) - repeatWeekdays := SnapshotPolicyManager.RepeatWeekdaysToIntArray(sps[i].RepeatWeekdays) - timePoints := SnapshotPolicyManager.TimePointsToIntArray(sps[i].TimePoints) - spsDict.Remove("repeat_weekdays") - spsDict.Remove("time_points") - spsDict.Add(jsonutils.Marshal(repeatWeekdays), "repeat_weekdays") - spsDict.Add(jsonutils.Marshal(timePoints), "time_points") - snapshotpoliciesJson.Add(spsDict) + policy := api.SimpleSnapshotPolicy{} + policy.RepeatWeekdays = SnapshotPolicyManager.RepeatWeekdaysToIntArray(sps[i].RepeatWeekdays) + policy.TimePoints = SnapshotPolicyManager.TimePointsToIntArray(sps[i].TimePoints) + out.Snapshotpolicies = append(out.Snapshotpolicies, policy) } - extra.Add(snapshotpoliciesJson, "snapshotpolicies") storage := self.GetStorage() if storage != nil { manualSnapshotCount, _ := self.GetManualSnapshotCount() if utils.IsInStringArray(storage.StorageType, append(api.SHARED_FILE_STORAGE, api.STORAGE_LOCAL)) { - extra.Set("manual_snapshot_count", jsonutils.NewInt(int64(manualSnapshotCount))) - extra.Set("max_manual_snapshot_count", jsonutils.NewInt(int64(options.Options.DefaultMaxManualSnapshotCount))) + out.ManualSnapshotCount = manualSnapshotCount + out.MaxManualSnapshotCount = options.Options.DefaultMaxManualSnapshotCount } } - return extra + return out } -func (self *SDisk) GetExtraDetails(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject) (*jsonutils.JSONDict, error) { - extra, err := self.SVirtualResourceBase.GetExtraDetails(ctx, userCred, query) +func (self *SDisk) GetExtraDetails(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject, details bool) (api.DiskDetails, error) { + var err error + out := api.DiskDetails{} + out.VirtualResourceDetails, err = self.SVirtualResourceBase.GetExtraDetails(ctx, userCred, query, details) if err != nil { - return nil, err + return out, err } - return self.getMoreDetails(ctx, userCred, extra), nil -} - -func (self *SDisk) GetCustomizeColumns(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject) *jsonutils.JSONDict { - extra := self.SVirtualResourceBase.GetCustomizeColumns(ctx, userCred, query) - return self.getMoreDetails(ctx, userCred, extra) + return self.getMoreDetails(ctx, userCred, out), nil } func (self *SDisk) StartDiskResizeTask(ctx context.Context, userCred mcclient.TokenCredential, sizeMb int64, parentTaskId string, pendingUsage quotas.IQuota) error { @@ -1948,7 +1938,7 @@ func (self *SDisk) GetShortDesc(ctx context.Context) *jsonutils.JSONDict { var billingInfo SCloudBillingInfo if storage != nil { - billingInfo.SCloudProviderInfo = storage.getCloudProviderInfo() + billingInfo.CloudproviderInfo = storage.getCloudProviderInfo() } if priceKey := self.GetMetadata("ext:price_key", nil); len(priceKey) > 0 { diff --git a/pkg/compute/models/dynamicschedtags.go b/pkg/compute/models/dynamicschedtags.go index 295f536e16..c4f6707151 100644 --- a/pkg/compute/models/dynamicschedtags.go +++ b/pkg/compute/models/dynamicschedtags.go @@ -196,26 +196,23 @@ func (self *SDynamicschedtag) getSchedtag() *SSchedtag { return obj.(*SSchedtag) } -func (self *SDynamicschedtag) getMoreColumns(extra *jsonutils.JSONDict) *jsonutils.JSONDict { +func (self *SDynamicschedtag) getMoreColumns(out api.DynamicschedtagDetails) api.DynamicschedtagDetails { schedtag := self.getSchedtag() if schedtag != nil { - extra.Add(jsonutils.NewString(schedtag.GetName()), "schedtag") - extra.Add(jsonutils.NewString(schedtag.ResourceType), "resource_type") + out.Schedtag = schedtag.GetName() + out.ResourceType = schedtag.ResourceType } - return extra + return out } -func (self *SDynamicschedtag) GetCustomizeColumns(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject) *jsonutils.JSONDict { - extra := self.SStandaloneResourceBase.GetCustomizeColumns(ctx, userCred, query) - return self.getMoreColumns(extra) -} - -func (self *SDynamicschedtag) GetExtraDetails(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject) (*jsonutils.JSONDict, error) { - extra, err := self.SStandaloneResourceBase.GetExtraDetails(ctx, userCred, query) +func (self *SDynamicschedtag) GetExtraDetails(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject, details bool) (api.DynamicschedtagDetails, error) { + var err error + out := api.DynamicschedtagDetails{} + out.StandaloneResourceDetails, err = self.SStandaloneResourceBase.GetExtraDetails(ctx, userCred, query, details) if err != nil { - return nil, err + return out, err } - return self.getMoreColumns(extra), nil + return self.getMoreColumns(out), nil } func (manager *SDynamicschedtagManager) GetEnabledDynamicSchedtagsByResource(resType string) []SDynamicschedtag { diff --git a/pkg/compute/models/elasticcache_backups.go b/pkg/compute/models/elasticcache_backups.go index 0db73fe5e2..3be5e4b4b5 100644 --- a/pkg/compute/models/elasticcache_backups.go +++ b/pkg/compute/models/elasticcache_backups.go @@ -122,24 +122,25 @@ func (manager *SElasticcacheBackupManager) SyncElasticcacheBackups(ctx context.C return syncResult } -func (self *SElasticcacheBackup) GetCustomizeColumns(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject) *jsonutils.JSONDict { - extra := self.SStatusStandaloneResourceBase.GetCustomizeColumns(ctx, userCred, query) +func (self *SElasticcacheBackup) GetExtraDetails(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject, isList bool) (api.ElasticcacheBackupDetails, error) { + var err error + out := api.ElasticcacheBackupDetails{} + out.StandaloneResourceDetails, err = self.SStatusStandaloneResourceBase.GetExtraDetails(ctx, userCred, query, isList) + if err != nil { + return out, err + } icache, err := db.FetchById(ElasticcacheManager, self.ElasticcacheId) if err == nil { ec := icache.(*SElasticcache) provider := ec.GetCloudprovider() region := ec.GetRegion() zone := ec.GetZone() - info := MakeCloudProviderInfo(region, zone, provider) - extra.Update(jsonutils.Marshal(&info)) + out.CloudproviderInfo = MakeCloudProviderInfo(region, zone, provider) - info2 := jsonutils.NewDict() - info2.Set("engine", jsonutils.NewString(ec.Engine)) - info2.Set("engine_version", jsonutils.NewString(ec.EngineVersion)) - extra.Update(info2) + out.Engine = ec.Engine + out.EngineVersion = ec.EngineVersion } - - return extra + return out, nil } func (self *SElasticcacheBackup) syncRemoveCloudElasticcacheBackup(ctx context.Context, userCred mcclient.TokenCredential) error { diff --git a/pkg/compute/models/elasticcache_instances.go b/pkg/compute/models/elasticcache_instances.go index 2578aa2170..291ce0fa9e 100644 --- a/pkg/compute/models/elasticcache_instances.go +++ b/pkg/compute/models/elasticcache_instances.go @@ -140,43 +140,38 @@ func elasticcacheSubResourceFetchOwner(q *sqlchemy.SQuery, userCred mcclient.IId return q } -func (self *SElasticcache) getCloudProviderInfo() SCloudProviderInfo { +func (self *SElasticcache) getCloudProviderInfo() api.CloudproviderInfo { region := self.GetRegion() provider := self.GetCloudprovider() zone := self.GetZone() return MakeCloudProviderInfo(region, zone, provider) } -func (self *SElasticcache) updateExtraDetails(ctx context.Context, userCred mcclient.TokenCredential, extra *jsonutils.JSONDict) *jsonutils.JSONDict { - info := self.getCloudProviderInfo() - extra.Update(jsonutils.Marshal(&info)) +func (self *SElasticcache) updateExtraDetails(ctx context.Context, userCred mcclient.TokenCredential, out api.ElasticcacheDetails) api.ElasticcacheDetails { + out.CloudproviderInfo = self.getCloudProviderInfo() vpc, err := VpcManager.FetchById(self.VpcId) if err == nil { - extra.Set("vpc", jsonutils.NewString(vpc.GetName())) + out.Vpc = vpc.GetName() } network, err := NetworkManager.FetchById(self.NetworkId) if err == nil { - extra.Set("network", jsonutils.NewString(network.GetName())) + out.Network = network.GetName() } - return extra + return out } -func (self *SElasticcache) GetExtraDetails(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject) (*jsonutils.JSONDict, error) { - extra, err := self.SStatusStandaloneResourceBase.GetExtraDetails(ctx, userCred, query) +func (self *SElasticcache) GetExtraDetails(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject, details bool) (api.ElasticcacheDetails, error) { + var err error + out := api.ElasticcacheDetails{} + out.VirtualResourceDetails, err = self.SVirtualResourceBase.GetExtraDetails(ctx, userCred, query, details) if err != nil { - return nil, err + return out, err } - return self.updateExtraDetails(ctx, userCred, extra), nil -} - -func (self *SElasticcache) GetCustomizeColumns(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject) *jsonutils.JSONDict { - extra := self.SStatusStandaloneResourceBase.GetCustomizeColumns(ctx, userCred, query) - - return self.updateExtraDetails(ctx, userCred, extra) + return self.updateExtraDetails(ctx, userCred, out), nil } func (self *SElasticcache) GetElasticcacheParameters() ([]SElasticcacheParameter, error) { diff --git a/pkg/compute/models/elasticcache_skus.go b/pkg/compute/models/elasticcache_skus.go index f131b8192f..6d0290d12a 100644 --- a/pkg/compute/models/elasticcache_skus.go +++ b/pkg/compute/models/elasticcache_skus.go @@ -97,8 +97,11 @@ func (self SElasticcacheSku) GetGlobalId() string { return self.ExternalId } -func (self *SElasticcacheSku) GetCustomizeColumns(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject) *jsonutils.JSONDict { - return self.SStatusStandaloneResourceBase.GetCustomizeColumns(ctx, userCred, query) +func (self *SElasticcacheSku) GetExtraDetails(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject, isList bool) (api.ElasticcacheSkuDetails, error) { + var err error + out := api.ElasticcacheSkuDetails{} + out.StandaloneResourceDetails, err = self.SStatusStandaloneResourceBase.GetExtraDetails(ctx, userCred, query, isList) + return out, err } func (manager *SElasticcacheSkuManager) GetSkuCountByRegion(regionId string) (int, error) { diff --git a/pkg/compute/models/elasticips.go b/pkg/compute/models/elasticips.go index 51ac3f74cd..3212fe08d4 100644 --- a/pkg/compute/models/elasticips.go +++ b/pkg/compute/models/elasticips.go @@ -65,21 +65,35 @@ type SElasticip struct { SManagedResourceBase SBillingResourceBase + // IP子网Id, 仅私有云不为空 NetworkId string `width:"36" charset:"ascii" nullable:"true" get:"user" list:"user" create:"optional"` - Mode string `width:"32" charset:"ascii" list:"user"` + // 标识弹性或非弹性 + // public_ip: 公网IP + // elastic_ip: 弹性公网IP + // example: elastic_ip + Mode string `width:"32" charset:"ascii" list:"user"` + // IP地址 IpAddr string `width:"17" charset:"ascii" list:"user" create:"optional"` + // 绑定资源类型 AssociateType string `width:"32" charset:"ascii" list:"user"` - AssociateId string `width:"256" charset:"ascii" list:"user"` + // 绑定资源Id + AssociateId string `width:"256" charset:"ascii" list:"user"` + // 带宽大小 Bandwidth int `list:"user" create:"optional" default:"0"` + // 计费类型: 流量、带宽 + // example: bandwidth ChargeType string `name:"charge_type" list:"user" create:"required"` - BgpType string `list:"user" create:"optional"` // 目前只有华为云此字段是必需填写的。 + // 目前只有华为云此字段是必需填写的 + BgpType string `list:"user" create:"optional"` + // 是否跟随主机删除而自动释放 AutoDellocate tristate.TriState `default:"false" get:"user" create:"optional" update:"user"` + // 区域Id CloudregionId string `width:"36" charset:"ascii" nullable:"false" list:"user" create:"required"` } @@ -197,7 +211,7 @@ func (self *SElasticip) GetShortDesc(ctx context.Context) *jsonutils.JSONDict { billingInfo := SCloudBillingInfo{} - billingInfo.SCloudProviderInfo = self.getCloudProviderInfo() + billingInfo.CloudproviderInfo = self.getCloudProviderInfo() billingInfo.SBillingBaseInfo = self.getBillingBaseInfo() @@ -1063,27 +1077,23 @@ func (self *SElasticip) StartEipSyncstatusTask(ctx context.Context, userCred mcc return nil } -func (self *SElasticip) GetExtraDetails(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject) (*jsonutils.JSONDict, error) { - extra, err := self.SVirtualResourceBase.GetExtraDetails(ctx, userCred, query) +func (self *SElasticip) GetExtraDetails(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject, details bool) (api.ElasticipDetails, error) { + var err error + out := api.ElasticipDetails{} + out.VirtualResourceDetails, err = self.SVirtualResourceBase.GetExtraDetails(ctx, userCred, query, details) if err != nil { - return nil, err + return out, err } - return self.getMoreDetails(extra), nil + return self.getMoreDetails(out), nil } -func (self *SElasticip) GetCustomizeColumns(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject) *jsonutils.JSONDict { - extra := self.SVirtualResourceBase.GetCustomizeColumns(ctx, userCred, query) - return self.getMoreDetails(extra) -} - -func (self *SElasticip) getMoreDetails(extra *jsonutils.JSONDict) *jsonutils.JSONDict { - info := self.getCloudProviderInfo() - extra.Update(jsonutils.Marshal(&info)) +func (self *SElasticip) getMoreDetails(out api.ElasticipDetails) api.ElasticipDetails { + out.CloudproviderInfo = self.getCloudProviderInfo() instance := self.GetAssociateResource() if instance != nil { - extra.Add(jsonutils.NewString(instance.GetName()), "associate_name") + out.AssociateName = instance.GetName() } - return extra + return out } func (manager *SElasticipManager) NewEipForVMOnHost(ctx context.Context, userCred mcclient.TokenCredential, vm *SGuest, host *SHost, bw int, chargeType string, pendingUsage quotas.IQuota) (*SElasticip, error) { @@ -1289,7 +1299,7 @@ func (self *SElasticip) DoPendingDelete(ctx context.Context, userCred mcclient.T self.Dissociate(ctx, userCred) } -func (self *SElasticip) getCloudProviderInfo() SCloudProviderInfo { +func (self *SElasticip) getCloudProviderInfo() api.CloudproviderInfo { region := self.GetRegion() provider := self.GetCloudprovider() return MakeCloudProviderInfo(region, nil, provider) diff --git a/pkg/compute/models/external_projects.go b/pkg/compute/models/external_projects.go index a9fc1de9cb..6340e306fe 100644 --- a/pkg/compute/models/external_projects.go +++ b/pkg/compute/models/external_projects.go @@ -79,34 +79,29 @@ func (manager *SExternalProjectManager) getProjectsByProviderId(providerId strin return projects, nil } -func (self *SExternalProject) getCloudProviderInfo() SCloudProviderInfo { +func (self *SExternalProject) getCloudProviderInfo() api.CloudproviderInfo { provider := self.GetCloudprovider() return MakeCloudProviderInfo(nil, nil, provider) } -func (self *SExternalProject) getMoreDetails(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject, extra *jsonutils.JSONDict) *jsonutils.JSONDict { - info := self.getCloudProviderInfo() - - extra.Update(jsonutils.Marshal(&info)) +func (self *SExternalProject) getMoreDetails(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject, out api.ExternalProjectDetails) api.ExternalProjectDetails { + out.CloudproviderInfo = self.getCloudProviderInfo() tenant, err := db.TenantCacheManager.FetchTenantById(ctx, self.ProjectId) if err == nil { - extra.Add(jsonutils.NewString(tenant.GetName()), "tenant") + out.Tenant = tenant.GetName() } - return extra + return out } -func (self *SExternalProject) GetCustomizeColumns(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject) *jsonutils.JSONDict { - extra := self.SStandaloneResourceBase.GetCustomizeColumns(ctx, userCred, query) - return self.getMoreDetails(ctx, userCred, query, extra) -} - -func (self *SExternalProject) GetExtraDetails(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject) (*jsonutils.JSONDict, error) { - extra, err := self.SStandaloneResourceBase.GetExtraDetails(ctx, userCred, query) +func (self *SExternalProject) GetExtraDetails(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject, details bool) (api.ExternalProjectDetails, error) { + var err error + out := api.ExternalProjectDetails{} + out.StandaloneResourceDetails, err = self.SStandaloneResourceBase.GetExtraDetails(ctx, userCred, query, details) if err != nil { - return nil, err + return out, err } - return self.getMoreDetails(ctx, userCred, query, extra), nil + return self.getMoreDetails(ctx, userCred, query, out), nil } func (manager *SExternalProjectManager) GetProject(externalId string, providerId string) (*SExternalProject, error) { diff --git a/pkg/compute/models/globalvpcs.go b/pkg/compute/models/globalvpcs.go index 8980477029..bdea80c85d 100644 --- a/pkg/compute/models/globalvpcs.go +++ b/pkg/compute/models/globalvpcs.go @@ -74,12 +74,14 @@ func (self *SGlobalVpc) GetVpcs() ([]SVpc, error) { return vpcs, nil } -func (self *SGlobalVpc) GetExtraDetails(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject) (*jsonutils.JSONDict, error) { - return self.SEnabledStatusStandaloneResourceBase.GetExtraDetails(ctx, userCred, query) -} - -func (self *SGlobalVpc) GetCustomizeColumns(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject) *jsonutils.JSONDict { - return self.SEnabledStatusStandaloneResourceBase.GetCustomizeColumns(ctx, userCred, query) +func (self *SGlobalVpc) GetExtraDetails(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject, details bool) (api.GlobalVpcDetails, error) { + var err error + out := api.GlobalVpcDetails{} + out.StandaloneResourceDetails, err = self.SEnabledStatusStandaloneResourceBase.GetExtraDetails(ctx, userCred, query, details) + if err != nil { + return out, err + } + return out, nil } func (manager *SGlobalVpcManager) ValidateCreateData(ctx context.Context, userCred mcclient.TokenCredential, ownerId mcclient.IIdentityProvider, query jsonutils.JSONObject, input api.GlobalVpcCreateInput) (api.GlobalVpcCreateInput, error) { diff --git a/pkg/compute/models/groupguests.go b/pkg/compute/models/groupguests.go index 1e84886870..467eb51773 100644 --- a/pkg/compute/models/groupguests.go +++ b/pkg/compute/models/groupguests.go @@ -20,6 +20,7 @@ import ( "yunion.io/x/jsonutils" "yunion.io/x/sqlchemy" + api "yunion.io/x/onecloud/pkg/apis/compute" "yunion.io/x/onecloud/pkg/cloudcommon/db" "yunion.io/x/onecloud/pkg/mcclient" ) @@ -64,17 +65,16 @@ func (joint *SGroupguest) Slave() db.IStandaloneModel { return db.JointSlave(joint) } -func (self *SGroupguest) GetCustomizeColumns(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject) *jsonutils.JSONDict { - extra := self.SGroupJointsBase.GetCustomizeColumns(ctx, userCred, query) - return db.JointModelExtra(self, extra) -} - -func (self *SGroupguest) GetExtraDetails(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject) (*jsonutils.JSONDict, error) { - extra, err := self.SGroupJointsBase.GetExtraDetails(ctx, userCred, query) +func (self *SGroupguest) GetExtraDetails(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject, details bool) (api.GroupguestDetails, error) { + var err error + out := api.GroupguestDetails{} + out.ModelBaseDetails, err = self.SGroupJointsBase.GetExtraDetails(ctx, userCred, query, details) if err != nil { - return nil, err + return out, err } - return db.JointModelExtra(self, extra), nil + out.Instancegroup, out.Server = db.JointModelExtra(self) + out.Guest = out.Server + return out, nil } func (self *SGroupguest) Delete(ctx context.Context, userCred mcclient.TokenCredential) error { diff --git a/pkg/compute/models/groupnetworks.go b/pkg/compute/models/groupnetworks.go index af4497abac..8740f5864c 100644 --- a/pkg/compute/models/groupnetworks.go +++ b/pkg/compute/models/groupnetworks.go @@ -20,6 +20,7 @@ import ( "yunion.io/x/jsonutils" "yunion.io/x/log" + api "yunion.io/x/onecloud/pkg/apis/compute" "yunion.io/x/onecloud/pkg/cloudcommon/db" "yunion.io/x/onecloud/pkg/mcclient" ) @@ -70,17 +71,15 @@ func (joint *SGroupnetwork) Slave() db.IStandaloneModel { return db.JointSlave(joint) } -func (self *SGroupnetwork) GetCustomizeColumns(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject) *jsonutils.JSONDict { - extra := self.SGroupJointsBase.GetCustomizeColumns(ctx, userCred, query) - return db.JointModelExtra(self, extra) -} - -func (self *SGroupnetwork) GetExtraDetails(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject) (*jsonutils.JSONDict, error) { - extra, err := self.SGroupJointsBase.GetExtraDetails(ctx, userCred, query) +func (self *SGroupnetwork) GetExtraDetails(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject, details bool) (api.GroupnetworkDetails, error) { + var err error + out := api.GroupnetworkDetails{} + out.ModelBaseDetails, err = self.SGroupJointsBase.GetExtraDetails(ctx, userCred, query, details) if err != nil { - return nil, err + return out, err } - return db.JointModelExtra(self, extra), nil + out.Instancegroup, out.Network = db.JointModelExtra(self) + return out, nil } func (self *SGroupnetwork) GetNetwork() *SNetwork { diff --git a/pkg/compute/models/groups.go b/pkg/compute/models/groups.go index 40f243e063..9e9818941e 100644 --- a/pkg/compute/models/groups.go +++ b/pkg/compute/models/groups.go @@ -62,15 +62,20 @@ func init() { type SGroup struct { db.SVirtualResourceBase - ServiceType string `width:"36" charset:"ascii" nullable:"true" list:"user" update:"user" create:"optional"` // Column(VARCHAR(36, charset='ascii'), nullable=True) - ParentId string `width:"36" charset:"ascii" nullable:"true" list:"user" update:"user" create:"optional"` // Column(VARCHAR(36, charset='ascii'), nullable=True) - ZoneId string `width:"36" charset:"ascii" nullable:"true" list:"user" update:"user" create:"optional"` // Column(VARCHAR(36, charset='ascii'), nullable=True) - SchedStrategy string `width:"16" charset:"ascii" nullable:"true" default:"" list:"user" update:"user" create:"optional"` // Column(VARCHAR(16, charset='ascii'), nullable=True, default='') + // 服务类型 + ServiceType string `width:"36" charset:"ascii" nullable:"true" list:"user" update:"user" create:"optional"` + ParentId string `width:"36" charset:"ascii" nullable:"true" list:"user" update:"user" create:"optional"` + // 可用区Id + // example: zone1 + ZoneId string `width:"36" charset:"ascii" nullable:"true" list:"user" update:"user" create:"optional"` + // 调度策略 + SchedStrategy string `width:"16" charset:"ascii" nullable:"true" default:"" list:"user" update:"user" create:"optional"` // the upper limit number of guests with this group in a host Granularity int `nullable:"false" list:"user" get:"user" create:"optional" update:"user" default:"1"` ForceDispersion tristate.TriState `list:"user" get:"user" create:"optional" update:"user" default:"true"` - Enabled tristate.TriState `nullable:"false" default:"true" create:"optional" list:"user" update:"user"` + // 是否启用 + Enabled tristate.TriState `nullable:"false" default:"true" create:"optional" list:"user" update:"user"` } // 主机组列表 @@ -94,30 +99,22 @@ func (sm *SGroupManager) ListItemFilter(ctx context.Context, q *sqlchemy.SQuery, return q, nil } -func (group *SGroup) GetCustomizeColumns(ctx context.Context, userCred mcclient.TokenCredential, - query jsonutils.JSONObject) *jsonutils.JSONDict { - extra := group.SVirtualResourceBase.GetCustomizeColumns(ctx, userCred, query) - ret, _ := group.getMoreDetails(ctx, userCred, extra) - extra.Update(ret.JSON(ret)) - return extra -} - func (group *SGroup) GetExtraDetails(ctx context.Context, userCred mcclient.TokenCredential, - query jsonutils.JSONObject) (*api.InstanceGroupDetail, error) { - extra, err := group.SVirtualResourceBase.GetExtraDetails(ctx, userCred, query) + query jsonutils.JSONObject, details bool) (api.InstanceGroupDetail, error) { + var err error + out := api.InstanceGroupDetail{} + out.VirtualResourceDetails, err = group.SVirtualResourceBase.GetExtraDetails(ctx, userCred, query, details) if err != nil { - return nil, err + return out, err } - return group.getMoreDetails(ctx, userCred, extra) + return group.getMoreDetails(ctx, userCred, out) } func (group *SGroup) getMoreDetails(ctx context.Context, userCred mcclient.TokenCredential, - data jsonutils.JSONObject) (*api.InstanceGroupDetail, error) { + out api.InstanceGroupDetail) (api.InstanceGroupDetail, error) { q := GroupguestManager.Query().Equals("group_id", group.Id) - count, _ := q.CountWithError() - output := new(api.InstanceGroupDetail) - output.GuestCount = int64(count) - return output, nil + out.GuestCount, _ = q.CountWithError() + return out, nil } func (group *SGroup) ValidateDeleteCondition(ctx context.Context) error { diff --git a/pkg/compute/models/guest_template.go b/pkg/compute/models/guest_template.go index 1edecde5cf..24a8b7c12e 100644 --- a/pkg/compute/models/guest_template.go +++ b/pkg/compute/models/guest_template.go @@ -177,34 +177,23 @@ func (gt *SGuestTemplate) ValidateUpdateData(ctx context.Context, userCred mccli return gt.SSharableVirtualResourceBase.ValidateUpdateData(ctx, userCred, query, data) } -func (gt *SGuestTemplate) GetCustomizeColumns(ctx context.Context, userCred mcclient.TokenCredential, - query jsonutils.JSONObject) *jsonutils.JSONDict { - extra := gt.SVirtualResourceBase.GetCustomizeColumns(ctx, userCred, query) - out := &computeapis.GuesttemplateDetails{} - gt.getMoreDetailsV2(ctx, userCred, out) - ret := out.JSON(out) - ret.Update(extra) - return ret -} - func (gt *SGuestTemplate) GetExtraDetails(ctx context.Context, userCred mcclient.TokenCredential, - query jsonutils.JSONObject) (*computeapis.GuesttemplateDetails, error) { - - out := &computeapis.GuesttemplateDetails{} - err := gt.SSharableVirtualResourceBase.GetExtraDetailsV2(ctx, userCred, query, &out.SharableVirtualResourceDetails) + query jsonutils.JSONObject, details bool) (computeapis.GuesttemplateDetails, error) { + var err error + out := computeapis.GuesttemplateDetails{} + out.SharableVirtualResourceDetails, err = gt.SSharableVirtualResourceBase.GetExtraDetails(ctx, userCred, query, details) if err != nil { return out, err } - gt.getMoreDetailsV2(ctx, userCred, out) - return out, nil + return gt.getMoreDetails(ctx, userCred, out) } -func (gt *SGuestTemplate) getMoreDetailsV2(ctx context.Context, userCred mcclient.TokenCredential, - out *computeapis.GuesttemplateDetails) { +func (gt *SGuestTemplate) getMoreDetails(ctx context.Context, userCred mcclient.TokenCredential, + out computeapis.GuesttemplateDetails) (computeapis.GuesttemplateDetails, error) { input, err := cmdline.FetchServerCreateInputByJSON(gt.Content) if err != nil { - return + return out, err } configInfo := computeapis.GuesttemplateConfigInfo{} if len(input.PreferRegion) != 0 { @@ -338,7 +327,7 @@ func (gt *SGuestTemplate) getMoreDetailsV2(ctx context.Context, userCred mcclien } out.ConfigInfo = configInfo - return + return out, nil } func (gt *SGuestTemplate) PerformPublic(ctx context.Context, userCred mcclient.TokenCredential, diff --git a/pkg/compute/models/guestdisks.go b/pkg/compute/models/guestdisks.go index 231a496245..fd67a98335 100644 --- a/pkg/compute/models/guestdisks.go +++ b/pkg/compute/models/guestdisks.go @@ -109,33 +109,28 @@ func (joint *SGuestdisk) Slave() db.IStandaloneModel { return db.JointSlave(joint) } -func (self *SGuestdisk) getExtraInfo(extra *jsonutils.JSONDict) *jsonutils.JSONDict { +func (self *SGuestdisk) getExtraInfo(out api.GuestDiskDetails) api.GuestDiskDetails { disk := self.GetDisk() if storage := disk.GetStorage(); storage != nil { - extra.Add(jsonutils.NewString(storage.StorageType), "storage_type") + out.StorageType = storage.StorageType + out.MediumType = storage.MediumType } - extra.Add(jsonutils.NewInt(int64(disk.DiskSize)), "disk_size") - extra.Add(jsonutils.NewString(disk.Status), "status") - extra.Add(jsonutils.NewString(disk.DiskType), "disk_type") - if storage := disk.GetStorage(); storage != nil { - extra.Add(jsonutils.NewString(storage.MediumType), "medium_type") - } - return extra + out.DiskSize = disk.DiskSize + out.Status = disk.Status + out.DiskType = disk.DiskType + return out } -func (self *SGuestdisk) GetCustomizeColumns(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject) *jsonutils.JSONDict { - extra := self.SGuestJointsBase.GetCustomizeColumns(ctx, userCred, query) - extra = db.JointModelExtra(self, extra) - return self.getExtraInfo(extra) -} - -func (self *SGuestdisk) GetExtraDetails(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject) (*jsonutils.JSONDict, error) { - extra, err := self.SGuestJointsBase.GetExtraDetails(ctx, userCred, query) +func (self *SGuestdisk) GetExtraDetails(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject, details bool) (api.GuestDiskDetails, error) { + var err error + out := api.GuestDiskDetails{} + out.ModelBaseDetails, err = self.SGuestJointsBase.GetExtraDetails(ctx, userCred, query, details) if err != nil { - return nil, err + return out, err } - extra = db.JointModelExtra(self, extra) - return self.getExtraInfo(extra), nil + out.Guest, out.Disk = db.JointModelExtra(self) + out.Server = out.Guest + return self.getExtraInfo(out), nil } func (self *SGuestdisk) DoSave(driver string, cache string, mountpoint string) error { diff --git a/pkg/compute/models/guestnetworks.go b/pkg/compute/models/guestnetworks.go index d51bac0b22..88c3186c30 100644 --- a/pkg/compute/models/guestnetworks.go +++ b/pkg/compute/models/guestnetworks.go @@ -99,17 +99,16 @@ func (joint *SGuestnetwork) Slave() db.IStandaloneModel { return db.JointSlave(joint) } -func (self *SGuestnetwork) GetCustomizeColumns(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject) *jsonutils.JSONDict { - extra := self.SGuestJointsBase.GetCustomizeColumns(ctx, userCred, query) - return db.JointModelExtra(self, extra) -} - -func (self *SGuestnetwork) GetExtraDetails(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject) (*jsonutils.JSONDict, error) { - extra, err := self.SGuestJointsBase.GetExtraDetails(ctx, userCred, query) +func (self *SGuestnetwork) GetExtraDetails(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject, details bool) (api.GuestnetworkDetails, error) { + var err error + out := api.GuestnetworkDetails{} + out.ModelBaseDetails, err = self.SGuestJointsBase.GetExtraDetails(ctx, userCred, query, details) if err != nil { - return nil, err + return out, err } - return db.JointModelExtra(self, extra), nil + out.Server, out.Network = db.JointModelExtra(self) + out.Guest = out.Server + return out, nil } func (manager *SGuestnetworkManager) AllowCreateItem(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject, data jsonutils.JSONObject) bool { diff --git a/pkg/compute/models/guests.go b/pkg/compute/models/guests.go index 37642eb88e..f210e4c3d8 100644 --- a/pkg/compute/models/guests.go +++ b/pkg/compute/models/guests.go @@ -91,34 +91,49 @@ type SGuest struct { SBillingResourceBase SDeletePreventableResourceBase - VcpuCount int `nullable:"false" default:"1" list:"user" create:"optional"` // Column(TINYINT, nullable=False, default=1) - VmemSize int `nullable:"false" list:"user" create:"required"` // Column(Integer, nullable=False) + // CPU大小 + VcpuCount int `nullable:"false" default:"1" list:"user" create:"optional"` + // 内存大小, 单位Mb + VmemSize int `nullable:"false" list:"user" create:"required"` - BootOrder string `width:"8" charset:"ascii" nullable:"true" default:"cdn" list:"user" update:"user" create:"optional"` // Column(VARCHAR(8, charset='ascii'), nullable=True, default='cdn') + // 启动顺序 + BootOrder string `width:"8" charset:"ascii" nullable:"true" default:"cdn" list:"user" update:"user" create:"optional"` - ShutdownBehavior string `width:"16" charset:"ascii" default:"stop" list:"user" update:"user" create:"optional"` // Column(VARCHAR(16, charset='ascii'), default=SHUTDOWN_STOP) + // 关机操作类型 + // example: stop + ShutdownBehavior string `width:"16" charset:"ascii" default:"stop" list:"user" update:"user" create:"optional"` - KeypairId string `width:"36" charset:"ascii" nullable:"true" list:"user" create:"optional"` // Column(VARCHAR(36, charset='ascii'), nullable=True) + // 秘钥对Id + KeypairId string `width:"36" charset:"ascii" nullable:"true" list:"user" create:"optional"` - HostId string `width:"36" charset:"ascii" nullable:"true" list:"admin" get:"admin" index:"true"` // Column(VARCHAR(36, charset='ascii'), nullable=True) + // 宿主机Id + HostId string `width:"36" charset:"ascii" nullable:"true" list:"admin" get:"admin" index:"true"` + // 备份机所在宿主机Id BackupHostId string `width:"36" charset:"ascii" nullable:"true" list:"user" get:"user"` - Vga string `width:"36" charset:"ascii" nullable:"true" list:"user" update:"user" create:"optional"` // Column(VARCHAR(36, charset='ascii'), nullable=True) - Vdi string `width:"36" charset:"ascii" nullable:"true" list:"user" update:"user" create:"optional"` // Column(VARCHAR(36, charset='ascii'), nullable=True) - Machine string `width:"36" charset:"ascii" nullable:"true" list:"user" update:"user" create:"optional"` // Column(VARCHAR(36, charset='ascii'), nullable=True) - Bios string `width:"36" charset:"ascii" nullable:"true" list:"user" update:"user" create:"optional"` // Column(VARCHAR(36, charset='ascii'), nullable=True) - OsType string `width:"36" charset:"ascii" nullable:"true" list:"user" update:"user" create:"optional"` // Column(VARCHAR(36, charset='ascii'), nullable=True) + Vga string `width:"36" charset:"ascii" nullable:"true" list:"user" update:"user" create:"optional"` + Vdi string `width:"36" charset:"ascii" nullable:"true" list:"user" update:"user" create:"optional"` + Machine string `width:"36" charset:"ascii" nullable:"true" list:"user" update:"user" create:"optional"` + Bios string `width:"36" charset:"ascii" nullable:"true" list:"user" update:"user" create:"optional"` + // 操作系统类型 + OsType string `width:"36" charset:"ascii" nullable:"true" list:"user" update:"user" create:"optional"` - FlavorId string `width:"36" charset:"ascii" nullable:"true" list:"user" create:"optional"` // Column(VARCHAR(36, charset='ascii'), nullable=True) + FlavorId string `width:"36" charset:"ascii" nullable:"true" list:"user" create:"optional"` - SecgrpId string `width:"36" charset:"ascii" nullable:"true" get:"user" create:"optional"` // Column(VARCHAR(36, charset='ascii'), nullable=True) - AdminSecgrpId string `width:"36" charset:"ascii" nullable:"true" get:"admin"` // Column(VARCHAR(36, charset='ascii'), nullable=True) + // 安全组Id + // example: default + SecgrpId string `width:"36" charset:"ascii" nullable:"true" get:"user" create:"optional"` + // 管理员可见安全组Id + AdminSecgrpId string `width:"36" charset:"ascii" nullable:"true" get:"admin"` SrcIpCheck tristate.TriState `nullable:"false" default:"true" create:"optional" list:"user" update:"user"` SrcMacCheck tristate.TriState `nullable:"false" default:"true" create:"optional" list:"user" update:"user"` - Hypervisor string `width:"16" charset:"ascii" nullable:"false" default:"kvm" list:"user" create:"required"` // Column(VARCHAR(16, charset='ascii'), nullable=False, default=HYPERVISOR_DEFAULT) + // 虚拟化技术 + // example: kvm + Hypervisor string `width:"16" charset:"ascii" nullable:"false" default:"kvm" list:"user" create:"required"` + // 套餐名称 InstanceType string `width:"64" charset:"utf8" nullable:"true" list:"user" create:"optional"` } @@ -1588,38 +1603,18 @@ func (self *SGuest) getExtBandwidth() int { return self.getBandwidth(true) } -func (self *SGuest) GetCustomizeColumns(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject) *jsonutils.JSONDict { - extra := self.SVirtualResourceBase.GetCustomizeColumns(ctx, userCred, query) - fields := stringutils2.NewSortedStrings(jsonutils.GetQueryStringArray(query, "field")) - - if query.Contains("group") { - groupId, _ := query.GetString("group") - q := GroupguestManager.Query().Equals("group_id", groupId).Equals("guest_id", self.Id) - var groupGuest SGroupguest - err := q.First(&groupGuest) - if err == nil { - extra.Add(jsonutils.NewTimeString(groupGuest.CreatedAt), "attach_time") - } - } - return self.moreExtraInfo(extra, fields) -} - -func (self *SGuest) moreExtraInfo(extra *jsonutils.JSONDict, fields stringutils2.SSortedStrings) *jsonutils.JSONDict { +func (self *SGuest) moreExtraInfo(out api.ServerDetails, fields stringutils2.SSortedStrings) api.ServerDetails { // extra.Add(jsonutils.NewInt(int64(self.getExtBandwidth())), "ext_bw") - if self.IsPrepaidRecycle() { - extra.Add(jsonutils.JSONTrue, "is_prepaid_recycle") - } else { - extra.Add(jsonutils.JSONFalse, "is_prepaid_recycle") - } + out.IsPrepaidRecycle = self.IsPrepaidRecycle() if len(self.BackupHostId) > 0 && (len(fields) == 0 || fields.Contains("backup_host_name") || fields.Contains("backup_host_status")) { backupHost := HostManager.FetchHostById(self.BackupHostId) if len(fields) == 0 || fields.Contains("backup_host_name") { - extra.Set("backup_host_name", jsonutils.NewString(backupHost.Name)) + out.BackupHostName = backupHost.Name } if len(fields) == 0 || fields.Contains("backup_host_status") { - extra.Set("backup_host_status", jsonutils.NewString(backupHost.HostStatus)) + out.BackupHostStatus = backupHost.HostStatus } } @@ -1627,50 +1622,41 @@ func (self *SGuest) moreExtraInfo(extra *jsonutils.JSONDict, fields stringutils2 host := self.GetHost() if host != nil { if len(fields) == 0 || fields.Contains("host") { - extra.Add(jsonutils.NewString(host.Name), "host") + out.Host = host.Name } if len(fields) == 0 || fields.ContainsAny(providerInfoFields...) { info := host.getCloudProviderInfo() if len(fields) == 0 { - extra.Update(jsonutils.Marshal(&info)) + out.CloudproviderInfo = info } else { - extra.Update(jsonutils.Marshal(&info).(*jsonutils.JSONDict).CopyIncludes([]string(fields)...)) + jsonutils.Update(&out, jsonutils.Marshal(&info).(*jsonutils.JSONDict).CopyIncludes([]string(fields)...)) } } if len(fields) == 0 || fields.Contains("host_sn") { - extra.Add(jsonutils.NewString(host.SN), "host_sn") + out.HostSN = host.SN } } } if len(fields) == 0 || fields.Contains("can_recycle") { err := self.CanPerformPrepaidRecycle() - if err != nil { - extra.Add(jsonutils.JSONFalse, "can_recycle") - } else { - extra.Add(jsonutils.JSONTrue, "can_recycle") + if err == nil { + out.CanRecycle = true } } if len(fields) == 0 || fields.Contains("auto_delete_at") { if self.PendingDeleted { pendingDeletedAt := self.PendingDeletedAt.Add(time.Second * time.Duration(options.Options.PendingDeleteExpireSeconds)) - extra.Add(jsonutils.NewString(timeutils.FullIsoTime(pendingDeletedAt)), "auto_delete_at") + out.AutoDeleteAt = pendingDeletedAt } } - if metaData, err := db.GetVisiableMetadata(self, nil); err == nil { - extra.Add(jsonutils.Marshal(metaData), "metadata") - } + out.Metadata, _ = db.GetVisiableMetadata(self, nil) + out.DiskCount = self.GetDisksQuery().Count() + out.CdromSupport, _ = self.GetDriver().IsSupportCdrom(self) - q := self.GetDisksQuery() - count, _ := q.CountWithError() - extra.Add(jsonutils.NewInt(int64(count)), "disk_count") - - cdromSupport, _ := self.GetDriver().IsSupportCdrom(self) - extra.Set("cdrom_support", jsonutils.NewBool(cdromSupport)) - - return extra + return out } func (self *SGuest) GetMetadataHideKeys() []string { @@ -1679,32 +1665,46 @@ func (self *SGuest) GetMetadataHideKeys() []string { } } -func (self *SGuest) GetExtraDetails(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject) (*jsonutils.JSONDict, error) { - extra, err := self.SVirtualResourceBase.GetExtraDetails(ctx, userCred, query) +func (self *SGuest) GetExtraDetails(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject, isList bool) (api.ServerDetails, error) { + var err error + out := api.ServerDetails{} + out.VirtualResourceDetails, err = self.SVirtualResourceBase.GetExtraDetails(ctx, userCred, query, isList) if err != nil { - return nil, err + return out, err } - extra.Add(jsonutils.NewString(self.getNetworksDetails()), "networks") - extra.Add(jsonutils.NewString(self.getDisksDetails()), "disks") - extra.Add(self.getDisksInfoDetails(), "disks_info") - - extra.Add(jsonutils.NewString(strings.Join(self.getVirtualIPs(), ",")), "virtual_ips") - extra.Add(jsonutils.NewString(self.getSecurityGroupsRules()), "security_rules") - - osName := self.GetOS() - if len(osName) > 0 { - extra.Add(jsonutils.NewString(osName), "os_name") - if len(self.OsType) == 0 { - extra.Add(jsonutils.NewString(osName), "os_type") + var fields stringutils2.SSortedStrings + if isList { + fields = stringutils2.NewSortedStrings(jsonutils.GetQueryStringArray(query, "field")) + if query.Contains("group") { + groupId, _ := query.GetString("group") + q := GroupguestManager.Query().Equals("group_id", groupId).Equals("guest_id", self.Id) + var groupGuest SGroupguest + err := q.First(&groupGuest) + if err == nil { + out.AttachTime = groupGuest.CreatedAt + } } - } + } else { + out.Networks = self.getNetworksDetails() + out.DisksInfo = self.getDisksInfoDetails() + out.VirtualIps = strings.Join(self.getVirtualIPs(), ",") + out.SecurityRules = self.getSecurityGroupsRules() - if db.IsAdminAllowGet(userCred, self) { - extra.Add(jsonutils.NewString(self.getAdminSecurityRules()), "admin_security_rules") - } + osName := self.GetOS() + if len(osName) > 0 { + out.OsName = osName + if len(self.OsType) == 0 { + out.OsType = osName + } + } - return self.moreExtraInfo(extra, nil), nil + if userCred.HasSystemAdminPrivilege() { + out.AdminSecurityRules = self.getAdminSecurityRules() + } + + } + return self.moreExtraInfo(out, fields), nil } func (manager *SGuestManager) ListItemExportKeys(ctx context.Context, q *sqlchemy.SQuery, userCred mcclient.TokenCredential, query jsonutils.JSONObject) (*sqlchemy.SQuery, error) { @@ -4020,7 +4020,7 @@ func (self *SGuest) GetShortDesc(ctx context.Context) *jsonutils.JSONDict { if host != nil { desc.Set("host", jsonutils.NewString(host.Name)) desc.Set("host_id", jsonutils.NewString(host.Id)) - billingInfo.SCloudProviderInfo = host.getCloudProviderInfo() + billingInfo.CloudproviderInfo = host.getCloudProviderInfo() } if priceKey := self.GetMetadata("ext:price_key", nil); len(priceKey) > 0 { diff --git a/pkg/compute/models/hostnetworks.go b/pkg/compute/models/hostnetworks.go index 3f52b282a6..c31f57263d 100644 --- a/pkg/compute/models/hostnetworks.go +++ b/pkg/compute/models/hostnetworks.go @@ -20,6 +20,7 @@ import ( "yunion.io/x/jsonutils" "yunion.io/x/sqlchemy" + api "yunion.io/x/onecloud/pkg/apis/compute" "yunion.io/x/onecloud/pkg/cloudcommon/db" "yunion.io/x/onecloud/pkg/mcclient" ) @@ -70,22 +71,20 @@ func (bn *SHostnetwork) Slave() db.IStandaloneModel { return db.JointSlave(bn) } -func (bn *SHostnetwork) GetCustomizeColumns(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject) *jsonutils.JSONDict { - extra := bn.SHostJointsBase.GetCustomizeColumns(ctx, userCred, query) - extra = db.JointModelExtra(bn, extra) +func (bn *SHostnetwork) GetExtraDetails(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject, details bool) (api.HostnetworkDetails, error) { + var err error + out := api.HostnetworkDetails{} + out.ModelBaseDetails, err = bn.SHostJointsBase.GetExtraDetails(ctx, userCred, query, details) + if err != nil { + return out, err + } + out.Host, out.Network = db.JointModelExtra(bn) + out.Baremetal = out.Host netif := bn.GetNetInterface() if netif != nil { - extra.Add(jsonutils.NewString(netif.NicType), "nic_type") + out.NicType = netif.NicType } - return extra -} - -func (bn *SHostnetwork) GetExtraDetails(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject) (*jsonutils.JSONDict, error) { - extra, err := bn.SHostJointsBase.GetExtraDetails(ctx, userCred, query) - if err != nil { - return nil, err - } - return db.JointModelExtra(bn, extra), nil + return out, nil } func (bn *SHostnetwork) GetHost() *SHost { diff --git a/pkg/compute/models/hosts.go b/pkg/compute/models/hosts.go index 7cc3bda491..1c3668fdeb 100644 --- a/pkg/compute/models/hosts.go +++ b/pkg/compute/models/hosts.go @@ -82,54 +82,82 @@ type SHost struct { SManagedResourceBase SBillingResourceBase - Rack string `width:"16" charset:"ascii" nullable:"true" get:"admin" update:"admin" create:"admin_optional"` // Column(VARCHAR(16, charset='ascii'), nullable=True) - Slots string `width:"16" charset:"ascii" nullable:"true" get:"admin" update:"admin" create:"admin_optional"` // Column(VARCHAR(16, charset='ascii'), nullable=True) + // 机架 + Rack string `width:"16" charset:"ascii" nullable:"true" get:"admin" update:"admin" create:"admin_optional"` + Slots string `width:"16" charset:"ascii" nullable:"true" get:"admin" update:"admin" create:"admin_optional"` - AccessMac string `width:"32" charset:"ascii" nullable:"false" index:"true" list:"admin" update:"admin"` // Column(VARCHAR(32, charset='ascii'), nullable=False, index=True) + AccessMac string `width:"32" charset:"ascii" nullable:"false" index:"true" list:"admin" update:"admin"` - AccessIp string `width:"16" charset:"ascii" nullable:"true" list:"admin"` // Column(VARCHAR(16, charset='ascii'), nullable=True) + // Ip地址 + AccessIp string `width:"16" charset:"ascii" nullable:"true" list:"admin"` - ManagerUri string `width:"256" charset:"ascii" nullable:"true" list:"admin" update:"admin" create:"admin_optional"` // Column(VARCHAR(256, charset='ascii'), nullable=True) + // 管理地址 + ManagerUri string `width:"256" charset:"ascii" nullable:"true" list:"admin" update:"admin" create:"admin_optional"` - SysInfo jsonutils.JSONObject `nullable:"true" search:"admin" list:"admin" update:"admin" create:"admin_optional"` // Column(JSONEncodedDict, nullable=True) - SN string `width:"128" charset:"ascii" nullable:"true" list:"admin" update:"admin" create:"admin_optional"` // Column(VARCHAR(128, charset='ascii'), nullable=True) + // 系统信息 + SysInfo jsonutils.JSONObject `nullable:"true" search:"admin" list:"admin" update:"admin" create:"admin_optional"` + // SN信息 + SN string `width:"128" charset:"ascii" nullable:"true" list:"admin" update:"admin" create:"admin_optional"` - CpuCount int `nullable:"true" list:"admin" update:"admin" create:"admin_optional"` // Column(TINYINT, nullable=True) # cpu count - NodeCount int8 `nullable:"true" list:"admin" update:"admin" create:"admin_optional"` // Column(TINYINT, nullable=True) - CpuDesc string `width:"64" charset:"ascii" nullable:"true" get:"admin" update:"admin" create:"admin_optional"` // Column(VARCHAR(64, charset='ascii'), nullable=True) - CpuMhz int `nullable:"true" get:"admin" update:"admin" create:"admin_optional"` // Column(Integer, nullable=True) # cpu MHz - CpuCache int `nullable:"true" get:"admin" update:"admin" create:"admin_optional"` // Column(Integer, nullable=True) # cpu Cache in KB - CpuReserved int `nullable:"true" default:"0" list:"admin" update:"admin" create:"admin_optional"` // Column(TINYINT, nullable=True, default=0) - CpuCmtbound float32 `nullable:"true" default:"8" list:"admin" update:"admin" create:"admin_optional"` // = Column(Float, nullable=True) - CpuMicrocode string `width:"64" charset:"ascii" nullable:"true" get:"admin" update:"admin" create:"admin_optional"` - CpuArchitecture string `width:"16" charset:"ascii" nullable:"true" get:"user" update:"admin" create:"admin_optional"` + // CPU大小 + CpuCount int `nullable:"true" list:"admin" update:"admin" create:"admin_optional"` + // 物理CPU颗数 + NodeCount int8 `nullable:"true" list:"admin" update:"admin" create:"admin_optional"` + // CPU描述信息 + CpuDesc string `width:"64" charset:"ascii" nullable:"true" get:"admin" update:"admin" create:"admin_optional"` + // CPU频率 + CpuMhz int `nullable:"true" get:"admin" update:"admin" create:"admin_optional"` + // CPU缓存大小,单位KB + CpuCache int `nullable:"true" get:"admin" update:"admin" create:"admin_optional"` + // 预留CPU大小 + CpuReserved int `nullable:"true" default:"0" list:"admin" update:"admin" create:"admin_optional"` + // CPU超分比 + CpuCmtbound float32 `nullable:"true" default:"8" list:"admin" update:"admin" create:"admin_optional"` + // CPUMicrocode + CpuMicrocode string `width:"64" charset:"ascii" nullable:"true" get:"admin" update:"admin" create:"admin_optional"` + // CPU架构 + CpuArchitecture string `width:"16" charset:"ascii" nullable:"true" get:"user" update:"admin" create:"admin_optional"` - MemSize int `nullable:"true" list:"admin" update:"admin" create:"admin_optional"` // Column(Integer, nullable=True) # memory size in MB - MemReserved int `nullable:"true" default:"0" list:"admin" update:"admin" create:"admin_optional"` // Column(Integer, nullable=True, default=0) # memory reserved in MB - MemCmtbound float32 `nullable:"true" default:"1" list:"admin" update:"admin" create:"admin_optional"` // = Column(Float, nullable=True) + // 内存大小,单位Mb + MemSize int `nullable:"true" list:"admin" update:"admin" create:"admin_optional"` + // 预留内存大小 + MemReserved int `nullable:"true" default:"0" list:"admin" update:"admin" create:"admin_optional"` + // 内存超分比 + MemCmtbound float32 `nullable:"true" default:"1" list:"admin" update:"admin" create:"admin_optional"` - StorageSize int `nullable:"true" list:"admin" update:"admin" create:"admin_optional"` // Column(Integer, nullable=True) # storage size in MB - StorageType string `width:"20" charset:"ascii" nullable:"true" list:"admin" update:"admin" create:"admin_optional"` // Column(VARCHAR(20, charset='ascii'), nullable=True) - StorageDriver string `width:"20" charset:"ascii" nullable:"true" get:"admin" update:"admin" create:"admin_optional"` // Column(VARCHAR(20, charset='ascii'), nullable=True) - StorageInfo jsonutils.JSONObject `nullable:"true" get:"admin" update:"admin" create:"admin_optional"` // Column(JSONEncodedDict, nullable=True) + // 存储大小,单位Mb + StorageSize int `nullable:"true" list:"admin" update:"admin" create:"admin_optional"` + // 存储类型 + StorageType string `width:"20" charset:"ascii" nullable:"true" list:"admin" update:"admin" create:"admin_optional"` + // 存储驱动类型 + StorageDriver string `width:"20" charset:"ascii" nullable:"true" get:"admin" update:"admin" create:"admin_optional"` + // 存储详情 + StorageInfo jsonutils.JSONObject `nullable:"true" get:"admin" update:"admin" create:"admin_optional"` - IpmiIp string `width:"16" charset:"ascii" nullable:"true" list:"admin"` // Column(VARCHAR(16, charset='ascii'), nullable=True) + // IPMI地址 + IpmiIp string `width:"16" charset:"ascii" nullable:"true" list:"admin"` - IpmiInfo jsonutils.JSONObject `nullable:"true" get:"admin" update:"admin" create:"admin_optional"` // Column(JSONEncodedDict, nullable=True) + // IPMI详情 + IpmiInfo jsonutils.JSONObject `nullable:"true" get:"admin" update:"admin" create:"admin_optional"` - // Status string = Column(VARCHAR(16, charset='ascii'), nullable=False, default=baremetalstatus.INIT) # status - HostStatus string `width:"16" charset:"ascii" nullable:"false" default:"offline" list:"admin"` // Column(VARCHAR(16, charset='ascii'), nullable=False, server_default=HOST_OFFLINE, default=HOST_OFFLINE) + // 宿主机状态 + // example: online + HostStatus string `width:"16" charset:"ascii" nullable:"false" default:"offline" list:"admin"` + // 可用区Id + // example: zone1 ZoneId string `width:"128" charset:"ascii" nullable:"true" list:"admin" update:"admin" create:"admin_optional"` - HostType string `width:"36" charset:"ascii" nullable:"false" list:"admin" update:"admin" create:"admin_required"` // Column(VARCHAR(36, charset='ascii'), nullable=False) + // 宿主机类型 + HostType string `width:"36" charset:"ascii" nullable:"false" list:"admin" update:"admin" create:"admin_required"` - Version string `width:"64" charset:"ascii" list:"admin" update:"admin" create:"admin_optional"` // Column(VARCHAR(64, charset='ascii')) + Version string `width:"64" charset:"ascii" list:"admin" update:"admin" create:"admin_optional"` OvnVersion string `width:"64" charset:"ascii" list:"admin" update:"admin" create:"admin_optional"` - IsBaremetal bool `nullable:"true" default:"false" list:"admin" update:"admin" create:"admin_optional"` // Column(Boolean, nullable=True, default=False) + IsBaremetal bool `nullable:"true" default:"false" list:"admin" update:"admin" create:"admin_optional"` - IsMaintenance bool `nullable:"true" default:"false" list:"admin"` // Column(Boolean, nullable=True, default=False) + // 是否处于维护状态 + IsMaintenance bool `nullable:"true" default:"false" list:"admin"` LastPingAt time.Time `` @@ -2322,16 +2350,15 @@ func (self *SHost) getGuestsResource(status string) *SHostGuestResourceUsage { return &stat } -func (self *SHost) getMoreDetails(ctx context.Context, extra *jsonutils.JSONDict) *jsonutils.JSONDict { - info := self.getCloudProviderInfo() - extra.Update(jsonutils.Marshal(&info)) +func (self *SHost) getMoreDetails(ctx context.Context, out api.HostDetails) api.HostDetails { + out.CloudproviderInfo = self.getCloudProviderInfo() server := self.GetBaremetalServer() if server != nil { - extra.Add(jsonutils.NewString(server.Id), "server_id") - extra.Add(jsonutils.NewString(server.Name), "server") + out.ServerId = server.Id + out.Server = server.Name if self.HostType == api.HOST_TYPE_BAREMETAL { - extra.Add(jsonutils.NewString(strings.Join(server.GetRealIPs(), ",")), "server_ips") + out.ServerIps = strings.Join(server.GetRealIPs(), ",") } } netifs := self.GetNetInterfaces() @@ -2345,10 +2372,10 @@ func (self *SHost) getMoreDetails(ctx context.Context, extra *jsonutils.JSONDict } nicInfos = append(nicInfos, nicInfo) } - extra.Add(jsonutils.NewInt(int64(len(nicInfos))), "nic_count") - extra.Add(jsonutils.NewArray(nicInfos...), "nic_info") + out.NicCount = len(nicInfos) + out.NicInfo = nicInfos } - extra = GetSchedtagsDetailsToResource(self, ctx, extra) + out.Schedtags = GetSchedtagsDetailsToResourceV2(self, ctx) var usage *SHostGuestResourceUsage if options.Options.IgnoreNonrunningGuests { usage = self.getGuestsResource(api.VM_RUNNING) @@ -2356,70 +2383,65 @@ func (self *SHost) getMoreDetails(ctx context.Context, extra *jsonutils.JSONDict usage = self.getGuestsResource("") } if usage != nil { - extra.Add(jsonutils.NewInt(int64(usage.GuestVcpuCount)), "cpu_commit") - extra.Add(jsonutils.NewInt(int64(usage.GuestVmemSize)), "mem_commit") + out.CpuCommit = usage.GuestVcpuCount + out.MemCommit = usage.GuestVmemSize } containerCount, _ := self.GetContainerCount(nil) runningContainerCount, _ := self.GetContainerCount(api.VM_RUNNING_STATUS) guestCount, _ := self.GetGuestCount() nonesysGuestCnt, _ := self.GetNonsystemGuestCount() runningGuestCnt, _ := self.GetRunningGuestCount() - extra.Add(jsonutils.NewInt(int64(guestCount-containerCount)), "guests") - extra.Add(jsonutils.NewInt(int64(nonesysGuestCnt-containerCount)), "nonsystem_guests") - extra.Add(jsonutils.NewInt(int64(runningGuestCnt-runningContainerCount)), "running_guests") + out.Guests = guestCount - containerCount + out.NonsystemGuests = nonesysGuestCnt - containerCount + out.RunningGuests = runningGuestCnt - runningContainerCount totalCpu := self.GetCpuCount() cpuCommitRate := 0.0 if totalCpu > 0 && usage.GuestVcpuCount > 0 { cpuCommitRate = float64(usage.GuestVcpuCount) * 1.0 / float64(totalCpu) } - extra.Add(jsonutils.NewFloat(cpuCommitRate), "cpu_commit_rate") + out.CpuCommitRate = cpuCommitRate totalMem := self.GetMemSize() memCommitRate := 0.0 if totalMem > 0 && usage.GuestVmemSize > 0 { memCommitRate = float64(usage.GuestVmemSize) * 1.0 / float64(totalMem) } - extra.Add(jsonutils.NewFloat(memCommitRate), "mem_commit_rate") + out.MemCommitRate = memCommitRate capa := self.GetAttachedLocalStorageCapacity() - extra.Add(jsonutils.NewInt(int64(capa.Capacity)), "storage") - extra.Add(jsonutils.NewInt(int64(capa.Used)), "storage_used") - extra.Add(jsonutils.NewInt(int64(capa.Wasted)), "storage_waste") - extra.Add(jsonutils.NewInt(int64(capa.VCapacity)), "storage_virtual") - extra.Add(jsonutils.NewInt(int64(capa.GetFree())), "storage_free") - extra.Add(jsonutils.NewFloat(capa.GetCommitRate()), "storage_commit_rate") - extra.Add(self.GetHardwareSpecification(), "spec") + out.Storage = capa.Capacity + out.StorageUsed = capa.Used + out.StorageWaste = capa.Wasted + out.StorageVirtual = capa.VCapacity + out.StorageFree = capa.GetFree() + out.StorageCommitRate = capa.GetCommitRate() + out.Spec = self.GetHardwareSpecification() // extra = self.SManagedResourceBase.getExtraDetails(ctx, extra) + out.IsPrepaidRecycle = false if self.IsPrepaidRecycle() { - extra.Add(jsonutils.JSONTrue, "is_prepaid_recycle") - } else { - extra.Add(jsonutils.JSONFalse, "is_prepaid_recycle") + out.IsPrepaidRecycle = true } if self.IsBaremetal { + out.CanPrepare = true err := self.canPrepare() - if err == nil { - extra.Add(jsonutils.JSONTrue, "can_prepare") - } else { - extra.Add(jsonutils.JSONFalse, "can_prepare") - extra.Add(jsonutils.NewString(err.Error()), "prepare_fail_reason") + if err != nil { + out.CanPrepare = false + out.PrepareFailReason = err.Error() } } - return extra + return out } -func (self *SHost) GetCustomizeColumns(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject) *jsonutils.JSONDict { - extra := self.SEnabledStatusStandaloneResourceBase.GetCustomizeColumns(ctx, userCred, query) - return self.getMoreDetails(ctx, extra) -} - -func (self *SHost) GetExtraDetails(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject) (*jsonutils.JSONDict, error) { - extra, err := self.SEnabledStatusStandaloneResourceBase.GetExtraDetails(ctx, userCred, query) +func (self *SHost) GetExtraDetails(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject, details bool) (api.HostDetails, error) { + var err error + out := api.HostDetails{} + out.StandaloneResourceDetails, err = self.SEnabledStatusStandaloneResourceBase.GetExtraDetails(ctx, userCred, query, details) if err != nil { - return nil, err + return out, err } - return self.getMoreDetails(ctx, extra), nil + return self.getMoreDetails(ctx, out), nil } func (self *SHost) AllowGetDetailsVnc(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject) bool { @@ -4296,7 +4318,7 @@ func (manager *SHostManager) GetHostByIp(hostIp string) (*SHost, error) { return host.(*SHost), nil } -func (self *SHost) getCloudProviderInfo() SCloudProviderInfo { +func (self *SHost) getCloudProviderInfo() api.CloudproviderInfo { var region *SCloudregion zone := self.GetZone() if zone != nil { diff --git a/pkg/compute/models/hostschedtags.go b/pkg/compute/models/hostschedtags.go index ef343a1277..ffc59e1a4e 100644 --- a/pkg/compute/models/hostschedtags.go +++ b/pkg/compute/models/hostschedtags.go @@ -19,6 +19,7 @@ import ( "yunion.io/x/jsonutils" + api "yunion.io/x/onecloud/pkg/apis/compute" "yunion.io/x/onecloud/pkg/cloudcommon/db" "yunion.io/x/onecloud/pkg/mcclient" ) @@ -69,12 +70,12 @@ func (self *SHostschedtag) Master() db.IStandaloneModel { return self.SSchedtagJointsBase.master(self) } -func (self *SHostschedtag) GetCustomizeColumns(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject) *jsonutils.JSONDict { - return self.SSchedtagJointsBase.getCustomizeColumns(self, ctx, userCred, query) -} - -func (self *SHostschedtag) GetExtraDetails(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject) (*jsonutils.JSONDict, error) { - return self.SSchedtagJointsBase.getExtraDetails(self, ctx, userCred, query) +func (self *SHostschedtag) GetExtraDetails(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject, details bool) (api.HostschedtagDetails, error) { + out := api.HostschedtagDetails{} + out.JoinModelBaseDetails, _ = self.SSchedtagJointsBase.getExtraDetails(self, ctx, userCred, query, details) + out.Host, out.Schedtag = db.JointModelExtra(self) + out.Baremetal = out.Host + return out, nil } func (self *SHostschedtag) Delete(ctx context.Context, userCred mcclient.TokenCredential) error { diff --git a/pkg/compute/models/hoststorages.go b/pkg/compute/models/hoststorages.go index 58f54c05a4..598afd88c8 100644 --- a/pkg/compute/models/hoststorages.go +++ b/pkg/compute/models/hoststorages.go @@ -58,13 +58,18 @@ func init() { type SHoststorage struct { SHostJointsBase - MountPoint string `width:"256" charset:"ascii" nullable:"false" list:"admin" update:"admin" create:"required"` // Column(VARCHAR(256, charset='ascii'), nullable=False) + // 挂载点 + MountPoint string `width:"256" charset:"ascii" nullable:"false" list:"admin" update:"admin" create:"required"` - HostId string `width:"36" charset:"ascii" nullable:"false" list:"admin" create:"required"` // Column(VARCHAR(36, charset='ascii'), nullable=False) - StorageId string `width:"36" charset:"ascii" nullable:"false" list:"admin" create:"required"` // Column(VARCHAR(36, charset='ascii'), nullable=False) + // 宿主机Id + HostId string `width:"36" charset:"ascii" nullable:"false" list:"admin" create:"required"` + // 存储Id + StorageId string `width:"36" charset:"ascii" nullable:"false" list:"admin" create:"required"` - Config *jsonutils.JSONArray `nullable:"true" get:"admin"` // Column(JSONEncodedDict, nullable=True) - RealCapacity int64 `nullable:"true" list:"admin"` // Column(Integer, nullable=True) + // 配置信息 + Config *jsonutils.JSONArray `nullable:"true" get:"admin"` + // 真实容量大小 + RealCapacity int64 `nullable:"true" list:"admin"` } func (manager *SHoststorageManager) GetMasterFieldName() string { @@ -83,19 +88,15 @@ func (joint *SHoststorage) Slave() db.IStandaloneModel { return db.JointSlave(joint) } -func (self *SHoststorage) GetCustomizeColumns(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject) *jsonutils.JSONDict { - extra := self.SHostJointsBase.GetCustomizeColumns(ctx, userCred, query) - extra = db.JointModelExtra(self, extra) - return self.getExtraDetails(extra) -} - -func (self *SHoststorage) GetExtraDetails(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject) (*jsonutils.JSONDict, error) { - extra, err := self.SHostJointsBase.GetExtraDetails(ctx, userCred, query) +func (self *SHoststorage) GetExtraDetails(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject, details bool) (api.HoststorageDetails, error) { + var err error + out := api.HoststorageDetails{} + out.ModelBaseDetails, err = self.SHostJointsBase.GetExtraDetails(ctx, userCred, query, details) if err != nil { - return nil, err + return out, err } - extra = db.JointModelExtra(self, extra) - return self.getExtraDetails(extra), nil + out.Baremetal, out.Storage = db.JointModelExtra(self) + return self.getExtraDetails(out), nil } func (self *SHoststorage) GetHost() *SHost { @@ -205,37 +206,37 @@ func (self *SHoststorage) SyncStorageStatus(userCred mcclient.TokenCredential) { } } -func (self *SHoststorage) getExtraDetails(extra *jsonutils.JSONDict) *jsonutils.JSONDict { +func (self *SHoststorage) getExtraDetails(out api.HoststorageDetails) api.HoststorageDetails { host := self.GetHost() - extra.Add(jsonutils.NewString(host.Name), "host") + out.Host = host.Name storage := self.GetStorage() - extra.Add(jsonutils.NewString(storage.Name), "storage") - extra.Add(jsonutils.NewInt(int64(storage.Capacity)), "capacity") + out.Storage = storage.Name + out.Capacity = storage.Capacity if storage.StorageConf != nil { - extra.Set("storage_conf", storage.StorageConf) + out.StorageConf = storage.StorageConf } used := storage.GetUsedCapacity(tristate.True) wasted := storage.GetUsedCapacity(tristate.False) - extra.Add(jsonutils.NewInt(int64(used)), "used_capacity") - extra.Add(jsonutils.NewInt(int64(wasted)), "waste_capacity") - extra.Add(jsonutils.NewInt(int64(storage.GetFreeCapacity())), "free_capacity") - extra.Add(jsonutils.NewString(storage.StorageType), "storage_type") - extra.Add(jsonutils.NewString(storage.MediumType), "medium_type") - extra.Add(jsonutils.NewBool(storage.Enabled.Bool()), "enabled") - extra.Add(jsonutils.NewFloat(float64(storage.GetOvercommitBound())), "cmtbound") + out.UsedCapacity = used + out.WasteCapacity = wasted + out.FreeCapacity = storage.GetFreeCapacity() + out.StorageType = storage.StorageType + out.MediumType = storage.MediumType + out.Enabled = storage.Enabled.Bool() + out.Cmtbound = storage.GetOvercommitBound() //extra.Add(jsonutils.NewInt(int64(self.GetGuestDiskCount())), "guest_disk_count") - extra = db.FetchModelExtraCountProperties(self, extra) + out.GuestDiskCount, _ = self.GetGuestDiskCount() if len(storage.StoragecacheId) > 0 { storagecache := StoragecacheManager.FetchStoragecacheById(storage.StoragecacheId) if storagecache != nil { - extra.Set("imagecache_path", jsonutils.NewString(storage.GetStorageCachePath(self.MountPoint, storagecache.Path))) - extra.Set("storagecache_id", jsonutils.NewString(storagecache.Id)) + out.StoragecacheId = storagecache.Id + out.ImagecachePath = storage.GetStorageCachePath(self.MountPoint, storagecache.Path) } } - return extra + return out } func (self *SHoststorage) GetGuestDiskCount() (int, error) { diff --git a/pkg/compute/models/hostwires.go b/pkg/compute/models/hostwires.go index 993e5496f0..625cf96823 100644 --- a/pkg/compute/models/hostwires.go +++ b/pkg/compute/models/hostwires.go @@ -20,6 +20,7 @@ import ( "yunion.io/x/jsonutils" "yunion.io/x/sqlchemy" + api "yunion.io/x/onecloud/pkg/apis/compute" "yunion.io/x/onecloud/pkg/cloudcommon/db" "yunion.io/x/onecloud/pkg/httperrors" "yunion.io/x/onecloud/pkg/mcclient" @@ -49,13 +50,18 @@ func init() { type SHostwire struct { SHostJointsBase - Bridge string `width:"16" charset:"ascii" nullable:"false" list:"admin" update:"admin" create:"admin_required"` // Column(VARCHAR(16, charset='ascii'), nullable=False) - Interface string `width:"16" charset:"ascii" nullable:"false" list:"admin" update:"admin" create:"admin_required"` // Column(VARCHAR(16, charset='ascii'), nullable=False) - IsMaster bool `nullable:"true" default:"false" list:"admin" update:"admin" create:"admin_optional"` // Column(Boolean, nullable=True, default=False) - MacAddr string `width:"18" charset:"ascii" list:"admin" update:"admin" create:"admin_required"` // Column(VARCHAR(18, charset='ascii')) + Bridge string `width:"16" charset:"ascii" nullable:"false" list:"admin" update:"admin" create:"admin_required"` + // 接口名称 + Interface string `width:"16" charset:"ascii" nullable:"false" list:"admin" update:"admin" create:"admin_required"` + // 是否是主地址 + IsMaster bool `nullable:"true" default:"false" list:"admin" update:"admin" create:"admin_optional"` + // MAC地址 + MacAddr string `width:"18" charset:"ascii" list:"admin" update:"admin" create:"admin_required"` - HostId string `width:"128" charset:"ascii" nullable:"false" list:"admin" create:"admin_required"` // = Column(VARCHAR(ID_LENGTH, charset='ascii'), nullable=False) - WireId string `width:"128" charset:"ascii" nullable:"false" list:"admin" create:"admin_required"` // Column(VARCHAR(ID_LENGTH, charset='ascii'), nullable=False) + // 宿主机Id + HostId string `width:"128" charset:"ascii" nullable:"false" list:"admin" create:"admin_required"` + // 二层网络Id + WireId string `width:"128" charset:"ascii" nullable:"false" list:"admin" create:"admin_required"` } func (manager *SHostwireManager) GetMasterFieldName() string { @@ -74,19 +80,15 @@ func (joint *SHostwire) Slave() db.IStandaloneModel { return db.JointSlave(joint) } -func (self *SHostwire) GetCustomizeColumns(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject) *jsonutils.JSONDict { - extra := self.SHostJointsBase.GetCustomizeColumns(ctx, userCred, query) - extra = db.JointModelExtra(self, extra) - return self.getExtraDetails(extra) -} - -func (self *SHostwire) GetExtraDetails(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject) (*jsonutils.JSONDict, error) { - extra, err := self.SHostJointsBase.GetExtraDetails(ctx, userCred, query) +func (self *SHostwire) GetExtraDetails(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject, details bool) (api.HostwireDetails, error) { + var err error + out := api.HostwireDetails{} + out.ModelBaseDetails, err = self.SHostJointsBase.GetExtraDetails(ctx, userCred, query, details) if err != nil { - return nil, err + return out, err } - extra = db.JointModelExtra(self, extra) - return self.getExtraDetails(extra), nil + out.Baremetal, out.Wire = db.JointModelExtra(self) + return self.getExtraDetails(out), nil } func (hw *SHostwire) GetWire() *SWire { @@ -105,12 +107,12 @@ func (hw *SHostwire) GetHost() *SHost { return nil } -func (hw *SHostwire) getExtraDetails(extra *jsonutils.JSONDict) *jsonutils.JSONDict { +func (hw *SHostwire) getExtraDetails(out api.HostwireDetails) api.HostwireDetails { wire := hw.GetWire() if wire != nil { - extra.Add(jsonutils.NewInt(int64(wire.Bandwidth)), "bandwidth") + out.Bandwidth = wire.Bandwidth } - return extra + return out } func (self *SHostwire) GetGuestnicsCount() (int, error) { diff --git a/pkg/compute/models/instance_snapshots.go b/pkg/compute/models/instance_snapshots.go index 3dc71127c9..9f713fc9b2 100644 --- a/pkg/compute/models/instance_snapshots.go +++ b/pkg/compute/models/instance_snapshots.go @@ -49,14 +49,22 @@ func init() { type SInstanceSnapshot struct { db.SVirtualResourceBase - GuestId string `width:"36" charset:"ascii" nullable:"false" list:"user" create:"required" index:"true"` - ServerConfig jsonutils.JSONObject `nullable:"true" list:"user"` + // 云主机Id + GuestId string `width:"36" charset:"ascii" nullable:"false" list:"user" create:"required" index:"true"` + // 云主机配置 + ServerConfig jsonutils.JSONObject `nullable:"true" list:"user"` + // 云主机标签 ServerMetadata jsonutils.JSONObject `nullable:"true" list:"user"` - AutoDelete bool `default:"false" update:"user" list:"user"` - RefCount int `default:"0" list:"user"` - SecGroups jsonutils.JSONObject `nullable:"true" list:"user"` - KeypairId string `width:"36" charset:"ascii" nullable:"true" list:"user"` - OsType string `width:"36" charset:"ascii" nullable:"true" list:"user"` + // 是否自动删除 + AutoDelete bool `default:"false" update:"user" list:"user"` + // 引用次数 + RefCount int `default:"0" list:"user"` + // 安全组 + SecGroups jsonutils.JSONObject `nullable:"true" list:"user"` + // 秘钥Id + KeypairId string `width:"36" charset:"ascii" nullable:"true" list:"user"` + // 操作系统类型 + OsType string `width:"36" charset:"ascii" nullable:"true" list:"user"` } type SInstanceSnapshotManager struct { @@ -98,51 +106,47 @@ func (self *SInstanceSnapshot) AllowUpdateItem(ctx context.Context, userCred mcc return false } -func (self *SInstanceSnapshot) GetCustomizeColumns(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject) *jsonutils.JSONDict { - extra := self.SVirtualResourceBase.GetCustomizeColumns(ctx, userCred, query) - extra = self.getMoreDetails(userCred, extra) - return extra -} - -func (self *SInstanceSnapshot) getMoreDetails(userCred mcclient.TokenCredential, extra *jsonutils.JSONDict) *jsonutils.JSONDict { +func (self *SInstanceSnapshot) getMoreDetails(userCred mcclient.TokenCredential, out api.InstnaceSnapshotDetails) api.InstnaceSnapshotDetails { if guest := GuestManager.FetchGuestById(self.GuestId); guest != nil { - extra.Set("guest_status", jsonutils.NewString(guest.Status)) - extra.Set("guest", jsonutils.NewString(guest.Name)) + out.Guest = guest.Name + out.GuestStatus = guest.Status } var osType string snapshots, _ := self.GetSnapshots() - snapshotsDesc := jsonutils.NewArray() + out.Snapshots = []api.SimpleSnapshot{} for i := 0; i < len(snapshots); i++ { if snapshots[i].DiskType == api.DISK_TYPE_SYS { osType = snapshots[i].OsType } - jsonDict := jsonutils.Marshal(&snapshots[i]).(*jsonutils.JSONDict) - metaFields := db.GetDetailFields(SnapshotManager, userCred) - jsonDict = jsonDict.CopyIncludes(metaFields...) + out.Snapshots = append(out.Snapshots, api.SimpleSnapshot{ + Id: snapshots[i].Id, + Name: snapshots[i].Name, + StorageId: snapshots[i].StorageId, + DiskType: snapshots[i].DiskType, + CloudregionId: snapshots[i].CloudregionId, + }) + if len(snapshots[i].StorageId) > 0 { storage := snapshots[i].GetStorage() if storage != nil { - jsonDict.Set("storage_type", jsonutils.NewString(storage.StorageType)) + out.StorageType = storage.StorageType } } - snapshotsDesc.Add(jsonDict) } - extra.Set("snapshots", snapshotsDesc) if len(osType) > 0 { - properties := jsonutils.NewDict() - properties.Set("os_type", jsonutils.NewString(osType)) - extra.Set("properties", properties) + out.Properties = map[string]string{"os_type": osType} } - return extra + return out } -func (self *SInstanceSnapshot) GetExtraDetails(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject) (*jsonutils.JSONDict, error) { - extra, err := self.SVirtualResourceBase.GetExtraDetails(ctx, userCred, query) +func (self *SInstanceSnapshot) GetExtraDetails(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject, details bool) (api.InstnaceSnapshotDetails, error) { + var err error + out := api.InstnaceSnapshotDetails{} + out.VirtualResourceDetails, err = self.SVirtualResourceBase.GetExtraDetails(ctx, userCred, query, details) if err != nil { - return nil, err + return out, err } - extra = self.getMoreDetails(userCred, extra) - return extra, nil + return self.getMoreDetails(userCred, out), nil } func (self *SInstanceSnapshot) StartCreateInstanceSnapshotTask( diff --git a/pkg/compute/models/isolated_devices.go b/pkg/compute/models/isolated_devices.go index fc61ec56fa..f33a6e680f 100644 --- a/pkg/compute/models/isolated_devices.go +++ b/pkg/compute/models/isolated_devices.go @@ -73,22 +73,23 @@ func init() { type SIsolatedDevice struct { db.SStandaloneResourceBase - // name = Column(VARCHAR(16, charset='utf8'), nullable=True, default='', server_default='') # not used - - HostId string `width:"36" charset:"ascii" nullable:"false" default:"" index:"true" list:"admin" create:"admin_required"` // Column(VARCHAR(36, charset='ascii'), nullable=False, default='', server_default='', index=True) + // 宿主机Id + HostId string `width:"36" charset:"ascii" nullable:"false" default:"" index:"true" list:"admin" create:"admin_required"` // # PCI / GPU-HPC / GPU-VGA / USB / NIC - DevType string `width:"16" charset:"ascii" nullable:"false" default:"" index:"true" list:"admin" create:"admin_required" update:"admin"` // Column(VARCHAR(16, charset='ascii'), nullable=False, default='', server_default='', index=True) + // 设备类型 + DevType string `width:"16" charset:"ascii" nullable:"false" default:"" index:"true" list:"admin" create:"admin_required" update:"admin"` // # Specific device name read from lspci command, e.g. `Tesla K40m` ... - Model string `width:"32" charset:"ascii" nullable:"false" default:"" index:"true" list:"admin" create:"admin_required" update:"admin"` // Column(VARCHAR(32, charset='ascii'), nullable=False, default='', server_default='', index=True) + Model string `width:"32" charset:"ascii" nullable:"false" default:"" index:"true" list:"admin" create:"admin_required" update:"admin"` - GuestId string `width:"36" charset:"ascii" nullable:"true" index:"true" list:"admin"` // Column(VARCHAR(36, charset='ascii'), nullable=True, index=True) + // 云主机Id + GuestId string `width:"36" charset:"ascii" nullable:"true" index:"true" list:"admin"` // # pci address of `Bus:Device.Function` format, or usb bus address of `bus.addr` - Addr string `width:"16" charset:"ascii" nullable:"true" list:"admin" update:"admin" create:"admin_optional"` // Column(VARCHAR(16, charset='ascii'), nullable=True) + Addr string `width:"16" charset:"ascii" nullable:"true" list:"admin" update:"admin" create:"admin_optional"` - VendorDeviceId string `width:"16" charset:"ascii" nullable:"true" list:"admin" create:"admin_optional"` // Column(VARCHAR(16, charset='ascii'), nullable=True) + VendorDeviceId string `width:"16" charset:"ascii" nullable:"true" list:"admin" create:"admin_optional"` } func (manager *SIsolatedDeviceManager) AllowListItems(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject) bool { @@ -590,32 +591,27 @@ func (self *SIsolatedDevice) getGuest() *SGuest { return nil } -func (self *SIsolatedDevice) getMoreDetails(extra *jsonutils.JSONDict) *jsonutils.JSONDict { +func (self *SIsolatedDevice) getMoreDetails(out api.IsolateDeviceDetails) api.IsolateDeviceDetails { host := self.getHost() if host != nil { - extra.Add(jsonutils.NewString(host.Name), "host") + out.Host = host.Name } guest := self.getGuest() if guest != nil { - extra.Add(jsonutils.NewString(guest.Name), "guest") - extra.Add(jsonutils.NewString(guest.Status), "guest_status") + out.Guest = guest.Name + out.GuestStatus = guest.Status } - return extra + return out } -func (self *SIsolatedDevice) GetExtraDetails(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject) (*jsonutils.JSONDict, error) { - extra, err := self.SStandaloneResourceBase.GetExtraDetails(ctx, userCred, query) +func (self *SIsolatedDevice) GetExtraDetails(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject, details bool) (api.IsolateDeviceDetails, error) { + var err error + out := api.IsolateDeviceDetails{} + out.StandaloneResourceDetails, err = self.SStandaloneResourceBase.GetExtraDetails(ctx, userCred, query, details) if err != nil { - return nil, err + return out, err } - extra = self.getMoreDetails(extra) - return extra, nil -} - -func (self *SIsolatedDevice) GetCustomizeColumns(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject) *jsonutils.JSONDict { - extra := self.SStandaloneResourceBase.GetCustomizeColumns(ctx, userCred, query) - extra = self.getMoreDetails(extra) - return extra + return self.getMoreDetails(out), nil } func (self *SIsolatedDevice) ClearSchedDescCache() error { diff --git a/pkg/compute/models/keypairs.go b/pkg/compute/models/keypairs.go index 19d9946881..d3c8c1f90f 100644 --- a/pkg/compute/models/keypairs.go +++ b/pkg/compute/models/keypairs.go @@ -54,11 +54,18 @@ func init() { type SKeypair struct { db.SStandaloneResourceBase - Scheme string `width:"12" charset:"ascii" nullable:"true" list:"user" create:"required"` // Column(VARCHAR(length=12, charset='ascii'), nullable=True, default='RSA') - Fingerprint string `width:"48" charset:"ascii" nullable:"false" list:"user" create:"required"` // Column(VARCHAR(length=48, charset='ascii'), nullable=False) - PrivateKey string `width:"2048" charset:"ascii" nullable:"true" create:"optional"` // Column(VARCHAR(length=2048, charset='ascii'), nullable=False) - PublicKey string `width:"1024" charset:"ascii" nullable:"false" list:"user" create:"required"` // Column(VARCHAR(length=1024, charset='ascii'), nullable=False) - OwnerId string `width:"128" charset:"ascii" index:"true" nullable:"false" create:"required"` // Column(VARCHAR(length=36, charset='ascii'), index=True, nullable=False) + // 加密类型 + // example: RSA + Scheme string `width:"12" charset:"ascii" nullable:"true" list:"user" create:"required"` + // 指纹信息 + // example: 1d:3a:83:4a:a1:f3:75:97:ec:d1:ef:f8:3f:a7:5d:9e + Fingerprint string `width:"48" charset:"ascii" nullable:"false" list:"user" create:"required"` + // 私钥 + PrivateKey string `width:"2048" charset:"ascii" nullable:"true" create:"optional"` + // 公钥 + PublicKey string `width:"1024" charset:"ascii" nullable:"false" list:"user" create:"required"` + // 用户Id + OwnerId string `width:"128" charset:"ascii" index:"true" nullable:"false" create:"required"` } // 列出ssh密钥对 @@ -94,39 +101,25 @@ func (self *SKeypair) AllowGetDetails(ctx context.Context, userCred mcclient.Tok return self.IsOwner(userCred) || db.IsAdminAllowGet(userCred, self) } -func (self *SKeypair) GetCustomizeColumns(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject) *jsonutils.JSONDict { - extra := self.SStandaloneResourceBase.GetCustomizeColumns(ctx, userCred, query) - extra.Add(jsonutils.NewInt(int64(len(self.PrivateKey))), "private_key_len") - - guestCnt, err := self.GetLinkedGuestsCount() - if err == nil { - extra.Add(jsonutils.NewInt(int64(guestCnt)), "linked_guest_count") - } - - return extra -} - -func (self *SKeypair) GetExtraDetails(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject) (*jsonutils.JSONDict, error) { - extra, err := self.SStandaloneResourceBase.GetExtraDetails(ctx, userCred, query) +func (self *SKeypair) GetExtraDetails(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject, isList bool) (api.KeypairDetails, error) { + var err error + out := api.KeypairDetails{} + out.StandaloneResourceDetails, err = self.SStandaloneResourceBase.GetExtraDetails(ctx, userCred, query, isList) if err != nil { - return nil, err + return out, err } - extra.Add(jsonutils.NewInt(int64(len(self.PrivateKey))), "private_key_len") + out.PrivateKeyLen = len(self.PrivateKey) - guestCnt, err := self.GetLinkedGuestsCount() - if err != nil { - return nil, httperrors.NewInternalServerError("GetLinkedGuestsCount fail %s", err) - } - extra.Add(jsonutils.NewInt(int64(guestCnt)), "linked_guest_count") + out.LinkedGuestCount, _ = self.GetLinkedGuestsCount() - if db.IsAdminAllowGet(userCred, self) { - extra.Add(jsonutils.NewString(self.OwnerId), "owner_id") + if !isList && db.IsAdminAllowGet(userCred, self) { + out.OwnerId = self.OwnerId uc, _ := db.UserCacheManager.FetchUserById(ctx, self.OwnerId) if uc != nil { - extra.Add(jsonutils.NewString(uc.Name), "owner_name") + out.OwnerName = uc.Name } } - return extra, nil + return out, nil } func (manager *SKeypairManager) AllowCreateItem(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject, data jsonutils.JSONObject) bool { diff --git a/pkg/compute/models/loadbalanceracls.go b/pkg/compute/models/loadbalanceracls.go index 45d332631d..69f584c3cc 100644 --- a/pkg/compute/models/loadbalanceracls.go +++ b/pkg/compute/models/loadbalanceracls.go @@ -252,14 +252,11 @@ func (lbacl *SLoadbalancerAcl) PostCreate(ctx context.Context, userCred mcclient lbacl.SetStatus(userCred, api.LB_STATUS_ENABLED, "") } -func (lbacl *SLoadbalancerAcl) GetCustomizeColumns(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject) *jsonutils.JSONDict { - extra := lbacl.SSharableVirtualResourceBase.GetCustomizeColumns(ctx, userCred, query) - return extra -} - -func (lbacl *SLoadbalancerAcl) GetExtraDetails(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject) (*jsonutils.JSONDict, error) { - extra := lbacl.GetCustomizeColumns(ctx, userCred, query) - return extra, nil +func (lbacl *SLoadbalancerAcl) GetExtraDetails(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject, details bool) (api.LoadbalancerAclDetails, error) { + var err error + out := api.LoadbalancerAclDetails{} + out.SharableVirtualResourceDetails, err = lbacl.SSharableVirtualResourceBase.GetExtraDetails(ctx, userCred, query, details) + return out, err } func (lbacl *SLoadbalancerAcl) AllowPerformPatch(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject, data *jsonutils.JSONDict) bool { diff --git a/pkg/compute/models/loadbalanceragents.go b/pkg/compute/models/loadbalanceragents.go index 992b916115..fea1a2f37a 100644 --- a/pkg/compute/models/loadbalanceragents.go +++ b/pkg/compute/models/loadbalanceragents.go @@ -547,26 +547,23 @@ func (lbagent *SLoadbalancerAgent) ValidateUpdateData(ctx context.Context, userC return data, nil } -func (lbagent *SLoadbalancerAgent) GetCustomizeColumns(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject) *jsonutils.JSONDict { - extra := lbagent.SStandaloneResourceBase.GetCustomizeColumns(ctx, userCred, query) - { - m, err := LoadbalancerClusterManager.FetchById(lbagent.ClusterId) - if err != nil { - log.Errorf("loadbalancer agent %s(%s): fetch cluster (%s) error: %s", - lbagent.Name, lbagent.Id, lbagent.ClusterId, err) - } else { - lbcluster := m.(*SLoadbalancerCluster) - extra.Set("cluster", jsonutils.NewString(lbcluster.GetName())) - zoneInfo := lbcluster.SZoneResourceBase.GetCustomizeColumns(ctx, userCred, query) - extra.Update(zoneInfo) - } +func (lbagent *SLoadbalancerAgent) GetExtraDetails(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject, details bool) (api.LoadbalancerAgentDetails, error) { + var err error + out := api.LoadbalancerAgentDetails{} + out.StandaloneResourceDetails, err = lbagent.SStandaloneResourceBase.GetExtraDetails(ctx, userCred, query, details) + if err != nil { + return out, err } - return extra -} - -func (lbagent *SLoadbalancerAgent) GetExtraDetails(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject) (*jsonutils.JSONDict, error) { - extra := lbagent.GetCustomizeColumns(ctx, userCred, query) - return extra, nil + m, err := LoadbalancerClusterManager.FetchById(lbagent.ClusterId) + if err != nil { + log.Errorf("loadbalancer agent %s(%s): fetch cluster (%s) error: %s", + lbagent.Name, lbagent.Id, lbagent.ClusterId, err) + return out, err + } + lbcluster := m.(*SLoadbalancerCluster) + out.Cluster = lbcluster.GetName() + out.ZoneInfo = lbcluster.SZoneResourceBase.GetExtraDetails(ctx, userCred, query) + return out, nil } func (manager *SLoadbalancerAgentManager) QueryDistinctExtraField(q *sqlchemy.SQuery, field string) (*sqlchemy.SQuery, error) { diff --git a/pkg/compute/models/loadbalancerawscachedlbb.go b/pkg/compute/models/loadbalancerawscachedlbb.go index d7eda141ee..c92865d63e 100644 --- a/pkg/compute/models/loadbalancerawscachedlbb.go +++ b/pkg/compute/models/loadbalancerawscachedlbb.go @@ -18,7 +18,6 @@ import ( "context" "fmt" - "yunion.io/x/jsonutils" "yunion.io/x/pkg/errors" "yunion.io/x/pkg/util/compare" @@ -60,10 +59,6 @@ type SAwsCachedLb struct { CachedBackendGroupId string `width:"36" charset:"ascii" nullable:"true" list:"user" create:"optional"` } -func (lbb *SAwsCachedLb) GetCustomizeColumns(context.Context, mcclient.TokenCredential, jsonutils.JSONObject) *jsonutils.JSONDict { - return nil -} - func (man *SAwsCachedLbManager) GetBackendsByLocalBackendId(backendId string) ([]SAwsCachedLb, error) { loadbalancerBackends := []SAwsCachedLb{} q := man.Query().Equals("backend_id", backendId) diff --git a/pkg/compute/models/loadbalancerawscachedlbbg.go b/pkg/compute/models/loadbalancerawscachedlbbg.go index be3d3d0d0a..df128655f8 100644 --- a/pkg/compute/models/loadbalancerawscachedlbbg.go +++ b/pkg/compute/models/loadbalancerawscachedlbbg.go @@ -20,7 +20,6 @@ import ( "strconv" "strings" - "yunion.io/x/jsonutils" "yunion.io/x/log" "yunion.io/x/pkg/errors" "yunion.io/x/pkg/util/compare" @@ -69,10 +68,6 @@ type SAwsCachedLbbg struct { HealthCheckInterval int `nullable:"false" list:"user" create:"required"` // 健康检查时间间隔 } -func (lbb *SAwsCachedLbbg) GetCustomizeColumns(context.Context, mcclient.TokenCredential, jsonutils.JSONObject) *jsonutils.JSONDict { - return nil -} - func (lbbg *SAwsCachedLbbg) GetLocalBackendGroup(ctx context.Context, userCred mcclient.TokenCredential) (*SLoadbalancerBackendGroup, error) { if len(lbbg.BackendGroupId) == 0 { return nil, fmt.Errorf("GetLocalBackendGroup no related local backendgroup") diff --git a/pkg/compute/models/loadbalancerbackendgroups.go b/pkg/compute/models/loadbalancerbackendgroups.go index fb1a6dd1e9..8ecb00467a 100644 --- a/pkg/compute/models/loadbalancerbackendgroups.go +++ b/pkg/compute/models/loadbalancerbackendgroups.go @@ -386,27 +386,22 @@ func (lbbg *SLoadbalancerBackendGroup) ValidatePurgeCondition(ctx context.Contex return nil } -func (lbbg *SLoadbalancerBackendGroup) GetCustomizeColumns(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject) *jsonutils.JSONDict { - extra := lbbg.SVirtualResourceBase.GetCustomizeColumns(ctx, userCred, query) - { - lb, err := LoadbalancerManager.FetchById(lbbg.LoadbalancerId) - if err != nil { - log.Errorf("loadbalancer backend group %s(%s): fetch loadbalancer (%s) error: %s", - lbbg.Name, lbbg.Id, lbbg.LoadbalancerId, err) - } else { - extra.Set("loadbalancer", jsonutils.NewString(lb.GetName())) - } +func (lbbg *SLoadbalancerBackendGroup) GetExtraDetails(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject, details bool) (api.LoadbalancerBackendGroupDetails, error) { + var err error + out := api.LoadbalancerBackendGroupDetails{} + out.VirtualResourceDetails, err = lbbg.SVirtualResourceBase.GetExtraDetails(ctx, userCred, query, details) + if err != nil { + return out, err } - regionInfo := lbbg.SCloudregionResourceBase.GetCustomizeColumns(ctx, userCred, query) - if regionInfo != nil { - extra.Update(regionInfo) + lb, err := LoadbalancerManager.FetchById(lbbg.LoadbalancerId) + if err != nil { + log.Errorf("loadbalancer backend group %s(%s): fetch loadbalancer (%s) error: %s", + lbbg.Name, lbbg.Id, lbbg.LoadbalancerId, err) + return out, err } - return extra -} - -func (lbbg *SLoadbalancerBackendGroup) GetExtraDetails(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject) (*jsonutils.JSONDict, error) { - extra := lbbg.GetCustomizeColumns(ctx, userCred, query) - return extra, nil + out.Loadbalancer = lb.GetName() + out.CloudregionInfo = lbbg.SCloudregionResourceBase.GetExtraDetails(ctx, userCred, query) + return out, nil } func (lbbg *SLoadbalancerBackendGroup) PostCreate(ctx context.Context, userCred mcclient.TokenCredential, ownerId mcclient.IIdentityProvider, query jsonutils.JSONObject, data jsonutils.JSONObject) { diff --git a/pkg/compute/models/loadbalancerbackends.go b/pkg/compute/models/loadbalancerbackends.go index 285d04d2f1..45b2773fa3 100644 --- a/pkg/compute/models/loadbalancerbackends.go +++ b/pkg/compute/models/loadbalancerbackends.go @@ -274,25 +274,6 @@ func (lbb *SLoadbalancerBackend) PostCreate(ctx context.Context, userCred mcclie } } -func (lbb *SLoadbalancerBackend) GetCustomizeColumns(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject) *jsonutils.JSONDict { - extra := lbb.SVirtualResourceBase.GetCustomizeColumns(ctx, userCred, query) - providerInfo := lbb.SManagedResourceBase.GetCustomizeColumns(ctx, userCred, query) - if providerInfo != nil { - extra.Update(providerInfo) - } - regionInfo := lbb.SCloudregionResourceBase.GetCustomizeColumns(ctx, userCred, query) - if regionInfo != nil { - extra.Update(regionInfo) - } - - if vpc, err := lbb.getVpc(ctx); err != nil { - log.Warningf("loadbalancer backend %s(%s): get vpc: %v", lbb.Name, lbb.Id, err) - } else if vpc != nil { - extra.Set("vpc_id", jsonutils.NewString(vpc.Id)) - } - return extra -} - func (lbb *SLoadbalancerBackend) getVpc(ctx context.Context) (*SVpc, error) { if lbb.BackendType != api.LB_BACKEND_GUEST { return nil, nil @@ -313,9 +294,25 @@ func (lbb *SLoadbalancerBackend) getVpc(ctx context.Context) (*SVpc, error) { return vpc, nil } -func (lbb *SLoadbalancerBackend) GetExtraDetails(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject) (*jsonutils.JSONDict, error) { - extra := lbb.GetCustomizeColumns(ctx, userCred, query) - return extra, nil +func (lbb *SLoadbalancerBackend) GetExtraDetails(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject, details bool) (api.LoadbalancerBackendDetails, error) { + var err error + out := api.LoadbalancerBackendDetails{} + out.VirtualResourceDetails, err = lbb.SVirtualResourceBase.GetExtraDetails(ctx, userCred, query, details) + if err != nil { + return out, err + } + + provider := lbb.GetCloudprovider() + region := lbb.GetRegion() + out.CloudproviderInfo = MakeCloudProviderInfo(region, nil, provider) + + vpc, err := lbb.getVpc(ctx) + if err != nil { + log.Warningf("loadbalancer backend %s(%s): get vpc: %v", lbb.Name, lbb.Id, err) + return out, err + } + out.VpcId = vpc.Id + return out, nil } func (lbb *SLoadbalancerBackend) StartLoadBalancerBackendCreateTask(ctx context.Context, userCred mcclient.TokenCredential, parentTaskId string) error { diff --git a/pkg/compute/models/loadbalancercachedacls.go b/pkg/compute/models/loadbalancercachedacls.go index f0a6a601a7..717fac4922 100644 --- a/pkg/compute/models/loadbalancercachedacls.go +++ b/pkg/compute/models/loadbalancercachedacls.go @@ -202,22 +202,18 @@ func (lbacl *SCachedLoadbalancerAcl) GetListener() (*SLoadbalancerListener, erro return listener.(*SLoadbalancerListener), nil } -func (lbacl *SCachedLoadbalancerAcl) GetCustomizeColumns(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject) *jsonutils.JSONDict { - extra := lbacl.SSharableVirtualResourceBase.GetCustomizeColumns(ctx, userCred, query) - providerInfo := lbacl.SManagedResourceBase.GetCustomizeColumns(ctx, userCred, query) - if providerInfo != nil { - extra.Update(providerInfo) +func (lbacl *SCachedLoadbalancerAcl) GetExtraDetails(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject, details bool) (api.CachedLoadbalancerAclDetails, error) { + var err error + out := api.CachedLoadbalancerAclDetails{} + out.SharableVirtualResourceDetails, err = lbacl.SSharableVirtualResourceBase.GetExtraDetails(ctx, userCred, query, details) + if err != nil { + return out, err } - regionInfo := lbacl.SCloudregionResourceBase.GetCustomizeColumns(ctx, userCred, query) - if regionInfo != nil { - extra.Update(regionInfo) - } - return extra -} + provider := lbacl.GetCloudprovider() + region := lbacl.GetRegion() + out.CloudproviderInfo = MakeCloudProviderInfo(region, nil, provider) -func (lbacl *SCachedLoadbalancerAcl) GetExtraDetails(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject) (*jsonutils.JSONDict, error) { - extra := lbacl.GetCustomizeColumns(ctx, userCred, query) - return extra, nil + return out, nil } func (lbacl *SCachedLoadbalancerAcl) AllowPerformPatch(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject, data *jsonutils.JSONDict) bool { diff --git a/pkg/compute/models/loadbalancercachedcertificates.go b/pkg/compute/models/loadbalancercachedcertificates.go index 185e93416e..d3e27920d1 100644 --- a/pkg/compute/models/loadbalancercachedcertificates.go +++ b/pkg/compute/models/loadbalancercachedcertificates.go @@ -189,22 +189,18 @@ func (self *SCachedLoadbalancerCertificate) PostCreate(ctx context.Context, user return } -func (self *SCachedLoadbalancerCertificate) GetCustomizeColumns(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject) *jsonutils.JSONDict { - extra := self.SVirtualResourceBase.GetCustomizeColumns(ctx, userCred, query) - providerInfo := self.SManagedResourceBase.GetCustomizeColumns(ctx, userCred, query) - if providerInfo != nil { - extra.Update(providerInfo) +func (self *SCachedLoadbalancerCertificate) GetExtraDetails(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject, details bool) (api.CachedLoadbalancerCertificateDetails, error) { + var err error + out := api.CachedLoadbalancerCertificateDetails{} + out.VirtualResourceDetails, err = self.SVirtualResourceBase.GetExtraDetails(ctx, userCred, query, details) + if err != nil { + return out, err } - regionInfo := self.SCloudregionResourceBase.GetCustomizeColumns(ctx, userCred, query) - if regionInfo != nil { - extra.Update(regionInfo) - } - return extra -} + provider := self.GetCloudprovider() + region := self.GetRegion() + out.CloudproviderInfo = MakeCloudProviderInfo(region, nil, provider) -func (self *SCachedLoadbalancerCertificate) GetExtraDetails(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject) (*jsonutils.JSONDict, error) { - extra := self.GetCustomizeColumns(ctx, userCred, query) - return extra, nil + return out, nil } func (lbcert *SCachedLoadbalancerCertificate) GetIRegion() (cloudprovider.ICloudRegion, error) { diff --git a/pkg/compute/models/loadbalancercertificates.go b/pkg/compute/models/loadbalancercertificates.go index 646c15443f..9b7051463b 100644 --- a/pkg/compute/models/loadbalancercertificates.go +++ b/pkg/compute/models/loadbalancercertificates.go @@ -122,14 +122,11 @@ func (lbcert *SLoadbalancerCertificate) PostCreate(ctx context.Context, userCred lbcert.SetStatus(userCred, api.LB_STATUS_ENABLED, "") } -func (lbcert *SLoadbalancerCertificate) GetCustomizeColumns(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject) *jsonutils.JSONDict { - extra := lbcert.SVirtualResourceBase.GetCustomizeColumns(ctx, userCred, query) - return extra -} - -func (lbcert *SLoadbalancerCertificate) GetExtraDetails(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject) (*jsonutils.JSONDict, error) { - extra := lbcert.GetCustomizeColumns(ctx, userCred, query) - return extra, nil +func (lbcert *SLoadbalancerCertificate) GetExtraDetails(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject, details bool) (api.LoadbalancerCertificateDetails, error) { + var err error + out := api.LoadbalancerCertificateDetails{} + out.VirtualResourceDetails, err = lbcert.SVirtualResourceBase.GetExtraDetails(ctx, userCred, query, details) + return out, err } func (lbcert *SLoadbalancerCertificate) ValidateDeleteCondition(ctx context.Context) error { diff --git a/pkg/compute/models/loadbalancerclusters.go b/pkg/compute/models/loadbalancerclusters.go index 9853f99b1d..5524959227 100644 --- a/pkg/compute/models/loadbalancerclusters.go +++ b/pkg/compute/models/loadbalancerclusters.go @@ -172,18 +172,15 @@ func (lbc *SLoadbalancerCluster) ValidateDeleteCondition(ctx context.Context) er return lbc.SStandaloneResourceBase.ValidateDeleteCondition(ctx) } -func (lbc *SLoadbalancerCluster) GetCustomizeColumns(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject) *jsonutils.JSONDict { - extra := lbc.SStandaloneResourceBase.GetCustomizeColumns(ctx, userCred, query) - zoneInfo := lbc.SZoneResourceBase.GetCustomizeColumns(ctx, userCred, query) - if zoneInfo != nil { - extra.Update(zoneInfo) +func (lbc *SLoadbalancerCluster) GetExtraDetails(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject, details bool) (api.LoadbalancerCusterDetails, error) { + var err error + out := api.LoadbalancerCusterDetails{} + out.StandaloneResourceDetails, err = lbc.SStandaloneResourceBase.GetExtraDetails(ctx, userCred, query, details) + if err != nil { + return out, err } - return extra -} - -func (lbc *SLoadbalancerCluster) GetExtraDetails(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject) (*jsonutils.JSONDict, error) { - extra := lbc.GetCustomizeColumns(ctx, userCred, query) - return extra, nil + out.ZoneInfo = lbc.SZoneResourceBase.GetExtraDetails(ctx, userCred, query) + return out, nil } func (lbc *SLoadbalancerCluster) CustomizeDelete(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject, data jsonutils.JSONObject) error { diff --git a/pkg/compute/models/loadbalancerhuaweicachedlbb.go b/pkg/compute/models/loadbalancerhuaweicachedlbb.go index af0c168ebb..eb79b5078e 100644 --- a/pkg/compute/models/loadbalancerhuaweicachedlbb.go +++ b/pkg/compute/models/loadbalancerhuaweicachedlbb.go @@ -19,7 +19,6 @@ import ( "database/sql" "fmt" - "yunion.io/x/jsonutils" "yunion.io/x/log" "yunion.io/x/pkg/errors" "yunion.io/x/pkg/util/compare" @@ -62,10 +61,6 @@ type SHuaweiCachedLb struct { CachedBackendGroupId string `width:"36" charset:"ascii" nullable:"true" list:"user" create:"optional"` } -func (lbb *SHuaweiCachedLb) GetCustomizeColumns(context.Context, mcclient.TokenCredential, jsonutils.JSONObject) *jsonutils.JSONDict { - return nil -} - func (man *SHuaweiCachedLbManager) GetBackendsByLocalBackendId(backendId string) ([]SHuaweiCachedLb, error) { loadbalancerBackends := []SHuaweiCachedLb{} q := man.Query().IsFalse("pending_deleted").Equals("backend_id", backendId) diff --git a/pkg/compute/models/loadbalancerhuaweicachedlbbg.go b/pkg/compute/models/loadbalancerhuaweicachedlbbg.go index a3c1bbf10b..8f0c493279 100644 --- a/pkg/compute/models/loadbalancerhuaweicachedlbbg.go +++ b/pkg/compute/models/loadbalancerhuaweicachedlbbg.go @@ -20,7 +20,6 @@ import ( "strconv" "strings" - "yunion.io/x/jsonutils" "yunion.io/x/log" "yunion.io/x/pkg/errors" "yunion.io/x/pkg/util/compare" @@ -66,10 +65,6 @@ type SHuaweiCachedLbbg struct { ProtocolType string `width:"16" charset:"ascii" nullable:"false" list:"user" create:"required"` // 监听协议类型 } -func (lbb *SHuaweiCachedLbbg) GetCustomizeColumns(context.Context, mcclient.TokenCredential, jsonutils.JSONObject) *jsonutils.JSONDict { - return nil -} - func (lbbg *SHuaweiCachedLbbg) GetLocalBackendGroup(ctx context.Context, userCred mcclient.TokenCredential) (*SLoadbalancerBackendGroup, error) { if len(lbbg.BackendGroupId) == 0 { return nil, fmt.Errorf("GetLocalBackendGroup no related local backendgroup") diff --git a/pkg/compute/models/loadbalancerlistenerrules.go b/pkg/compute/models/loadbalancerlistenerrules.go index bfe984df4c..ebf54a0094 100644 --- a/pkg/compute/models/loadbalancerlistenerrules.go +++ b/pkg/compute/models/loadbalancerlistenerrules.go @@ -498,30 +498,27 @@ func (lbr *SLoadbalancerListenerRule) ValidateUpdateData(ctx context.Context, us return region.GetDriver().ValidateUpdateLoadbalancerListenerRuleData(ctx, userCred, data, backendGroupV.Model) } -func (lbr *SLoadbalancerListenerRule) GetCustomizeColumns(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject) *jsonutils.JSONDict { - extra := lbr.SVirtualResourceBase.GetCustomizeColumns(ctx, userCred, query) +func (lbr *SLoadbalancerListenerRule) GetExtraDetails(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject, details bool) (api.LoadbalancerListenerRuleDetails, error) { + var err error + out := api.LoadbalancerListenerRuleDetails{} + out.VirtualResourceDetails, err = lbr.SVirtualResourceBase.GetExtraDetails(ctx, userCred, query, details) + if err != nil { + return out, err + } + out.CloudregionInfo = lbr.SCloudregionResourceBase.GetExtraDetails(ctx, userCred, query) if lbr.BackendGroupId == "" { log.Errorf("loadbalancer listener rule %s(%s): empty backend group field", lbr.Name, lbr.Id) - return extra + return out, nil } lbbg, err := LoadbalancerBackendGroupManager.FetchById(lbr.BackendGroupId) if err != nil { log.Errorf("loadbalancer listener rule %s(%s): fetch backend group (%s) error: %s", lbr.Name, lbr.Id, lbr.BackendGroupId, err) - return extra + return out, err } - extra.Set("backend_group", jsonutils.NewString(lbbg.GetName())) + out.BackendGroup = lbbg.GetName() - regionInfo := lbr.SCloudregionResourceBase.GetCustomizeColumns(ctx, userCred, query) - if regionInfo != nil { - extra.Update(regionInfo) - } - return extra -} - -func (lbr *SLoadbalancerListenerRule) GetExtraDetails(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject) (*jsonutils.JSONDict, error) { - extra := lbr.GetCustomizeColumns(ctx, userCred, query) - return extra, nil + return out, nil } func (lbr *SLoadbalancerListenerRule) GetLoadbalancerListener() *SLoadbalancerListener { diff --git a/pkg/compute/models/loadbalancerlisteners.go b/pkg/compute/models/loadbalancerlisteners.go index 9332dd056c..d6d406ef57 100644 --- a/pkg/compute/models/loadbalancerlisteners.go +++ b/pkg/compute/models/loadbalancerlisteners.go @@ -405,16 +405,22 @@ func (lblis *SLoadbalancerListener) StartLoadBalancerListenerSyncTask(ctx contex return nil } -func (lblis *SLoadbalancerListener) GetCustomizeColumns(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject) *jsonutils.JSONDict { - extra := lblis.SVirtualResourceBase.GetCustomizeColumns(ctx, userCred, query) +func (lblis *SLoadbalancerListener) GetExtraDetails(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject, details bool) (api.LoadbalancerListenerDetails, error) { + var err error + out := api.LoadbalancerListenerDetails{} + out.VirtualResourceDetails, err = lblis.SVirtualResourceBase.GetExtraDetails(ctx, userCred, query, details) + if err != nil { + return out, err + } + { lb, err := LoadbalancerManager.FetchById(lblis.LoadbalancerId) if err != nil { log.Errorf("loadbalancer listener %s(%s): fetch loadbalancer (%s) error: %s", lblis.Name, lblis.Id, lblis.LoadbalancerId, err) - return extra + return out, err } - extra.Set("loadbalancer", jsonutils.NewString(lb.GetName())) + out.Loadbalancer = lb.GetName() } { if lblis.BackendGroupId != "" { @@ -422,33 +428,26 @@ func (lblis *SLoadbalancerListener) GetCustomizeColumns(ctx context.Context, use if err != nil { log.Errorf("loadbalancer listener %s(%s): fetch backend group (%s) error: %s", lblis.Name, lblis.Id, lblis.BackendGroupId, err) - return extra + return out, err } - extra.Set("backend_group", jsonutils.NewString(lbbg.GetName())) + out.BackendGroup = lbbg.GetName() } } if len(lblis.AclId) > 0 { if acl := lblis.GetCachedLoadbalancerAcl(); acl != nil { - extra.Set("acl_name", jsonutils.NewString(acl.Name)) + out.AclName = acl.Name } } if len(lblis.CertificateId) > 0 { if cert, _ := lblis.GetLoadbalancerCertificate(); cert != nil { - extra.Set("certificate_name", jsonutils.NewString(cert.Name)) - extra.Set("origin_certificate_id", jsonutils.NewString(cert.CertificateId)) + out.CertificateName = cert.Name + out.OriginCertificateId = cert.CertificateId } } - regionInfo := lblis.SCloudregionResourceBase.GetCustomizeColumns(ctx, userCred, query) - if regionInfo != nil { - extra.Update(regionInfo) - } - return extra -} + out.CloudregionInfo = lblis.SCloudregionResourceBase.GetExtraDetails(ctx, userCred, query) -func (lblis *SLoadbalancerListener) GetExtraDetails(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject) (*jsonutils.JSONDict, error) { - extra := lblis.GetCustomizeColumns(ctx, userCred, query) - return extra, nil + return out, nil } func (lblis *SLoadbalancerListener) PostCreate(ctx context.Context, userCred mcclient.TokenCredential, ownerId mcclient.IIdentityProvider, query jsonutils.JSONObject, data jsonutils.JSONObject) { diff --git a/pkg/compute/models/loadbalancernetworks.go b/pkg/compute/models/loadbalancernetworks.go index 3a7cce0925..3bff6898ef 100644 --- a/pkg/compute/models/loadbalancernetworks.go +++ b/pkg/compute/models/loadbalancernetworks.go @@ -213,9 +213,15 @@ func (ln *SLoadbalancerNetwork) Detach(ctx context.Context, userCred mcclient.To return db.DetachJoint(ctx, userCred, ln) } -func (ln *SLoadbalancerNetwork) GetCustomizeColumns(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject) *jsonutils.JSONDict { - extra := jsonutils.NewDict() - return db.JointModelExtra(ln, extra) +func (ln *SLoadbalancerNetwork) GetExtraDetails(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject, details bool) (api.LoadbalancernetworkDetails, error) { + var err error + out := api.LoadbalancernetworkDetails{} + out.ModelBaseDetails, err = ln.SVirtualJointResourceBase.GetExtraDetails(ctx, userCred, query, details) + if err != nil { + return out, err + } + out.Loadbalancer, out.Network = db.JointModelExtra(ln) + return out, nil } func totalLBNicCount( diff --git a/pkg/compute/models/loadbalancers.go b/pkg/compute/models/loadbalancers.go index 4cb57db1b2..8ad6fe1dce 100644 --- a/pkg/compute/models/loadbalancers.go +++ b/pkg/compute/models/loadbalancers.go @@ -77,17 +77,26 @@ type SLoadbalancer struct { SZoneResourceBase SLoadbalancerRateLimiter - Address string `width:"128" charset:"ascii" nullable:"true" list:"user" create:"optional"` + // IP地址 + Address string `width:"128" charset:"ascii" nullable:"true" list:"user" create:"optional"` + // 地址类型 AddressType string `width:"16" charset:"ascii" nullable:"true" list:"user" create:"optional"` + // 网络类型 NetworkType string `width:"16" charset:"ascii" nullable:"true" list:"user" create:"optional"` - NetworkId string `width:"147" charset:"ascii" nullable:"true" list:"user" create:"optional"` - VpcId string `width:"36" charset:"ascii" nullable:"true" list:"user" create:"optional"` - ClusterId string `width:"36" charset:"ascii" nullable:"true" list:"user" create:"optional"` + // 子网Id + NetworkId string `width:"147" charset:"ascii" nullable:"true" list:"user" create:"optional"` + // 虚拟私有网络Id + VpcId string `width:"36" charset:"ascii" nullable:"true" list:"user" create:"optional"` + // 负载均衡集群Id + ClusterId string `width:"36" charset:"ascii" nullable:"true" list:"user" create:"optional"` + // 计费类型 ChargeType string `list:"user" get:"user" create:"optional" update:"user"` + // 套餐名称 LoadbalancerSpec string `list:"user" get:"user" list:"user" create:"optional"` + // 后端服务器组Id BackendGroupId string `width:"36" charset:"ascii" nullable:"true" list:"user" update:"user"` LBInfo jsonutils.JSONObject `charset:"utf8" nullable:"true" list:"user" update:"admin" create:"admin_optional"` } @@ -400,32 +409,28 @@ func (lb *SLoadbalancer) ValidateUpdateData(ctx context.Context, userCred mcclie return lb.SVirtualResourceBase.ValidateUpdateData(ctx, userCred, query, data) } -func (lb *SLoadbalancer) GetCustomizeColumns(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject) *jsonutils.JSONDict { - extra := lb.SVirtualResourceBase.GetCustomizeColumns(ctx, userCred, query) - providerInfo := lb.SManagedResourceBase.GetCustomizeColumns(ctx, userCred, query) - if providerInfo != nil { - extra.Update(providerInfo) +func (lb *SLoadbalancer) GetExtraDetails(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject, details bool) (api.LoadbalancerDetails, error) { + var err error + out := api.LoadbalancerDetails{} + out.VirtualResourceDetails, err = lb.SVirtualResourceBase.GetExtraDetails(ctx, userCred, query, details) + if err != nil { + return out, err } - zoneInfo := lb.SZoneResourceBase.GetCustomizeColumns(ctx, userCred, query) - if zoneInfo != nil { - extra.Update(zoneInfo) - } else { - regionInfo := lb.SCloudregionResourceBase.GetCustomizeColumns(ctx, userCred, query) - if regionInfo != nil { - extra.Update(regionInfo) - } - } + provider := lb.GetCloudprovider() + zone := lb.GetZone() + region := lb.GetRegion() + out.CloudproviderInfo = MakeCloudProviderInfo(region, zone, provider) eip, _ := lb.GetEip() if eip != nil { - extra.Set("eip", jsonutils.NewString(eip.IpAddr)) - extra.Set("eip_mode", jsonutils.NewString(eip.Mode)) + out.Eip = eip.IpAddr + out.EipMode = eip.Mode } if len(lb.VpcId) > 0 { if vpc := lb.GetVpc(); vpc != nil { - extra.Set("vpc", jsonutils.NewString(vpc.Name)) + out.Vpc = vpc.Name } } @@ -434,16 +439,12 @@ func (lb *SLoadbalancer) GetCustomizeColumns(ctx context.Context, userCred mccli if err != nil { log.Errorf("loadbalancer %s(%s): fetch backend group (%s) error: %s", lb.Name, lb.Id, lb.BackendGroupId, err) - return extra + return out, err } - extra.Set("backend_group", jsonutils.NewString(lbbg.GetName())) + out.BackendGroup = lbbg.GetName() } - return extra -} -func (lb *SLoadbalancer) GetExtraDetails(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject) (*jsonutils.JSONDict, error) { - extra := lb.GetCustomizeColumns(ctx, userCred, query) - return extra, nil + return out, nil } func (lb *SLoadbalancer) ValidateDeleteCondition(ctx context.Context) error { diff --git a/pkg/compute/models/managedresource.go b/pkg/compute/models/managedresource.go index 809b2cfcc0..1e2456b8af 100644 --- a/pkg/compute/models/managedresource.go +++ b/pkg/compute/models/managedresource.go @@ -20,8 +20,6 @@ import ( "fmt" "strings" - "yunion.io/x/jsonutils" - "yunion.io/x/log" "yunion.io/x/sqlchemy" "yunion.io/x/onecloud/pkg/apis" @@ -30,7 +28,6 @@ import ( "yunion.io/x/onecloud/pkg/cloudcommon/db" "yunion.io/x/onecloud/pkg/cloudprovider" "yunion.io/x/onecloud/pkg/httperrors" - "yunion.io/x/onecloud/pkg/mcclient" ) type SManagedResourceBase struct { @@ -65,45 +62,6 @@ func (self *SManagedResourceBase) GetRegionDriver() (IRegionDriver, error) { return driver, nil } -func (self *SManagedResourceBase) GetCustomizeColumns(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject) *jsonutils.JSONDict { - provider := self.GetCloudprovider() - if provider == nil { - return nil - } - info := map[string]string{ - "manager": provider.GetName(), - "manager_id": provider.GetId(), - } - if len(provider.ProjectId) > 0 { - info["manager_project_id"] = provider.ProjectId - info["manager_project_domain_id"] = provider.DomainId - tc, err := db.TenantCacheManager.FetchTenantById(appctx.Background, provider.ProjectId) - if err == nil { - info["manager_project"] = tc.Name - info["manager_project_domain"] = tc.Domain - } - } - - account := provider.GetCloudaccount() - if account != nil { - info["account"] = account.GetName() - info["account_id"] = account.GetId() - info["provider"] = account.Provider - info["brand"] = account.Brand - - info["account_domain_id"] = account.DomainId - dc, err := db.TenantCacheManager.FetchDomainById(appctx.Background, account.DomainId) - if err == nil { - info["account_domain"] = dc.Name - } - } else { - // 避免account为空导致列表加载失败,这里记录日志即可 - log.Errorf("provider %s Cloudaccount %s not found", provider.GetName(), provider.CloudaccountId) - } - - return jsonutils.Marshal(info).(*jsonutils.JSONDict) -} - func (self *SManagedResourceBase) GetProviderFactory() (cloudprovider.ICloudProviderFactory, error) { provider := self.GetCloudprovider() if provider == nil { @@ -460,60 +418,8 @@ func fetchExternalId(extId string) string { } } -func MakeCloudProviderInfoV2(region *SCloudregion, zone *SZone, provider *SCloudprovider) api.CloudproviderDetails { - info := api.CloudproviderDetails{} - - if zone != nil { - info.Zone = zone.GetName() - info.ZoneId = zone.GetId() - } - - if region != nil { - info.Region = region.GetName() - info.RegionId = region.GetId() - info.CloudregionId = region.GetId() - } - - if provider != nil { - info.Manager = provider.GetName() - info.ManagerId = provider.GetId() - - if len(provider.ProjectId) > 0 { - info.ManagerProjectId = provider.ProjectId - tc, err := db.TenantCacheManager.FetchTenantById(appctx.Background, provider.ProjectId) - if err == nil { - info.ManagerProject = tc.GetName() - info.ManagerDomain = tc.Domain - info.ManagerDomainId = tc.DomainId - } - } - - account := provider.GetCloudaccount() - info.Account = account.GetName() - info.AccountId = account.GetId() - - info.Provider = provider.Provider - info.Brand = account.Brand - info.CloudEnv = account.GetCloudEnv() - - if region != nil { - info.RegionExternalId = region.ExternalId - info.RegionExtId = fetchExternalId(region.ExternalId) - if zone != nil { - info.ZoneExtId = fetchExternalId(zone.ExternalId) - } - } - } else { - info.CloudEnv = api.CLOUD_ENV_ON_PREMISE - info.Provider = api.CLOUD_PROVIDER_ONECLOUD - info.Brand = api.CLOUD_PROVIDER_ONECLOUD - } - - return info -} - -func MakeCloudProviderInfo(region *SCloudregion, zone *SZone, provider *SCloudprovider) SCloudProviderInfo { - info := SCloudProviderInfo{} +func MakeCloudProviderInfo(region *SCloudregion, zone *SZone, provider *SCloudprovider) api.CloudproviderInfo { + info := api.CloudproviderInfo{} if zone != nil { info.Zone = zone.GetName() diff --git a/pkg/compute/models/natdtable.go b/pkg/compute/models/natdtable.go index f5baf0cffd..4dc685ea62 100644 --- a/pkg/compute/models/natdtable.go +++ b/pkg/compute/models/natdtable.go @@ -246,31 +246,28 @@ func (manager *SNatDEntryManager) newFromCloudNatDTable(ctx context.Context, use return &table, nil } -func (self *SNatDEntry) GetExtraDetails(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject) (*jsonutils.JSONDict, error) { - extra, err := self.SStatusStandaloneResourceBase.GetExtraDetails(ctx, userCred, query) +func (self *SNatDEntry) GetExtraDetails(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject, details bool) (api.NatDEntryDetails, error) { + var err error + out := api.NatDEntryDetails{} + out.StandaloneResourceDetails, err = self.SStatusStandaloneResourceBase.GetExtraDetails(ctx, userCred, query, details) if err != nil { - return nil, err + return out, err } - return self.getMoreDetails(ctx, userCred, extra), nil -} - -func (self *SNatDEntry) GetCustomizeColumns(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject) *jsonutils.JSONDict { - extra := self.SStatusStandaloneResourceBase.GetCustomizeColumns(ctx, userCred, query) - return self.getMoreDetails(ctx, userCred, extra) + return self.getMoreDetails(ctx, userCred, out), nil } func (self *SNatDEntry) getMoreDetails(ctx context.Context, userCred mcclient.TokenCredential, - query *jsonutils.JSONDict) *jsonutils.JSONDict { + out api.NatDEntryDetails) api.NatDEntryDetails { natgateway, err := self.GetNatgateway() if err != nil { log.Errorf("failed to get naggateway %s for dtable %s(%s) error: %v", self.NatgatewayId, self.Name, self.Id, err) - return query + return out } - query.Add(jsonutils.NewString(natgateway.Name), "natgateway") - query.Add(jsonutils.NewString(NatGatewayManager.NatNameToReal(self.Name, natgateway.GetId())), "real_name") - return query + out.Natgateway = natgateway.Name + out.RealName = NatGatewayManager.NatNameToReal(self.Name, natgateway.GetId()) + return out } func (self *SNatDEntry) PostCreate(ctx context.Context, userCred mcclient.TokenCredential, ownerId mcclient.IIdentityProvider, query jsonutils.JSONObject, data jsonutils.JSONObject) { diff --git a/pkg/compute/models/natgateways.go b/pkg/compute/models/natgateways.go index 4b296ebb73..0e0dc3994f 100644 --- a/pkg/compute/models/natgateways.go +++ b/pkg/compute/models/natgateways.go @@ -243,41 +243,35 @@ func (self *SNatGateway) GetDTableSize(filter func(q *sqlchemy.SQuery) *sqlchemy return q.CountWithError() } -func (self *SNatGateway) GetExtraDetails(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject) (*jsonutils.JSONDict, error) { - extra, err := self.SStatusStandaloneResourceBase.GetExtraDetails(ctx, userCred, query) +func (self *SNatGateway) GetExtraDetails(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject, isList bool) (api.NatgatewayDetails, error) { + var err error + out := api.NatgatewayDetails{} + out.StandaloneResourceDetails, err = self.SStatusStandaloneResourceBase.GetExtraDetails(ctx, userCred, query, isList) if err != nil { - return nil, err + return out, err } - return self.getMoreDetails(ctx, userCred, extra) -} + if isList { + region := self.GetRegion() + provider := self.GetCloudprovider() + out.CloudproviderInfo = MakeCloudProviderInfo(region, nil, provider) -func (self *SNatGateway) GetCustomizeColumns(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject) *jsonutils.JSONDict { - extra := self.SStatusStandaloneResourceBase.GetCustomizeColumns(ctx, userCred, query) - accountInfo := self.SManagedResourceBase.GetCustomizeColumns(ctx, userCred, query) - if accountInfo != nil { - extra.Update(accountInfo) + vpc, err := self.GetVpc() + if err != nil { + log.Errorf("failed to found vpc info for nat gateway %s(%s) error: %v", self.Name, self.Id, err) + return out, err + } + out.Vpc = vpc.Name } - regionInfo := self.SCloudregionResourceBase.GetCustomizeColumns(ctx, userCred, query) - if regionInfo != nil { - extra.Update(regionInfo) - } - vpc, err := self.GetVpc() - if err != nil { - log.Errorf("failed to found vpc info for nat gateway %s(%s) error: %v", self.Name, self.Id, err) - return extra - } - extra.Add(jsonutils.NewString(vpc.Name), "vpc") - extra, _ = self.getMoreDetails(ctx, userCred, extra) - return extra + + return self.getMoreDetails(ctx, userCred, out) } func (self *SNatGateway) getMoreDetails(ctx context.Context, userCred mcclient.TokenCredential, - extra *jsonutils.JSONDict) (*jsonutils.JSONDict, error) { + out api.NatgatewayDetails) (api.NatgatewayDetails, error) { - spec := self.GetRegion().GetDriver().DealNatGatewaySpec(self.NatSpec) - extra.Add(jsonutils.NewString(spec), "nat_spec") + out.NatSpec = self.GetRegion().GetDriver().DealNatGatewaySpec(self.NatSpec) - return extra, nil + return out, nil } func (manager *SNatGetewayManager) SyncNatGateways(ctx context.Context, userCred mcclient.TokenCredential, syncOwnerId mcclient.IIdentityProvider, provider *SCloudprovider, vpc *SVpc, cloudNatGateways []cloudprovider.ICloudNatGateway) ([]SNatGateway, []cloudprovider.ICloudNatGateway, compare.SyncResult) { diff --git a/pkg/compute/models/natstable.go b/pkg/compute/models/natstable.go index 4d12a3c6d8..64432fee11 100644 --- a/pkg/compute/models/natstable.go +++ b/pkg/compute/models/natstable.go @@ -302,39 +302,38 @@ func (manager *SNatSEntryManager) checkNetWorkId(networkId string) (*SNetwork, e return model.(*SNetwork), nil } -func (self *SNatSEntry) GetExtraDetails(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject) (*jsonutils.JSONDict, error) { - extra, err := self.SStatusStandaloneResourceBase.GetExtraDetails(ctx, userCred, query) +func (self *SNatSEntry) GetExtraDetails(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject, details bool) (api.NatSEntryDetails, error) { + var err error + out := api.NatSEntryDetails{} + out.StandaloneResourceDetails, err = self.SStatusStandaloneResourceBase.GetExtraDetails(ctx, userCred, query, details) if err != nil { - return nil, err + return out, err } - return self.getMoreDetails(ctx, userCred, extra), nil -} - -func (self *SNatSEntry) GetCustomizeColumns(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject) *jsonutils.JSONDict { - extra := self.SStatusStandaloneResourceBase.GetCustomizeColumns(ctx, userCred, query) - - return self.getMoreDetails(ctx, userCred, extra) + return self.getMoreDetails(ctx, userCred, out), nil } func (self *SNatSEntry) getMoreDetails(ctx context.Context, userCred mcclient.TokenCredential, - query *jsonutils.JSONDict) *jsonutils.JSONDict { + out api.NatSEntryDetails) api.NatSEntryDetails { network, err := self.GetNetwork() if err != nil { - return query + return out } if network == nil { - return query + return out + } + out.Network = api.SimpleNetwork{ + Id: network.Id, + Name: network.Name, } - query.Add(jsonutils.Marshal(network), "network") natgateway, err := self.GetNatgateway() if err != nil { log.Errorf("failed to get naggateway %s for stable %s(%s) error: %v", self.NatgatewayId, self.Name, self.Id, err) - return query + return out } - query.Add(jsonutils.NewString(natgateway.Name), "natgateway") - query.Add(jsonutils.NewString(NatGatewayManager.NatNameToReal(self.Name, natgateway.GetId())), "real_name") - return query + out.Natgateway = natgateway.Name + out.RealName = NatGatewayManager.NatNameToReal(self.Name, natgateway.GetId()) + return out } func (self *SNatSEntry) PostCreate(ctx context.Context, userCred mcclient.TokenCredential, ownerId mcclient.IIdentityProvider, query jsonutils.JSONObject, data jsonutils.JSONObject) { diff --git a/pkg/compute/models/networkinterfaces.go b/pkg/compute/models/networkinterfaces.go index e3a3f7b210..8af55fcd93 100644 --- a/pkg/compute/models/networkinterfaces.go +++ b/pkg/compute/models/networkinterfaces.go @@ -54,9 +54,12 @@ type SNetworkInterface struct { SManagedResourceBase SCloudregionResourceBase - Mac string `width:"36" charset:"ascii" list:"user"` + // MAC地址 + Mac string `width:"36" charset:"ascii" list:"user"` + // 绑定资源类型 AssociateType string `width:"36" charset:"ascii" list:"user" nullable:"true" create:"optional"` - AssociateId string `width:"36" charset:"ascii" list:"user"` + // 绑定资源Id + AssociateId string `width:"36" charset:"ascii" list:"user"` } func (manager *SNetworkInterfaceManager) GetContextManagers() [][]db.IModelManager { @@ -101,32 +104,38 @@ func (manager *SNetworkInterfaceManager) ListItemFilter(ctx context.Context, q * return q, nil } -func (self *SNetworkInterface) GetCustomizeColumns(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject) *jsonutils.JSONDict { - extra := self.SStatusStandaloneResourceBase.GetCustomizeColumns(ctx, userCred, query) - accountInfo := self.SManagedResourceBase.GetCustomizeColumns(ctx, userCred, query) - if accountInfo != nil { - extra.Update(accountInfo) - } - regionInfo := self.SCloudregionResourceBase.GetCustomizeColumns(ctx, userCred, query) - if regionInfo != nil { - extra.Update(regionInfo) +func (self *SNetworkInterface) GetExterDetails(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject, isList bool) (api.NetworkInterfaceDetails, error) { + var err error + out := api.NetworkInterfaceDetails{} + out.StandaloneResourceDetails, err = self.SStatusStandaloneResourceBase.GetExtraDetails(ctx, userCred, query, isList) + if err != nil { + return out, err } + + provider := self.GetCloudprovider() + region := self.GetRegion() + out.CloudproviderInfo = MakeCloudProviderInfo(region, nil, provider) + networks, err := self.GetNetworks() if err != nil { log.Errorf("failed to get network for networkinterface %s(%s) error: %v", self.Name, self.Id, err) - return extra + return out, nil } - networkArray := jsonutils.NewArray() + out.Networks = []api.NetworkInterfaceNetworkInfo{} for _, network := range networks { - detail, err := network.GetDetailJson() + _network, err := network.GetNetwork() if err != nil { - log.Errorf("failed to get networkinterface network %s detail error: %v", network.IpAddr, err) - return extra + return out, err } - networkArray.Add(detail) + out.Networks = append(out.Networks, api.NetworkInterfaceNetworkInfo{ + NetworkId: network.NetworkId, + IpAddr: network.IpAddr, + Primary: network.Primary, + NetworkinterfaceId: network.NetworkinterfaceId, + Network: _network.Name, + }) } - extra.Add(networkArray, "networks") - return extra + return out, nil } func (manager *SNetworkInterfaceManager) getNetworkInterfacesByProviderId(providerId string) ([]SNetworkInterface, error) { diff --git a/pkg/compute/models/networks.go b/pkg/compute/models/networks.go index ab53c4fcb9..a1a0d3983b 100644 --- a/pkg/compute/models/networks.go +++ b/pkg/compute/models/networks.go @@ -78,33 +78,40 @@ type SNetwork struct { IfnameHint string `width:"9" charset:"ascii" nullable:"true" list:"user" create:"optional"` - GuestIpStart string `width:"16" charset:"ascii" nullable:"false" list:"user" update:"user" create:"required"` // Column(VARCHAR(16, charset='ascii'), nullable=False) - GuestIpEnd string `width:"16" charset:"ascii" nullable:"false" list:"user" update:"user" create:"required"` // Column(VARCHAR(16, charset='ascii'), nullable=False) - GuestIpMask int8 `nullable:"false" list:"user" update:"user" create:"required"` // Column(TINYINT, nullable=False) - GuestGateway string `width:"16" charset:"ascii" nullable:"true" list:"user" update:"user" create:"optional"` // Column(VARCHAR(16, charset='ascii'), nullable=True) - GuestDns string `width:"16" charset:"ascii" nullable:"true" list:"user" update:"user" create:"optional"` // Column(VARCHAR(16, charset='ascii'), nullable=True) + // 起始IP地址 + GuestIpStart string `width:"16" charset:"ascii" nullable:"false" list:"user" update:"user" create:"required"` + // 接收IP地址 + GuestIpEnd string `width:"16" charset:"ascii" nullable:"false" list:"user" update:"user" create:"required"` + // 掩码 + GuestIpMask int8 `nullable:"false" list:"user" update:"user" create:"required"` + // 网关地址 + GuestGateway string `width:"16" charset:"ascii" nullable:"true" list:"user" update:"user" create:"optional"` + // DNS + GuestDns string `width:"16" charset:"ascii" nullable:"true" list:"user" update:"user" create:"optional"` // allow multiple dhcp, seperated by "," - GuestDhcp string `width:"64" charset:"ascii" nullable:"true" list:"user" update:"user" create:"optional"` // Column(VARCHAR(16, charset='ascii'), nullable=True) + GuestDhcp string `width:"64" charset:"ascii" nullable:"true" list:"user" update:"user" create:"optional"` - GuestDomain string `width:"128" charset:"ascii" nullable:"true" get:"user" update:"user"` // Column(VARCHAR(128, charset='ascii'), nullable=True) + GuestDomain string `width:"128" charset:"ascii" nullable:"true" get:"user" update:"user"` - GuestIp6Start string `width:"64" charset:"ascii" nullable:"true"` // Column(VARCHAR(64, charset='ascii'), nullable=True) - GuestIp6End string `width:"64" charset:"ascii" nullable:"true"` // Column(VARCHAR(64, charset='ascii'), nullable=True) - GuestIp6Mask int8 `nullable:"true"` // Column(TINYINT, nullable=True) - GuestGateway6 string `width:"64" charset:"ascii" nullable:"true"` // Column(VARCHAR(64, charset='ascii'), nullable=True) - GuestDns6 string `width:"64" charset:"ascii" nullable:"true"` // Column(VARCHAR(64, charset='ascii'), nullable=True) + GuestIp6Start string `width:"64" charset:"ascii" nullable:"true"` + GuestIp6End string `width:"64" charset:"ascii" nullable:"true"` + GuestIp6Mask int8 `nullable:"true"` + GuestGateway6 string `width:"64" charset:"ascii" nullable:"true"` + GuestDns6 string `width:"64" charset:"ascii" nullable:"true"` - GuestDomain6 string `width:"128" charset:"ascii" nullable:"true"` // Column(VARCHAR(128, charset='ascii'), nullable=True) + GuestDomain6 string `width:"128" charset:"ascii" nullable:"true"` - VlanId int `nullable:"false" default:"1" list:"user" update:"user" create:"optional"` // Column(Integer, nullable=False, default=1) + VlanId int `nullable:"false" default:"1" list:"user" update:"user" create:"optional"` - WireId string `width:"36" charset:"ascii" nullable:"false" list:"user" create:"required"` // Column(VARCHAR(36, charset='ascii'), nullable=False) + // 二层网络Id + WireId string `width:"36" charset:"ascii" nullable:"false" list:"user" create:"required"` - // IsChanged = Column(Boolean, nullable=False, default=False) + // 服务器类型 + // example: server + ServerType string `width:"16" charset:"ascii" default:"guest" nullable:"true" list:"user" update:"user" create:"optional"` - ServerType string `width:"16" charset:"ascii" default:"guest" nullable:"true" list:"user" update:"user" create:"optional"` // Column(VARCHAR(16, charset='ascii'), nullable=True) - - AllocPolicy string `width:"16" charset:"ascii" nullable:"true" get:"user" update:"user" create:"optional"` // Column(VARCHAR(16, charset='ascii'), nullable=True) + // 分配策略 + AllocPolicy string `width:"16" charset:"ascii" nullable:"true" get:"user" update:"user" create:"optional"` AllocTimoutSeconds int `default:"0" nullable:"true" get:"admin"` } @@ -982,58 +989,7 @@ func (self *SNetwork) GetPorts() int { return self.getIPRange().AddressCount() } -func (self *SNetwork) getMoreDetails(ctx context.Context, extra *jsonutils.JSONDict) *jsonutils.JSONDict { - wire := self.GetWire() - zone := self.getZone() - if zone != nil { - extra.Add(jsonutils.NewString(zone.Name), "zone") - extra.Add(jsonutils.NewString(zone.Id), "zone_id") - } - if wire != nil { - extra.Add(jsonutils.NewString(wire.Name), "wire") - } - if self.IsExitNetwork() { - extra.Add(jsonutils.JSONTrue, "exit") - } else { - extra.Add(jsonutils.JSONFalse, "exit") - } - extra.Add(jsonutils.NewInt(int64(self.GetPorts())), "ports") - portsUsed, _ := self.GetTotalNicCount() - extra.Add(jsonutils.NewInt(int64(portsUsed)), "ports_used") - vnics, _ := self.GetGuestnicsCount() - extra.Add(jsonutils.NewInt(int64(vnics)), "vnics") - bmVnics, _ := self.GetBaremetalNicsCount() - extra.Add(jsonutils.NewInt(int64(bmVnics)), "bm_vnics") - lbVnics, _ := self.GetLoadbalancerIpsCount() - extra.Add(jsonutils.NewInt(int64(lbVnics)), "lb_vnics") - eips, _ := self.GetEipsCount() - extra.Add(jsonutils.NewInt(int64(eips)), "eip_vnics") - groupVnics, _ := self.GetGroupNicsCount() - extra.Add(jsonutils.NewInt(int64(groupVnics)), "group_vnics") - reserveVnics, _ := self.GetReservedNicsCount() - extra.Add(jsonutils.NewInt(int64(reserveVnics)), "reserve_vnics") - - vpc := self.getVpc() - if vpc != nil { - extra.Add(jsonutils.NewString(vpc.GetId()), "vpc_id") - extra.Add(jsonutils.NewString(vpc.GetName()), "vpc") - if len(vpc.GetExternalId()) > 0 { - extra.Add(jsonutils.NewString(vpc.GetExternalId()), "vpc_ext_id") - } - info := vpc.getCloudProviderInfo() - extra.Update(jsonutils.Marshal(&info)) - } - routes := self.GetRoutes() - if len(routes) > 0 { - extra.Add(jsonutils.Marshal(routes), "routes") - } - - extra = GetSchedtagsDetailsToResource(self, ctx, extra) - - return extra -} - -func (self *SNetwork) getMoreDetailsV2(ctx context.Context, out *api.NetworkDetails) { +func (self *SNetwork) getMoreDetails(ctx context.Context, out api.NetworkDetails, details bool) (api.NetworkDetails, error) { wire := self.GetWire() if wire != nil { out.Wire = wire.Name @@ -1057,7 +1013,7 @@ func (self *SNetwork) getMoreDetailsV2(ctx context.Context, out *api.NetworkDeta out.Vpc = vpc.Name out.VpcId = vpc.Id out.VpcExtId = vpc.ExternalId - out.CloudproviderDetails = vpc.getCloudProviderInfoV2() + out.CloudproviderInfo = vpc.getCloudProviderInfo() } if len(out.Zone) == 0 { zone := self.getZone() @@ -1068,22 +1024,17 @@ func (self *SNetwork) getMoreDetailsV2(ctx context.Context, out *api.NetworkDeta } out.Routes = self.GetRoutes() out.Schedtags = GetSchedtagsDetailsToResourceV2(self, ctx) -} - -func (self *SNetwork) GetExtraDetails(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject) (*api.NetworkDetails, error) { - out := &api.NetworkDetails{} - err := self.SSharableVirtualResourceBase.GetExtraDetailsV2(ctx, userCred, query, &out.SharableVirtualResourceDetails) - if err != nil { - return nil, err - } - self.getMoreDetailsV2(ctx, out) return out, nil } -func (self *SNetwork) GetCustomizeColumns(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject) *jsonutils.JSONDict { - extra := self.SSharableVirtualResourceBase.GetCustomizeColumns(ctx, userCred, query) - extra = self.getMoreDetails(ctx, extra) - return extra +func (self *SNetwork) GetExtraDetails(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject, details bool) (api.NetworkDetails, error) { + var err error + out := api.NetworkDetails{} + out.SharableVirtualResourceDetails, err = self.SSharableVirtualResourceBase.GetExtraDetails(ctx, userCred, query, details) + if err != nil { + return out, err + } + return self.getMoreDetails(ctx, out, details) } func (self *SNetwork) AllowPerformReserveIp(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject, data jsonutils.JSONObject) bool { diff --git a/pkg/compute/models/networkschedtags.go b/pkg/compute/models/networkschedtags.go index bf31afb43e..75ad213461 100644 --- a/pkg/compute/models/networkschedtags.go +++ b/pkg/compute/models/networkschedtags.go @@ -19,6 +19,7 @@ import ( "yunion.io/x/jsonutils" + api "yunion.io/x/onecloud/pkg/apis/compute" "yunion.io/x/onecloud/pkg/cloudcommon/db" "yunion.io/x/onecloud/pkg/mcclient" ) @@ -69,12 +70,13 @@ func (s *SNetworkschedtag) Master() db.IStandaloneModel { return s.SSchedtagJointsBase.master(s) } -func (s *SNetworkschedtag) GetCustomizeColumns(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject) *jsonutils.JSONDict { - return s.SSchedtagJointsBase.getCustomizeColumns(s, ctx, userCred, query) -} +func (s *SNetworkschedtag) GetExtraDetails(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject, details bool) (api.NetworkschedtagDetails, error) { + var err error + out := api.NetworkschedtagDetails{} + out.JoinModelBaseDetails, err = s.SSchedtagJointsBase.getExtraDetails(s, ctx, userCred, query, details) + out.Network, out.Schedtag = db.JointModelExtra(s) + return out, err -func (s *SNetworkschedtag) GetExtraDetails(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject) (*jsonutils.JSONDict, error) { - return s.SSchedtagJointsBase.getExtraDetails(s, ctx, userCred, query) } func (s *SNetworkschedtag) Delete(ctx context.Context, userCred mcclient.TokenCredential) error { diff --git a/pkg/compute/models/reservedips.go b/pkg/compute/models/reservedips.go index 9da8b084c0..9cd883b187 100644 --- a/pkg/compute/models/reservedips.go +++ b/pkg/compute/models/reservedips.go @@ -52,14 +52,20 @@ func init() { type SReservedip struct { db.SResourceBase - Id int64 `primary:"true" auto_increment:"true" list:"admin"` // = Column(BigInteger, primary_key=True) - NetworkId string `width:"36" charset:"ascii" nullable:"false" list:"admin"` // Column(VARCHAR(36, charset='ascii'), nullable=False) - IpAddr string `width:"16" charset:"ascii" list:"admin"` // Column(VARCHAR(16, charset='ascii')) + // 自增Id + Id int64 `primary:"true" auto_increment:"true" list:"admin"` + // IP子网Id + NetworkId string `width:"36" charset:"ascii" nullable:"false" list:"admin"` + // IP地址 + IpAddr string `width:"16" charset:"ascii" list:"admin"` - Notes string `width:"512" charset:"utf8" nullable:"true" list:"admin" update:"admin"` // ]Column(VARCHAR(512, charset='utf8'), nullable=True) + // 预留原因或描述 + Notes string `width:"512" charset:"utf8" nullable:"true" list:"admin" update:"admin"` + // 过期时间 ExpiredAt time.Time `nullable:"true" list:"admin"` + // 状态 Status string `width:"12" charset:"ascii" nullable:"false" default:"unknown" list:"admin" create:"admin_optional" update:"admin"` } @@ -183,18 +189,19 @@ func (self *SReservedip) Release(ctx context.Context, userCred mcclient.TokenCre return err } -func (self *SReservedip) GetCustomizeColumns(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject) *jsonutils.JSONDict { - extra := self.SResourceBase.GetCustomizeColumns(ctx, userCred, query) +func (self *SReservedip) GetExtraDetails(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject, details bool) (api.ReservedipDetails, error) { + var err error + out := api.ReservedipDetails{} + out.ModelBaseDetails, err = self.SResourceBase.GetExtraDetails(ctx, userCred, query, details) + if err != nil { + return out, err + } net := self.GetNetwork() if net != nil { - extra.Add(jsonutils.NewString(net.Name), "network") + out.Network = net.Name } - if self.IsExpired() { - extra.Add(jsonutils.JSONTrue, "expired") - } else { - extra.Add(jsonutils.JSONFalse, "expired") - } - return extra + out.Expired = self.IsExpired() + return out, nil } // 预留IP地址列表 diff --git a/pkg/compute/models/routetables.go b/pkg/compute/models/routetables.go index ca5b2e12e1..0556992805 100644 --- a/pkg/compute/models/routetables.go +++ b/pkg/compute/models/routetables.go @@ -328,37 +328,29 @@ func (rt *SRouteTable) PerformDelRoutes(ctx context.Context, userCred mcclient.T return nil, nil } -func (rt *SRouteTable) getMoreDetails(extra *jsonutils.JSONDict) *jsonutils.JSONDict { - info := rt.getCloudProviderInfo() - extra.Update(jsonutils.Marshal(&info)) - return extra -} - -func (rt *SRouteTable) GetCustomizeColumns(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject) *jsonutils.JSONDict { - extra := rt.SVirtualResourceBase.GetCustomizeColumns(ctx, userCred, query) +func (rt *SRouteTable) GetExtraDetails(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject, details bool) (api.RouteTableDetails, error) { + var err error + out := api.RouteTableDetails{} + out.VirtualResourceDetails, err = rt.SVirtualResourceBase.GetExtraDetails(ctx, userCred, query, details) + if err != nil { + return out, err + } vpcM, err := VpcManager.FetchById(rt.VpcId) if err != nil { log.Errorf("route table %s(%s): fetch vpc (%s) error: %s", rt.Name, rt.Id, rt.VpcId, err) - return extra + return out, err } + out.Vpc = vpcM.GetName() cloudregionM, err := CloudregionManager.FetchById(rt.CloudregionId) if err != nil { log.Errorf("route table %s(%s): fetch cloud region (%s) error: %s", rt.Name, rt.Id, rt.CloudregionId, err) - return extra + return out, err } - extra.Set("vpc", jsonutils.NewString(vpcM.GetName())) - extra.Set("cloudregion", jsonutils.NewString(cloudregionM.GetName())) - - extra = rt.getMoreDetails(extra) - return extra -} - -func (rt *SRouteTable) GetExtraDetails(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject) (*jsonutils.JSONDict, error) { - extra := rt.GetCustomizeColumns(ctx, userCred, query) - extra = rt.getMoreDetails(extra) - return extra, nil + out.Cloudregion = cloudregionM.GetName() + out.CloudproviderInfo = rt.getCloudProviderInfo() + return out, nil } func (man *SRouteTableManager) SyncRouteTables(ctx context.Context, userCred mcclient.TokenCredential, vpc *SVpc, cloudRouteTables []cloudprovider.ICloudRouteTable) ([]SRouteTable, []cloudprovider.ICloudRouteTable, compare.SyncResult) { @@ -529,7 +521,7 @@ func (self *SRouteTable) getRegion() (*SCloudregion, error) { return vpc.GetRegion() } -func (self *SRouteTable) getCloudProviderInfo() SCloudProviderInfo { +func (self *SRouteTable) getCloudProviderInfo() api.CloudproviderInfo { region, _ := self.getRegion() provider := self.GetCloudprovider() return MakeCloudProviderInfo(region, nil, provider) diff --git a/pkg/compute/models/schedpolicies.go b/pkg/compute/models/schedpolicies.go index a1f2385ea4..dbb9affd76 100644 --- a/pkg/compute/models/schedpolicies.go +++ b/pkg/compute/models/schedpolicies.go @@ -137,26 +137,23 @@ func (self *SSchedpolicy) getSchedtag() *SSchedtag { return obj.(*SSchedtag) } -func (self *SSchedpolicy) getMoreColumns(extra *jsonutils.JSONDict) *jsonutils.JSONDict { +func (self *SSchedpolicy) getMoreColumns(out api.SchedpolicyDetails) api.SchedpolicyDetails { schedtag := self.getSchedtag() if schedtag != nil { - extra.Add(jsonutils.NewString(schedtag.GetName()), "schedtag") - extra.Add(jsonutils.NewString(schedtag.ResourceType), "resource_type") + out.Schedtag = schedtag.Name + out.ResourceType = schedtag.ResourceType } - return extra + return out } -func (self *SSchedpolicy) GetCustomizeColumns(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject) *jsonutils.JSONDict { - extra := self.SStandaloneResourceBase.GetCustomizeColumns(ctx, userCred, query) - return self.getMoreColumns(extra) -} - -func (self *SSchedpolicy) GetExtraDetails(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject) (*jsonutils.JSONDict, error) { - extra, err := self.SStandaloneResourceBase.GetExtraDetails(ctx, userCred, query) +func (self *SSchedpolicy) GetExtraDetails(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject, details bool) (api.SchedpolicyDetails, error) { + var err error + out := api.SchedpolicyDetails{} + out.StandaloneResourceDetails, err = self.SStandaloneResourceBase.GetExtraDetails(ctx, userCred, query, details) if err != nil { - return nil, err + return out, err } - return self.getMoreColumns(extra), nil + return self.getMoreColumns(out), nil } func (manager *SSchedpolicyManager) getAllEnabledPoliciesByResource(resType string) []SSchedpolicy { diff --git a/pkg/compute/models/schedtagjoint.go b/pkg/compute/models/schedtagjoint.go index 17112769f4..514979c8dc 100644 --- a/pkg/compute/models/schedtagjoint.go +++ b/pkg/compute/models/schedtagjoint.go @@ -147,17 +147,14 @@ func (joint *SSchedtagJointsBase) Slave() db.IStandaloneModel { return db.JointSlave(joint) } -func (joint *SSchedtagJointsBase) getCustomizeColumns(obj db.IJointModel, ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject) *jsonutils.JSONDict { - extra := joint.SJointResourceBase.GetCustomizeColumns(ctx, userCred, query) - return db.JointModelExtra(obj, extra) -} - -func (joint *SSchedtagJointsBase) getExtraDetails(obj db.IJointModel, ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject) (*jsonutils.JSONDict, error) { - extra, err := joint.SJointResourceBase.GetExtraDetails(ctx, userCred, query) +func (joint *SSchedtagJointsBase) getExtraDetails(obj db.IJointModel, ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject, details bool) (apis.JoinModelBaseDetails, error) { + var err error + out := apis.JoinModelBaseDetails{} + out.ModelBaseDetails, err = joint.SJointResourceBase.GetExtraDetails(ctx, userCred, query, details) if err != nil { - return nil, err + return out, err } - return db.JointModelExtra(obj, extra), nil + return out, nil } func (joint *SSchedtagJointsBase) Delete(ctx context.Context, userCred mcclient.TokenCredential) error { diff --git a/pkg/compute/models/schedtags.go b/pkg/compute/models/schedtags.go index 43ca73a767..0a0023db18 100644 --- a/pkg/compute/models/schedtags.go +++ b/pkg/compute/models/schedtags.go @@ -316,28 +316,32 @@ func (self *SSchedtag) getDynamicSchedtagCount() (int, error) { return DynamicschedtagManager.Query().Equals("schedtag_id", self.Id).CountWithError() } -func (self *SSchedtag) getMoreColumns(extra *jsonutils.JSONDict) *jsonutils.JSONDict { - extra = self.SScopedResourceBase.GetMoreColumns(extra) +func (self *SSchedtag) getMoreColumns(out api.SchedtagDetails) api.SchedtagDetails { + out.ProjectId = self.SScopedResourceBase.ProjectId cnt, _ := self.GetObjectCount() - extra.Add(jsonutils.NewInt(int64(cnt)), fmt.Sprintf("%s_count", self.GetJointManager().GetMasterManager().Keyword())) - cnt, _ = self.getDynamicSchedtagCount() - extra.Add(jsonutils.NewInt(int64(cnt)), "dynamic_schedtag_count") - cnt, _ = self.getSchedPoliciesCount() - extra.Add(jsonutils.NewInt(int64(cnt)), "schedpolicy_count") - return extra -} - -func (self *SSchedtag) GetCustomizeColumns(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject) *jsonutils.JSONDict { - extra := self.SStandaloneResourceBase.GetCustomizeColumns(ctx, userCred, query) - return self.getMoreColumns(extra) -} - -func (self *SSchedtag) GetExtraDetails(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject) (*jsonutils.JSONDict, error) { - extra, err := self.SStandaloneResourceBase.GetExtraDetails(ctx, userCred, query) - if err != nil { - return nil, err + keyword := self.GetJointManager().GetMasterManager().Keyword() + switch keyword { + case HostManager.Keyword(): + out.HostCount = cnt + case GuestManager.Keyword(): + out.ServerCount = cnt + default: + out.OtherCount = cnt + out.JoinModelKeyword = keyword } - return self.getMoreColumns(extra), nil + out.DynamicSchedtagCount, _ = self.getDynamicSchedtagCount() + out.SchedpolicyCount, _ = self.getSchedPoliciesCount() + return out +} + +func (self *SSchedtag) GetExtraDetails(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject, details bool) (api.SchedtagDetails, error) { + var err error + out := api.SchedtagDetails{} + out.StandaloneResourceDetails, err = self.SStandaloneResourceBase.GetExtraDetails(ctx, userCred, query, details) + if err != nil { + return out, err + } + return self.getMoreColumns(out), nil } /*func (self *SSchedtag) PostUpdate(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject, data jsonutils.JSONObject) { @@ -350,8 +354,8 @@ func (self *SSchedtag) GetShortDesc(ctx context.Context) *jsonutils.JSONDict { return desc } -func (self *SSchedtag) GetShortDescV2(ctx context.Context) *api.SchedtagShortDescDetails { - desc := &api.SchedtagShortDescDetails{} +func (self *SSchedtag) GetShortDescV2(ctx context.Context) api.SchedtagShortDescDetails { + desc := api.SchedtagShortDescDetails{} desc.StandaloneResourceShortDescDetail = self.SStandaloneResourceBase.GetShortDescV2(ctx) desc.Default = self.DefaultStrategy return desc @@ -489,7 +493,7 @@ func GetSchedtagsDetailsToResourceV2(obj IModelWithSchedtag, ctx context.Context if schedtags != nil && len(schedtags) > 0 { for i := 0; i < len(schedtags); i += 1 { desc := schedtags[i].GetShortDescV2(ctx) - info = append(info, *desc) + info = append(info, desc) } } return info diff --git a/pkg/compute/models/secgroupcache.go b/pkg/compute/models/secgroupcache.go index 86cdd687f1..3f72fb9d26 100644 --- a/pkg/compute/models/secgroupcache.go +++ b/pkg/compute/models/secgroupcache.go @@ -44,8 +44,10 @@ type SSecurityGroupCache struct { SCloudregionResourceBase SManagedResourceBase + // 安全组Id SecgroupId string `width:"128" charset:"ascii" list:"user" create:"required"` - VpcId string `width:"128" charset:"ascii" list:"user" create:"required"` + // 虚拟私有网络外部Id + VpcId string `width:"128" charset:"ascii" list:"user" create:"required"` } var SecurityGroupCacheManager *SSecurityGroupCacheManager @@ -113,21 +115,23 @@ func (self *SSecurityGroupCache) GetVpc() (*SVpc, error) { return vpc.(*SVpc), nil } -func (self *SSecurityGroupCache) GetCustomizeColumns(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject) *jsonutils.JSONDict { - extra := self.SStandaloneResourceBase.GetCustomizeColumns(ctx, userCred, query) - regionInfo := self.SCloudregionResourceBase.GetCustomizeColumns(ctx, userCred, query) - if regionInfo != nil { - extra.Update(regionInfo) - } - accountInfo := self.SManagedResourceBase.GetCustomizeColumns(ctx, userCred, query) - if accountInfo != nil { - extra.Update(accountInfo) +func (self *SSecurityGroupCache) GetExtraDetails(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject, isList bool) (api.SecurityGroupCacheDetails, error) { + var err error + out := api.SecurityGroupCacheDetails{} + out.StandaloneResourceDetails, err = self.SStandaloneResourceBase.GetExtraDetails(ctx, userCred, query, isList) + if err != nil { + return out, err } + provider := self.GetCloudprovider() + region := self.GetRegion() + + out.CloudproviderInfo = MakeCloudProviderInfo(region, nil, provider) + vpc, _ := self.GetVpc() if vpc != nil { - extra.Add(jsonutils.NewString(vpc.Name), "vpc") + out.Vpc = vpc.Name } - return extra + return out, nil } func (manager *SSecurityGroupCacheManager) GetSecgroupCache(ctx context.Context, userCred mcclient.TokenCredential, secgroupId, vpcId string, regionId string, providerId string) (*SSecurityGroupCache, error) { diff --git a/pkg/compute/models/secgroups.go b/pkg/compute/models/secgroups.go index 7011eabf38..1d498eaa4c 100644 --- a/pkg/compute/models/secgroups.go +++ b/pkg/compute/models/secgroups.go @@ -71,7 +71,7 @@ const ( type SSecurityGroup struct { db.SSharableVirtualResourceBase - IsDirty bool `nullable:"false" default:"false"` // Column(Boolean, nullable=False, default=False) + IsDirty bool `nullable:"false" default:"false"` } // 安全组列表 @@ -228,29 +228,21 @@ func (self *SSecurityGroup) getDesc() jsonutils.JSONObject { return desc } -func (self *SSecurityGroup) GetExtraDetails(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject) (*jsonutils.JSONDict, error) { - extra, err := self.SSharableVirtualResourceBase.GetExtraDetails(ctx, userCred, query) +func (self *SSecurityGroup) GetExtraDetails(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject, isList bool) (api.SecgroupDetails, error) { + var err error + out := api.SecgroupDetails{} + out.SharableVirtualResourceDetails, err = self.SSharableVirtualResourceBase.GetExtraDetails(ctx, userCred, query, isList) if err != nil { - return nil, err + return out, err } - extra.Add(jsonutils.NewInt(int64(len(self.GetGuests()))), "guest_cnt") - cnt, _ := self.GetSecgroupCacheCount() - extra.Add(jsonutils.NewInt(int64(cnt)), "cache_cnt") - extra.Add(jsonutils.NewString(self.getSecurityRuleString("")), "rules") - extra.Add(jsonutils.NewString(self.getSecurityRuleString("in")), "in_rules") - extra.Add(jsonutils.NewString(self.getSecurityRuleString("out")), "out_rules") - return extra, nil -} - -func (self *SSecurityGroup) GetCustomizeColumns(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject) *jsonutils.JSONDict { - extra := self.SSharableVirtualResourceBase.GetCustomizeColumns(ctx, userCred, query) - - extra.Add(jsonutils.NewInt(int64(len(self.GetGuests()))), "guest_cnt") - cnt, _ := self.GetSecgroupCacheCount() - extra.Add(jsonutils.NewInt(int64(cnt)), "cache_cnt") - extra.Add(jsonutils.NewTimeString(self.CreatedAt), "created_at") - extra.Add(jsonutils.NewString(self.Description), "description") - return extra + out.GuestCnt = len(self.GetGuests()) + out.CacheCnt, _ = self.GetSecgroupCacheCount() + if !isList { + out.Rules = self.getSecurityRuleString("") + out.InRules = self.getSecurityRuleString("in") + out.OutRules = self.getSecurityRuleString("out") + } + return out, nil } func (manager *SSecurityGroupManager) ValidateCreateData( diff --git a/pkg/compute/models/skus.go b/pkg/compute/models/skus.go index c0616fd7ab..c407e282d8 100644 --- a/pkg/compute/models/skus.go +++ b/pkg/compute/models/skus.go @@ -255,8 +255,13 @@ func (self *SServerSku) AllowGetDetails(ctx context.Context, userCred mcclient.T return true } -func (self *SServerSku) GetCustomizeColumns(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject) *jsonutils.JSONDict { - extra := self.SStatusStandaloneResourceBase.GetCustomizeColumns(ctx, userCred, query) +func (self *SServerSku) GetExtraDetails(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject, details bool) (api.ServerSkuDetails, error) { + var err error + out := api.ServerSkuDetails{} + out.StandaloneResourceDetails, err = self.SStatusStandaloneResourceBase.GetExtraDetails(ctx, userCred, query, details) + if err != nil { + return out, err + } // count var count int countKey := self.GetId() + ".total_guest_count" @@ -267,34 +272,23 @@ func (self *SServerSku) GetCustomizeColumns(ctx context.Context, userCred mcclie } else { count = v.(int) } + out.TotalGuestCount = count - extra.Add(jsonutils.NewInt(int64(count)), "total_guest_count") - - zoneInfo := self.SZoneResourceBase.GetCustomizeColumns(ctx, userCred, query) - if zoneInfo != nil { - extra.Update(zoneInfo) + zone := self.GetZone() + if zone != nil { + out.Zone = zone.Name + out.ZoneExtId = fetchExternalId(zone.ExternalId) } - // region - name, extId, err := getNameAndExtId(self.CloudregionId, CloudregionManager) - if err == nil { - extra.Add(jsonutils.NewString(name), "region") - extra.Add(jsonutils.NewString(extId), "region_ext_id") - } else { - log.Debugf("GetCustomizeColumns %s", err) + region, _ := self.GetRegion() + if region != nil { + out.Region = region.Name + out.RegionId = region.Id + out.RegionExternalId = region.ExternalId + out.RegionExtId = fetchExternalId(region.ExternalId) } - return extra -} - -func (self *SServerSku) GetExtraDetails(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject) (*jsonutils.JSONDict, error) { - extra, err := self.SStatusStandaloneResourceBase.GetExtraDetails(ctx, userCred, query) - if err != nil { - return nil, err - } - count, _ := skuRelatedGuestCount(self) - extra.Add(jsonutils.NewInt(int64(count)), "total_guest_count") - return extra, nil + return out, nil } func (manager *SServerSkuManager) AllowCreateItem(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject, data jsonutils.JSONObject) bool { diff --git a/pkg/compute/models/snapshotpolicy.go b/pkg/compute/models/snapshotpolicy.go index 5fb3b0192c..16f2de0731 100644 --- a/pkg/compute/models/snapshotpolicy.go +++ b/pkg/compute/models/snapshotpolicy.go @@ -313,37 +313,25 @@ func (sp *SSnapshotPolicy) StartSnapshotPolicyDeleteTask(ctx context.Context, us return nil } -func (sp *SSnapshotPolicy) GetCustomizeColumns(ctx context.Context, userCred mcclient.TokenCredential, - query jsonutils.JSONObject) *jsonutils.JSONDict { - extraDict := sp.SVirtualResourceBase.GetCustomizeColumns(ctx, userCred, query) - ret, _ := sp.getMoreDetails(ctx, userCred, extraDict) - return ret -} - func (sp *SSnapshotPolicy) GetExtraDetails(ctx context.Context, userCred mcclient.TokenCredential, - query jsonutils.JSONObject) (*jsonutils.JSONDict, error) { - extraDict, err := sp.SVirtualResourceBase.GetExtraDetails(ctx, userCred, query) + query jsonutils.JSONObject, details bool) (api.SnapshotPolicyDetails, error) { + var err error + out := api.SnapshotPolicyDetails{} + out.VirtualResourceDetails, err = sp.SVirtualResourceBase.GetExtraDetails(ctx, userCred, query, details) if err != nil { - return nil, err + return out, err } - return sp.getMoreDetails(ctx, userCred, extraDict) + return sp.getMoreDetails(ctx, userCred, out) } func (sp *SSnapshotPolicy) getMoreDetails(ctx context.Context, userCred mcclient.TokenCredential, - extraDict *jsonutils.JSONDict) (*jsonutils.JSONDict, error) { + out api.SnapshotPolicyDetails) (api.SnapshotPolicyDetails, error) { - ret := extraDict - // more - weekdays := SnapshotPolicyManager.RepeatWeekdaysToIntArray(sp.RepeatWeekdays) - timePoints := SnapshotPolicyManager.TimePointsToIntArray(sp.TimePoints) - ret.Add(jsonutils.Marshal(weekdays), "repeat_weekdays") - ret.Add(jsonutils.Marshal(timePoints), "time_points") - count, err := SnapshotPolicyDiskManager.FetchDiskCountBySPID(sp.Id) - if err != nil { - return ret, err - } - ret.Add(jsonutils.NewInt(int64(count)), "binding_disk_count") - return ret, nil + var err error + out.RepeatWeekdays = SnapshotPolicyManager.RepeatWeekdaysToIntArray(sp.RepeatWeekdays) + out.TimePoints = SnapshotPolicyManager.TimePointsToIntArray(sp.TimePoints) + out.BindingDiskCount, err = SnapshotPolicyDiskManager.FetchDiskCountBySPID(sp.Id) + return out, err } // ==================================================== sync =========================================================== diff --git a/pkg/compute/models/snapshotpolicycache.go b/pkg/compute/models/snapshotpolicycache.go index 79f3834753..7c532bd0b5 100644 --- a/pkg/compute/models/snapshotpolicycache.go +++ b/pkg/compute/models/snapshotpolicycache.go @@ -111,18 +111,18 @@ func (spc *SSnapshotPolicyCache) GetSnapshotPolicy() (*SSnapshotPolicy, error) { return model.(*SSnapshotPolicy), nil } -func (spc *SSnapshotPolicyCache) GetCustomizeColumns(ctx context.Context, userCred mcclient.TokenCredential, - query jsonutils.JSONObject) *jsonutils.JSONDict { - extra := spc.SStandaloneResourceBase.GetCustomizeColumns(ctx, userCred, query) - regionInfo := spc.SCloudregionResourceBase.GetCustomizeColumns(ctx, userCred, query) - if regionInfo != nil { - extra.Update(regionInfo) +func (spc *SSnapshotPolicyCache) GetExtraDetails(ctx context.Context, userCred mcclient.TokenCredential, + query jsonutils.JSONObject, isList bool) (api.SnapshotPolicyCacheDetails, error) { + var err error + out := api.SnapshotPolicyCacheDetails{} + out.StandaloneResourceDetails, err = spc.SStandaloneResourceBase.GetExtraDetails(ctx, userCred, query, isList) + if err != nil { + return out, err } - accountInfo := spc.SManagedResourceBase.GetCustomizeColumns(ctx, userCred, query) - if accountInfo != nil { - extra.Update(accountInfo) - } - return extra + provider := spc.GetCloudprovider() + region := spc.GetRegion() + out.CloudproviderInfo = MakeCloudProviderInfo(region, nil, provider) + return out, nil } // =============================================== detach and delete =================================================== diff --git a/pkg/compute/models/snapshotpolicydisks.go b/pkg/compute/models/snapshotpolicydisks.go index 7a08413489..291a3b1d58 100644 --- a/pkg/compute/models/snapshotpolicydisks.go +++ b/pkg/compute/models/snapshotpolicydisks.go @@ -95,32 +95,20 @@ func (sd *SSnapshotPolicyDisk) SetStatus(userCred mcclient.TokenCredential, stat return nil } -func (self *SSnapshotPolicyDisk) GetCustomizeColumns(ctx context.Context, userCred mcclient.TokenCredential, - query jsonutils.JSONObject) *jsonutils.JSONDict { - - ret, _ := self.getMoreDetails(ctx, userCred, query) - return ret -} - -func (self *SSnapshotPolicyDisk) GetExtraDetails(ctx context.Context, userCred mcclient.TokenCredential, - query jsonutils.JSONObject) (*jsonutils.JSONDict, error) { - - return self.getMoreDetails(ctx, userCred, query) -} - -func (self *SSnapshotPolicyDisk) getMoreDetails(ctx context.Context, userCred mcclient.TokenCredential, - query jsonutils.JSONObject) (*jsonutils.JSONDict, error) { - - ret := jsonutils.NewDict() - disk := DiskManager.FetchDiskById(self.DiskId) - extraDict, err := disk.GetExtraDetails(ctx, userCred, query) +func (self *SSnapshotPolicyDisk) GetExtraDetails(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject, details bool) (compute.SnapshotPolicyDiskDetails, error) { + var err error + out := compute.SnapshotPolicyDiskDetails{} + out.ModelBaseDetails, err = self.SVirtualJointResourceBase.GetExtraDetails(ctx, userCred, query, details) if err != nil { - return ret, nil + return out, err } - dict := jsonutils.Marshal(disk).(*jsonutils.JSONDict) - dict.Update(extraDict) - ret.Add(dict, "disk") - return ret, nil + _, out.Snapshotpolicy = db.JointModelExtra(self) + disk := DiskManager.FetchDiskById(self.DiskId) + out.Disk, err = disk.GetExtraDetails(ctx, userCred, query, details) + if err != nil { + return out, nil + } + return out, nil } // ==================================================== fetch ========================================================== diff --git a/pkg/compute/models/snapshots.go b/pkg/compute/models/snapshots.go index 8396184dcc..a42233720d 100644 --- a/pkg/compute/models/snapshots.go +++ b/pkg/compute/models/snapshots.go @@ -50,21 +50,25 @@ type SSnapshot struct { SManagedResourceBase + // 磁盘Id DiskId string `width:"36" charset:"ascii" nullable:"true" create:"required" list:"user" index:"true"` // Only onecloud has StorageId - StorageId string `width:"36" charset:"ascii" nullable:"true" list:"admin" create:"optional"` - CreatedBy string `width:"36" charset:"ascii" nullable:"false" default:"manual" list:"user" create:"optional"` - Location string `charset:"ascii" nullable:"true" list:"admin" create:"optional"` - Size int `nullable:"false" list:"user" create:"required"` // MB + StorageId string `width:"36" charset:"ascii" nullable:"true" list:"admin" create:"optional"` + CreatedBy string `width:"36" charset:"ascii" nullable:"false" default:"manual" list:"user" create:"optional"` + Location string `charset:"ascii" nullable:"true" list:"admin" create:"optional"` + // 快照大小,单位Mb + Size int `nullable:"false" list:"user" create:"required"` OutOfChain bool `nullable:"false" default:"false" list:"admin" create:"optional"` FakeDeleted bool `nullable:"false" default:"false"` DiskType string `width:"32" charset:"ascii" nullable:"true" list:"user" create:"optional"` - OsType string `width:"32" charset:"ascii" nullable:"true" list:"user" create:"optional"` + // 操作系统类型 + OsType string `width:"32" charset:"ascii" nullable:"true" list:"user" create:"optional"` // create disk from snapshot, snapshot as disk backing file RefCount int `nullable:"false" default:"0" list:"user"` + // 区域Id CloudregionId string `width:"36" charset:"ascii" nullable:"true" list:"user" create:"optional"` BackingDiskId string `width:"36" charset:"ascii" nullable:"true" default:""` ExpiredAt time.Time `nullable:"true" list:"user" create:"optional"` @@ -138,42 +142,38 @@ func (manager *SSnapshotManager) ListItemFilter(ctx context.Context, q *sqlchemy return q, nil } -func (self *SSnapshot) GetCustomizeColumns(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject) *jsonutils.JSONDict { - extra := self.SVirtualResourceBase.GetCustomizeColumns(ctx, userCred, query) - return self.getMoreDetails(extra) -} - -func (self *SSnapshot) GetExtraDetails(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject) (*jsonutils.JSONDict, error) { - extra, err := self.SVirtualResourceBase.GetExtraDetails(ctx, userCred, query) +func (self *SSnapshot) GetExtraDetails(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject, details bool) (api.SnapshotDetails, error) { + var err error + out := api.SnapshotDetails{} + out.VirtualResourceDetails, err = self.SVirtualResourceBase.GetExtraDetails(ctx, userCred, query, details) if err != nil { - return nil, err + return out, err } - return self.getMoreDetails(extra), nil + return self.getMoreDetails(out), nil } -func (self *SSnapshot) getMoreDetails(extra *jsonutils.JSONDict) *jsonutils.JSONDict { +func (self *SSnapshot) getMoreDetails(out api.SnapshotDetails) api.SnapshotDetails { if IStorage, _ := StorageManager.FetchById(self.StorageId); IStorage != nil { storage := IStorage.(*SStorage) - extra.Add(jsonutils.NewString(storage.StorageType), "storage_type") + out.StorageType = storage.StorageType } disk, _ := self.GetDisk() if disk != nil { - extra.Add(jsonutils.NewString(disk.Status), "disk_status") + out.DiskStatus = disk.Status + out.DiskName = disk.Name guests := disk.GetGuests() if len(guests) == 1 { - extra.Add(jsonutils.NewString(guests[0].Name), "guest") - extra.Add(jsonutils.NewString(guests[0].Id), "guest_id") - extra.Add(jsonutils.NewString(guests[0].Status), "guest_status") + out.Guest = guests[0].Name + out.GuestId = guests[0].Id + out.GuestStatus = guests[0].Status } - extra.Add(jsonutils.NewString(disk.Name), "disk_name") } if t, _ := InstanceSnapshotJointManager.IsSubSnapshot(self.Id); t { - extra.Set("is_sub_snapshot", jsonutils.JSONTrue) + out.IsSubSnapshot = true } - info := self.getCloudProviderInfo() - extra.Update(jsonutils.Marshal(&info)) - return extra + out.CloudproviderInfo = self.getCloudProviderInfo() + return out } func (self *SSnapshot) GetShortDesc(ctx context.Context) *jsonutils.JSONDict { @@ -849,7 +849,7 @@ func (self *SSnapshot) PerformPurge(ctx context.Context, userCred mcclient.Token return nil, err } -func (self *SSnapshot) getCloudProviderInfo() SCloudProviderInfo { +func (self *SSnapshot) getCloudProviderInfo() api.CloudproviderInfo { region := self.GetRegion() provider := self.GetCloudprovider() return MakeCloudProviderInfo(region, nil, provider) diff --git a/pkg/compute/models/storagecachedimages.go b/pkg/compute/models/storagecachedimages.go index ef74e5106d..f82a07f6c7 100644 --- a/pkg/compute/models/storagecachedimages.go +++ b/pkg/compute/models/storagecachedimages.go @@ -62,15 +62,21 @@ func init() { type SStoragecachedimage struct { db.SJointResourceBase + // 存储缓存Id StoragecacheId string `width:"36" charset:"ascii" nullable:"false" list:"admin" create:"admin_required"` - CachedimageId string `width:"36" charset:"ascii" nullable:"false" list:"admin" create:"admin_required"` + // 镜像缓存Id + CachedimageId string `width:"36" charset:"ascii" nullable:"false" list:"admin" create:"admin_required"` + // 外部Id ExternalId string `width:"256" charset:"utf8" nullable:"false" get:"admin"` - Status string `width:"32" charset:"ascii" nullable:"false" default:"init" list:"admin" update:"admin" create:"admin_required"` // = Column(VARCHAR(32, charset='ascii'), nullable=False, - Path string `width:"256" charset:"utf8" nullable:"true" list:"admin" update:"admin" create:"admin_optional"` // = Column(VARCHAR(256, charset='utf8'), nullable=True) - LastDownload time.Time `get:"admin"` // = Column(DateTime) - DownloadRefcnt int `get:"admin"` // = Column(Integer) + // 镜像状态 + Status string `width:"32" charset:"ascii" nullable:"false" default:"init" list:"admin" update:"admin" create:"admin_required"` + Path string `width:"256" charset:"utf8" nullable:"true" list:"admin" update:"admin" create:"admin_optional"` + // 上次下载时间 + LastDownload time.Time `get:"admin"` + // 下载引用次数 + DownloadRefcnt int `get:"admin"` } func (manager *SStoragecachedimageManager) GetMasterFieldName() string { @@ -139,19 +145,15 @@ func (self *SStoragecachedimage) GetHost() (*SHost, error) { return sc.GetHost() } -func (self *SStoragecachedimage) GetCustomizeColumns(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject) *jsonutils.JSONDict { - extra := self.SJointResourceBase.GetCustomizeColumns(ctx, userCred, query) - extra = db.JointModelExtra(self, extra) - return self.getExtraDetails(ctx, extra) -} - -func (self *SStoragecachedimage) GetExtraDetails(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject) (*jsonutils.JSONDict, error) { - extra, err := self.SJointResourceBase.GetExtraDetails(ctx, userCred, query) +func (self *SStoragecachedimage) GetExtraDetails(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject, details bool) (api.StoragecachedimageDetails, error) { + var err error + out := api.StoragecachedimageDetails{} + out.ModelBaseDetails, err = self.SJointResourceBase.GetExtraDetails(ctx, userCred, query, details) if err != nil { - return nil, err + return out, err } - extra = db.JointModelExtra(self, extra) - return self.getExtraDetails(ctx, extra), nil + out.Storagecache, out.Cachedimage = db.JointModelExtra(self) + return self.getExtraDetails(ctx, out), nil } func (manager *SStoragecachedimageManager) AllowListDescendent(ctx context.Context, userCred mcclient.TokenCredential, model db.IStandaloneModel, query jsonutils.JSONObject) bool { @@ -174,23 +176,22 @@ func (self *SStoragecachedimage) GetStoragecache() (*SStoragecache, error) { return cache.(*SStoragecache), nil } -func (self *SStoragecachedimage) getExtraDetails(ctx context.Context, extra *jsonutils.JSONDict) *jsonutils.JSONDict { +func (self *SStoragecachedimage) getExtraDetails(ctx context.Context, out api.StoragecachedimageDetails) api.StoragecachedimageDetails { storagecache, _ := self.GetStoragecache() if storagecache != nil { - extra.Add(jsonutils.NewStringArray(storagecache.getStorageNames()), "storages") + out.Storages = storagecache.getStorageNames() host, _ := storagecache.GetHost() if host != nil { - extra.Add(host.GetShortDesc(ctx), "host") + out.Host = host.GetShortDesc(ctx) } } cachedImage := self.GetCachedimage() if cachedImage != nil { - extra.Add(jsonutils.NewString(cachedImage.GetName()), "image") - extra.Add(jsonutils.NewInt(cachedImage.Size), "size") + out.Image = cachedImage.GetName() + out.Size = cachedImage.Size } - cnt, _ := self.getReferenceCount() - extra.Add(jsonutils.NewInt(int64(cnt)), "reference") - return extra + out.Reference, _ = self.getReferenceCount() + return out } func (self *SStoragecachedimage) getCdromReferenceCount() (int, error) { diff --git a/pkg/compute/models/storagecaches.go b/pkg/compute/models/storagecaches.go index 42b4541701..e29495fd28 100644 --- a/pkg/compute/models/storagecaches.go +++ b/pkg/compute/models/storagecaches.go @@ -61,6 +61,7 @@ type SStoragecache struct { SManagedResourceBase + // 镜像存储地址 Path string `width:"256" charset:"utf8" nullable:"true" list:"user" update:"admin" create:"admin_optional"` // = Column(VARCHAR(256, charset='utf8'), nullable=True) } @@ -253,19 +254,14 @@ func (self *SStoragecache) syncWithCloudStoragecache(ctx context.Context, userCr return nil } -func (self *SStoragecache) GetExtraDetails(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject) (*jsonutils.JSONDict, error) { - extra, err := self.SStandaloneResourceBase.GetExtraDetails(ctx, userCred, query) +func (self *SStoragecache) GetExtraDetails(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject, details bool) (api.StoragecacheDetails, error) { + var err error + out := api.StoragecacheDetails{} + out.StandaloneResourceDetails, err = self.SStandaloneResourceBase.GetExtraDetails(ctx, userCred, query, details) if err != nil { - return nil, err + return out, err } - extra = self.getMoreDetails(ctx, extra) - return extra, nil -} - -func (self *SStoragecache) GetCustomizeColumns(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject) *jsonutils.JSONDict { - extra := self.SStandaloneResourceBase.GetCustomizeColumns(ctx, userCred, query) - extra = self.getMoreDetails(ctx, extra) - return extra + return self.getMoreDetails(ctx, out), nil } func (self *SStoragecache) getCachedImageList(excludeIds []string, imageType string, status []string) []SCachedimage { @@ -329,16 +325,16 @@ func (self *SStoragecache) getCachedImageSize() int64 { return size } -func (self *SStoragecache) getMoreDetails(ctx context.Context, extra *jsonutils.JSONDict) *jsonutils.JSONDict { - extra.Add(jsonutils.NewStringArray(self.getStorageNames()), "storages") - extra.Add(jsonutils.NewInt(self.getCachedImageSize()), "size") - extra.Add(jsonutils.NewInt(int64(self.getCachedImageCount())), "count") +func (self *SStoragecache) getMoreDetails(ctx context.Context, out api.StoragecacheDetails) api.StoragecacheDetails { + out.Storages = self.getStorageNames() + out.Size = self.getCachedImageSize() + out.Count = self.getCachedImageCount() host, _ := self.GetHost() if host != nil { - extra.Add(host.GetShortDesc(ctx), "host") + out.Host = host.GetShortDesc(ctx) } - return extra + return out } func (self *SStoragecache) StartImageCacheTask(ctx context.Context, userCred mcclient.TokenCredential, imageId string, format string, isForce bool, parentTaskId string) error { diff --git a/pkg/compute/models/storages.go b/pkg/compute/models/storages.go index 604323a29c..ac2c2b248f 100644 --- a/pkg/compute/models/storages.go +++ b/pkg/compute/models/storages.go @@ -64,21 +64,35 @@ type SStorage struct { SManagedResourceBase - Capacity int64 `nullable:"false" list:"admin" update:"admin" create:"admin_required"` // Column(Integer, nullable=False) # capacity of disk in MB - Reserved int64 `nullable:"true" default:"0" list:"admin" update:"admin"` // Column(Integer, nullable=True, default=0) - StorageType string `width:"32" charset:"ascii" nullable:"false" list:"user" create:"admin_required"` // Column(VARCHAR(32, charset='ascii'), nullable=False) - MediumType string `width:"32" charset:"ascii" nullable:"false" list:"user" update:"admin" create:"admin_required"` // Column(VARCHAR(32, charset='ascii'), nullable=False) - Cmtbound float32 `nullable:"true" default:"1" list:"admin" update:"admin"` // Column(Float, nullable=True) - StorageConf jsonutils.JSONObject `nullable:"true" get:"admin" update:"admin"` // = Column(JSONEncodedDict, nullable=True) + // 容量大小,单位Mb + Capacity int64 `nullable:"false" list:"admin" update:"admin" create:"admin_required"` + // 预留容量大小 + Reserved int64 `nullable:"true" default:"0" list:"admin" update:"admin"` + // 存储类型 + // example: local + StorageType string `width:"32" charset:"ascii" nullable:"false" list:"user" create:"admin_required"` + // 介质类型 + // example: ssd + MediumType string `width:"32" charset:"ascii" nullable:"false" list:"user" update:"admin" create:"admin_required"` + // 超售比 + Cmtbound float32 `nullable:"true" default:"1" list:"admin" update:"admin"` + // 存储配置信息 + StorageConf jsonutils.JSONObject `nullable:"true" get:"admin" update:"admin"` + // 可用区Id ZoneId string `width:"36" charset:"ascii" nullable:"false" list:"user" create:"admin_required"` + // 存储缓存Id StoragecacheId string `width:"36" charset:"ascii" nullable:"true" list:"admin" get:"admin" update:"admin" create:"optional"` + // 是否启用 Enabled tristate.TriState `nullable:"false" default:"true" list:"user" create:"optional"` - Status string `width:"36" charset:"ascii" nullable:"false" default:"offline" update:"admin" list:"user" create:"optional"` + // 状态 + Status string `width:"36" charset:"ascii" nullable:"false" default:"offline" update:"admin" list:"user" create:"optional"` // indicating whether system disk can be allocated in this storage + // 是否可以用作系统盘存储 + // example: true IsSysDiskStore tristate.TriState `nullable:"false" default:"true" list:"user" create:"optional" update:"admin"` } @@ -385,30 +399,30 @@ func (self *SStorage) getStorageCapacity() SStorageCapacity { return capa } -func (self *SStorage) getMoreDetails(ctx context.Context, extra *jsonutils.JSONDict) *jsonutils.JSONDict { +func (self *SStorage) getMoreDetails(ctx context.Context, out api.StorageDetails) api.StorageDetails { capa := self.getStorageCapacity() - extra.Update(capa.ToJson()) + out.Capacity = capa.Capacity + out.Used = capa.Used + out.Wasted = capa.Wasted + out.VCapacity = capa.VCapacity + out.CommitRate = capa.GetCommitRate() + out.FreeCapacity = capa.GetFree() - extra.Add(jsonutils.NewFloat(float64(self.GetOvercommitBound())), "commit_bound") + out.CommitBound = self.GetOvercommitBound() + out.CloudproviderInfo = self.getCloudProviderInfo() + out.Schedtags = GetSchedtagsDetailsToResourceV2(self, ctx) - info := self.getCloudProviderInfo() - extra.Update(jsonutils.Marshal(&info)) - extra = GetSchedtagsDetailsToResource(self, ctx, extra) - - return extra + return out } -func (self *SStorage) GetCustomizeColumns(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject) *jsonutils.JSONDict { - extra := self.SStandaloneResourceBase.GetCustomizeColumns(ctx, userCred, query) - return self.getMoreDetails(ctx, extra) -} - -func (self *SStorage) GetExtraDetails(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject) (*jsonutils.JSONDict, error) { - extra, err := self.SStandaloneResourceBase.GetExtraDetails(ctx, userCred, query) +func (self *SStorage) GetExtraDetails(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject, details bool) (api.StorageDetails, error) { + var err error + out := api.StorageDetails{} + out.StandaloneResourceDetails, err = self.SStandaloneResourceBase.GetExtraDetails(ctx, userCred, query, details) if err != nil { - return nil, err + return out, err } - return self.getMoreDetails(ctx, extra), nil + return self.getMoreDetails(ctx, out), nil } func (self *SStorage) GetUsedCapacity(isReady tristate.TriState) int64 { @@ -1196,7 +1210,7 @@ func (self *SStorage) ClearSchedDescCache() error { return nil } -func (self *SStorage) getCloudProviderInfo() SCloudProviderInfo { +func (self *SStorage) getCloudProviderInfo() api.CloudproviderInfo { var region *SCloudregion zone := self.getZone() if zone != nil { diff --git a/pkg/compute/models/storageschedtags.go b/pkg/compute/models/storageschedtags.go index 70608a5518..b73ec54642 100644 --- a/pkg/compute/models/storageschedtags.go +++ b/pkg/compute/models/storageschedtags.go @@ -19,6 +19,7 @@ import ( "yunion.io/x/jsonutils" + api "yunion.io/x/onecloud/pkg/apis/compute" "yunion.io/x/onecloud/pkg/cloudcommon/db" "yunion.io/x/onecloud/pkg/mcclient" ) @@ -69,12 +70,12 @@ func (joint *SStorageschedtag) Master() db.IStandaloneModel { return joint.SSchedtagJointsBase.master(joint) } -func (joint *SStorageschedtag) GetCustomizeColumns(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject) *jsonutils.JSONDict { - return joint.SSchedtagJointsBase.getCustomizeColumns(joint, ctx, userCred, query) -} - -func (joint *SStorageschedtag) GetExtraDetails(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject) (*jsonutils.JSONDict, error) { - return joint.SSchedtagJointsBase.getExtraDetails(joint, ctx, userCred, query) +func (joint *SStorageschedtag) GetExtraDetails(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject, details bool) (api.StorageschedtagDetails, error) { + var err error + out := api.StorageschedtagDetails{} + out.JoinModelBaseDetails, err = joint.SSchedtagJointsBase.getExtraDetails(joint, ctx, userCred, query, details) + out.Storage, out.Schedtag = db.JointModelExtra(joint) + return out, err } func (joint *SStorageschedtag) Delete(ctx context.Context, userCred mcclient.TokenCredential) error { diff --git a/pkg/compute/models/vpcs.go b/pkg/compute/models/vpcs.go index b1dec2e8ea..189cdefa7c 100644 --- a/pkg/compute/models/vpcs.go +++ b/pkg/compute/models/vpcs.go @@ -61,12 +61,18 @@ type SVpc struct { SManagedResourceBase + // 是否是默认VPC + // example: true IsDefault bool `default:"false" list:"admin" create:"admin_optional"` + // CIDR地址段 + // example: 192.168.222.0/24 CidrBlock string `charset:"ascii" nullable:"true" list:"admin" create:"admin_required"` + // 区域Id CloudregionId string `width:"36" charset:"ascii" nullable:"false" list:"admin" create:"admin_required"` - GlobalvpcId string `width:"36" charset:"ascii" list:"user"` + // 全局VPC Id + GlobalvpcId string `width:"36" charset:"ascii" list:"user"` } func (manager *SVpcManager) GetContextManagers() [][]db.IModelManager { @@ -236,38 +242,16 @@ func (self *SVpc) GetRouteTableCount() (int, error) { return self.GetRouteTableQuery().CountWithError() } -func (self *SVpc) getMoreDetails(extra *jsonutils.JSONDict) *jsonutils.JSONDict { - cnt, _ := self.GetWireCount() - extra.Add(jsonutils.NewInt(int64(cnt)), "wire_count") - cnt, _ = self.GetNetworkCount() - extra.Add(jsonutils.NewInt(int64(cnt)), "network_count") - cnt, _ = self.GetRouteTableCount() - extra.Add(jsonutils.NewInt(int64(cnt)), "routetable_count") - cnt, _ = self.GetNatgatewayCount() - extra.Add(jsonutils.NewInt(int64(cnt)), "natgateway_count") - /* region, err := self.GetRegion() - if err != nil { - log.Errorf("failed getting region for vpc %s(%s)", self.Name, self.Id) - return extra - } - extra.Add(jsonutils.NewString(region.GetName()), "region") - if len(region.GetExternalId()) > 0 { - extra.Add(jsonutils.NewString(region.GetExternalId()), "region_external_id") - }*/ - - info := self.getCloudProviderInfo() - extra.Update(jsonutils.Marshal(&info)) - - return extra +func (self *SVpc) getMoreDetails(out api.VpcDetails) api.VpcDetails { + out.WireCount, _ = self.GetWireCount() + out.NetworkCount, _ = self.GetNetworkCount() + out.RoutetableCount, _ = self.GetRouteTableCount() + out.NatgatewayCount, _ = self.GetNatgatewayCount() + out.CloudproviderInfo = self.getCloudProviderInfo() + return out } -func (self *SVpc) getCloudProviderInfoV2() api.CloudproviderDetails { - region, _ := self.GetRegion() - provider := self.GetCloudprovider() - return MakeCloudProviderInfoV2(region, nil, provider) -} - -func (self *SVpc) getCloudProviderInfo() SCloudProviderInfo { +func (self *SVpc) getCloudProviderInfo() api.CloudproviderInfo { region, _ := self.GetRegion() provider := self.GetCloudprovider() return MakeCloudProviderInfo(region, nil, provider) @@ -301,17 +285,14 @@ func (self *SVpc) getZoneByExternalId(externalId string) (*SZone, error) { return nil, fmt.Errorf("found %d duplicate zones by externalId %s in cloudregion %s(%s)", len(zones), externalId, region.Name, region.Id) } -func (self *SVpc) GetCustomizeColumns(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject) *jsonutils.JSONDict { - extra := self.SEnabledStatusStandaloneResourceBase.GetCustomizeColumns(ctx, userCred, query) - return self.getMoreDetails(extra) -} - -func (self *SVpc) GetExtraDetails(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject) (*jsonutils.JSONDict, error) { - extra, err := self.SEnabledStatusStandaloneResourceBase.GetExtraDetails(ctx, userCred, query) +func (self *SVpc) GetExtraDetails(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject, details bool) (api.VpcDetails, error) { + var err error + out := api.VpcDetails{} + out.StandaloneResourceDetails, err = self.SEnabledStatusStandaloneResourceBase.GetExtraDetails(ctx, userCred, query, details) if err != nil { - return nil, err + return out, err } - return self.getMoreDetails(extra), nil + return self.getMoreDetails(out), nil } func (manager *SVpcManager) getVpcsByRegion(region *SCloudregion, provider *SCloudprovider) ([]SVpc, error) { diff --git a/pkg/compute/models/wires.go b/pkg/compute/models/wires.go index df4d7eb41c..90e5aa9bb6 100644 --- a/pkg/compute/models/wires.go +++ b/pkg/compute/models/wires.go @@ -61,11 +61,17 @@ type SWire struct { db.SStandaloneResourceBase db.SExternalizedResourceBase - Bandwidth int `list:"admin" update:"admin" nullable:"false" create:"admin_required"` // = Column(Integer, nullable=False) # bandwidth of network in Mbps - Mtu int `list:"admin" update:"admin" nullable:"false" create:"admin_optional" default:"1500"` - ScheduleRank int `list:"admin" update:"admin"` // = Column(Integer, default=0, nullable=True) - ZoneId string `width:"36" charset:"ascii" nullable:"true" list:"admin" create:"admin_required"` // = Column(VARCHAR(36, charset='ascii'), nullable=False) - VpcId string `wdith:"36" charset:"ascii" nullable:"false" list:"admin" create:"admin_required"` + // 带宽大小, 单位Mbps + // example: 1000 + Bandwidth int `list:"admin" update:"admin" nullable:"false" create:"admin_required"` + // MTU + // example: MTU + Mtu int `list:"admin" update:"admin" nullable:"false" create:"admin_optional" default:"1500"` + ScheduleRank int `list:"admin" update:"admin"` + // 可用区Id + ZoneId string `width:"36" charset:"ascii" nullable:"true" list:"admin" create:"admin_required"` + // VPC Id + VpcId string `wdith:"36" charset:"ascii" nullable:"false" list:"admin" create:"admin_required"` } func (manager *SWireManager) GetContextManagers() [][]db.IModelManager { @@ -906,36 +912,29 @@ func (self *SWire) getRegion() *SCloudregion { return nil } -func (self *SWire) GetCustomizeColumns(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject) *jsonutils.JSONDict { - extra := self.SStandaloneResourceBase.GetCustomizeColumns(ctx, userCred, query) - return self.getMoreDetails(extra) -} - -func (self *SWire) GetExtraDetails(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject) (*jsonutils.JSONDict, error) { - extra, err := self.SStandaloneResourceBase.GetExtraDetails(ctx, userCred, query) +func (self *SWire) GetExtraDetails(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject, isList bool) (api.WireDetails, error) { + var err error + out := api.WireDetails{} + out.StandaloneResourceDetails, err = self.SStandaloneResourceBase.GetExtraDetails(ctx, userCred, query, isList) if err != nil { - return nil, err + return out, err } - return self.getMoreDetails(extra), nil + return self.getMoreDetails(out), nil } -func (self *SWire) getMoreDetails(extra *jsonutils.JSONDict) *jsonutils.JSONDict { - cnt, _ := self.NetworkCount() +func (self *SWire) getMoreDetails(out api.WireDetails) api.WireDetails { + out.Networks, _ = self.NetworkCount() zone := self.GetZone() if zone != nil { - extra.Add(jsonutils.NewString(string(zone.Name)), "zone") + out.Zone = zone.Name } - extra.Add(jsonutils.NewInt(int64(cnt)), "networks") vpc := self.getVpc() if vpc != nil { - extra.Add(jsonutils.NewString(vpc.GetName()), "vpc") - if len(vpc.GetExternalId()) > 0 { - extra.Add(jsonutils.NewString(vpc.GetExternalId()), "vpc_ext_id") - } - info := vpc.getCloudProviderInfo() - extra.Update(jsonutils.Marshal(&info)) + out.Vpc = vpc.Name + out.VpcExtId = vpc.GetExternalId() + out.CloudproviderInfo = vpc.getCloudProviderInfo() } - return extra + return out } func (man *SWireManager) removeWiresByVpc(ctx context.Context, userCred mcclient.TokenCredential, vpc *SVpc) error { diff --git a/pkg/compute/models/zoneresource.go b/pkg/compute/models/zoneresource.go index 499b925594..0178965bc8 100644 --- a/pkg/compute/models/zoneresource.go +++ b/pkg/compute/models/zoneresource.go @@ -19,6 +19,7 @@ import ( "yunion.io/x/jsonutils" + api "yunion.io/x/onecloud/pkg/apis/compute" "yunion.io/x/onecloud/pkg/mcclient" ) @@ -30,25 +31,11 @@ func (self *SZoneResourceBase) GetZone() *SZone { return ZoneManager.FetchZoneById(self.ZoneId) } -func (self *SZoneResourceBase) GetCustomizeColumns(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject) *jsonutils.JSONDict { +func (self *SZoneResourceBase) GetExtraDetails(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject) api.ZoneInfo { + out := api.ZoneInfo{} zone := self.GetZone() if zone == nil { - return nil + return out } - info := map[string]string{ - "zone": zone.GetName(), - "zone_id": zone.GetId(), - } - if len(zone.ExternalId) > 0 { - info["zone_ext_id"] = fetchExternalId(zone.ExternalId) - } - if region := zone.GetRegion(); region != nil { - info["region"] = region.GetName() - info["region_id"] = region.GetId() - if len(region.ExternalId) > 0 { - info["region_external_id"] = region.ExternalId - info["region_ext_id"] = fetchExternalId(region.ExternalId) - } - } - return jsonutils.Marshal(info).(*jsonutils.JSONDict) + return zone.GetZoneInfo() } diff --git a/pkg/compute/models/zones.go b/pkg/compute/models/zones.go index 1fadedd878..eed67c6ee1 100644 --- a/pkg/compute/models/zones.go +++ b/pkg/compute/models/zones.go @@ -57,12 +57,11 @@ type SZone struct { db.SStatusStandaloneResourceBase db.SExternalizedResourceBase - Location string `width:"256" charset:"utf8" get:"user" list:"user" update:"admin"` // = Column(VARCHAR(256, charset='utf8')) - Contacts string `width:"256" charset:"utf8" get:"user" update:"admin"` // = Column(VARCHAR(256, charset='utf8')) - NameCn string `width:"256" charset:"utf8"` // = Column(VARCHAR(256, charset='utf8')) - // status = Column(VARCHAR(36, charset='ascii'), nullable=False, default=ZONE_DISABLE) - ManagerUri string `width:"256" charset:"ascii" list:"admin" update:"admin"` // = Column(VARCHAR(256, charset='ascii'), nullable=True) - // admin_id = Column(VARCHAR(36, charset='ascii'), nullable=False) + Location string `width:"256" charset:"utf8" get:"user" list:"user" update:"admin"` + Contacts string `width:"256" charset:"utf8" get:"user" update:"admin"` + NameCn string `width:"256" charset:"utf8"` + ManagerUri string `width:"256" charset:"ascii" list:"admin" update:"admin"` + // 区域Id CloudregionId string `width:"36" charset:"ascii" nullable:"false" list:"user" create:"admin_required"` } @@ -180,28 +179,37 @@ func (zone *SZone) getNetworkCount() (int, error) { return getNetworkCount(nil, zone, "") } -func zoneExtra(zone *SZone, extra *jsonutils.JSONDict) *jsonutils.JSONDict { - usage := zone.GeneralUsage() - extra.Update(jsonutils.Marshal(usage)) +func (zone *SZone) GetZoneInfo() api.ZoneInfo { + out := api.ZoneInfo{ + Zone: zone.Name, + ZoneExtId: fetchExternalId(zone.ExternalId), + } region := zone.GetRegion() if region != nil { - extra.Add(jsonutils.NewString(region.Name), "cloudregion") - extra.Add(jsonutils.NewString(region.Provider), "provider") + out.CloudregionInfo = region.GetRegionInfo() } - return extra + return out } -func (zone *SZone) GetCustomizeColumns(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject) *jsonutils.JSONDict { - extra := zone.SStandaloneResourceBase.GetCustomizeColumns(ctx, userCred, query) - return zoneExtra(zone, extra) +func zoneExtra(zone *SZone, out api.ZoneDetails) api.ZoneDetails { + usage := zone.GeneralUsage() + jsonutils.Update(&out, usage) + region := zone.GetRegion() + if region != nil { + out.Provider = region.Provider + out.Cloudregion = region.Name + } + return out } -func (zone *SZone) GetExtraDetails(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject) (*jsonutils.JSONDict, error) { - extra, err := zone.SStandaloneResourceBase.GetExtraDetails(ctx, userCred, query) +func (zone *SZone) GetExtraDetails(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject, details bool) (api.ZoneDetails, error) { + var err error + out := api.ZoneDetails{} + out.StandaloneResourceDetails, err = zone.SStandaloneResourceBase.GetExtraDetails(ctx, userCred, query, details) if err != nil { - return nil, err + return out, err } - return zoneExtra(zone, extra), nil + return zoneExtra(zone, out), nil } func (zone *SZone) GetCloudRegionId() string { diff --git a/pkg/compute/specs/handler.go b/pkg/compute/specs/handler.go index 3defac61ee..4a14292bd6 100644 --- a/pkg/compute/specs/handler.go +++ b/pkg/compute/specs/handler.go @@ -26,6 +26,7 @@ import ( "yunion.io/x/onecloud/pkg/appctx" "yunion.io/x/onecloud/pkg/appsrv" + "yunion.io/x/onecloud/pkg/cloudcommon/db" "yunion.io/x/onecloud/pkg/cloudcommon/policy" "yunion.io/x/onecloud/pkg/compute/models" "yunion.io/x/onecloud/pkg/httperrors" @@ -238,7 +239,7 @@ func QueryObjectsToJson(objs []models.ISpecModel, ctx context.Context, userCred if !ok { return nil, fmt.Errorf("Invalid model data structure, not a dict") } - extraDict := obj.GetCustomizeColumns(ctx, userCred, query) + extraDict, _ := db.GetExtraDetails(obj, ctx, userCred, query, false) if extraDict != nil { jsonDict.Update(extraDict) } diff --git a/pkg/image/models/image_guest.go b/pkg/image/models/image_guest.go index 8ef08bf7ab..88a7a180ce 100644 --- a/pkg/image/models/image_guest.go +++ b/pkg/image/models/image_guest.go @@ -279,20 +279,20 @@ type sPair struct { } func (self *SGuestImage) getMoreDetails(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject, - extra *jsonutils.JSONDict) *jsonutils.JSONDict { + out api.GuestImageDetails) api.GuestImageDetails { if self.Status != api.IMAGE_STATUS_ACTIVE { self.checkStatus(ctx, userCred) - extra.Add(jsonutils.NewString(self.Status), "status") + out.Status = self.Status } images, err := GuestImageJointManager.GetImagesByGuestImageId(self.Id) if err != nil { - return extra + return out } var size int64 = 0 if len(images) == 0 { - extra.Add(jsonutils.NewInt(size), "size") - return extra + out.Size = size + return out } dataImages := make([]sPair, 0, len(images)-1) var rootImage sPair @@ -301,8 +301,8 @@ func (self *SGuestImage) getMoreDetails(ctx context.Context, userCred mcclient.T size += image.Size if !image.IsData.IsTrue() { rootImage = sPair{image.Id, images[i].Name, image.MinDiskMB, image.DiskFormat, image.Size, image.Status} - extra.Add(jsonutils.NewInt(int64(image.MinRamMB)), "min_ram_mb") - extra.Add(jsonutils.NewString(image.DiskFormat), "disk_format") + out.MinRamMb = image.MinRamMB + out.DiskFormat = image.DiskFormat continue } dataImages = append(dataImages, sPair{image.Id, image.Name, image.MinDiskMB, image.DiskFormat, image.Size, @@ -312,44 +312,37 @@ func (self *SGuestImage) getMoreDetails(ctx context.Context, userCred mcclient.T sort.Slice(dataImages, func(i, j int) bool { return dataImages[i].Name < dataImages[j].Name }) - extra.Add(jsonutils.NewInt(size), "size") - extra.Add(jsonutils.Marshal(rootImage), "root_image") - extra.Add(jsonutils.Marshal(dataImages), "data_images") + out.Size = size + out.RootImage = jsonutils.Marshal(rootImage) + out.DataImages = jsonutils.Marshal(dataImages) // properties of root image - properties, _ := ImagePropertyManager.GetProperties(rootImage.ID) + properties, err := ImagePropertyManager.GetProperties(rootImage.ID) if err != nil { - return extra + return out } propJson := jsonutils.NewDict() for k, v := range properties { propJson.Add(jsonutils.NewString(v), k) } - extra.Add(propJson, "properties") - extra.Set("disable_delete", jsonutils.NewBool(self.Protected.Bool())) - return extra -} - -func (self *SGuestImage) GetCustomizeColumns(ctx context.Context, userCred mcclient.TokenCredential, - query jsonutils.JSONObject) *jsonutils.JSONDict { - - extra := self.SSharableVirtualResourceBase.GetCustomizeColumns(ctx, userCred, query) - return self.getMoreDetails(ctx, userCred, query, extra) + out.Properties = propJson + out.DisableDelete = self.Protected.Bool() + return out } func (self *SGuestImage) GetExtraDetails(ctx context.Context, userCred mcclient.TokenCredential, - query jsonutils.JSONObject) (*jsonutils.JSONDict, error) { + query jsonutils.JSONObject, details bool) (api.GuestImageDetails, error) { - extra, err := self.SSharableVirtualResourceBase.GetExtraDetails(ctx, userCred, query) + var err error + out := api.GuestImageDetails{} + out.SharableVirtualResourceDetails, err = self.SSharableVirtualResourceBase.GetExtraDetails(ctx, userCred, query, details) if err != nil { - return nil, err + return out, err } - if query.Contains("image_ids") { - imageIds, _ := query.Get("image_ids") - extra.Add(imageIds, "image_ids") - return extra, nil + if details && query.Contains("image_ids") { + out.ImageIds, _ = query.Get("image_ids") } - return self.getMoreDetails(ctx, userCred, query, extra), nil + return self.getMoreDetails(ctx, userCred, query, out), nil } func (self *SGuestImage) PostUpdate(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject, diff --git a/pkg/image/models/images.go b/pkg/image/models/images.go index d5fca85586..e8523a8227 100644 --- a/pkg/image/models/images.go +++ b/pkg/image/models/images.go @@ -108,23 +108,34 @@ func init() { type SImage struct { db.SSharableVirtualResourceBase + // 镜像大小, 单位Byte Size int64 `nullable:"true" list:"user" create:"optional"` - // VirtualSize int64 `nullable:"true" list:"user" create:"optional"` + // 存储地址 Location string `nullable:"true"` - DiskFormat string `width:"20" charset:"ascii" nullable:"true" list:"user" create:"optional" default:"raw"` // Column(VARCHAR(32, charset='ascii'), nullable=False, default='qcow2') - Checksum string `width:"32" charset:"ascii" nullable:"true" get:"user" list:"user"` - FastHash string `width:"32" charset:"ascii" nullable:"true" get:"user"` - Owner string `width:"255" charset:"ascii" nullable:"true" get:"user"` - MinDiskMB int32 `name:"min_disk" nullable:"false" default:"0" list:"user" create:"optional" update:"user"` - MinRamMB int32 `name:"min_ram" nullable:"false" default:"0" list:"user" create:"optional" update:"user"` + // 镜像格式 + DiskFormat string `width:"20" charset:"ascii" nullable:"true" list:"user" create:"optional" default:"raw"` + // 校验和 + Checksum string `width:"32" charset:"ascii" nullable:"true" get:"user" list:"user"` + FastHash string `width:"32" charset:"ascii" nullable:"true" get:"user"` + // 用户Id + Owner string `width:"255" charset:"ascii" nullable:"true" get:"user"` + // 最小系统盘要求 + MinDiskMB int32 `name:"min_disk" nullable:"false" default:"0" list:"user" create:"optional" update:"user"` + // 最小内存要求 + MinRamMB int32 `name:"min_ram" nullable:"false" default:"0" list:"user" create:"optional" update:"user"` - Protected tristate.TriState `nullable:"false" default:"true" list:"user" get:"user" create:"optional" update:"user"` - IsStandard tristate.TriState `nullable:"false" default:"false" list:"user" get:"user" create:"domain_optional"` + // 是否有删除保护 + Protected tristate.TriState `nullable:"false" default:"true" list:"user" get:"user" create:"optional" update:"user"` + // 是否是标准镜像 + IsStandard tristate.TriState `nullable:"false" default:"false" list:"user" get:"user" create:"admin_optional"` + // 是否是主机镜像 IsGuestImage tristate.TriState `nullable:"false" default:"false" create:"optional" list:"user"` - IsData tristate.TriState `nullable:"false" default:"false" create:"optional" list:"user"` + // 是否是数据盘镜像 + IsData tristate.TriState `nullable:"false" default:"false" create:"optional" list:"user"` // image copy from url, save origin checksum before probe + // 从镜像时长导入的镜像校验和 OssChecksum string `width:"32" charset:"ascii" nullable:"true" get:"user" list:"user"` } @@ -241,60 +252,48 @@ func (self *SImage) CustomizedGetDetailsBody(ctx context.Context, userCred mccli return nil, nil } -func (self *SImage) getMoreDetails(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject, extra *jsonutils.JSONDict) *jsonutils.JSONDict { +func (self *SImage) getMoreDetails(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject, out api.ImageDetails) api.ImageDetails { var ossChksum = self.OssChecksum if len(self.OssChecksum) == 0 { ossChksum = self.Checksum } - extra.Set("oss_checksum", jsonutils.NewString(ossChksum)) - extra.Set("disable_delete", jsonutils.NewBool(self.Protected.Bool())) - return extra + out.OssChecksum = ossChksum + out.DisableDelete = self.Protected.Bool() + return out } -func (self *SImage) GetCustomizeColumns(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject) *jsonutils.JSONDict { - extra := self.SSharableVirtualResourceBase.GetCustomizeColumns(ctx, userCred, query) - properties, _ := ImagePropertyManager.GetProperties(self.Id) - if len(properties) > 0 { - jsonProps := jsonutils.NewDict() - for k, v := range properties { - jsonProps.Add(jsonutils.NewString(v), k) - } - extra.Add(jsonProps, "properties") - } - return self.getMoreDetails(ctx, userCred, query, extra) -} - -func (self *SImage) GetExtraDetails(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject) (*jsonutils.JSONDict, error) { - extra, err := self.SSharableVirtualResourceBase.GetExtraDetails(ctx, userCred, query) +func (self *SImage) GetExtraDetails(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject, details bool) (api.ImageDetails, error) { + var err error + out := api.ImageDetails{} + out.SharableVirtualResourceDetails, err = self.SSharableVirtualResourceBase.GetExtraDetails(ctx, userCred, query, details) if err != nil { - return nil, err + return out, err } properties, err := ImagePropertyManager.GetProperties(self.Id) if err != nil { - return nil, httperrors.NewGeneralError(err) + return out, httperrors.NewGeneralError(err) } propJson := jsonutils.NewDict() for k, v := range properties { propJson.Add(jsonutils.NewString(v), k) } - extra.Add(propJson, "properties") + out.Properties = propJson if self.PendingDeleted { pendingDeletedAt := self.PendingDeletedAt.Add(time.Second * time.Duration(options.Options.PendingDeleteExpireSeconds)) - extra.Add(jsonutils.NewString(timeutils.FullIsoTime(pendingDeletedAt)), "auto_delete_at") + out.AutoDeleteAt = pendingDeletedAt + //extra.Add(jsonutils.NewString(timeutils.FullIsoTime(pendingDeletedAt)), "auto_delete_at") } - return self.getMoreDetails(ctx, userCred, query, extra), nil + return self.getMoreDetails(ctx, userCred, query, out), nil } func (self *SImage) GetExtraDetailsHeaders(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject) map[string]string { headers := make(map[string]string) - extra, _ := self.SVirtualResourceBase.GetExtraDetails(ctx, userCred, query) - if extra == nil { - extra = jsonutils.NewDict() - } + _extra, _ := self.SVirtualResourceBase.GetExtraDetails(ctx, userCred, query, false) + extra := _extra.JSON(_extra) extraRows := self.GetModelManager().FetchCustomizeColumns(ctx, userCred, query, []db.IModel{self}, nil) if len(extraRows) == 1 { extra.Update(extraRows[0]) diff --git a/pkg/keystone/models/credentials.go b/pkg/keystone/models/credentials.go index 51a53c6ab1..4ec4ef366e 100644 --- a/pkg/keystone/models/credentials.go +++ b/pkg/keystone/models/credentials.go @@ -166,29 +166,26 @@ func (self *SCredential) ValidateUpdateData(ctx context.Context, userCred mcclie return self.SStandaloneResourceBase.ValidateUpdateData(ctx, userCred, query, data) } -func (self *SCredential) GetCustomizeColumns(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject) *jsonutils.JSONDict { - extra := self.SStandaloneResourceBase.GetCustomizeColumns(ctx, userCred, query) - return credentialExtra(self, extra) -} - -func (self *SCredential) GetExtraDetails(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject) (*jsonutils.JSONDict, error) { - extra, err := self.SStandaloneResourceBase.GetExtraDetails(ctx, userCred, query) +func (self *SCredential) GetExtraDetails(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject, details bool) (api.CredentialDetails, error) { + var err error + out := api.CredentialDetails{} + out.StandaloneResourceDetails, err = self.SStandaloneResourceBase.GetExtraDetails(ctx, userCred, query, details) if err != nil { - return nil, err + return out, err } - return credentialExtra(self, extra), nil + return credentialExtra(self, out), nil } -func credentialExtra(cred *SCredential, extra *jsonutils.JSONDict) *jsonutils.JSONDict { - extra.Add(jsonutils.NewString(string(cred.getBlob())), "blob") +func credentialExtra(cred *SCredential, out api.CredentialDetails) api.CredentialDetails { + out.Blob = string(cred.getBlob()) usr, _ := UserManager.FetchUserExtended(cred.UserId, "", "", "") if usr != nil { - extra.Add(jsonutils.NewString(usr.Name), "user") - extra.Add(jsonutils.NewString(usr.DomainId), "domain_id") - extra.Add(jsonutils.NewString(usr.DomainName), "domain") + out.User = usr.Name + out.Domain = usr.DomainName + out.DomainId = usr.DomainId } - return extra + return out } func (self *SCredential) getBlob() []byte { diff --git a/pkg/keystone/models/domains.go b/pkg/keystone/models/domains.go index c4cb2e9cec..b01bfd0783 100644 --- a/pkg/keystone/models/domains.go +++ b/pkg/keystone/models/domains.go @@ -268,38 +268,29 @@ func (domain *SDomain) ValidateUpdateData(ctx context.Context, userCred mcclient return domain.SStandaloneResourceBase.ValidateUpdateData(ctx, userCred, query, data) } -func (domain *SDomain) GetCustomizeColumns(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject) *jsonutils.JSONDict { - extra := domain.SStandaloneResourceBase.GetCustomizeColumns(ctx, userCred, query) - return domainExtra(domain, extra) -} - -func (domain *SDomain) GetExtraDetails(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject) (*jsonutils.JSONDict, error) { - extra, err := domain.SStandaloneResourceBase.GetExtraDetails(ctx, userCred, query) +func (domain *SDomain) GetExtraDetails(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject, details bool) (api.DomainDetails, error) { + var err error + out := api.DomainDetails{} + out.StandaloneResourceDetails, err = domain.SStandaloneResourceBase.GetExtraDetails(ctx, userCred, query, details) if err != nil { - return nil, err + return out, err } - return domainExtra(domain, extra), nil + return domainExtra(domain, out), nil } -func domainExtra(domain *SDomain, extra *jsonutils.JSONDict) *jsonutils.JSONDict { +func domainExtra(domain *SDomain, out api.DomainDetails) api.DomainDetails { // idp, _ := domain.GetIdentityProvider() // if idp != nil { // extra.Add(jsonutils.NewString(idp.Name), "driver") // } - usrCnt, _ := domain.GetUserCount() - extra.Add(jsonutils.NewInt(int64(usrCnt)), "user_count") - grpCnt, _ := domain.GetGroupCount() - extra.Add(jsonutils.NewInt(int64(grpCnt)), "group_count") - prjCnt, _ := domain.GetProjectCount() - extra.Add(jsonutils.NewInt(int64(prjCnt)), "project_count") - roleCnt, _ := domain.GetRoleCount() - extra.Add(jsonutils.NewInt(int64(roleCnt)), "role_count") - policyCnt, _ := domain.GetPolicyCount() - extra.Add(jsonutils.NewInt(int64(policyCnt)), "policy_count") - idpCnt, _ := domain.GetIdpCount() - extra.Add(jsonutils.NewInt(int64(idpCnt)), "idp_count") - return extra + out.UserCout, _ = domain.GetUserCount() + out.GroupCount, _ = domain.GetGroupCount() + out.ProjectCout, _ = domain.GetProjectCount() + out.RoleCount, _ = domain.GetRoleCount() + out.PolicyCount, _ = domain.GetPolicyCount() + out.IdpCount, _ = domain.GetIdpCount() + return out } func (domain *SDomain) getUsers() ([]SUser, error) { diff --git a/pkg/keystone/models/endpoints.go b/pkg/keystone/models/endpoints.go index dc8569ebdc..02f22a5222 100644 --- a/pkg/keystone/models/endpoints.go +++ b/pkg/keystone/models/endpoints.go @@ -283,21 +283,14 @@ func (endpoint *SEndpoint) ValidateDeleteCondition(ctx context.Context) error { return endpoint.SStandaloneResourceBase.ValidateDeleteCondition(ctx) } -func (endpoint *SEndpoint) GetCustomizeColumns(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject) *jsonutils.JSONDict { - extra := endpoint.SStandaloneResourceBase.GetCustomizeColumns(ctx, userCred, query) - return endpointExtra(endpoint, extra) -} - -func (endpoint *SEndpoint) GetExtraDetails(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject) (*jsonutils.JSONDict, error) { - extra, err := endpoint.SStandaloneResourceBase.GetExtraDetails(ctx, userCred, query) +func (endpoint *SEndpoint) GetExtraDetails(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject, details bool) (api.EndpointDetails, error) { + var err error + out := api.EndpointDetails{} + out.StandaloneResourceDetails, err = endpoint.SStandaloneResourceBase.GetExtraDetails(ctx, userCred, query, details) if err != nil { - return nil, err + return out, err } - return endpointExtra(endpoint, extra), nil -} - -func endpointExtra(endpoint *SEndpoint, extra *jsonutils.JSONDict) *jsonutils.JSONDict { - return extra + return out, nil } func (manager *SEndpointManager) ValidateCreateData(ctx context.Context, userCred mcclient.TokenCredential, ownerId mcclient.IIdentityProvider, query jsonutils.JSONObject, data *jsonutils.JSONDict) (*jsonutils.JSONDict, error) { diff --git a/pkg/keystone/models/groups.go b/pkg/keystone/models/groups.go index 128847de27..015d0a781a 100644 --- a/pkg/keystone/models/groups.go +++ b/pkg/keystone/models/groups.go @@ -144,25 +144,20 @@ func (group *SGroup) Delete(ctx context.Context, userCred mcclient.TokenCredenti return group.SIdentityBaseResource.Delete(ctx, userCred) } -func (group *SGroup) GetCustomizeColumns(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject) *jsonutils.JSONDict { - extra := group.SIdentityBaseResource.GetCustomizeColumns(ctx, userCred, query) - return groupExtra(group, extra) -} - -func (group *SGroup) GetExtraDetails(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject) (*jsonutils.JSONDict, error) { - extra, err := group.SIdentityBaseResource.GetExtraDetails(ctx, userCred, query) +func (group *SGroup) GetExtraDetails(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject, details bool) (api.GroupDetails, error) { + var err error + out := api.GroupDetails{} + out.StandaloneResourceDetails, err = group.SIdentityBaseResource.GetExtraDetails(ctx, userCred, query, details) if err != nil { - return nil, err + return out, err } - return groupExtra(group, extra), nil + return groupExtra(group, out), nil } -func groupExtra(group *SGroup, extra *jsonutils.JSONDict) *jsonutils.JSONDict { - usrCnt, _ := group.GetUserCount() - extra.Add(jsonutils.NewInt(int64(usrCnt)), "user_count") - prjCnt, _ := group.GetProjectCount() - extra.Add(jsonutils.NewInt(int64(prjCnt)), "project_count") - return extra +func groupExtra(group *SGroup, out api.GroupDetails) api.GroupDetails { + out.UserCount, _ = group.GetUserCount() + out.ProjectCount, _ = group.GetProjectCount() + return out } func (manager *SGroupManager) RegisterExternalGroup(ctx context.Context, idpId string, domainId string, groupId string, groupName string) (*SGroup, error) { diff --git a/pkg/keystone/models/identity_provider.go b/pkg/keystone/models/identity_provider.go index b1e3b3a21a..a54a2bb5f6 100644 --- a/pkg/keystone/models/identity_provider.go +++ b/pkg/keystone/models/identity_provider.go @@ -398,29 +398,31 @@ func (self *SIdentityProvider) PerformSync(ctx context.Context, userCred mcclien return nil, nil } -func (self *SIdentityProvider) GetCustomizeColumns(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject) *jsonutils.JSONDict { - extra := self.SEnabledStatusStandaloneResourceBase.GetCustomizeColumns(ctx, userCred, query) - return self.getMoreDetails(extra) -} - -func (self *SIdentityProvider) GetExtraDetails(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject) (*jsonutils.JSONDict, error) { - extra, err := self.SEnabledStatusStandaloneResourceBase.GetExtraDetails(ctx, userCred, query) +func (self *SIdentityProvider) GetExtraDetails(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject, details bool) (api.IdentityProviderDetails, error) { + var err error + out := api.IdentityProviderDetails{} + out.StandaloneResourceDetails, err = self.SEnabledStatusStandaloneResourceBase.GetExtraDetails(ctx, userCred, query, details) if err != nil { - return nil, err + return out, err } - return self.getMoreDetails(extra), nil + return self.getMoreDetails(out), nil } -func (self *SIdentityProvider) getMoreDetails(extra *jsonutils.JSONDict) *jsonutils.JSONDict { - extra = db.FetchModelExtraCountProperties(self, extra) - extra.Set("sync_interval_seconds", jsonutils.NewInt(int64(self.getSyncIntervalSeconds()))) +func (self *SIdentityProvider) getMoreDetails(out api.IdentityProviderDetails) api.IdentityProviderDetails { + out.RoleCount, _ = self.GetRoleCount() + out.UserCount, _ = self.GetUserCount() + out.PolicyCount, _ = self.GetPolicyCount() + out.DomainCount, _ = self.GetDomainCount() + out.ProjectCount, _ = self.GetProjectCount() + out.GroupCount, _ = self.GetGroupCount() + out.SyncIntervalSeconds = self.getSyncIntervalSeconds() if len(self.TargetDomainId) > 0 { domain, _ := DomainManager.FetchDomainById(self.TargetDomainId) if domain != nil { - extra.Set("target_domain", jsonutils.NewString(domain.Name)) + out.TargetDomain = domain.Name } } - return extra + return out } func (self *SIdentityProvider) ValidateUpdateData(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject, data *jsonutils.JSONDict) (*jsonutils.JSONDict, error) { diff --git a/pkg/keystone/models/policies.go b/pkg/keystone/models/policies.go index 2f0b4ba860..561b6ed6af 100644 --- a/pkg/keystone/models/policies.go +++ b/pkg/keystone/models/policies.go @@ -222,19 +222,16 @@ func (manager *SPolicyManager) ListItemFilter(ctx context.Context, q *sqlchemy.S return q, nil } -func (policy *SPolicy) GetCustomizeColumns(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject) *jsonutils.JSONDict { - extra := policy.SEnabledIdentityBaseResource.GetCustomizeColumns(ctx, userCred, query) - return policyExtra(policy, extra) -} - -func (policy *SPolicy) GetExtraDetails(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject) (*jsonutils.JSONDict, error) { - extra, err := policy.SEnabledIdentityBaseResource.GetExtraDetails(ctx, userCred, query) +func (policy *SPolicy) GetExtraDetails(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject, details bool) (api.PolicyDetails, error) { + var err error + out := api.PolicyDetails{} + out.StandaloneResourceDetails, err = policy.SEnabledIdentityBaseResource.GetExtraDetails(ctx, userCred, query, details) if err != nil { - return nil, err + return out, err } - return policyExtra(policy, extra), nil + return policyExtra(policy, out), nil } -func policyExtra(policy *SPolicy, extra *jsonutils.JSONDict) *jsonutils.JSONDict { - return extra +func policyExtra(policy *SPolicy, out api.PolicyDetails) api.PolicyDetails { + return out } diff --git a/pkg/keystone/models/projects.go b/pkg/keystone/models/projects.go index 89746b862d..6f6e5187c0 100644 --- a/pkg/keystone/models/projects.go +++ b/pkg/keystone/models/projects.go @@ -289,35 +289,30 @@ func (proj *SProject) ValidateUpdateData(ctx context.Context, userCred mcclient. return proj.SIdentityBaseResource.ValidateUpdateData(ctx, userCred, query, data) } -func (proj *SProject) GetCustomizeColumns(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject) *jsonutils.JSONDict { - extra := proj.SIdentityBaseResource.GetCustomizeColumns(ctx, userCred, query) - return projectExtra(proj, extra) -} - -func (proj *SProject) GetExtraDetails(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject) (*jsonutils.JSONDict, error) { - extra, err := proj.SIdentityBaseResource.GetExtraDetails(ctx, userCred, query) +func (proj *SProject) GetExtraDetails(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject, details bool) (api.ProjectDetails, error) { + var err error + out := api.ProjectDetails{} + out.StandaloneResourceDetails, err = proj.SIdentityBaseResource.GetExtraDetails(ctx, userCred, query, details) if err != nil { - return nil, err + return out, err } - return projectExtra(proj, extra), nil + return projectExtra(proj, out), nil } -func projectExtra(proj *SProject, extra *jsonutils.JSONDict) *jsonutils.JSONDict { - grpCnt, _ := proj.GetGroupCount() - extra.Add(jsonutils.NewInt(int64(grpCnt)), "group_count") - usrCnt, _ := proj.GetUserCount() - extra.Add(jsonutils.NewInt(int64(usrCnt)), "user_count") +func projectExtra(proj *SProject, out api.ProjectDetails) api.ProjectDetails { + out.GroupCount, _ = proj.GetGroupCount() + out.UserCount, _ = proj.GetUserCount() external, update, _ := proj.getExternalResources() if len(external) > 0 { - extra.Add(jsonutils.Marshal(external), "ext_resources") - extra.Add(jsonutils.NewTimeString(update), "ext_resources_last_update") + out.ExtResource = jsonutils.Marshal(external) + out.ExtResourcesLastUpdate = update if update.IsZero() { update = time.Now() } nextUpdate := update.Add(time.Duration(options.Options.FetchProjectResourceCountIntervalSeconds) * time.Second) - extra.Add(jsonutils.NewTimeString(nextUpdate), "ext_resources_next_update") + out.ExtResourcesNextUpdate = nextUpdate } - return extra + return out } func (proj *SProject) getExternalResources() (map[string]int, time.Time, error) { diff --git a/pkg/keystone/models/regions.go b/pkg/keystone/models/regions.go index 9b4e15e558..3cbc1c58d7 100644 --- a/pkg/keystone/models/regions.go +++ b/pkg/keystone/models/regions.go @@ -99,23 +99,19 @@ func (region *SRegion) ValidateDeleteCondition(ctx context.Context) error { return region.SStandaloneResourceBase.ValidateDeleteCondition(ctx) } -func (region *SRegion) GetCustomizeColumns(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject) *jsonutils.JSONDict { - extra := region.SStandaloneResourceBase.GetCustomizeColumns(ctx, userCred, query) - return regionExtra(region, extra) -} - -func (region *SRegion) GetExtraDetails(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject) (*jsonutils.JSONDict, error) { - extra, err := region.SStandaloneResourceBase.GetExtraDetails(ctx, userCred, query) +func (region *SRegion) GetExtraDetails(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject, details bool) (api.RegionDetails, error) { + var err error + out := api.RegionDetails{} + out.StandaloneResourceDetails, err = region.SStandaloneResourceBase.GetExtraDetails(ctx, userCred, query, details) if err != nil { - return nil, err + return out, err } - return regionExtra(region, extra), nil + return regionExtra(region, out), nil } -func regionExtra(region *SRegion, extra *jsonutils.JSONDict) *jsonutils.JSONDict { - epCnt, _ := region.GetEndpointCount() - extra.Add(jsonutils.NewInt(int64(epCnt)), "endpoint_count") - return extra +func regionExtra(region *SRegion, out api.RegionDetails) api.RegionDetails { + out.EndpointCount, _ = region.GetEndpointCount() + return out } func (manager *SRegionManager) ValidateCreateData(ctx context.Context, userCred mcclient.TokenCredential, ownerId mcclient.IIdentityProvider, query jsonutils.JSONObject, data *jsonutils.JSONDict) (*jsonutils.JSONDict, error) { diff --git a/pkg/keystone/models/roles.go b/pkg/keystone/models/roles.go index 876e941694..d69ec776a4 100644 --- a/pkg/keystone/models/roles.go +++ b/pkg/keystone/models/roles.go @@ -195,31 +195,22 @@ func (role *SRole) ValidateDeleteCondition(ctx context.Context) error { return role.SIdentityBaseResource.ValidateDeleteCondition(ctx) } -func (role *SRole) GetCustomizeColumns(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject) *jsonutils.JSONDict { - extra := role.SIdentityBaseResource.GetCustomizeColumns(ctx, userCred, query) - return roleExtra(role, extra) -} - -func (role *SRole) GetExtraDetails(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject) (*jsonutils.JSONDict, error) { - extra, err := role.SIdentityBaseResource.GetExtraDetails(ctx, userCred, query) +func (role *SRole) GetExtraDetails(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject, details bool) (api.RoleDetails, error) { + var err error + out := api.RoleDetails{} + out.StandaloneResourceDetails, err = role.SIdentityBaseResource.GetExtraDetails(ctx, userCred, query, details) if err != nil { - return nil, err + return out, err } - return roleExtra(role, extra), nil + return roleExtra(role, out), nil } -func roleExtra(role *SRole, extra *jsonutils.JSONDict) *jsonutils.JSONDict { - usrCnt, _ := role.GetUserCount() - extra.Add(jsonutils.NewInt(int64(usrCnt)), "user_count") - grpCnt, _ := role.GetGroupCount() - extra.Add(jsonutils.NewInt(int64(grpCnt)), "group_count") - prjCnt, _ := role.GetProjectCount() - extra.Add(jsonutils.NewInt(int64(prjCnt)), "project_count") - policies := policy.PolicyManager.RoleMatchPolicies(role.Name) - if len(policies) > 0 { - extra.Add(jsonutils.NewStringArray(policies), "match_policies") - } - return extra +func roleExtra(role *SRole, out api.RoleDetails) api.RoleDetails { + out.UserCount, _ = role.GetUserCount() + out.GroupCount, _ = role.GetGroupCount() + out.ProjectCount, _ = role.GetProjectCount() + out.MatchPolicies = policy.PolicyManager.RoleMatchPolicies(role.Name) + return out } // 角色列表 diff --git a/pkg/keystone/models/services.go b/pkg/keystone/models/services.go index 5947f5387e..4cf6272610 100644 --- a/pkg/keystone/models/services.go +++ b/pkg/keystone/models/services.go @@ -108,23 +108,19 @@ func (service *SService) ValidateDeleteCondition(ctx context.Context) error { return service.SStandaloneResourceBase.ValidateDeleteCondition(ctx) } -func (service *SService) GetCustomizeColumns(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject) *jsonutils.JSONDict { - extra := service.SStandaloneResourceBase.GetCustomizeColumns(ctx, userCred, query) - return serviceExtra(service, extra) -} - -func (service *SService) GetExtraDetails(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject) (*jsonutils.JSONDict, error) { - extra, err := service.SStandaloneResourceBase.GetExtraDetails(ctx, userCred, query) +func (service *SService) GetExtraDetails(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject, details bool) (api.ServiceDetails, error) { + var err error + out := api.ServiceDetails{} + out.StandaloneResourceDetails, err = service.SStandaloneResourceBase.GetExtraDetails(ctx, userCred, query, details) if err != nil { - return nil, err + return out, err } - return serviceExtra(service, extra), nil + return serviceExtra(service, out), nil } -func serviceExtra(service *SService, extra *jsonutils.JSONDict) *jsonutils.JSONDict { - epCnt, _ := service.GetEndpointCount() - extra.Add(jsonutils.NewInt(int64(epCnt)), "endpoint_count") - return extra +func serviceExtra(service *SService, out api.ServiceDetails) api.ServiceDetails { + out.EndpointCount, _ = service.GetEndpointCount() + return out } func (service *SService) PostCreate(ctx context.Context, userCred mcclient.TokenCredential, ownerId mcclient.IIdentityProvider, query jsonutils.JSONObject, data jsonutils.JSONObject) { diff --git a/pkg/keystone/models/users.go b/pkg/keystone/models/users.go index ce7ae4156e..4ccff7408a 100644 --- a/pkg/keystone/models/users.go +++ b/pkg/keystone/models/users.go @@ -478,40 +478,34 @@ func (user *SUser) GetCredentialCount() (int, error) { return q.CountWithError() } -func (user *SUser) GetCustomizeColumns(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject) *jsonutils.JSONDict { - extra := user.SEnabledIdentityBaseResource.GetCustomizeColumns(ctx, userCred, query) - return userExtra(user, extra) -} - -func (user *SUser) GetExtraDetails(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject) (*jsonutils.JSONDict, error) { - extra, err := user.SEnabledIdentityBaseResource.GetExtraDetails(ctx, userCred, query) +func (user *SUser) GetExtraDetails(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject, details bool) (api.UserDetails, error) { + var err error + out := api.UserDetails{} + out.StandaloneResourceDetails, err = user.SEnabledIdentityBaseResource.GetExtraDetails(ctx, userCred, query, details) if err != nil { - return nil, err + return out, err } - return userExtra(user, extra), nil + return userExtra(user, out), nil } -func userExtra(user *SUser, extra *jsonutils.JSONDict) *jsonutils.JSONDict { - grpCnt, _ := user.GetGroupCount() - extra.Add(jsonutils.NewInt(int64(grpCnt)), "group_count") - prjCnt, _ := user.GetProjectCount() - extra.Add(jsonutils.NewInt(int64(prjCnt)), "project_count") - credCnt, _ := user.GetCredentialCount() - extra.Add(jsonutils.NewInt(int64(credCnt)), "credential_count") +func userExtra(user *SUser, out api.UserDetails) api.UserDetails { + out.GroupCount, _ = user.GetGroupCount() + out.ProjectCount, _ = user.GetProjectCount() + out.CredentialCount, _ = user.GetCredentialCount() localUser, _ := LocalUserManager.fetchLocalUser(user.Id, user.DomainId, 0) if localUser != nil { if localUser.FailedAuthCount > 0 { - extra.Add(jsonutils.NewInt(int64(localUser.FailedAuthCount)), "failed_auth_count") - extra.Add(jsonutils.NewTimeString(localUser.FailedAuthAt), "failed_auth_at") + out.FailedAuthCount = localUser.FailedAuthCount + out.FailedAuthAt = localUser.FailedAuthAt } localPass, _ := PasswordManager.FetchLastPassword(localUser.Id) if localPass != nil && !localPass.ExpiresAt.IsZero() { - extra.Add(jsonutils.NewTimeString(localPass.ExpiresAt), "password_expires_at") + out.PasswordExpiresAt = localPass.ExpiresAt } } - return extra + return out } func (user *SUser) initLocalData(passwd string) error { diff --git a/pkg/notify/models/mod_contact.go b/pkg/notify/models/mod_contact.go index e7e7d102eb..454d48b63c 100644 --- a/pkg/notify/models/mod_contact.go +++ b/pkg/notify/models/mod_contact.go @@ -27,6 +27,7 @@ import ( "yunion.io/x/pkg/util/sets" "yunion.io/x/sqlchemy" + api "yunion.io/x/onecloud/pkg/apis/notify" "yunion.io/x/onecloud/pkg/cloudcommon/db" "yunion.io/x/onecloud/pkg/mcclient" "yunion.io/x/onecloud/pkg/notify/utils" @@ -183,19 +184,8 @@ func (self *SContactManager) FetchByMore(uid, contact, contactType string) ([]SC return records, nil } -func (self *SContact) GetCustomizeColumns(ctx context.Context, userCred mcclient.TokenCredential, - query jsonutils.JSONObject) *jsonutils.JSONDict { - - extra := self.SStandaloneResourceBase.GetCustomizeColumns(ctx, userCred, query) - ret, err := self.getMoreDetail(ctx, userCred, extra) - if err != nil { - log.Errorf("getMoreDetail error: %s", err) - } - return ret -} - func (self *SContact) getMoreDetail(ctx context.Context, userCred mcclient.TokenCredential, - ret *jsonutils.JSONDict) (*jsonutils.JSONDict, error) { + out api.ContactDetails) (api.ContactDetails, error) { uname, err := utils.GetUsernameByID(ctx, self.UID) if errors.Cause(err) == sql.ErrNoRows { @@ -203,29 +193,31 @@ func (self *SContact) getMoreDetail(ctx context.Context, userCred mcclient.Token err = nil } if err != nil { - return ret, err + return out, err } q := ContactManager.Query().Equals("uid", self.UID) contacts := make([]SContact, 0) err = db.FetchModelObjects(ContactManager, q, &contacts) if err != nil { - return ret, errors.Wrapf(err, "fetch Contacts of uid %s error", self.UID) + return out, errors.Wrapf(err, "fetch Contacts of uid %s error", self.UID) } - ret.Add(jsonutils.NewString(self.UID), "id") - ret.Add(jsonutils.NewString(uname), "name") - ret.Add(jsonutils.NewString(jsonutils.Marshal(contacts).String()), "details") + out.Id = self.UID + out.Name = uname + out.Details = jsonutils.Marshal(contacts).String() - return ret, nil + return out, nil } func (self *SContact) GetExtraDetail(ctx context.Context, userCred mcclient.TokenCredential, - query jsonutils.JSONObject) (*jsonutils.JSONDict, error) { - extra, err := self.SStandaloneResourceBase.GetExtraDetails(ctx, userCred, query) + query jsonutils.JSONObject, details bool) (api.ContactDetails, error) { + var err error + out := api.ContactDetails{} + out.ModelBaseDetails, err = self.SStatusStandaloneResourceBase.GetExtraDetails(ctx, userCred, query, details) if err != nil { - return nil, err + return out, err } - return self.getMoreDetail(ctx, userCred, extra) + return self.getMoreDetail(ctx, userCred, out) } // 联系方式列表 diff --git a/pkg/notify/models/mod_notification.go b/pkg/notify/models/mod_notification.go index 976c5206b3..219a23cff9 100644 --- a/pkg/notify/models/mod_notification.go +++ b/pkg/notify/models/mod_notification.go @@ -26,6 +26,7 @@ import ( "yunion.io/x/pkg/errors" "yunion.io/x/sqlchemy" + api "yunion.io/x/onecloud/pkg/apis/notify" "yunion.io/x/onecloud/pkg/cloudcommon/db" "yunion.io/x/onecloud/pkg/cloudcommon/policy" "yunion.io/x/onecloud/pkg/httperrors" @@ -103,43 +104,13 @@ type UserDetail struct { ReceivedAt time.Time } -func (self *SNotification) GetCustomizeColumns(ctx context.Context, userCred mcclient.TokenCredential, - query jsonutils.JSONObject) *jsonutils.JSONDict { - - // collect user infos - scopeStr, err := query.GetString("scope") +func (self *SNotification) GetExtraDetails(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject, details bool) (api.NotificationDetails, error) { + var err error + out := api.NotificationDetails{} + out.ModelBaseDetails, err = self.SStatusStandaloneResourceBase.GetExtraDetails(ctx, userCred, query, details) if err != nil { - scopeStr = "system" + return out, err } - scope := rbacutils.TRbacScope(scopeStr) - - var userDetails []UserDetail - if scope.HigherEqual(rbacutils.ScopeSystem) { - // fetch users from database - userDetails, err = NotificationManager.fetchUserDetailByClusterID(ctx, self.ClusterID) - if err != nil { - log.Errorf(err.Error()) - } - - } else { - userDetail := UserDetail{ - Status: self.Status, - Name: userCred.GetUserId(), - ReceivedAt: self.ReceivedAt, - } - name, err := utils.GetUsernameByID(ctx, self.UID) - if err == nil && len(name) != 0 { - userDetail.Name = name - } - userDetails = []UserDetail{userDetail} - } - ret := jsonutils.NewDict() - ret.Add(jsonutils.Marshal(userDetails), "user_list") - ret.Add(jsonutils.NewString(self.ClusterID), "id") - return ret -} - -func (self *SNotification) GetExtraDetails(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject) (*jsonutils.JSONDict, error) { userDetail := UserDetail{ Status: self.Status, Name: self.UID, @@ -147,12 +118,10 @@ func (self *SNotification) GetExtraDetails(ctx context.Context, userCred mcclien } name, err := utils.GetUsernameByID(ctx, self.UID) if err == nil && len(name) != 0 { - userDetail.Name = name + out.Name = name } - ret := jsonutils.NewDict() - data := jsonutils.Marshal([]UserDetail{userDetail}) - ret.Add(data, "user_list") - return ret, nil + out.UserList = jsonutils.Marshal([]UserDetail{userDetail}) + return out, nil } func (self *SNotificationManager) AllowListItems(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject) bool {