From 4e4d0059076f88fa0dd6823e60c0a2e0e899c78d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=B1=88=E8=BD=A9?= Date: Thu, 18 Oct 2018 17:08:56 +0800 Subject: [PATCH] =?UTF-8?q?Azure=20stop=E9=BB=98=E8=AE=A4=E4=BD=BF?= =?UTF-8?q?=E7=94=A8deallocate?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pkg/util/azure/instance.go | 12 +++++++----- pkg/util/azure/shell/instance.go | 4 ++-- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/pkg/util/azure/instance.go b/pkg/util/azure/instance.go index 1bfa396d5a..1b180d9429 100644 --- a/pkg/util/azure/instance.go +++ b/pkg/util/azure/instance.go @@ -543,7 +543,7 @@ func (self *SInstance) RebuildRoot(imageId string, passwd string, publicKey stri func (region *SRegion) ReplaceSystemDisk(instanceId, imageId, passwd, publicKey string, sysSizeGB int32) (string, error) { log.Debugf("ReplaceSystemDisk %s image: %s", instanceId, imageId) - if err := region.DeallocateVM(instanceId); err != nil { + if err := region.deallocateVM(instanceId); err != nil { return "", err } if instance, err := region.GetInstance(instanceId); err != nil { @@ -792,16 +792,18 @@ func (self *SInstance) StopVM(isForce bool) error { } func (self *SRegion) StopVM(instanceId string, isForce bool) error { - return self.doStopVM(instanceId, isForce) + return self.deallocateVM(instanceId) } -func (self *SRegion) DeallocateVM(instanceId string) error { +func (self *SRegion) deallocateVM(instanceId string) error { _, resourceGroup, instanceName := pareResourceGroupWithName(instanceId, INSTANCE_RESOURCE) computeClient := compute.NewVirtualMachinesClientWithBaseURI(self.client.baseUrl, self.client.subscriptionId) computeClient.Authorizer = self.client.authorizer - if result, err := computeClient.PowerOff(context.Background(), resourceGroup, instanceName); err != nil { + result, err := computeClient.Deallocate(context.Background(), resourceGroup, instanceName) + if err != nil { return err - } else if err := result.WaitForCompletion(context.Background(), computeClient.Client); err != nil { + } + if err := result.WaitForCompletion(context.Background(), computeClient.Client); err != nil { return err } return nil diff --git a/pkg/util/azure/shell/instance.go b/pkg/util/azure/shell/instance.go index 9ec4db0ce5..8b34612969 100644 --- a/pkg/util/azure/shell/instance.go +++ b/pkg/util/azure/shell/instance.go @@ -71,8 +71,8 @@ func init() { return cli.DeleteVM(args.ID) }) - shellutils.R(&InstanceOptions{}, "instance-deallocate", "Deallocate intance", func(cli *azure.SRegion, args *InstanceOptions) error { - return cli.DeallocateVM(args.ID) + shellutils.R(&InstanceOptions{}, "instance-stop", "Stop intance", func(cli *azure.SRegion, args *InstanceOptions) error { + return cli.StopVM(args.ID, true) }) type InstanceRebuildOptions struct {