Skip to content

Commit 16a51ee

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 1a3f394 commit 16a51ee

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
@@ -30,6 +30,8 @@
3030
import javax.naming.ConfigurationException;
3131

3232
import com.cloud.agent.api.*;
33+
import com.cloud.configuration.Config;
34+
import com.cloud.configuration.dao.ConfigurationDao;
3335
import com.cloud.utils.Pair;
3436
import org.apache.cloudstack.api.ApiConstants;
3537
import org.apache.log4j.Logger;
@@ -155,6 +157,14 @@ public boolean configure(String name, Map<String, Object> params) throws Configu
155157
_isEchoScAgent = Boolean.valueOf(echoScAgent);
156158
}
157159

160+
String ipmiIface = "default";
161+
try {
162+
ConfigurationDao configDao = ComponentContext.getComponent(ConfigurationDao.class);
163+
ipmiIface = configDao.getValue(Config.BaremetalIpmiLanInterface.key());
164+
} catch (Exception e) {
165+
s_logger.debug(e.getMessage(), e);
166+
}
167+
158168
String injectScript = "scripts/util/ipmi.py";
159169
String scriptPath = Script.findScript("", injectScript);
160170
if (scriptPath == null) {
@@ -164,13 +174,15 @@ public boolean configure(String name, Map<String, Object> params) throws Configu
164174
_pingCommand = new Script2(pythonPath, s_logger);
165175
_pingCommand.add(scriptPath);
166176
_pingCommand.add("ping");
177+
_pingCommand.add("interface=" + ipmiIface);
167178
_pingCommand.add("hostname=" + _ip);
168179
_pingCommand.add("usrname=" + _username);
169180
_pingCommand.add("password=" + _password, ParamType.PASSWORD);
170181

171182
_setPxeBootCommand = new Script2(pythonPath, s_logger);
172183
_setPxeBootCommand.add(scriptPath);
173184
_setPxeBootCommand.add("boot_dev");
185+
_setPxeBootCommand.add("interface=" + ipmiIface);
174186
_setPxeBootCommand.add("hostname=" + _ip);
175187
_setPxeBootCommand.add("usrname=" + _username);
176188
_setPxeBootCommand.add("password=" + _password, ParamType.PASSWORD);
@@ -179,6 +191,7 @@ public boolean configure(String name, Map<String, Object> params) throws Configu
179191
_setDiskBootCommand = new Script2(pythonPath, s_logger);
180192
_setDiskBootCommand.add(scriptPath);
181193
_setDiskBootCommand.add("boot_dev");
194+
_setDiskBootCommand.add("interface=" + ipmiIface);
182195
_setDiskBootCommand.add("hostname=" + _ip);
183196
_setDiskBootCommand.add("usrname=" + _username);
184197
_setDiskBootCommand.add("password=" + _password, ParamType.PASSWORD);
@@ -187,20 +200,23 @@ public boolean configure(String name, Map<String, Object> params) throws Configu
187200
_rebootCommand = new Script2(pythonPath, s_logger);
188201
_rebootCommand.add(scriptPath);
189202
_rebootCommand.add("reboot");
203+
_rebootCommand.add("interface=" + ipmiIface);
190204
_rebootCommand.add("hostname=" + _ip);
191205
_rebootCommand.add("usrname=" + _username);
192206
_rebootCommand.add("password=" + _password, ParamType.PASSWORD);
193207

194208
_getStatusCommand = new Script2(pythonPath, s_logger);
195209
_getStatusCommand.add(scriptPath);
196210
_getStatusCommand.add("ping");
211+
_getStatusCommand.add("interface=" + ipmiIface);
197212
_getStatusCommand.add("hostname=" + _ip);
198213
_getStatusCommand.add("usrname=" + _username);
199214
_getStatusCommand.add("password=" + _password, ParamType.PASSWORD);
200215

201216
_powerOnCommand = new Script2(pythonPath, s_logger);
202217
_powerOnCommand.add(scriptPath);
203218
_powerOnCommand.add("power");
219+
_powerOnCommand.add("interface=" + ipmiIface);
204220
_powerOnCommand.add("hostname=" + _ip);
205221
_powerOnCommand.add("usrname=" + _username);
206222
_powerOnCommand.add("password=" + _password, ParamType.PASSWORD);
@@ -209,6 +225,7 @@ public boolean configure(String name, Map<String, Object> params) throws Configu
209225
_powerOffCommand = new Script2(pythonPath, s_logger);
210226
_powerOffCommand.add(scriptPath);
211227
_powerOffCommand.add("power");
228+
_powerOffCommand.add("interface=" + ipmiIface);
212229
_powerOffCommand.add("hostname=" + _ip);
213230
_powerOffCommand.add("usrname=" + _username);
214231
_powerOffCommand.add("password=" + _password, ParamType.PASSWORD);
@@ -217,6 +234,7 @@ public boolean configure(String name, Map<String, Object> params) throws Configu
217234
_forcePowerOffCommand = new Script2(pythonPath, s_logger);
218235
_forcePowerOffCommand.add(scriptPath);
219236
_forcePowerOffCommand.add("power");
237+
_forcePowerOffCommand.add("interface=" + ipmiIface);
220238
_forcePowerOffCommand.add("hostname=" + _ip);
221239
_forcePowerOffCommand.add("usrname=" + _username);
222240
_forcePowerOffCommand.add("password=" + _password, ParamType.PASSWORD);
@@ -225,6 +243,7 @@ public boolean configure(String name, Map<String, Object> params) throws Configu
225243
_bootOrRebootCommand = new Script2(pythonPath, s_logger);
226244
_bootOrRebootCommand.add(scriptPath);
227245
_bootOrRebootCommand.add("boot_or_reboot");
246+
_bootOrRebootCommand.add("interface=" + ipmiIface);
228247
_bootOrRebootCommand.add("hostname=" + _ip);
229248
_bootOrRebootCommand.add("usrname=" + _username);
230249
_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
@@ -423,6 +423,7 @@ public enum Config {
423423
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),
424424
IntervalToEchoBaremetalSecurityGroupAgent("Advanced", ManagementServer.class, Integer.class, "interval.baremetal.securitygroup.agent.echo", "10", "Interval to echo baremetal security group agent, in seconds", null),
425425
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),
426+
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),
426427

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

0 commit comments

Comments
 (0)