mirror of
https://github.com/yunionio/cloudpods.git
synced 2026-09-24 16:03:43 +08:00
Merge pull request #10629 from rainzm/storagecache/fix
feat(region): virtually display the esxiagent of the cached image as a host
This commit is contained in:
@@ -199,6 +199,15 @@ func (self *SStoragecachedimage) getExtraDetails(ctx context.Context, out api.St
|
||||
host, _ := storagecache.GetHost()
|
||||
if host != nil {
|
||||
out.Host = host.GetShortDesc(ctx)
|
||||
} else {
|
||||
var err error
|
||||
hostDesc, err := storagecache.GetEsxiAgentHostDesc()
|
||||
if err != nil {
|
||||
log.Errorf("unable to GetEsxiAgentHostDesc of stroagecache: %s", err.Error())
|
||||
}
|
||||
if hostDesc != nil {
|
||||
out.Host = hostDesc
|
||||
}
|
||||
}
|
||||
}
|
||||
cachedImage := self.GetCachedimage()
|
||||
|
||||
@@ -18,6 +18,7 @@ import (
|
||||
"context"
|
||||
"database/sql"
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
"github.com/serialx/hashring"
|
||||
|
||||
@@ -103,6 +104,26 @@ func (self *SStoragecache) getStorageNames() []string {
|
||||
return names
|
||||
}
|
||||
|
||||
func (self *SStoragecache) GetEsxiAgentHostDesc() (*jsonutils.JSONDict, error) {
|
||||
if !strings.Contains(self.Name, "esxiagent") {
|
||||
return nil, nil
|
||||
}
|
||||
obj, err := BaremetalagentManager.FetchById(self.ExternalId)
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(err, "unable to fetch baremetalagent %s", obj.GetId())
|
||||
}
|
||||
agent := obj.(*SBaremetalagent)
|
||||
host := &SHost{}
|
||||
host.Id = agent.Id
|
||||
host.Name = agent.Name
|
||||
host.ZoneId = agent.ZoneId
|
||||
host.SetModelManager(HostManager, host)
|
||||
ret := host.GetShortDesc(context.Background())
|
||||
ret.Set("provider", jsonutils.NewString(api.CLOUD_PROVIDER_VMWARE))
|
||||
ret.Set("brand", jsonutils.NewString(api.CLOUD_PROVIDER_VMWARE))
|
||||
return ret, nil
|
||||
}
|
||||
|
||||
func (self *SStoragecache) GetHost() (*SHost, error) {
|
||||
hostId, err := self.getHostId()
|
||||
if err != nil {
|
||||
|
||||
Reference in New Issue
Block a user