Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions pkg/db/metal/machine.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ type Machine struct {
PartitionID string `rethinkdb:"partitionid"`
SizeID string `rethinkdb:"sizeid"`
RackID string `rethinkdb:"rackid"`
RoomID string `rethinkdb:"roomid"`
Waiting bool `rethinkdb:"waiting"`
PreAllocated bool `rethinkdb:"preallocated"`
Hardware MachineHardware `rethinkdb:"hardware"`
Expand Down
1 change: 1 addition & 0 deletions pkg/db/metal/switch.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ type (
Switch struct {
Base
Rack string `rethinkdb:"rackid"`
Room string `rethinkdb:"roomid"`
Partition string `rethinkdb:"partitionid"`
ReplaceMode SwitchReplaceMode `rethinkdb:"mode"`
ManagementIP string `rethinkdb:"management_ip"`
Expand Down
6 changes: 6 additions & 0 deletions pkg/db/queries/machine.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,12 @@ func MachineFilter(rq *apiv2.MachineQuery) func(q r.Term) r.Term {
})
}

if rq.Room != nil {
q = q.Filter(func(row r.Term) r.Term {
return row.Field("roomid").Eq(*rq.Room)
})
}

if rq.Labels != nil {
for key, value := range rq.Labels.Labels {
tag := fmt.Sprintf("%s=%s", key, value)
Expand Down
6 changes: 6 additions & 0 deletions pkg/db/queries/machine_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ var (
PartitionID: "p1",
SizeID: "c1-medium",
RackID: "rack-1",
RoomID: "room-1",
Waiting: false,
PreAllocated: false,
Hardware: metal.MachineHardware{
Expand Down Expand Up @@ -362,6 +363,11 @@ func TestMachineFilter(t *testing.T) {
rq: &apiv2.MachineQuery{Rack: new("rack-2")},
want: []*metal.Machine{m2},
},
{
name: "by room",
rq: &apiv2.MachineQuery{Room: new("room-1")},
want: []*metal.Machine{m1},
},
{
name: "by state",
rq: &apiv2.MachineQuery{State: apiv2.MachineState_MACHINE_STATE_LOCKED.Enum()},
Expand Down
6 changes: 6 additions & 0 deletions pkg/db/queries/switch.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,12 @@ func SwitchFilter(query *apiv2.SwitchQuery) func(q r.Term) r.Term {
})
}

if query.Room != nil {
q = q.Filter(func(row r.Term) r.Term {
return row.Field("roomid").Eq(*query.Room)
})
}

if query.Os != nil {
if query.Os.Vendor != nil {
stringValue, err := enum.GetStringValue(query.Os.Vendor)
Expand Down
8 changes: 8 additions & 0 deletions pkg/db/queries/switch_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ var (
sw1 = &metal.Switch{
Base: metal.Base{ID: "sw1"},
Rack: "rack01",
Room: "room01",
Partition: "partition-a",
OS: &metal.SwitchOS{
Vendor: metal.SwitchOSVendorCumulus,
Expand Down Expand Up @@ -117,6 +118,13 @@ func TestSwitchFilter(t *testing.T) {
},
want: []*metal.Switch{sw1, sw2},
},
{
name: "query by room",
rq: &apiv2.SwitchQuery{
Room: new("room01"),
},
want: []*metal.Switch{sw1},
},
{
name: "query by os vendor",
rq: &apiv2.SwitchQuery{
Expand Down
2 changes: 2 additions & 0 deletions pkg/repository/machine.go
Original file line number Diff line number Diff line change
Expand Up @@ -607,6 +607,7 @@ func (r *machineRepository) convertToProto(ctx context.Context, m *metal.Machine
},
Partition: partition,
Rack: m.RackID,
Room: m.RoomID,
Size: size,
Hardware: hardware,
Allocation: allocation,
Expand Down Expand Up @@ -904,6 +905,7 @@ func (r *machineRepository) Register(ctx context.Context, req *infrav2.BootServi
return err
}
m.RackID = machine.Rack
m.RoomID = machine.Room
return r.s.ds.Machine().Update(ctx, m)
},
retry.Attempts(10),
Expand Down
3 changes: 3 additions & 0 deletions pkg/repository/switch.go
Original file line number Diff line number Diff line change
Expand Up @@ -367,6 +367,7 @@ func (r *switchRepository) ConnectMachineWithSwitches(ctx context.Context, m *ap
return errorutil.FailedPrecondition("connected switches of a machine must reside in the same rack, rack of switch %s: %s, rack of switch %s: %s, machine: %s", s1.Name, s1.Rack, s2.Name, s2.Rack, m.Uuid)
}
m.Rack = s1.Rack
m.Room = s1.Room

sws, err := r.s.ds.Switch().List(ctx, queries.SwitchFilter(&apiv2.SwitchQuery{
ConnectedMachineId: &m.Uuid,
Expand Down Expand Up @@ -743,6 +744,7 @@ func (r *switchRepository) convertToInternal(ctx context.Context, sw *apiv2.Swit
Description: sw.Description,
},
Rack: pointer.SafeDeref(sw.Rack),
Room: pointer.SafeDeref(sw.Room),
Partition: sw.Partition,
ReplaceMode: replaceMode,
ManagementIP: sw.ManagementIp,
Expand Down Expand Up @@ -815,6 +817,7 @@ func (r *switchRepository) convertToProto(ctx context.Context, sw *metal.Switch)
},
Description: sw.Description,
Rack: pointer.PointerOrNil(sw.Rack),
Room: pointer.PointerOrNil(sw.Room),
Partition: sw.Partition,
ReplaceMode: replaceMode,
ManagementIp: sw.ManagementIP,
Expand Down
3 changes: 3 additions & 0 deletions pkg/service/infra/switch/switch-service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ func Test_switchServiceServer_Register(t *testing.T) {
Switch: &apiv2.Switch{
Id: "p01-r01leaf01-1",
Rack: new(sc.P01Rack01),
Room: new(sc.P01Rack01Room01),
Partition: sc.Partition1,
ManagementIp: "1.1.1.1",
ReplaceMode: apiv2.SwitchReplaceMode_SWITCH_REPLACE_MODE_OPERATIONAL,
Expand All @@ -54,6 +55,7 @@ func Test_switchServiceServer_Register(t *testing.T) {
Id: "p01-r01leaf01-1",
Meta: &apiv2.Meta{},
Rack: new(sc.P01Rack01),
Room: new(sc.P01Rack01Room01),
Partition: sc.Partition1,
ManagementIp: "1.1.1.1",
ReplaceMode: apiv2.SwitchReplaceMode_SWITCH_REPLACE_MODE_OPERATIONAL,
Expand All @@ -72,6 +74,7 @@ func Test_switchServiceServer_Register(t *testing.T) {
Id: "p01-r01leaf01-1",
Meta: &apiv2.Meta{},
Rack: new(sc.P01Rack01),
Room: new(sc.P01Rack01Room01),
Partition: sc.Partition1,
ManagementIp: "1.1.1.1",
ReplaceMode: apiv2.SwitchReplaceMode_SWITCH_REPLACE_MODE_OPERATIONAL,
Expand Down
3 changes: 3 additions & 0 deletions pkg/test/scenarios/spec.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@ const (
P02Rack02 = "p02-rack02"
P02Rack03 = "p02-rack03"

P01Rack01Room01 = "p01-rack01-room01"
P01Rack02Room01 = "p01-rack02-room01"

Machine1 = "00000000-0000-0000-0000-000000000001"
Machine2 = "00000000-0000-0000-0000-000000000002"
Machine3 = "00000000-0000-0000-0000-000000000003"
Expand Down
Loading