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

Function UpdateInstanceProfiles

internal/server/db/cluster/instance_profiles.go:42–79  ·  view source on GitHub ↗

UpdateInstanceProfiles updates the profiles of an instance in the order they are given.

(ctx context.Context, tx *sql.Tx, instanceID int, projectName string, profiles []string)

Source from the content-addressed store, hash-verified

40
41// UpdateInstanceProfiles updates the profiles of an instance in the order they are given.
42func UpdateInstanceProfiles(ctx context.Context, tx *sql.Tx, instanceID int, projectName string, profiles []string) error {
43 err := DeleteInstanceProfiles(ctx, tx, instanceID)
44 if err != nil {
45 return err
46 }
47
48 project := projectName
49 enabled, err := ProjectHasProfiles(ctx, tx, project)
50 if err != nil {
51 return fmt.Errorf("Check if project has profiles: %w", err)
52 }
53
54 if !enabled {
55 project = "default"
56 }
57
58 applyOrder := 1
59 stmt, err := Stmt(tx, instanceProfileCreate)
60 if err != nil {
61 return fmt.Errorf("Failed to get \"instanceProfileCreate\" prepared statement: %w", err)
62 }
63
64 for _, name := range profiles {
65 profileID, err := GetProfileID(ctx, tx, project, name)
66 if err != nil {
67 return err
68 }
69
70 _, err = stmt.Exec(instanceID, profileID, applyOrder)
71 if err != nil {
72 return err
73 }
74
75 applyOrder = applyOrder + 1
76 }
77
78 return nil
79}

Callers 6

CreateInternalFunction · 0.92
UpdateMethod · 0.92
TestInstanceListFunction · 0.92
TestCreateInstanceFunction · 0.92

Calls 6

DeleteInstanceProfilesFunction · 0.85
ProjectHasProfilesFunction · 0.85
GetProfileIDFunction · 0.85
ErrorfMethod · 0.80
StmtFunction · 0.70
ExecMethod · 0.65

Used in the wild real call sites across dependent graphs

searching dependent graphs…