From b47ee82112b0b78f9e9f5d4a82eb25f7912def74 Mon Sep 17 00:00:00 2001 From: Qu Xuan Date: Wed, 11 Mar 2020 18:32:06 +0800 Subject: [PATCH] =?UTF-8?q?hotfix:=20=E6=94=AF=E6=8C=81=E6=9B=B4=E6=96=B0?= =?UTF-8?q?=E4=BA=91=E8=B4=A6=E5=8F=B7=E5=AF=86=E7=A0=81=E6=97=B6=E6=B5=8B?= =?UTF-8?q?=E8=AF=95=E8=B4=A6=E5=8F=B7=E8=BF=9E=E9=80=9A=E6=80=A7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- cmd/climc/shell/cloudaccounts.go | 127 +++++++++++++++++++++++++ pkg/apis/compute/zz_generated.model.go | 62 ++++++------ pkg/compute/models/cloudaccounts.go | 24 +++++ 3 files changed, 186 insertions(+), 27 deletions(-) diff --git a/cmd/climc/shell/cloudaccounts.go b/cmd/climc/shell/cloudaccounts.go index b7846c8b39..c51245c704 100644 --- a/cmd/climc/shell/cloudaccounts.go +++ b/cmd/climc/shell/cloudaccounts.go @@ -722,6 +722,133 @@ func init() { return nil }) + R(&options.SVMwareCloudAccountUpdateCredentialOptions{}, "cloud-account-test-connectivity-vmware", "Update credential of a VMware cloud account", func(s *mcclient.ClientSession, args *options.SVMwareCloudAccountUpdateCredentialOptions) error { + params := jsonutils.Marshal(args) + result, err := modules.Cloudaccounts.PerformAction(s, args.ID, "test-connectivity", params) + if err != nil { + return err + } + printObject(result) + return nil + }) + + R(&options.SAliyunCloudAccountUpdateCredentialOptions{}, "cloud-account-test-connectivity-aliyun", "Update credential of an Aliyun cloud account", func(s *mcclient.ClientSession, args *options.SAliyunCloudAccountUpdateCredentialOptions) error { + params := jsonutils.Marshal(args) + result, err := modules.Cloudaccounts.PerformAction(s, args.ID, "test-connectivity", params) + if err != nil { + return err + } + printObject(result) + return nil + }) + + R(&options.SAzureCloudAccountUpdateCredentialOptions{}, "cloud-account-test-connectivity-azure", "Update credential of an Azure cloud account", func(s *mcclient.ClientSession, args *options.SAzureCloudAccountUpdateCredentialOptions) error { + params := jsonutils.Marshal(args) + result, err := modules.Cloudaccounts.PerformAction(s, args.ID, "test-connectivity", params) + if err != nil { + return err + } + printObject(result) + return nil + }) + + R(&options.SQcloudCloudAccountUpdateCredentialOptions{}, "cloud-account-test-connectivity-qcloud", "Update credential of a Qcloud cloud account", func(s *mcclient.ClientSession, args *options.SQcloudCloudAccountUpdateCredentialOptions) error { + params := jsonutils.Marshal(args) + result, err := modules.Cloudaccounts.PerformAction(s, args.ID, "test-connectivity", params) + if err != nil { + return err + } + printObject(result) + return nil + }) + + R(&options.SAWSCloudAccountUpdateCredentialOptions{}, "cloud-account-test-connectivity-aws", "Update credential of an AWS cloud account", func(s *mcclient.ClientSession, args *options.SAWSCloudAccountUpdateCredentialOptions) error { + params := jsonutils.Marshal(args) + result, err := modules.Cloudaccounts.PerformAction(s, args.ID, "test-connectivity", params) + if err != nil { + return err + } + printObject(result) + return nil + }) + + R(&options.SOpenStackCloudAccountUpdateCredentialOptions{}, "cloud-account-test-connectivity-openstack", "Update credential of an OpenStack cloud account", func(s *mcclient.ClientSession, args *options.SOpenStackCloudAccountUpdateCredentialOptions) error { + params := jsonutils.Marshal(args) + result, err := modules.Cloudaccounts.PerformAction(s, args.ID, "test-connectivity", params) + if err != nil { + return err + } + printObject(result) + return nil + }) + + R(&options.SHuaweiCloudAccountUpdateCredentialOptions{}, "cloud-account-test-connectivity-huawei", "Update credential of an Huawei cloud account", func(s *mcclient.ClientSession, args *options.SHuaweiCloudAccountUpdateCredentialOptions) error { + params := jsonutils.Marshal(args) + result, err := modules.Cloudaccounts.PerformAction(s, args.ID, "test-connectivity", params) + if err != nil { + return err + } + printObject(result) + return nil + }) + + R(&options.SUcloudCloudAccountUpdateCredentialOptions{}, "cloud-account-test-connectivity-ucloud", "Update credential of a Ucloud cloud account", func(s *mcclient.ClientSession, args *options.SUcloudCloudAccountUpdateCredentialOptions) error { + params := jsonutils.Marshal(args) + result, err := modules.Cloudaccounts.PerformAction(s, args.ID, "test-connectivity", params) + if err != nil { + return err + } + printObject(result) + return nil + }) + + R(&options.SZStackCloudAccountUpdateCredentialOptions{}, "cloud-account-test-connectivity-zstack", "Update credential of a ZStack cloud account", func(s *mcclient.ClientSession, args *options.SZStackCloudAccountUpdateCredentialOptions) error { + params := jsonutils.Marshal(args) + result, err := modules.Cloudaccounts.PerformAction(s, args.ID, "test-connectivity", params) + if err != nil { + return err + } + printObject(result) + return nil + }) + + R(&options.SGoogleCloudAccountUpdateCredentialOptions{}, "cloud-account-test-connectivity-google", "Update credential of a Google cloud account", func(s *mcclient.ClientSession, args *options.SGoogleCloudAccountUpdateCredentialOptions) error { + data, err := ioutil.ReadFile(args.GoogleJsonFile) + if err != nil { + return err + } + params, err := jsonutils.Parse(data) + if err != nil { + return err + } + result, err := modules.Cloudaccounts.PerformAction(s, args.ID, "test-connectivity", params) + if err != nil { + return err + } + printObject(result) + return nil + }) + + R(&options.SS3CloudAccountUpdateCredentialOptions{}, "cloud-account-test-connectivity-s3", "Update credential of a generic S3 cloud account", func(s *mcclient.ClientSession, args *options.SS3CloudAccountUpdateCredentialOptions) error { + params := jsonutils.Marshal(args) + result, err := modules.Cloudaccounts.PerformAction(s, args.ID, "test-connectivity", params) + if err != nil { + return err + } + printObject(result) + return nil + }) + + R(&options.SCtyunCloudAccountUpdateCredentialOptions{}, "cloud-account-test-connectivity-ctyun", "Update credential of an Ctyun cloud account", func(s *mcclient.ClientSession, args *options.SCtyunCloudAccountUpdateCredentialOptions) error { + params := jsonutils.Marshal(args) + result, err := modules.Cloudaccounts.PerformAction(s, args.ID, "test-connectivity", params) + if err != nil { + return err + } + printObject(result) + return nil + }) + type CloudaccountSyncOptions struct { ID string `help:"ID or Name of cloud account"` Force bool `help:"Force sync no matter what"` diff --git a/pkg/apis/compute/zz_generated.model.go b/pkg/apis/compute/zz_generated.model.go index 7e680ab792..c3222b91f8 100644 --- a/pkg/apis/compute/zz_generated.model.go +++ b/pkg/apis/compute/zz_generated.model.go @@ -625,37 +625,41 @@ type SElasticcacheSku struct { LocalCategory string `json:"local_category"` PrepaidStatus string `json:"prepaid_status"` PostpaidStatus string `json:"postpaid_status"` - Engine string `json:"engine"` // 引擎 redis|memcached - EngineVersion string `json:"engine_version"` + Engine string `json:"engine"` // 引擎版本 3.0 - CpuArch string `json:"cpu_arch"` + EngineVersion string `json:"engine_version"` // CPU 架构 x86|ARM - StorageType string `json:"storage_type"` + CpuArch string `json:"cpu_arch"` // 存储类型 DRAM|SCM - PerformanceType string `json:"performance_type"` + StorageType string `json:"storage_type"` // standrad|enhanced - NodeType string `json:"node_type"` - MemorySizeMB int `json:"memory_size_mb"` + PerformanceType string `json:"performance_type"` + // single(单副本) | double(双副本) | readone (单可读) | readthree (3可读) | readfive(5只读) + NodeType string `json:"node_type"` // 内存容量 - DiskSizeGB int `json:"disk_size_gb"` + MemorySizeMB int `json:"memory_size_mb"` // 套餐附带硬盘容量 - ShardNum int `json:"shard_num"` + DiskSizeGB int `json:"disk_size_gb"` // 最小分片数量 - MaxShardNum int `json:"max_shard_num"` + ShardNum int `json:"shard_num"` // 最大分片数量 - ReplicasNum int `json:"replicas_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"` + MaxClients int `json:"max_clients"` // 最大连接数 - MaxInBandwidthMb int `json:"max_in_bandwidth_mb"` + MaxConnections int `json:"max_connections"` // 最大内网带宽 - MaxMemoryMB int `json:"max_memory_mb"` + MaxInBandwidthMb int `json:"max_in_bandwidth_mb"` // 实际可使用的最大内存 - QPS int `json:"qps"` + MaxMemoryMB int `json:"max_memory_mb"` + // QPS参考值 + QPS int `json:"qps"` + // 公有云厂商 Aliyun/Azure/AWS/Qcloud/... Provider string `json:"provider"` } @@ -669,8 +673,10 @@ type SElasticip struct { // IP子网Id, 仅私有云不为空 NetworkId string `json:"network_id"` // 标识弹性或非弹性 - // public_ip: 公网IP - // elastic_ip: 弹性公网IP + // | Mode | 说明 | + // |------------|------------| + // | public_ip | 公网IP | + // | elastic_ip | 弹性公网IP | // example: elastic_ip Mode string `json:"mode"` // IP地址 @@ -816,6 +822,7 @@ type SGuestTemplate struct { // SGuestdisk is an autogenerated struct via yunion.io/x/onecloud/pkg/compute/models.SGuestdisk. type SGuestdisk struct { SGuestJointsBase + // SDiskResourceBase `list:"user" create:"required"` DiskId string `json:"disk_id"` ImagePath string `json:"image_path"` Driver string `json:"driver"` @@ -834,22 +841,23 @@ type SGuestdisk struct { type SGuestnetwork struct { SGuestJointsBase NetworkId string `json:"network_id"` - // Column(VARCHAR(36, charset='ascii'), nullable=False) + // MAC地址 MacAddr string `json:"mac_addr"` - // Column(VARCHAR(32, charset='ascii'), nullable=False) + // IPv4地址 IpAddr string `json:"ip_addr"` - // Column(VARCHAR(16, charset='ascii'), nullable=True) + // IPv6地址 Ip6Addr string `json:"ip6_addr"` - // Column(VARCHAR(64, charset='ascii'), nullable=True) + // 虚拟网卡驱动 Driver string `json:"driver"` - // Column(VARCHAR(16, charset='ascii'), nullable=True) + // 带宽限制,单位mbps BwLimit int `json:"bw_limit"` - // Column(Integer, nullable=False, default=0) # Mbps + // 网卡序号 Index byte `json:"index"` - // Column(TINYINT, nullable=False, default=0) + // 是否为虚拟接口(无IP) Virtual bool `json:"virtual"` - // Column(Boolean, default=False) - Ifname string `json:"ifname"` + // 虚拟网卡设备名称 + Ifname string `json:"ifname"` + // bind配对网卡MAC地址 TeamWith string `json:"team_with"` } diff --git a/pkg/compute/models/cloudaccounts.go b/pkg/compute/models/cloudaccounts.go index 23f0a63ca8..76730fc1f8 100644 --- a/pkg/compute/models/cloudaccounts.go +++ b/pkg/compute/models/cloudaccounts.go @@ -453,6 +453,30 @@ func (self *SCloudaccount) PerformSync(ctx context.Context, userCred mcclient.To return nil, err } +func (self *SCloudaccount) AllowPerformTestConnectivity(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject, data jsonutils.JSONObject) bool { + return db.IsAdminAllowPerform(userCred, self, "test-connectivity") +} + +// 测试账号连通性(更新秘钥信息时) +func (self *SCloudaccount) PerformTestConnectivity(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject, input cloudprovider.SCloudaccountCredential) (jsonutils.JSONObject, error) { + providerDriver, err := self.GetProviderFactory() + if err != nil { + return nil, httperrors.NewBadRequestError("failed to found provider factory error: %v", err) + } + + account, err := providerDriver.ValidateUpdateCloudaccountCredential(ctx, userCred, input, self.Account) + if err != nil { + return nil, err + } + + _, err = cloudprovider.IsValidCloudAccount(self.AccessUrl, account.Account, account.Secret, self.Provider) + if err != nil { + return nil, httperrors.NewInputParameterError("invalid cloud account info error: %s", err.Error()) + } + + return nil, nil +} + func (self *SCloudaccount) AllowPerformUpdateCredential(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject, data jsonutils.JSONObject) bool { return db.IsAdminAllowPerform(userCred, self, "update-credential") }