Azure stop默认使用deallocate

This commit is contained in:
屈轩
2018-10-18 17:08:56 +08:00
parent a72b479bdb
commit 4e4d005907
2 changed files with 9 additions and 7 deletions
+7 -5
View File
@@ -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
+2 -2
View File
@@ -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 {