diff --git a/pkg/compute/models/storagecachedimages.go b/pkg/compute/models/storagecachedimages.go index 892861ff2b..44b588d53e 100644 --- a/pkg/compute/models/storagecachedimages.go +++ b/pkg/compute/models/storagecachedimages.go @@ -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() diff --git a/pkg/compute/models/storagecaches.go b/pkg/compute/models/storagecaches.go index 33c7b378d7..157743f802 100644 --- a/pkg/compute/models/storagecaches.go +++ b/pkg/compute/models/storagecaches.go @@ -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 {