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

Method getInstance

database/sql/instances.go:130–159  ·  view source on GitHub ↗
(_ context.Context, tx *gorm.DB, instanceNameOrID string, preload ...string)

Source from the content-addressed store, hash-verified

128}
129
130func (s *sqlDatabase) getInstance(_ context.Context, tx *gorm.DB, instanceNameOrID string, preload ...string) (Instance, error) {
131 var instance Instance
132
133 var whereArg any = instanceNameOrID
134 whereClause := "name = ?"
135 id, err := uuid.Parse(instanceNameOrID)
136 if err == nil {
137 whereArg = id
138 whereClause = "id = ?"
139 }
140 q := tx
141
142 if len(preload) > 0 {
143 for _, item := range preload {
144 q = q.Preload(item)
145 }
146 }
147
148 q = q.Model(&Instance{}).
149 Preload(clause.Associations).
150 Where(whereClause, whereArg).
151 First(&instance)
152 if q.Error != nil {
153 if errors.Is(q.Error, gorm.ErrRecordNotFound) {
154 return Instance{}, fmt.Errorf("error fetching instance by name: %w", runnerErrors.ErrNotFound)
155 }
156 return Instance{}, fmt.Errorf("error fetching instance by name: %w", q.Error)
157 }
158 return instance, nil
159}
160
161func (s *sqlDatabase) GetInstance(ctx context.Context, instanceName string) (params.Instance, error) {
162 instance, err := s.getInstance(ctx, s.conn, instanceName, "StatusMessages", "Pool", "ScaleSet")

Callers 6

CreateOrUpdateJobMethod · 0.95
GetInstanceMethod · 0.95
DeleteInstanceByNameMethod · 0.95
AddInstanceEventMethod · 0.95
updateInstanceMethod · 0.95

Calls

no outgoing calls

Tested by

no test coverage detected