Skip to content

Commit fd5b9a2

Browse files
author
Frank.Zhang
committed
CLOUDSTACK-4674
[baremetal] /usr/share/cloudstack-common/scripts/util/ipmi.py script need to recognize various ipmi version and BMC type of server
1 parent ef6038f commit fd5b9a2

3 files changed

Lines changed: 36 additions & 7 deletions

File tree

‎plugins/hypervisors/baremetal/src/com/cloud/baremetal/networkservice/BareMetalResourceBase.java‎

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@
3131
import javax.naming.ConfigurationException;
3232

3333
import com.cloud.agent.api.*;
34+
import com.cloud.configuration.Config;
35+
import com.cloud.configuration.dao.ConfigurationDao;
3436
import com.cloud.utils.Pair;
3537
import org.apache.cloudstack.api.ApiConstants;
3638
import org.apache.log4j.Logger;
@@ -181,6 +183,14 @@ public boolean configure(String name, Map<String, Object> params) throws Configu
181183
_isEchoScAgent = Boolean.valueOf(echoScAgent);
182184
}
183185

186+
String ipmiIface = "default";
187+
try {
188+
ConfigurationDao configDao = ComponentContext.getComponent(ConfigurationDao.class);
189+
ipmiIface = configDao.getValue(Config.BaremetalIpmiLanInterface.key());
190+
} catch (Exception e) {
191+
s_logger.debug(e.getMessage(), e);
192+
}
193+
184194
String injectScript = "scripts/util/ipmi.py";
185195
String scriptPath = Script.findScript("", injectScript);
186196
if (scriptPath == null) {
@@ -190,13 +200,15 @@ public boolean configure(String name, Map<String, Object> params) throws Configu
190200
_pingCommand = new Script2(pythonPath, s_logger);
191201
_pingCommand.add(scriptPath);
192202
_pingCommand.add("ping");
203+
_pingCommand.add("interface=" + ipmiIface);
193204
_pingCommand.add("hostname=" + _ip);
194205
_pingCommand.add("usrname=" + _username);
195206
_pingCommand.add("password=" + _password, ParamType.PASSWORD);
196207

197208
_setPxeBootCommand = new Script2(pythonPath, s_logger);
198209
_setPxeBootCommand.add(scriptPath);
199210
_setPxeBootCommand.add("boot_dev");
211+
_setPxeBootCommand.add("interface=" + ipmiIface);
200212
_setPxeBootCommand.add("hostname=" + _ip);
201213
_setPxeBootCommand.add("usrname=" + _username);
202214
_setPxeBootCommand.add("password=" + _password, ParamType.PASSWORD);
@@ -205,6 +217,7 @@ public boolean configure(String name, Map<String, Object> params) throws Configu
205217
_setDiskBootCommand = new Script2(pythonPath, s_logger);
206218
_setDiskBootCommand.add(scriptPath);
207219
_setDiskBootCommand.add("boot_dev");
220+
_setDiskBootCommand.add("interface=" + ipmiIface);
208221
_setDiskBootCommand.add("hostname=" + _ip);
209222
_setDiskBootCommand.add("usrname=" + _username);
210223
_setDiskBootCommand.add("password=" + _password, ParamType.PASSWORD);
@@ -213,20 +226,23 @@ public boolean configure(String name, Map<String, Object> params) throws Configu
213226
_rebootCommand = new Script2(pythonPath, s_logger);
214227
_rebootCommand.add(scriptPath);
215228
_rebootCommand.add("reboot");
229+
_rebootCommand.add("interface=" + ipmiIface);
216230
_rebootCommand.add("hostname=" + _ip);
217231
_rebootCommand.add("usrname=" + _username);
218232
_rebootCommand.add("password=" + _password, ParamType.PASSWORD);
219233

220234
_getStatusCommand = new Script2(pythonPath, s_logger);
221235
_getStatusCommand.add(scriptPath);
222236
_getStatusCommand.add("ping");
237+
_getStatusCommand.add("interface=" + ipmiIface);
223238
_getStatusCommand.add("hostname=" + _ip);
224239
_getStatusCommand.add("usrname=" + _username);
225240
_getStatusCommand.add("password=" + _password, ParamType.PASSWORD);
226241

227242
_powerOnCommand = new Script2(pythonPath, s_logger);
228243
_powerOnCommand.add(scriptPath);
229244
_powerOnCommand.add("power");
245+
_powerOnCommand.add("interface=" + ipmiIface);
230246
_powerOnCommand.add("hostname=" + _ip);
231247
_powerOnCommand.add("usrname=" + _username);
232248
_powerOnCommand.add("password=" + _password, ParamType.PASSWORD);
@@ -235,6 +251,7 @@ public boolean configure(String name, Map<String, Object> params) throws Configu
235251
_powerOffCommand = new Script2(pythonPath, s_logger);
236252
_powerOffCommand.add(scriptPath);
237253
_powerOffCommand.add("power");
254+
_powerOffCommand.add("interface=" + ipmiIface);
238255
_powerOffCommand.add("hostname=" + _ip);
239256
_powerOffCommand.add("usrname=" + _username);
240257
_powerOffCommand.add("password=" + _password, ParamType.PASSWORD);
@@ -243,6 +260,7 @@ public boolean configure(String name, Map<String, Object> params) throws Configu
243260
_forcePowerOffCommand = new Script2(pythonPath, s_logger);
244261
_forcePowerOffCommand.add(scriptPath);
245262
_forcePowerOffCommand.add("power");
263+
_forcePowerOffCommand.add("interface=" + ipmiIface);
246264
_forcePowerOffCommand.add("hostname=" + _ip);
247265
_forcePowerOffCommand.add("usrname=" + _username);
248266
_forcePowerOffCommand.add("password=" + _password, ParamType.PASSWORD);
@@ -251,6 +269,7 @@ public boolean configure(String name, Map<String, Object> params) throws Configu
251269
_bootOrRebootCommand = new Script2(pythonPath, s_logger);
252270
_bootOrRebootCommand.add(scriptPath);
253271
_bootOrRebootCommand.add("boot_or_reboot");
272+
_bootOrRebootCommand.add("interface=" + ipmiIface);
254273
_bootOrRebootCommand.add("hostname=" + _ip);
255274
_bootOrRebootCommand.add("usrname=" + _username);
256275
_bootOrRebootCommand.add("password=" + _password, ParamType.PASSWORD);

‎scripts/util/ipmi.py‎

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,15 @@ def check_tool():
8383
print "Can not find ipmitool"
8484
return False
8585

86+
def addInterfaceOption(cmd, args):
87+
iface = args.get("interface")
88+
if not iface or iface == "default":
89+
return cmd
90+
91+
cmd.insert(0, iface)
92+
cmd.insert(0, "-I")
93+
return cmd
94+
8695
def ping(args):
8796
hostname = args.get("hostname")
8897
usrname = args.get("usrname")
@@ -92,7 +101,7 @@ def ping(args):
92101
print "No hostname"
93102
return 1
94103

95-
o = ipmitool("-H", hostname, "-U", usrname, "-P", password, "chassis", "power", "status")
104+
o = ipmitool(*addInterfaceOption(["-H", hostname, "-U", usrname, "-P", password, "chassis", "power", "status"], args))
96105
if o.ret:
97106
print o.stderr
98107
return 1
@@ -114,7 +123,7 @@ def boot_dev(args):
114123
print "No boot device specified"
115124
return 1
116125

117-
o = ipmitool("-H", hostname, "-U", usrname, "-P", password, "chassis", "bootdev", dev)
126+
o = ipmitool(*addInterfaceOption(["-H", hostname, "-U", usrname, "-P", password, "chassis", "bootdev", dev], args))
118127
if o.ret:
119128
print o.stderr
120129
return 1
@@ -130,16 +139,16 @@ def reboot(args):
130139
print "No hostname"
131140
return 1
132141

133-
o = ipmitool("-H", hostname, "-U", usrname, "-P", password, "chassis", "power", "status")
142+
o = ipmitool(*addInterfaceOption(["-H", hostname, "-U", usrname, "-P", password, "chassis", "power", "status"], args))
134143
if o.ret:
135144
print o.stderr
136145
return 1
137146

138147

139148
if "is on" in o.stdout:
140-
o = ipmitool("-H", hostname, "-U", usrname, "-P", password, "chassis", "power", "cycle")
149+
o = ipmitool(*addInterfaceOption(["-H", hostname, "-U", usrname, "-P", password, "chassis", "power", "cycle"], args))
141150
else:
142-
o = ipmitool("-H", hostname, "-U", usrname, "-P", password, "chassis", "power", "reset")
151+
o = ipmitool(*addInterfaceOption(["-H", hostname, "-U", usrname, "-P", password, "chassis", "power", "reset"], args))
143152

144153
if o.ret:
145154
print o.stderr
@@ -157,7 +166,7 @@ def power(args):
157166
print "No hostname"
158167
return 1
159168

160-
o = ipmitool("-H", hostname, "-U", usrname, "-P", password, "chassis", "power", action)
169+
o = ipmitool(*addInterfaceOption(["-H", hostname, "-U", usrname, "-P", password, "chassis", "power", action], args))
161170
if o.ret:
162171
print o.stderr
163172
return 1
@@ -168,7 +177,7 @@ def boot_or_reboot(args):
168177
hostname = args.get("hostname")
169178
usrname = args.get("usrname")
170179
password = args.get("password")
171-
o = ipmitool("-H", hostname, "-U", usrname, "-P", password, "chassis", "power", "status")
180+
o = ipmitool(*addInterfaceOption(["-H", hostname, "-U", usrname, "-P", password, "chassis", "power", "status"], args))
172181
if o.ret:
173182
print o.stderr
174183
return 1

‎server/src/com/cloud/configuration/Config.java‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -378,6 +378,7 @@ public enum Config {
378378
EnableBaremetalSecurityGroupAgentEcho("Advanced", ManagementServer.class, Boolean.class, "enable.baremetal.securitygroup.agent.echo", "false", "After starting provision process, periodcially echo security agent installed in the template. Treat provisioning as success only if echo successfully", null),
379379
IntervalToEchoBaremetalSecurityGroupAgent("Advanced", ManagementServer.class, Integer.class, "interval.baremetal.securitygroup.agent.echo", "10", "Interval to echo baremetal security group agent, in seconds", null),
380380
TimeoutToEchoBaremetalSecurityGroupAgent("Advanced", ManagementServer.class, Integer.class, "timeout.baremetal.securitygroup.agent.echo", "3600", "Timeout to echo baremetal security group agent, in seconds, the provisioning process will be treated as a failure", null),
381+
BaremetalIpmiLanInterface("Advanced", ManagementServer.class, String.class, "baremetal.ipmi.lan.interface", "default", "option specified in -I option of impitool. candidates are: open/bmc/lipmi/lan/lanplus/free/imb, see ipmitool man page for details. default valule 'default' means using default option of ipmitool", null),
381382

382383
ApiLimitEnabled("Advanced", ManagementServer.class, Boolean.class, "api.throttling.enabled", "false", "Enable/disable Api rate limit", null),
383384
ApiLimitInterval("Advanced", ManagementServer.class, Integer.class, "api.throttling.interval", "1", "Time interval (in seconds) to reset API count", null),

0 commit comments

Comments
 (0)