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

Method getPoolInstanceByName

database/sql/instances.go:108–128  ·  view source on GitHub ↗
(poolID string, instanceName string)

Source from the content-addressed store, hash-verified

106}
107
108func (s *sqlDatabase) getPoolInstanceByName(poolID string, instanceName string) (Instance, error) {
109 pool, err := s.getPoolByID(s.conn, poolID)
110 if err != nil {
111 return Instance{}, fmt.Errorf("error fetching pool: %w", err)
112 }
113
114 var instance Instance
115 q := s.conn.Model(&Instance{}).
116 Preload(clause.Associations).
117 Where("name = ? and pool_id = ?", instanceName, pool.ID).
118 First(&instance)
119 if q.Error != nil {
120 if errors.Is(q.Error, gorm.ErrRecordNotFound) {
121 return Instance{}, fmt.Errorf("error fetching pool instance by name: %w", runnerErrors.ErrNotFound)
122 }
123 return Instance{}, fmt.Errorf("error fetching pool instance by name: %w", q.Error)
124 }
125
126 instance.Pool = pool
127 return instance, nil
128}
129
130func (s *sqlDatabase) getInstance(_ context.Context, tx *gorm.DB, instanceNameOrID string, preload ...string) (Instance, error) {
131 var instance Instance

Callers 1

DeleteInstanceMethod · 0.95

Calls 1

getPoolByIDMethod · 0.95

Tested by

no test coverage detected