mirror of
https://github.com/yunionio/cloudpods.git
synced 2026-09-24 16:03:43 +08:00
refactor: find the most suitable storage
This commit is contained in:
@@ -223,21 +223,34 @@ func (self *SESXiGuestDriver) GetJsonDescAtHost(ctx context.Context, userCred mc
|
||||
return desc, errors.Errorf("no such storage cache associated with cacheimage %s", templateId)
|
||||
}
|
||||
if len(storageCaches) > 1 {
|
||||
return desc, errors.Errorf("there are multiple storageCache associated with caheimage '%s' ??!!", templateId)
|
||||
log.Warningf("there are multiple storageCache associated with caheimage '%s' ??!!", templateId)
|
||||
}
|
||||
|
||||
var hostIp string
|
||||
storageCacheHost, err := storageCaches[0].GetHost()
|
||||
if err != nil {
|
||||
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
|
||||
var storageCacheHost *models.SHost
|
||||
// select storagecacheHost
|
||||
for i := range storageCaches {
|
||||
hosts, err := storageCaches[i].GetHosts()
|
||||
if err != nil {
|
||||
return desc, errors.Wrap(err, "storageCaches.GetHosts")
|
||||
}
|
||||
for i := range hosts {
|
||||
if host.GetId() == hosts[i].GetId() {
|
||||
storageCacheHost = &hosts[i]
|
||||
}
|
||||
}
|
||||
}
|
||||
hostIp = storageCacheHost.AccessIp
|
||||
|
||||
if storageCacheHost == nil {
|
||||
storageCacheHost, err = storageCaches[0].GetHost()
|
||||
if err != nil {
|
||||
return desc, errors.Wrapf(err, "unable to GetHost of storageCache %s", storageCaches[0].Id)
|
||||
}
|
||||
if storageCacheHost == nil {
|
||||
return desc, fmt.Errorf("unable to GetHost of storageCache %s: result is nil", storageCaches[0].Id)
|
||||
}
|
||||
}
|
||||
|
||||
hostIp := storageCacheHost.AccessIp
|
||||
imageInfo := SEsxiImageInfo{
|
||||
ImageType: img.ImageType,
|
||||
ImageExternalId: img.ExternalId,
|
||||
|
||||
@@ -133,7 +133,7 @@ func (self *SStoragecache) GetRegion() (*SCloudregion, error) {
|
||||
return region, nil
|
||||
}
|
||||
|
||||
func (self *SStoragecache) getHostId() (string, error) {
|
||||
func (self *SStoragecache) GetHosts() ([]SHost, error) {
|
||||
hoststorages := HoststorageManager.Query().SubQuery()
|
||||
storages := StorageManager.Query().SubQuery()
|
||||
|
||||
@@ -153,7 +153,15 @@ func (self *SStoragecache) getHostId() (string, error) {
|
||||
sqlchemy.IsTrue(storages.Field("enabled")))).
|
||||
Filter(sqlchemy.Equals(hoststorages.Field("storage_id"), storages.Field("id"))).All(&hosts)
|
||||
if err != nil {
|
||||
return "", err
|
||||
return nil, err
|
||||
}
|
||||
return hosts, nil
|
||||
}
|
||||
|
||||
func (self *SStoragecache) getHostId() (string, error) {
|
||||
hosts, err := self.GetHosts()
|
||||
if err != nil {
|
||||
return "", errors.Wrap(err, "GetHosts")
|
||||
}
|
||||
|
||||
hostIds := make([]string, 0)
|
||||
|
||||
Reference in New Issue
Block a user