Cherry-picked changes from release-0.3
* Resolved PEP8 issues * Improved RabbitMQ connection handling, updated requirements and README file * MANIFEST.in file added + formatting * Add installer and init.d scripts * version bump to 0.3 Change-Id: Ieca65706da2e3d25ffc0801eabab5905945dab28
This commit is contained in:
parent
c43e2b3024
commit
482f83ef32
|
@ -0,0 +1,3 @@
|
|||
include requirements.txt
|
||||
prune windows-agent
|
||||
prune python-agent
|
|
@ -0,0 +1,10 @@
|
|||
Murano Python Agent README
|
||||
==========================
|
||||
Murano Python Agent is a VM-side guest agent that accepts commands from
|
||||
Murano Conductor and executes them. Python Agent works on Linux and
|
||||
uses new execution plan format described in `Unified Agent blueprint
|
||||
<https://wiki.openstack.org/wiki/Murano/UnifiedAgent>`_
|
||||
|
||||
SEE ALSO
|
||||
--------
|
||||
* `Murano <https://wiki.openstack.org/wiki/Murano>`__
|
|
@ -1,8 +1,8 @@
|
|||
[DEFAULT]
|
||||
debug=True
|
||||
verbose=True
|
||||
|
||||
storage=.
|
||||
log_file = /var/log/murano-agent.log
|
||||
storage=/var/murano/plans
|
||||
|
||||
[rabbitmq]
|
||||
|
||||
|
|
|
@ -0,0 +1,103 @@
|
|||
#!/bin/sh
|
||||
# Copyright (c) 2013 Mirantis, Inc.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License"); you may
|
||||
# not use this file except in compliance with the License. You may obtain
|
||||
# a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
# Author: Igor Yozhikov <iyozhikov@mirantis.com>
|
||||
#
|
||||
### BEGIN INIT INFO
|
||||
# Provides: murano-agent
|
||||
# Required-Start: $network $local_fs $remote_fs $syslog
|
||||
# Required-Stop: $remote_fs
|
||||
# Default-Start: 2 3 4 5
|
||||
# Default-Stop: 0 1 6
|
||||
# Short-Description: Launches the murano linux agent
|
||||
# Description: This startup script launches murano linux agent.
|
||||
### END INIT INFO
|
||||
|
||||
|
||||
PATH=/sbin:/usr/sbin:/bin:/usr/bin:/usr/local/bin
|
||||
DESC="murano-agent"
|
||||
NAME=murano-agent
|
||||
DAEMON=/usr/local/bin/muranoagent
|
||||
PIDFILE=/var/run/$NAME.pid
|
||||
SCRIPTNAME=/etc/init.d/$NAME
|
||||
SYSTEM_USER=root
|
||||
CONFIG_FILE=/etc/murano/agent.conf
|
||||
DATADIR=/var/murano/plans
|
||||
|
||||
# Exit if the package is not installed
|
||||
[ -x $DAEMON ] || exit 5
|
||||
|
||||
# source function library
|
||||
. /lib/lsb/init-functions
|
||||
|
||||
if [ ! -d "$DATADIR" ]; then
|
||||
mkdir -p ${DATADIR}
|
||||
chown ${SYSTEM_USER} ${DATADIR}
|
||||
fi
|
||||
|
||||
do_start () {
|
||||
start-stop-daemon --start --background --quiet --chuid $SYSTEM_USER:$SYSTEM_USER --make-pidfile --pidfile $PIDFILE --startas $DAEMON --test -- --config-file=$CONFIG_FILE > /dev/null || return 1
|
||||
start-stop-daemon --start --background --quiet --chuid $SYSTEM_USER:$SYSTEM_USER --make-pidfile --pidfile $PIDFILE --startas $DAEMON -- --config-file=$CONFIG_FILE || return 2
|
||||
}
|
||||
|
||||
do_stop () {
|
||||
start-stop-daemon --stop --quiet --retry=TERM/30/KILL/5 --pidfile $PIDFILE
|
||||
RETVAL="$?"
|
||||
rm -f $PIDFILE
|
||||
return "$RETVAL"
|
||||
}
|
||||
|
||||
case "$1" in
|
||||
start)
|
||||
log_daemon_msg "Starting $DESC" "$NAME"
|
||||
do_start
|
||||
case "$?" in
|
||||
0|1) log_end_msg 0 ;;
|
||||
2) log_end_msg 1 ;;
|
||||
esac
|
||||
;;
|
||||
stop)
|
||||
log_daemon_msg "Stopping $DESC" "$NAME"
|
||||
do_stop
|
||||
case "$?" in
|
||||
0|1) log_end_msg 0 ;;
|
||||
2) log_end_msg 1 ;;
|
||||
esac
|
||||
;;
|
||||
status)
|
||||
status_of_proc "$DAEMON" "$NAME" && exit 0 || exit $?
|
||||
;;
|
||||
restart|force-reload)
|
||||
log_daemon_msg "Restarting $DESC" "$NAME"
|
||||
do_stop
|
||||
case "$?" in
|
||||
0|1)
|
||||
do_start
|
||||
case "$?" in
|
||||
0) log_end_msg 0 ;;
|
||||
1) log_end_msg 1 ;; # Old process is still running
|
||||
*) log_end_msg 1 ;; # Failed to start
|
||||
esac
|
||||
;;
|
||||
*)
|
||||
# Failed to stop
|
||||
log_end_msg 1
|
||||
;;
|
||||
esac
|
||||
;;
|
||||
*)
|
||||
echo "Usage: $SCRIPTNAME {start|stop|status|restart|force-reload}" >&2
|
||||
exit 3
|
||||
;;
|
||||
esac
|
|
@ -0,0 +1,103 @@
|
|||
#!/bin/sh
|
||||
# Copyright (c) 2013 Mirantis, Inc.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License"); you may
|
||||
# not use this file except in compliance with the License. You may obtain
|
||||
# a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
# Author: Igor Yozhikov <iyozhikov@mirantis.com>
|
||||
#
|
||||
### BEGIN INIT INFO
|
||||
# Provides: murano-agent
|
||||
# Required-Start: $network $local_fs $remote_fs $syslog
|
||||
# Required-Stop: $remote_fs
|
||||
# Default-Start: 2 3 4 5
|
||||
# Default-Stop: 0 1 6
|
||||
# Short-Description: Launches the murano linux agent
|
||||
# Description: This startup script launches murano linux agent.
|
||||
### END INIT INFO
|
||||
# chkconfig: 3 90 10
|
||||
# description: This startup script launches the murano linux agent.
|
||||
# config: /etc/murano/agent.conf
|
||||
#
|
||||
PATH=/sbin:/usr/sbin:/bin:/usr/bin:/usr/local/bin
|
||||
DESC="murano-agent"
|
||||
NAME=murano-agent
|
||||
DAEMON=/usr/local/bin/muranoagent
|
||||
PIDFILE=/var/run/$NAME.pid
|
||||
SCRIPTNAME=/etc/init.d/$NAME
|
||||
SYSTEM_USER=root
|
||||
CONFIG_FILE=/etc/murano/agent.conf
|
||||
DATADIR=/var/murano/plans
|
||||
LOCKFILE=/var/lock/subsys/$NAME
|
||||
# Exit if the package is not installed
|
||||
[ -x $DAEMON ] || exit 5
|
||||
|
||||
# source function library
|
||||
. /etc/init.d/functions
|
||||
|
||||
RETVAL=0
|
||||
|
||||
if [ ! -d "$DATADIR" ]; then
|
||||
mkdir -p $DATADIR
|
||||
chown $SYSTEM_USER $DATADIR
|
||||
fi
|
||||
|
||||
start() {
|
||||
echo -n "Starting $NAME: "
|
||||
daemon --user $SYSTEM_USER "$DAEMON --config-file=$CONFIG_FILE &>/dev/null & echo \$! > $PIDFILE"
|
||||
RETVAL=$?
|
||||
echo
|
||||
[ $RETVAL -eq 0 ] && touch $LOCKFILE
|
||||
return $RETVAL
|
||||
}
|
||||
|
||||
stop() {
|
||||
echo -n "Stopping $NAME: "
|
||||
#killproc $DAEMON -TERM
|
||||
killproc -p $PIDFILE $DAEMON
|
||||
RETVAL=$?
|
||||
echo
|
||||
[ $RETVAL -eq 0 ] && rm -f $LOCKFILE
|
||||
return $RETVAL
|
||||
}
|
||||
|
||||
restart() {
|
||||
stop
|
||||
start
|
||||
}
|
||||
|
||||
rh_status() {
|
||||
# run checks to determine if the service is running or use generic status
|
||||
status $DAEMON
|
||||
}
|
||||
|
||||
|
||||
case "$1" in
|
||||
start)
|
||||
start
|
||||
;;
|
||||
|
||||
stop)
|
||||
stop
|
||||
;;
|
||||
|
||||
restart)
|
||||
restart
|
||||
;;
|
||||
|
||||
status)
|
||||
rh_status
|
||||
;;
|
||||
*)
|
||||
echo $"Usage: $0 {start|stop|status|restart}"
|
||||
exit 2
|
||||
esac
|
||||
exit $?
|
|
@ -32,6 +32,7 @@ import types
|
|||
log = logging.getLogger(__name__)
|
||||
format_version = '2.0.0'
|
||||
|
||||
|
||||
class MuranoAgent(service.Service):
|
||||
def __init__(self):
|
||||
self._queue = ExecutionPlanQueue()
|
||||
|
@ -42,8 +43,8 @@ class MuranoAgent(service.Service):
|
|||
try:
|
||||
log.debug('Loading plugin %s', name)
|
||||
__import__(name)
|
||||
except Exception, ex:
|
||||
log.warn('Cannot load package %s', name, exc_info=1)
|
||||
except Exception:
|
||||
log.warn('Cannot load package %s', name, exc_info=True)
|
||||
pass
|
||||
|
||||
def _load(self):
|
||||
|
@ -56,14 +57,15 @@ class MuranoAgent(service.Service):
|
|||
|
||||
def start(self):
|
||||
self._load()
|
||||
msg_iterator = self._wait_plan()
|
||||
while True:
|
||||
try:
|
||||
self._loop_func()
|
||||
self._loop_func(msg_iterator)
|
||||
except Exception as ex:
|
||||
log.exception(ex)
|
||||
sleep(5)
|
||||
|
||||
def _loop_func(self):
|
||||
def _loop_func(self, msg_iterator):
|
||||
result, timestamp = self._queue.get_execution_plan_result()
|
||||
if result is not None:
|
||||
if self._send_result(result):
|
||||
|
@ -75,7 +77,7 @@ class MuranoAgent(service.Service):
|
|||
self._run(plan)
|
||||
return
|
||||
|
||||
self._wait_plan()
|
||||
msg_iterator.next()
|
||||
|
||||
def _run(self, plan):
|
||||
with ExecutionPlanRunner(plan) as runner:
|
||||
|
@ -111,26 +113,44 @@ class MuranoAgent(service.Service):
|
|||
return MqClient(**connection_params)
|
||||
|
||||
def _wait_plan(self):
|
||||
with self._create_rmq_client() as mq:
|
||||
with mq.open(CONF.rabbitmq.input_queue,
|
||||
prefetch_count=1) as subscription:
|
||||
msg = subscription.get_message(timeout=5)
|
||||
if msg is not None and isinstance(msg.body, dict):
|
||||
if 'ID' not in msg.body and msg.id:
|
||||
msg.body['ID'] = msg.id
|
||||
err = self._verify_plan(msg.body)
|
||||
if err is None:
|
||||
self._queue.put_execution_plan(msg.body)
|
||||
else:
|
||||
try:
|
||||
execution_result = ExecutionResult.from_error(
|
||||
err, Bunch(msg.body))
|
||||
self._send_result(execution_result)
|
||||
except ValueError:
|
||||
log.warn('Execution result is not produced')
|
||||
delay = 5
|
||||
while True:
|
||||
try:
|
||||
with self._create_rmq_client() as mq:
|
||||
with mq.open(CONF.rabbitmq.input_queue,
|
||||
prefetch_count=1) as subscription:
|
||||
while True:
|
||||
msg = subscription.get_message(timeout=5)
|
||||
if msg is not None and isinstance(msg.body, dict):
|
||||
self._handle_message(msg)
|
||||
|
||||
if msg is not None:
|
||||
msg.ack()
|
||||
yield
|
||||
delay = 5
|
||||
except KeyboardInterrupt:
|
||||
break
|
||||
except Exception:
|
||||
log.warn('Communication error', exc_info=True)
|
||||
sleep(delay)
|
||||
delay = min(delay * 1.2, 60)
|
||||
|
||||
def _handle_message(self, msg):
|
||||
print msg.body
|
||||
if 'ID' not in msg.body and msg.id:
|
||||
msg.body['ID'] = msg.id
|
||||
err = self._verify_plan(msg.body)
|
||||
if err is None:
|
||||
self._queue.put_execution_plan(msg.body)
|
||||
else:
|
||||
try:
|
||||
execution_result = ExecutionResult.from_error(
|
||||
err, Bunch(msg.body))
|
||||
|
||||
self._send_result(execution_result)
|
||||
except ValueError:
|
||||
log.warn('Execution result is not produced')
|
||||
|
||||
if msg is not None:
|
||||
msg.ack()
|
||||
|
||||
def _verify_plan(self, plan):
|
||||
plan_format_version = plan.get('FormatVersion', '1.0.0')
|
||||
|
|
|
@ -110,6 +110,3 @@ def setup_logging():
|
|||
|
||||
handler.setFormatter(formatter)
|
||||
root_logger.addHandler(handler)
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -13,6 +13,7 @@
|
|||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
|
||||
class AgentException(Exception):
|
||||
def __init__(self, code, message=None, additional_data=None):
|
||||
self._error_code = code
|
||||
|
@ -32,4 +33,3 @@ class CustomException(AgentException):
|
|||
def __init__(self, code, message=None, additional_data=None):
|
||||
super(CustomException, self).__init__(
|
||||
code + 100, message, additional_data)
|
||||
|
||||
|
|
|
@ -82,5 +82,3 @@ class ExecutionPlanQueue(object):
|
|||
def get_execution_plan_result(self):
|
||||
return self._get_first_file(
|
||||
ExecutionPlanQueue.result_filename)
|
||||
|
||||
|
||||
|
|
|
@ -67,7 +67,6 @@ class ApplicationExecutor(object):
|
|||
raise muranoagent.exceptions.CustomException(
|
||||
0,
|
||||
message='Script {0} returned error code'.format(self._name),
|
||||
additional_data= result)
|
||||
additional_data=result)
|
||||
|
||||
return Bunch(result)
|
||||
|
||||
|
|
|
@ -40,7 +40,7 @@ class FilesManager(object):
|
|||
filedef = self._files[file_id]
|
||||
filename = filedef['Name']
|
||||
|
||||
file_folder = os.path.join(script_folder, os.path.dirname(filename))
|
||||
file_folder = os.path.join(script_folder, os.path.dirname(filename))
|
||||
if not os.path.exists(file_folder):
|
||||
os.makedirs(file_folder)
|
||||
|
||||
|
|
|
@ -104,8 +104,7 @@ def _listen(host, start_port, end_port, listen_func):
|
|||
try:
|
||||
return listen_func((host, try_port))
|
||||
except socket.error as exc:
|
||||
if (exc.errno != errno.EADDRINUSE or
|
||||
try_port >= end_port):
|
||||
if (exc.errno != errno.EADDRINUSE or try_port >= end_port):
|
||||
raise
|
||||
try_port += 1
|
||||
|
||||
|
|
|
@ -0,0 +1,13 @@
|
|||
# Copyright (c) 2013 Mirantis, Inc.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License"); you may
|
||||
# not use this file except in compliance with the License. You may obtain
|
||||
# a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
|
@ -2,5 +2,6 @@ pbr>=0.5.21,<1.0
|
|||
semver
|
||||
bunch
|
||||
oslo.config>=1.2.0
|
||||
murano-common
|
||||
|
||||
http://tarballs.openstack.org/murano-common/murano-common-release-0.3.tar.gz#egg=murano-common-release-0.3
|
||||
iso8601
|
||||
babel
|
||||
|
|
|
@ -0,0 +1,210 @@
|
|||
#!/bin/sh
|
||||
# Copyright (c) 2013 Mirantis, Inc.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License"); you may
|
||||
# not use this file except in compliance with the License. You may obtain
|
||||
# a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
#
|
||||
# CentOS script
|
||||
LOGLVL=1
|
||||
SERVICE_CONTENT_DIRECTORY=`cd $(dirname "$0") && pwd`
|
||||
PREREQ_PKGS="git wget make gcc python-pip python-iso8601 python-six python-anyjson python-eventlet python-devel python-setuptools"
|
||||
PIPAPPS="pip python-pip pip-python"
|
||||
PIPCMD=""
|
||||
SERVICE_SRV_NAME="murano-agent"
|
||||
ETC_CFG_DIR="/etc/murano"
|
||||
|
||||
|
||||
|
||||
# Functions
|
||||
# Loger function
|
||||
log()
|
||||
{
|
||||
MSG=$1
|
||||
if [ $LOGLVL -gt 0 ]; then
|
||||
echo "LOG:> $MSG"
|
||||
fi
|
||||
}
|
||||
|
||||
# find pip
|
||||
find_pip()
|
||||
{
|
||||
for cmd in $PIPAPPS
|
||||
do
|
||||
_cmd=$(which $cmd 2>/dev/null)
|
||||
if [ $? -eq 0 ];then
|
||||
break
|
||||
fi
|
||||
done
|
||||
if [ -z $_cmd ];then
|
||||
echo "Can't find \"pip\" in system, please install it first, exiting!"
|
||||
exit 1
|
||||
else
|
||||
PIPCMD=$_cmd
|
||||
fi
|
||||
}
|
||||
|
||||
# Check or install package
|
||||
in_sys_pkg()
|
||||
{
|
||||
PKG=$1
|
||||
rpm -q $PKG > /dev/null 2>&1
|
||||
if [ $? -eq 0 ]; then
|
||||
log "Package \"$PKG\" already installed"
|
||||
else
|
||||
log "Installing \"$PKG\"..."
|
||||
yum install $PKG --assumeyes > /dev/null 2>&1
|
||||
if [ $? -ne 0 ];then
|
||||
log "installation fails, exiting!!!"
|
||||
exit
|
||||
fi
|
||||
fi
|
||||
}
|
||||
|
||||
# install
|
||||
inst()
|
||||
{
|
||||
# Checking packages
|
||||
for PKG in $PREREQ_PKGS
|
||||
do
|
||||
in_sys_pkg $PKG
|
||||
done
|
||||
# Find python pip
|
||||
find_pip
|
||||
MRN_CND_SPY=$SERVICE_CONTENT_DIRECTORY/setup.py
|
||||
if [ -e $MRN_CND_SPY ]; then
|
||||
chmod +x $MRN_CND_SPY
|
||||
log "$MRN_CND_SPY output:_____________________________________________________________"
|
||||
## Setup through pip
|
||||
# Creating tarball
|
||||
rm -rf $SERVICE_CONTENT_DIRECTORY/*.egg-info
|
||||
cd $SERVICE_CONTENT_DIRECTORY && python $MRN_CND_SPY egg_info
|
||||
if [ $? -ne 0 ];then
|
||||
log "\"$MRN_CND_SPY\" egg info creation FAILS, exiting!!!"
|
||||
exit 1
|
||||
fi
|
||||
rm -rf $SERVICE_CONTENT_DIRECTORY/dist/*
|
||||
cd $SERVICE_CONTENT_DIRECTORY && $MRN_CND_SPY sdist
|
||||
if [ $? -ne 0 ];then
|
||||
log "\"$MRN_CND_SPY\" tarball creation FAILS, exiting!!!"
|
||||
exit 1
|
||||
fi
|
||||
# Running tarball install
|
||||
TRBL_FILE=$(basename `ls $SERVICE_CONTENT_DIRECTORY/dist/murano-agent*.tar.gz`)
|
||||
$PIPCMD install $SERVICE_CONTENT_DIRECTORY/dist/$TRBL_FILE
|
||||
if [ $? -ne 0 ];then
|
||||
log "$PIPCMD install \"$TRBL_FILE\" FAILS, recreate terball with \"python setup.py sdist\" command, exiting!!!"
|
||||
exit 1
|
||||
fi
|
||||
# Creating etc directory for config files
|
||||
if [ ! -d $ETC_CFG_DIR ];then
|
||||
log "Creating $ETC_CFG_DIR direcory..."
|
||||
mkdir -p $ETC_CFG_DIR
|
||||
if [ $? -ne 0 ];then
|
||||
log "Can't create $ETC_CFG_DIR, exiting!!!"
|
||||
exit 1
|
||||
fi
|
||||
fi
|
||||
log "Making sample configuration file at \"$ETC_CFG_DIR\""
|
||||
cp -f "$SERVICE_CONTENT_DIRECTORY/etc/agent.conf" "$ETC_CFG_DIR/agent.conf"
|
||||
else
|
||||
log "$MRN_CND_SPY not found!"
|
||||
fi
|
||||
}
|
||||
|
||||
# searching for service executable in path
|
||||
get_service_exec_path()
|
||||
{
|
||||
if [ -z "$SERVICE_EXEC_PATH" ]; then
|
||||
SERVICE_EXEC_PATH=$(which muranoagent)
|
||||
if [ $? -ne 0 ]; then
|
||||
log "Can't find \"muranoagent ($SERVICE_SRV_NAME)\", please install the \"$SERVICE_SRV_NAME\" by running \"$(basename "$0") install\" or set variable SERVICE_EXEC_PATH=/path/to/daemon before running setup script, exiting!"
|
||||
exit 1
|
||||
fi
|
||||
else
|
||||
if [ ! -x "$SERVICE_EXEC_PATH" ]; then
|
||||
log "\"$SERVICE_EXEC_PATH\" in not executable, please install the muranoagent \"($SERVICE_SRV_NAME)\" or set variable SERVICE_EXEC_PATH=/path/to/daemon before running setup script, exiting!"
|
||||
exit 1
|
||||
fi
|
||||
fi
|
||||
}
|
||||
|
||||
# uninstall
|
||||
uninst()
|
||||
{
|
||||
# Uninstall trough pip
|
||||
find_pip
|
||||
# looking up for python package installed
|
||||
PYPKG=$SERVICE_SRV_NAME
|
||||
_pkg=$($PIPCMD freeze | grep $PYPKG)
|
||||
if [ $? -eq 0 ]; then
|
||||
log "Removing package \"$PYPKG\" with pip"
|
||||
$PIPCMD uninstall $_pkg --yes
|
||||
else
|
||||
log "Python package \"$PYPKG\" not found"
|
||||
fi
|
||||
}
|
||||
|
||||
# inject init
|
||||
injectinit()
|
||||
{
|
||||
log "Enabling $SERVICE_SRV_NAME in init.d..."
|
||||
cp -f "$SERVICE_CONTENT_DIRECTORY/init.d/murano-agent-el6" "/etc/init.d/$SERVICE_SRV_NAME"
|
||||
sed -i "s/DAEMON=.*/DAEMON=$(echo $SERVICE_EXEC_PATH | sed -e 's/\//\\\//g')/" /etc/init.d/$SERVICE_SRV_NAME
|
||||
chmod 755 /etc/init.d/$SERVICE_SRV_NAME
|
||||
chkconfig --add $SERVICE_SRV_NAME
|
||||
chkconfig $SERVICE_SRV_NAME on
|
||||
}
|
||||
|
||||
purgeinit()
|
||||
{
|
||||
log "Removing from init.d..."
|
||||
chkconfig $SERVICE_SRV_NAME off
|
||||
chkconfig --del $SERVICE_SRV_NAME
|
||||
rm -f /etc/init.d/$SERVICE_SRV_NAME
|
||||
#Fedora compat.
|
||||
systemctl --system daemon-reload > /dev/null 2>&1
|
||||
}
|
||||
|
||||
# Command line args'
|
||||
COMMAND="$1"
|
||||
case $COMMAND in
|
||||
inject-init )
|
||||
get_service_exec_path
|
||||
log "Injecting \"$SERVICE_SRV_NAME\" to init..."
|
||||
injectinit
|
||||
postinst
|
||||
;;
|
||||
|
||||
install )
|
||||
inst
|
||||
get_service_exec_path
|
||||
injectinit
|
||||
;;
|
||||
|
||||
purge-init )
|
||||
log "Purging \"$SERVICE_SRV_NAME\" from init..."
|
||||
service $SERVICE_SRV_NAME stop
|
||||
purgeinit
|
||||
;;
|
||||
|
||||
uninstall )
|
||||
log "Uninstalling \"$SERVICE_SRV_NAME\" from system..."
|
||||
service $SERVICE_SRV_NAME stop
|
||||
purgeinit
|
||||
uninst
|
||||
;;
|
||||
|
||||
* )
|
||||
echo -e "Usage: $(basename "$0") command \nCommands:\n\tinstall - Install $SERVICE_SRV_NAME software\n\tuninstall - Uninstall $SERVICE_SRV_NAME software\n\tinject-init - Add $SERVICE_SRV_NAME to the system start-up\n\tpurge-init - Remove $SERVICE_SRV_NAME from the system start-up"
|
||||
exit 1
|
||||
;;
|
||||
esac
|
|
@ -1,8 +1,7 @@
|
|||
[metadata]
|
||||
name = murano-agent
|
||||
version = 0.3
|
||||
summary = Python Murano Agent
|
||||
description-file =
|
||||
README.rst
|
||||
license = Apache License, Version 2.0
|
||||
author = Mirantis, Inc.
|
||||
author-email = murano-all@lists.openstack.org
|
||||
|
|
|
@ -0,0 +1,206 @@
|
|||
#!/bin/sh
|
||||
# Copyright (c) 2013 Mirantis, Inc.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License"); you may
|
||||
# not use this file except in compliance with the License. You may obtain
|
||||
# a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
#
|
||||
# Ubuntu script
|
||||
LOGLVL=1
|
||||
SERVICE_CONTENT_DIRECTORY=`cd $(dirname "$0") && pwd`
|
||||
PREREQ_PKGS="git wget make gcc python-pip python-iso8601 python-six python-anyjson python-eventlet python-dev python-setuptools"
|
||||
PIPAPPS="pip python-pip pip-python"
|
||||
PIPCMD=""
|
||||
SERVICE_SRV_NAME="murano-agent"
|
||||
ETC_CFG_DIR="/etc/murano"
|
||||
|
||||
|
||||
|
||||
# Functions
|
||||
# Loger function
|
||||
log()
|
||||
{
|
||||
MSG=$1
|
||||
if [ $LOGLVL -gt 0 ]; then
|
||||
echo "LOG:> $MSG"
|
||||
fi
|
||||
}
|
||||
|
||||
# find pip
|
||||
find_pip()
|
||||
{
|
||||
for cmd in $PIPAPPS
|
||||
do
|
||||
_cmd=$(which $cmd 2>/dev/null)
|
||||
if [ $? -eq 0 ];then
|
||||
break
|
||||
fi
|
||||
done
|
||||
if [ -z $_cmd ];then
|
||||
echo "Can't find \"pip\" in system, please install it first, exiting!"
|
||||
exit 1
|
||||
else
|
||||
PIPCMD=$_cmd
|
||||
fi
|
||||
}
|
||||
|
||||
# Check or install package
|
||||
in_sys_pkg()
|
||||
{
|
||||
PKG=$1
|
||||
dpkg -s $PKG > /dev/null 2>&1
|
||||
if [ $? -eq 0 ]; then
|
||||
log "Package \"$PKG\" already installed"
|
||||
else
|
||||
log "Installing \"$PKG\"..."
|
||||
apt-get install $PKG --yes > /dev/null 2>&1
|
||||
if [ $? -ne 0 ];then
|
||||
log "installation fails, exiting!!!"
|
||||
exit
|
||||
fi
|
||||
fi
|
||||
}
|
||||
|
||||
# install
|
||||
inst()
|
||||
{
|
||||
# Checking packages
|
||||
for PKG in $PREREQ_PKGS
|
||||
do
|
||||
in_sys_pkg $PKG
|
||||
done
|
||||
# Find python pip
|
||||
find_pip
|
||||
MRN_CND_SPY=$SERVICE_CONTENT_DIRECTORY/setup.py
|
||||
if [ -e $MRN_CND_SPY ]; then
|
||||
chmod +x $MRN_CND_SPY
|
||||
log "$MRN_CND_SPY output:_____________________________________________________________"
|
||||
## Setup through pip
|
||||
# Creating tarball
|
||||
rm -rf $SERVICE_CONTENT_DIRECTORY/*.egg-info
|
||||
cd $SERVICE_CONTENT_DIRECTORY && python $MRN_CND_SPY egg_info
|
||||
if [ $? -ne 0 ];then
|
||||
log "\"$MRN_CND_SPY\" egg info creation FAILS, exiting!!!"
|
||||
exit 1
|
||||
fi
|
||||
rm -rf $SERVICE_CONTENT_DIRECTORY/dist/*
|
||||
cd $SERVICE_CONTENT_DIRECTORY && $MRN_CND_SPY sdist
|
||||
if [ $? -ne 0 ];then
|
||||
log "\"$MRN_CND_SPY\" tarball creation FAILS, exiting!!!"
|
||||
exit 1
|
||||
fi
|
||||
# Running tarball install
|
||||
TRBL_FILE=$(basename `ls $SERVICE_CONTENT_DIRECTORY/dist/murano-agent*.tar.gz`)
|
||||
$PIPCMD install $SERVICE_CONTENT_DIRECTORY/dist/$TRBL_FILE
|
||||
if [ $? -ne 0 ];then
|
||||
log "$PIPCMD install \"$TRBL_FILE\" FAILS, recreate terball with \"python setup.py sdist\" command, exiting!!!"
|
||||
exit 1
|
||||
fi
|
||||
# Creating etc directory for config files
|
||||
if [ ! -d $ETC_CFG_DIR ];then
|
||||
log "Creating $ETC_CFG_DIR direcory..."
|
||||
mkdir -p $ETC_CFG_DIR
|
||||
if [ $? -ne 0 ];then
|
||||
log "Can't create $ETC_CFG_DIR, exiting!!!"
|
||||
exit 1
|
||||
fi
|
||||
fi
|
||||
log "Making sample configuration file at \"$ETC_CFG_DIR\""
|
||||
cp -f "$SERVICE_CONTENT_DIRECTORY/etc/agent.conf" "$ETC_CFG_DIR/agent.conf"
|
||||
else
|
||||
log "$MRN_CND_SPY not found!"
|
||||
fi
|
||||
}
|
||||
|
||||
# searching for service executable in path
|
||||
get_service_exec_path()
|
||||
{
|
||||
if [ -z "$SERVICE_EXEC_PATH" ]; then
|
||||
SERVICE_EXEC_PATH=$(which muranoagent)
|
||||
if [ $? -ne 0 ]; then
|
||||
log "Can't find \"muranoagent ($SERVICE_SRV_NAME)\", please install the \"$SERVICE_SRV_NAME\" by running \"$(basename "$0") install\" or set variable SERVICE_EXEC_PATH=/path/to/daemon before running setup script, exiting!"
|
||||
exit 1
|
||||
fi
|
||||
else
|
||||
if [ ! -x "$SERVICE_EXEC_PATH" ]; then
|
||||
log "\"$SERVICE_EXEC_PATH\" in not executable, please install the muranoagent \"($SERVICE_SRV_NAME)\" or set variable SERVICE_EXEC_PATH=/path/to/daemon before running setup script, exiting!"
|
||||
exit 1
|
||||
fi
|
||||
fi
|
||||
}
|
||||
|
||||
# uninstall
|
||||
uninst()
|
||||
{
|
||||
# Uninstall trough pip
|
||||
find_pip
|
||||
# looking up for python package installed
|
||||
PYPKG=$SERVICE_SRV_NAME
|
||||
_pkg=$($PIPCMD freeze | grep $PYPKG)
|
||||
if [ $? -eq 0 ]; then
|
||||
log "Removing package \"$PYPKG\" with pip"
|
||||
$PIPCMD uninstall $_pkg --yes
|
||||
else
|
||||
log "Python package \"$PYPKG\" not found"
|
||||
fi
|
||||
}
|
||||
|
||||
# inject init
|
||||
injectinit()
|
||||
{
|
||||
log "Enabling $SERVICE_SRV_NAME in init.d..."
|
||||
cp -f "$SERVICE_CONTENT_DIRECTORY/init.d/murano-agent-deb" "/etc/init.d/$SERVICE_SRV_NAME"
|
||||
sed -i "s/DAEMON=.*/DAEMON=$(echo $SERVICE_EXEC_PATH | sed -e 's/\//\\\//g')/" /etc/init.d/$SERVICE_SRV_NAME
|
||||
chmod 755 /etc/init.d/$SERVICE_SRV_NAME
|
||||
update-rc.d $SERVICE_SRV_NAME defaults
|
||||
}
|
||||
|
||||
purgeinit()
|
||||
{
|
||||
log "Removing from init.d..."
|
||||
update-rc.d -f $SERVICE_SRV_NAME remove
|
||||
rm -f /etc/init.d/$SERVICE_SRV_NAME
|
||||
}
|
||||
|
||||
# Command line args'
|
||||
COMMAND="$1"
|
||||
case $COMMAND in
|
||||
inject-init )
|
||||
get_service_exec_path
|
||||
log "Injecting \"$SERVICE_SRV_NAME\" to init..."
|
||||
injectinit
|
||||
postinst
|
||||
;;
|
||||
|
||||
install )
|
||||
inst
|
||||
get_service_exec_path
|
||||
injectinit
|
||||
;;
|
||||
|
||||
purge-init )
|
||||
log "Purging \"$SERVICE_SRV_NAME\" from init..."
|
||||
service $SERVICE_SRV_NAME stop
|
||||
purgeinit
|
||||
;;
|
||||
|
||||
uninstall )
|
||||
log "Uninstalling \"$SERVICE_SRV_NAME\" from system..."
|
||||
service $SERVICE_SRV_NAME stop
|
||||
purgeinit
|
||||
uninst
|
||||
;;
|
||||
|
||||
* )
|
||||
echo -e "Usage: $(basename "$0") command \nCommands:\n\tinstall - Install $SERVICE_SRV_NAME software\n\tuninstall - Uninstall $SERVICE_SRV_NAME software\n\tinject-init - Add $SERVICE_SRV_NAME to the system start-up\n\tpurge-init - Remove $SERVICE_SRV_NAME from the system start-up"
|
||||
exit 1
|
||||
;;
|
||||
esac
|
|
@ -0,0 +1,18 @@
|
|||
# Needed for testing
|
||||
unittest2
|
||||
coverage>=3.6
|
||||
fixtures>=0.3.14
|
||||
mox>=0.5.3
|
||||
nose
|
||||
nose-exclude
|
||||
openstack.nose_plugin>=0.7
|
||||
nosehtmloutput>=0.0.3
|
||||
pep8==1.3.3
|
||||
sphinx>=1.1.2
|
||||
requests>=1.1
|
||||
testtools>=0.9.32
|
||||
mock>=1.0
|
||||
|
||||
# Optional packages that should be installed when testing
|
||||
xattr>=0.4
|
||||
pysendfile==2.0.0
|
Loading…
Reference in New Issue