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

Method DeleteInstance

database/sql/instances.go:170–211  ·  view source on GitHub ↗
(_ context.Context, poolID string, instanceName string)

Source from the content-addressed store, hash-verified

168}
169
170func (s *sqlDatabase) DeleteInstance(_ context.Context, poolID string, instanceName string) (err error) {
171 instance, err := s.getPoolInstanceByName(poolID, instanceName)
172 if err != nil {
173 if errors.Is(err, runnerErrors.ErrNotFound) {
174 return nil
175 }
176 return fmt.Errorf("error deleting instance: %w", err)
177 }
178
179 defer func() {
180 if err == nil {
181 var providerID string
182 if instance.ProviderID != nil {
183 providerID = *instance.ProviderID
184 }
185 instanceNotif := params.Instance{
186 ID: instance.ID.String(),
187 Name: instance.Name,
188 ProviderID: providerID,
189 AgentID: instance.AgentID,
190 }
191 switch {
192 case instance.PoolID != nil:
193 instanceNotif.PoolID = instance.PoolID.String()
194 case instance.ScaleSetFkID != nil:
195 instanceNotif.ScaleSetID = *instance.ScaleSetFkID
196 }
197
198 if notifyErr := s.sendNotify(common.InstanceEntityType, common.DeleteOperation, instanceNotif); notifyErr != nil {
199 slog.With(slog.Any("error", notifyErr)).Error("failed to send notify")
200 }
201 }
202 }()
203
204 if q := s.conn.Unscoped().Delete(&instance); q.Error != nil {
205 if errors.Is(q.Error, gorm.ErrRecordNotFound) {
206 return nil
207 }
208 return fmt.Errorf("error deleting instance: %w", q.Error)
209 }
210 return nil
211}
212
213func (s *sqlDatabase) DeleteInstanceByName(ctx context.Context, instanceName string) error {
214 instance, err := s.getInstance(ctx, s.conn, instanceName, "Pool", "ScaleSet")

Callers

nothing calls this directly

Calls 5

getPoolInstanceByNameMethod · 0.95
sendNotifyMethod · 0.95
DeleteMethod · 0.65
StringMethod · 0.45
ErrorMethod · 0.45

Tested by

no test coverage detected