mirror of
https://github.com/yunionio/cloudpods.git
synced 2026-09-19 02:37:24 +08:00
fix: prefetch image error when create guest with vmware template
1. Only need the corresponding vmware template in the vcenter where the host is located. 2. Chose storagecache which cacheimage is ready before deploying.
This commit is contained in:
@@ -172,7 +172,7 @@ func (self *SESXiGuestDriver) GetJsonDescAtHost(ctx context.Context, userCred mc
|
||||
if img.ImageType != cloudprovider.CachedImageTypeSystem {
|
||||
return desc
|
||||
}
|
||||
sciSubQ := models.StoragecachedimageManager.Query("storagecache_id").Equals("cachedimage_id", templateId).SubQuery()
|
||||
sciSubQ := models.StoragecachedimageManager.Query("storagecache_id").Equals("cachedimage_id", templateId).Equals("status", api.CACHED_IMAGE_STATUS_READY).SubQuery()
|
||||
scQ := models.StoragecacheManager.Query().In("id", sciSubQ)
|
||||
storageCaches := make([]models.SStoragecache, 0, 1)
|
||||
err = db.FetchModelObjects(models.StoragecacheManager, scQ, &storageCaches)
|
||||
|
||||
@@ -221,7 +221,11 @@ func (c *SAgentImageCacheManager) perfetchTemplateVMImageCache(ctx context.Conte
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
_, err = host.GetTemplateVMById(data.ImageExternalId)
|
||||
dc, err := host.GetDatacenter()
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "host.GetDatacenter")
|
||||
}
|
||||
_, err = dc.GetTemplateVMById(data.ImageExternalId)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
@@ -364,3 +364,41 @@ func (dc *SDatacenter) GetNetworks() ([]IVMNetwork, error) {
|
||||
}
|
||||
return dc.inetworks, nil
|
||||
}
|
||||
|
||||
func (dc *SDatacenter) GetTemplateVMs() ([]*SVirtualMachine, error) {
|
||||
hosts, err := dc.GetIHosts()
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "SDatacenter.GetIHosts")
|
||||
}
|
||||
templateVms := make([]*SVirtualMachine, 5)
|
||||
for _, ihost := range hosts {
|
||||
host := ihost.(*SHost)
|
||||
tvms, err := host.GetTemplateVMs()
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "host.GetTemplateVMs")
|
||||
}
|
||||
templateVms = append(templateVms, tvms...)
|
||||
}
|
||||
return templateVms, nil
|
||||
}
|
||||
|
||||
func (dc *SDatacenter) GetTemplateVMById(id string) (*SVirtualMachine, error) {
|
||||
id = dc.manager.getPrivateId(id)
|
||||
hosts, err := dc.GetIHosts()
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "SDatacenter.GetIHosts")
|
||||
}
|
||||
for _, ihost := range hosts {
|
||||
host := ihost.(*SHost)
|
||||
tvms, err := host.GetTemplateVMs()
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "host.GetTemplateVMs")
|
||||
}
|
||||
for i := range tvms {
|
||||
if tvms[i].GetGlobalId() == id {
|
||||
return tvms[i], nil
|
||||
}
|
||||
}
|
||||
}
|
||||
return nil, cloudprovider.ErrNotFound
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user