Commit e4a9cd3b authored by Thomas Goirand's avatar Thomas Goirand

* Add option to perform ipmitool settings in the target image when running on

    the slave image.
  * Add option to show the calculated IPMI console command.
parent 9b7ee686
......@@ -8,6 +8,9 @@ openstack-cluster-installer (21) UNRELEASED; urgency=medium
* List all bridge setup with OCI in neutron's config, allowing a virtually
unlimited number of bridges.
* Fix service_credentials/cafile in ceilometer.
* Add option to perform ipmitool settings in the target image when running on
the slave image.
* Add option to show the calculated IPMI console command.
[ Oliver Chaze ]
* swift: do not log in syslog general logs
......
......@@ -7,7 +7,7 @@ _ocicli() {
prev="${COMP_WORDS[COMP_CWORD-1]}"
cmd_name="${COMP_WORDS[1]}"
opts="machine-list machine-show machine-set machine-add machine-remove machine-destroy machine-reboot-on-hdd machine-reboot-on-live machine-ipmi-reboot-on-hdd machine-ipmi-reboot-on-live machine-install-os machine-display-install-cmd machine-install-log machine-set-ipmi location-list location-create location-delete network-create network-list network-delete network-add network-remove network-set cluster-list cluster-create cluster-delete cluster-show-networks cluster-show-machines cluster-show-ips swift-region-list swift-region-create swift-region-delete swift-calculate-ring role-list role-create role-delete"
opts="machine-list machine-console machine-show machine-set machine-add machine-remove machine-destroy machine-reboot-on-hdd machine-reboot-on-live machine-ipmi-reboot-on-hdd machine-ipmi-reboot-on-live machine-install-os machine-display-install-cmd machine-install-log machine-set-ipmi location-list location-create location-delete network-create network-list network-delete network-add network-remove network-set cluster-list cluster-create cluster-delete cluster-show-networks cluster-show-machines cluster-show-ips swift-region-list swift-region-create swift-region-delete swift-calculate-ring role-list role-create role-delete"
iface_names="none eth0 eth1 eth2 eth3 eth4 eth5 10m1 10m2 10m3 10m4 100m1 100m2 100m3 100m4 1g1 1g2 1g3 1g4 10g1 10g2 10g3 10g4"
case "${cmd_name}" in
......@@ -40,6 +40,18 @@ _ocicli() {
;;
esac
;;
machine-console)
case ${COMP_CWORD} in
2)
local serial_list=$(ocicli -csv machine-list | q -d, -H "SELECT serial FROM -" | tr \\n " ")
COMPREPLY=( $(compgen -W "${serial_list}" -- ${cur}) )
return 0
;;
*)
return 0
;;
esac
;;
machine-remove)
case ${COMP_CWORD} in
2)
......
......@@ -28,7 +28,8 @@ usage (){
echo " machine-ipmi-reboot-on-live <machine_serial>"
echo " machine-install-os <machine_serial>"
echo " machine-install-log <machine_serial>"
echo " machine-set-ipmi <serial> <use-ipmi:yes/no> <ipmi-ip-addr> <ipmi-port> <ipmi-username> <ipmi-password>"
echo " machine-set-ipmi [--do-ipmitool-cmds] [--ipmi-defgw GATEWAY] [--ipmi-netmask NETMASK] <serial> <use-ipmi:yes/no> <ipmi-ip-addr> <ipmi-port> <ipmi-username> <ipmi-password>"
echo " machine-console <serial>"
echo ""
echo " network-list"
echo " network-set <network-name> [--cidr MASK] [--iface1 IFDEFINITION] [--iface2 IFDEFINITION] [--ip IPv4] [--is-public yes/no] [--location location-name] [--mtu MTU] [--role ROLE] [--vlan VLAN_NUM] [--bridge-name NAME]"
......@@ -293,6 +294,12 @@ else
"machine-install-log")
echo -n ""
;;
"machine-set-ipmi")
echo -n ""
;;
"machine-console")
echo -n ""
;;
"swift-calculate-ring")
echo -n ""
;;
......@@ -363,10 +370,28 @@ case "${ACTION}" in
cat ${API_RESPONSE_FILE} | jq -r '.["data"]'
;;
"machine-set-ipmi")
ocicli_call "action=machine_set_ipmi&serial=${1}&ipmi_use=${2}&ipmi_addr=${3}&ipmi_port=${4}&ipmi_username=${5}&ipmi_password=${6}"
ocicli_display_status
# Prototype: machine-set-ipmi [--do-ipmitool-cmds] [--ipmi-defgw GATEWAY] [--ipmi-netmask NETMASK] <serial> <use-ipmi:yes/no> <ipmi-ip-addr> <ipmi-port> <ipmi-username> <ipmi-password>
if [ "${1}" = "--do-ipmitool-cmds" ] ; then
MORE_PARAMS="&perform_ipmitool_cmd=yes";
shift
if [ "${1}" = "--ipmi-defgw" ] ; then
MORE_PARAMS="${MORE_PARAMS}&ipmi_default_gw=${2}"
shift
shift
fi
if [ "${1}" = "--ipmi-netmask" ] ; then
MORE_PARAMS="${MORE_PARAMS}&ipmi_netmask=${2}"
shift
shift
fi
fi
ocicli_call "action=machine_set_ipmi&serial=${1}&ipmi_use=${2}&ipmi_addr=${3}&ipmi_port=${4}&ipmi_username=${5}&ipmi_password=${6}${MORE_PARAMS}"
cat ${API_RESPONSE_FILE} | jq -r '.["message"]'
;;
"machine-console")
ocicli_call "action=ipmi_show_cmd_console&serial=${1}"
cat ${API_RESPONSE_FILE} | jq -r '.["message"]'
;;
"location-list")
ocicli_location_list
;;
......
......@@ -2622,8 +2622,8 @@ function api_actions($con,$conf){
$json["message"] = "No machine with serial $safe_machine_serial in database.";
return $json;
}
$a = mysqli_fetch_array($r);
$safe_machine_id = $a["id"];
$machine = mysqli_fetch_array($r);
$safe_machine_id = $machine["id"];
if(!isset($_REQUEST["ipmi_use"])){
$json["status"] = "error";
......@@ -2645,6 +2645,22 @@ function api_actions($con,$conf){
return $json;
}
}
if(isset($_REQUEST["ipmi_default_gw"])){
$safe_ipmi_default_gw = safe_ipv4("ipmi_default_gw");
if($safe_ipmi_default_gw === FALSE){
$json["status"] = "error";
$json["message"] = "IPMI default gw in wrong format.";
return $json;
}
}
if(isset($_REQUEST["ipmi_netmask"])){
$safe_ipmi_netmask = safe_ipv4("ipmi_netmask");
if($safe_ipmi_netmask === FALSE){
$json["status"] = "error";
$json["message"] = "IPMI netmask in wrong format.";
return $json;
}
}
$safe_ipmi_port = safe_int("ipmi_port");
if($safe_ipmi_port === FALSE){
$out .= "IPMI port in wrong format.";
......@@ -2662,6 +2678,43 @@ function api_actions($con,$conf){
$json["message"] = "IPMI password in wrong format.";
return $json;
}
if(isset($_REQUEST["perform_ipmitool_cmd"]) && $_REQUEST["perform_ipmitool_cmd"] == "yes"){
// Set the username
$cmd = "ipmitool user set name 2 " . $safe_ipmi_username;
$json["message"] .= "\n$cmd";
// echo $cmd . "\n";
send_ssh_cmd($conf, $con, $machine["ipaddr"], $cmd);
// Set the password
$cmd = "ipmitool user set password 2 " . $safe_ipmi_password;
$json["message"] .= "\n$cmd";
// echo $cmd . "\n";
send_ssh_cmd($conf, $con, $machine["ipaddr"], $cmd);
// Set DHCP off
$cmd = "ipmitool lan set 1 ipsrc static";
$json["message"] .= "\n$cmd";
// echo $cmd . "\n";
send_ssh_cmd($conf, $con, $machine["ipaddr"], $cmd);
// Set the IP address
$cmd = "ipmitool lan set 1 ipaddr " . $safe_ipmi_addr;
$json["message"] .= "\n$cmd";
// echo $cmd . "\n";
send_ssh_cmd($conf, $con, $machine["ipaddr"], $cmd);
// Set the default GW
$cmd = "ipmitool lan set 1 defgw ipaddr " . $safe_ipmi_default_gw;
$json["message"] .= "\n$cmd";
// echo $cmd . "\n";
send_ssh_cmd($conf, $con, $machine["ipaddr"], $cmd);
// Set the default GW
$cmd = "ipmitool lan set 1 netmask " . $safe_ipmi_netmask;
$json["message"] .= "\n$cmd";
// echo $cmd . "\n";
send_ssh_cmd($conf, $con, $machine["ipaddr"], $cmd);
$cmd = "ipmitool lan print 1";
$json["message"] .= "\n$cmd";
$out = send_ssh_cmd($conf, $con, $machine["ipaddr"], $cmd);
$json["message"] .= "\n$out";
}
$q = "UPDATE machines SET ipmi_use='yes', ipmi_addr='$safe_ipmi_addr', ipmi_port='$safe_ipmi_port', ipmi_username='$safe_ipmi_username', ipmi_password='$safe_ipmi_password' WHERE id='$safe_machine_id'";
$r = mysqli_query($con, $q);
if($r === FALSE){
......@@ -2671,6 +2724,31 @@ function api_actions($con,$conf){
}
return $json;
break;
case "ipmi_show_cmd_console":
$safe_machine_serial = safe_serial("serial");
if($safe_machine_serial === FALSE){
$json["status"] = "error";
$json["message"] = "Wrong machine serial number format.";
return $json;
}
$q = "SELECT * FROM machines WHERE serial='$safe_machine_serial'";
$r = mysqli_query($con, $q);
if($r === FALSE){
$json["status"] = "error";
$json["message"] = mysqli_error($con);
return $json;
}
$n = mysqli_num_rows($r);
if($n != 1){
$json["status"] = "error";
$json["message"] = "No machine with serial $safe_machine_serial in database.";
return $json;
}
$machine = mysqli_fetch_array($r);
$cmd = "ipmitool -I lanplus -H " . $machine["ipmi_addr"] ." -U " . $machine["ipmi_username"] ." -P " . $machine["ipmi_password"] . " sol activate";
$json["message"] .= "\n$cmd";
return $json;
break;
case "ipmi_reboot_on_hdd":
$safe_machine_serial = safe_serial("serial");
if($safe_machine_serial === FALSE){
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment