mirror of
https://github.com/yunionio/cloudpods.git
synced 2026-09-19 10:46:58 +08:00
refactor(esxi): replace GetTemplateVMById with FetchTemplateVMById
FetchTemplateVMById 更好,因为它更轻量,更快。
This commit is contained in:
@@ -225,7 +225,7 @@ func (c *SAgentImageCacheManager) perfetchTemplateVMImageCache(ctx context.Conte
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "host.GetDatacenter")
|
||||
}
|
||||
_, err = dc.GetTemplateVMById(data.ImageExternalId)
|
||||
_, err = dc.FetchTemplateVMById(data.ImageExternalId)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
@@ -436,24 +436,3 @@ func (dc *SDatacenter) GetTemplateVMs() ([]*SVirtualMachine, error) {
|
||||
}
|
||||
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