Skip to content

Commit

Permalink
[#1552] Rename constants
Browse files Browse the repository at this point in the history
  • Loading branch information
fivitti committed Nov 4, 2024
1 parent 9e88708 commit 9bab7fa
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 21 deletions.
4 changes: 2 additions & 2 deletions backend/server/apps/kea/subnet.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ func sharedNetworkExists(dbi dbops.DBI, network *dbmodel.SharedNetwork, existing
// Get the subnets included in this shared network.
dbNetwork, err := dbmodel.GetSharedNetworkWithRelations(
dbi, existing.ID,
dbmodel.SharedNetworkRelationAddressPools,
dbmodel.SharedNetworkRelationPrefixPools,
dbmodel.SharedNetworkRelationSubnetsAddressPools,
dbmodel.SharedNetworkRelationSubnetsPrefixPools,
)
if err != nil {
return nil, err
Expand Down
34 changes: 17 additions & 17 deletions backend/server/database/model/sharednetwork.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,13 +46,13 @@ const (
SharedNetworkRelationLocalSharedNetworksAccessPoints SharedNetworkRelation = "LocalSharedNetworks.Daemon.App.AccessPoints"
SharedNetworkRelationLocalSharedNetworksMachine SharedNetworkRelation = "LocalSharedNetworks.Daemon.App.Machine"
SharedNetworkRelationLocalSubnets SharedNetworkRelation = "Subnets.LocalSubnets"
SharedNetworkRelationAddressPools SharedNetworkRelation = "Subnets.LocalSubnets.AddressPools"
SharedNetworkRelationPrefixPools SharedNetworkRelation = "Subnets.LocalSubnets.PrefixPools"
SharedNetworkRelationSubnetDaemon SharedNetworkRelation = "Subnets.LocalSubnets.Daemon"
SharedNetworkRelationSubnetKeaDaemon SharedNetworkRelation = "Subnets.LocalSubnets.Daemon.KeaDaemon"
SharedNetworkRelationSubnetApp SharedNetworkRelation = "Subnets.LocalSubnets.Daemon.App"
SharedNetworkRelationSubnetAccessPoints SharedNetworkRelation = "Subnets.LocalSubnets.Daemon.App.AccessPoints"
SharedNetworkRelationSubnetMachine SharedNetworkRelation = "Subnets.LocalSubnets.Daemon.App.Machine"
SharedNetworkRelationSubnetsAddressPools SharedNetworkRelation = "Subnets.LocalSubnets.AddressPools"
SharedNetworkRelationSubnetsPrefixPools SharedNetworkRelation = "Subnets.LocalSubnets.PrefixPools"
SharedNetworkRelationSubnetsDaemon SharedNetworkRelation = "Subnets.LocalSubnets.Daemon"
SharedNetworkRelationSubnetsKeaDaemon SharedNetworkRelation = "Subnets.LocalSubnets.Daemon.KeaDaemon"
SharedNetworkRelationSubnetsApp SharedNetworkRelation = "Subnets.LocalSubnets.Daemon.App"
SharedNetworkRelationSubnetsAccessPoints SharedNetworkRelation = "Subnets.LocalSubnets.Daemon.App.AccessPoints"
SharedNetworkRelationSubnetsMachine SharedNetworkRelation = "Subnets.LocalSubnets.Daemon.App.Machine"
)

// This structure holds shared network information retrieved from an app.
Expand Down Expand Up @@ -298,11 +298,11 @@ func GetSharedNetworkWithRelations(dbi dbops.DBI, networkID int64, relations ...

for _, relation := range relations {
switch relation {
case SharedNetworkRelationAddressPools:
case SharedNetworkRelationSubnetsAddressPools:
model = model.Relation(string(relation), func(q *orm.Query) (*orm.Query, error) {
return q.Order("address_pool.id ASC"), nil
})
case SharedNetworkRelationPrefixPools:
case SharedNetworkRelationSubnetsPrefixPools:
model = model.Relation(string(relation), func(q *orm.Query) (*orm.Query, error) {
return q.Order("prefix_pool.id ASC"), nil
})
Expand All @@ -327,14 +327,14 @@ func GetSharedNetworkWithRelations(dbi dbops.DBI, networkID int64, relations ...
// Fetches a shared network with the subnets it contains.
func GetSharedNetwork(dbi dbops.DBI, networkID int64) (network *SharedNetwork, err error) {
return GetSharedNetworkWithRelations(dbi, networkID,
SharedNetworkRelationLocalSharedNetworkKeaDaemon,
SharedNetworkRelationLocalSharedNetworkAccessPoints,
SharedNetworkRelationLocalSharedNetworkMachine,
SharedNetworkRelationAddressPools,
SharedNetworkRelationPrefixPools,
SharedNetworkRelationSubnetKeaDaemon,
SharedNetworkRelationSubnetAccessPoints,
SharedNetworkRelationSubnetMachine)
SharedNetworkRelationLocalSharedNetworksKeaDaemon,
SharedNetworkRelationLocalSharedNetworksAccessPoints,
SharedNetworkRelationLocalSharedNetworksMachine,
SharedNetworkRelationSubnetsAddressPools,
SharedNetworkRelationSubnetsPrefixPools,
SharedNetworkRelationSubnetsKeaDaemon,
SharedNetworkRelationSubnetsAccessPoints,
SharedNetworkRelationSubnetsMachine)
}

// Fetches a collection of shared networks from the database. The
Expand Down
7 changes: 5 additions & 2 deletions backend/server/database/model/sharednetwork_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -321,8 +321,11 @@ func TestGetSharedNetworkWithRelations(t *testing.T) {
err = AddLocalSharedNetworks(db, &network)
require.NoError(t, err)

returned, err := GetSharedNetworkWithRelations(db, network.ID,
SharedNetworkRelationAddressPools, SharedNetworkRelationPrefixPools)
returned, err := GetSharedNetworkWithRelations(
db, network.ID,
SharedNetworkRelationSubnetsAddressPools,
SharedNetworkRelationSubnetsPrefixPools,
)
require.NoError(t, err)
require.NotNil(t, returned)
require.Equal(t, network.Name, returned.Name)
Expand Down

0 comments on commit 9bab7fa

Please sign in to comment.