From cfa6fc4cfe13e1b57b4093761cc2a610273be6c2 Mon Sep 17 00:00:00 2001 From: Zexi Li Date: Tue, 19 Nov 2019 19:14:49 +0800 Subject: [PATCH] support generate --- .gitignore | 1 + Makefile | 18 + pkg/apis/cloudprovider/doc.go | 15 + pkg/apis/cloudprovider/zz_generated.model.go | 23 + pkg/apis/compute/bucket.go | 18 + pkg/apis/compute/guests.go | 5 +- pkg/apis/compute/zz_generated.model.go | 1320 ++++++++++++++++++ pkg/apis/identity/assignments.go | 30 +- pkg/apis/identity/zz_generated.model.go | 184 +++ pkg/apis/image/zz_generated.model.go | 57 + pkg/apis/zz_generated.model.go | 128 ++ pkg/cloudcommon/db/caller.go | 202 +++ pkg/cloudcommon/db/caller_test.go | 119 ++ pkg/cloudcommon/db/db_dispatcher.go | 67 +- pkg/cloudcommon/db/interface.go | 13 +- pkg/cloudcommon/db/models.go | 4 + pkg/cloudprovider/geoinfo.go | 1 + pkg/compute/models/buckets.go | 10 +- pkg/compute/models/guest_actions.go | 9 +- pkg/compute/models/guests.go | 1 + pkg/image/service/handlers.go | 2 +- pkg/image/service/service.go | 2 +- pkg/keystone/service/handlers.go | 2 +- pkg/keystone/service/service.go | 2 +- pkg/keystone/tokens/auth.go | 14 + pkg/mcclient/input.go | 18 +- pkg/mcclient/token2.go | 62 +- pkg/notify/dispatcher.go | 4 +- scripts/codegen.sh | 104 ++ 29 files changed, 2327 insertions(+), 108 deletions(-) create mode 100644 pkg/apis/cloudprovider/doc.go create mode 100644 pkg/apis/cloudprovider/zz_generated.model.go create mode 100644 pkg/apis/compute/zz_generated.model.go create mode 100644 pkg/apis/identity/zz_generated.model.go create mode 100644 pkg/apis/image/zz_generated.model.go create mode 100644 pkg/apis/zz_generated.model.go create mode 100644 pkg/cloudcommon/db/caller.go create mode 100644 pkg/cloudcommon/db/caller_test.go create mode 100755 scripts/codegen.sh diff --git a/.gitignore b/.gitignore index 4a0d0899c7..6999276610 100644 --- a/.gitignore +++ b/.gitignore @@ -33,3 +33,4 @@ _output GPATH GRTAGS GTAGS +pkg/generated diff --git a/Makefile b/Makefile index d45c0b2a70..a0ad0663f0 100644 --- a/Makefile +++ b/Makefile @@ -232,3 +232,21 @@ endef help: export helpText:=$(helpText) help: @echo "$$helpText" + +gen-model-api-check: + which swagger-gen || (GO111MODULE=off go get -u github.com/yunionio/code-generator/cmd/model-api-gen) + +gen-model-api: + ./scripts/codegen.sh model_api + +gen-swagger-check: + which swagger || (GO111MODULE=off go get -u github.com/go-swagger/go-swagger/cmd/swagger) + which swagger-gen || (GO111MODULE=off go get -u github.com/yunionio/code-generator/cmd/swagger-gen) + which swagger-serve || (GO111MODULE=off go get -u github.com/yunionio/code-generator/cmd/swagger-serve) + +gen-swagger: gen-swagger-check + ./scripts/codegen.sh swagger_spec + ./scripts/codegen.sh swagger_yaml + +swagger-serve: gen-swagger + ./scripts/codegen.sh swagger_serve diff --git a/pkg/apis/cloudprovider/doc.go b/pkg/apis/cloudprovider/doc.go new file mode 100644 index 0000000000..5997bbb7ae --- /dev/null +++ b/pkg/apis/cloudprovider/doc.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 cloudprovider // import "yunion.io/x/onecloud/pkg/apis/cloudprovider" diff --git a/pkg/apis/cloudprovider/zz_generated.model.go b/pkg/apis/cloudprovider/zz_generated.model.go new file mode 100644 index 0000000000..fe54f991f0 --- /dev/null +++ b/pkg/apis/cloudprovider/zz_generated.model.go @@ -0,0 +1,23 @@ +// 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. + +// Code generated by model-api-gen. DO NOT EDIT. + +package cloudprovider + +// SGeographicInfo is an autogenerated struct via yunion.io/x/onecloud/pkg/cloudprovider.SGeographicInfo. +type SGeographicInfo struct { + Latitude float32 `json:"latitude"` + Longitude float32 `json:"longitude"` + City string `json:"city"` + CountryCode string `json:"country_code"` +} diff --git a/pkg/apis/compute/bucket.go b/pkg/apis/compute/bucket.go index 4b1fd5ec81..e2a1aabd45 100644 --- a/pkg/apis/compute/bucket.go +++ b/pkg/apis/compute/bucket.go @@ -14,6 +14,10 @@ package compute +import ( + "yunion.io/x/onecloud/pkg/apis" +) + const ( BUCKET_OPS_STATS_CHANGE = "stats_change" @@ -30,3 +34,17 @@ const ( BUCKET_UPLOAD_OBJECT_ACL_HEADER = "X-Yunion-Bucket-Upload-Acl" BUCKET_UPLOAD_OBJECT_STORAGECLASS_HEADER = "X-Yunion-Bucket-Upload-Storageclass" ) + +type BucketCreateInput struct { + apis.Meta + + Name string `json:"name"` + Cloudregion string `json:"cloudregion"` + Manager string `json:"manager"` + StorageClass string `json:"storage_class"` + Description string `json:"description"` +} + +type BucketDetail struct { + SBucket +} diff --git a/pkg/apis/compute/guests.go b/pkg/apis/compute/guests.go index c655827e03..e917cc8550 100644 --- a/pkg/apis/compute/guests.go +++ b/pkg/apis/compute/guests.go @@ -7,7 +7,10 @@ import ( type ServerRebuildRootInput struct { apis.Meta - Image string `json:"image"` + // 镜像名称 + Image string `json:"image"` + // 镜像 id + // required: true ImageId string `json:"image_id"` Keypair string `json:"keypair"` KeypairId string `json:"keypair_id"` diff --git a/pkg/apis/compute/zz_generated.model.go b/pkg/apis/compute/zz_generated.model.go new file mode 100644 index 0000000000..8a8bd2bbf8 --- /dev/null +++ b/pkg/apis/compute/zz_generated.model.go @@ -0,0 +1,1320 @@ +// 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. + +// Code generated by model-api-gen. DO NOT EDIT. + +package compute + +import ( + time "time" + + jsonutils "yunion.io/x/jsonutils" + + "yunion.io/x/onecloud/pkg/apis" + "yunion.io/x/onecloud/pkg/apis/cloudprovider" +) + +// SAwsCachedLb is an autogenerated struct via yunion.io/x/onecloud/pkg/compute/models.SAwsCachedLb. +type SAwsCachedLb struct { + apis.SVirtualResourceBase + apis.SExternalizedResourceBase + SManagedResourceBase + SCloudregionResourceBase + BackendServerId string `json:"backend_server_id"` + BackendId string `json:"backend_id"` + CachedBackendGroupId string `json:"cached_backend_group_id"` +} + +// SAwsCachedLbbg is an autogenerated struct via yunion.io/x/onecloud/pkg/compute/models.SAwsCachedLbbg. +type SAwsCachedLbbg struct { + apis.SVirtualResourceBase + apis.SExternalizedResourceBase + SManagedResourceBase + SCloudregionResourceBase + LoadbalancerId string `json:"loadbalancer_id"` + BackendGroupId string `json:"backend_group_id"` + TargetType string `json:"target_type"` + ProtocolType string `json:"protocol_type"` + Port int `json:"port"` + HealthCheckProtocol string `json:"health_check_protocol"` + HealthCheckInterval int `json:"health_check_interval"` +} + +// SBaremetalagent is an autogenerated struct via yunion.io/x/onecloud/pkg/compute/models.SBaremetalagent. +type SBaremetalagent struct { + apis.SStandaloneResourceBase + Status string `json:"status"` + AccessIp string `json:"access_ip"` + ManagerUri string `json:"manager_uri"` + ZoneId string `json:"zone_id"` + AgentType string `json:"agent_type"` + Version string `json:"version"` + StoragecacheId string `json:"storagecache_id"` +} + +// SBillingResourceBase is an autogenerated struct via yunion.io/x/onecloud/pkg/compute/models.SBillingResourceBase. +type SBillingResourceBase struct { + BillingType string `json:"billing_type"` + ExpiredAt time.Time `json:"expired_at"` + BillingCycle string `json:"billing_cycle"` +} + +// SBucket is an autogenerated struct via yunion.io/x/onecloud/pkg/compute/models.SBucket. +type SBucket struct { + apis.SVirtualResourceBase + apis.SExternalizedResourceBase + SManagedResourceBase + CloudregionId string `json:"cloudregion_id"` + StorageClass string `json:"storage_class"` + Location string `json:"location"` + Acl string `json:"acl"` + SizeBytes int64 `json:"size_bytes"` + ObjectCnt int `json:"object_cnt"` + SizeBytesLimit int64 `json:"size_bytes_limit"` + ObjectCntLimit int `json:"object_cnt_limit"` + AccessUrls jsonutils.JSONObject `json:"access_urls"` +} + +// SCachedLoadbalancerAcl is an autogenerated struct via yunion.io/x/onecloud/pkg/compute/models.SCachedLoadbalancerAcl. +type SCachedLoadbalancerAcl struct { + apis.SSharableVirtualResourceBase + apis.SExternalizedResourceBase + SManagedResourceBase + SCloudregionResourceBase + AclId string `json:"acl_id"` + ListenerId string `json:"listener_id"` +} + +// SCachedLoadbalancerCertificate is an autogenerated struct via yunion.io/x/onecloud/pkg/compute/models.SCachedLoadbalancerCertificate. +type SCachedLoadbalancerCertificate struct { + apis.SVirtualResourceBase + apis.SExternalizedResourceBase + SManagedResourceBase + SCloudregionResourceBase + CertificateId string `json:"certificate_id"` +} + +// SCachedimage is an autogenerated struct via yunion.io/x/onecloud/pkg/compute/models.SCachedimage. +type SCachedimage struct { + apis.SStandaloneResourceBase + apis.SExternalizedResourceBase + Size int64 `json:"size"` + Info jsonutils.JSONObject `json:"info"` + LastSync time.Time `json:"last_sync"` + LastRef time.Time `json:"last_ref"` + RefCount int `json:"ref_count"` + ImageType string `json:"image_type"` +} + +// SCloudaccount is an autogenerated struct via yunion.io/x/onecloud/pkg/compute/models.SCloudaccount. +type SCloudaccount struct { + apis.SEnabledStatusStandaloneResourceBase + apis.SDomainizedResourceBase + SSyncableBaseResource + LastAutoSync time.Time `json:"last_auto_sync"` + ProjectId string `json:"project_id"` + AccessUrl string `json:"access_url"` + Account string `json:"account"` + Secret string `json:"secret"` + AccountId string `json:"account_id"` + IsPublicCloud *bool `json:"is_public_cloud,omitempty"` + IsOnPremise bool `json:"is_on_premise"` + HasObjectStorage bool `json:"has_object_storage"` + Provider string `json:"provider"` + EnableAutoSync bool `json:"enable_auto_sync"` + SyncIntervalSeconds int `json:"sync_interval_seconds"` + Balance float64 `json:"balance"` + ProbeAt time.Time `json:"probe_at"` + HealthStatus string `json:"health_status"` + ErrorCount int `json:"error_count"` + AutoCreateProject bool `json:"auto_create_project"` + Version string `json:"version"` + Sysinfo jsonutils.JSONObject `json:"sysinfo"` + Brand string `json:"brand"` + Options *jsonutils.JSONDict `json:"options"` + IsPublic bool `json:"is_public"` + ShareMode string `json:"share_mode"` +} + +// SCloudprovider is an autogenerated struct via yunion.io/x/onecloud/pkg/compute/models.SCloudprovider. +type SCloudprovider struct { + apis.SEnabledStatusStandaloneResourceBase + apis.SProjectizedResourceBase + SSyncableBaseResource + HealthStatus string `json:"health_status"` + AccessUrl string `json:"access_url"` + Account string `json:"account"` + Secret string `json:"secret"` + CloudaccountId string `json:"cloudaccount_id"` + Provider string `json:"provider"` +} + +// SCloudproviderregion is an autogenerated struct via yunion.io/x/onecloud/pkg/compute/models.SCloudproviderregion. +type SCloudproviderregion struct { + apis.SJointResourceBase + SSyncableBaseResource + CloudproviderId string `json:"cloudprovider_id"` + CloudregionId string `json:"cloudregion_id"` + Enabled bool `json:"enabled"` + SyncResults jsonutils.JSONObject `json:"sync_results"` + LastDeepSyncAt time.Time `json:"last_deep_sync_at"` +} + +// SCloudregion is an autogenerated struct via yunion.io/x/onecloud/pkg/compute/models.SCloudregion. +type SCloudregion struct { + apis.SEnabledStatusStandaloneResourceBase + SManagedResourceBase + apis.SExternalizedResourceBase + cloudprovider.SGeographicInfo + Provider string `json:"provider"` +} + +// SCloudregionResourceBase is an autogenerated struct via yunion.io/x/onecloud/pkg/compute/models.SCloudregionResourceBase. +type SCloudregionResourceBase struct { + CloudregionId string `json:"cloudregion_id"` +} + +// SDBInstance is an autogenerated struct via yunion.io/x/onecloud/pkg/compute/models.SDBInstance. +type SDBInstance struct { + apis.SVirtualResourceBase + apis.SExternalizedResourceBase + SManagedResourceBase + SBillingResourceBase + SCloudregionResourceBase + DisableDelete *bool `json:"disable_delete,omitempty"` + MasterInstanceId string `json:"master_instance_id"` + VcpuCount int `json:"vcpu_count"` + VmemSizeMb int `json:"vmem_size_mb"` + StorageType string `json:"storage_type"` + DiskSizeGB int `json:"disk_size_gb"` + Port int `json:"port"` + Category string `json:"category"` + Engine string `json:"engine"` + EngineVersion string `json:"engine_version"` + InstanceType string `json:"instance_type"` + MaintainTime string `json:"maintain_time"` + SecgroupId string `json:"secgroup_id"` + VpcId string `json:"vpc_id"` + ConnectionStr string `json:"connection_str"` + InternalConnectionStr string `json:"internal_connection_str"` + Zone1 string `json:"zone1"` + Zone2 string `json:"zone2"` + Zone3 string `json:"zone3"` + ZoneId string `json:"zone_id"` +} + +// SDBInstanceAccount is an autogenerated struct via yunion.io/x/onecloud/pkg/compute/models.SDBInstanceAccount. +type SDBInstanceAccount struct { + apis.SVirtualResourceBase + apis.SExternalizedResourceBase + Secret string `json:"secret"` + DBInstanceId string `json:"db_instance_id"` +} + +// SDBInstanceBackup is an autogenerated struct via yunion.io/x/onecloud/pkg/compute/models.SDBInstanceBackup. +type SDBInstanceBackup struct { + apis.SVirtualResourceBase + SCloudregionResourceBase + SManagedResourceBase + apis.SExternalizedResourceBase + Engine string `json:"engine"` + EngineVersion string `json:"engine_version"` + StartTime time.Time `json:"start_time"` + EndTime time.Time `json:"end_time"` + BackupMode string `json:"backup_mode"` + DBNames string `json:"db_names"` + BackupSizeMb int `json:"backup_size_mb"` + DBInstanceId string `json:"db_instance_id"` +} + +// SDBInstanceDatabase is an autogenerated struct via yunion.io/x/onecloud/pkg/compute/models.SDBInstanceDatabase. +type SDBInstanceDatabase struct { + apis.SVirtualResourceBase + apis.SExternalizedResourceBase + CharacterSet string `json:"character_set"` + DBInstanceId string `json:"db_instance_id"` +} + +// SDBInstanceJointsBase is an autogenerated struct via yunion.io/x/onecloud/pkg/compute/models.SDBInstanceJointsBase. +type SDBInstanceJointsBase struct { + apis.SVirtualJointResourceBase + DBInstanceId string `json:"db_instance_id"` +} + +// SDBInstanceNetwork is an autogenerated struct via yunion.io/x/onecloud/pkg/compute/models.SDBInstanceNetwork. +type SDBInstanceNetwork struct { + SDBInstanceJointsBase + NetworkId string `json:"network_id"` + IpAddr string `json:"ip_addr"` +} + +// SDBInstanceParameter is an autogenerated struct via yunion.io/x/onecloud/pkg/compute/models.SDBInstanceParameter. +type SDBInstanceParameter struct { + apis.SStandaloneResourceBase + apis.SExternalizedResourceBase + DBInstanceId string `json:"db_instance_id"` + Key string `json:"key"` + Value string `json:"value"` +} + +// SDBInstancePrivilege is an autogenerated struct via yunion.io/x/onecloud/pkg/compute/models.SDBInstancePrivilege. +type SDBInstancePrivilege struct { + apis.SResourceBase + apis.SExternalizedResourceBase + Id string `json:"id"` + Privilege string `json:"privilege"` + DBInstanceaccountId string `json:"db_instanceaccount_id"` + DBInstancedatabaseId string `json:"db_instancedatabase_id"` +} + +// SDBInstanceSku is an autogenerated struct via yunion.io/x/onecloud/pkg/compute/models.SDBInstanceSku. +type SDBInstanceSku struct { + apis.SEnabledStatusStandaloneResourceBase + apis.SExternalizedResourceBase + SCloudregionResourceBase + Provider string `json:"provider"` + StorageType string `json:"storage_type"` + DiskSizeStep int `json:"disk_size_step"` + MaxDiskSizeGb int `json:"max_disk_size_gb"` + MinDiskSizeGb int `json:"min_disk_size_gb"` + IOPS int `json:"iops"` + TPS int `json:"tps"` + QPS int `json:"qps"` + MaxConnections int `json:"max_connections"` + VcpuCount int `json:"vcpu_count"` + VmemSizeMb int `json:"vmem_size_mb"` + Category string `json:"category"` + Engine string `json:"engine"` + EngineVersion string `json:"engine_version"` + Zone1 string `json:"zone1"` + Zone2 string `json:"zone2"` + Zone3 string `json:"zone3"` + ZoneId string `json:"zone_id"` +} + +// SDisk is an autogenerated struct via yunion.io/x/onecloud/pkg/compute/models.SDisk. +type SDisk struct { + apis.SSharableVirtualResourceBase + apis.SExternalizedResourceBase + SBillingResourceBase + DiskFormat string `json:"disk_format"` + DiskSize int `json:"disk_size"` + AccessPath string `json:"access_path"` + AutoDelete bool `json:"auto_delete"` + StorageId string `json:"storage_id"` + BackupStorageId string `json:"backup_storage_id"` + TemplateId string `json:"template_id"` + SnapshotId string `json:"snapshot_id"` + FsFormat string `json:"fs_format"` + DiskType string `json:"disk_type"` + Nonpersistent bool `json:"nonpersistent"` +} + +// SDnsRecord is an autogenerated struct via yunion.io/x/onecloud/pkg/compute/models.SDnsRecord. +type SDnsRecord struct { + apis.SAdminSharableVirtualResourceBase + Ttl int `json:"ttl"` + Enabled *bool `json:"enabled,omitempty"` +} + +// SDynamicschedtag is an autogenerated struct via yunion.io/x/onecloud/pkg/compute/models.SDynamicschedtag. +type SDynamicschedtag struct { + apis.SStandaloneResourceBase + Condition string `json:"condition"` + SchedtagId string `json:"schedtag_id"` + Enabled *bool `json:"enabled,omitempty"` +} + +// SElasticcache is an autogenerated struct via yunion.io/x/onecloud/pkg/compute/models.SElasticcache. +type SElasticcache struct { + apis.SVirtualResourceBase + apis.SExternalizedResourceBase + SBillingResourceBase + SManagedResourceBase + SCloudregionResourceBase + SZoneResourceBase + SlaveZones string `json:"slave_zones"` + DisableDelete *bool `json:"disable_delete,omitempty"` + InstanceType string `json:"instance_type"` + CapacityMB int `json:"capacity_mb"` + LocalCategory string `json:"local_category"` + NodeType string `json:"node_type"` + Engine string `json:"engine"` + EngineVersion string `json:"engine_version"` + VpcId string `json:"vpc_id"` + NetworkType string `json:"network_type"` + NetworkId string `json:"network_id"` + SecurityGroupId string `json:"security_group_id"` + PrivateDNS string `json:"private_dns"` + PrivateIpAddr string `json:"private_ip_addr"` + PrivateConnectPort int `json:"private_connect_port"` + PublicDNS string `json:"public_dns"` + PublicIpAddr string `json:"public_ip_addr"` + PublicConnectPort int `json:"public_connect_port"` + MaintainStartTime string `json:"maintain_start_time"` + MaintainEndTime string `json:"maintain_end_time"` + AuthMode string `json:"auth_mode"` +} + +// SElasticcacheAccount is an autogenerated struct via yunion.io/x/onecloud/pkg/compute/models.SElasticcacheAccount. +type SElasticcacheAccount struct { + apis.SStatusStandaloneResourceBase + apis.SExternalizedResourceBase + ElasticcacheId string `json:"elasticcache_id"` + AccountType string `json:"account_type"` + AccountPrivilege string `json:"account_privilege"` + Password string `json:"password"` +} + +// SElasticcacheAcl is an autogenerated struct via yunion.io/x/onecloud/pkg/compute/models.SElasticcacheAcl. +type SElasticcacheAcl struct { + apis.SStatusStandaloneResourceBase + apis.SExternalizedResourceBase + ElasticcacheId string `json:"elasticcache_id"` + IpList string `json:"ip_list"` +} + +// SElasticcacheBackup is an autogenerated struct via yunion.io/x/onecloud/pkg/compute/models.SElasticcacheBackup. +type SElasticcacheBackup struct { + apis.SStatusStandaloneResourceBase + apis.SExternalizedResourceBase + ElasticcacheId string `json:"elasticcache_id"` + BackupSizeMb int `json:"backup_size_mb"` + BackupType string `json:"backup_type"` + BackupMode string `json:"backup_mode"` + DownloadURL string `json:"download_url"` + StartTime time.Time `json:"start_time"` + EndTime time.Time `json:"end_time"` +} + +// SElasticcacheParameter is an autogenerated struct via yunion.io/x/onecloud/pkg/compute/models.SElasticcacheParameter. +type SElasticcacheParameter struct { + apis.SStatusStandaloneResourceBase + apis.SExternalizedResourceBase + ElasticcacheId string `json:"elasticcache_id"` + Key string `json:"key"` + Value string `json:"value"` + ValueRange string `json:"value_range"` + Modifiable bool `json:"modifiable"` + ForceRestart bool `json:"force_restart"` +} + +// SElasticcacheSku is an autogenerated struct via yunion.io/x/onecloud/pkg/compute/models.SElasticcacheSku. +type SElasticcacheSku struct { + apis.SStatusStandaloneResourceBase + apis.SExternalizedResourceBase + SCloudregionResourceBase + SZoneResourceBase + SlaveZoneId string `json:"slave_zone_id"` + InstanceSpec string `json:"instance_spec"` + EngineArch string `json:"engine_arch"` + LocalCategory string `json:"local_category"` + PrepaidStatus string `json:"prepaid_status"` + PostpaidStatus string `json:"postpaid_status"` + Engine string `json:"engine"` + EngineVersion string `json:"engine_version"` + CpuArch string `json:"cpu_arch"` + StorageType string `json:"storage_type"` + PerformanceType string `json:"performance_type"` + NodeType string `json:"node_type"` + MemorySizeMB int `json:"memory_size_mb"` + DiskSizeGB int `json:"disk_size_gb"` + ShardNum int `json:"shard_num"` + MaxShardNum int `json:"max_shard_num"` + ReplicasNum int `json:"replicas_num"` + MaxReplicasNum int `json:"max_replicas_num"` + MaxClients int `json:"max_clients"` + MaxConnections int `json:"max_connections"` + MaxInBandwidthMb int `json:"max_in_bandwidth_mb"` + MaxMemoryMB int `json:"max_memory_mb"` + QPS int `json:"qps"` + Provider string `json:"provider"` +} + +// SElasticip is an autogenerated struct via yunion.io/x/onecloud/pkg/compute/models.SElasticip. +type SElasticip struct { + apis.SVirtualResourceBase + apis.SExternalizedResourceBase + SManagedResourceBase + SBillingResourceBase + NetworkId string `json:"network_id"` + Mode string `json:"mode"` + IpAddr string `json:"ip_addr"` + AssociateType string `json:"associate_type"` + AssociateId string `json:"associate_id"` + Bandwidth int `json:"bandwidth"` + ChargeType string `json:"charge_type"` + BgpType string `json:"bgp_type"` + AutoDellocate *bool `json:"auto_dellocate,omitempty"` + CloudregionId string `json:"cloudregion_id"` +} + +// SExternalProject is an autogenerated struct via yunion.io/x/onecloud/pkg/compute/models.SExternalProject. +type SExternalProject struct { + apis.SStandaloneResourceBase + SManagedResourceBase + apis.SProjectizedResourceBase + apis.SExternalizedResourceBase +} + +// SGroup is an autogenerated struct via yunion.io/x/onecloud/pkg/compute/models.SGroup. +type SGroup struct { + apis.SVirtualResourceBase + ServiceType string `json:"service_type"` + ParentId string `json:"parent_id"` + ZoneId string `json:"zone_id"` + SchedStrategy string `json:"sched_strategy"` + Granularity int `json:"granularity"` + ForceDispersion *bool `json:"force_dispersion,omitempty"` + Enabled *bool `json:"enabled,omitempty"` +} + +// SGroupJointsBase is an autogenerated struct via yunion.io/x/onecloud/pkg/compute/models.SGroupJointsBase. +type SGroupJointsBase struct { + apis.SVirtualJointResourceBase + GroupId string `json:"group_id"` +} + +// SGroupguest is an autogenerated struct via yunion.io/x/onecloud/pkg/compute/models.SGroupguest. +type SGroupguest struct { + SGroupJointsBase + Tag string `json:"tag"` + GuestId string `json:"guest_id"` +} + +// SGroupnetwork is an autogenerated struct via yunion.io/x/onecloud/pkg/compute/models.SGroupnetwork. +type SGroupnetwork struct { + SGroupJointsBase + NetworkId string `json:"network_id"` + IpAddr string `json:"ip_addr"` + Index byte `json:"index"` + EipId string `json:"eip_id"` +} + +// SGuest is an autogenerated struct via yunion.io/x/onecloud/pkg/compute/models.SGuest. +type SGuest struct { + apis.SVirtualResourceBase + apis.SExternalizedResourceBase + SBillingResourceBase + VcpuCount int `json:"vcpu_count"` + VmemSize int `json:"vmem_size"` + BootOrder string `json:"boot_order"` + DisableDelete *bool `json:"disable_delete,omitempty"` + ShutdownBehavior string `json:"shutdown_behavior"` + KeypairId string `json:"keypair_id"` + HostId string `json:"host_id"` + BackupHostId string `json:"backup_host_id"` + Vga string `json:"vga"` + Vdi string `json:"vdi"` + Machine string `json:"machine"` + Bios string `json:"bios"` + OsType string `json:"os_type"` + FlavorId string `json:"flavor_id"` + SecgrpId string `json:"secgrp_id"` + AdminSecgrpId string `json:"admin_secgrp_id"` + Hypervisor string `json:"hypervisor"` + InstanceType string `json:"instance_type"` +} + +// SGuestJointsBase is an autogenerated struct via yunion.io/x/onecloud/pkg/compute/models.SGuestJointsBase. +type SGuestJointsBase struct { + apis.SVirtualJointResourceBase + GuestId string `json:"guest_id"` +} + +// SGuestdisk is an autogenerated struct via yunion.io/x/onecloud/pkg/compute/models.SGuestdisk. +type SGuestdisk struct { + SGuestJointsBase + DiskId string `json:"disk_id"` + ImagePath string `json:"image_path"` + Driver string `json:"driver"` + CacheMode string `json:"cache_mode"` + AioMode string `json:"aio_mode"` + Iops int `json:"iops"` + Bps int `json:"bps"` + Mountpoint string `json:"mountpoint"` + Index byte `json:"index"` +} + +// SGuestnetwork is an autogenerated struct via yunion.io/x/onecloud/pkg/compute/models.SGuestnetwork. +type SGuestnetwork struct { + SGuestJointsBase + NetworkId string `json:"network_id"` + MacAddr string `json:"mac_addr"` + IpAddr string `json:"ip_addr"` + Ip6Addr string `json:"ip6_addr"` + Driver string `json:"driver"` + BwLimit int `json:"bw_limit"` + Index byte `json:"index"` + Virtual bool `json:"virtual"` + Ifname string `json:"ifname"` + TeamWith string `json:"team_with"` +} + +// SGuestsecgroup is an autogenerated struct via yunion.io/x/onecloud/pkg/compute/models.SGuestsecgroup. +type SGuestsecgroup struct { + SGuestJointsBase + SecgroupId string `json:"secgroup_id"` +} + +// SHost is an autogenerated struct via yunion.io/x/onecloud/pkg/compute/models.SHost. +type SHost struct { + apis.SEnabledStatusStandaloneResourceBase + apis.SExternalizedResourceBase + SManagedResourceBase + SBillingResourceBase + Rack string `json:"rack"` + Slots string `json:"slots"` + AccessMac string `json:"access_mac"` + AccessIp string `json:"access_ip"` + ManagerUri string `json:"manager_uri"` + SysInfo jsonutils.JSONObject `json:"sys_info"` + SN string `json:"sn"` + CpuCount int `json:"cpu_count"` + NodeCount byte `json:"node_count"` + CpuDesc string `json:"cpu_desc"` + CpuMhz int `json:"cpu_mhz"` + CpuCache int `json:"cpu_cache"` + CpuReserved int `json:"cpu_reserved"` + CpuCmtbound float32 `json:"cpu_cmtbound"` + CpuMicrocode string `json:"cpu_microcode"` + CpuArchitecture string `json:"cpu_architecture"` + MemSize int `json:"mem_size"` + MemReserved int `json:"mem_reserved"` + MemCmtbound float32 `json:"mem_cmtbound"` + StorageSize int `json:"storage_size"` + StorageType string `json:"storage_type"` + StorageDriver string `json:"storage_driver"` + StorageInfo jsonutils.JSONObject `json:"storage_info"` + IpmiIp string `json:"ipmi_ip"` + IpmiInfo jsonutils.JSONObject `json:"ipmi_info"` + HostStatus string `json:"host_status"` + ZoneId string `json:"zone_id"` + HostType string `json:"host_type"` + Version string `json:"version"` + IsBaremetal bool `json:"is_baremetal"` + IsMaintenance bool `json:"is_maintenance"` + LastPingAt time.Time `json:"last_ping_at"` + ResourceType string `json:"resource_type"` + RealExternalId string `json:"real_external_id"` + IsImport bool `json:"is_import"` + EnablePxeBoot *bool `json:"enable_pxe_boot,omitempty"` + Uuid string `json:"uuid"` + BootMode string `json:"boot_mode"` +} + +// SHostJointsBase is an autogenerated struct via yunion.io/x/onecloud/pkg/compute/models.SHostJointsBase. +type SHostJointsBase struct { + apis.SJointResourceBase +} + +// SHostnetwork is an autogenerated struct via yunion.io/x/onecloud/pkg/compute/models.SHostnetwork. +type SHostnetwork struct { + SHostJointsBase + BaremetalId string `json:"baremetal_id"` + NetworkId string `json:"network_id"` + IpAddr string `json:"ip_addr"` + MacAddr string `json:"mac_addr"` +} + +// SHostschedtag is an autogenerated struct via yunion.io/x/onecloud/pkg/compute/models.SHostschedtag. +type SHostschedtag struct { + SSchedtagJointsBase + HostId string `json:"host_id"` +} + +// SHoststorage is an autogenerated struct via yunion.io/x/onecloud/pkg/compute/models.SHoststorage. +type SHoststorage struct { + SHostJointsBase + MountPoint string `json:"mount_point"` + HostId string `json:"host_id"` + StorageId string `json:"storage_id"` + Config *jsonutils.JSONArray `json:"config"` + RealCapacity int64 `json:"real_capacity"` +} + +// SHostwire is an autogenerated struct via yunion.io/x/onecloud/pkg/compute/models.SHostwire. +type SHostwire struct { + SHostJointsBase + Bridge string `json:"bridge"` + Interface string `json:"interface"` + IsMaster bool `json:"is_master"` + MacAddr string `json:"mac_addr"` + HostId string `json:"host_id"` + WireId string `json:"wire_id"` +} + +// SHuaweiCachedLb is an autogenerated struct via yunion.io/x/onecloud/pkg/compute/models.SHuaweiCachedLb. +type SHuaweiCachedLb struct { + apis.SVirtualResourceBase + apis.SExternalizedResourceBase + SManagedResourceBase + SCloudregionResourceBase + BackendServerId string `json:"backend_server_id"` + BackendId string `json:"backend_id"` + CachedBackendGroupId string `json:"cached_backend_group_id"` +} + +// SHuaweiCachedLbbg is an autogenerated struct via yunion.io/x/onecloud/pkg/compute/models.SHuaweiCachedLbbg. +type SHuaweiCachedLbbg struct { + apis.SVirtualResourceBase + apis.SExternalizedResourceBase + SManagedResourceBase + SCloudregionResourceBase + LoadbalancerId string `json:"loadbalancer_id"` + BackendGroupId string `json:"backend_group_id"` + AssociatedId string `json:"associated_id"` + AssociatedType string `json:"associated_type"` + ProtocolType string `json:"protocol_type"` +} + +// SInstanceSnapshot is an autogenerated struct via yunion.io/x/onecloud/pkg/compute/models.SInstanceSnapshot. +type SInstanceSnapshot struct { + apis.SVirtualResourceBase + GuestId string `json:"guest_id"` + ServerConfig jsonutils.JSONObject `json:"server_config"` + ServerMetadata jsonutils.JSONObject `json:"server_metadata"` + AutoDelete bool `json:"auto_delete"` + RefCount int `json:"ref_count"` + SecGroups jsonutils.JSONObject `json:"sec_groups"` + KeypairId string `json:"keypair_id"` + OsType string `json:"os_type"` +} + +// SInstanceSnapshotJoint is an autogenerated struct via yunion.io/x/onecloud/pkg/compute/models.SInstanceSnapshotJoint. +type SInstanceSnapshotJoint struct { + apis.SVirtualJointResourceBase + InstanceSnapshotId string `json:"instance_snapshot_id"` + SnapshotId string `json:"snapshot_id"` + DiskIndex byte `json:"disk_index"` +} + +// SIsolatedDevice is an autogenerated struct via yunion.io/x/onecloud/pkg/compute/models.SIsolatedDevice. +type SIsolatedDevice struct { + apis.SStandaloneResourceBase + HostId string `json:"host_id"` + DevType string `json:"dev_type"` + Model string `json:"model"` + GuestId string `json:"guest_id"` + Addr string `json:"addr"` + VendorDeviceId string `json:"vendor_device_id"` +} + +// SKeypair is an autogenerated struct via yunion.io/x/onecloud/pkg/compute/models.SKeypair. +type SKeypair struct { + apis.SStandaloneResourceBase + Scheme string `json:"scheme"` + Fingerprint string `json:"fingerprint"` + PrivateKey string `json:"private_key"` + PublicKey string `json:"public_key"` + OwnerId string `json:"owner_id"` +} + +// SLoadbalancer is an autogenerated struct via yunion.io/x/onecloud/pkg/compute/models.SLoadbalancer. +type SLoadbalancer struct { + apis.SVirtualResourceBase + apis.SExternalizedResourceBase + SManagedResourceBase + SCloudregionResourceBase + SZoneResourceBase + SLoadbalancerRateLimiter + Address string `json:"address"` + AddressType string `json:"address_type"` + NetworkType string `json:"network_type"` + NetworkId string `json:"network_id"` + VpcId string `json:"vpc_id"` + ClusterId string `json:"cluster_id"` + ChargeType string `json:"charge_type"` + LoadbalancerSpec string `json:"loadbalancer_spec"` + BackendGroupId string `json:"backend_group_id"` + LBInfo jsonutils.JSONObject `json:"lb_info"` +} + +// SLoadbalancerAcl is an autogenerated struct via yunion.io/x/onecloud/pkg/compute/models.SLoadbalancerAcl. +type SLoadbalancerAcl struct { + apis.SSharableVirtualResourceBase + apis.SExternalizedResourceBase + SManagedResourceBase + SCloudregionResourceBase + AclEntries *SLoadbalancerAclEntries `json:"acl_entries"` + Fingerprint string `json:"fingerprint"` +} + +// SLoadbalancerAclEntries is an autogenerated struct via yunion.io/x/onecloud/pkg/compute/models.SLoadbalancerAclEntries. +type SLoadbalancerAclEntries []*SLoadbalancerAclEntry + +// SLoadbalancerAclEntry is an autogenerated struct via yunion.io/x/onecloud/pkg/compute/models.SLoadbalancerAclEntry. +type SLoadbalancerAclEntry struct { + Cidr string `json:"cidr"` + Comment string `json:"comment"` +} + +// SLoadbalancerAgent is an autogenerated struct via yunion.io/x/onecloud/pkg/compute/models.SLoadbalancerAgent. +type SLoadbalancerAgent struct { + apis.SStandaloneResourceBase + Version string `json:"version"` + IP string `json:"ip"` + HaState string `json:"ha_state"` + HbLastSeen time.Time `json:"hb_last_seen"` + HbTimeout int `json:"hb_timeout"` + Params *SLoadbalancerAgentParams `json:"params"` + Loadbalancers time.Time `json:"loadbalancers"` + LoadbalancerListeners time.Time `json:"loadbalancer_listeners"` + LoadbalancerListenerRules time.Time `json:"loadbalancer_listener_rules"` + LoadbalancerBackendGroups time.Time `json:"loadbalancer_backend_groups"` + LoadbalancerBackends time.Time `json:"loadbalancer_backends"` + LoadbalancerAcls time.Time `json:"loadbalancer_acls"` + LoadbalancerCertificates time.Time `json:"loadbalancer_certificates"` + Deployment *SLoadbalancerAgentDeployment `json:"deployment"` + ClusterId string `json:"cluster_id"` +} + +// SLoadbalancerAgentDeployment is an autogenerated struct via yunion.io/x/onecloud/pkg/compute/models.SLoadbalancerAgentDeployment. +type SLoadbalancerAgentDeployment struct { + Host string `json:"host"` + AnsiblePlaybook string `json:"ansible_playbook"` + AnsiblePlaybookUndeployment string `json:"ansible_playbook_undeployment"` +} + +// SLoadbalancerAgentParams is an autogenerated struct via yunion.io/x/onecloud/pkg/compute/models.SLoadbalancerAgentParams. +type SLoadbalancerAgentParams struct { + KeepalivedConfTmpl string `json:"keepalived_conf_tmpl"` + HaproxyConfTmpl string `json:"haproxy_conf_tmpl"` + TelegrafConfTmpl string `json:"telegraf_conf_tmpl"` + Vrrp SLoadbalancerAgentParamsVrrp `json:"vrrp"` + Haproxy SLoadbalancerAgentParamsHaproxy `json:"haproxy"` + Telegraf SLoadbalancerAgentParamsTelegraf `json:"telegraf"` +} + +// SLoadbalancerAgentParamsHaproxy is an autogenerated struct via yunion.io/x/onecloud/pkg/compute/models.SLoadbalancerAgentParamsHaproxy. +type SLoadbalancerAgentParamsHaproxy struct { + GlobalLog string `json:"global_log"` + GlobalNbthread int `json:"global_nbthread"` + LogHttp bool `json:"log_http"` + LogTcp bool `json:"log_tcp"` + LogNormal bool `json:"log_normal"` +} + +// SLoadbalancerAgentParamsTelegraf is an autogenerated struct via yunion.io/x/onecloud/pkg/compute/models.SLoadbalancerAgentParamsTelegraf. +type SLoadbalancerAgentParamsTelegraf struct { + InfluxDbOutputUrl string `json:"influx_db_output_url"` + InfluxDbOutputName string `json:"influx_db_output_name"` + InfluxDbOutputUnsafeSsl bool `json:"influx_db_output_unsafe_ssl"` + HaproxyInputInterval int `json:"haproxy_input_interval"` +} + +// SLoadbalancerAgentParamsVrrp is an autogenerated struct via yunion.io/x/onecloud/pkg/compute/models.SLoadbalancerAgentParamsVrrp. +type SLoadbalancerAgentParamsVrrp struct { + Priority int `json:"priority"` + VirtualRouterId int `json:"virtual_router_id"` + GarpMasterRefresh int `json:"garp_master_refresh"` + Preempt bool `json:"preempt"` + Interface string `json:"interface"` + AdvertInt int `json:"advert_int"` + Pass string `json:"pass"` +} + +// SLoadbalancerBackend is an autogenerated struct via yunion.io/x/onecloud/pkg/compute/models.SLoadbalancerBackend. +type SLoadbalancerBackend struct { + apis.SVirtualResourceBase + apis.SExternalizedResourceBase + SManagedResourceBase + SCloudregionResourceBase + BackendGroupId string `json:"backend_group_id"` + BackendId string `json:"backend_id"` + BackendType string `json:"backend_type"` + BackendRole string `json:"backend_role"` + Weight int `json:"weight"` + Address string `json:"address"` + Port int `json:"port"` + SendProxy string `json:"send_proxy"` +} + +// SLoadbalancerBackendGroup is an autogenerated struct via yunion.io/x/onecloud/pkg/compute/models.SLoadbalancerBackendGroup. +type SLoadbalancerBackendGroup struct { + apis.SVirtualResourceBase + apis.SExternalizedResourceBase + SManagedResourceBase + SCloudregionResourceBase + Type string `json:"type"` + LoadbalancerId string `json:"loadbalancer_id"` +} + +// SLoadbalancerCertificate is an autogenerated struct via yunion.io/x/onecloud/pkg/compute/models.SLoadbalancerCertificate. +type SLoadbalancerCertificate struct { + apis.SVirtualResourceBase + apis.SExternalizedResourceBase + SManagedResourceBase + SCloudregionResourceBase + Certificate string `json:"certificate"` + PrivateKey string `json:"private_key"` + PublicKeyAlgorithm string `json:"public_key_algorithm"` + PublicKeyBitLen int `json:"public_key_bit_len"` + SignatureAlgorithm string `json:"signature_algorithm"` + Fingerprint string `json:"fingerprint"` + NotBefore time.Time `json:"not_before"` + NotAfter time.Time `json:"not_after"` + CommonName string `json:"common_name"` + SubjectAlternativeNames string `json:"subject_alternative_names"` +} + +// SLoadbalancerCluster is an autogenerated struct via yunion.io/x/onecloud/pkg/compute/models.SLoadbalancerCluster. +type SLoadbalancerCluster struct { + apis.SStandaloneResourceBase + SZoneResourceBase + WireId string `json:"wire_id"` +} + +// SLoadbalancerHTTPListener is an autogenerated struct via yunion.io/x/onecloud/pkg/compute/models.SLoadbalancerHTTPListener. +type SLoadbalancerHTTPListener struct { + StickySession string `json:"sticky_session"` + StickySessionType string `json:"sticky_session_type"` + StickySessionCookie string `json:"sticky_session_cookie"` + StickySessionCookieTimeout int `json:"sticky_session_cookie_timeout"` + XForwardedFor bool `json:"xforwarded_for"` + Gzip bool `json:"gzip"` +} + +// SLoadbalancerHTTPRateLimiter is an autogenerated struct via yunion.io/x/onecloud/pkg/compute/models.SLoadbalancerHTTPRateLimiter. +type SLoadbalancerHTTPRateLimiter struct { + HTTPRequestRate int `json:"http_request_rate"` + HTTPRequestRatePerSrc int `json:"http_request_rate_per_src"` +} + +// SLoadbalancerHTTPSListener is an autogenerated struct via yunion.io/x/onecloud/pkg/compute/models.SLoadbalancerHTTPSListener. +type SLoadbalancerHTTPSListener struct { + CertificateId string `json:"certificate_id"` + CachedCertificateId string `json:"cached_certificate_id"` + TLSCipherPolicy string `json:"tls_cipher_policy"` + EnableHttp2 bool `json:"enable_http2"` +} + +// SLoadbalancerHealthCheck is an autogenerated struct via yunion.io/x/onecloud/pkg/compute/models.SLoadbalancerHealthCheck. +type SLoadbalancerHealthCheck struct { + HealthCheck string `json:"health_check"` + HealthCheckType string `json:"health_check_type"` + HealthCheckDomain string `json:"health_check_domain"` + HealthCheckURI string `json:"health_check_uri"` + HealthCheckHttpCode string `json:"health_check_http_code"` + HealthCheckRise int `json:"health_check_rise"` + HealthCheckFall int `json:"health_check_fall"` + HealthCheckTimeout int `json:"health_check_timeout"` + HealthCheckInterval int `json:"health_check_interval"` + HealthCheckReq string `json:"health_check_req"` + HealthCheckExp string `json:"health_check_exp"` +} + +// SLoadbalancerListener is an autogenerated struct via yunion.io/x/onecloud/pkg/compute/models.SLoadbalancerListener. +type SLoadbalancerListener struct { + apis.SVirtualResourceBase + apis.SExternalizedResourceBase + SManagedResourceBase + SCloudregionResourceBase + LoadbalancerId string `json:"loadbalancer_id"` + ListenerType string `json:"listener_type"` + ListenerPort int `json:"listener_port"` + BackendGroupId string `json:"backend_group_id"` + BackendServerPort int `json:"backend_server_port"` + Scheduler string `json:"scheduler"` + SendProxy string `json:"send_proxy"` + ClientRequestTimeout int `json:"client_request_timeout"` + ClientIdleTimeout int `json:"client_idle_timeout"` + BackendConnectTimeout int `json:"backend_connect_timeout"` + BackendIdleTimeout int `json:"backend_idle_timeout"` + AclStatus string `json:"acl_status"` + AclType string `json:"acl_type"` + AclId string `json:"acl_id"` + CachedAclId string `json:"cached_acl_id"` + SLoadbalancerRateLimiter + SLoadbalancerTCPListener + SLoadbalancerUDPListener + SLoadbalancerHTTPListener + SLoadbalancerHTTPSListener + SLoadbalancerHealthCheck + SLoadbalancerHTTPRateLimiter +} + +// SLoadbalancerListenerRule is an autogenerated struct via yunion.io/x/onecloud/pkg/compute/models.SLoadbalancerListenerRule. +type SLoadbalancerListenerRule struct { + apis.SVirtualResourceBase + apis.SExternalizedResourceBase + SManagedResourceBase + SCloudregionResourceBase + IsDefault bool `json:"is_default"` + ListenerId string `json:"listener_id"` + BackendGroupId string `json:"backend_group_id"` + Domain string `json:"domain"` + Path string `json:"path"` + Condition string `json:"condition"` + SLoadbalancerHealthCheck + SLoadbalancerHTTPRateLimiter +} + +// SLoadbalancerNetwork is an autogenerated struct via yunion.io/x/onecloud/pkg/compute/models.SLoadbalancerNetwork. +type SLoadbalancerNetwork struct { + apis.SVirtualJointResourceBase + LoadbalancerId string `json:"loadbalancer_id"` + NetworkId string `json:"network_id"` + IpAddr string `json:"ip_addr"` +} + +// SLoadbalancerRateLimiter is an autogenerated struct via yunion.io/x/onecloud/pkg/compute/models.SLoadbalancerRateLimiter. +type SLoadbalancerRateLimiter struct { + EgressMbps int `json:"egress_mbps"` +} + +// SLoadbalancerTCPListener is an autogenerated struct via yunion.io/x/onecloud/pkg/compute/models.SLoadbalancerTCPListener. +type SLoadbalancerTCPListener struct { +} + +// SLoadbalancerUDPListener is an autogenerated struct via yunion.io/x/onecloud/pkg/compute/models.SLoadbalancerUDPListener. +type SLoadbalancerUDPListener struct { +} + +// SManagedResourceBase is an autogenerated struct via yunion.io/x/onecloud/pkg/compute/models.SManagedResourceBase. +type SManagedResourceBase struct { + ManagerId string `json:"manager_id"` +} + +// SNatEntry is an autogenerated struct via yunion.io/x/onecloud/pkg/compute/models.SNatEntry. +type SNatEntry struct { + apis.SStatusStandaloneResourceBase + apis.SExternalizedResourceBase + NatgatewayId string `json:"natgateway_id"` +} + +// SNatGateway is an autogenerated struct via yunion.io/x/onecloud/pkg/compute/models.SNatGateway. +type SNatGateway struct { + apis.SStatusStandaloneResourceBase + apis.SExternalizedResourceBase + SManagedResourceBase + SCloudregionResourceBase + SBillingResourceBase + VpcId string `json:"vpc_id"` + NatSpec string `json:"nat_spec"` +} + +// SNetwork is an autogenerated struct via yunion.io/x/onecloud/pkg/compute/models.SNetwork. +type SNetwork struct { + apis.SSharableVirtualResourceBase + apis.SExternalizedResourceBase + IfnameHint string `json:"ifname_hint"` + GuestIpStart string `json:"guest_ip_start"` + GuestIpEnd string `json:"guest_ip_end"` + GuestIpMask byte `json:"guest_ip_mask"` + GuestGateway string `json:"guest_gateway"` + GuestDns string `json:"guest_dns"` + GuestDhcp string `json:"guest_dhcp"` + GuestDomain string `json:"guest_domain"` + GuestIp6Start string `json:"guest_ip6_start"` + GuestIp6End string `json:"guest_ip6_end"` + GuestIp6Mask byte `json:"guest_ip6_mask"` + GuestGateway6 string `json:"guest_gateway6"` + GuestDns6 string `json:"guest_dns6"` + GuestDomain6 string `json:"guest_domain6"` + VlanId int `json:"vlan_id"` + WireId string `json:"wire_id"` + ServerType string `json:"server_type"` + AllocPolicy string `json:"alloc_policy"` + AllocTimoutSeconds int `json:"alloc_timout_seconds"` +} + +// SNetworkInterface is an autogenerated struct via yunion.io/x/onecloud/pkg/compute/models.SNetworkInterface. +type SNetworkInterface struct { + apis.SStatusStandaloneResourceBase + apis.SExternalizedResourceBase + SManagedResourceBase + SCloudregionResourceBase + Mac string `json:"mac"` + AssociateType string `json:"associate_type"` + AssociateId string `json:"associate_id"` +} + +// SNetworkinterfacenetwork is an autogenerated struct via yunion.io/x/onecloud/pkg/compute/models.SNetworkinterfacenetwork. +type SNetworkinterfacenetwork struct { + apis.SJointResourceBase + Primary bool `json:"primary"` + IpAddr string `json:"ip_addr"` + NetworkinterfaceId string `json:"networkinterface_id"` + NetworkId string `json:"network_id"` +} + +// SNetworkschedtag is an autogenerated struct via yunion.io/x/onecloud/pkg/compute/models.SNetworkschedtag. +type SNetworkschedtag struct { + SSchedtagJointsBase + NetworkId string `json:"network_id"` +} + +// SReservedip is an autogenerated struct via yunion.io/x/onecloud/pkg/compute/models.SReservedip. +type SReservedip struct { + apis.SResourceBase + Id int64 `json:"id"` + NetworkId string `json:"network_id"` + IpAddr string `json:"ip_addr"` + Notes string `json:"notes"` + ExpiredAt time.Time `json:"expired_at"` + Status string `json:"status"` +} + +// SRoute is an autogenerated struct via yunion.io/x/onecloud/pkg/compute/models.SRoute. +type SRoute struct { + Type string `json:"type"` + Cidr string `json:"cidr"` + NextHopType string `json:"next_hop_type"` + NextHopId string `json:"next_hop_id"` +} + +// SRouteTable is an autogenerated struct via yunion.io/x/onecloud/pkg/compute/models.SRouteTable. +type SRouteTable struct { + apis.SVirtualResourceBase + apis.SExternalizedResourceBase + SManagedResourceBase + VpcId string `json:"vpc_id"` + CloudregionId string `json:"cloudregion_id"` + Type string `json:"type"` + Routes *SRoutes `json:"routes"` +} + +// SRoutes is an autogenerated struct via yunion.io/x/onecloud/pkg/compute/models.SRoutes. +type SRoutes []*SRoute + +// SSchedpolicy is an autogenerated struct via yunion.io/x/onecloud/pkg/compute/models.SSchedpolicy. +type SSchedpolicy struct { + apis.SStandaloneResourceBase + Condition string `json:"condition"` + SchedtagId string `json:"schedtag_id"` + Strategy string `json:"strategy"` + Enabled *bool `json:"enabled,omitempty"` +} + +// SSchedtag is an autogenerated struct via yunion.io/x/onecloud/pkg/compute/models.SSchedtag. +type SSchedtag struct { + apis.SStandaloneResourceBase + apis.SScopedResourceBase + DefaultStrategy string `json:"default_strategy"` + ResourceType string `json:"resource_type"` +} + +// SSchedtagJointsBase is an autogenerated struct via yunion.io/x/onecloud/pkg/compute/models.SSchedtagJointsBase. +type SSchedtagJointsBase struct { + apis.SJointResourceBase + SchedtagId string `json:"schedtag_id"` +} + +// SSecurityGroup is an autogenerated struct via yunion.io/x/onecloud/pkg/compute/models.SSecurityGroup. +type SSecurityGroup struct { + apis.SSharableVirtualResourceBase + IsDirty bool `json:"is_dirty"` +} + +// SSecurityGroupCache is an autogenerated struct via yunion.io/x/onecloud/pkg/compute/models.SSecurityGroupCache. +type SSecurityGroupCache struct { + apis.SStatusStandaloneResourceBase + apis.SExternalizedResourceBase + SCloudregionResourceBase + SManagedResourceBase + SecgroupId string `json:"secgroup_id"` + VpcId string `json:"vpc_id"` +} + +// SSecurityGroupRule is an autogenerated struct via yunion.io/x/onecloud/pkg/compute/models.SSecurityGroupRule. +type SSecurityGroupRule struct { + apis.SResourceBase + Id string `json:"id"` + Priority int64 `json:"priority"` + Protocol string `json:"protocol"` + Ports string `json:"ports"` + Direction string `json:"direction"` + CIDR string `json:"cidr"` + Action string `json:"action"` + Description string `json:"description"` + SecgroupID string `json:"secgroup_id"` +} + +// SServerSku is an autogenerated struct via yunion.io/x/onecloud/pkg/compute/models.SServerSku. +type SServerSku struct { + apis.SStatusStandaloneResourceBase + apis.SExternalizedResourceBase + SCloudregionResourceBase + SZoneResourceBase + Enabled bool `json:"enabled"` + InstanceTypeFamily string `json:"instance_type_family"` + InstanceTypeCategory string `json:"instance_type_category"` + LocalCategory string `json:"local_category"` + PrepaidStatus string `json:"prepaid_status"` + PostpaidStatus string `json:"postpaid_status"` + CpuCoreCount int `json:"cpu_core_count"` + MemorySizeMB int `json:"memory_size_mb"` + OsName string `json:"os_name"` + SysDiskResizable *bool `json:"omitempty,sys_disk_resizable"` + SysDiskType string `json:"sys_disk_type"` + SysDiskMinSizeGB int `json:"sys_disk_min_size_gb"` + SysDiskMaxSizeGB int `json:"sys_disk_max_size_gb"` + AttachedDiskType string `json:"attached_disk_type"` + AttachedDiskSizeGB int `json:"attached_disk_size_gb"` + AttachedDiskCount int `json:"attached_disk_count"` + DataDiskTypes string `json:"data_disk_types"` + DataDiskMaxCount int `json:"data_disk_max_count"` + NicType string `json:"nic_type"` + NicMaxCount int `json:"nic_max_count"` + GpuAttachable *bool `json:"gpu_attachable,omitempty"` + GpuSpec string `json:"gpu_spec"` + GpuCount int `json:"gpu_count"` + GpuMaxCount int `json:"gpu_max_count"` + Provider string `json:"provider"` +} + +// SSnapshot is an autogenerated struct via yunion.io/x/onecloud/pkg/compute/models.SSnapshot. +type SSnapshot struct { + apis.SVirtualResourceBase + apis.SExternalizedResourceBase + SManagedResourceBase + DiskId string `json:"disk_id"` + StorageId string `json:"storage_id"` + CreatedBy string `json:"created_by"` + Location string `json:"location"` + Size int `json:"size"` + OutOfChain bool `json:"out_of_chain"` + FakeDeleted bool `json:"fake_deleted"` + DiskType string `json:"disk_type"` + OsType string `json:"os_type"` + RefCount int `json:"ref_count"` + CloudregionId string `json:"cloudregion_id"` + BackingDiskId string `json:"backing_disk_id"` + ExpiredAt time.Time `json:"expired_at"` +} + +// SSnapshotPolicy is an autogenerated struct via yunion.io/x/onecloud/pkg/compute/models.SSnapshotPolicy. +type SSnapshotPolicy struct { + apis.SVirtualResourceBase + RetentionDays int `json:"retention_days"` + RepeatWeekdays byte `json:"repeat_weekdays"` + TimePoints uint32 `json:"time_points"` + IsActivated *bool `json:"is_activated,omitempty"` +} + +// SSnapshotPolicyCache is an autogenerated struct via yunion.io/x/onecloud/pkg/compute/models.SSnapshotPolicyCache. +type SSnapshotPolicyCache struct { + apis.SStatusStandaloneResourceBase + apis.SExternalizedResourceBase + SCloudregionResourceBase + SManagedResourceBase + SnapshotpolicyId string `json:"snapshotpolicy_id"` +} + +// SSnapshotPolicyDisk is an autogenerated struct via yunion.io/x/onecloud/pkg/compute/models.SSnapshotPolicyDisk. +type SSnapshotPolicyDisk struct { + apis.SVirtualJointResourceBase + SnapshotpolicyId string `json:"snapshotpolicy_id"` + DiskId string `json:"disk_id"` + Status string `json:"status"` +} + +// SStorage is an autogenerated struct via yunion.io/x/onecloud/pkg/compute/models.SStorage. +type SStorage struct { + apis.SStandaloneResourceBase + apis.SExternalizedResourceBase + SManagedResourceBase + Capacity int64 `json:"capacity"` + Reserved int64 `json:"reserved"` + StorageType string `json:"storage_type"` + MediumType string `json:"medium_type"` + Cmtbound float32 `json:"cmtbound"` + StorageConf jsonutils.JSONObject `json:"storage_conf"` + ZoneId string `json:"zone_id"` + StoragecacheId string `json:"storagecache_id"` + Enabled *bool `json:"enabled,omitempty"` + Status string `json:"status"` + IsSysDiskStore *bool `json:"is_sys_disk_store,omitempty"` +} + +// SStoragecache is an autogenerated struct via yunion.io/x/onecloud/pkg/compute/models.SStoragecache. +type SStoragecache struct { + apis.SStandaloneResourceBase + apis.SExternalizedResourceBase + SManagedResourceBase + Path string `json:"path"` +} + +// SStoragecachedimage is an autogenerated struct via yunion.io/x/onecloud/pkg/compute/models.SStoragecachedimage. +type SStoragecachedimage struct { + apis.SJointResourceBase + StoragecacheId string `json:"storagecache_id"` + CachedimageId string `json:"cachedimage_id"` + ExternalId string `json:"external_id"` + Status string `json:"status"` + Path string `json:"path"` + LastDownload time.Time `json:"last_download"` + DownloadRefcnt int `json:"download_refcnt"` +} + +// SStorageschedtag is an autogenerated struct via yunion.io/x/onecloud/pkg/compute/models.SStorageschedtag. +type SStorageschedtag struct { + SSchedtagJointsBase + StorageId string `json:"storage_id"` +} + +// SSyncableBaseResource is an autogenerated struct via yunion.io/x/onecloud/pkg/compute/models.SSyncableBaseResource. +type SSyncableBaseResource struct { + SyncStatus string `json:"sync_status"` + LastSync time.Time `json:"last_sync"` + LastSyncEndAt time.Time `json:"last_sync_end_at"` +} + +// SVCenter is an autogenerated struct via yunion.io/x/onecloud/pkg/compute/models.SVCenter. +type SVCenter struct { + apis.SEnabledStatusStandaloneResourceBase + Hostname string `json:"hostname"` + Port int `json:"port"` + Account string `json:"account"` + Password string `json:"password"` + LastSync time.Time `json:"last_sync"` + Version string `json:"version"` + Sysinfo jsonutils.JSONObject `json:"sysinfo"` +} + +// SVpc is an autogenerated struct via yunion.io/x/onecloud/pkg/compute/models.SVpc. +type SVpc struct { + apis.SEnabledStatusStandaloneResourceBase + apis.SExternalizedResourceBase + SManagedResourceBase + IsDefault bool `json:"is_default"` + CidrBlock string `json:"cidr_block"` + CloudregionId string `json:"cloudregion_id"` +} + +// SWire is an autogenerated struct via yunion.io/x/onecloud/pkg/compute/models.SWire. +type SWire struct { + apis.SStandaloneResourceBase + apis.SExternalizedResourceBase + Bandwidth int `json:"bandwidth"` + Mtu int `json:"mtu"` + ScheduleRank int `json:"schedule_rank"` + ZoneId string `json:"zone_id"` + VpcId string `json:"vpc_id"` +} + +// SZone is an autogenerated struct via yunion.io/x/onecloud/pkg/compute/models.SZone. +type SZone struct { + apis.SStatusStandaloneResourceBase + apis.SExternalizedResourceBase + Location string `json:"location"` + Contacts string `json:"contacts"` + NameCn string `json:"name_cn"` + ManagerUri string `json:"manager_uri"` + CloudregionId string `json:"cloudregion_id"` +} + +// SZoneResourceBase is an autogenerated struct via yunion.io/x/onecloud/pkg/compute/models.SZoneResourceBase. +type SZoneResourceBase struct { + ZoneId string `json:"zone_id"` +} diff --git a/pkg/apis/identity/assignments.go b/pkg/apis/identity/assignments.go index 06f464fc5b..5bf204e165 100644 --- a/pkg/apis/identity/assignments.go +++ b/pkg/apis/identity/assignments.go @@ -15,35 +15,35 @@ package identity type SIdentityObject struct { - Id string - Name string + Id string `json:"id"` + Name string `json:"name"` } type SDomainObject struct { SIdentityObject - Domain SIdentityObject + Domain SIdentityObject `json:"domain"` } type SFetchDomainObject struct { SIdentityObject - Domain string - DomainId string + Domain string `json:"domain"` + DomainId string `json:"domain_id"` } type SRoleAssignment struct { Scope struct { - Domain SIdentityObject - Project SDomainObject - } - User SDomainObject - Group SDomainObject - Role SDomainObject + Domain SIdentityObject `json:"domain"` + Project SDomainObject `json:"project"` + } `json:"scope"` + User SDomainObject `json:"user"` + Group SDomainObject `json:"group"` + Role SDomainObject `json:"role"` Policies struct { - Project []string - Domain []string - System []string - } + Project []string `json:"project"` + Domain []string `json:"domain"` + System []string `json:"system"` + } `json:"policies"` } // rbacutils.IRbacIdentity interfaces diff --git a/pkg/apis/identity/zz_generated.model.go b/pkg/apis/identity/zz_generated.model.go new file mode 100644 index 0000000000..6b462f44e8 --- /dev/null +++ b/pkg/apis/identity/zz_generated.model.go @@ -0,0 +1,184 @@ +// 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. + +// Code generated by model-api-gen. DO NOT EDIT. + +package identity + +import ( + time "time" + + jsonutils "yunion.io/x/jsonutils" + + "yunion.io/x/onecloud/pkg/apis" +) + +// SAssignment is an autogenerated struct via yunion.io/x/onecloud/pkg/keystone/models.SAssignment. +type SAssignment struct { + apis.SResourceBase + Type string `json:"type"` + ActorId string `json:"actor_id"` + TargetId string `json:"target_id"` + RoleId string `json:"role_id"` + Inherited *bool `json:"inherited,omitempty"` +} + +// SConfigOption is an autogenerated struct via yunion.io/x/onecloud/pkg/keystone/models.SConfigOption. +type SConfigOption struct { + apis.SResourceBase + ResType string `json:"res_type"` + ResId string `json:"res_id"` + Group string `json:"group"` + Option string `json:"option"` + Value jsonutils.JSONObject `json:"value"` +} + +// SCredential is an autogenerated struct via yunion.io/x/onecloud/pkg/keystone/models.SCredential. +type SCredential struct { + apis.SStandaloneResourceBase + UserId string `json:"user_id"` + ProjectId string `json:"project_id"` + Type string `json:"type"` + KeyHash string `json:"key_hash"` + Extra *jsonutils.JSONDict `json:"extra"` + EncryptedBlob string `json:"encrypted_blob"` + Enabled *bool `json:"enabled,omitempty"` +} + +// SDomain is an autogenerated struct via yunion.io/x/onecloud/pkg/keystone/models.SDomain. +type SDomain struct { + apis.SStandaloneResourceBase + Extra *jsonutils.JSONDict `json:"extra"` + Enabled *bool `json:"enabled,omitempty"` + IsDomain *bool `json:"is_domain,omitempty"` + DomainId string `json:"domain_id"` + ParentId string `json:"parent_id"` +} + +// SEnabledIdentityBaseResource is an autogenerated struct via yunion.io/x/onecloud/pkg/keystone/models.SEnabledIdentityBaseResource. +type SEnabledIdentityBaseResource struct { + SIdentityBaseResource + Enabled *bool `json:"enabled,omitempty"` +} + +// SEndpoint is an autogenerated struct via yunion.io/x/onecloud/pkg/keystone/models.SEndpoint. +type SEndpoint struct { + apis.SStandaloneResourceBase + LegacyEndpointId string `json:"legacy_endpoint_id"` + Interface string `json:"interface"` + ServiceId string `json:"service_id"` + Url string `json:"url"` + Extra *jsonutils.JSONDict `json:"extra"` + Enabled *bool `json:"enabled,omitempty"` + RegionId string `json:"region_id"` +} + +// SFederatedUser is an autogenerated struct via yunion.io/x/onecloud/pkg/keystone/models.SFederatedUser. +type SFederatedUser struct { + apis.SResourceBase + Id int `json:"id"` + UserId string `json:"user_id"` + IdpId string `json:"idp_id"` + ProtocolId string `json:"protocol_id"` + UniqueId string `json:"unique_id"` + DisplayName string `json:"display_name"` +} + +// SIdentityBaseResource is an autogenerated struct via yunion.io/x/onecloud/pkg/keystone/models.SIdentityBaseResource. +type SIdentityBaseResource struct { + apis.SStandaloneResourceBase + apis.SDomainizedResourceBase + Extra *jsonutils.JSONDict `json:"extra"` +} + +// SIdentityProvider is an autogenerated struct via yunion.io/x/onecloud/pkg/keystone/models.SIdentityProvider. +type SIdentityProvider struct { + apis.SEnabledStatusStandaloneResourceBase + Driver string `json:"driver"` + Template string `json:"template"` + TargetDomainId string `json:"target_domain_id"` + AutoCreateProject *bool `json:"auto_create_project,omitempty"` + ErrorCount int `json:"error_count"` + SyncStatus string `json:"sync_status"` + LastSync time.Time `json:"last_sync"` + LastSyncEndAt time.Time `json:"last_sync_end_at"` + SyncIntervalSeconds int `json:"sync_interval_seconds"` +} + +// SIdmapping is an autogenerated struct via yunion.io/x/onecloud/pkg/keystone/models.SIdmapping. +type SIdmapping struct { + apis.SResourceBase + PublicId string `json:"public_id"` + IdpId string `json:"idp_id"` + IdpEntityId string `json:"idp_entity_id"` + EntityType string `json:"entity_type"` +} + +// SLocalUser is an autogenerated struct via yunion.io/x/onecloud/pkg/keystone/models.SLocalUser. +type SLocalUser struct { + apis.SResourceBase + Id int `json:"id"` + UserId string `json:"user_id"` + DomainId string `json:"domain_id"` + Name string `json:"name"` + FailedAuthCount int `json:"failed_auth_count"` + FailedAuthAt time.Time `json:"failed_auth_at"` +} + +// SPassword is an autogenerated struct via yunion.io/x/onecloud/pkg/keystone/models.SPassword. +type SPassword struct { + apis.SResourceBase + Id int `json:"id"` + LocalUserId int `json:"local_user_id"` + Password string `json:"password"` + ExpiresAt time.Time `json:"expires_at"` + SelfService bool `json:"self_service"` + PasswordHash string `json:"password_hash"` + CreatedAtInt int64 `json:"created_at_int"` + ExpiresAtInt int64 `json:"expires_at_int"` +} + +// SPolicy is an autogenerated struct via yunion.io/x/onecloud/pkg/keystone/models.SPolicy. +type SPolicy struct { + SEnabledIdentityBaseResource + apis.SSharableBaseResource + Type string `json:"type"` + Blob jsonutils.JSONObject `json:"blob"` +} + +// SRegion is an autogenerated struct via yunion.io/x/onecloud/pkg/keystone/models.SRegion. +type SRegion struct { + apis.SStandaloneResourceBase + ParentRegionId string `json:"parent_region_id"` + Extra *jsonutils.JSONDict `json:"extra"` +} + +// SRole is an autogenerated struct via yunion.io/x/onecloud/pkg/keystone/models.SRole. +type SRole struct { + SIdentityBaseResource + apis.SSharableBaseResource +} + +// SService is an autogenerated struct via yunion.io/x/onecloud/pkg/keystone/models.SService. +type SService struct { + apis.SStandaloneResourceBase + Type string `json:"type"` + Enabled *bool `json:"enabled,omitempty"` + Extra *jsonutils.JSONDict `json:"extra"` +} + +// SUsergroupMembership is an autogenerated struct via yunion.io/x/onecloud/pkg/keystone/models.SUsergroupMembership. +type SUsergroupMembership struct { + apis.SResourceBase + UserId string `json:"user_id"` + GroupId string `json:"group_id"` +} diff --git a/pkg/apis/image/zz_generated.model.go b/pkg/apis/image/zz_generated.model.go new file mode 100644 index 0000000000..e45d56e956 --- /dev/null +++ b/pkg/apis/image/zz_generated.model.go @@ -0,0 +1,57 @@ +// 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. + +// Code generated by model-api-gen. DO NOT EDIT. + +package image + +import ( + "yunion.io/x/onecloud/pkg/apis" +) + +// SGuestImage is an autogenerated struct via yunion.io/x/onecloud/pkg/image/models.SGuestImage. +type SGuestImage struct { + apis.SSharableVirtualResourceBase + Protected *bool `json:"omitempty,protected"` +} + +// SGuestImageJoint is an autogenerated struct via yunion.io/x/onecloud/pkg/image/models.SGuestImageJoint. +type SGuestImageJoint struct { + apis.SJointResourceBase + GuestImageId string `json:"guest_image_id"` + ImageId string `json:"image_id"` +} + +// SImage is an autogenerated struct via yunion.io/x/onecloud/pkg/image/models.SImage. +type SImage struct { + apis.SSharableVirtualResourceBase + Size int64 `json:"size"` + Location string `json:"location"` + DiskFormat string `json:"disk_format"` + Checksum string `json:"checksum"` + FastHash string `json:"fast_hash"` + Owner string `json:"owner"` + MinDiskMB int32 `json:"min_disk_mb"` + MinRamMB int32 `json:"min_ram_mb"` + Protected *bool `json:"omitempty,protected"` + IsStandard *bool `json:"is_standard,omitempty"` + IsGuestImage *bool `json:"is_guest_image,omitempty"` + IsData *bool `json:"is_data,omitempty"` + OssChecksum string `json:"oss_checksum"` +} + +// SImagePeripheral is an autogenerated struct via yunion.io/x/onecloud/pkg/image/models.SImagePeripheral. +type SImagePeripheral struct { + apis.SResourceBase + Id int `json:"id"` + ImageId string `json:"image_id"` +} diff --git a/pkg/apis/zz_generated.model.go b/pkg/apis/zz_generated.model.go new file mode 100644 index 0000000000..4608572323 --- /dev/null +++ b/pkg/apis/zz_generated.model.go @@ -0,0 +1,128 @@ +// 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. + +// Code generated by model-api-gen. DO NOT EDIT. + +package apis + +import ( + time "time" +) + +// SAdminSharableVirtualResourceBase is an autogenerated struct via yunion.io/x/onecloud/pkg/cloudcommon/db.SAdminSharableVirtualResourceBase. +type SAdminSharableVirtualResourceBase struct { + SSharableVirtualResourceBase + Records string `json:"records"` +} + +// SDomainizedResourceBase is an autogenerated struct via yunion.io/x/onecloud/pkg/cloudcommon/db.SDomainizedResourceBase. +type SDomainizedResourceBase struct { + DomainId string `json:"domain_id"` +} + +// SEnabledStatusStandaloneResourceBase is an autogenerated struct via yunion.io/x/onecloud/pkg/cloudcommon/db.SEnabledStatusStandaloneResourceBase. +type SEnabledStatusStandaloneResourceBase struct { + SStatusStandaloneResourceBase + Enabled bool `json:"enabled"` +} + +// SExternalizedResourceBase is an autogenerated struct via yunion.io/x/onecloud/pkg/cloudcommon/db.SExternalizedResourceBase. +type SExternalizedResourceBase struct { + ExternalId string `json:"external_id"` +} + +// SJointResourceBase is an autogenerated struct via yunion.io/x/onecloud/pkg/cloudcommon/db.SJointResourceBase. +type SJointResourceBase struct { + SResourceBase + RowId int64 `json:"row_id"` +} + +// SKeystoneCacheObject is an autogenerated struct via yunion.io/x/onecloud/pkg/cloudcommon/db.SKeystoneCacheObject. +type SKeystoneCacheObject struct { + SStandaloneResourceBase + DomainId string `json:"domain_id"` + Domain string `json:"domain"` + LastCheck time.Time `json:"last_check"` +} + +// SProjectizedResourceBase is an autogenerated struct via yunion.io/x/onecloud/pkg/cloudcommon/db.SProjectizedResourceBase. +type SProjectizedResourceBase struct { + SDomainizedResourceBase + ProjectId string `json:"project_id"` +} + +// SResourceBase is an autogenerated struct via yunion.io/x/onecloud/pkg/cloudcommon/db.SResourceBase. +type SResourceBase struct { + CreatedAt time.Time `json:"created_at"` + UpdatedAt time.Time `json:"updated_at"` + UpdateVersion int `json:"update_version"` + DeletedAt time.Time `json:"deleted_at"` + Deleted bool `json:"deleted"` +} + +// SScopedResourceBase is an autogenerated struct via yunion.io/x/onecloud/pkg/cloudcommon/db.SScopedResourceBase. +type SScopedResourceBase struct { + DomainId string `json:"domain_id"` + ProjectId string `json:"project_id"` +} + +// SSharableBaseResource is an autogenerated struct via yunion.io/x/onecloud/pkg/cloudcommon/db.SSharableBaseResource. +type SSharableBaseResource struct { + IsPublic bool `json:"is_public"` +} + +// SSharableVirtualResourceBase is an autogenerated struct via yunion.io/x/onecloud/pkg/cloudcommon/db.SSharableVirtualResourceBase. +type SSharableVirtualResourceBase struct { + SVirtualResourceBase + IsPublic bool `json:"is_public"` + PublicScope string `json:"public_scope"` +} + +// SSharedResource is an autogenerated struct via yunion.io/x/onecloud/pkg/cloudcommon/db.SSharedResource. +type SSharedResource struct { + SResourceBase + Id int64 `json:"id"` + ResourceType string `json:"resource_type"` + ResourceId string `json:"resource_id"` + OwnerProjectId string `json:"owner_project_id"` + TargetProjectId string `json:"target_project_id"` +} + +// SStandaloneResourceBase is an autogenerated struct via yunion.io/x/onecloud/pkg/cloudcommon/db.SStandaloneResourceBase. +type SStandaloneResourceBase struct { + SResourceBase + Id string `json:"id"` + Name string `json:"name"` + Description string `json:"description"` + IsEmulated bool `json:"is_emulated"` +} + +// SStatusStandaloneResourceBase is an autogenerated struct via yunion.io/x/onecloud/pkg/cloudcommon/db.SStatusStandaloneResourceBase. +type SStatusStandaloneResourceBase struct { + SStandaloneResourceBase + Status string `json:"status"` +} + +// SVirtualJointResourceBase is an autogenerated struct via yunion.io/x/onecloud/pkg/cloudcommon/db.SVirtualJointResourceBase. +type SVirtualJointResourceBase struct { + SJointResourceBase +} + +// SVirtualResourceBase is an autogenerated struct via yunion.io/x/onecloud/pkg/cloudcommon/db.SVirtualResourceBase. +type SVirtualResourceBase struct { + SStatusStandaloneResourceBase + SProjectizedResourceBase + ProjectSrc string `json:"project_src"` + IsSystem bool `json:"is_system"` + PendingDeletedAt time.Time `json:"pending_deleted_at"` + PendingDeleted bool `json:"pending_deleted"` +} diff --git a/pkg/cloudcommon/db/caller.go b/pkg/cloudcommon/db/caller.go new file mode 100644 index 0000000000..5e666f198f --- /dev/null +++ b/pkg/cloudcommon/db/caller.go @@ -0,0 +1,202 @@ +// 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 ( + "context" + "fmt" + "reflect" + + "yunion.io/x/jsonutils" + "yunion.io/x/pkg/gotypes" + "yunion.io/x/sqlchemy" + + "yunion.io/x/onecloud/pkg/httperrors" + "yunion.io/x/onecloud/pkg/mcclient" +) + +type Caller struct { + modelVal reflect.Value + funcName string + inputs []interface{} + + funcVal reflect.Value +} + +func NewCaller(model interface{}, fName string) *Caller { + return &Caller{ + modelVal: reflect.ValueOf(model), + funcName: fName, + } +} + +func (c *Caller) Inputs(inputs ...interface{}) *Caller { + c.inputs = inputs + return c +} + +func (c *Caller) Call() ([]reflect.Value, error) { + return callObject(c.modelVal, c.funcName, c.inputs...) +} + +func call(obj interface{}, fName string, inputs ...interface{}) ([]reflect.Value, error) { + return call(reflect.ValueOf(obj), fName, inputs...) +} + +func callObject(modelVal reflect.Value, fName string, inputs ...interface{}) ([]reflect.Value, error) { + funcVal := modelVal.MethodByName(fName) + return callFunc(funcVal, inputs...) +} + +func callFunc(funcVal reflect.Value, inputs ...interface{}) ([]reflect.Value, error) { + fName := funcVal.String() + if !funcVal.IsValid() || funcVal.IsNil() { + return nil, httperrors.NewActionNotFoundError(fmt.Sprintf("%s method not found", fName)) + } + funcType := funcVal.Type() + paramLen := funcType.NumIn() + if paramLen != len(inputs) { + return nil, httperrors.NewInternalServerError("%s method params length not match, expected %d, input %d", fName, paramLen, len(inputs)) + } + params := make([]*param, paramLen) + for i := range inputs { + params[i] = newParam(funcType.In(i), inputs[i]) + } + args := convertParams(params) + return funcVal.Call(args), nil +} + +func convertParams(params []*param) []reflect.Value { + ret := make([]reflect.Value, 0) + for _, p := range params { + ret = append(ret, p.convert()) + } + return ret +} + +type param struct { + pType reflect.Type + input reflect.Value +} + +func newParam(pType reflect.Type, input interface{}) *param { + return ¶m{ + pType: pType, + input: reflect.ValueOf(input), + } +} + +func isJSONObject(val reflect.Value) (jsonutils.JSONObject, bool) { + obj, ok := val.Interface().(jsonutils.JSONObject) + if !ok { + return nil, false + } + return obj, true +} + +func (p *param) convert() reflect.Value { + obj, ok := isJSONObject(p.input) + if !ok { + return p.input + } + // generate object by type + val := reflect.New(p.pType) + obj.Unmarshal(val.Interface()) + return val.Elem() +} + +func ValueToJSONObject(out reflect.Value) jsonutils.JSONObject { + if obj, ok := isJSONObject(out); ok { + return obj + } + return jsonutils.Marshal(out.Interface()) +} + +func ValueToError(out reflect.Value) error { + errVal := out.Interface() + if !gotypes.IsNil(errVal) { + return errVal.(error) + } + return nil +} + +func ValidateCreateData(manager IModelManager, ctx context.Context, userCred mcclient.TokenCredential, ownerId mcclient.IIdentityProvider, query jsonutils.JSONObject, data *jsonutils.JSONDict) (*jsonutils.JSONDict, error) { + ret, err := call(manager, "ValidateCreateData", userCred, ownerId, query, data) + if err != nil { + return nil, httperrors.NewGeneralError(err) + } + if len(ret) != 2 { + return nil, httperrors.NewInternalServerError("Invald ValidateCreateData return value") + } + resVal := ret[0] + if err := ValueToError(ret[1]); err != nil { + return nil, err + } + return ValueToJSONObject(resVal).(*jsonutils.JSONDict), nil +} + +func ListItemFilter(manager IModelManager, ctx context.Context, q *sqlchemy.SQuery, userCred mcclient.TokenCredential, query jsonutils.JSONObject) (*sqlchemy.SQuery, error) { + ret, err := call(manager, "ListItemFilter", ctx, q, userCred, query) + if err != nil { + return nil, httperrors.NewGeneralError(err) + } + if len(ret) != 2 { + return nil, httperrors.NewInternalServerError("Invald ListItemFilter return value") + } + if err := ValueToError(ret[1]); err != nil { + return nil, err + } + 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) + if err != nil { + return nil, httperrors.NewGeneralError(err) + } + if len(ret) != 2 { + return nil, httperrors.NewInternalServerError("Invald GetExtraDetails return value") + } + if err := ValueToError(ret[1]); err != nil { + return nil, err + } + return ValueToJSONObject(ret[0]).(*jsonutils.JSONDict), nil +} + +func ValidateUpdateData(model IModel, ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject, data *jsonutils.JSONDict) (*jsonutils.JSONDict, error) { + ret, err := call(model, "ValidateUpdateData", userCred, query, data) + if err != nil { + return nil, httperrors.NewGeneralError(err) + } + if len(ret) != 2 { + return nil, httperrors.NewInternalServerError("Invald ValidateUpdateData return value") + } + resVal := ret[0] + if err := ValueToError(ret[1]); err != nil { + return nil, err + } + return ValueToJSONObject(resVal).(*jsonutils.JSONDict), nil +} + +func CustomizeDelete(model IModel, ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject, data jsonutils.JSONObject) error { + ret, err := call(model, "CustomizeDelete", userCred, query, data) + if err != nil { + return httperrors.NewGeneralError(err) + } + if len(ret) != 1 { + return httperrors.NewInternalServerError("Invald CustomizeDelete return value") + } + return ValueToError(ret[0]) +} diff --git a/pkg/cloudcommon/db/caller_test.go b/pkg/cloudcommon/db/caller_test.go new file mode 100644 index 0000000000..6c7784600e --- /dev/null +++ b/pkg/cloudcommon/db/caller_test.go @@ -0,0 +1,119 @@ +// 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 ( + "context" + "reflect" + "testing" + + "yunion.io/x/jsonutils" + "yunion.io/x/log" + + api "yunion.io/x/onecloud/pkg/apis/compute" +) + +func Test_valueToJSONObject(t *testing.T) { + tests := []struct { + name string + args interface{} + want jsonutils.JSONObject + }{ + { + name: "json2json", + args: jsonutils.NewDict(), + want: jsonutils.NewDict(), + }, + { + name: "struct2json", + args: &api.ServerRebuildRootInput{Image: "image"}, + want: jsonutils.Marshal(api.ServerRebuildRootInput{Image: "image"}), + }, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + if got := ValueToJSONObject(reflect.ValueOf(tt.args)); !reflect.DeepEqual(got, tt.want) { + t.Errorf("toJSONObject() = %v, want %v", got, tt.want) + } + }) + } +} + +type fakeModel struct{} + +func (m *fakeModel) PerformAction(ctx context.Context, input *api.ServerRebuildRootInput) *api.SGuest { + log.Infof("input: %#v", input) + out := new(api.SGuest) + out.Id = input.ImageId + return out +} + +func Test_call(t *testing.T) { + type args struct { + modelVal reflect.Value + fName string + inputs []interface{} + } + + fModel := new(fakeModel) + + c1Out := new(api.SGuest) + c1Out.Id = "id" + + tests := []struct { + name string + args args + want []reflect.Value + wantErr bool + }{ + { + name: "input struct", + args: args{ + modelVal: reflect.ValueOf(fModel), + fName: "PerformAction", + inputs: []interface{}{context.TODO(), &api.ServerRebuildRootInput{ImageId: "id"}}, + }, + want: []reflect.Value{reflect.ValueOf(c1Out)}, + wantErr: false, + }, + { + name: "input json object", + args: args{ + modelVal: reflect.ValueOf(fModel), + fName: "PerformAction", + inputs: []interface{}{context.TODO(), jsonutils.Marshal(api.ServerRebuildRootInput{ImageId: "id"})}, + }, + want: []reflect.Value{reflect.ValueOf(c1Out)}, + wantErr: false, + }, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + got, err := callObject(tt.args.modelVal, tt.args.fName, tt.args.inputs...) + if (err != nil) != tt.wantErr { + t.Errorf("call() error = %v, wantErr %v", err, tt.wantErr) + return + } + log.Infof("out1 %s", jsonutils.Marshal(got[0].Interface())) + for i := range got { + gi := got[i].Interface() + wt := tt.want[i].Interface() + if !reflect.DeepEqual(gi, wt) { + t.Errorf("call() = %v, want %v", got, tt.want) + } + } + }) + } +} diff --git a/pkg/cloudcommon/db/db_dispatcher.go b/pkg/cloudcommon/db/db_dispatcher.go index 0702f8a78d..3183bc6228 100644 --- a/pkg/cloudcommon/db/db_dispatcher.go +++ b/pkg/cloudcommon/db/db_dispatcher.go @@ -255,7 +255,7 @@ func listItemQueryFilters(manager IModelManager, q = manager.FilterBySystemAttributes(q, userCred, query, queryScope) q = manager.FilterByHiddenSystemAttributes(q, userCred, query, queryScope) - q, err = manager.ListItemFilter(ctx, q, userCred, query) + q, err = ListItemFilter(manager, ctx, q, userCred, query) if err != nil { return nil, err } @@ -709,7 +709,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 := item.GetExtraDetails(ctx, userCred, query) + extraDict, err := GetExtraDetails(item, ctx, userCred, query) if err != nil { return nil, httperrors.NewGeneralError(err) } @@ -822,11 +822,7 @@ func (dispatcher *DBModelDispatcher) GetSpecific(ctx context.Context, idStr stri return nil, err } - params := []reflect.Value{ - reflect.ValueOf(ctx), - reflect.ValueOf(userCred), - reflect.ValueOf(query), - } + params := []interface{}{ctx, userCred, query} specCamel := utils.Kebab2Camel(spec, "-") modelValue := reflect.ValueOf(model) @@ -844,7 +840,10 @@ func (dispatcher *DBModelDispatcher) GetSpecific(ctx context.Context, idStr stri return nil, httperrors.NewSpecNotFoundError("%s %s %s not found", dispatcher.Keyword(), idStr, spec) } - outs := funcValue.Call(params) + outs, err := callFunc(funcValue, params...) + if err != nil { + return nil, err + } if len(outs) != 1 { return nil, httperrors.NewInternalServerError("Invald %s return value", funcName) } @@ -859,20 +858,23 @@ func (dispatcher *DBModelDispatcher) GetSpecific(ctx context.Context, idStr stri return nil, httperrors.NewSpecNotFoundError("%s %s %s not found", dispatcher.Keyword(), idStr, spec) } - outs := funcValue.Call(params) + outs, err := callFunc(funcValue, params...) + if err != nil { + return nil, err + } if len(outs) != 2 { return nil, httperrors.NewInternalServerError("Invald %s return value", funcName) } - resVal := outs[0].Interface() + resVal := outs[0] errVal := outs[1].Interface() if !gotypes.IsNil(errVal) { return nil, errVal.(error) } else { - if gotypes.IsNil(resVal) { + if gotypes.IsNil(resVal.Interface()) { return nil, nil } else { - return resVal.(jsonutils.JSONObject), nil + return ValueToJSONObject(resVal), nil } } } @@ -1013,7 +1015,7 @@ func _doCreateItem( if batchCreate { dataDict, err = manager.BatchCreateValidateCreateData(ctx, userCred, ownerId, query, dataDict) } else { - dataDict, err = manager.ValidateCreateData(ctx, userCred, ownerId, query, dataDict) + dataDict, err = ValidateCreateData(manager, ctx, userCred, ownerId, query, dataDict) } if err != nil { @@ -1265,7 +1267,7 @@ func managerPerformCheckCreateData( return nil, httperrors.NewForbiddenError("not allow to perform %s", action) } - return manager.ValidateCreateData(ctx, userCred, ownerId, query, bodyDict) + return ValidateCreateData(manager, ctx, userCred, ownerId, query, bodyDict) } func (dispatcher *DBModelDispatcher) PerformClassAction(ctx context.Context, action string, query jsonutils.JSONObject, data jsonutils.JSONObject) (jsonutils.JSONObject, error) { @@ -1358,23 +1360,12 @@ func reflectDispatcherInternal( } } - var params []reflect.Value + var params []interface{} if isGeneral { - params = []reflect.Value{ - reflect.ValueOf(ctx), - reflect.ValueOf(userCred), - reflect.ValueOf(spec), - reflect.ValueOf(query), - reflect.ValueOf(data), - } + params = []interface{}{ctx, userCred, spec, query, data} } else { - params = []reflect.Value{ - reflect.ValueOf(ctx), - reflect.ValueOf(userCred), - reflect.ValueOf(query), - reflect.ValueOf(data), - } + params = []interface{}{ctx, userCred, query, data} } if consts.IsRbacEnabled() { @@ -1402,7 +1393,10 @@ func reflectDispatcherInternal( return nil, httperrors.NewActionNotFoundError(msg) } - outs := allowFuncValue.Call(params) + outs, err := callFunc(allowFuncValue, params...) + if err != nil { + return nil, err + } if len(outs) != 1 { return nil, httperrors.NewInternalServerError("Invald %s return value", allowFuncName) } @@ -1412,19 +1406,22 @@ func reflectDispatcherInternal( } } - outs := funcValue.Call(params) + outs, err := callFunc(funcValue, params...) + if err != nil { + return nil, err + } if len(outs) != 2 { return nil, httperrors.NewInternalServerError("Invald %s return value", funcName) } - resVal := outs[0].Interface() + resVal := outs[0] errVal := outs[1].Interface() if !gotypes.IsNil(errVal) { return nil, errVal.(error) } else { - if gotypes.IsNil(resVal) { + if gotypes.IsNil(resVal.Interface()) { return nil, nil } else { - return resVal.(jsonutils.JSONObject), nil + return ValueToJSONObject(resVal), nil } } } @@ -1452,7 +1449,7 @@ func updateItem(manager IModelManager, item IModel, ctx context.Context, userCre } } - dataDict, err = item.ValidateUpdateData(ctx, userCred, query, dataDict) + dataDict, err = ValidateUpdateData(item, ctx, userCred, query, dataDict) if err != nil { errMsg := fmt.Sprintf("validate update data error: %s", err) log.Errorf(errMsg) @@ -1563,7 +1560,7 @@ func deleteItem(manager IModelManager, model IModel, ctx context.Context, userCr return nil, err } - err = model.CustomizeDelete(ctx, userCred, query, data) + err = CustomizeDelete(model, ctx, userCred, query, data) if err != nil { log.Errorf("customize delete error: %s", err) return nil, httperrors.NewNotAcceptableError(err.Error()) diff --git a/pkg/cloudcommon/db/interface.go b/pkg/cloudcommon/db/interface.go index f4af6e6154..2168c3d4f0 100644 --- a/pkg/cloudcommon/db/interface.go +++ b/pkg/cloudcommon/db/interface.go @@ -52,7 +52,8 @@ type IModelManager interface { // list hooks AllowListItems(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject) bool ValidateListConditions(ctx context.Context, userCred mcclient.TokenCredential, query *jsonutils.JSONDict) (*jsonutils.JSONDict, error) - ListItemFilter(ctx context.Context, q *sqlchemy.SQuery, userCred mcclient.TokenCredential, query jsonutils.JSONObject) (*sqlchemy.SQuery, error) + // ListItemFilter dynamic called by dispatcher + // ListItemFilter(ctx context.Context, q *sqlchemy.SQuery, userCred mcclient.TokenCredential, query jsonutils.JSONObject) (*sqlchemy.SQuery, error) CustomizeFilterList(ctx context.Context, q *sqlchemy.SQuery, userCred mcclient.TokenCredential, query jsonutils.JSONObject) (*CustomizeListFilters, error) ExtraSearchConditions(ctx context.Context, q *sqlchemy.SQuery, like string) []sqlchemy.ICondition GetExportExtraKeys(ctx context.Context, query jsonutils.JSONObject, rowMap map[string]string) *jsonutils.JSONDict @@ -80,7 +81,8 @@ type IModelManager interface { // create hooks AllowCreateItem(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject, data jsonutils.JSONObject) bool BatchCreateValidateCreateData(ctx context.Context, userCred mcclient.TokenCredential, ownerId mcclient.IIdentityProvider, query jsonutils.JSONObject, data *jsonutils.JSONDict) (*jsonutils.JSONDict, error) - ValidateCreateData(ctx context.Context, userCred mcclient.TokenCredential, ownerId mcclient.IIdentityProvider, query jsonutils.JSONObject, data *jsonutils.JSONDict) (*jsonutils.JSONDict, error) + // ValidateCreateData dynamic called by dispatcher + // ValidateCreateData(ctx context.Context, userCred mcclient.TokenCredential, ownerId mcclient.IIdentityProvider, query jsonutils.JSONObject, data *jsonutils.JSONDict) (*jsonutils.JSONDict, error) OnCreateComplete(ctx context.Context, items []IModel, userCred mcclient.TokenCredential, query jsonutils.JSONObject, data jsonutils.JSONObject) BatchPreValidate(ctx context.Context, userCred mcclient.TokenCredential, ownerId mcclient.IIdentityProvider, query jsonutils.JSONObject, data *jsonutils.JSONDict, count int) (func(), error) @@ -139,7 +141,8 @@ type IModel interface { // get hooks AllowGetDetails(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject) bool - GetExtraDetails(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject) (*jsonutils.JSONDict, error) + // GetExtraDetails dynamic call by model dispatcher + // GetExtraDetails(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject) (*jsonutils.JSONDict, error) GetExtraDetailsHeaders(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject) map[string]string // create hooks @@ -154,7 +157,7 @@ type IModel interface { ValidateUpdateCondition(ctx context.Context) error AllowUpdateItem(ctx context.Context, userCred mcclient.TokenCredential) bool - ValidateUpdateData(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject, data *jsonutils.JSONDict) (*jsonutils.JSONDict, error) + // ValidateUpdateData(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject, data *jsonutils.JSONDict) (*jsonutils.JSONDict, error) PreUpdate(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject, data jsonutils.JSONObject) PostUpdate(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject, data jsonutils.JSONObject) @@ -163,7 +166,7 @@ type IModel interface { // delete hooks AllowDeleteItem(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject, data jsonutils.JSONObject) bool ValidateDeleteCondition(ctx context.Context) error - CustomizeDelete(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject, data jsonutils.JSONObject) error + // CustomizeDelete(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject, data jsonutils.JSONObject) error PreDelete(ctx context.Context, userCred mcclient.TokenCredential) MarkDelete() error Delete(ctx context.Context, userCred mcclient.TokenCredential) error diff --git a/pkg/cloudcommon/db/models.go b/pkg/cloudcommon/db/models.go index fea3d9d469..7e46656ad5 100644 --- a/pkg/cloudcommon/db/models.go +++ b/pkg/cloudcommon/db/models.go @@ -29,6 +29,10 @@ import ( var globalTables map[string]IModelManager +func GlobalModelManagerTables() map[string]IModelManager { + return globalTables +} + func RegisterModelManager(modelMan IModelManager) { if globalTables == nil { globalTables = make(map[string]IModelManager) diff --git a/pkg/cloudprovider/geoinfo.go b/pkg/cloudprovider/geoinfo.go index 7042ebf452..00a23c4ec2 100644 --- a/pkg/cloudprovider/geoinfo.go +++ b/pkg/cloudprovider/geoinfo.go @@ -14,6 +14,7 @@ package cloudprovider +// +onecloud:model-api-gen type SGeographicInfo struct { Latitude float32 `list:"user" update:"admin" create:"admin_optional"` Longitude float32 `list:"user" update:"admin" create:"admin_optional"` diff --git a/pkg/compute/models/buckets.go b/pkg/compute/models/buckets.go index e8d52a9b22..a9aa624aec 100644 --- a/pkg/compute/models/buckets.go +++ b/pkg/compute/models/buckets.go @@ -391,8 +391,9 @@ func (manager *SBucketManager) ValidateCreateData( userCred mcclient.TokenCredential, ownerId mcclient.IIdentityProvider, query jsonutils.JSONObject, - data *jsonutils.JSONDict, + input *api.BucketCreateInput, ) (*jsonutils.JSONDict, error) { + data := input.JSON(input) cloudRegionV := validators.NewModelIdOrNameValidator("cloudregion", CloudregionManager.Keyword(), ownerId) managerV := validators.NewModelIdOrNameValidator("manager", CloudproviderManager.Keyword(), ownerId) for _, v := range []validators.IValidator{ @@ -492,12 +493,15 @@ func (bucket *SBucket) GetCustomizeColumns(ctx context.Context, userCred mcclien return bucket.getMoreDetails(extra) } -func (bucket *SBucket) GetExtraDetails(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject) (*jsonutils.JSONDict, error) { +func (bucket *SBucket) GetExtraDetails(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject) (*api.BucketDetail, error) { extra, err := bucket.SVirtualResourceBase.GetExtraDetails(ctx, userCred, query) if err != nil { return nil, err } - return bucket.getMoreDetails(extra), nil + ret := bucket.getMoreDetails(extra) + out := new(api.BucketDetail) + err = ret.Unmarshal(out) + return out, err } func joinPath(ep, path string) string { diff --git a/pkg/compute/models/guest_actions.go b/pkg/compute/models/guest_actions.go index 5616ec7db0..fab9450aa8 100644 --- a/pkg/compute/models/guest_actions.go +++ b/pkg/compute/models/guest_actions.go @@ -1303,13 +1303,8 @@ func (self *SGuest) AllowPerformRebuildRoot(ctx context.Context, userCred mcclie return self.IsOwner(userCred) || db.IsAdminAllowPerform(userCred, self, "rebuild-root") } -func (self *SGuest) PerformRebuildRoot(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject, data jsonutils.JSONObject) (jsonutils.JSONObject, error) { - input := api.ServerRebuildRootInput{} - err := data.Unmarshal(&input) - if err != nil { - return nil, httperrors.NewInputParameterError("invalid input: %s", err) - } - +// 重装系统(更换系统镜像) +func (self *SGuest) PerformRebuildRoot(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject, input *api.ServerRebuildRootInput) (*api.SGuest, error) { imageId := input.GetImageName() if len(imageId) > 0 { diff --git a/pkg/compute/models/guests.go b/pkg/compute/models/guests.go index 0296de07ed..5f002b1aba 100644 --- a/pkg/compute/models/guests.go +++ b/pkg/compute/models/guests.go @@ -1269,6 +1269,7 @@ func (manager *SGuestManager) BatchCreateValidateCreateData(ctx context.Context, return input.JSON(input), nil } +// 创建虚拟机实例 func (manager *SGuestManager) ValidateCreateData(ctx context.Context, userCred mcclient.TokenCredential, ownerId mcclient.IIdentityProvider, query jsonutils.JSONObject, data *jsonutils.JSONDict) (*jsonutils.JSONDict, error) { input, err := manager.validateCreateData(ctx, userCred, ownerId, query, data) if err != nil { diff --git a/pkg/image/service/handlers.go b/pkg/image/service/handlers.go index fabfec9666..2579dfc427 100644 --- a/pkg/image/service/handlers.go +++ b/pkg/image/service/handlers.go @@ -28,7 +28,7 @@ const ( API_VERSION = "v1" ) -func initHandlers(app *appsrv.Application) { +func InitHandlers(app *appsrv.Application) { db.InitAllManagers() // add version handler with API_VERSION prefix diff --git a/pkg/image/service/service.go b/pkg/image/service/service.go index 1afb5ca686..fdea2d54b8 100644 --- a/pkg/image/service/service.go +++ b/pkg/image/service/service.go @@ -89,7 +89,7 @@ func StartService() { } app := app_common.InitApp(baseOpts, true) - initHandlers(app) + InitHandlers(app) db.EnsureAppInitSyncDB(app, dbOpts, models.InitDB) diff --git a/pkg/keystone/service/handlers.go b/pkg/keystone/service/handlers.go index 75fa145292..fc5fafac65 100644 --- a/pkg/keystone/service/handlers.go +++ b/pkg/keystone/service/handlers.go @@ -28,7 +28,7 @@ const ( API_VERSION = "v3" ) -func initHandlers(app *appsrv.Application) { +func InitHandlers(app *appsrv.Application) { db.InitAllManagers() // add version handler with API_VERSION prefix diff --git a/pkg/keystone/service/service.go b/pkg/keystone/service/service.go index 94149abfa3..612f0cf8e3 100644 --- a/pkg/keystone/service/service.go +++ b/pkg/keystone/service/service.go @@ -70,7 +70,7 @@ func StartService() { */ app := app_common.InitApp(&opts.BaseOptions, true) - initHandlers(app) + InitHandlers(app) db.EnsureAppInitSyncDB(app, &opts.DBOptions, models.InitDB) diff --git a/pkg/keystone/tokens/auth.go b/pkg/keystone/tokens/auth.go index 80626ae3a9..63291e1377 100644 --- a/pkg/keystone/tokens/auth.go +++ b/pkg/keystone/tokens/auth.go @@ -248,6 +248,13 @@ func authUserByAccessKeyV3(ctx context.Context, input mcclient.SAuthenticationIn return usrExt, credential.ProjectId, aksk, nil } +// +onecloud:swagger-gen-route-method=POST +// +onecloud:swagger-gen-route-path=/v3/auth/tokens +// +onecloud:swagger-gen-route-tag=authentication +// +onecloud:swagger-gen-param-body-index=1 +// +onecloud:swagger-gen-resp-index=0 + +// keystone keystone v3认证API func AuthenticateV3(ctx context.Context, input mcclient.SAuthenticationInputV3) (*mcclient.TokenCredentialV3, error) { var akskInfo api.SAccessKeySecretInfo var user *api.SUserExtended @@ -346,6 +353,13 @@ func AuthenticateV3(ctx context.Context, input mcclient.SAuthenticationInputV3) return tokenV3, nil } +// +onecloud:swagger-gen-route-method=POST +// +onecloud:swagger-gen-route-path=/v2.0/tokens +// +onecloud:swagger-gen-route-tag=authentication +// +onecloud:swagger-gen-param-body-index=1 +// +onecloud:swagger-gen-resp-index=0 + +// keystone v2 认证接口,通过用户名/密码或者 token 认证 func AuthenticateV2(ctx context.Context, input mcclient.SAuthenticationInputV2) (*mcclient.TokenCredentialV2, error) { var user *api.SUserExtended var err error diff --git a/pkg/mcclient/input.go b/pkg/mcclient/input.go index 3780f9b979..28b2192a4d 100644 --- a/pkg/mcclient/input.go +++ b/pkg/mcclient/input.go @@ -42,14 +42,22 @@ type SAuthenticationInputV2 struct { } type SAuthenticationIdentity struct { - Methods []string `json:"methods,omitempty"` + // 认证方式列表 + Methods []string `json:"methods,omitempty"` + // 密码认证信息 Password struct { User struct { - Id string `json:"id,omitempty"` - Name string `json:"name,omitempty"` + // 用户ID + Id string `json:"id,omitempty"` + // 用户名称 + Name string `json:"name,omitempty"` + // 密码 Password string `json:"password,omitempty"` - Domain struct { - Id string `json:"id,omitempty"` + // 域的信息 + Domain struct { + // 域ID + Id string `json:"id,omitempty"` + // 域名称 Name string `json:"name,omitempty"` } } `json:"user,omitempty"` diff --git a/pkg/mcclient/token2.go b/pkg/mcclient/token2.go index 1f8b05a25c..dedf117c20 100644 --- a/pkg/mcclient/token2.go +++ b/pkg/mcclient/token2.go @@ -27,61 +27,61 @@ import ( ) type KeystoneEndpointV2 struct { - Id string - InternalURL string - PublicURL string - AdminURL string - Region string + Id string `json:"id"` + InternalURL string `json:"internal_url"` + PublicURL string `json:"public_url"` + AdminURL string `json:"admin_url"` + Region string `json:"region"` } type KeystoneServiceV2 struct { - Name string - Type string - Endpoints []KeystoneEndpointV2 + Name string `json:"name"` + Type string `json:"type"` + Endpoints []KeystoneEndpointV2 `json:"endpoints"` } type KeystoneRoleV2 struct { - Name string + Name string `json:"name"` } type KeystoneUserV2 struct { - Id string - Name string - Username string - Roles []KeystoneRoleV2 + Id string `json:"id"` + Name string `json:"name"` + Username string `json:"username"` + Roles []KeystoneRoleV2 `json:"roles"` } type KeystoneTenantV2 struct { - Id string - Name string - Enabled bool - Description string + Id string `json:"id"` + Name string `json:"name"` + Enabled bool `json:"enabled"` + Description string `json:"description"` Domain struct { - Id string - Name string - } + Id string `json:"id"` + Name string `json:"name"` + } `json:"domain"` } type KeystoneTokenV2 struct { - Id string - Expires time.Time - Tenant KeystoneTenantV2 + Id string `json:"id"` + Expires time.Time `json:"expires"` + Tenant KeystoneTenantV2 `json:"tenant"` } type KeystoneMetadataV2 struct { - IsAdmin int - Roles []string + IsAdmin int `json:"is_admin"` + Roles []string `json:"roles"` } type KeystoneServiceCatalogV2 []KeystoneServiceV2 type TokenCredentialV2 struct { - Token KeystoneTokenV2 - ServiceCatalog KeystoneServiceCatalogV2 - User KeystoneUserV2 - Tenants []KeystoneTenantV2 - Metadata KeystoneMetadataV2 - Context SAuthContext + Token KeystoneTokenV2 `json:"token"` + ServiceCatalog KeystoneServiceCatalogV2 `json:"service_catalog"` + User KeystoneUserV2 `json:"user"` + Tenants []KeystoneTenantV2 `json:"tenants"` + Metadata KeystoneMetadataV2 `json:"metadata"` + Context SAuthContext `json:"context"` } func (token *TokenCredentialV2) GetTokenString() string { diff --git a/pkg/notify/dispatcher.go b/pkg/notify/dispatcher.go index c0788edf31..97160bc8a0 100644 --- a/pkg/notify/dispatcher.go +++ b/pkg/notify/dispatcher.go @@ -450,7 +450,7 @@ func DeleteItem(model db.IModel, ctx context.Context, userCred mcclient.TokenCre log.Errorf("validate delete condition error: %s", err) return err } - err = model.CustomizeDelete(ctx, userCred, query, data) + err = db.CustomizeDelete(model, ctx, userCred, query, data) if err != nil { log.Errorf("customize delete error: %s", err) return httperrors.NewNotAcceptableError(err.Error()) @@ -482,7 +482,7 @@ func UpdateItem(manager db.IModelManager, item db.IModel, ctx context.Context, u return httperrors.NewInternalServerError("Invalid data JSONObject") } - dataDict, err = item.ValidateUpdateData(ctx, userCred, query, dataDict) + dataDict, err = db.ValidateUpdateData(item, ctx, userCred, query, dataDict) if err != nil { errMsg := fmt.Sprintf("validate update data error: %s", err) log.Errorf(errMsg) diff --git a/scripts/codegen.sh b/scripts/codegen.sh new file mode 100755 index 0000000000..0c36593df9 --- /dev/null +++ b/scripts/codegen.sh @@ -0,0 +1,104 @@ +#!/bin/bash + +set -o errexit +set -o pipefail + +ONECLOUD="yunion.io/x/onecloud" +PKG_ONECLOUD="$ONECLOUD/pkg" +PKG_APIS="$PKG_ONECLOUD/apis" +PKG_GENERATED="$PKG_ONECLOUD/generated" +PKG_SWAGGER="$PKG_GENERATED/swagger" + +MODEL_API_PKG_MAP=( + "$PKG_ONECLOUD/cloudcommon/db:$PKG_APIS" + "$PKG_ONECLOUD/cloudprovider:$PKG_APIS/cloudprovider" + "$PKG_ONECLOUD/compute/models:$PKG_APIS/compute" + "$PKG_ONECLOUD/image/models:$PKG_APIS/image" + "$PKG_ONECLOUD/keystone/models:$PKG_APIS/identity" +) + +MODEL_SWAGGER_PKG_MAP=( + "$PKG_ONECLOUD/compute/models:$PKG_SWAGGER/compute" + "$PKG_ONECLOUD/image/models:$PKG_SWAGGER/image" + "$PKG_ONECLOUD/keystone/models:$PKG_SWAGGER/identity" +) + +CURDIR="$(dirname $(dirname $0))" +DOCS_DIR="$CURDIR/docs" +OUTPUT_DIR="$CURDIR/_output" +OUTPUT_SWAGGER_DIR="$OUTPUT_DIR/swagger" + +generate_model_api() { + for pkg_path in "${MODEL_API_PKG_MAP[@]}"; do + model_pkg="${pkg_path%%:*}" + api_pkg="${pkg_path##*:}" + model-api-gen \ + --input-dirs $model_pkg \ + --output-package $api_pkg + done +} + +generate_swagger_spec() { +# for pkg_path in "${MODEL_SWAGGER_PKG_MAP[@]}"; do +# model_pkg="${pkg_path%%:*}" +# swaager_pkg="${pkg_path##*:}" +# swagger-gen \ +# --input-dirs $model_pkg \ +# --output-package $swaager_pkg +# done + swagger-gen \ + -i "$PKG_ONECLOUD/compute/models" \ + -p "$PKG_SWAGGER/compute" + + swagger-gen \ + -i "$PKG_ONECLOUD/image/models" \ + -p "$PKG_SWAGGER/image" + + swagger-gen \ + -i "$PKG_ONECLOUD/keystone/tokens" \ + -i "$PKG_ONECLOUD/keystone/models" \ + -p "$PKG_SWAGGER/identity" +} + +generate_swagger_yaml() { + mkdir -p "$OUTPUT_SWAGGER_DIR" + for pkg_path in "${MODEL_SWAGGER_PKG_MAP[@]}"; do + model_pkg="${pkg_path%%:*}" + swaager_pkg="${pkg_path##*:}" + work_dir=${swaager_pkg#"$ONECLOUD"} + GO111MODULE=off swagger generate spec \ + --scan-models \ + --work-dir="$CURDIR/$work_dir" \ + -o "$OUTPUT_SWAGGER_DIR/swagger_$(basename $swaager_pkg).yaml" + done +} + +generate_swagger_serve() { + input_files="$(find $OUTPUT_SWAGGER_DIR -name 'swagger_*.yaml' -type f | paste -sd,)" + swagger-serve generate -i "$input_files" -o "$OUTPUT_SWAGGER_DIR" --serve +} + +show_help() { + cat < +Subcommands: + model_api: genereate model struct code + swagger_spec: generate swagger spec code + swagger_serve: generate swagger web site +EOF +} + +subcmd=$1 +case $subcmd in + "" | "-h" | "--help") + show_help + ;; + *) + shift + generate_${subcmd} $@ + if [ $? = 127 ]; then + echo "Run --help for a list of known subcommands." >&2 + exit 1 + fi + ;; +esac