mirror of
https://github.com/yunionio/cloudpods.git
synced 2026-09-21 14:19:49 +08:00
Merge pull request #9829 from lvyangyang/fix-tags2
fix(region): tag bugs fix
This commit is contained in:
@@ -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" //创建中
|
||||
|
||||
@@ -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" // 管理账号
|
||||
|
||||
@@ -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"
|
||||
|
||||
|
||||
@@ -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"
|
||||
)
|
||||
|
||||
|
||||
@@ -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
|
||||
}
|
||||
@@ -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
|
||||
}
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -5702,12 +5702,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)
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
|
||||
@@ -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()))
|
||||
}
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -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))
|
||||
}
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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], "=")
|
||||
|
||||
@@ -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.
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
|
||||
@@ -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
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user