Skip to content

Commit a43a57f

Browse files
committed
cmd/incusd: Update calls to generated code
Signed-off-by: Max Asnaashari <[email protected]>
1 parent de51332 commit a43a57f

19 files changed

+56
-36
lines changed

cmd/incusd/api_internal_recover.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,12 +80,12 @@ func internalRecoverScan(ctx context.Context, s *state.State, userPools []api.St
8080
return err
8181
}
8282

83-
profileConfigs, err := dbCluster.GetConfig(ctx, tx.Tx(), "profile")
83+
profileConfigs, err := dbCluster.GetAllProfileConfigs(ctx, tx.Tx())
8484
if err != nil {
8585
return err
8686
}
8787

88-
profileDevices, err := dbCluster.GetDevices(ctx, tx.Tx(), "profile")
88+
profileDevices, err := dbCluster.GetAllProfileDevices(ctx, tx.Tx())
8989
if err != nil {
9090
return err
9191
}

cmd/incusd/instance_patch.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -191,12 +191,12 @@ func instancePatch(d *Daemon, r *http.Request) response.Response {
191191
return err
192192
}
193193

194-
profileConfigs, err := cluster.GetConfig(ctx, tx.Tx(), "profile")
194+
profileConfigs, err := cluster.GetAllProfileConfigs(ctx, tx.Tx())
195195
if err != nil {
196196
return err
197197
}
198198

199-
profileDevices, err := cluster.GetDevices(ctx, tx.Tx(), "profile")
199+
profileDevices, err := cluster.GetAllProfileDevices(ctx, tx.Tx())
200200
if err != nil {
201201
return err
202202
}

cmd/incusd/instance_post.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -358,12 +358,12 @@ func instancePost(d *Daemon, r *http.Request) response.Response {
358358
return err
359359
}
360360

361-
dbProfileConfigs, err := dbCluster.GetConfig(ctx, tx.Tx(), "profile")
361+
dbProfileConfigs, err := dbCluster.GetAllProfileConfigs(ctx, tx.Tx())
362362
if err != nil {
363363
return err
364364
}
365365

366-
dbProfileDevices, err := dbCluster.GetDevices(ctx, tx.Tx(), "profile")
366+
dbProfileDevices, err := dbCluster.GetAllProfileDevices(ctx, tx.Tx())
367367
if err != nil {
368368
return err
369369
}
@@ -713,12 +713,12 @@ func migrateInstance(ctx context.Context, s *state.State, inst instance.Instance
713713
return err
714714
}
715715

716-
profileConfigs, err := dbCluster.GetConfig(ctx, tx.Tx(), "profile")
716+
profileConfigs, err := dbCluster.GetAllProfileConfigs(ctx, tx.Tx())
717717
if err != nil {
718718
return err
719719
}
720720

721-
profileDevices, err := dbCluster.GetDevices(ctx, tx.Tx(), "profile")
721+
profileDevices, err := dbCluster.GetAllProfileDevices(ctx, tx.Tx())
722722
if err != nil {
723723
return err
724724
}

cmd/incusd/instance_put.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -137,12 +137,12 @@ func instancePut(d *Daemon, r *http.Request) response.Response {
137137
return err
138138
}
139139

140-
profileConfigs, err := cluster.GetConfig(ctx, tx.Tx(), "profile")
140+
profileConfigs, err := cluster.GetAllProfileConfigs(ctx, tx.Tx())
141141
if err != nil {
142142
return err
143143
}
144144

145-
profileDevices, err := cluster.GetDevices(ctx, tx.Tx(), "profile")
145+
profileDevices, err := cluster.GetAllProfileDevices(ctx, tx.Tx())
146146
if err != nil {
147147
return err
148148
}

cmd/incusd/instances_post.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1060,12 +1060,12 @@ func instancesPost(d *Daemon, r *http.Request) response.Response {
10601060
return err
10611061
}
10621062

1063-
dbProfileConfigs, err := dbCluster.GetConfig(ctx, tx.Tx(), "profile")
1063+
dbProfileConfigs, err := dbCluster.GetAllProfileConfigs(ctx, tx.Tx())
10641064
if err != nil {
10651065
return err
10661066
}
10671067

