diff --git a/heartbeat/SysInfo.in b/heartbeat/SysInfo.in index c57b7b661..8a268d760 100644 --- a/heartbeat/SysInfo.in +++ b/heartbeat/SysInfo.in @@ -1,372 +1,372 @@ #!@BASH_SHELL@ # # # SysInfo OCF Resource Agent # It records (in the CIB) various attributes of a node # # Copyright (c) 2004 SUSE LINUX AG, Lars Marowsky-Bree # All Rights Reserved. # # This program is free software; you can redistribute it and/or modify # it under the terms of version 2 of the GNU General Public License as # published by the Free Software Foundation. # # This program is distributed in the hope that it would be useful, but # WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. # # Further, this software is distributed without any warranty that it is # free of the rightful claim of any third person regarding infringement # or the like. Any license provided herein, whether implied or # otherwise, applies only to this software file. Patent licenses, if # any, provided herein do not apply to combinations of this program with # other software, or any other product whatsoever. # # You should have received a copy of the GNU General Public License # along with this program; if not, write the Free Software Foundation, # Inc., 59 Temple Place - Suite 330, Boston MA 02111-1307, USA. # ####################################################################### # Initialization: : ${OCF_FUNCTIONS_DIR=${OCF_ROOT}/lib/heartbeat} . ${OCF_FUNCTIONS_DIR}/ocf-shellfuncs # Parameter defaults OCF_RESKEY_pidfile_default="$HA_RSCTMP/SysInfo-${OCF_RESOURCE_INSTANCE}" OCF_RESKEY_delay_default="0s" OCF_RESKEY_clone_default="0" : ${OCF_RESKEY_pidfile=${OCF_RESKEY_pidfile_default}} : ${OCF_RESKEY_delay=${OCF_RESKEY_delay_default}} : ${OCF_RESKEY_clone=${OCF_RESKEY_clone_default}} ####################################################################### meta_data() { cat < 1.0 This is a SysInfo Resource Agent. It records (in the CIB) various attributes of a node Sample Linux output: arch: i686 os: Linux-2.4.26-gentoo-r14 free_swap: 1999 cpu_info: Intel(R) Celeron(R) CPU 2.40GHz cpu_speed: 4771.02 cpu_cores: 1 cpu_load: 0.00 ram_total: 513 ram_free: 117 root_free: 2.4 Sample Darwin output: arch: i386 os: Darwin-8.6.2 cpu_info: Intel Core Duo cpu_speed: 2.16 cpu_cores: 2 cpu_load: 0.18 ram_total: 2016 ram_free: 787 root_free: 13 Units: free_swap: Mb ram_*: Mb root_free: Gb cpu_speed (Linux): bogomips cpu_speed (Darwin): Ghz Records various node attributes in the CIB PID file PID file Interval to allow values to stabilize Dampening Delay END } ####################################################################### UpdateStat() { name=$1; shift value="$*" echo -e "$name:\t$value" - ${HA_SBIN_DIR}/attrd_updater ${OCF_RESKEY_delay} -S status -n $name -v "$value" + ${HA_SBIN_DIR}/attrd_updater ${OCF_RESKEY_delay} -n $name -v "$value" } SysInfoStats() { UpdateStat arch "`uname -m`" UpdateStat os "`uname -s`-`uname -r`" case `uname -s` in "Darwin") mem=`top -l 1 | grep Mem: | awk '{print $10}'` mem_used=`top -l 1 | grep Mem: | awk '{print $8}'` mem=`SysInfo_mem_units $mem` mem_used=`SysInfo_mem_units $mem_used` mem_total=`expr $mem_used + $mem` cpu_type=`system_profiler SPHardwareDataType | grep "CPU Type:"` cpu_type=${cpu_type/*: /} cpu_speed=`system_profiler SPHardwareDataType | grep "CPU Speed:" | awk '{print $3}'` cpu_cores=`system_profiler SPHardwareDataType | grep "Number Of"` cpu_cores=${cpu_cores/*: /} ;; "Linux") if [ -f /proc/cpuinfo ]; then cpu_type=`grep "model name" /proc/cpuinfo | head -n 1` cpu_type=${cpu_type/*: /} cpu_speed=`grep "bogomips" /proc/cpuinfo | head -n 1` cpu_speed=${cpu_speed/*: /} cpu_cores=`grep "^processor" /proc/cpuinfo | wc -l` fi if [ -f /proc/meminfo ]; then # meminfo results are in kB mem=`grep "SwapFree" /proc/meminfo | awk '{print $2"k"}'` if [ ! -z $mem ]; then UpdateStat free_swap `SysInfo_mem_units $mem` fi mem=`grep "Inactive" /proc/meminfo | awk '{print $2"k"}'` mem_total=`grep "MemTotal" /proc/meminfo | awk '{print $2"k"}'` else mem=`top -n 1 | grep Mem: | awk '{print $7}'` fi ;; *) esac if [ x != x"$cpu_type" ]; then UpdateStat cpu_info "$cpu_type" fi if [ x != x"$cpu_speed" ]; then UpdateStat cpu_speed "$cpu_speed" fi if [ x != x"$cpu_cores" ]; then UpdateStat cpu_cores "$cpu_cores" fi loads=`uptime` load15=`echo ${loads} | awk '{print $10}'` UpdateStat cpu_load $load15 if [ ! -z "$mem" ]; then # Massage the memory values UpdateStat ram_total `SysInfo_mem_units $mem_total` UpdateStat ram_free `SysInfo_mem_units $mem` fi # Portability notes: # o df: -h flag not available on Solaris 8. (OK on 9, 10, ...) #FIXME# # o tail: explicit "-n" not available in Solaris; instead simplify # 'tail -n ' to the equivalent 'tail -'. disk=`df -h / | tail -1 | awk '{print $4}'` if [ x != x"$disk" ]; then UpdateStat root_free `SysInfo_hdd_units $disk` fi } SysInfo_mem_units() { mem=$1 if [ -z $1 ]; then return fi memlen=`expr ${#mem} - 1` memlen_alt=`expr ${#mem} - 2` if [ ${mem:$memlen:1} = "G" ]; then mem="${mem:0:$memlen}" if [ $mem != ${mem/./} ]; then mem_before=${mem/.*/} mem_after=${mem/*./} mem=$[mem_before*1024] if [ ${#mem_after} = 0 ]; then : elif [ ${#mem_after} = 1 ]; then mem=$[mem+100*$mem_after] elif [ ${#mem_after} = 2 ]; then mem=$[mem+10*$mem_after] elif [ ${#mem_after} = 3 ]; then mem=$[mem+$mem_after] else mem_after=${mem_after:0:3} mem=$[mem+$mem_after] fi fi elif [ ${mem:$memlen:1} = "M" ]; then mem=${mem/.*/} mem="${mem:0:$memlen}" elif [ ${mem:$memlen:1} = "k" ]; then mem="${mem:0:$memlen}" mem=${mem/.*/} mem=`expr $mem / 1024` elif [ ${mem:$memlen_alt:2} = "kB" ]; then mem="${mem:0:$memlen_alt}" mem=${mem/.*/} mem=`expr $mem / 1024` elif [ ${mem:$memlen_alt:2} = "Mb" ]; then mem="${mem:0:$memlen_alt}" mem=${mem/.*/} elif [ ${mem:$memlen_alt:2} = "MB" ]; then mem="${mem:0:$memlen_alt}" mem=${mem/.*/} fi # Round to the next multiple of 50 memlen=`expr ${#mem} - 2` mem_round="${mem:$memlen:2}" if [ x$mem_round = x ]; then : elif [ $mem_round = "00" ]; then : else mem_round=`echo $mem_round | sed 's/^0//'` if [ $mem_round -lt "50" ]; then mem=$[mem+50] mem=$[mem-$mem_round] else mem=$[mem+100] mem=$[mem-$mem_round] fi fi echo $mem } SysInfo_hdd_units() { disk=$1 disklen=`expr ${#disk} - 1` disklen_alt=`expr ${#disk} - 2` if [ ${disk:$disklen:1} = "G" ]; then disk="${disk:0:$disklen}" elif [ ${disk:$disklen:1} = "M" ]; then disk="${disk:0:$disklen}" disk=${disk/.*/} disk=`expr $disk / 1024` elif [ ${disk:$disklen:1} = "k" ]; then disk="${disk:0:$disklen}" disk=${disk/.*/} disk=`expr $disk / 1048576` elif [ ${disk:$disklen_alt:2} = "kB" ]; then disk="${disk:0:$disklen_alt}" disk=${disk/.*/} disk=`expr $disk / 1048576` elif [ ${disk:$disklen_alt:2} = "Mb" ]; then disk="${disk:0:$disklen_alt}" disk=${disk/.*/} disk=`expr $disk / 1024` elif [ ${disk:$disklen_alt:2} = "MB" ]; then disk="${disk:0:$disklen_alt}" disk=${disk/.*/} disk=`expr $disk / 1024` fi echo $disk } SysInfo_usage() { cat < $OCF_RESKEY_pidfile SysInfoStats exit $OCF_SUCCESS } SysInfo_stop() { rm $OCF_RESKEY_pidfile exit $OCF_SUCCESS } SysInfo_monitor() { if [ -f $OCF_RESKEY_pidfile ]; then clone=`cat $OCF_RESKEY_pidfile` fi if [ x$clone = x ]; then rm $OCF_RESKEY_pidfile exit $OCF_NOT_RUNNING elif [ $clone = $OCF_RESKEY_clone ]; then SysInfoStats exit $OCF_SUCCESS elif [ x$OCF_RESKEY_CRM_meta_globally_unique = xtrue ] || [ x$OCF_RESKEY_CRM_meta_globally_unique = xTrue ] || [ x$OCF_RESKEY_CRM_meta_globally_unique = xyes ] || [ x$OCF_RESKEY_CRM_meta_globally_unique = xYes ]; then SysInfoStats exit $OCF_SUCCESS fi exit $OCF_NOT_RUNNING } SysInfo_validate() { return $OCF_SUCCESS } if [ $# -ne 1 ]; then SysInfo_usage exit $OCF_ERR_ARGS fi if [ x != x${OCF_RESKEY_delay} ]; then OCF_RESKEY_delay="-d ${OCF_RESKEY_delay}" fi case $__OCF_ACTION in meta-data) meta_data exit $OCF_SUCCESS ;; start) SysInfo_start ;; stop) SysInfo_stop ;; monitor) SysInfo_monitor ;; validate-all) SysInfo_validate ;; usage|help) SysInfo_usage exit $OCF_SUCCESS ;; *) SysInfo_usage exit $OCF_ERR_UNIMPLEMENTED ;; esac exit $? diff --git a/heartbeat/lxd-info.in b/heartbeat/lxd-info.in index f9fb44ac4..88b15e57e 100644 --- a/heartbeat/lxd-info.in +++ b/heartbeat/lxd-info.in @@ -1,156 +1,156 @@ #!@BASH_SHELL@ # # # LXD Registration Service OCF Resource Agent # It records (in the CIB) various attributes of a node # # Copyright (c) 2017 Mathieu Grzybek # All Rights Reserved. # # This program is free software; you can redistribute it and/or modify # it under the terms of version 2 of the GNU General Public License as # published by the Free Software Foundation. # # This program is distributed in the hope that it would be useful, but # WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. # # Further, this software is distributed without any warranty that it is # free of the rightful claim of any third person regarding infringement # or the like. Any license provided herein, whether implied or # otherwise, applies only to this software file. Patent licenses, if # any, provided herein do not apply to combinations of this program with # other software, or any other product whatsoever. # # You should have received a copy of the GNU General Public License # along with this program; if not, write the Free Software Foundation, # Inc., 59 Temple Place - Suite 330, Boston MA 02111-1307, USA. # ####################################################################### # Initialization: : ${OCF_FUNCTIONS_DIR=${OCF_ROOT}/lib/heartbeat} . ${OCF_FUNCTIONS_DIR}/ocf-shellfuncs # Parameter defaults OCF_RESKEY_pidfile_default="$HA_RSCTMP/LXDInfo-${OCF_RESOURCE_INSTANCE}" OCF_RESKEY_delay_default="0s" OCF_RESKEY_clone_default="0" : ${OCF_RESKEY_pidfile=${OCF_RESKEY_pidfile_default}} : ${OCF_RESKEY_delay=${OCF_RESKEY_delay_default}} : ${OCF_RESKEY_clone=${OCF_RESKEY_clone_default}} ####################################################################### meta_data() { cat < 1.0 This is a LXD Registration Service Resource Agent. It records (in the CIB) attributes about the number of running LXD containers running on the node. Sample output: lxd_containers: 5 Records various node attributes in the CIB PID file PID file Interval to allow values to stabilize Dampening Delay END } ####################################################################### LXDInfoStats() { value=$(lxc list|grep -ci RUNNING) echo -e "lxd_containers:\t$value" - ${HA_SBIN_DIR}/attrd_updater ${OCF_RESKEY_delay} -S status -n lxd_containers -v $value + ${HA_SBIN_DIR}/attrd_updater ${OCF_RESKEY_delay} -n lxd_containers -v $value } LXDInfo_usage() { cat < $OCF_RESKEY_pidfile LXDInfoStats exit $OCF_SUCCESS } LXDInfo_stop() { rm -f $OCF_RESKEY_pidfile - ${HA_SBIN_DIR}/attrd_updater ${OCF_RESKEY_delay} -D -S state -n lxd_containers + ${HA_SBIN_DIR}/attrd_updater ${OCF_RESKEY_delay} -D -n lxd_containers exit $OCF_SUCCESS } LXDInfo_monitor() { if [ -f "$OCF_RESKEY_pidfile" ] ; then LXDInfoStats exit $OCF_RUNNING fi exit $OCF_NOT_RUNNING } LXDInfo_validate() { return $OCF_SUCCESS } if [ $# -ne 1 ]; then LXDInfo_usage exit $OCF_ERR_ARGS fi if [ x != x${OCF_RESKEY_delay} ]; then OCF_RESKEY_delay="-d ${OCF_RESKEY_delay}" fi case $__OCF_ACTION in meta-data) meta_data exit $OCF_SUCCESS ;; start) LXDInfo_start ;; stop) LXDInfo_stop ;; monitor) LXDInfo_monitor ;; validate-all) LXDInfo_validate ;; usage|help) LXDInfo_usage exit $OCF_SUCCESS ;; *) LXDInfo_usage exit $OCF_ERR_UNIMPLEMENTED ;; esac exit $? diff --git a/heartbeat/machine-info.in b/heartbeat/machine-info.in index bfa7ce5fc..6bd328aa8 100644 --- a/heartbeat/machine-info.in +++ b/heartbeat/machine-info.in @@ -1,157 +1,157 @@ #!@BASH_SHELL@ # # # Virtual Machine and Container Registration Service OCF Resource Agent # It records (in the CIB) various attributes of a node # # Copyright (c) 2017 Mathieu Grzybek # All Rights Reserved. # # This program is free software; you can redistribute it and/or modify # it under the terms of version 2 of the GNU General Public License as # published by the Free Software Foundation. # # This program is distributed in the hope that it would be useful, but # WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. # # Further, this software is distributed without any warranty that it is # free of the rightful claim of any third person regarding infringement # or the like. Any license provided herein, whether implied or # otherwise, applies only to this software file. Patent licenses, if # any, provided herein do not apply to combinations of this program with # other software, or any other product whatsoever. # # You should have received a copy of the GNU General Public License # along with this program; if not, write the Free Software Foundation, # Inc., 59 Temple Place - Suite 330, Boston MA 02111-1307, USA. # ####################################################################### # Initialization: : ${OCF_FUNCTIONS_DIR=${OCF_ROOT}/lib/heartbeat} . ${OCF_FUNCTIONS_DIR}/ocf-shellfuncs # Parameter defaults OCF_RESKEY_pidfile_default="$HA_RSCTMP/MachineInfo-${OCF_RESOURCE_INSTANCE}" OCF_RESKEY_delay_default="0s" OCF_RESKEY_clone_default="0" : ${OCF_RESKEY_pidfile=${OCF_RESKEY_pidfile_default}} : ${OCF_RESKEY_delay=${OCF_RESKEY_delay_default}} : ${OCF_RESKEY_clone=${OCF_RESKEY_clone_default}} ####################################################################### meta_data() { cat < 1.0 This is a Virtual Machine and Container Registration Service Resource Agent. It records (in the CIB) attributes about the number of running virtual machines and containers running on the node. It uses systemd machinectl. Sample output: machines: 5 Records various node attributes in the CIB PID file PID file Interval to allow values to stabilize Dampening Delay END } ####################################################################### MachineInfoStats() { value=$(machinectl|awk '/machines listed/ {print $1}') echo -e "machines:\t$value" - ${HA_SBIN_DIR}/attrd_updater ${OCF_RESKEY_delay} -S status -n machines -v $value + ${HA_SBIN_DIR}/attrd_updater ${OCF_RESKEY_delay} -n machines -v $value } MachineInfo_usage() { cat < $OCF_RESKEY_pidfile MachineInfoStats exit $OCF_SUCCESS } MachineInfo_stop() { rm -f $OCF_RESKEY_pidfile - ${HA_SBIN_DIR}/attrd_updater ${OCF_RESKEY_delay} -D -S state -n machines + ${HA_SBIN_DIR}/attrd_updater ${OCF_RESKEY_delay} -D -n machines exit $OCF_SUCCESS } MachineInfo_monitor() { if [ -f "$OCF_RESKEY_pidfile" ] ; then MachineInfoStats exit $OCF_RUNNING fi exit $OCF_NOT_RUNNING } MachineInfo_validate() { return $OCF_SUCCESS } if [ $# -ne 1 ]; then MachineInfo_usage exit $OCF_ERR_ARGS fi if [ x != x${OCF_RESKEY_delay} ]; then OCF_RESKEY_delay="-d ${OCF_RESKEY_delay}" fi case $__OCF_ACTION in meta-data) meta_data exit $OCF_SUCCESS ;; start) MachineInfo_start ;; stop) MachineInfo_stop ;; monitor) MachineInfo_monitor ;; validate-all) MachineInfo_validate ;; usage|help) MachineInfo_usage exit $OCF_SUCCESS ;; *) MachineInfo_usage exit $OCF_ERR_UNIMPLEMENTED ;; esac exit $? diff --git a/heartbeat/openstack-floating-ip b/heartbeat/openstack-floating-ip index 7317f19a8..a7c072844 100755 --- a/heartbeat/openstack-floating-ip +++ b/heartbeat/openstack-floating-ip @@ -1,257 +1,257 @@ #!/bin/sh # # # OCF resource agent to move a floating address in an Openstack tenant. # # Copyright (c) 2018 Mathieu GRZYBEK # Based on code of Markus Guertler # All Rights Reserved. # # This program is free software; you can redistribute it and/or modify # it under the terms of version 2 of the GNU General Public License as # published by the Free Software Foundation. # # This program is distributed in the hope that it would be useful, but # WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. # # Further, this software is distributed without any warranty that it is # free of the rightful claim of any third person regarding infringement # or the like. Any license provided herein, whether implied or # otherwise, applies only to this software file. Patent licenses, if # any, provided herein do not apply to combinations of this program with # other software, or any other product whatsoever. # # You should have received a copy of the GNU General Public License # along with this program; if not, write the Free Software Foundation, # Inc., 59 Temple Place - Suite 330, Boston MA 02111-1307, USA. # ####################################################################### # Initialization: : ${OCF_FUNCTIONS_DIR=${OCF_ROOT}/lib/heartbeat} . ${OCF_FUNCTIONS_DIR}/ocf-shellfuncs . ${OCF_FUNCTIONS_DIR}/openstack-common.sh # Defaults ####################################################################### USAGE="usage: $0 {start|stop|status|meta-data}"; ############################################################################### ############################################################################### # # Functions # ############################################################################### metadata() { cat < 1.0 Resource Agent to move a floating IP address from an instance to another one. It relies on attributes given by openstack-info resource agent (openstack_ports, openstack_id attributes). The attribute called "openstack_floating_ip" is updated. Move a floating IP END common_meta_data cat < Floating IP Identifier. IP ID Subnet Identifier to use to attach the address. Subnet ID END } osflip_validate() { local result check_binary "$OCF_RESKEY_openstackcli" get_config result=$(run_openstackcli "floating ip list") if ! echo "$result" | grep -q $OCF_RESKEY_ip_id; then ocf_exit_reason "ip-id $OCF_RESKEY_ip_id not found" return $OCF_ERR_CONFIGURED fi ${HA_SBIN_DIR}/attrd_updater --query -n openstack_ports -N $(crm_node -n) > /dev/null 2>&1 if [ $? -ne 0 ] && ! ocf_is_probe; then ocf_log warn "attr_updater failed to get openstack_ports attribute of node $OCF_RESOURCE_INSTANCE" return $OCF_ERR_GENERIC fi return $OCF_SUCCESS } osflip_monitor() { local result local floating_ip local node_port_ids local port local buffer node_port_ids=$(${HA_SBIN_DIR}/attrd_updater --query -n openstack_ports -N $(crm_node -n) \ | awk -F= '{gsub("\"","");print $NF}' \ | tr ',' ' ' \ | awk '{gsub("[^ ]*:", "");print}') # Is the IP active and attached? result=$(run_openstackcli "floating ip show \ --column port_id --column floating_ip_address \ --format yaml \ $OCF_RESKEY_ip_id") for port in $node_port_ids ; do if echo "$result" | grep -q $port ; then floating_ip=$(echo "$result" | awk '/floating_ip_address/ {print $2}') - ${HA_SBIN_DIR}/attrd_updater ${OCF_RESKEY_delay} -S status -n openstack_floating_ip -v $floating_ip + ${HA_SBIN_DIR}/attrd_updater ${OCF_RESKEY_delay} -n openstack_floating_ip -v $floating_ip return $OCF_SUCCESS fi done - ${HA_SBIN_DIR}/attrd_updater ${OCF_RESKEY_delay} -D -S state -n openstack_floating_ip + ${HA_SBIN_DIR}/attrd_updater ${OCF_RESKEY_delay} -D -n openstack_floating_ip ocf_log warn "$OCF_RESKEY_ip_id is not attached to any fixed address" return $OCF_NOT_RUNNING } osflip_stop() { ocf_log info "Bringing down IP address $OCF_RESKEY_ip_id" osflip_monitor if [ $? = $OCF_NOT_RUNNING ]; then ocf_log info "Address $OCF_RESKEY_ip_id already down" return $OCF_SUCCESS fi if ! run_openstackcli "floating ip unset --port $OCF_RESKEY_ip_id"; then return $OCF_ERR_GENERIC fi osflip_monitor if [ $? != $OCF_NOT_RUNNING ]; then ocf_log error "Couldn't unset IP address $OCF_RESKEY_ip_id." return $OCF_ERR_GENERIC fi ocf_log info "Successfully brought down $OCF_RESKEY_ip_id" return $OCF_SUCCESS } osflip_start() { local node_port_id local node_port_ids osflip_monitor if [ $? = $OCF_SUCCESS ]; then ocf_log info "$OCF_RESKEY_ip_id already started" return $OCF_SUCCESS fi # Get port_id from subnet_id node_port_ids=$(${HA_SBIN_DIR}/attrd_updater --query -n openstack_ports -N $(crm_node -n) \ | awk '{gsub("value=","") ; gsub("\"","") ; print $NF}') node_port_id=$(echo $node_port_ids \ | tr ',' '\n' \ | awk -F: "/$OCF_RESKEY_subnet_id/ {print \$2}") ocf_log info "Moving IP address $OCF_RESKEY_ip_id to port ID $node_port_id" run_openstackcli "floating ip set --port $node_port_id $OCF_RESKEY_ip_id" if [ $? != $OCF_SUCCESS ]; then ocf_log error "$OCF_RESKEY_ip_id Cannot be set to port $node_port_id" return $OCF_ERR_GENERIC fi osflip_monitor if [ $? != $OCF_SUCCESS ]; then ocf_log error "$OCF_RESKEY_ip_id Cannot be set to port $node_port_id" return $OCF_ERR_GENERIC fi ocf_log info "Successfully brought up $OCF_RESKEY_ip_id" return $OCF_SUCCESS } ############################################################################### # # MAIN # ############################################################################### case $__OCF_ACTION in meta-data) metadata exit $OCF_SUCCESS ;; usage|help) echo $USAGE exit $OCF_SUCCESS ;; esac if ! ocf_is_root; then ocf_log err "You must be root for $__OCF_ACTION operation." exit $OCF_ERR_PERM fi case $__OCF_ACTION in start) osflip_validate || exit $? osflip_start;; stop) osflip_validate || exit $? osflip_stop;; monitor) osflip_validate || exit $? osflip_monitor;; validate-all) osflip_validate ;; *) echo $USAGE exit $OCF_ERR_UNIMPLEMENTED ;; esac exit $? diff --git a/heartbeat/openstack-virtual-ip b/heartbeat/openstack-virtual-ip index 361357d55..e54926a09 100755 --- a/heartbeat/openstack-virtual-ip +++ b/heartbeat/openstack-virtual-ip @@ -1,258 +1,258 @@ #!/bin/sh # # # OCF resource agent to move a virtual address in an Openstack tenant. # # Copyright (c) 2018 Mathieu GRZYBEK # Based on code of Markus Guertler # All Rights Reserved. # # This program is free software; you can redistribute it and/or modify # it under the terms of version 2 of the GNU General Public License as # published by the Free Software Foundation. # # This program is distributed in the hope that it would be useful, but # WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. # # Further, this software is distributed without any warranty that it is # free of the rightful claim of any third person regarding infringement # or the like. Any license provided herein, whether implied or # otherwise, applies only to this software file. Patent licenses, if # any, provided herein do not apply to combinations of this program with # other software, or any other product whatsoever. # # You should have received a copy of the GNU General Public License # along with this program; if not, write the Free Software Foundation, # Inc., 59 Temple Place - Suite 330, Boston MA 02111-1307, USA. # ####################################################################### # Initialization: : ${OCF_FUNCTIONS_DIR=${OCF_ROOT}/lib/heartbeat} . ${OCF_FUNCTIONS_DIR}/ocf-shellfuncs . ${OCF_FUNCTIONS_DIR}/openstack-common.sh # Defaults ####################################################################### USAGE="usage: $0 {start|stop|status|meta-data}"; ############################################################################### ############################################################################### # # Functions # ############################################################################### metadata() { cat < 1.0 Resource Agent to move a virtual IP address from an instance to another one by adding an allowed-address pair associated with an instance port. It relies on attributes given by openstack-info resource agent (openstack_ports, openstack_id attributes). The attribute called "openstack_virtual_ip" is updated. Move a virtual IP END common_meta_data cat < Virtual IP Address. IP Address Subnet Identifier to use to attach the address. Subnet ID END } osvip_port_id() { # Get port_id from subnet_id node_port_ids=$(${HA_SBIN_DIR}/attrd_updater --query -n openstack_ports -N $(crm_node -n) \ | awk '{gsub("value=","") ; gsub("\"","") ; print $NF}') node_port_id=$(echo $node_port_ids \ | tr ',' '\n' \ | awk -F: "/$OCF_RESKEY_subnet_id/ {print \$2}") echo ${node_port_id} } osvip_validate() { check_binary "$OCF_RESKEY_openstackcli" get_config ${HA_SBIN_DIR}/attrd_updater --query -n openstack_ports -N $(crm_node -n) > /dev/null 2>&1 if [ $? -ne 0 ] && ! ocf_is_probe; then ocf_log warn "attr_updater failed to get openstack_ports attribute of node $OCF_RESOURCE_INSTANCE" return $OCF_ERR_GENERIC fi return $OCF_SUCCESS } osvip_monitor() { local result node_port_id=$(osvip_port_id) result=$(run_openstackcli "port show \ --format value \ --column allowed_address_pairs \ ${node_port_id}") if echo "$result" | grep -q "$OCF_RESKEY_ip"; then - ${HA_SBIN_DIR}/attrd_updater ${OCF_RESKEY_delay} -S status -n openstack_virtual_ip -v $OCF_RESKEY_ip + ${HA_SBIN_DIR}/attrd_updater ${OCF_RESKEY_delay} -n openstack_virtual_ip -v $OCF_RESKEY_ip return $OCF_SUCCESS fi - ${HA_SBIN_DIR}/attrd_updater ${OCF_RESKEY_delay} -D -S state -n openstack_virtual_ip + ${HA_SBIN_DIR}/attrd_updater ${OCF_RESKEY_delay} -D -n openstack_virtual_ip ocf_log warn "$OCF_RESKEY_ip is not attached to any fixed address" return $OCF_NOT_RUNNING } osvip_stop() { node_port_id=$(osvip_port_id) ocf_log info "Bringing down IP address $OCF_RESKEY_ip" osvip_monitor if [ $? = $OCF_NOT_RUNNING ]; then ocf_log info "Address $OCF_RESKEY_ip already down" return $OCF_SUCCESS fi mac_address=$(run_openstackcli "port show \ --format value \ --column mac_address \ $node_port_id") echo "${mac_address}" | grep -q -P "^([0-9a-f]{2}:){5}[0-9a-f]{2}$" if [ $? -ne 0 ]; then ocf_log error "MAC address '${mac_address}' is not valid." return $OCF_ERR_GENERIC fi if ! run_openstackcli "port unset \ --allowed-address \ ip-address=$OCF_RESKEY_ip,mac-address=${mac_address} \ $node_port_id"; then return $OCF_ERR_GENERIC fi osvip_monitor if [ $? != $OCF_NOT_RUNNING ]; then ocf_log error "Couldn't unset IP address $OCF_RESKEY_ip." return $OCF_ERR_GENERIC fi ocf_log info "Successfully brought down $OCF_RESKEY_ip" return $OCF_SUCCESS } osvip_start() { node_port_id=$(osvip_port_id) osvip_monitor if [ $? = $OCF_SUCCESS ]; then ocf_log info "$OCF_RESKEY_ip already started" return $OCF_SUCCESS fi ocf_log info "Moving IP address $OCF_RESKEY_ip to port ID $node_port_id" run_openstackcli "port set \ --allowed-address ip-address=$OCF_RESKEY_ip \ $node_port_id" if [ $? != $OCF_SUCCESS ]; then ocf_log error "$OCF_RESKEY_ip Cannot be set to port $node_port_id" return $OCF_ERR_GENERIC fi osvip_monitor if [ $? != $OCF_SUCCESS ]; then ocf_log error "$OCF_RESKEY_ip Cannot be set to port $node_port_id" return $OCF_ERR_GENERIC fi ocf_log info "Successfully brought up $OCF_RESKEY_ip" return $OCF_SUCCESS } ############################################################################### # # MAIN # ############################################################################### case $__OCF_ACTION in meta-data) metadata exit $OCF_SUCCESS ;; usage|help) echo $USAGE exit $OCF_SUCCESS ;; esac if ! ocf_is_root; then ocf_log err "You must be root for $__OCF_ACTION operation." exit $OCF_ERR_PERM fi case $__OCF_ACTION in start) osvip_validate || exit $? osvip_start;; stop) osvip_validate || exit $? osvip_stop;; monitor) osvip_validate || exit $? osvip_monitor;; validate-all) osvip_validate ;; *) echo $USAGE exit $OCF_ERR_UNIMPLEMENTED ;; esac exit $?