Commit 58a79e0a authored by Dimitris Aragiorgis's avatar Dimitris Aragiorgis

deploy: Support run command

..to kinda simulate pdsh. Specifically:

  snf-deploy run --setup synnefo --cmd "apt-get update" -vvv

or:

  snf-deploy run --target-nodes node1,node2 --cmd "apt-get update"
Signed-off-by: default avatarDimitris Aragiorgis <dimara@grnet.gr>
parent c1282636
......@@ -66,6 +66,18 @@ Usage: setup --node NODE [--role ROLE | --method METHOD --component COMPONENT]
--component COMPONENT (one of the subcomponents)
"""
elif "run" in cmds:
print """
Usage: setup --setup SETUP | --target-nodes NODE1,NODE2... --cmd "some cmd"
Run a specific bash command on the requested nodes
--target-nodes NODES Comma separated nodes definded in nodes.conf
--setup SETUP Target all nodes in SETUP defined in setups.conf
--cmd CMD The bash command to be executed
"""
else:
print """
Usage: snf-deploy [-h] [-c CONFDIR] [-t TEMPLATE_DIR] [-s STATE_DIR]
......@@ -87,6 +99,7 @@ Usage: snf-deploy [-h] [-c CONFDIR] [-t TEMPLATE_DIR] [-s STATE_DIR]
keygen Create ssh and ddns keys
ganeti Deploy a Ganeti cluster on the requested setup
ganeti-qa Deploy a Ganeti QA cluster on the requested cluster
run Run a specific bash command on the target nodes
help Display a help message for the following command
"""
......@@ -122,7 +135,6 @@ def fabcommand(args, actions):
# ".format(args.confdir, env.packages, env.templates, args.cluster_name,
# env.lib, args.autoconf, args.disable_colors, args.key_inject)
fabfile.setup_env(args)
with settings(hide(*lhide), show(*lshow)):
for a in actions:
fn = getattr(fabfile, a)
......@@ -218,11 +230,19 @@ def parse_options():
default=constants.DEFAULT_SETUP,
help="The target setup")
parser.add_argument("--cmd", dest="cmd",
default="date",
help="The command to run on target nodes")
parser.add_argument("--target-nodes", dest="target_nodes",
default=None,
help="The target nodes to run cmd")
# available commands
parser.add_argument("command", type=str,
choices=["packages", "vcluster", "cleanup", "image",
"setup", "test", "synnefo", "keygen",
"ganeti", "ganeti-qa", "help"],
"ganeti", "ganeti-qa", "help", "run"],
help="Run on of the supported deployment commands")
# available actions for the run command
......@@ -251,6 +271,9 @@ def get_actions(*args):
"setup": [
"setup",
],
"run": [
"run",
],
}
......
......@@ -74,7 +74,7 @@ class Context(object):
def _get(self, role):
try:
return config.get_single_node_role_info(self.setup, role)
except ConfigParser.NoOptionError:
except (ConfigParser.NoOptionError, ConfigParser.NoSectionError):
return config.get_node_info(constants.DUMMY_NODE)
@property
......@@ -157,4 +157,8 @@ def init(args):
context.role = args.role
context.cluster = args.cluster
context.setup = args.setup
context.method = args.method
context.component = args.component
context.target_nodes = args.target_nodes
context.cmd = args.cmd
update_passwords()
......@@ -59,14 +59,6 @@ def with_node(fn):
return wrapper
def setup_env(args):
env.component = args.component
env.method = args.method
env.role = args.role
env.cluster = args.cluster
env.node = args.node
# Helper methods that are invoked via fabric's execute
@with_node
......@@ -145,16 +137,29 @@ def setup_qa(ctx=None):
@with_ctx
def setup(ctx=None):
if env.node:
if env.component:
C = roles.get(env.component, ctx)
elif env.role:
C = roles.get(env.role, ctx)
if env.method:
fn = getattr(C, env.method)
if context.node:
if context.component:
C = roles.get(context.component, ctx)
elif context.role:
C = roles.get(context.role, ctx)
if context.method:
fn = getattr(C, context.method)
fn()
else:
C.setup()
elif env.cluster:
elif context.cluster:
_setup_cluster(ctx)
@with_ctx
def run(ctx=None):
if context.target_nodes:
nodes = context.target_nodes.split(",")
else:
nodes = ctx.all_nodes
for node in nodes:
ctx.update(node=node)
c = roles.get("HW", ctx)
c.run(context.cmd)
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