1068-
dbProfileDevices, err := dbCluster.GetDevices(ctx, tx.Tx(), "profile")
1068+
dbProfileDevices, err := dbCluster.GetAllProfileDevices(ctx, tx.Tx())
10691069
if err != nil {
10701070
return err
10711071
}

cmd/incusd/profiles.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -213,12 +213,12 @@ func profilesGet(d *Daemon, r *http.Request) response.Response {
213213
}
214214

215215
if mustLoadObjects {
216-
profileConfigs, err := dbCluster.GetConfig(ctx, tx.Tx(), "profile")
216+
profileConfigs, err := dbCluster.GetAllProfileConfigs(ctx, tx.Tx())
217217
if err != nil {
218218
return err
219219
}
220220

221-
profileDevices, err := dbCluster.GetDevices(ctx, tx.Tx(), "profile")
221+
profileDevices, err := dbCluster.GetAllProfileDevices(ctx, tx.Tx())
222222
if err != nil {
223223
return err
224224
}
@@ -476,12 +476,12 @@ func profileGet(d *Daemon, r *http.Request) response.Response {
476476
return fmt.Errorf("Fetch profile: %w", err)
477477
}
478478

479-
profileConfigs, err := dbCluster.GetConfig(ctx, tx.Tx(), "profile")
479+
profileConfigs, err := dbCluster.GetAllProfileConfigs(ctx, tx.Tx())
480480
if err != nil {
481481
return err
482482
}
483483

484-
profileDevices, err := dbCluster.GetDevices(ctx, tx.Tx(), "profile")
484+
profileDevices, err := dbCluster.GetAllProfileDevices(ctx, tx.Tx())
485485
if err != nil {
486486
return err
487487
}

internal/server/backup/backup_config_utils.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,13 +52,13 @@ func ConfigToInstanceDBArgs(state *state.State, c *config.Config, projectName st
5252
}
5353

5454
// Get all the profile configs.
55-
profileConfigs, err := cluster.GetConfig(ctx, tx.Tx(), "profile")
55+
profileConfigs, err := cluster.GetAllProfileConfigs(ctx, tx.Tx())
5656
if err != nil {
5757
return err
5858
}
5959

6060
// Get all the profile devices.
61-
profileDevices, err := cluster.GetDevices(ctx, tx.Tx(), "profile")
61+
profileDevices, err := cluster.GetAllProfileDevices(ctx, tx.Tx())
6262
if err != nil {
6363
return err
6464
}

internal/server/db/cluster/instances.go

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,14 +84,14 @@ func (i *Instance) ToAPI(ctx context.Context, tx *sql.Tx, instanceDevices map[in
8484
}
8585

8686
if profileConfigs == nil {
87-
profileConfigs, err = GetConfig(ctx, tx, "profile")
87+
profileConfigs, err = GetAllProfileConfigs(ctx, tx)
8888
if err != nil {
8989
return nil, err
9090
}
9191
}
9292

9393
if profileDevices == nil {
94-
profileDevices, err = GetDevices(ctx, tx, "profile")
94+
profileDevices, err = GetAllProfileDevices(ctx, tx)
9595
if err != nil {
9696
return nil, err
9797
}
@@ -158,3 +158,13 @@ func (i *Instance) ToAPI(ctx context.Context, tx *sql.Tx, instanceDevices map[in
158158
Project: i.Project,
159159
}, nil
160160
}
161+
162+
// GetAllInstanceConfigs returns a map of all instance configurations, keyed by database ID.
163+
func GetAllInstanceConfigs(ctx context.Context, tx *sql.Tx) (map[int]map[string]string, error) {
164+
return GetConfig(ctx, tx, "instances", "instance")
165+
}
166+
167+
// GetAllInstanceDevices returns a map of all instance devices, keyed by database ID.
168+
func GetAllInstanceDevices(ctx context.Context, tx *sql.Tx) (map[int][]Device, error) {
169+
return GetDevices(ctx, tx, "instances", "instance")
170+
}

internal/server/db/cluster/profiles.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,3 +169,13 @@ func ExpandInstanceDevices(devices config.Devices, profiles []api.Profile) confi
169169

170170
return expandedDevices
171171
}
172+
173+
// GetAllProfileConfigs returns a map of all profile configurations, keyed by database ID.
174+
func GetAllProfileConfigs(ctx context.Context, tx *sql.Tx) (map[int]map[string]string, error) {
175+
return GetConfig(ctx, tx, "profiles", "profile")
176+
}
177+
178+
// GetAllProfileDevices returns a map of all profile devices, keyed by database ID.
179+
func GetAllProfileDevices(ctx context.Context, tx *sql.Tx) (map[int][]Device, error) {
180+
return GetDevices(ctx, tx, "profiles", "profile")
181+
}

internal/server/db/cluster/projects.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,7 @@ DELETE FROM projects_config WHERE projects_config.project_id = ?
214214
return fmt.Errorf("Delete project config: %w", err)
215215
}
216216

217-
err = UpdateConfig(ctx, tx, "project", int(id), object.Config)
217+
err = UpdateConfig(ctx, tx, "projects", "project", int(id), object.Config)
218218
if err != nil {
219219
return fmt.Errorf("Insert config for project: %w", err)
220220
}

internal/server/db/instances.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -536,13 +536,13 @@ func (c *ClusterTx) instanceProfilesFill(ctx context.Context, snapshotsMode bool
536536
}
537537

538538
// Get all the profile configs.
539-
profileConfigs, err := cluster.GetConfig(context.TODO(), c.Tx(), "profile")
539+
profileConfigs, err := cluster.GetAllProfileConfigs(context.TODO(), c.Tx())
540540
if err != nil {
541541
return fmt.Errorf("Failed loading profile configs: %w", err)
542542
}
543543

544544
// Get all the profile devices.
545-
profileDevices, err := cluster.GetDevices(context.TODO(), c.Tx(), "profile")
545+
profileDevices, err := cluster.GetAllProfileDevices(context.TODO(), c.Tx())
546546
if err != nil {
547547
return fmt.Errorf("Failed loading profile devices: %w", err)
548548
}

internal/server/db/node.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -534,7 +534,7 @@ JOIN cluster_groups ON cluster_groups.id = nodes_cluster_groups.group_id`
534534
}
535535
}
536536

537-
config, err := cluster.GetConfig(context.TODO(), c.Tx(), "node")
537+
config, err := cluster.GetConfig(context.TODO(), c.Tx(), "nodes", "node")
538538
if err != nil {
539539
return nil, fmt.Errorf("Failed to fetch nodes config: %w", err)
540540
}
@@ -617,7 +617,7 @@ func (c *ClusterTx) BootstrapNode(name string, address string) error {
617617

618618
// UpdateNodeConfig updates the replaces the node's config with the specified config.
619619
func (c *ClusterTx) UpdateNodeConfig(ctx context.Context, id int64, config map[string]string) error {
620-
err := cluster.UpdateConfig(ctx, c.Tx(), "node", int(id), config)
620+
err := cluster.UpdateConfig(ctx, c.Tx(), "nodes", "node", int(id), config)
621621
if err != nil {
622622
return fmt.Errorf("Unable to update node config: %w", err)
623623
}

internal/server/db/profiles.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,13 +79,13 @@ func (c *ClusterTx) GetProfiles(ctx context.Context, projectName string, profile
7979
}
8080

8181
// Get all the profile configs.
82-
profileConfigs, err := cluster.GetConfig(ctx, c.Tx(), "profile")
82+
profileConfigs, err := cluster.GetAllProfileConfigs(ctx, c.Tx())
8383
if err != nil {
8484
return nil, err
8585
}
8686

8787
// Get all the profile devices.
88-
profileDevices, err := cluster.GetDevices(ctx, c.Tx(), "profile")
88+
profileDevices, err := cluster.GetAllProfileDevices(ctx, c.Tx())
8989
if err != nil {
9090
return nil, err
9191
}

internal/server/network/acl/acl_load.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ func UsedBy(s *state.State, aclProjectName string, usageFunc func(ctx context.Co
146146
}
147147

148148
// Get all the profile devices.
149-
profileDevicesByID, err := cluster.GetDevices(ctx, tx.Tx(), "profile")
149+
profileDevicesByID, err := cluster.GetAllProfileDevices(ctx, tx.Tx())
150150
if err != nil {
151151
return err
152152
}

internal/server/network/network_utils.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,7 @@ func UsedBy(s *state.State, networkProjectName string, networkID int64, networkN
197197
}
198198

199199
// Get all the profile devices.
200-
profileDevices, err := cluster.GetDevices(ctx, tx.Tx(), "profile")
200+
profileDevices, err := cluster.GetAllProfileDevices(ctx, tx.Tx())
201201
if err != nil {
202202
return err
203203
}

internal/server/project/permissions.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1257,12 +1257,12 @@ func fetchProject(tx *db.ClusterTx, projectName string, skipIfNoLimits bool) (*p
12571257
return nil, fmt.Errorf("Fetch profiles from database: %w", err)
12581258
}
12591259

1260-
dbProfileConfigs, err := cluster.GetConfig(ctx, tx.Tx(), "profile")
1260+
dbProfileConfigs, err := cluster.GetAllProfileConfigs(ctx, tx.Tx())
12611261
if err != nil {
12621262
return nil, fmt.Errorf("Fetch profile configs from database: %w", err)
12631263
}
12641264

1265-
dbProfileDevices, err := cluster.GetDevices(ctx, tx.Tx(), "profile")
1265+
dbProfileDevices, err := cluster.GetAllProfileDevices(ctx, tx.Tx())
12661266
if err != nil {
12671267
return nil, fmt.Errorf("Fetch profile devices from database: %w", err)
12681268
}
@@ -1282,7 +1282,7 @@ func fetchProject(tx *db.ClusterTx, projectName string, skipIfNoLimits bool) (*p
12821282
return nil, fmt.Errorf("Fetch project instances from database: %w", err)
12831283
}
12841284

1285-
dbInstanceDevices, err := cluster.GetDevices(ctx, tx.Tx(), "instance")
1285+
dbInstanceDevices, err := cluster.GetAllInstanceDevices(ctx, tx.Tx())
12861286
if err != nil {
12871287
return nil, fmt.Errorf("Fetch instance devices from database: %w", err)
12881288
}

internal/server/scriptlet/instance_placement.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,7 @@ func InstancePlacementRun(ctx context.Context, l logger.Logger, s *state.State,
212212
}
213213
}
214214

215-
objectDevices, err := dbCluster.GetDevices(ctx, tx.Tx(), "instance")
215+
objectDevices, err := dbCluster.GetAllInstanceDevices(ctx, tx.Tx())
216216
if err != nil {
217217
return err
218218
}

internal/server/storage/storage.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,7 @@ func UsedBy(ctx context.Context, s *state.State, pool Pool, firstOnly bool, memb
212212
}
213213

214214
// Get all the profile devices.
215-
profileDevices, err := cluster.GetDevices(ctx, tx.Tx(), "profile")
215+
profileDevices, err := cluster.GetAllProfileDevices(ctx, tx.Tx())
216216
if err != nil {
217217
return fmt.Errorf("Failed loading profile devices: %w", err)
218218
}

internal/server/storage/utils.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -829,13 +829,13 @@ func VolumeUsedByProfileDevices(s *state.State, poolName string, projectName str
829829
}
830830

831831
// Get all the profile configs.
832-
profileConfigs, err := cluster.GetConfig(ctx, tx.Tx(), "profile")
832+
profileConfigs, err := cluster.GetAllProfileConfigs(ctx, tx.Tx())
833833
if err != nil {
834834
return fmt.Errorf("Failed loading profile configs: %w", err)
835835
}
836836

837837
// Get all the profile devices.
838-
profileDevices, err := cluster.GetDevices(ctx, tx.Tx(), "profile")
838+
profileDevices, err := cluster.GetAllProfileDevices(ctx, tx.Tx())
839839
if err != nil {
840840
return fmt.Errorf("Failed loading profile devices: %w", err)
841841
}

0 commit comments

Comments
 (0)