Skip to content

Commit 4c9bda6

Browse files
committed
Add ipmi_priv_level to driver_info
Add a new parameter to optionaly set the ipmi privilage level used when connected to BMC's over ipmi, the default "ADMINISTRATOR" isn't always available (e.g. in ibmcloud).
1 parent 9cb78ee commit 4c9bda6

File tree

3 files changed

+41
-9
lines changed

3 files changed

+41
-9
lines changed

docs/api.md

+3
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,9 @@ communicate with them.
3232
* IPMI
3333
* `ipmi://<host>:<port>`, an unadorned `<host>:<port>` is also accepted
3434
and the port is optional, if using the default one (623).
35+
* The ipmi privilege level can be set from the default(`ADMINISTRATOR`)
36+
to `OPERATOR` with an option URL parameter `privilegelevel`.
37+
`ipmi://<host>:<port>?privilegelevel=OPERATOR`
3538
* Dell iDRAC
3639
* `idrac://` (or `idrac+http://` to disable TLS).
3740
* `idrac-virtualmedia://` to use virtual media instead of PXE

pkg/bmc/access_test.go

+19-5
Original file line numberDiff line numberDiff line change
@@ -678,11 +678,25 @@ func TestDriverInfo(t *testing.T) {
678678
Scenario: "ipmi default port",
679679
input: "ipmi://192.168.122.1",
680680
expects: map[string]interface{}{
681-
"ipmi_port": ipmiDefaultPort,
682-
"ipmi_password": "",
683-
"ipmi_username": "",
684-
"ipmi_address": "192.168.122.1",
685-
"ipmi_verify_ca": false,
681+
"ipmi_port": ipmiDefaultPort,
682+
"ipmi_password": "",
683+
"ipmi_username": "",
684+
"ipmi_address": "192.168.122.1",
685+
"ipmi_verify_ca": false,
686+
"ipmi_priv_level": "ADMINISTRATOR",
687+
},
688+
},
689+
690+
{
691+
Scenario: "ipmi setting privilege level",
692+
input: "ipmi://192.168.122.1?privilegelevel=OPERATOR",
693+
expects: map[string]interface{}{
694+
"ipmi_port": ipmiDefaultPort,
695+
"ipmi_password": "",
696+
"ipmi_username": "",
697+
"ipmi_address": "192.168.122.1",
698+
"ipmi_verify_ca": false,
699+
"ipmi_priv_level": "OPERATOR",
686700
},
687701
},
688702

pkg/bmc/ipmi.go

+19-4
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,24 @@ func init() {
1212
RegisterFactory("libvirt", newIPMIAccessDetails, []string{})
1313
}
1414

15+
func getPrivilegeLevel(rawquery string) string {
16+
privilegelevel := "ADMINISTRATOR"
17+
q, err := url.ParseQuery(rawquery)
18+
if err != nil {
19+
return privilegelevel
20+
}
21+
if val, ok := q["privilegelevel"]; ok {
22+
return val[0]
23+
}
24+
return privilegelevel
25+
}
26+
1527
func newIPMIAccessDetails(parsedURL *url.URL, disableCertificateVerification bool) (AccessDetails, error) {
1628
return &ipmiAccessDetails{
1729
bmcType: parsedURL.Scheme,
1830
portNum: parsedURL.Port(),
1931
hostname: parsedURL.Hostname(),
32+
privilegelevel: getPrivilegeLevel(parsedURL.RawQuery),
2033
disableCertificateVerification: disableCertificateVerification,
2134
}, nil
2235
}
@@ -25,6 +38,7 @@ type ipmiAccessDetails struct {
2538
bmcType string
2639
portNum string
2740
hostname string
41+
privilegelevel string
2842
disableCertificateVerification bool
2943
}
3044

@@ -61,10 +75,11 @@ func (a *ipmiAccessDetails) DisableCertificateVerification() bool {
6175
// the kernel and ramdisk locations).
6276
func (a *ipmiAccessDetails) DriverInfo(bmcCreds Credentials) map[string]interface{} {
6377
result := map[string]interface{}{
64-
"ipmi_port": a.portNum,
65-
"ipmi_username": bmcCreds.Username,
66-
"ipmi_password": bmcCreds.Password,
67-
"ipmi_address": a.hostname,
78+
"ipmi_port": a.portNum,
79+
"ipmi_username": bmcCreds.Username,
80+
"ipmi_password": bmcCreds.Password,
81+
"ipmi_address": a.hostname,
82+
"ipmi_priv_level": a.privilegelevel,
6883
}
6984

7085
if a.disableCertificateVerification {

0 commit comments

Comments
 (0)