From 481e176ea254c6ae07928c6d8da13c47f428109c Mon Sep 17 00:00:00 2001 From: lvyangyang Date: Tue, 12 Jan 2021 03:29:50 -0500 Subject: [PATCH] =?UTF-8?q?fix(region):=20tag=20bugs=20fix=20-azure=20tags?= =?UTF-8?q?=20replace/refresh=20-tags=20action=20logs=20-=E5=BF=BD?= =?UTF-8?q?=E7=95=A5=E5=88=9B=E5=BB=BA=E4=B8=AD=E4=B8=BB=E6=9C=BA=E7=9A=84?= =?UTF-8?q?metadate=E5=90=8C=E6=AD=A5=E4=BB=BB=E5=8A=A1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pkg/apis/compute/dbinstance_const.go | 3 +++ pkg/apis/compute/elasticcache_const.go | 5 ++++ pkg/apis/compute/guest_const.go | 3 +++ pkg/apis/compute/loadbalancer_const.go | 3 +++ pkg/cloudprovider/resourcetags.go | 20 +++++++++++++++ pkg/compute/guestdrivers/managedvirtual.go | 14 ++++++++++- pkg/compute/models/buckets.go | 14 ++++++++++- pkg/compute/models/guests.go | 4 +++ pkg/compute/regiondrivers/managedvirtual.go | 24 +++++++++++++++--- .../tasks/dbinstance_remote_update_task.go | 4 +-- .../tasks/elasticcache_remote_update_task.go | 4 +-- pkg/compute/tasks/guest_remote_update_task.go | 25 +++++++++++++------ .../tasks/loadbalancer_remote_update_task.go | 5 ++-- pkg/multicloud/aws/instance.go | 3 ++- pkg/multicloud/azure/azure.go | 7 +++++- pkg/multicloud/azure/instance.go | 7 +++++- pkg/multicloud/azure/shell/instance.go | 2 +- pkg/multicloud/google/instance.go | 7 +++++- pkg/multicloud/huawei/instance.go | 16 ++++++------ pkg/multicloud/huawei/shell/instance.go | 13 ++++++++++ 20 files changed, 152 insertions(+), 31 deletions(-) create mode 100644 pkg/cloudprovider/resourcetags.go diff --git a/pkg/apis/compute/dbinstance_const.go b/pkg/apis/compute/dbinstance_const.go index 5d45f9cd19..7fb2828402 100644 --- a/pkg/apis/compute/dbinstance_const.go +++ b/pkg/apis/compute/dbinstance_const.go @@ -51,6 +51,9 @@ const ( DBINSTANCE_FAILE = "failed" //操作失败 + DBINSTANCE_UPDATE_TAGS = "update_tags" + DBINSTANCE_UPDATE_TAGS_FAILED = "update_tags_fail" + //备份状态 DBINSTANCE_BACKUP_READY = "ready" //正常 DBINSTANCE_BACKUP_CREATING = "creating" //创建中 diff --git a/pkg/apis/compute/elasticcache_const.go b/pkg/apis/compute/elasticcache_const.go index 5fd5a66907..92dbcb8a40 100644 --- a/pkg/apis/compute/elasticcache_const.go +++ b/pkg/apis/compute/elasticcache_const.go @@ -60,6 +60,11 @@ const ( ELASTIC_CACHE_ACCOUNT_STATUS_DELETED = "deleted" // 已删除 ) +const ( + ELASTIC_CACHE_UPDATE_TAGS = "update_tags" + ELASTIC_CACHE_UPDATE_TAGS_FAILED = "update_tags_fail" +) + const ( ELASTIC_CACHE_ACCOUNT_TYPE_NORMAL = "normal" // 普通账号 ELASTIC_CACHE_ACCOUNT_TYPE_ADMIN = "admin" // 管理账号 diff --git a/pkg/apis/compute/guest_const.go b/pkg/apis/compute/guest_const.go index 50aeff048c..8e745c3cd4 100644 --- a/pkg/apis/compute/guest_const.go +++ b/pkg/apis/compute/guest_const.go @@ -140,6 +140,9 @@ const ( VM_TEMPLATE_SAVING = "tempalte_saving" VM_TEMPLATE_SAVE_FAILED = "template_save_failed" + VM_UPDATE_TAGS = "update_tags" + VM_UPDATE_TAGS_FAILED = "update_tags_fail" + SHUTDOWN_STOP = "stop" SHUTDOWN_TERMINATE = "terminate" diff --git a/pkg/apis/compute/loadbalancer_const.go b/pkg/apis/compute/loadbalancer_const.go index c2592324e4..fd16df1803 100644 --- a/pkg/apis/compute/loadbalancer_const.go +++ b/pkg/apis/compute/loadbalancer_const.go @@ -55,6 +55,9 @@ const ( LB_STATUS_START_FAILED = "start_failed" LB_STATUS_STOP_FAILED = "stop_failed" + LB_UPDATE_TAGS = "update_tags" + LB_UPDATE_TAGS_FAILED = "update_tags_fail" + LB_STATUS_UNKNOWN = "unknown" ) diff --git a/pkg/cloudprovider/resourcetags.go b/pkg/cloudprovider/resourcetags.go new file mode 100644 index 0000000000..ecce8963a6 --- /dev/null +++ b/pkg/cloudprovider/resourcetags.go @@ -0,0 +1,20 @@ +// 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 + +type TagsUpdateInfo struct { + OldTags map[string]string + NewTags map[string]string +} diff --git a/pkg/compute/guestdrivers/managedvirtual.go b/pkg/compute/guestdrivers/managedvirtual.go index b8e7bb5462..131aa2d72d 100644 --- a/pkg/compute/guestdrivers/managedvirtual.go +++ b/pkg/compute/guestdrivers/managedvirtual.go @@ -40,6 +40,7 @@ import ( "yunion.io/x/onecloud/pkg/mcclient" "yunion.io/x/onecloud/pkg/util/billing" "yunion.io/x/onecloud/pkg/util/cloudinit" + "yunion.io/x/onecloud/pkg/util/logclient" ) type SManagedVirtualizedGuestDriver struct { @@ -1267,14 +1268,21 @@ func (self *SManagedVirtualizedGuestDriver) RequestRemoteUpdate(ctx context.Cont if err != nil { return errors.Wrap(err, "guest.GetIVM") } + oldTags, err := iVM.GetTags() + if err != nil { + return errors.Wrap(err, "iVM.GetTags()") + } tags, err := guest.GetAllUserMetadata() if err != nil { log.Errorf("GetAllUserMetadata fail %s", err) } else { + tagsUpdateInfo := cloudprovider.TagsUpdateInfo{OldTags: oldTags, NewTags: tags} err := iVM.SetTags(tags, replaceTags) if err != nil { + logclient.AddSimpleActionLog(guest, logclient.ACT_UPDATE_TAGS, err, userCred, false) return errors.Wrap(err, "iVM.SetMetadata") } + logclient.AddSimpleActionLog(guest, logclient.ACT_UPDATE_TAGS, tagsUpdateInfo, userCred, true) // sync back cloud metadata iVM.Refresh() err = models.SyncVirtualResourceMetadata(ctx, userCred, guest, iVM) @@ -1282,9 +1290,13 @@ func (self *SManagedVirtualizedGuestDriver) RequestRemoteUpdate(ctx context.Cont return errors.Wrap(err, "syncVirtualResourceMetadata") } } + err = iVM.UpdateVM(ctx, guest.Name) if err != nil { - return errors.Wrap(err, "iVM.UpdateVM") + if errors.Cause(err) != cloudprovider.ErrNotSupported { + return errors.Wrap(err, "iVM.UpdateVM") + } } + return nil } diff --git a/pkg/compute/models/buckets.go b/pkg/compute/models/buckets.go index 528dd14f44..c692e0a6db 100644 --- a/pkg/compute/models/buckets.go +++ b/pkg/compute/models/buckets.go @@ -1869,19 +1869,31 @@ func (bucket *SBucket) processObjectsActionInput(input api.BucketObjectsActionIn } func (bucket *SBucket) OnMetadataUpdated(ctx context.Context, userCred mcclient.TokenCredential) { + if len(bucket.ExternalId) == 0 { + return + } iBucket, err := bucket.GetIBucket() if err != nil { log.Errorf("bucket.GetIBucket() failed: %s", err) return } + oldTags, err := iBucket.GetTags() + if err != nil { + logclient.AddSimpleActionLog(bucket, logclient.ACT_UPDATE_TAGS, err, userCred, false) + log.Errorf("iBucket.GetTags failed: %s", err) + return + } tags, _ := bucket.GetAllUserMetadata() + tagsUpdateInfo := cloudprovider.TagsUpdateInfo{OldTags: oldTags, NewTags: tags} + err = cloudprovider.SetBucketMetadata(iBucket, tags, true) if err != nil { + logclient.AddSimpleActionLog(bucket, logclient.ACT_UPDATE_TAGS, err, userCred, false) log.Errorf("iBucket.SetMetadata failed: %s", err) return } syncMetadata(ctx, userCred, bucket, iBucket) - db.OpsLog.LogEvent(bucket, db.ACT_UPDATE_TAGS, tags, userCred) + logclient.AddSimpleActionLog(bucket, logclient.ACT_UPDATE_TAGS, tagsUpdateInfo, userCred, true) } func (manager *SBucketManager) ListItemExportKeys(ctx context.Context, diff --git a/pkg/compute/models/guests.go b/pkg/compute/models/guests.go index b3afdb3959..db7a153a99 100644 --- a/pkg/compute/models/guests.go +++ b/pkg/compute/models/guests.go @@ -5695,12 +5695,16 @@ func (guest *SGuest) StartRemoteUpdateTask(ctx context.Context, userCred mcclien log.Errorln(err) return errors.Wrap(err, "Start GuestRemoteUpdateTask") } else { + guest.SetStatus(userCred, api.VM_UPDATE_TAGS, "StartRemoteUpdateTask") task.ScheduleRun(nil) } return nil } func (guest *SGuest) OnMetadataUpdated(ctx context.Context, userCred mcclient.TokenCredential) { + if len(guest.ExternalId) == 0 { + return + } err := guest.StartRemoteUpdateTask(ctx, userCred, true, "") if err != nil { log.Errorf("StartRemoteUpdateTask fail: %s", err) diff --git a/pkg/compute/regiondrivers/managedvirtual.go b/pkg/compute/regiondrivers/managedvirtual.go index 5656ef7942..a2e4f6f3ed 100644 --- a/pkg/compute/regiondrivers/managedvirtual.go +++ b/pkg/compute/regiondrivers/managedvirtual.go @@ -331,14 +331,21 @@ func (self *SManagedVirtualizationRegionDriver) RequestRemoteUpdateLoadbalancer( if err != nil { return nil, err } + oldTags, err := iLoadbalancer.GetTags() + if err != nil { + return nil, errors.Wrap(err, "iLoadbalancer.GetTags()") + } tags, err := lb.GetAllUserMetadata() + tagsUpdateInfo := cloudprovider.TagsUpdateInfo{OldTags: oldTags, NewTags: tags} if err != nil { log.Errorf("GetAllUserMetadata fail %s", err) } else { err := iLoadbalancer.SetTags(tags, replaceTags) if err != nil { + logclient.AddActionLogWithStartable(task, lb, logclient.ACT_UPDATE, tagsUpdateInfo, userCred, false) return nil, errors.Wrap(err, "iLoadbalancer.SetMetadata") } + logclient.AddActionLogWithStartable(task, lb, logclient.ACT_UPDATE, tagsUpdateInfo, userCred, true) // sync back cloud metadata iLoadbalancer.Refresh() err = models.SyncVirtualResourceMetadata(ctx, userCred, lb, iLoadbalancer) @@ -348,7 +355,6 @@ func (self *SManagedVirtualizationRegionDriver) RequestRemoteUpdateLoadbalancer( } return nil, nil }) - // nil ops return nil } @@ -2726,14 +2732,21 @@ func (self *SManagedVirtualizationRegionDriver) RequestRemoteUpdateDBInstance(ct if err != nil { return nil, errors.Wrap(err, "instance.GetIDBInstance") } + oldTags, err := iRds.GetTags() + if err != nil { + return nil, errors.Wrap(err, "iRds.GetTags()") + } tags, err := instance.GetAllUserMetadata() + tagsUpdateInfo := cloudprovider.TagsUpdateInfo{OldTags: oldTags, NewTags: tags} if err != nil { log.Errorf("GetAllUserMetadata fail %s", err) } else { err := iRds.SetTags(tags, replaceTags) if err != nil { + logclient.AddActionLogWithStartable(task, instance, logclient.ACT_UPDATE, tagsUpdateInfo, userCred, false) return nil, errors.Wrap(err, "iRds.SetMetadata") } + logclient.AddActionLogWithStartable(task, instance, logclient.ACT_UPDATE, tagsUpdateInfo, userCred, true) // sync back cloud metadata iRds.Refresh() err = models.SyncVirtualResourceMetadata(ctx, userCred, instance, iRds) @@ -2743,7 +2756,6 @@ func (self *SManagedVirtualizationRegionDriver) RequestRemoteUpdateDBInstance(ct } return nil, nil }) - // nil ops return nil } @@ -3125,14 +3137,21 @@ func (self *SManagedVirtualizationRegionDriver) RequestRemoteUpdateElasticcache( } iElasticcache, err := iRegion.GetIElasticcacheById(elasticcache.ExternalId) + oldTags, err := iElasticcache.GetTags() + if err != nil { + return nil, errors.Wrap(err, "iElasticcache.GetTags()") + } tags, err := elasticcache.GetAllUserMetadata() + tagsUpdateInfo := cloudprovider.TagsUpdateInfo{OldTags: oldTags, NewTags: tags} if err != nil { log.Errorf("GetAllUserMetadata fail %s", err) } else { err := iElasticcache.SetTags(tags, replaceTags) if err != nil { + logclient.AddActionLogWithStartable(task, elasticcache, logclient.ACT_UPDATE, tagsUpdateInfo, userCred, false) return nil, errors.Wrap(err, "iElasticcache.SetMetadata") } + logclient.AddActionLogWithStartable(task, elasticcache, logclient.ACT_UPDATE, tagsUpdateInfo, userCred, true) // sync back cloud metadata iElasticcache.Refresh() err = models.SyncVirtualResourceMetadata(ctx, userCred, elasticcache, iElasticcache) @@ -3142,7 +3161,6 @@ func (self *SManagedVirtualizationRegionDriver) RequestRemoteUpdateElasticcache( } return nil, nil }) - // nil ops return nil } diff --git a/pkg/compute/tasks/dbinstance_remote_update_task.go b/pkg/compute/tasks/dbinstance_remote_update_task.go index ba5c5db1b8..d7f9e4bc39 100644 --- a/pkg/compute/tasks/dbinstance_remote_update_task.go +++ b/pkg/compute/tasks/dbinstance_remote_update_task.go @@ -19,10 +19,10 @@ import ( "yunion.io/x/jsonutils" + api "yunion.io/x/onecloud/pkg/apis/compute" "yunion.io/x/onecloud/pkg/cloudcommon/db" "yunion.io/x/onecloud/pkg/cloudcommon/db/taskman" "yunion.io/x/onecloud/pkg/compute/models" - "yunion.io/x/onecloud/pkg/util/logclient" ) type DBInstanceRemoteUpdateTask struct { @@ -34,7 +34,7 @@ func init() { } func (self *DBInstanceRemoteUpdateTask) taskFail(ctx context.Context, dbinstance *models.SDBInstance, reason jsonutils.JSONObject) { - logclient.AddActionLogWithStartable(self, dbinstance, logclient.ACT_UPDATE_TAGS, reason, self.UserCred, false) + dbinstance.SetStatus(self.UserCred, api.DBINSTANCE_UPDATE_TAGS_FAILED, reason.String()) self.SetStageFailed(ctx, reason) } diff --git a/pkg/compute/tasks/elasticcache_remote_update_task.go b/pkg/compute/tasks/elasticcache_remote_update_task.go index 9d43445b8d..862e0cd0e0 100644 --- a/pkg/compute/tasks/elasticcache_remote_update_task.go +++ b/pkg/compute/tasks/elasticcache_remote_update_task.go @@ -20,10 +20,10 @@ import ( "yunion.io/x/jsonutils" + api "yunion.io/x/onecloud/pkg/apis/compute" "yunion.io/x/onecloud/pkg/cloudcommon/db" "yunion.io/x/onecloud/pkg/cloudcommon/db/taskman" "yunion.io/x/onecloud/pkg/compute/models" - "yunion.io/x/onecloud/pkg/util/logclient" ) type ElasticcacheRemoteUpdateTask struct { @@ -35,7 +35,7 @@ func init() { } func (self *ElasticcacheRemoteUpdateTask) taskFail(ctx context.Context, elasticcache *models.SElasticcache, reason jsonutils.JSONObject) { - logclient.AddActionLogWithStartable(self, elasticcache, logclient.ACT_UPDATE_TAGS, reason, self.UserCred, false) + elasticcache.SetStatus(self.UserCred, api.ELASTIC_CACHE_UPDATE_TAGS_FAILED, reason.String()) self.SetStageFailed(ctx, reason) } diff --git a/pkg/compute/tasks/guest_remote_update_task.go b/pkg/compute/tasks/guest_remote_update_task.go index 3e2d88fbd8..adf1811ce9 100644 --- a/pkg/compute/tasks/guest_remote_update_task.go +++ b/pkg/compute/tasks/guest_remote_update_task.go @@ -18,13 +18,12 @@ import ( "context" "yunion.io/x/jsonutils" - "yunion.io/x/log" "yunion.io/x/pkg/errors" + api "yunion.io/x/onecloud/pkg/apis/compute" "yunion.io/x/onecloud/pkg/cloudcommon/db" "yunion.io/x/onecloud/pkg/cloudcommon/db/taskman" "yunion.io/x/onecloud/pkg/compute/models" - "yunion.io/x/onecloud/pkg/util/logclient" ) type GuestRemoteUpdateTask struct { @@ -37,13 +36,11 @@ func init() { func (self *GuestRemoteUpdateTask) OnInit(ctx context.Context, obj db.IStandaloneModel, data jsonutils.JSONObject) { guest := obj.(*models.SGuest) - db.OpsLog.LogEvent(guest, db.ACT_SYNC_CONF, nil, self.UserCred) self.SetStage("OnRemoteUpdateComplete", nil) replaceTags := jsonutils.QueryBoolean(self.Params, "replace_tags", false) taskman.LocalTaskRun(self, func() (jsonutils.JSONObject, error) { - if err := guest.GetDriver().RequestRemoteUpdate(ctx, guest, self.UserCred, replaceTags); err != nil { - logclient.AddActionLogWithStartable(self, guest, logclient.ACT_UPDATE, err, self.UserCred, false) - log.Errorf("RequestRemoteUpdate faled %v", err) + err := guest.GetDriver().RequestRemoteUpdate(ctx, guest, self.UserCred, replaceTags) + if err != nil { return nil, errors.Wrap(err, "RequestRemoteUpdate") } return nil, nil @@ -51,6 +48,20 @@ func (self *GuestRemoteUpdateTask) OnInit(ctx context.Context, obj db.IStandalon } -func (self *GuestRemoteUpdateTask) OnRemoteUpdateComplete(ctx context.Context, obj db.IStandaloneModel, data jsonutils.JSONObject) { +func (self *GuestRemoteUpdateTask) OnRemoteUpdateComplete(ctx context.Context, guest *models.SGuest, data jsonutils.JSONObject) { + self.SetStage("OnSyncStatusComplete", nil) + guest.StartSyncstatus(ctx, self.UserCred, self.GetTaskId()) +} + +func (self *GuestRemoteUpdateTask) OnRemoteUpdateCompleteFailed(ctx context.Context, guest *models.SGuest, data jsonutils.JSONObject) { + guest.SetStatus(self.UserCred, api.VM_UPDATE_TAGS_FAILED, data.String()) + self.SetStageFailed(ctx, data) +} + +func (self *GuestRemoteUpdateTask) OnSyncStatusComplete(ctx context.Context, guest *models.SGuest, data jsonutils.JSONObject) { self.SetStageComplete(ctx, nil) } + +func (self *GuestRemoteUpdateTask) OnSyncStatusCompleteFailed(ctx context.Context, guest *models.SGuest, data jsonutils.JSONObject) { + self.SetStageFailed(ctx, data) +} diff --git a/pkg/compute/tasks/loadbalancer_remote_update_task.go b/pkg/compute/tasks/loadbalancer_remote_update_task.go index 577849232f..ad8926ba00 100644 --- a/pkg/compute/tasks/loadbalancer_remote_update_task.go +++ b/pkg/compute/tasks/loadbalancer_remote_update_task.go @@ -20,10 +20,10 @@ import ( "yunion.io/x/jsonutils" + api "yunion.io/x/onecloud/pkg/apis/compute" "yunion.io/x/onecloud/pkg/cloudcommon/db" "yunion.io/x/onecloud/pkg/cloudcommon/db/taskman" "yunion.io/x/onecloud/pkg/compute/models" - "yunion.io/x/onecloud/pkg/util/logclient" ) type LoadbalancerRemoteUpdateTask struct { @@ -35,7 +35,7 @@ func init() { } func (self *LoadbalancerRemoteUpdateTask) taskFail(ctx context.Context, lb *models.SLoadbalancer, reason jsonutils.JSONObject) { - logclient.AddActionLogWithStartable(self, lb, logclient.ACT_UPDATE_TAGS, reason, self.UserCred, false) + lb.SetStatus(self.UserCred, api.LB_UPDATE_TAGS_FAILED, reason.String()) self.SetStageFailed(ctx, reason) } @@ -48,7 +48,6 @@ func (self *LoadbalancerRemoteUpdateTask) OnInit(ctx context.Context, obj db.ISt } self.SetStage("OnRemoteUpdateComplete", nil) replaceTags := jsonutils.QueryBoolean(self.Params, "replace_tags", false) - if err := region.GetDriver().RequestRemoteUpdateLoadbalancer(ctx, self.GetUserCred(), lb, replaceTags, self); err != nil { self.taskFail(ctx, lb, jsonutils.NewString(err.Error())) } diff --git a/pkg/multicloud/aws/instance.go b/pkg/multicloud/aws/instance.go index 21de470188..59a8ef7148 100644 --- a/pkg/multicloud/aws/instance.go +++ b/pkg/multicloud/aws/instance.go @@ -272,6 +272,7 @@ func (self *SInstance) GetTags() (map[string]string, error) { return nil, errors.Wrap(err, "tags.Unmarshal") } delete(data, "Name") + delete(data, "Description") return data, nil } @@ -1004,7 +1005,7 @@ func (self *SRegion) DeployVM(instanceId string, name string, password string, k func (self *SRegion) UpdateVM(instanceId string, hostname string) error { // https://docs.aws.amazon.com/zh_cn/AWSEC2/latest/UserGuide/set-hostname.html - return fmt.Errorf("aws not support change hostname.") + return cloudprovider.ErrNotSupported } func (self *SRegion) ReplaceSystemDisk(ctx context.Context, instanceId string, image *SImage, sysDiskSizeGB int, keypair string, userdata string) (string, error) { diff --git a/pkg/multicloud/azure/azure.go b/pkg/multicloud/azure/azure.go index 747cd92d84..b8280d2551 100644 --- a/pkg/multicloud/azure/azure.go +++ b/pkg/multicloud/azure/azure.go @@ -928,6 +928,7 @@ func (self *SAzureClient) GetCapabilities() []string { type TagParams struct { Properties TagProperties `json:"properties"` + Operation string `json:"operation"` } type TagProperties struct { @@ -953,6 +954,10 @@ func (self *SAzureClient) SetTags(resourceId string, tags map[string]string) (js } path := fmt.Sprintf("/%s/providers/Microsoft.Resources/tags/default", resourceId) input := TagParams{} + input.Operation = "replace" input.Properties.Tags = tags - return self.put(path, jsonutils.Marshal(input)) + if len(tags) == 0 { + return nil, self.del(path) + } + return self.patch(path, jsonutils.Marshal(input)) } diff --git a/pkg/multicloud/azure/instance.go b/pkg/multicloud/azure/instance.go index 28855d1b05..37ba5e4272 100644 --- a/pkg/multicloud/azure/instance.go +++ b/pkg/multicloud/azure/instance.go @@ -327,7 +327,12 @@ func (self *SInstance) Refresh() error { if err != nil { return err } - return jsonutils.Update(self, instance) + err = jsonutils.Update(self, instance) + if err != nil { + return err + } + self.Tags = instance.Tags + return nil } func (self *SInstance) GetStatus() string { diff --git a/pkg/multicloud/azure/shell/instance.go b/pkg/multicloud/azure/shell/instance.go index 265bbefdcb..efd87772f5 100644 --- a/pkg/multicloud/azure/shell/instance.go +++ b/pkg/multicloud/azure/shell/instance.go @@ -231,7 +231,7 @@ func init() { ID string `help:"Instance ID"` Tags []string } - shellutils.R(&InstanceSetTagsOptions{}, "instance-set-tags", "get intance metadata", func(cli *azure.SRegion, args *InstanceSetTagsOptions) error { + shellutils.R(&InstanceSetTagsOptions{}, "instance-set-tags", "set intance metadata", func(cli *azure.SRegion, args *InstanceSetTagsOptions) error { tags := map[string]string{} for i := range args.Tags { splited := strings.Split(args.Tags[i], "=") diff --git a/pkg/multicloud/google/instance.go b/pkg/multicloud/google/instance.go index 73ae3932c7..93f8a50414 100644 --- a/pkg/multicloud/google/instance.go +++ b/pkg/multicloud/google/instance.go @@ -153,7 +153,12 @@ func (instance *SInstance) Refresh() error { if err != nil { return err } - return jsonutils.Update(instance, _instance) + err = jsonutils.Update(instance, _instance) + if err != nil { + return err + } + instance.Labels = _instance.Labels + return nil } //PROVISIONING, STAGING, RUNNING, STOPPING, STOPPED, SUSPENDING, SUSPENDED, and TERMINATED. diff --git a/pkg/multicloud/huawei/instance.go b/pkg/multicloud/huawei/instance.go index 836b46856e..4ae58a610e 100644 --- a/pkg/multicloud/huawei/instance.go +++ b/pkg/multicloud/huawei/instance.go @@ -233,7 +233,12 @@ func (self *SInstance) Refresh() error { return cloudprovider.ErrNotFound } - return jsonutils.Update(self, new) + err = jsonutils.Update(self, new) + if err != nil { + return err + } + self.Tags = new.Tags + return nil } func (self *SInstance) IsEmulated() bool { @@ -1169,14 +1174,11 @@ func (self *SRegion) DeleteVM(instanceId string) error { func (self *SRegion) UpdateVM(instanceId, name string) error { params := jsonutils.NewDict() - serversObj := jsonutils.NewArray() serverObj := jsonutils.NewDict() - serverObj.Add(jsonutils.NewString(instanceId), "id") - serversObj.Add(serverObj) - params.Add(serversObj, "servers") - params.Add(jsonutils.NewString(name), "name") + serverObj.Add(jsonutils.NewString(name), "name") + params.Add(serverObj, "server") - _, err := self.ecsClient.Servers.PerformAction2("server-name", "", params, "") + _, err := self.ecsClient.Servers.Update(instanceId, params) return err } diff --git a/pkg/multicloud/huawei/shell/instance.go b/pkg/multicloud/huawei/shell/instance.go index 19cb24b199..95818a8525 100644 --- a/pkg/multicloud/huawei/shell/instance.go +++ b/pkg/multicloud/huawei/shell/instance.go @@ -222,4 +222,17 @@ func init() { } return nil }) + + type InstanceUpdateNameOptions struct { + ID string `help:"Instance ID"` + Name string + } + shellutils.R(&InstanceUpdateNameOptions{}, "instance-set-name", "set intance name", func(cli *huawei.SRegion, args *InstanceUpdateNameOptions) error { + + err := cli.UpdateVM(args.ID, args.Name) + if err != nil { + return err + } + return nil + }) }