feat: change templateid as <providerId>/<uuid> in esxi

This commit is contained in:
rainzm
2020-10-15 10:48:36 +08:00
parent 281d1c45df
commit 335c8eecc0
5 changed files with 35 additions and 4 deletions
+4
View File
@@ -87,6 +87,10 @@ func alterNameValidator(model IModel, name string) error {
return nil
}
func GenerateAlertName(model IModel, hint string) (string, error) {
return GenerateName2(model.GetModelManager(), nil, hint, model, 1)
}
func GenerateName(manager IModelManager, ownerId mcclient.IIdentityProvider, hint string) (string, error) {
return GenerateName2(manager, ownerId, hint, nil, 1)
}
+6 -1
View File
@@ -192,8 +192,13 @@ func (self *SESXiGuestDriver) GetJsonDescAtHost(ctx context.Context, userCred mc
var hostIp string
storageCacheHost, err := storageCaches[0].GetHost()
if err != nil {
log.Errorf("fail to GetHost of storageCache %s", storageCaches[0].Id)
log.Errorf("unable to GetHost of storageCache %s: %v", storageCaches[0].Id, err)
hostIp = storageCaches[0].ExternalId
} else if storageCacheHost == nil {
log.Errorf("unable to GetHost of storageCache %s: result is nil", storageCaches[0].Id)
hostIp = storageCaches[0].ExternalId
} else {
hostIp = storageCacheHost.AccessIp
}
hostIp = storageCacheHost.AccessIp
imageInfo := SEsxiImageInfo{
+5 -1
View File
@@ -472,7 +472,11 @@ func (self *SCachedimage) canDeleteLastCache() bool {
func (self *SCachedimage) syncWithCloudImage(ctx context.Context, userCred mcclient.TokenCredential, ownerId mcclient.IIdentityProvider, image cloudprovider.ICloudImage, managerId string) error {
diff, err := db.UpdateWithLock(ctx, self, func() error {
self.Name = image.GetName()
newName, err := db.GenerateAlertName(self, image.GetName())
if err != nil {
return errors.Wrap(err, "GenerateAlertName")
}
self.Name = newName
self.Size = image.GetSizeByte()
self.ExternalId = image.GetGlobalId()
self.ImageType = image.GetImageType()
+2 -1
View File
@@ -351,7 +351,8 @@ func (cli *SESXiClient) scanAllMObjects(props []string, dst interface{}) error {
func (cli *SESXiClient) SearchTemplateVM(id string) (*SVirtualMachine, error) {
filter := property.Filter{}
filter["summary.config.uuid"] = id
uuid := toTemplateUuid(id)
filter["summary.config.uuid"] = uuid
var movms []mo.VirtualMachine
err := cli.scanMObjectsWithFilter(cli.client.ServiceContent.RootFolder, VIRTUAL_MACHINE_PROPS, &movms, filter)
if err != nil {
+18 -1
View File
@@ -16,6 +16,8 @@ package esxi
import (
"context"
"fmt"
"strings"
"time"
"yunion.io/x/jsonutils"
@@ -42,8 +44,23 @@ func NewVMTemplate(vm *SVirtualMachine, cache *SDatastoreImageCache) *SVMTemplat
}
}
const splitStr = "/"
func toTemplateUuid(templateId string) string {
ids := strings.Split(templateId, splitStr)
if len(ids) == 1 {
return ids[0]
}
return ids[1]
}
func toTemplateId(providerId string, templateUuid string) string {
return fmt.Sprintf("%s%s%s", providerId, splitStr, templateUuid)
}
func (t *SVMTemplate) GetId() string {
return t.uuid
providerId := t.vm.manager.cpcfg.Id
return toTemplateId(providerId, t.uuid)
}
func (t *SVMTemplate) UEFI() bool {