Skip to content

Commit 8550156

Browse files
Merge pull request tinkerbell#33 from jacobweinstock/protobuf-clean-up
Update protobufs
2 parents 982ecde + cb19f4d commit 8550156

16 files changed

+503
-482
lines changed

api/v1/bmc.pb.go

Lines changed: 233 additions & 213 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

api/v1/bmc.proto

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,6 @@ service BMC {
1818
message NetworkSourceRequest {
1919
v1.Authn authn = 1;
2020
v1.Vendor vendor = 2;
21-
enum NetworkSource {
22-
DHCP = 0;
23-
STATIC = 1;
24-
}
2521
NetworkSource network_source = 3;
2622
}
2723

@@ -32,11 +28,7 @@ message NetworkSourceResponse {
3228
message ResetRequest {
3329
v1.Authn authn = 1;
3430
v1.Vendor vendor = 2;
35-
enum Kind {
36-
COLD = 0;
37-
WARM = 1;
38-
}
39-
Kind kind = 3;
31+
ResetKind reset_kind = 3;
4032
}
4133

4234
message ResetResponse {
@@ -46,11 +38,7 @@ message ResetResponse {
4638
message UserCreds {
4739
string username = 1;
4840
string password = 2;
49-
enum Role {
50-
admin = 0;
51-
user = 1;
52-
};
53-
Role role = 3;
41+
UserRole user_role = 3;
5442
}
5543

5644
message CreateUserRequest {
@@ -82,3 +70,21 @@ message UpdateUserRequest {
8270
message UpdateUserResponse {
8371
string task_id = 1;
8472
}
73+
74+
enum UserRole {
75+
USER_ROLE_UNSPECIFIED = 0;
76+
USER_ROLE_ADMIN = 1;
77+
USER_ROLE_USER = 2;
78+
}
79+
80+
enum ResetKind {
81+
RESET_KIND_UNSPECIFIED = 0;
82+
RESET_KIND_COLD = 1;
83+
RESET_KIND_WARM = 2;
84+
}
85+
86+
enum NetworkSource {
87+
NETWORK_SOURCE_UNSPECIFIED = 0;
88+
NETWORK_SOURCE_DHCP = 1;
89+
NETWORK_SOURCE_STATIC = 2;
90+
}

api/v1/common.pb.go

Lines changed: 3 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

api/v1/machine.pb.go

Lines changed: 162 additions & 142 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

api/v1/machine.proto

Lines changed: 21 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,7 @@ service Machine {
1515
message DeviceRequest {
1616
v1.Authn authn = 1;
1717
v1.Vendor vendor = 2;
18-
enum Device {
19-
NONE = 0;
20-
BIOS = 1;
21-
CDROM = 2;
22-
DISK = 3;
23-
PXE = 4;
24-
}
25-
Device device = 3;
18+
BootDevice boot_device = 3;
2619
bool persistent = 4;
2720
bool efi_boot = 5;
2821
}
@@ -34,19 +27,30 @@ message DeviceResponse {
3427
message PowerRequest {
3528
v1.Authn authn = 1;
3629
v1.Vendor vendor = 2;
37-
enum Action {
38-
ON = 0;
39-
OFF = 1;
40-
HARDOFF = 2;
41-
CYCLE = 3;
42-
RESET = 4;
43-
STATUS = 5;
44-
}
45-
Action action = 3;
30+
PowerAction power_action = 3;
4631
int32 soft_timeout = 4;
4732
int32 off_duration = 5;
4833
}
4934

5035
message PowerResponse {
5136
string task_id = 1;
5237
}
38+
39+
enum BootDevice {
40+
BOOT_DEVICE_UNSPECIFIED = 0;
41+
BOOT_DEVICE_NONE = 1;
42+
BOOT_DEVICE_BIOS = 2;
43+
BOOT_DEVICE_CDROM = 4;
44+
BOOT_DEVICE_DISK = 5;
45+
BOOT_DEVICE_PXE = 6;
46+
}
47+
48+
enum PowerAction {
49+
POWER_ACTION_UNSPECIFIED = 0;
50+
POWER_ACTION_ON = 1;
51+
POWER_ACTION_OFF = 2;
52+
POWER_ACTION_HARDOFF = 3;
53+
POWER_ACTION_CYCLE = 4;
54+
POWER_ACTION_RESET = 5;
55+
POWER_ACTION_STATUS = 6;
56+
}

api/v1/task.pb.go

Lines changed: 3 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

api/v1/user.proto

Lines changed: 0 additions & 49 deletions
This file was deleted.

cmd/machine.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,17 +48,17 @@ var machineCmd = &cobra.Command{
4848
Authn: &v1.Authn_DirectAuthn{
4949
DirectAuthn: &v1.DirectAuthn{
5050
Host: &v1.Host{
51-
Host: "10.249.51.28",
51+
Host: "127.0.0.1",
5252
},
53-
Username: "Administrator",
54-
Password: "YFJDJC9T",
53+
Username: "ADMIN",
54+
Password: "ADMIN",
5555
},
5656
},
5757
},
5858
Vendor: &v1.Vendor{
5959
Name: "HP",
6060
},
61-
Action: v1.PowerRequest_STATUS,
61+
PowerAction: v1.PowerAction_POWER_ACTION_STATUS,
6262
})
6363
if err != nil {
6464
logger.V(0).Error(err, "error calling")

server/grpcsvr/oob/bmc/users_bmclib.go

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ func (b *bmclibUserManagement) create(ctx context.Context) repository.Error {
4949
{
5050
Name: b.creds.Username,
5151
Password: b.creds.Password,
52-
Role: b.creds.Role.String(),
52+
Role: userRoleToString(b.creds.UserRole),
5353
Enable: true,
5454
},
5555
}
@@ -69,7 +69,7 @@ func (b *bmclibUserManagement) update(ctx context.Context) repository.Error {
6969
{
7070
Name: b.creds.Username,
7171
Password: b.creds.Password,
72-
Role: b.creds.Role.String(),
72+
Role: userRoleToString(b.creds.UserRole),
7373
Enable: true,
7474
},
7575
}
@@ -102,3 +102,14 @@ func (b *bmclibUserManagement) delete(ctx context.Context) repository.Error {
102102
}
103103
return errMsg
104104
}
105+
106+
func userRoleToString(role v1.UserRole) string {
107+
var r string
108+
switch role.String() {
109+
case "USER_ROLE_USER":
110+
r = "user"
111+
default:
112+
r = "admin"
113+
}
114+
return r
115+
}

server/grpcsvr/oob/machine/machine.go

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ func (m Action) BootDevice(ctx context.Context) (result string, errMsg repositor
105105
return result, errMsg
106106
}
107107

108-
base := "setting boot device: " + m.BootDeviceRequest.GetDevice().String()
108+
base := "setting boot device: " + m.BootDeviceRequest.GetBootDevice().String()
109109
msg := "working on " + base
110110
m.SendStatusMessage(msg)
111111

@@ -165,7 +165,7 @@ func (m Action) Power(ctx context.Context) (result string, errMsg repository.Err
165165
return result, errMsg
166166
}
167167

168-
base := "power " + m.PowerRequest.GetAction().String()
168+
base := "power " + m.PowerRequest.GetPowerAction().String()
169169
msg := "working on " + base
170170
m.SendStatusMessage(msg)
171171

@@ -205,7 +205,7 @@ func (m Action) Power(ctx context.Context) (result string, errMsg repository.Err
205205
for _, connection := range connections {
206206
if connection.Connected {
207207
m.Log.V(1).Info("trying", "name", connection.Name)
208-
result, errMsg = doAction(ctx, m.PowerRequest.GetAction(), connection.pwr)
208+
result, errMsg = doAction(ctx, m.PowerRequest.GetPowerAction(), connection.pwr)
209209
if errMsg.Message == "" {
210210
m.Log.V(1).Info("action implemented by", "implementer", connection.Name)
211211
break
@@ -221,22 +221,25 @@ func (m Action) Power(ctx context.Context) (result string, errMsg repository.Err
221221
return strings.ToLower(result), errMsg //nolint
222222
}
223223

224-
func doAction(ctx context.Context, action v1.PowerRequest_Action, pwr power) (result string, errMsg repository.Error) {
224+
func doAction(ctx context.Context, action v1.PowerAction, pwr power) (result string, errMsg repository.Error) {
225225
switch action {
226-
case v1.PowerRequest_ON:
226+
case v1.PowerAction_POWER_ACTION_ON:
227227
result, errMsg = pwr.on(ctx)
228-
case v1.PowerRequest_OFF:
228+
case v1.PowerAction_POWER_ACTION_OFF:
229229
result, errMsg = pwr.off(ctx)
230-
case v1.PowerRequest_STATUS:
230+
case v1.PowerAction_POWER_ACTION_STATUS:
231231
result, errMsg = pwr.status(ctx)
232-
case v1.PowerRequest_RESET:
232+
case v1.PowerAction_POWER_ACTION_RESET:
233233
result, errMsg = pwr.reset(ctx)
234-
case v1.PowerRequest_HARDOFF:
234+
case v1.PowerAction_POWER_ACTION_HARDOFF:
235235
result, errMsg = pwr.hardoff(ctx)
236-
case v1.PowerRequest_CYCLE:
236+
case v1.PowerAction_POWER_ACTION_CYCLE:
237237
result, errMsg = pwr.cycle(ctx)
238+
case v1.PowerAction_POWER_ACTION_UNSPECIFIED:
239+
errMsg.Code = v1.Code_value["INVALID_ARGUMENT"]
240+
errMsg.Message = "UNSPECIFIED power action"
238241
default:
239-
errMsg.Code = v1.Code_value["UNKNOWN"]
242+
errMsg.Code = v1.Code_value["INVALID_ARGUMENT"]
240243
errMsg.Message = "unknown power action"
241244
}
242245
return result, errMsg

server/grpcsvr/oob/machine/machine_bootdevice_ipmi.go

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -81,19 +81,23 @@ func (b *ipmiBootDevice) Close(ctx context.Context) {
8181
// setBootDevice will try to set boot device using ipmitool interface lan and lanplus
8282
func (b *ipmiBootDevice) setBootDevice(ctx context.Context) (result string, errMsg repository.Error) {
8383
var dev goipmi.BootDevice
84-
switch b.mAction.BootDeviceRequest.Device {
85-
case v1.DeviceRequest_NONE:
84+
switch b.mAction.BootDeviceRequest.BootDevice {
85+
case v1.BootDevice_BOOT_DEVICE_NONE:
8686
dev = goipmi.BootDeviceNone
87-
case v1.DeviceRequest_BIOS:
87+
case v1.BootDevice_BOOT_DEVICE_BIOS:
8888
dev = goipmi.BootDeviceBios
89-
case v1.DeviceRequest_CDROM:
89+
case v1.BootDevice_BOOT_DEVICE_CDROM:
9090
dev = goipmi.BootDeviceCdrom
91-
case v1.DeviceRequest_DISK:
91+
case v1.BootDevice_BOOT_DEVICE_DISK:
9292
dev = goipmi.BootDeviceDisk
93-
case v1.DeviceRequest_PXE:
93+
case v1.BootDevice_BOOT_DEVICE_PXE:
9494
dev = goipmi.BootDevicePxe
95+
case v1.BootDevice_BOOT_DEVICE_UNSPECIFIED:
96+
errMsg.Code = v1.Code_value["INVALID_ARGUMENT"]
97+
errMsg.Message = "UNSPECIFIED boot device"
98+
return result, errMsg
9599
default:
96-
errMsg.Code = v1.Code_value["UNKNOWN"]
100+
errMsg.Code = v1.Code_value["INVALID_ARGUMENT"]
97101
errMsg.Message = "unknown boot device"
98102
return result, errMsg
99103
}

server/grpcsvr/oob/machine/machine_bootdevice_ipmi_test.go

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -63,34 +63,34 @@ func TestIPMIBootDeviceConnect(t *testing.T) {
6363
func TestSetBootDevice(t *testing.T) {
6464
testCases := []struct {
6565
name string
66-
device v1.DeviceRequest_Device
66+
device v1.BootDevice
6767
err *repository.Error
6868
}{
6969
{
7070
name: "set device: pxe",
71-
device: v1.DeviceRequest_PXE,
71+
device: v1.BootDevice_BOOT_DEVICE_PXE,
7272
},
7373
{
7474
name: "set device: disk",
75-
device: v1.DeviceRequest_DISK,
75+
device: v1.BootDevice_BOOT_DEVICE_DISK,
7676
},
7777
{
7878
name: "set device: cdrom",
79-
device: v1.DeviceRequest_CDROM,
79+
device: v1.BootDevice_BOOT_DEVICE_CDROM,
8080
},
8181
{
8282
name: "set device: bios",
83-
device: v1.DeviceRequest_BIOS,
83+
device: v1.BootDevice_BOOT_DEVICE_BIOS,
8484
},
8585
{
8686
name: "set device: none",
87-
device: v1.DeviceRequest_NONE,
87+
device: v1.BootDevice_BOOT_DEVICE_NONE,
8888
},
8989
{
9090
name: "set device: unknown",
91-
device: v1.DeviceRequest_Device(9),
91+
device: v1.BootDevice(9),
9292
err: &repository.Error{
93-
Code: 2,
93+
Code: 3,
9494
Message: "unknown boot device",
9595
},
9696
},
@@ -107,7 +107,7 @@ func TestSetBootDevice(t *testing.T) {
107107
for _, tc := range testCases {
108108
testCase := tc
109109
t.Run(testCase.name, func(t *testing.T) {
110-
expectedResult := "boot device set: " + strings.ToLower(tc.device.String())
110+
expectedResult := "boot device set: " + strings.ToLower(strings.TrimSpace(strings.Split(tc.name, ":")[1]))
111111

112112
ctx, cancel := context.WithTimeout(context.Background(), 1*time.Second)
113113
defer cancel()
@@ -119,7 +119,7 @@ func TestSetBootDevice(t *testing.T) {
119119
Log: l,
120120
StatusMessages: make(chan string),
121121
},
122-
BootDeviceRequest: &v1.DeviceRequest{Device: tc.device},
122+
BootDeviceRequest: &v1.DeviceRequest{BootDevice: tc.device},
123123
},
124124
user: "admin",
125125
password: "admin",

0 commit comments

Comments
 (0)