MCPcopy Create free account
hub / github.com/cloudbase/garm / GetEntityForInstance

Method GetEntityForInstance

cache/instance_cache.go:73–108  ·  view source on GitHub ↗
(name string)

Source from the content-addressed store, hash-verified

71}
72
73func (i *InstanceCache) GetEntityForInstance(name string) (params.ForgeEntity, bool) {
74 instance, ok := i.GetInstance(name)
75 if !ok {
76 return params.ForgeEntity{}, ok
77 }
78
79 var entityID string
80 switch {
81 case instance.ScaleSetID > 0:
82 if scaleSet, ok := GetScaleSetByID(instance.ScaleSetID); ok {
83 scaleSetEntity, err := scaleSet.GetEntity()
84 if err != nil {
85 return params.ForgeEntity{}, false
86 }
87 entityID = scaleSetEntity.ID
88 }
89 case instance.PoolID != "":
90 if pool, ok := GetPoolByID(instance.PoolID); ok {
91 poolEntity, err := pool.GetEntity()
92 if err != nil {
93 return params.ForgeEntity{}, false
94 }
95 entityID = poolEntity.ID
96 }
97 default:
98 return params.ForgeEntity{}, false
99 }
100
101 // Get the full entity
102 if entityID != "" {
103 if entity, ok := GetEntity(entityID); ok {
104 return entity, true
105 }
106 }
107 return params.ForgeEntity{}, false
108}
109
110func (i *InstanceCache) GetInstancesForPool(poolID string) []params.Instance {
111 i.mux.Lock()

Callers 1

GetEntityForInstanceFunction · 0.80

Calls 5

GetInstanceMethod · 0.95
GetScaleSetByIDFunction · 0.85
GetPoolByIDFunction · 0.85
GetEntityFunction · 0.85
GetEntityMethod · 0.65

Tested by

no test coverage detected