CLOUDSTACK-4674

[baremetal] /usr/share/cloudstack-common/scripts/util/ipmi.py script
need to recognize various ipmi version and BMC type of server
This commit is contained in:
Frank.Zhang 2013-10-28 14:48:01 -07:00
parent ef6038f1b3
commit fd5b9a2780
3 changed files with 36 additions and 7 deletions

View File

@ -31,6 +31,8 @@ import javax.ejb.Local;
import javax.naming.ConfigurationException;
import com.cloud.agent.api.*;
import com.cloud.configuration.Config;
import com.cloud.configuration.dao.ConfigurationDao;
import com.cloud.utils.Pair;
import org.apache.cloudstack.api.ApiConstants;
import org.apache.log4j.Logger;
@ -181,6 +183,14 @@ public class BareMetalResourceBase extends ManagerBase implements ServerResource
_isEchoScAgent = Boolean.valueOf(echoScAgent);
}
String ipmiIface = "default";
try {
ConfigurationDao configDao = ComponentContext.getComponent(ConfigurationDao.class);
ipmiIface = configDao.getValue(Config.BaremetalIpmiLanInterface.key());
} catch (Exception e) {
s_logger.debug(e.getMessage(), e);
}
String injectScript = "scripts/util/ipmi.py";
String scriptPath = Script.findScript("", injectScript);
if (scriptPath == null) {
@ -190,6 +200,7 @@ public class BareMetalResourceBase extends ManagerBase implements ServerResource
_pingCommand = new Script2(pythonPath, s_logger);
_pingCommand.add(scriptPath);
_pingCommand.add("ping");
_pingCommand.add("interface=" + ipmiIface);
_pingCommand.add("hostname=" + _ip);
_pingCommand.add("usrname=" + _username);
_pingCommand.add("password=" + _password, ParamType.PASSWORD);
@ -197,6 +208,7 @@ public class BareMetalResourceBase extends ManagerBase implements ServerResource
_setPxeBootCommand = new Script2(pythonPath, s_logger);
_setPxeBootCommand.add(scriptPath);
_setPxeBootCommand.add("boot_dev");
_setPxeBootCommand.add("interface=" + ipmiIface);
_setPxeBootCommand.add("hostname=" + _ip);
_setPxeBootCommand.add("usrname=" + _username);
_setPxeBootCommand.add("password=" + _password, ParamType.PASSWORD);
@ -205,6 +217,7 @@ public class BareMetalResourceBase extends ManagerBase implements ServerResource
_setDiskBootCommand = new Script2(pythonPath, s_logger);
_setDiskBootCommand.add(scriptPath);
_setDiskBootCommand.add("boot_dev");
_setDiskBootCommand.add("interface=" + ipmiIface);
_setDiskBootCommand.add("hostname=" + _ip);
_setDiskBootCommand.add("usrname=" + _username);
_setDiskBootCommand.add("password=" + _password, ParamType.PASSWORD);
@ -213,6 +226,7 @@ public class BareMetalResourceBase extends ManagerBase implements ServerResource
_rebootCommand = new Script2(pythonPath, s_logger);
_rebootCommand.add(scriptPath);
_rebootCommand.add("reboot");
_rebootCommand.add("interface=" + ipmiIface);
_rebootCommand.add("hostname=" + _ip);
_rebootCommand.add("usrname=" + _username);
_rebootCommand.add("password=" + _password, ParamType.PASSWORD);
@ -220,6 +234,7 @@ public class BareMetalResourceBase extends ManagerBase implements ServerResource
_getStatusCommand = new Script2(pythonPath, s_logger);
_getStatusCommand.add(scriptPath);
_getStatusCommand.add("ping");
_getStatusCommand.add("interface=" + ipmiIface);
_getStatusCommand.add("hostname=" + _ip);
_getStatusCommand.add("usrname=" + _username);
_getStatusCommand.add("password=" + _password, ParamType.PASSWORD);
@ -227,6 +242,7 @@ public class BareMetalResourceBase extends ManagerBase implements ServerResource
_powerOnCommand = new Script2(pythonPath, s_logger);
_powerOnCommand.add(scriptPath);
_powerOnCommand.add("power");
_powerOnCommand.add("interface=" + ipmiIface);
_powerOnCommand.add("hostname=" + _ip);
_powerOnCommand.add("usrname=" + _username);
_powerOnCommand.add("password=" + _password, ParamType.PASSWORD);
@ -235,6 +251,7 @@ public class BareMetalResourceBase extends ManagerBase implements ServerResource
_powerOffCommand = new Script2(pythonPath, s_logger);
_powerOffCommand.add(scriptPath);
_powerOffCommand.add("power");
_powerOffCommand.add("interface=" + ipmiIface);
_powerOffCommand.add("hostname=" + _ip);
_powerOffCommand.add("usrname=" + _username);
_powerOffCommand.add("password=" + _password, ParamType.PASSWORD);
@ -243,6 +260,7 @@ public class BareMetalResourceBase extends ManagerBase implements ServerResource
_forcePowerOffCommand = new Script2(pythonPath, s_logger);
_forcePowerOffCommand.add(scriptPath);
_forcePowerOffCommand.add("power");
_forcePowerOffCommand.add("interface=" + ipmiIface);
_forcePowerOffCommand.add("hostname=" + _ip);
_forcePowerOffCommand.add("usrname=" + _username);
_forcePowerOffCommand.add("password=" + _password, ParamType.PASSWORD);
@ -251,6 +269,7 @@ public class BareMetalResourceBase extends ManagerBase implements ServerResource
_bootOrRebootCommand = new Script2(pythonPath, s_logger);
_bootOrRebootCommand.add(scriptPath);
_bootOrRebootCommand.add("boot_or_reboot");
_bootOrRebootCommand.add("interface=" + ipmiIface);
_bootOrRebootCommand.add("hostname=" + _ip);
_bootOrRebootCommand.add("usrname=" + _username);
_bootOrRebootCommand.add("password=" + _password, ParamType.PASSWORD);

View File

@ -83,6 +83,15 @@ def check_tool():
print "Can not find ipmitool"
return False
def addInterfaceOption(cmd, args):
iface = args.get("interface")
if not iface or iface == "default":
return cmd
cmd.insert(0, iface)
cmd.insert(0, "-I")
return cmd
def ping(args):
hostname = args.get("hostname")
usrname = args.get("usrname")
@ -92,7 +101,7 @@ def ping(args):
print "No hostname"
return 1
o = ipmitool("-H", hostname, "-U", usrname, "-P", password, "chassis", "power", "status")
o = ipmitool(*addInterfaceOption(["-H", hostname, "-U", usrname, "-P", password, "chassis", "power", "status"], args))
if o.ret:
print o.stderr
return 1
@ -114,7 +123,7 @@ def boot_dev(args):
print "No boot device specified"
return 1
o = ipmitool("-H", hostname, "-U", usrname, "-P", password, "chassis", "bootdev", dev)
o = ipmitool(*addInterfaceOption(["-H", hostname, "-U", usrname, "-P", password, "chassis", "bootdev", dev], args))
if o.ret:
print o.stderr
return 1
@ -130,16 +139,16 @@ def reboot(args):
print "No hostname"
return 1
o = ipmitool("-H", hostname, "-U", usrname, "-P", password, "chassis", "power", "status")
o = ipmitool(*addInterfaceOption(["-H", hostname, "-U", usrname, "-P", password, "chassis", "power", "status"], args))
if o.ret:
print o.stderr
return 1
if "is on" in o.stdout:
o = ipmitool("-H", hostname, "-U", usrname, "-P", password, "chassis", "power", "cycle")
o = ipmitool(*addInterfaceOption(["-H", hostname, "-U", usrname, "-P", password, "chassis", "power", "cycle"], args))
else:
o = ipmitool("-H", hostname, "-U", usrname, "-P", password, "chassis", "power", "reset")
o = ipmitool(*addInterfaceOption(["-H", hostname, "-U", usrname, "-P", password, "chassis", "power", "reset"], args))
if o.ret:
print o.stderr
@ -157,7 +166,7 @@ def power(args):
print "No hostname"
return 1
o = ipmitool("-H", hostname, "-U", usrname, "-P", password, "chassis", "power", action)
o = ipmitool(*addInterfaceOption(["-H", hostname, "-U", usrname, "-P", password, "chassis", "power", action], args))
if o.ret:
print o.stderr
return 1
@ -168,7 +177,7 @@ def boot_or_reboot(args):
hostname = args.get("hostname")
usrname = args.get("usrname")
password = args.get("password")
o = ipmitool("-H", hostname, "-U", usrname, "-P", password, "chassis", "power", "status")
o = ipmitool(*addInterfaceOption(["-H", hostname, "-U", usrname, "-P", password, "chassis", "power", "status"], args))
if o.ret:
print o.stderr
return 1

View File

@ -378,6 +378,7 @@ public enum Config {
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),
IntervalToEchoBaremetalSecurityGroupAgent("Advanced", ManagementServer.class, Integer.class, "interval.baremetal.securitygroup.agent.echo", "10", "Interval to echo baremetal security group agent, in seconds", null),
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),
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),
ApiLimitEnabled("Advanced", ManagementServer.class, Boolean.class, "api.throttling.enabled", "false", "Enable/disable Api rate limit", null),
ApiLimitInterval("Advanced", ManagementServer.class, Integer.class, "api.throttling.interval", "1", "Time interval (in seconds) to reset API count", null),