bd998017d5
Create host inventory services (api, conductor and agent) and
python-inventoryclient.
The inventory service collects the host resources and provides a
REST API and client to expose the host resources.
Create plugin for integration with system configuration (sysinv)
service.
This is the initial inventory service infratructure commit.
Puppet configuration, SM integration and host integration with
sysinv(systemconfig) changes are pending and planned to be
delivered in future commits.
Tests Performed:
Verify the changes are inert on config_controller installation
and provisioning.
Puppet and spec changes are required in order to create keystone,
database and activate inventory services.
Unit tests performed (when puppet configuration for keystone, database
is applied):
Trigger host configure_check, configure signals into
systemconfig(sysinv).
Verify python-inventoryclient and api service:
Disks and related storage resources are pending.
inventory host-cpu-list/show
inventory host-device-list/show/modify
inventory host-ethernetport-list/show
inventory host-lldp-neighbor-list
inventory host-lldp-agent-list/show
inventory host-memory-list/show
inventory host-node-list/show
inventory host-port-list/show
Tox Unit tests:
inventory: pep8
python-inventoryclient: py27, pep8, cover, pylint
Change-Id: I744ac0de098608c55b9356abf180cc36601cfb8d
Story: 2002950
Task: 22952
Signed-off-by: John Kung <john.kung@windriver.com>
410 lines
11 KiB
Bash
Executable File
410 lines
11 KiB
Bash
Executable File
#!/bin/sh
|
|
#
|
|
# Copyright (c) 2013-2018 Wind River Systems, Inc.
|
|
#
|
|
# SPDX-License-Identifier: Apache-2.0
|
|
#
|
|
# Purpose: This resource agent manages
|
|
#
|
|
# .... the STX Inventory REST API Service
|
|
#
|
|
#
|
|
# OCF instance parameters:
|
|
# OCF_RESKEY_binary
|
|
# OCF_RESKEY_client_binary
|
|
# OCF_RESKEY_config
|
|
# OCF_RESKEY_os_username
|
|
# OCF_RESKEY_os_tenant_name
|
|
# OCF_RESKEY_os_auth_url
|
|
# OCF_RESKEY_os_password
|
|
# OCF_RESKEY_user
|
|
# OCF_RESKEY_pid
|
|
# OCF_RESKEY_additional_parameters
|
|
#
|
|
# RA Spec:
|
|
#
|
|
# http://www.opencf.org/cgi-bin/viewcvs.cgi/specs/ra/resource-agent-api.txt?rev=HEAD
|
|
#
|
|
#######################################################################
|
|
# Initialization:
|
|
|
|
: ${OCF_FUNCTIONS_DIR=${OCF_ROOT}/lib/heartbeat}
|
|
. ${OCF_FUNCTIONS_DIR}/ocf-shellfuncs
|
|
|
|
process="inventory"
|
|
service="-api"
|
|
binname="${process}${service}"
|
|
|
|
#######################################################################
|
|
|
|
# Fill in some defaults if no values are specified
|
|
OCF_RESKEY_binary_default=${binname}
|
|
OCF_RESKEY_dbg_default="false"
|
|
OCF_RESKEY_user_default="inventory"
|
|
OCF_RESKEY_pid_default="/var/run/${binname}.pid"
|
|
OCF_RESKEY_config_default="/etc/inventory/inventory.conf"
|
|
OCF_RESKEY_client_binary_default="inventory"
|
|
|
|
: ${OCF_RESKEY_binary=${OCF_RESKEY_binary_default}}
|
|
: ${OCF_RESKEY_dbg=${OCF_RESKEY_dbg_default}}
|
|
: ${OCF_RESKEY_user=${OCF_RESKEY_user_default}}
|
|
: ${OCF_RESKEY_pid=${OCF_RESKEY_pid_default}}
|
|
: ${OCF_RESKEY_config=${OCF_RESKEY_config_default}}
|
|
: ${OCF_RESKEY_client_binary=${OCF_RESKEY_client_binary_default}}
|
|
|
|
mydaemon="/usr/bin/${OCF_RESKEY_binary}"
|
|
|
|
#######################################################################
|
|
|
|
usage() {
|
|
cat <<UEND
|
|
|
|
usage: $0 (start|stop|status|reload|monitor|validate-all|meta-data)
|
|
|
|
$0 manages the Platform's Inventory REST API (inventory-api) process as an HA resource
|
|
|
|
The 'start' ..... operation starts the inventory-api service in the active state.
|
|
The 'stop' ...... operation stops the inventory-api service.
|
|
The 'reload' .... operation stops and then starts the inventory-api service.
|
|
The 'status' .... operation checks the status of the inventory-api service.
|
|
The 'monitor' .... operation indicates the in-service status of the inventory-api service.
|
|
The 'validate-all' operation reports whether the parameters are valid.
|
|
The 'meta-data' .. operation reports the inventory's meta-data information.
|
|
|
|
UEND
|
|
}
|
|
|
|
#######################################################################
|
|
|
|
meta_data() {
|
|
if [ ${OCF_RESKEY_dbg} = "true" ] ; then
|
|
ocf_log info "${binname}:meta_data"
|
|
fi
|
|
|
|
cat <<END
|
|
<?xml version="1.0"?>
|
|
<!DOCTYPE resource-agent SYSTEM "ra-api-1.dtd">
|
|
<resource-agent name="inventory">
|
|
<version>1.0</version>
|
|
|
|
<longdesc lang="en">
|
|
This 'inventory-api' is an OCF Compliant Resource Agent that manages start, stop
|
|
and in-service monitoring of the Inventory REST API Process
|
|
</longdesc>
|
|
|
|
<shortdesc lang="en">
|
|
Manages the Inventory REST API (inventory-api) process in the STX Platform.
|
|
</shortdesc>
|
|
|
|
|
|
<parameters>
|
|
|
|
<parameter name="dbg" unique="0" required="0">
|
|
<longdesc lang="en">
|
|
dbg = false ... info, warn and err logs sent to output stream (default)
|
|
dbg = true ... Additional debug logs are also sent to the output stream
|
|
</longdesc>
|
|
<shortdesc lang="en">Service Debug Control Option</shortdesc>
|
|
<content type="boolean" default="${OCF_RESKEY_dbg_default}"/>
|
|
</parameter>
|
|
|
|
<parameter name="user" unique="0" required="0">
|
|
<longdesc lang="en">
|
|
User running Inventory API Service (inventory-api)
|
|
</longdesc>
|
|
<shortdesc lang="en">Inventory API Service (inventory-api) user</shortdesc>
|
|
<content type="string" default="${OCF_RESKEY_user_default}" />
|
|
</parameter>
|
|
|
|
</parameters>
|
|
|
|
|
|
<actions>
|
|
<action name="start" timeout="10s" />
|
|
<action name="stop" timeout="10s" />
|
|
<action name="monitor" timeout="10s" interval="10m" />
|
|
<action name="meta-data" timeout="10s" />
|
|
<action name="validate-all" timeout="10s" />
|
|
</actions>
|
|
</resource-agent>
|
|
END
|
|
return ${OCF_SUCCESS}
|
|
}
|
|
|
|
inventory_api_validate() {
|
|
|
|
local rc
|
|
|
|
proc="${binname}:validate"
|
|
if [ ${OCF_RESKEY_dbg} = "true" ] ; then
|
|
ocf_log info "${proc}"
|
|
fi
|
|
|
|
check_binary ${OCF_RESKEY_binary}
|
|
|
|
if [ ! -f ${OCF_RESKEY_config} ] ; then
|
|
ocf_log err "${OCF_RESKEY_binary} ini file missing (${OCF_RESKEY_config})"
|
|
return ${OCF_ERR_CONFIGURED}
|
|
fi
|
|
|
|
getent passwd $OCF_RESKEY_user >/dev/null 2>&1
|
|
rc=$?
|
|
if [ $rc -ne 0 ]; then
|
|
ocf_log err "User $OCF_RESKEY_user doesn't exist"
|
|
return ${OCF_ERR_CONFIGURED}
|
|
fi
|
|
|
|
return ${OCF_SUCCESS}
|
|
}
|
|
|
|
inventory_api_status() {
|
|
local pid
|
|
local rc
|
|
|
|
proc="${binname}:status"
|
|
if [ ${OCF_RESKEY_dbg} = "true" ] ; then
|
|
ocf_log info "${proc}"
|
|
fi
|
|
|
|
if [ ! -f $OCF_RESKEY_pid ]; then
|
|
ocf_log info "${binname}:Inventory API (inventory-api) is not running"
|
|
return $OCF_NOT_RUNNING
|
|
else
|
|
pid=`cat $OCF_RESKEY_pid`
|
|
fi
|
|
|
|
ocf_run -warn kill -s 0 $pid
|
|
rc=$?
|
|
if [ $rc -eq 0 ]; then
|
|
return $OCF_SUCCESS
|
|
else
|
|
ocf_log info "${binname}:Old PID file found, but Inventory API (inventory-api) is not running"
|
|
rm -f $OCF_RESKEY_pid
|
|
return $OCF_NOT_RUNNING
|
|
fi
|
|
}
|
|
|
|
inventory_api_monitor () {
|
|
local rc
|
|
proc="${binname}:monitor"
|
|
|
|
if [ ${OCF_RESKEY_dbg} = "true" ] ; then
|
|
ocf_log info "${proc}"
|
|
fi
|
|
|
|
inventory_api_status
|
|
rc=$?
|
|
# If status returned anything but success, return that immediately
|
|
if [ $rc -ne $OCF_SUCCESS ]; then
|
|
return $rc
|
|
fi
|
|
return $OCF_SUCCESS
|
|
|
|
if [ -n "$OCF_RESKEY_os_username" ] && [ -n "$OCF_RESKEY_os_tenant_name" ] && [ -n "$OCF_RESKEY_os_auth_url" ]; then
|
|
ocf_run -q $OCF_RESKEY_client_binary \
|
|
--os_username "$OCF_RESKEY_os_username" \
|
|
--os_project_name "$OCF_RESKEY_os_tenant_name" \
|
|
--os_auth_url "$OCF_RESKEY_os_auth_url" \
|
|
--os_region_name "$OCF_RESKEY_os_region_name" \
|
|
--system_url "$OCF_RESKEY_system_url" \
|
|
show > /dev/null 2>&1
|
|
rc=$?
|
|
if [ $rc -ne 0 ]; then
|
|
ocf_log err "Failed to connect to the Inventory Service (inventory-api): $rc"
|
|
return $OCF_NOT_RUNNING
|
|
fi
|
|
fi
|
|
|
|
ocf_log debug "Inventory Service (inventory-api) monitor succeeded"
|
|
|
|
return $OCF_SUCCESS
|
|
}
|
|
|
|
inventory_api_start () {
|
|
local rc
|
|
|
|
proc="${binname}:start"
|
|
if [ ${OCF_RESKEY_dbg} = "true" ] ; then
|
|
ocf_log info "${proc}"
|
|
fi
|
|
|
|
# If running then issue a ping test
|
|
if [ -f ${OCF_RESKEY_pid} ] ; then
|
|
inventory_api_status
|
|
rc=$?
|
|
if [ $rc -ne ${OCF_SUCCESS} ] ; then
|
|
ocf_log err "${proc} ping test failed (rc=${rc})"
|
|
inventory_api_stop
|
|
else
|
|
return ${OCF_SUCCESS}
|
|
fi
|
|
fi
|
|
|
|
if [ ${OCF_RESKEY_dbg} = "true" ] ; then
|
|
RUN_OPT_DEBUG="--debug"
|
|
else
|
|
RUN_OPT_DEBUG=""
|
|
fi
|
|
|
|
# switch to non-root user before starting service
|
|
su ${OCF_RESKEY_user} -g root -s /bin/sh -c "${OCF_RESKEY_binary} --config-file=${OCF_RESKEY_config} ${RUN_OPT_DEBUG}"' >> /dev/null 2>&1 & echo $!' > $OCF_RESKEY_pid
|
|
rc=$?
|
|
if [ ${rc} -ne ${OCF_SUCCESS} ] ; then
|
|
ocf_log err "${proc} failed ${mydaemon} daemon (rc=$rc)"
|
|
return ${OCF_ERR_GENERIC}
|
|
else
|
|
if [ -f ${OCF_RESKEY_pid} ] ; then
|
|
pid=`cat ${OCF_RESKEY_pid}`
|
|
ocf_log info "${proc} running with pid ${pid}"
|
|
else
|
|
ocf_log info "${proc} with no pid file"
|
|
fi
|
|
fi
|
|
|
|
# Record success or failure and return status
|
|
if [ ${rc} -eq $OCF_SUCCESS ] ; then
|
|
ocf_log info "Inventory Service (${OCF_RESKEY_binary}) started (pid=${pid})"
|
|
else
|
|
ocf_log err "Inventory Service (${OCF_RESKEY_binary}) failed to start (rc=${rc})"
|
|
rc=${OCF_NOT_RUNNING}
|
|
fi
|
|
|
|
return ${rc}
|
|
}
|
|
|
|
inventory_api_confirm_stop() {
|
|
local my_bin
|
|
local my_processes
|
|
|
|
my_binary=`which ${OCF_RESKEY_binary}`
|
|
my_processes=`pgrep -l -f "^(python|/usr/bin/python|/usr/bin/python2) ${my_binary}([^\w-]|$)"`
|
|
|
|
if [ -n "${my_processes}" ]
|
|
then
|
|
ocf_log info "About to SIGKILL the following: ${my_processes}"
|
|
pkill -KILL -f "^(python|/usr/bin/python|/usr/bin/python2) ${my_binary}([^\w-]|$)"
|
|
fi
|
|
}
|
|
|
|
inventory_api_stop () {
|
|
local rc
|
|
local pid
|
|
|
|
proc="${binname}:stop"
|
|
if [ ${OCF_RESKEY_dbg} = "true" ] ; then
|
|
ocf_log info "${proc}"
|
|
fi
|
|
|
|
inventory_api_status
|
|
rc=$?
|
|
if [ $rc -eq $OCF_NOT_RUNNING ]; then
|
|
ocf_log info "${proc} Inventory API (inventory-api) already stopped"
|
|
inventory_api_confirm_stop
|
|
return ${OCF_SUCCESS}
|
|
fi
|
|
|
|
# Try SIGTERM
|
|
pid=`cat $OCF_RESKEY_pid`
|
|
ocf_run kill -s TERM $pid
|
|
rc=$?
|
|
if [ $rc -ne 0 ]; then
|
|
ocf_log err "${proc} Inventory API (inventory-api) couldn't be stopped"
|
|
inventory_api_confirm_stop
|
|
exit $OCF_ERR_GENERIC
|
|
fi
|
|
|
|
# stop waiting
|
|
shutdown_timeout=15
|
|
if [ -n "$OCF_RESKEY_CRM_meta_timeout" ]; then
|
|
shutdown_timeout=$((($OCF_RESKEY_CRM_meta_timeout/1000)-5))
|
|
fi
|
|
count=0
|
|
while [ $count -lt $shutdown_timeout ]; do
|
|
inventory_api_status
|
|
rc=$?
|
|
if [ $rc -eq $OCF_NOT_RUNNING ]; then
|
|
break
|
|
fi
|
|
count=`expr $count + 1`
|
|
sleep 1
|
|
ocf_log info "${proc} Inventory API (inventory-api) still hasn't stopped yet. Waiting ..."
|
|
done
|
|
|
|
inventory_api_status
|
|
rc=$?
|
|
if [ $rc -ne $OCF_NOT_RUNNING ]; then
|
|
# SIGTERM didn't help either, try SIGKILL
|
|
ocf_log info "${proc} Inventory API (inventory-api) failed to stop after ${shutdown_timeout}s using SIGTERM. Trying SIGKILL ..."
|
|
ocf_run kill -s KILL $pid
|
|
fi
|
|
inventory_api_confirm_stop
|
|
|
|
ocf_log info "${proc} Inventory API (inventory-api) stopped."
|
|
|
|
rm -f $OCF_RESKEY_pid
|
|
|
|
return $OCF_SUCCESS
|
|
|
|
}
|
|
|
|
inventory_api_reload () {
|
|
local rc
|
|
|
|
proc="${binname}:reload"
|
|
if [ ${OCF_RESKEY_dbg} = "true" ] ; then
|
|
ocf_log info "${proc}"
|
|
fi
|
|
|
|
inventory_api_stop
|
|
rc=$?
|
|
if [ $rc -eq ${OCF_SUCCESS} ] ; then
|
|
#sleep 1
|
|
inventory_api_start
|
|
rc=$?
|
|
if [ $rc -eq ${OCF_SUCCESS} ] ; then
|
|
ocf_log info "Inventory (${OCF_RESKEY_binary}) process restarted"
|
|
fi
|
|
fi
|
|
|
|
if [ ${rc} -ne ${OCF_SUCCESS} ] ; then
|
|
ocf_log err "Inventory (${OCF_RESKEY_binary}) process failed to restart (rc=${rc})"
|
|
fi
|
|
|
|
return ${rc}
|
|
}
|
|
|
|
case ${__OCF_ACTION} in
|
|
meta-data) meta_data
|
|
exit ${OCF_SUCCESS}
|
|
;;
|
|
usage|help) usage
|
|
exit ${OCF_SUCCESS}
|
|
;;
|
|
esac
|
|
|
|
# Anything except meta-data and help must pass validation
|
|
inventory_api_validate || exit $?
|
|
|
|
if [ ${OCF_RESKEY_dbg} = "true" ] ; then
|
|
ocf_log info "${binname}:${__OCF_ACTION} action"
|
|
fi
|
|
|
|
case ${__OCF_ACTION} in
|
|
|
|
start) inventory_api_start
|
|
;;
|
|
stop) inventory_api_stop
|
|
;;
|
|
status) inventory_api_status
|
|
;;
|
|
reload) inventory_api_reload
|
|
;;
|
|
monitor) inventory_api_monitor
|
|
;;
|
|
validate-all) inventory_api_validate
|
|
;;
|
|
*) usage
|
|
exit ${OCF_ERR_UNIMPLEMENTED}
|
|
;;
|
|
esac
|