Merge pull request #15185 from gouqi11/fix/remotefile

fix/remotefile guest
This commit is contained in:
Zexi Li
2022-10-14 21:13:00 +08:00
committed by GitHub
3 changed files with 18 additions and 2 deletions

View File

@@ -2673,6 +2673,9 @@ func (self *SGuest) syncRemoveCloudVM(ctx context.Context, userCred mcclient.Tok
if err != nil {
return err
}
if len(self.ExternalId) == 0 {
return self.purge(ctx, userCred)
}
iVM, err := iregion.GetIVMById(self.ExternalId)
if err == nil { //漂移归位
if hostId := iVM.GetIHostId(); len(hostId) > 0 {

View File

@@ -21,6 +21,7 @@ import (
type SProject struct {
multicloud.SProjectBase
multicloud.RemoteFileTags
Id string
Name string

View File

@@ -17,6 +17,8 @@ package remotefile
import (
"fmt"
"yunion.io/x/pkg/errors"
api "yunion.io/x/onecloud/pkg/apis/compute"
"yunion.io/x/onecloud/pkg/cloudprovider"
"yunion.io/x/onecloud/pkg/multicloud"
@@ -85,8 +87,18 @@ func (self *SRegion) GetIZoneById(id string) (cloudprovider.ICloudZone, error) {
return nil, cloudprovider.ErrNotFound
}
func (self *SRegion) GetIVMById(id string) (cloudprovider.ICloudVM, error) {
return nil, cloudprovider.ErrNotImplemented
func (region *SRegion) GetIVMById(id string) (cloudprovider.ICloudVM, error) {
instances, err := region.client.GetInstances()
if err != nil {
return nil, err
}
instance := SInstance{}
for _, v := range instances {
if v.Id == id {
return &instance, nil
}
}
return nil, errors.Wrapf(errors.ErrNotFound, "GetIVMById:%s", id)
}
func (self *SRegion) GetIDiskById(id string) (cloudprovider.ICloudDisk, error) {