mirror of
https://github.com/yunionio/cloudpods.git
synced 2026-09-24 16:03:43 +08:00
fix(region): vendor update (#23452)
This commit is contained in:
@@ -96,7 +96,7 @@ require (
|
||||
k8s.io/cri-api v0.22.17
|
||||
k8s.io/klog/v2 v2.20.0
|
||||
moul.io/http2curl/v2 v2.3.0
|
||||
yunion.io/x/cloudmux v0.3.10-0-alpha.1.0.20250928091205-45bbf123e2c7
|
||||
yunion.io/x/cloudmux v0.3.10-0-alpha.1.0.20250930065031-d469e632afc7
|
||||
yunion.io/x/executor v0.0.0-20250518005516-5402e9e0bed0
|
||||
yunion.io/x/jsonutils v1.0.1-0.20250507052344-1abcf4f443b1
|
||||
yunion.io/x/log v1.0.1-0.20240305175729-7cf2d6cd5a91
|
||||
|
||||
@@ -1426,8 +1426,8 @@ sigs.k8s.io/structured-merge-diff/v4 v4.0.1/go.mod h1:bJZC9H9iH24zzfZ/41RGcq60oK
|
||||
sigs.k8s.io/yaml v1.1.0/go.mod h1:UJmg0vDUVViEyp3mgSv9WPwZCDxu4rQW1olrI1uml+o=
|
||||
sigs.k8s.io/yaml v1.2.0 h1:kr/MCeFWJWTwyaHoR9c8EjH9OumOmoF9YGiZd7lFm/Q=
|
||||
sigs.k8s.io/yaml v1.2.0/go.mod h1:yfXDCHCao9+ENCvLSE62v9VSji2MKu5jeNfTrofGhJc=
|
||||
yunion.io/x/cloudmux v0.3.10-0-alpha.1.0.20250928091205-45bbf123e2c7 h1:tr5VYfSFw1rlcn/hMrwH4Gq9AFEy7Mkgjc5kE/dLzhY=
|
||||
yunion.io/x/cloudmux v0.3.10-0-alpha.1.0.20250928091205-45bbf123e2c7/go.mod h1:R5iP/4nGCluuekoa30B5hM/49IfPpGHXwFK3yT7m6Vw=
|
||||
yunion.io/x/cloudmux v0.3.10-0-alpha.1.0.20250930065031-d469e632afc7 h1:s330bg28iOB9+D3cPtuwG5eeG9qHKkjicPh5P+ri4Ko=
|
||||
yunion.io/x/cloudmux v0.3.10-0-alpha.1.0.20250930065031-d469e632afc7/go.mod h1:R5iP/4nGCluuekoa30B5hM/49IfPpGHXwFK3yT7m6Vw=
|
||||
yunion.io/x/executor v0.0.0-20250518005516-5402e9e0bed0 h1:msG4SiDSVU7CrXH06WuHlNEZXIooTcmNbfrIGHuIHBU=
|
||||
yunion.io/x/executor v0.0.0-20250518005516-5402e9e0bed0/go.mod h1:Uxuou9WQIeJXNpy7t2fPLL0BYLvLiMvGQwY7Qc6aSws=
|
||||
yunion.io/x/jsonutils v0.0.0-20190625054549-a964e1e8a051/go.mod h1:4N0/RVzsYL3kH3WE/H1BjUQdFiWu50JGCFQuuy+Z634=
|
||||
|
||||
@@ -0,0 +1,35 @@
|
||||
// Copyright 2019 Yunion
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package providerdriver
|
||||
|
||||
import (
|
||||
api "yunion.io/x/onecloud/pkg/apis/compute"
|
||||
)
|
||||
|
||||
type KsyunCollect struct {
|
||||
SCollectByResourceIdDriver
|
||||
}
|
||||
|
||||
func (kc *KsyunCollect) GetProvider() string {
|
||||
return api.CLOUD_PROVIDER_KSYUN
|
||||
}
|
||||
|
||||
func (kc *KsyunCollect) IsSupportMetrics() bool {
|
||||
return true
|
||||
}
|
||||
|
||||
func init() {
|
||||
Register(&KsyunCollect{})
|
||||
}
|
||||
@@ -76,6 +76,10 @@ func (self *SKsyunGuestDriver) GetAttachDiskStatus() ([]string, error) {
|
||||
return []string{api.VM_READY, api.VM_RUNNING}, nil
|
||||
}
|
||||
|
||||
func (self *SKsyunGuestDriver) GetRebuildRootStatus() ([]string, error) {
|
||||
return []string{api.VM_READY}, nil
|
||||
}
|
||||
|
||||
func (self *SKsyunGuestDriver) IsAllowSaveImageOnRunning() bool {
|
||||
return true
|
||||
}
|
||||
@@ -168,3 +172,7 @@ func (self *SKsyunGuestDriver) IsSupportSetAutoRenew() bool {
|
||||
func (self *SKsyunGuestDriver) IsSupportShutdownMode() bool {
|
||||
return true
|
||||
}
|
||||
|
||||
func (self *SKsyunGuestDriver) IsNeedRestartForResetLoginInfo() bool {
|
||||
return false
|
||||
}
|
||||
|
||||
@@ -88,7 +88,11 @@ func (drv *SManagedVirtualizedGuestDriver) GetJsonDescAtHost(ctx context.Context
|
||||
config.InstanceType = guest.InstanceType
|
||||
|
||||
if len(guest.KeypairId) > 0 {
|
||||
config.PublicKey = guest.GetKeypairPublicKey()
|
||||
keypair := guest.GetKeypair()
|
||||
if keypair != nil {
|
||||
config.PublicKey = keypair.PublicKey
|
||||
config.KeypairName = keypair.Name
|
||||
}
|
||||
}
|
||||
|
||||
nics, _ := guest.GetNetworks("")
|
||||
@@ -784,10 +788,11 @@ func (drv *SManagedVirtualizedGuestDriver) RemoteDeployGuestForDeploy(ctx contex
|
||||
log.Debugf("Deploy VM params %s", params.String())
|
||||
|
||||
opts := &cloudprovider.SInstanceDeployOptions{
|
||||
Username: desc.Account,
|
||||
PublicKey: desc.PublicKey,
|
||||
Password: desc.Password,
|
||||
UserData: desc.UserData,
|
||||
Username: desc.Account,
|
||||
PublicKey: desc.PublicKey,
|
||||
KeypairName: desc.KeypairName,
|
||||
Password: desc.Password,
|
||||
UserData: desc.UserData,
|
||||
}
|
||||
opts.DeleteKeypair = jsonutils.QueryBoolean(params, "__delete_keypair__", false)
|
||||
|
||||
@@ -850,13 +855,14 @@ func (drv *SManagedVirtualizedGuestDriver) RemoteDeployGuestForRebuildRoot(ctx c
|
||||
defer lockman.ReleaseObject(ctx, guest)
|
||||
|
||||
conf := cloudprovider.SManagedVMRebuildRootConfig{
|
||||
Account: desc.Account,
|
||||
ImageId: desc.ExternalImageId,
|
||||
Password: desc.Password,
|
||||
PublicKey: desc.PublicKey,
|
||||
SysSizeGB: desc.SysDisk.SizeGB,
|
||||
OsType: desc.OsType,
|
||||
UserData: desc.UserData,
|
||||
Account: desc.Account,
|
||||
ImageId: desc.ExternalImageId,
|
||||
Password: desc.Password,
|
||||
PublicKey: desc.PublicKey,
|
||||
KeypairName: desc.KeypairName,
|
||||
SysSizeGB: desc.SysDisk.SizeGB,
|
||||
OsType: desc.OsType,
|
||||
UserData: desc.UserData,
|
||||
}
|
||||
return iVM.RebuildRoot(ctx, &conf)
|
||||
}()
|
||||
|
||||
@@ -5109,6 +5109,7 @@ func (self *SGuest) GetDeployConfigOnHost(ctx context.Context, userCred mcclient
|
||||
keypair := self.getKeypair()
|
||||
if keypair != nil {
|
||||
config.Add(jsonutils.NewString(keypair.PublicKey), "public_key")
|
||||
config.Add(jsonutils.NewString(keypair.Name), "keypair_name")
|
||||
}
|
||||
deletePubKey, _ := params.GetString("delete_public_key")
|
||||
if len(deletePubKey) > 0 {
|
||||
@@ -5848,6 +5849,10 @@ func (self *SGuest) GetKeypairPublicKey() string {
|
||||
return ""
|
||||
}
|
||||
|
||||
func (self *SGuest) GetKeypair() *SKeypair {
|
||||
return self.getKeypair()
|
||||
}
|
||||
|
||||
func (manager *SGuestManager) GetIpsInProjectWithName(projectId, name string, isExitOnly bool, addrType api.TAddressType) []string {
|
||||
name = strings.TrimSuffix(name, ".")
|
||||
|
||||
|
||||
Vendored
+1
-1
@@ -1900,7 +1900,7 @@ sigs.k8s.io/structured-merge-diff/v4/value
|
||||
# sigs.k8s.io/yaml v1.2.0
|
||||
## explicit; go 1.12
|
||||
sigs.k8s.io/yaml
|
||||
# yunion.io/x/cloudmux v0.3.10-0-alpha.1.0.20250928091205-45bbf123e2c7
|
||||
# yunion.io/x/cloudmux v0.3.10-0-alpha.1.0.20250930065031-d469e632afc7
|
||||
## explicit; go 1.24
|
||||
yunion.io/x/cloudmux/pkg/apis
|
||||
yunion.io/x/cloudmux/pkg/apis/billing
|
||||
|
||||
+12
@@ -143,6 +143,8 @@ const (
|
||||
STORAGE_KSYUN_SSD3_0 = "SSD3.0"
|
||||
// 高效云硬盘
|
||||
STORAGE_KSYUN_EHDD = "EHDD"
|
||||
// 本地SSD云硬盘
|
||||
STORAGE_KSYUN_LOCAL_SSD = "Local_SSD"
|
||||
|
||||
// cnware storage type
|
||||
STORAGE_CNWARE_FC_SAN = "fc-san"
|
||||
@@ -164,3 +166,13 @@ const (
|
||||
DISK_TYPE_SSD = "ssd"
|
||||
DISK_TYPE_HYBRID = "hybrid"
|
||||
)
|
||||
|
||||
var KSYUN_STORAGES = []string{
|
||||
STORAGE_KSYUN_ESSD_AUTO_PL,
|
||||
STORAGE_KSYUN_ESSD_PL1,
|
||||
STORAGE_KSYUN_ESSD_PL2,
|
||||
STORAGE_KSYUN_ESSD_PL3,
|
||||
STORAGE_KSYUN_SSD3_0,
|
||||
STORAGE_KSYUN_EHDD,
|
||||
STORAGE_KSYUN_LOCAL_SSD,
|
||||
}
|
||||
|
||||
+8
-7
@@ -188,13 +188,14 @@ type SManagedVMChangeConfig struct {
|
||||
}
|
||||
|
||||
type SManagedVMRebuildRootConfig struct {
|
||||
Account string
|
||||
Password string
|
||||
ImageId string
|
||||
PublicKey string
|
||||
SysSizeGB int
|
||||
OsType string
|
||||
UserData string
|
||||
Account string
|
||||
Password string
|
||||
ImageId string
|
||||
KeypairName string
|
||||
PublicKey string
|
||||
SysSizeGB int
|
||||
OsType string
|
||||
UserData string
|
||||
}
|
||||
|
||||
func (vmConfig *SManagedVMCreateConfig) GetConfig(config *jsonutils.JSONDict) error {
|
||||
|
||||
+2
-2
@@ -110,7 +110,7 @@ func (region *SRegion) GetDBInstance(id string) (*SDBInstance, error) {
|
||||
}
|
||||
|
||||
func (region *SRegion) GetDBInstances(id string) ([]SDBInstance, error) {
|
||||
params := map[string]string{}
|
||||
params := map[string]interface{}{}
|
||||
if len(id) > 0 {
|
||||
params["DBInstanceIdentifier"] = id
|
||||
}
|
||||
@@ -303,7 +303,7 @@ func (rds *SDBInstance) Delete() error {
|
||||
}
|
||||
|
||||
func (region *SRegion) DeleteDBInstance(instanceId string) error {
|
||||
params := map[string]string{}
|
||||
params := map[string]interface{}{}
|
||||
params["DBInstanceIdentifier"] = instanceId
|
||||
_, err := region.rdsRequest("DeleteDBInstance", params)
|
||||
return err
|
||||
|
||||
+1
-1
@@ -82,7 +82,7 @@ func (rds *SDBInstance) GetIDBInstanceAccounts() ([]cloudprovider.ICloudDBInstan
|
||||
}
|
||||
|
||||
func (region *SRegion) GetDBInstanceAccounts(id string) ([]SDBInstanceAccount, error) {
|
||||
params := map[string]string{
|
||||
params := map[string]interface{}{
|
||||
"DBInstanceIdentifier": id,
|
||||
}
|
||||
body, err := region.rdsRequest("DescribeInstanceAccounts", params)
|
||||
|
||||
+1
-1
@@ -109,7 +109,7 @@ func (backup *SDBInstanceBackup) GetDBInstanceId() string {
|
||||
}
|
||||
|
||||
func (region *SRegion) GetDBInstanceBackups(id string) ([]SDBInstanceBackup, error) {
|
||||
params := map[string]string{
|
||||
params := map[string]interface{}{
|
||||
"DBInstanceIdentifier": id,
|
||||
}
|
||||
ret := []SDBInstanceBackup{}
|
||||
|
||||
+1
-1
@@ -62,7 +62,7 @@ func (database *SDBInstanceDatabase) GetCharacterSet() string {
|
||||
}
|
||||
|
||||
func (region *SRegion) GetDBInstanceDatabases(id string) ([]SDBInstanceDatabase, error) {
|
||||
params := map[string]string{
|
||||
params := map[string]interface{}{
|
||||
"DBInstanceIdentifier": id,
|
||||
}
|
||||
resp, err := region.rdsRequest("DescribeInstanceDatabases", params)
|
||||
|
||||
+20
-8
@@ -77,7 +77,7 @@ func (region *SRegion) GetDisk(diskId string) (*SDisk, error) {
|
||||
|
||||
func (region *SRegion) GetDisks(diskIds []string, storageType, zoneId string) ([]SDisk, error) {
|
||||
disks := []SDisk{}
|
||||
params := map[string]string{
|
||||
params := map[string]interface{}{
|
||||
"MaxResults": "1000",
|
||||
}
|
||||
for i, v := range diskIds {
|
||||
@@ -120,8 +120,7 @@ func (region *SRegion) GetDisks(diskIds []string, storageType, zoneId string) ([
|
||||
}
|
||||
|
||||
func (region *SRegion) GetDiskByInstanceId(instanceId string) ([]SDisk, error) {
|
||||
disks := []SDisk{}
|
||||
params := map[string]string{
|
||||
params := map[string]interface{}{
|
||||
"MaxResults": "1000",
|
||||
}
|
||||
params["InstanceId"] = instanceId
|
||||
@@ -129,7 +128,14 @@ func (region *SRegion) GetDiskByInstanceId(instanceId string) ([]SDisk, error) {
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "DescribeInstanceVolumes")
|
||||
}
|
||||
return disks, resp.Unmarshal(&disks, "Attachments")
|
||||
ret := struct {
|
||||
Attachments []SDisk `json:"Attachments"`
|
||||
}{}
|
||||
err = resp.Unmarshal(&ret)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "unmarshal Attachments")
|
||||
}
|
||||
return ret.Attachments, nil
|
||||
}
|
||||
|
||||
func (disk *SDisk) GetIStorage() (cloudprovider.ICloudStorage, error) {
|
||||
@@ -175,6 +181,9 @@ func (disk *SDisk) GetProjectId() string {
|
||||
}
|
||||
|
||||
func (disk *SDisk) Refresh() error {
|
||||
if disk.VolumeType == api.STORAGE_KSYUN_LOCAL_SSD {
|
||||
return nil
|
||||
}
|
||||
disk, err := disk.storage.zone.region.GetDisk(disk.VolumeId)
|
||||
if err != nil {
|
||||
return err
|
||||
@@ -183,6 +192,9 @@ func (disk *SDisk) Refresh() error {
|
||||
}
|
||||
|
||||
func (disk *SDisk) GetStatus() string {
|
||||
if disk.VolumeType == api.STORAGE_KSYUN_LOCAL_SSD {
|
||||
return api.DISK_READY
|
||||
}
|
||||
// creating、available、attaching、inuse、detaching、extending、deleting、error
|
||||
switch disk.VolumeStatus {
|
||||
case "available", "inuse", "in-use":
|
||||
@@ -287,7 +299,7 @@ func (disk *SDisk) Rebuild(ctx context.Context) error {
|
||||
}
|
||||
|
||||
func (region *SRegion) DeleteDisk(id string) error {
|
||||
_, err := region.ebsRequest("DeleteVolume", map[string]string{
|
||||
_, err := region.ebsRequest("DeleteVolume", map[string]interface{}{
|
||||
"VolumeId": id,
|
||||
"ForceDelete": "true",
|
||||
})
|
||||
@@ -295,7 +307,7 @@ func (region *SRegion) DeleteDisk(id string) error {
|
||||
}
|
||||
|
||||
func (region *SRegion) ResizeDisk(id string, newSizeMB int64) error {
|
||||
_, err := region.ebsRequest("ResizeVolume", map[string]string{
|
||||
_, err := region.ebsRequest("ResizeVolume", map[string]interface{}{
|
||||
"VolumeId": id,
|
||||
"Size": fmt.Sprintf("%d", newSizeMB/1024),
|
||||
})
|
||||
@@ -303,7 +315,7 @@ func (region *SRegion) ResizeDisk(id string, newSizeMB int64) error {
|
||||
}
|
||||
|
||||
func (region *SRegion) ResetDisk(id string, snapshotId string) error {
|
||||
_, err := region.ebsRequest("ResetVolume", map[string]string{
|
||||
_, err := region.ebsRequest("ResetVolume", map[string]interface{}{
|
||||
"VolumeId": id,
|
||||
"SnapshotId": snapshotId,
|
||||
})
|
||||
@@ -311,7 +323,7 @@ func (region *SRegion) ResetDisk(id string, snapshotId string) error {
|
||||
}
|
||||
|
||||
func (region *SRegion) CreateDisk(storageType, zoneId string, opts *cloudprovider.DiskCreateConfig) (*SDisk, error) {
|
||||
params := map[string]string{
|
||||
params := map[string]interface{}{
|
||||
"VolumeName": opts.Name,
|
||||
"VolumeDesc": opts.Desc,
|
||||
"Size": fmt.Sprintf("%d", opts.SizeGb),
|
||||
|
||||
+18
-8
@@ -61,7 +61,7 @@ type SEip struct {
|
||||
}
|
||||
|
||||
func (region *SRegion) GetEips(eipIds []string) ([]SEip, error) {
|
||||
params := map[string]string{
|
||||
params := map[string]interface{}{
|
||||
"MaxResults": "1000",
|
||||
}
|
||||
for i, eipId := range eipIds {
|
||||
@@ -210,7 +210,7 @@ func (eip *SEip) ChangeBandwidth(bw int) error {
|
||||
}
|
||||
|
||||
func (region *SRegion) DeallocateEIP(eipId string) error {
|
||||
params := map[string]string{
|
||||
params := map[string]interface{}{
|
||||
"AllocationId": eipId,
|
||||
}
|
||||
_, err := region.eipRequest("ReleaseAddress", params)
|
||||
@@ -218,17 +218,27 @@ func (region *SRegion) DeallocateEIP(eipId string) error {
|
||||
}
|
||||
|
||||
func (region *SRegion) AssociateEip(eipId string, instanceId string) error {
|
||||
params := map[string]string{
|
||||
params := map[string]interface{}{
|
||||
"AllocationId": eipId,
|
||||
"InstanceId": instanceId,
|
||||
"InstanceType": "",
|
||||
"InstanceType": "Ipfwd",
|
||||
}
|
||||
_, err := region.eipRequest("AssociateAddress", params)
|
||||
vm, err := region.GetInstance(instanceId)
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "GetInstance")
|
||||
}
|
||||
for _, nic := range vm.NetworkInterfaceSet {
|
||||
if len(nic.AllocationId) == 0 {
|
||||
params["NetworkInterfaceId"] = nic.NetworkInterfaceId
|
||||
break
|
||||
}
|
||||
}
|
||||
_, err = region.eipRequest("AssociateAddress", params)
|
||||
return err
|
||||
}
|
||||
|
||||
func (region *SRegion) DissociateEip(eipId string) error {
|
||||
params := map[string]string{
|
||||
params := map[string]interface{}{
|
||||
"AllocationId": eipId,
|
||||
}
|
||||
_, err := region.eipRequest("DisassociateAddress", params)
|
||||
@@ -254,7 +264,7 @@ func (region *SRegion) CreateEip(opts *cloudprovider.SEip) (*SEip, error) {
|
||||
if len(lineId) == 0 {
|
||||
return nil, errors.Wrap(errors.ErrNotFound, "No bgp lines found")
|
||||
}
|
||||
params := map[string]string{
|
||||
params := map[string]interface{}{
|
||||
"LineId": lineId,
|
||||
"BandWidth": fmt.Sprintf("%d", opts.BandwidthMbps),
|
||||
"ChargeType": "DailyPaidByTransfer",
|
||||
@@ -282,7 +292,7 @@ type SLine struct {
|
||||
}
|
||||
|
||||
func (region *SRegion) GetLines() ([]SLine, error) {
|
||||
params := map[string]string{}
|
||||
params := map[string]interface{}{}
|
||||
body, err := region.eipRequest("GetLines", params)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "GetLines")
|
||||
|
||||
+9
-9
@@ -104,7 +104,7 @@ func (client *SKsyunClient) GetICloudgroups() ([]cloudprovider.ICloudgroup, erro
|
||||
}
|
||||
|
||||
func (client *SKsyunClient) ListGroups() ([]SGroup, error) {
|
||||
params := map[string]string{
|
||||
params := map[string]interface{}{
|
||||
"MaxItems": "100",
|
||||
}
|
||||
ret := []SGroup{}
|
||||
@@ -133,7 +133,7 @@ func (client *SKsyunClient) ListGroups() ([]SGroup, error) {
|
||||
}
|
||||
|
||||
func (client *SKsyunClient) ListGroupPolicies(name string) ([]SPolicy, error) {
|
||||
params := map[string]string{
|
||||
params := map[string]interface{}{
|
||||
"GroupName": name,
|
||||
"MaxItems": "100",
|
||||
}
|
||||
@@ -164,7 +164,7 @@ func (client *SKsyunClient) ListGroupPolicies(name string) ([]SPolicy, error) {
|
||||
}
|
||||
|
||||
func (client *SKsyunClient) AttachGroupPolicy(name, policy string) error {
|
||||
params := map[string]string{
|
||||
params := map[string]interface{}{
|
||||
"GroupName": name,
|
||||
"PolicyKrn": policy,
|
||||
}
|
||||
@@ -173,7 +173,7 @@ func (client *SKsyunClient) AttachGroupPolicy(name, policy string) error {
|
||||
}
|
||||
|
||||
func (client *SKsyunClient) DetachGroupPolicy(name, policy string) error {
|
||||
params := map[string]string{
|
||||
params := map[string]interface{}{
|
||||
"GroupName": name,
|
||||
"PolicyKrn": policy,
|
||||
}
|
||||
@@ -182,7 +182,7 @@ func (client *SKsyunClient) DetachGroupPolicy(name, policy string) error {
|
||||
}
|
||||
|
||||
func (client *SKsyunClient) DeleteGroup(name string) error {
|
||||
params := map[string]string{
|
||||
params := map[string]interface{}{
|
||||
"GroupName": name,
|
||||
}
|
||||
_, err := client.iamRequest("", "DeleteGroup", params)
|
||||
@@ -190,7 +190,7 @@ func (client *SKsyunClient) DeleteGroup(name string) error {
|
||||
}
|
||||
|
||||
func (client *SKsyunClient) AddUserToGroup(user, group string) error {
|
||||
params := map[string]string{
|
||||
params := map[string]interface{}{
|
||||
"GroupName": group,
|
||||
"UserName": user,
|
||||
}
|
||||
@@ -199,7 +199,7 @@ func (client *SKsyunClient) AddUserToGroup(user, group string) error {
|
||||
}
|
||||
|
||||
func (client *SKsyunClient) RemoveUserFromGroup(user, group string) error {
|
||||
params := map[string]string{
|
||||
params := map[string]interface{}{
|
||||
"GroupName": group,
|
||||
"UserName": user,
|
||||
}
|
||||
@@ -208,7 +208,7 @@ func (client *SKsyunClient) RemoveUserFromGroup(user, group string) error {
|
||||
}
|
||||
|
||||
func (client *SKsyunClient) CreateGroup(name, desc string) (*SGroup, error) {
|
||||
params := map[string]string{
|
||||
params := map[string]interface{}{
|
||||
"GroupName": name,
|
||||
"Description": desc,
|
||||
}
|
||||
@@ -233,7 +233,7 @@ func (client *SKsyunClient) GetICloudgroupByName(name string) (cloudprovider.ICl
|
||||
}
|
||||
|
||||
func (client *SKsyunClient) GetGroup(name string) (*SGroup, error) {
|
||||
params := map[string]string{
|
||||
params := map[string]interface{}{
|
||||
"GroupName": name,
|
||||
}
|
||||
resp, err := client.iamRequest("", "GetGroup", params)
|
||||
|
||||
+1
-1
@@ -80,7 +80,7 @@ func (region *SRegion) syncKeypair(keyName, publicKey string) (string, error) {
|
||||
}
|
||||
|
||||
func (region *SRegion) CreateVM(opts *cloudprovider.SManagedVMCreateConfig) (*SInstance, error) {
|
||||
params := map[string]string{
|
||||
params := map[string]interface{}{
|
||||
"InstanceName": opts.Name,
|
||||
"ImageId": opts.ExternalImageId,
|
||||
"InstanceType": opts.InstanceType,
|
||||
|
||||
+4
-2
@@ -212,6 +212,8 @@ func (region *SRegion) GetImage(imageId string) (*SImage, error) {
|
||||
return nil, err
|
||||
}
|
||||
for i := range images {
|
||||
storageCache := region.getStoragecache()
|
||||
images[i].storageCache = storageCache
|
||||
if images[i].ImageId == imageId {
|
||||
return &images[i], nil
|
||||
}
|
||||
@@ -220,7 +222,7 @@ func (region *SRegion) GetImage(imageId string) (*SImage, error) {
|
||||
}
|
||||
|
||||
func (region *SRegion) GetImages(id string, imageType string) ([]SImage, error) {
|
||||
params := map[string]string{}
|
||||
params := map[string]interface{}{}
|
||||
if len(id) > 0 {
|
||||
params["ImageId"] = id
|
||||
}
|
||||
@@ -243,7 +245,7 @@ func (region *SRegion) GetImages(id string, imageType string) ([]SImage, error)
|
||||
}
|
||||
|
||||
func (region *SRegion) DeleteImage(imageId string) error {
|
||||
params := map[string]string{
|
||||
params := map[string]interface{}{
|
||||
"ImageId": imageId,
|
||||
}
|
||||
_, err := region.ecsRequest("DeleteImage", params)
|
||||
|
||||
+114
-36
@@ -17,6 +17,7 @@ package ksyun
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
billing_api "yunion.io/x/cloudmux/pkg/apis/billing"
|
||||
@@ -24,6 +25,7 @@ import (
|
||||
"yunion.io/x/cloudmux/pkg/cloudprovider"
|
||||
"yunion.io/x/cloudmux/pkg/multicloud"
|
||||
"yunion.io/x/jsonutils"
|
||||
"yunion.io/x/log"
|
||||
"yunion.io/x/pkg/errors"
|
||||
"yunion.io/x/pkg/util/imagetools"
|
||||
"yunion.io/x/pkg/utils"
|
||||
@@ -72,6 +74,7 @@ type NetworkInterfaceSet struct {
|
||||
}
|
||||
|
||||
type SystemDisk struct {
|
||||
DiskId string `json:"DiskId"`
|
||||
DiskType string `json:"DiskType"`
|
||||
DiskSize int `json:"DiskSize"`
|
||||
}
|
||||
@@ -121,6 +124,7 @@ type SInstance struct {
|
||||
VncSupport bool `json:"VncSupport"`
|
||||
Platform string `json:"Platform"`
|
||||
ServiceEndTime time.Time `json:"ServiceEndTime"`
|
||||
BootMode string `json:"BootMode"`
|
||||
}
|
||||
|
||||
func (region *SRegion) GetInstances(zoneName string, instanceIds []string) ([]SInstance, error) {
|
||||
@@ -141,7 +145,7 @@ func (region *SRegion) GetInstances(zoneName string, instanceIds []string) ([]SI
|
||||
|
||||
func (region *SRegion) getInstances(zoneName string, instanceIds []string, projectIds []string) ([]SInstance, error) {
|
||||
instances := []SInstance{}
|
||||
params := map[string]string{
|
||||
params := map[string]interface{}{
|
||||
"MaxResults": "1000",
|
||||
"Marker": "0",
|
||||
}
|
||||
@@ -229,7 +233,7 @@ func (ins *SInstance) AttachDisk(ctx context.Context, diskId string) error {
|
||||
}
|
||||
|
||||
func (region *SRegion) AttachDisk(instanceId, diskId string) error {
|
||||
params := map[string]string{
|
||||
params := map[string]interface{}{
|
||||
"VolumeId": diskId,
|
||||
"InstanceId": instanceId,
|
||||
"DeleteWithInstance": "true",
|
||||
@@ -243,7 +247,7 @@ func (ins *SInstance) ChangeConfig(ctx context.Context, opts *cloudprovider.SMan
|
||||
}
|
||||
|
||||
func (region *SRegion) ChangeConfig(instanceId string, opts *cloudprovider.SManagedVMChangeConfig) error {
|
||||
params := map[string]string{
|
||||
params := map[string]interface{}{
|
||||
"InstanceId": instanceId,
|
||||
"InstanceType": opts.InstanceType,
|
||||
}
|
||||
@@ -256,7 +260,7 @@ func (ins *SInstance) DeleteVM(ctx context.Context) error {
|
||||
}
|
||||
|
||||
func (region *SRegion) DeleteVM(instanceId string) error {
|
||||
params := map[string]string{
|
||||
params := map[string]interface{}{
|
||||
"InstanceId.1": instanceId,
|
||||
"ForceDelete": "true",
|
||||
}
|
||||
@@ -269,7 +273,7 @@ func (ins *SInstance) DetachDisk(ctx context.Context, diskId string) error {
|
||||
}
|
||||
|
||||
func (region *SRegion) DetachDisk(instanceId, diskId string) error {
|
||||
params := map[string]string{
|
||||
params := map[string]interface{}{
|
||||
"VolumeId": diskId,
|
||||
}
|
||||
if len(instanceId) > 0 {
|
||||
@@ -280,7 +284,10 @@ func (region *SRegion) DetachDisk(instanceId, diskId string) error {
|
||||
}
|
||||
|
||||
func (ins *SInstance) GetBios() cloudprovider.TBiosType {
|
||||
return ""
|
||||
if strings.Contains(ins.BootMode, "BIOS") {
|
||||
return cloudprovider.BIOS
|
||||
}
|
||||
return cloudprovider.UEFI
|
||||
}
|
||||
|
||||
func (ins *SInstance) GetBootOrder() string {
|
||||
@@ -292,7 +299,7 @@ func (ins *SInstance) GetError() error {
|
||||
}
|
||||
|
||||
func (ins *SInstance) GetFullOsName() string {
|
||||
return ""
|
||||
return ins.Platform
|
||||
}
|
||||
|
||||
func (ins *SInstance) GetGlobalId() string {
|
||||
@@ -320,11 +327,11 @@ func (ins *SInstance) GetName() string {
|
||||
}
|
||||
|
||||
func (ins *SInstance) GetOsArch() string {
|
||||
return ""
|
||||
return imagetools.NormalizeImageInfo(ins.Platform, "", "", "", "").OsArch
|
||||
}
|
||||
|
||||
func (ins *SInstance) GetOsDist() string {
|
||||
return ""
|
||||
return imagetools.NormalizeImageInfo(ins.Platform, "", "", "", "").OsArch
|
||||
}
|
||||
|
||||
func (ins *SInstance) GetOsLang() string {
|
||||
@@ -337,7 +344,7 @@ func (ins *SInstance) GetOsType() cloudprovider.TOsType {
|
||||
}
|
||||
|
||||
func (ins *SInstance) GetOsVersion() string {
|
||||
return ""
|
||||
return imagetools.NormalizeImageInfo(ins.Platform, "", "", "", "").OsVersion
|
||||
}
|
||||
|
||||
func (ins *SInstance) GetProjectId() string {
|
||||
@@ -356,7 +363,7 @@ func (ins *SInstance) GetSecurityGroupIds() ([]string, error) {
|
||||
|
||||
func (ins *SInstance) GetStatus() string {
|
||||
switch ins.InstanceState.Name {
|
||||
case "block_device_mapping", "scheduling":
|
||||
case "block_device_mapping", "scheduling", "updating_password", "rebuilding":
|
||||
return api.VM_DEPLOYING
|
||||
case "active":
|
||||
return api.VM_RUNNING
|
||||
@@ -394,13 +401,47 @@ func (ins *SInstance) GetIDisks() ([]cloudprovider.ICloudDisk, error) {
|
||||
}
|
||||
res = append(res, &disks[i])
|
||||
}
|
||||
if ins.SystemDisk.DiskType == api.STORAGE_KSYUN_LOCAL_SSD {
|
||||
disk := &SDisk{
|
||||
VolumeId: ins.SystemDisk.DiskId,
|
||||
VolumeType: ins.SystemDisk.DiskType,
|
||||
VolumeName: ins.SystemDisk.DiskId,
|
||||
Size: ins.SystemDisk.DiskSize,
|
||||
VolumeCategory: "system",
|
||||
}
|
||||
storage := &SStorage{
|
||||
zone: ins.host.zone,
|
||||
StorageType: api.STORAGE_KSYUN_LOCAL_SSD,
|
||||
}
|
||||
disk.storage = storage
|
||||
res = append(res, disk)
|
||||
}
|
||||
for i := range ins.DataDisks {
|
||||
if ins.DataDisks[i].DiskType == api.STORAGE_KSYUN_LOCAL_SSD {
|
||||
disk := &SDisk{
|
||||
VolumeId: ins.DataDisks[i].DiskId,
|
||||
VolumeType: ins.DataDisks[i].DiskType,
|
||||
VolumeName: ins.DataDisks[i].DiskId,
|
||||
Size: ins.DataDisks[i].DiskSize,
|
||||
VolumeCategory: "data",
|
||||
}
|
||||
storage := &SStorage{
|
||||
zone: ins.host.zone,
|
||||
StorageType: api.STORAGE_KSYUN_LOCAL_SSD,
|
||||
}
|
||||
disk.storage = storage
|
||||
res = append(res, disk)
|
||||
}
|
||||
}
|
||||
return res, nil
|
||||
}
|
||||
|
||||
func (ins *SInstance) GetIEIP() (cloudprovider.ICloudEIP, error) {
|
||||
eipIds := []string{}
|
||||
for _, set := range ins.NetworkInterfaceSet {
|
||||
eipIds = append(eipIds, set.AllocationId)
|
||||
if len(set.AllocationId) > 0 {
|
||||
eipIds = append(eipIds, set.AllocationId)
|
||||
}
|
||||
}
|
||||
if len(eipIds) == 0 {
|
||||
return nil, cloudprovider.ErrNotFound
|
||||
@@ -459,7 +500,7 @@ func (ins *SInstance) GetVNCInfo(input *cloudprovider.ServerVncInput) (*cloudpro
|
||||
*/
|
||||
|
||||
func (region *SRegion) GetVNCInfo(instanceId string) (string, error) {
|
||||
resp, err := region.ecsRequest("DescribeInstanceVncUrl", map[string]string{"InstanceId": instanceId})
|
||||
resp, err := region.ecsRequest("DescribeInstanceVncUrl", map[string]interface{}{"InstanceId": instanceId})
|
||||
if err != nil {
|
||||
return "", errors.Wrap(err, "GetVNCAddress")
|
||||
}
|
||||
@@ -482,11 +523,38 @@ func (ins *SInstance) GetVga() string {
|
||||
return ""
|
||||
}
|
||||
|
||||
func (region *SRegion) BindKeypair(instanceId, keyName, publicKey string) error {
|
||||
keyId, err := region.syncKeypair(keyName, publicKey)
|
||||
if err != nil {
|
||||
return errors.Wrapf(err, "syncKeypair %s", keyName)
|
||||
}
|
||||
return region.AttachKey(instanceId, keyId)
|
||||
}
|
||||
|
||||
func (region *SRegion) AttachKey(instanceId, keyId string) error {
|
||||
params := map[string]interface{}{
|
||||
"InstanceId.1": instanceId,
|
||||
"KeyId.1": keyId,
|
||||
}
|
||||
_, err := region.ecsRequest("AttachKey", params)
|
||||
return err
|
||||
}
|
||||
|
||||
func (ins *SInstance) RebuildRoot(ctx context.Context, opts *cloudprovider.SManagedVMRebuildRootConfig) (string, error) {
|
||||
err := ins.getRegion().RebuildRoot(ins.InstanceId, opts)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
if len(opts.PublicKey) > 0 {
|
||||
keyName := opts.KeypairName
|
||||
if len(keyName) == 0 {
|
||||
keyName = ins.InstanceName
|
||||
}
|
||||
err = ins.getRegion().BindKeypair(ins.InstanceId, keyName, opts.PublicKey)
|
||||
if err != nil {
|
||||
log.Errorf("BindKeypair %s error: %v", keyName, err)
|
||||
}
|
||||
}
|
||||
disks, err := ins.GetIDisks()
|
||||
if err != nil {
|
||||
return "", err
|
||||
@@ -498,18 +566,14 @@ func (ins *SInstance) RebuildRoot(ctx context.Context, opts *cloudprovider.SMana
|
||||
}
|
||||
|
||||
func (region *SRegion) RebuildRoot(instanceId string, opts *cloudprovider.SManagedVMRebuildRootConfig) error {
|
||||
params := map[string]string{
|
||||
params := map[string]interface{}{
|
||||
"InstanceId": instanceId,
|
||||
"ImageId": opts.ImageId,
|
||||
}
|
||||
if len(opts.Password) > 0 {
|
||||
params["InstancePassword"] = opts.Password
|
||||
}
|
||||
/*
|
||||
if len(opts.PublicKey) > 0 {
|
||||
params["KeyPairName"] = opts.PublicKey
|
||||
}
|
||||
*/
|
||||
|
||||
if len(opts.UserData) > 0 {
|
||||
params["UserData"] = opts.UserData
|
||||
}
|
||||
@@ -537,7 +601,7 @@ func (ins *SInstance) StopVM(ctx context.Context, opts *cloudprovider.ServerStop
|
||||
}
|
||||
|
||||
func (region *SRegion) StartVM(instanceId string) error {
|
||||
params := map[string]string{
|
||||
params := map[string]interface{}{
|
||||
"InstanceId.1": instanceId,
|
||||
}
|
||||
_, err := region.ecsRequest("StartInstances", params)
|
||||
@@ -548,7 +612,7 @@ func (region *SRegion) StartVM(instanceId string) error {
|
||||
}
|
||||
|
||||
func (region *SRegion) StopVM(instanceId string, force, stopCharging bool) error {
|
||||
params := map[string]string{
|
||||
params := map[string]interface{}{
|
||||
"InstanceId.1": instanceId,
|
||||
"StoppedMode": "KeepCharging",
|
||||
}
|
||||
@@ -574,7 +638,7 @@ func (ins *SInstance) UpdateVM(ctx context.Context, opts cloudprovider.SInstance
|
||||
}
|
||||
|
||||
func (region *SRegion) UpdateVM(instanceId string, opts cloudprovider.SInstanceUpdateOptions) error {
|
||||
params := map[string]string{
|
||||
params := map[string]interface{}{
|
||||
"InstanceId": instanceId,
|
||||
}
|
||||
if len(opts.NAME) > 0 {
|
||||
@@ -592,25 +656,19 @@ func (ins *SInstance) GetIHost() cloudprovider.ICloudHost {
|
||||
}
|
||||
|
||||
func (ins *SInstance) DeployVM(ctx context.Context, opts *cloudprovider.SInstanceDeployOptions) error {
|
||||
if len(opts.PublicKey) > 0 {
|
||||
return ins.getRegion().BindKeypair(ins.InstanceId, opts.KeypairName, opts.PublicKey)
|
||||
}
|
||||
return ins.getRegion().DeployVM(ins.InstanceId, opts)
|
||||
}
|
||||
|
||||
func (region *SRegion) DeployVM(instanceId string, opts *cloudprovider.SInstanceDeployOptions) error {
|
||||
params := map[string]string{
|
||||
"InstanceId": instanceId,
|
||||
params := map[string]interface{}{
|
||||
"InstanceId": instanceId,
|
||||
"InstancePassword": opts.Password,
|
||||
"RestartMode": "Restart",
|
||||
}
|
||||
if len(opts.Password) > 0 {
|
||||
params["InstancePassword"] = opts.Password
|
||||
params["RestartMode"] = "Restart"
|
||||
}
|
||||
/*
|
||||
if len(opts.PublicKey) > 0 {
|
||||
params["KeyPairName"] = opts.PublicKey
|
||||
}
|
||||
if len(opts.UserData) > 0 {
|
||||
params["UserData"] = opts.UserData
|
||||
}
|
||||
*/
|
||||
|
||||
_, err := region.ecsRequest("ModifyInstanceAttribute", params)
|
||||
return err
|
||||
}
|
||||
@@ -629,3 +687,23 @@ func (ins *SInstance) GetCreatedAt() time.Time {
|
||||
func (ins *SInstance) GetExpiredAt() time.Time {
|
||||
return ins.ServiceEndTime
|
||||
}
|
||||
|
||||
func (ins *SInstance) SaveImage(opts *cloudprovider.SaveImageOptions) (cloudprovider.ICloudImage, error) {
|
||||
return ins.host.zone.region.SaveImage(ins.InstanceId, opts)
|
||||
}
|
||||
|
||||
func (region *SRegion) SaveImage(instanceId string, opts *cloudprovider.SaveImageOptions) (cloudprovider.ICloudImage, error) {
|
||||
params := map[string]interface{}{
|
||||
"InstanceId": instanceId,
|
||||
"Name": opts.Name,
|
||||
}
|
||||
resp, err := region.ecsRequest("CreateImage", params)
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(err, "CreateImage")
|
||||
}
|
||||
imageId, err := resp.GetString("ImageId")
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(err, "get imageId")
|
||||
}
|
||||
return region.GetImage(imageId)
|
||||
}
|
||||
|
||||
+1
-1
@@ -50,7 +50,7 @@ type SInstanceType struct {
|
||||
}
|
||||
|
||||
func (region *SRegion) GetInstanceTypes() ([]SInstanceType, error) {
|
||||
params := make(map[string]string)
|
||||
params := make(map[string]interface{})
|
||||
params["Region"] = region.Region
|
||||
zones, err := region.GetZones()
|
||||
if err != nil {
|
||||
|
||||
+2
-2
@@ -25,7 +25,7 @@ type SKeypair struct {
|
||||
}
|
||||
|
||||
func (cli *SKsyunClient) GetKeypairs() ([]SKeypair, error) {
|
||||
params := map[string]string{
|
||||
params := map[string]interface{}{
|
||||
"MaxResults": "1000",
|
||||
}
|
||||
ret := []SKeypair{}
|
||||
@@ -52,7 +52,7 @@ func (cli *SKsyunClient) GetKeypairs() ([]SKeypair, error) {
|
||||
}
|
||||
|
||||
func (cli *SKsyunClient) CreateKeypair(name, publicKey string) (*SKeypair, error) {
|
||||
params := map[string]string{
|
||||
params := map[string]interface{}{
|
||||
"KeyName": name,
|
||||
"PublicKey": publicKey,
|
||||
"IsCheck": "true",
|
||||
|
||||
+84
-31
@@ -22,6 +22,7 @@ import (
|
||||
"crypto/tls"
|
||||
"encoding/hex"
|
||||
"fmt"
|
||||
"io"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"sort"
|
||||
@@ -29,6 +30,8 @@ import (
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"github.com/aws/aws-sdk-go/aws/credentials"
|
||||
v4 "github.com/aws/aws-sdk-go/aws/signer/v4"
|
||||
"yunion.io/x/jsonutils"
|
||||
"yunion.io/x/pkg/errors"
|
||||
"yunion.io/x/pkg/gotypes"
|
||||
@@ -44,6 +47,7 @@ const (
|
||||
KSYUN_DEFAULT_API_VERSION = "2016-03-04"
|
||||
KSYUN_RDS_API_VERSION = "2016-07-01"
|
||||
KSYUN_SKS_API_VERSION = "2015-11-01"
|
||||
KSYUN_MONITOR_API_VERSION = "2018-11-14"
|
||||
)
|
||||
|
||||
type KsyunClientConfig struct {
|
||||
@@ -132,6 +136,8 @@ func (cli *SKsyunClient) getUrl(service, regionId string) (string, error) {
|
||||
return fmt.Sprintf("http://%s.api.ksyun.com", service), nil
|
||||
case "kec", "tag", "krds":
|
||||
return fmt.Sprintf("https://%s.%s.api.ksyun.com", service, regionId), nil
|
||||
case "monitor":
|
||||
return fmt.Sprintf("https://%s.api.ksyun.com", service), nil
|
||||
}
|
||||
return "", errors.Wrapf(cloudprovider.ErrNotSupported, "service %s", service)
|
||||
}
|
||||
@@ -172,9 +178,9 @@ func (cli *SKsyunClient) getDefaultClient() *http.Client {
|
||||
|
||||
// {"RequestId":"51aee78d-8c35-4778-92fb-a622c40fa5ae","Error":{"Code":"INVALID_ACTION","Message":"Not Found"}}
|
||||
type sKsyunError struct {
|
||||
Params map[string]string `json:"Params"`
|
||||
StatusCode int `json:"StatusCode"`
|
||||
RequestId string `json:"RequestId"`
|
||||
Params map[string]interface{} `json:"Params"`
|
||||
StatusCode int `json:"StatusCode"`
|
||||
RequestId string `json:"RequestId"`
|
||||
ErrorMsg struct {
|
||||
Code string `json:"Code"`
|
||||
Message string `json:"Message"`
|
||||
@@ -225,6 +231,44 @@ func (cli *SKsyunClient) sign(req *http.Request) (string, error) {
|
||||
|
||||
func (cli *SKsyunClient) Do(req *http.Request) (*http.Response, error) {
|
||||
client := cli.getDefaultClient()
|
||||
req.Header.Set("Accept", "application/json")
|
||||
|
||||
if req.Method == "POST" || req.Method == "PUT" || req.Method == "DELETE" && req.Body != nil {
|
||||
cred := credentials.NewStaticCredentials(cli.accessKeyId, cli.accessKeySecret, "")
|
||||
sig := v4.NewSigner(cred)
|
||||
var body io.ReadSeeker = nil
|
||||
bodyBytes, err := io.ReadAll(req.Body)
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(err, "ReadAll")
|
||||
}
|
||||
body = bytes.NewReader(bodyBytes)
|
||||
|
||||
v4Req, err := http.NewRequestWithContext(cli.ctx, req.Method, req.URL.String(), body)
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(err, "NewRequestWithContext")
|
||||
}
|
||||
v4Req.Header.Set("Accept", "application/json")
|
||||
v4Req.Header.Set("X-Amz-Date", time.Now().UTC().Format("20060102T150405Z"))
|
||||
v4Req.Header.Set("Content-Type", req.Header.Get("Content-Type"))
|
||||
v4Req.Header.Set("Host", req.URL.Host)
|
||||
v4Req.Header.Set("User-Agent", req.Header.Get("User-Agent"))
|
||||
v4Req.ContentLength = int64(len(bodyBytes))
|
||||
|
||||
service, regionId := "", KSYUN_DEFAULT_REGION
|
||||
urlInfo := strings.Split(req.URL.Host, ".")
|
||||
if len(urlInfo) < 2 {
|
||||
return nil, errors.Wrapf(errors.ErrInvalidStatus, "urlInfo")
|
||||
}
|
||||
service = urlInfo[0]
|
||||
if urlInfo[1] != "api" {
|
||||
regionId = urlInfo[1]
|
||||
}
|
||||
_, err = sig.Sign(v4Req, body, service, regionId, time.Now())
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(err, "sign")
|
||||
}
|
||||
return client.Do(v4Req)
|
||||
}
|
||||
|
||||
signature, err := cli.sign(req)
|
||||
if err != nil {
|
||||
@@ -238,72 +282,81 @@ func (cli *SKsyunClient) Do(req *http.Request) (*http.Response, error) {
|
||||
|
||||
query.Set("Signature", signature)
|
||||
req.URL.RawQuery = query.Encode()
|
||||
req.Header.Set("Accept", "application/json")
|
||||
|
||||
return client.Do(req)
|
||||
}
|
||||
|
||||
func (cli *SKsyunClient) ec2Request(regionId, apiName string, params map[string]string) (jsonutils.JSONObject, error) {
|
||||
func (cli *SKsyunClient) ec2Request(regionId, apiName string, params map[string]interface{}) (jsonutils.JSONObject, error) {
|
||||
return cli.request("kec", regionId, apiName, KSYUN_DEFAULT_API_VERSION, params)
|
||||
}
|
||||
|
||||
func (cli *SKsyunClient) iamRequest(regionId, apiName string, params map[string]string) (jsonutils.JSONObject, error) {
|
||||
func (cli *SKsyunClient) iamRequest(regionId, apiName string, params map[string]interface{}) (jsonutils.JSONObject, error) {
|
||||
return cli.request("iam", regionId, apiName, "2015-11-01", params)
|
||||
}
|
||||
|
||||
func (cli *SKsyunClient) tagRequest(regionId, apiName string, params map[string]string) (jsonutils.JSONObject, error) {
|
||||
func (cli *SKsyunClient) tagRequest(regionId, apiName string, params map[string]interface{}) (jsonutils.JSONObject, error) {
|
||||
return cli.request("tag", regionId, apiName, KSYUN_DEFAULT_API_VERSION, params)
|
||||
}
|
||||
|
||||
func (cli *SKsyunClient) eipRequest(regionId, apiName string, params map[string]string) (jsonutils.JSONObject, error) {
|
||||
func (cli *SKsyunClient) eipRequest(regionId, apiName string, params map[string]interface{}) (jsonutils.JSONObject, error) {
|
||||
return cli.request("eip", regionId, apiName, KSYUN_DEFAULT_API_VERSION, params)
|
||||
}
|
||||
|
||||
func (cli *SKsyunClient) ebsRequest(regionId, apiName string, params map[string]string) (jsonutils.JSONObject, error) {
|
||||
func (cli *SKsyunClient) ebsRequest(regionId, apiName string, params map[string]interface{}) (jsonutils.JSONObject, error) {
|
||||
return cli.request("ebs", regionId, apiName, KSYUN_DEFAULT_API_VERSION, params)
|
||||
}
|
||||
|
||||
func (cli *SKsyunClient) sksRequest(regionId, apiName string, params map[string]string) (jsonutils.JSONObject, error) {
|
||||
func (cli *SKsyunClient) sksRequest(regionId, apiName string, params map[string]interface{}) (jsonutils.JSONObject, error) {
|
||||
return cli.request("sks", regionId, apiName, KSYUN_SKS_API_VERSION, params)
|
||||
}
|
||||
|
||||
func (cli *SKsyunClient) rdsRequest(regionId, apiName string, params map[string]string) (jsonutils.JSONObject, error) {
|
||||
func (cli *SKsyunClient) rdsRequest(regionId, apiName string, params map[string]interface{}) (jsonutils.JSONObject, error) {
|
||||
return cli.request("krds", regionId, apiName, KSYUN_RDS_API_VERSION, params)
|
||||
}
|
||||
|
||||
func (cli *SKsyunClient) vpcRequest(regionId, apiName string, params map[string]string) (jsonutils.JSONObject, error) {
|
||||
func (cli *SKsyunClient) vpcRequest(regionId, apiName string, params map[string]interface{}) (jsonutils.JSONObject, error) {
|
||||
return cli.request("vpc", regionId, apiName, KSYUN_DEFAULT_API_VERSION, params)
|
||||
}
|
||||
|
||||
func (cli *SKsyunClient) request(service, regionId, apiName, apiVersion string, params map[string]string) (jsonutils.JSONObject, error) {
|
||||
func (cli *SKsyunClient) request(service, regionId, apiName, apiVersion string, params map[string]interface{}) (jsonutils.JSONObject, error) {
|
||||
uri, err := cli.getUrl(service, regionId)
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(err, "getUrl")
|
||||
}
|
||||
if params == nil {
|
||||
params = map[string]string{}
|
||||
params = map[string]interface{}{}
|
||||
}
|
||||
if len(regionId) > 0 {
|
||||
params["Region"] = regionId
|
||||
}
|
||||
params["Action"] = apiName
|
||||
params["Version"] = apiVersion
|
||||
params["Accesskey"] = cli.accessKeyId
|
||||
params["SignatureMethod"] = "HMAC-SHA256"
|
||||
params["Service"] = service
|
||||
params["Format"] = "json"
|
||||
params["SignatureVersion"] = "1.0"
|
||||
params["Timestamp"] = time.Now().UTC().Format("2006-01-02T15:04:05Z")
|
||||
|
||||
values := url.Values{}
|
||||
for k, v := range params {
|
||||
values.Set(k, v)
|
||||
}
|
||||
uri = fmt.Sprintf("%s?%s", uri, values.Encode())
|
||||
values.Set("Action", apiName)
|
||||
values.Set("Version", apiVersion)
|
||||
values.Set("Service", service)
|
||||
|
||||
method := httputils.GET
|
||||
if !strings.HasPrefix(apiName, "Describe") && !strings.HasPrefix(apiName, "Get") && service != "sks" {
|
||||
if apiName == "GetMetricStatisticsBatch" {
|
||||
method = httputils.POST
|
||||
}
|
||||
req := httputils.NewJsonRequest(method, uri, nil)
|
||||
|
||||
if method == httputils.GET {
|
||||
values.Set("Accesskey", cli.accessKeyId)
|
||||
values.Set("SignatureMethod", "HMAC-SHA256")
|
||||
values.Set("Format", "json")
|
||||
values.Set("SignatureVersion", "1.0")
|
||||
values.Set("Timestamp", time.Now().UTC().Format("2006-01-02T15:04:05Z"))
|
||||
if len(regionId) > 0 {
|
||||
values.Set("Region", regionId)
|
||||
}
|
||||
}
|
||||
|
||||
ksErr := &sKsyunError{Params: params}
|
||||
if method == httputils.GET {
|
||||
for k, v := range params {
|
||||
values.Set(k, fmt.Sprintf("%v", v))
|
||||
}
|
||||
params = nil
|
||||
}
|
||||
uri = fmt.Sprintf("%s?%s", uri, values.Encode())
|
||||
req := httputils.NewJsonRequest(method, uri, params)
|
||||
client := httputils.NewJsonClient(cli)
|
||||
_, resp, err := client.Send(cli.ctx, req, ksErr, cli.debug)
|
||||
if err != nil {
|
||||
|
||||
+114
@@ -0,0 +1,114 @@
|
||||
// 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 ksyun
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
"yunion.io/x/cloudmux/pkg/cloudprovider"
|
||||
"yunion.io/x/jsonutils"
|
||||
"yunion.io/x/log"
|
||||
"yunion.io/x/pkg/errors"
|
||||
)
|
||||
|
||||
func (cli *SKsyunClient) monitorRequest(regionId, action string, params map[string]interface{}) (jsonutils.JSONObject, error) {
|
||||
return cli.request("monitor", regionId, action, KSYUN_MONITOR_API_VERSION, params)
|
||||
}
|
||||
|
||||
func (cli *SKsyunClient) GetMetrics(opts *cloudprovider.MetricListOptions) ([]cloudprovider.MetricValues, error) {
|
||||
switch opts.ResourceType {
|
||||
case cloudprovider.METRIC_RESOURCE_TYPE_SERVER:
|
||||
return cli.GetEcsMetrics(opts)
|
||||
default:
|
||||
return nil, errors.Wrapf(cloudprovider.ErrNotImplemented, "%s", opts.ResourceType)
|
||||
}
|
||||
}
|
||||
|
||||
type SMetric struct {
|
||||
Instance string
|
||||
Datapoints struct {
|
||||
Member []struct {
|
||||
Average float64
|
||||
Timestamp time.Time
|
||||
UnixTimestamp int64
|
||||
}
|
||||
}
|
||||
Label string
|
||||
}
|
||||
|
||||
func (cli *SKsyunClient) GetEcsMetrics(opts *cloudprovider.MetricListOptions) ([]cloudprovider.MetricValues, error) {
|
||||
params := map[string]interface{}{
|
||||
"Namespace": "KEC",
|
||||
"StartTime": opts.StartTime.Format("2006-01-02T15:04:05Z"),
|
||||
"EndTime": opts.EndTime.Format("2006-01-02T15:04:05Z"),
|
||||
"Aggregate": []string{"Average"},
|
||||
"Metrics": []map[string]interface{}{
|
||||
{
|
||||
"InstanceID": opts.ResourceId,
|
||||
"MetricName": "cpu.utilizition.total",
|
||||
},
|
||||
{
|
||||
"InstanceID": opts.ResourceId,
|
||||
"MetricName": "memory.utilizition.total",
|
||||
},
|
||||
{
|
||||
"InstanceID": opts.ResourceId,
|
||||
"MetricName": "vfs.fs.size",
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
resp, err := cli.monitorRequest(opts.RegionExtId, "GetMetricStatisticsBatch", params)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
metrics := struct {
|
||||
GetMetricStatisticsBatchResults []SMetric
|
||||
}{}
|
||||
|
||||
err = resp.Unmarshal(&metrics)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
ret := []cloudprovider.MetricValues{}
|
||||
for _, metric := range metrics.GetMetricStatisticsBatchResults {
|
||||
values := []cloudprovider.MetricValue{}
|
||||
for _, value := range metric.Datapoints.Member {
|
||||
values = append(values, cloudprovider.MetricValue{
|
||||
Timestamp: value.Timestamp,
|
||||
Value: value.Average,
|
||||
})
|
||||
}
|
||||
metricValue := cloudprovider.MetricValues{
|
||||
Id: metric.Instance,
|
||||
Values: values,
|
||||
}
|
||||
switch metric.Label {
|
||||
case "cpu.utilizition.total":
|
||||
metricValue.MetricType = cloudprovider.VM_METRIC_TYPE_CPU_USAGE
|
||||
case "memory.utilizition.total":
|
||||
metricValue.MetricType = cloudprovider.VM_METRIC_TYPE_MEM_USAGE
|
||||
case "vfs.fs.size":
|
||||
metricValue.MetricType = cloudprovider.VM_METRIC_TYPE_DISK_USAGE
|
||||
default:
|
||||
log.Errorf("invalid metric label %s", metric.Label)
|
||||
continue
|
||||
}
|
||||
ret = append(ret, metricValue)
|
||||
}
|
||||
|
||||
return ret, nil
|
||||
}
|
||||
+3
-3
@@ -59,7 +59,7 @@ type SNetwork struct {
|
||||
|
||||
func (region *SRegion) GetNetworks(vpcIds, networkIds []string, zoneName string) ([]SNetwork, error) {
|
||||
networks := []SNetwork{}
|
||||
param := map[string]string{}
|
||||
param := map[string]interface{}{}
|
||||
searchIndex := 1
|
||||
if len(vpcIds) > 0 {
|
||||
param[fmt.Sprintf("Filter.%d.Name", searchIndex)] = "vpc-id"
|
||||
@@ -203,7 +203,7 @@ func (net *SNetwork) GetDescription() string {
|
||||
}
|
||||
|
||||
func (region *SRegion) DeleteNetwork(networkId string) error {
|
||||
params := map[string]string{
|
||||
params := map[string]interface{}{
|
||||
"SubnetId": networkId,
|
||||
}
|
||||
_, err := region.vpcRequest("DeleteSubnet", params)
|
||||
@@ -217,7 +217,7 @@ func (region *SRegion) CreateNetwork(vpcId, zoneId string, opts *cloudprovider.S
|
||||
}
|
||||
startIp := pref.Address.NetAddr(pref.MaskLen) // 0
|
||||
gateway := startIp.StepUp() // 1
|
||||
params := map[string]string{
|
||||
params := map[string]interface{}{
|
||||
"VpcId": vpcId,
|
||||
"SubnetName": opts.Name,
|
||||
"CidrBlock": opts.Cidr,
|
||||
|
||||
+3
-3
@@ -102,7 +102,7 @@ func (client *SKsyunClient) GetICloudpolicies() ([]cloudprovider.ICloudpolicy, e
|
||||
}
|
||||
|
||||
func (client *SKsyunClient) ListPolicies(scope string) ([]SPolicy, error) {
|
||||
params := map[string]string{
|
||||
params := map[string]interface{}{
|
||||
"MaxItems": "100",
|
||||
}
|
||||
if len(scope) > 0 {
|
||||
@@ -134,7 +134,7 @@ func (client *SKsyunClient) ListPolicies(scope string) ([]SPolicy, error) {
|
||||
}
|
||||
|
||||
func (client *SKsyunClient) DeletePolicy(krn string) error {
|
||||
params := map[string]string{
|
||||
params := map[string]interface{}{
|
||||
"PolicyKrn": krn,
|
||||
}
|
||||
_, err := client.iamRequest("", "DeletePolicy", params)
|
||||
@@ -146,7 +146,7 @@ type SPolicyVersion struct {
|
||||
}
|
||||
|
||||
func (client *SKsyunClient) GetPolicyVersion(krn, version string) (*SPolicyVersion, error) {
|
||||
params := map[string]string{
|
||||
params := map[string]interface{}{
|
||||
"PolicyKrn": krn,
|
||||
"VersionId": version,
|
||||
}
|
||||
|
||||
+1
-1
@@ -97,7 +97,7 @@ func (self *SKsyunClient) GetIProjects() ([]cloudprovider.ICloudProject, error)
|
||||
}
|
||||
|
||||
func (cli *SKsyunClient) CreateProject(name string) (*SProject, error) {
|
||||
params := map[string]string{
|
||||
params := map[string]interface{}{
|
||||
"ProjectName": name,
|
||||
}
|
||||
_, err := cli.iamRequest("", "CreateProject", params)
|
||||
|
||||
+6
-6
@@ -260,26 +260,26 @@ func (r *SRegion) GetIVMById(id string) (cloudprovider.ICloudVM, error) {
|
||||
return vm, nil
|
||||
}
|
||||
|
||||
func (region *SRegion) ecsRequest(action string, params map[string]string) (jsonutils.JSONObject, error) {
|
||||
func (region *SRegion) ecsRequest(action string, params map[string]interface{}) (jsonutils.JSONObject, error) {
|
||||
return region.client.ec2Request(region.Region, action, params)
|
||||
}
|
||||
|
||||
func (region *SRegion) tagRequest(action string, params map[string]string) (jsonutils.JSONObject, error) {
|
||||
func (region *SRegion) tagRequest(action string, params map[string]interface{}) (jsonutils.JSONObject, error) {
|
||||
return region.client.tagRequest(region.Region, action, params)
|
||||
}
|
||||
|
||||
func (region *SRegion) eipRequest(action string, params map[string]string) (jsonutils.JSONObject, error) {
|
||||
func (region *SRegion) eipRequest(action string, params map[string]interface{}) (jsonutils.JSONObject, error) {
|
||||
return region.client.eipRequest(region.Region, action, params)
|
||||
}
|
||||
|
||||
func (region *SRegion) ebsRequest(action string, params map[string]string) (jsonutils.JSONObject, error) {
|
||||
func (region *SRegion) ebsRequest(action string, params map[string]interface{}) (jsonutils.JSONObject, error) {
|
||||
return region.client.ebsRequest(region.Region, action, params)
|
||||
}
|
||||
|
||||
func (region *SRegion) vpcRequest(action string, params map[string]string) (jsonutils.JSONObject, error) {
|
||||
func (region *SRegion) vpcRequest(action string, params map[string]interface{}) (jsonutils.JSONObject, error) {
|
||||
return region.client.vpcRequest(region.Region, action, params)
|
||||
}
|
||||
|
||||
func (region *SRegion) rdsRequest(action string, params map[string]string) (jsonutils.JSONObject, error) {
|
||||
func (region *SRegion) rdsRequest(action string, params map[string]interface{}) (jsonutils.JSONObject, error) {
|
||||
return region.client.rdsRequest(region.Region, action, params)
|
||||
}
|
||||
|
||||
+2
-2
@@ -96,7 +96,7 @@ func (rule *SPermission) Delete() error {
|
||||
}
|
||||
|
||||
func (region *SRegion) DeleteSecurityGroupRule(groupId string, ruleId string) error {
|
||||
params := map[string]string{
|
||||
params := map[string]interface{}{
|
||||
"SecurityGroupId": groupId,
|
||||
"SecurityGroupEntryId": ruleId,
|
||||
}
|
||||
@@ -113,7 +113,7 @@ func (group *SSecurityGroup) CreateRule(opts *cloudprovider.SecurityGroupRuleCre
|
||||
}
|
||||
|
||||
func (region *SRegion) CreateSecurityGroupRule(groupId string, opts *cloudprovider.SecurityGroupRuleCreateOptions) (*SPermission, error) {
|
||||
params := map[string]string{
|
||||
params := map[string]interface{}{
|
||||
"SecurityGroupId": groupId,
|
||||
"CidrBlock": opts.CIDR,
|
||||
"Direction": string(opts.Direction),
|
||||
|
||||
+4
-4
@@ -119,7 +119,7 @@ func (secgroup *SSecurityGroup) GetReferences() ([]cloudprovider.SecurityGroupRe
|
||||
|
||||
func (region *SRegion) GetSecurityGroups(vpcId string, securityGroupIds []string) ([]SSecurityGroup, error) {
|
||||
ret := []SSecurityGroup{}
|
||||
params := map[string]string{
|
||||
params := map[string]interface{}{
|
||||
"MaxResults": "1000",
|
||||
}
|
||||
if len(vpcId) > 0 {
|
||||
@@ -165,7 +165,7 @@ func (region *SRegion) GetSecurityGroup(id string) (*SSecurityGroup, error) {
|
||||
}
|
||||
|
||||
func (region *SRegion) CreateSecurityGroup(opts *cloudprovider.SecurityGroupCreateInput) (*SSecurityGroup, error) {
|
||||
params := map[string]string{
|
||||
params := map[string]interface{}{
|
||||
"VpcId": opts.VpcId,
|
||||
"SecurityGroupName": opts.Name,
|
||||
}
|
||||
@@ -185,7 +185,7 @@ func (region *SRegion) CreateSecurityGroup(opts *cloudprovider.SecurityGroupCrea
|
||||
}
|
||||
|
||||
func (region *SRegion) SetSecurityGroups(secgroupIds []string, instanceId, nicId, subnetId string) error {
|
||||
params := map[string]string{
|
||||
params := map[string]interface{}{
|
||||
"InstanceId": instanceId,
|
||||
"NetworkInterfaceId": nicId,
|
||||
"SubnetId": subnetId,
|
||||
@@ -209,7 +209,7 @@ func (sg *SSecurityGroup) Delete() error {
|
||||
}
|
||||
|
||||
func (region *SRegion) DeleteSecurityGroup(secGrpId string) error {
|
||||
params := map[string]string{
|
||||
params := map[string]interface{}{
|
||||
"SecurityGroupId": secGrpId,
|
||||
}
|
||||
_, err := region.vpcRequest("DeleteSecurityGroup", params)
|
||||
|
||||
+3
-3
@@ -152,7 +152,7 @@ func (self *SSnapshot) Delete() error {
|
||||
}
|
||||
|
||||
func (region *SRegion) CreateSnapshot(diskId, name, desc string) (*SSnapshot, error) {
|
||||
params := map[string]string{
|
||||
params := map[string]interface{}{
|
||||
"VolumeId": diskId,
|
||||
"SnapshotName": name,
|
||||
"SnapshotDesc": desc,
|
||||
@@ -170,7 +170,7 @@ func (region *SRegion) CreateSnapshot(diskId, name, desc string) (*SSnapshot, er
|
||||
}
|
||||
|
||||
func (region *SRegion) GetSnapshots(snapshotId, volumeId string) ([]SSnapshot, error) {
|
||||
params := map[string]string{
|
||||
params := map[string]interface{}{
|
||||
"PageSize": "1000",
|
||||
}
|
||||
if len(snapshotId) > 0 {
|
||||
@@ -221,7 +221,7 @@ func (region *SRegion) GetSnapshot(id string) (*SSnapshot, error) {
|
||||
}
|
||||
|
||||
func (region *SRegion) DeleteSnapshot(snapshotId string) error {
|
||||
params := map[string]string{
|
||||
params := map[string]interface{}{
|
||||
"SnapshotId": snapshotId,
|
||||
}
|
||||
_, err := region.ebsRequest("DeleteSnapshot", params)
|
||||
|
||||
+10
-10
@@ -33,15 +33,6 @@ type SStorage struct {
|
||||
StorageType string
|
||||
}
|
||||
|
||||
var ksDiskTypes = []string{
|
||||
api.STORAGE_KSYUN_ESSD_AUTO_PL,
|
||||
api.STORAGE_KSYUN_ESSD_PL1,
|
||||
api.STORAGE_KSYUN_ESSD_PL2,
|
||||
api.STORAGE_KSYUN_ESSD_PL3,
|
||||
api.STORAGE_KSYUN_SSD3_0,
|
||||
api.STORAGE_KSYUN_EHDD,
|
||||
}
|
||||
|
||||
func (storage *SStorage) GetId() string {
|
||||
return fmt.Sprintf("%s-%s-%s", storage.zone.region.client.cpcfg.Id, storage.zone.GetId(), storage.StorageType)
|
||||
}
|
||||
@@ -108,6 +99,15 @@ func (storage *SStorage) CreateIDisk(opts *cloudprovider.DiskCreateConfig) (clou
|
||||
}
|
||||
|
||||
func (storage *SStorage) GetIDiskById(id string) (cloudprovider.ICloudDisk, error) {
|
||||
if len(strings.Split(id, "-")) >= 4 { // Local SSD
|
||||
return &SDisk{
|
||||
storage: storage,
|
||||
VolumeId: id,
|
||||
VolumeType: storage.StorageType,
|
||||
VolumeName: id,
|
||||
VolumeCategory: "data",
|
||||
}, nil
|
||||
}
|
||||
disks, err := storage.zone.region.GetDisks([]string{id}, "", storage.zone.GetId())
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -130,7 +130,7 @@ func (storage *SStorage) IsSysDiskStore() bool {
|
||||
}
|
||||
|
||||
func (storage *SStorage) DisableSync() bool {
|
||||
return false
|
||||
return storage.StorageType == api.STORAGE_KSYUN_LOCAL_SSD
|
||||
}
|
||||
|
||||
func (storage *SStorage) GetIStoragecache() cloudprovider.ICloudStoragecache {
|
||||
|
||||
+1
-1
@@ -32,7 +32,7 @@ func (vv TagSet) GetTags() map[string]string {
|
||||
}
|
||||
|
||||
func (self *SRegion) ListTags(resType string, resId string) (*TagSet, error) {
|
||||
params := map[string]string{
|
||||
params := map[string]interface{}{
|
||||
"MaxResults": "1000",
|
||||
"Filter.1.Name": "resource-type",
|
||||
"Filter.1.Value.1": resType,
|
||||
|
||||
+10
-10
@@ -103,7 +103,7 @@ func (user *SUser) ResetPassword(password string) error {
|
||||
}
|
||||
|
||||
func (client *SKsyunClient) UpdateLoginProfile(name, password string) error {
|
||||
params := map[string]string{
|
||||
params := map[string]interface{}{
|
||||
"UserName": name,
|
||||
"Password": password,
|
||||
"ViewAllProject": "true",
|
||||
@@ -119,7 +119,7 @@ type LoginProfile struct {
|
||||
}
|
||||
|
||||
func (client *SKsyunClient) GetLoginProfile(name string) (*LoginProfile, error) {
|
||||
params := map[string]string{
|
||||
params := map[string]interface{}{
|
||||
"UserName": name,
|
||||
}
|
||||
resp, err := client.iamRequest("", "GetLoginProfile", params)
|
||||
@@ -143,7 +143,7 @@ func (user *SUser) DetachPolicy(policyName string, policyType api.TPolicyType) e
|
||||
}
|
||||
|
||||
func (client *SKsyunClient) GetUsers() ([]SUser, error) {
|
||||
params := map[string]string{
|
||||
params := map[string]interface{}{
|
||||
"MaxItems": "100",
|
||||
}
|
||||
ret := []SUser{}
|
||||
@@ -172,7 +172,7 @@ func (client *SKsyunClient) GetUsers() ([]SUser, error) {
|
||||
}
|
||||
|
||||
func (client *SKsyunClient) DeleteUser(name string) error {
|
||||
params := map[string]string{
|
||||
params := map[string]interface{}{
|
||||
"UserName": name,
|
||||
}
|
||||
_, err := client.iamRequest("", "DeleteUser", params)
|
||||
@@ -201,7 +201,7 @@ func (client *SKsyunClient) CreateIClouduser(opts *cloudprovider.SClouduserCreat
|
||||
}
|
||||
|
||||
func (client *SKsyunClient) CreateUser(opts *cloudprovider.SClouduserCreateConfig) (*SUser, error) {
|
||||
params := map[string]string{
|
||||
params := map[string]interface{}{
|
||||
"UserName": opts.Name,
|
||||
"Remark": opts.Desc,
|
||||
"Email": opts.Email,
|
||||
@@ -221,7 +221,7 @@ func (client *SKsyunClient) CreateUser(opts *cloudprovider.SClouduserCreateConfi
|
||||
}
|
||||
|
||||
func (client *SKsyunClient) ListGroupsForUser(name string) ([]SGroup, error) {
|
||||
params := map[string]string{
|
||||
params := map[string]interface{}{
|
||||
"UserName": name,
|
||||
"MaxItems": "100",
|
||||
}
|
||||
@@ -251,7 +251,7 @@ func (client *SKsyunClient) ListGroupsForUser(name string) ([]SGroup, error) {
|
||||
}
|
||||
|
||||
func (client *SKsyunClient) ListAttachedUserPolicies(name string) ([]SPolicy, error) {
|
||||
params := map[string]string{
|
||||
params := map[string]interface{}{
|
||||
"UserName": name,
|
||||
"MaxItems": "100",
|
||||
}
|
||||
@@ -281,7 +281,7 @@ func (client *SKsyunClient) ListAttachedUserPolicies(name string) ([]SPolicy, er
|
||||
}
|
||||
|
||||
func (client *SKsyunClient) AttachUserPolicy(name, policy string) error {
|
||||
params := map[string]string{
|
||||
params := map[string]interface{}{
|
||||
"UserName": name,
|
||||
"PolicyKrn": policy,
|
||||
}
|
||||
@@ -290,7 +290,7 @@ func (client *SKsyunClient) AttachUserPolicy(name, policy string) error {
|
||||
}
|
||||
|
||||
func (client *SKsyunClient) DetachUserPolicy(name, policy string) error {
|
||||
params := map[string]string{
|
||||
params := map[string]interface{}{
|
||||
"UserName": name,
|
||||
"PolicyKrn": policy,
|
||||
}
|
||||
@@ -307,7 +307,7 @@ func (client *SKsyunClient) GetIClouduserByName(name string) (cloudprovider.IClo
|
||||
}
|
||||
|
||||
func (client *SKsyunClient) GetUser(name string) (*SUser, error) {
|
||||
params := map[string]string{
|
||||
params := map[string]interface{}{
|
||||
"UserName": name,
|
||||
}
|
||||
resp, err := client.iamRequest("", "GetUser", params)
|
||||
|
||||
+3
-3
@@ -40,7 +40,7 @@ type SVpc struct {
|
||||
}
|
||||
|
||||
func (region *SRegion) GetVpcs(ids []string) ([]SVpc, error) {
|
||||
param := map[string]string{
|
||||
param := map[string]interface{}{
|
||||
"MaxResults": "1000",
|
||||
}
|
||||
for i, vpcId := range ids {
|
||||
@@ -185,7 +185,7 @@ func (vpc *SVpc) GetIWireById(wireId string) (cloudprovider.ICloudWire, error) {
|
||||
}
|
||||
|
||||
func (vpc *SRegion) DeleteVpc(vpcId string) error {
|
||||
params := map[string]string{
|
||||
params := map[string]interface{}{
|
||||
"VpcId": vpcId,
|
||||
}
|
||||
_, err := vpc.vpcRequest("DeleteVpc", params)
|
||||
@@ -193,7 +193,7 @@ func (vpc *SRegion) DeleteVpc(vpcId string) error {
|
||||
}
|
||||
|
||||
func (region *SRegion) CreateVpc(opts *cloudprovider.VpcCreateOptions) (*SVpc, error) {
|
||||
params := map[string]string{
|
||||
params := map[string]interface{}{
|
||||
"VpcName": opts.NAME,
|
||||
"CidrBlock": opts.CIDR,
|
||||
}
|
||||
|
||||
+11
-7
@@ -35,9 +35,9 @@ type SZone struct {
|
||||
}
|
||||
|
||||
func (region *SRegion) GetZones() ([]SZone, error) {
|
||||
params := map[string]string{}
|
||||
params := map[string]interface{}{}
|
||||
if len(region.Region) > 0 {
|
||||
params = map[string]string{"Region": region.Region}
|
||||
params = map[string]interface{}{"Region": region.Region}
|
||||
}
|
||||
resp, err := region.ecsRequest("DescribeAvailabilityZones", params)
|
||||
if err != nil {
|
||||
@@ -148,13 +148,17 @@ func (zone *SZone) GetDescription() string {
|
||||
|
||||
func (zone *SZone) GetStorages() ([]SStorage, error) {
|
||||
zoneDiskType := []string{}
|
||||
for i := range ksDiskTypes {
|
||||
params := map[string]string{
|
||||
"VolumeType": ksDiskTypes[i],
|
||||
for i := range api.KSYUN_STORAGES {
|
||||
if api.KSYUN_STORAGES[i] == api.STORAGE_KSYUN_LOCAL_SSD {
|
||||
zoneDiskType = append(zoneDiskType, api.KSYUN_STORAGES[i])
|
||||
continue
|
||||
}
|
||||
params := map[string]interface{}{
|
||||
"VolumeType": api.KSYUN_STORAGES[i],
|
||||
}
|
||||
resp, err := zone.region.ebsRequest("DescribeAvailabilityZones", params)
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(err, "%s:ValidateAttachInstance", ksDiskTypes[i])
|
||||
return nil, errors.Wrapf(err, "%s:ValidateAttachInstance", api.KSYUN_STORAGES[i])
|
||||
}
|
||||
zoneList := []string{}
|
||||
err = resp.Unmarshal(&zoneList, "AvailabilityZones")
|
||||
@@ -162,7 +166,7 @@ func (zone *SZone) GetStorages() ([]SStorage, error) {
|
||||
return nil, errors.Wrap(err, "unmarshal zoneList")
|
||||
}
|
||||
if utils.IsInStringArray(zone.GetName(), zoneList) {
|
||||
zoneDiskType = append(zoneDiskType, ksDiskTypes[i])
|
||||
zoneDiskType = append(zoneDiskType, api.KSYUN_STORAGES[i])
|
||||
}
|
||||
}
|
||||
storages := []SStorage{}
|
||||
|
||||
+2
-2
@@ -168,7 +168,7 @@ func (self *SQcloudClient) GetEcsMetrics(opts *cloudprovider.MetricListOptions)
|
||||
},
|
||||
} {
|
||||
for metricName, tag := range metricNames {
|
||||
metrics, err := self.GetMonitorData("QCE/CVM", metricName, 0, opts.StartTime, opts.EndTime, opts.RegionExtId, "InstanceId", opts.ResourceIds)
|
||||
metrics, err := self.GetMonitorData("QCE/CVM", metricName, 60, opts.StartTime, opts.EndTime, opts.RegionExtId, "InstanceId", opts.ResourceIds)
|
||||
if err != nil {
|
||||
log.Errorf("GetMonitorData error: %v", err)
|
||||
continue
|
||||
@@ -236,7 +236,7 @@ func (self *SQcloudClient) GetRedisMetrics(opts *cloudprovider.MetricListOptions
|
||||
},
|
||||
} {
|
||||
for metricName, tag := range metricNames {
|
||||
metrics, err := self.GetMonitorData("QCE/REDIS_MEM", metricName, 0, opts.StartTime, opts.EndTime, opts.RegionExtId, "instanceid", opts.ResourceIds)
|
||||
metrics, err := self.GetMonitorData("QCE/REDIS_MEM", metricName, 60, opts.StartTime, opts.EndTime, opts.RegionExtId, "instanceid", opts.ResourceIds)
|
||||
if err != nil {
|
||||
log.Errorf("GetMonitorData error: %v", err)
|
||||
continue
|
||||
|
||||
+1
-1
@@ -511,7 +511,7 @@ func (client *SQcloudClient) getSdkClient(regionId string) (*common.Client, erro
|
||||
return nil
|
||||
}
|
||||
if client.cpcfg.ReadOnly {
|
||||
for _, prefix := range []string{"Get", "List", "Describe"} {
|
||||
for _, prefix := range []string{"Get", "List", "Describe", "LookUpEvents"} {
|
||||
if strings.HasPrefix(action, prefix) {
|
||||
return respCheck, nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user