MCPcopy
hub / github.com/lxc/incus / LoadInstanceDatabaseObject

Function LoadInstanceDatabaseObject

internal/server/instance/instance_utils.go:289–318  ·  view source on GitHub ↗

LoadInstanceDatabaseObject loads a db.Instance object, accounting for snapshots.

(ctx context.Context, tx *db.ClusterTx, project, name string)

Source from the content-addressed store, hash-verified

287
288// LoadInstanceDatabaseObject loads a db.Instance object, accounting for snapshots.
289func LoadInstanceDatabaseObject(ctx context.Context, tx *db.ClusterTx, project, name string) (*cluster.Instance, error) {
290 var container *cluster.Instance
291 var err error
292
293 if strings.Contains(name, instance.SnapshotDelimiter) {
294 parts := strings.SplitN(name, instance.SnapshotDelimiter, 2)
295 instanceName := parts[0]
296 snapshotName := parts[1]
297
298 inst, err := cluster.GetInstance(ctx, tx.Tx(), project, instanceName)
299 if err != nil {
300 return nil, fmt.Errorf("Failed to fetch instance %q in project %q: %w", name, project, err)
301 }
302
303 snapshot, err := cluster.GetInstanceSnapshot(ctx, tx.Tx(), project, instanceName, snapshotName)
304 if err != nil {
305 return nil, fmt.Errorf("Failed to fetch snapshot %q of instance %q in project %q: %w", snapshotName, instanceName, project, err)
306 }
307
308 c := snapshot.ToInstance(inst.Name, inst.Node, inst.Type, inst.Architecture)
309 container = &c
310 } else {
311 container, err = cluster.GetInstance(ctx, tx.Tx(), project, name)
312 if err != nil {
313 return nil, fmt.Errorf("Failed to fetch instance %q in project %q: %w", name, project, err)
314 }
315 }
316
317 return container, nil
318}
319
320// LoadByProjectAndName loads an instance by project and name.
321func LoadByProjectAndName(s *state.State, projectName string, instanceName string) (Instance, error) {

Callers 2

instancesPostFunction · 0.92
LoadByProjectAndNameFunction · 0.85

Calls 6

GetInstanceFunction · 0.92
GetInstanceSnapshotFunction · 0.92
TxMethod · 0.80
ErrorfMethod · 0.80
ToInstanceMethod · 0.80
ContainsMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…