Add -kl/--kolla-limit argument to limit kolla-ansible target hosts
This commit is contained in:
parent
10de93dc61
commit
a423e446d4
@ -49,6 +49,9 @@ def add_args(parser):
|
|||||||
"(default=$%s/inventory or %s/inventory) or "
|
"(default=$%s/inventory or %s/inventory) or "
|
||||||
"comma-separated host list for Kolla Ansible" %
|
"comma-separated host list for Kolla Ansible" %
|
||||||
(CONFIG_PATH_ENV, DEFAULT_CONFIG_PATH))
|
(CONFIG_PATH_ENV, DEFAULT_CONFIG_PATH))
|
||||||
|
parser.add_argument("-kl", "--kolla-limit", metavar="SUBSET",
|
||||||
|
help="further limit selected hosts to an additional "
|
||||||
|
"pattern")
|
||||||
parser.add_argument("-kt", "--kolla-tags", metavar="TAGS",
|
parser.add_argument("-kt", "--kolla-tags", metavar="TAGS",
|
||||||
help="only run plays and tasks tagged with these "
|
help="only run plays and tasks tagged with these "
|
||||||
"values in Kolla Ansible")
|
"values in Kolla Ansible")
|
||||||
@ -90,7 +93,7 @@ def _validate_args(parsed_args, inventory_filename):
|
|||||||
|
|
||||||
|
|
||||||
def build_args(parsed_args, command, inventory_filename, extra_vars=None,
|
def build_args(parsed_args, command, inventory_filename, extra_vars=None,
|
||||||
tags=None, verbose_level=None, extra_args=None):
|
tags=None, verbose_level=None, extra_args=None, limit=None):
|
||||||
"""Build arguments required for running Kolla Ansible."""
|
"""Build arguments required for running Kolla Ansible."""
|
||||||
venv_activate = os.path.join(parsed_args.kolla_venv, "bin", "activate")
|
venv_activate = os.path.join(parsed_args.kolla_venv, "bin", "activate")
|
||||||
cmd = ["source", venv_activate, "&&"]
|
cmd = ["source", venv_activate, "&&"]
|
||||||
@ -111,6 +114,9 @@ def build_args(parsed_args, command, inventory_filename, extra_vars=None,
|
|||||||
if extra_vars:
|
if extra_vars:
|
||||||
for extra_var_name, extra_var_value in extra_vars.items():
|
for extra_var_name, extra_var_value in extra_vars.items():
|
||||||
cmd += ["-e", "%s=%s" % (extra_var_name, extra_var_value)]
|
cmd += ["-e", "%s=%s" % (extra_var_name, extra_var_value)]
|
||||||
|
if parsed_args.kolla_limit or limit:
|
||||||
|
limits = [l for l in [parsed_args.kolla_limit, limit] if l]
|
||||||
|
cmd += ["--limit", ":&".join(limits)]
|
||||||
if parsed_args.kolla_tags or tags:
|
if parsed_args.kolla_tags or tags:
|
||||||
all_tags = [t for t in [parsed_args.kolla_tags, tags] if t]
|
all_tags = [t for t in [parsed_args.kolla_tags, tags] if t]
|
||||||
cmd += ["--tags", ",".join(all_tags)]
|
cmd += ["--tags", ",".join(all_tags)]
|
||||||
@ -120,14 +126,16 @@ def build_args(parsed_args, command, inventory_filename, extra_vars=None,
|
|||||||
|
|
||||||
|
|
||||||
def run(parsed_args, command, inventory_filename, extra_vars=None,
|
def run(parsed_args, command, inventory_filename, extra_vars=None,
|
||||||
tags=None, quiet=False, verbose_level=None, extra_args=None):
|
tags=None, quiet=False, verbose_level=None, extra_args=None,
|
||||||
|
limit=None):
|
||||||
"""Run a Kolla Ansible command."""
|
"""Run a Kolla Ansible command."""
|
||||||
_validate_args(parsed_args, inventory_filename)
|
_validate_args(parsed_args, inventory_filename)
|
||||||
cmd = build_args(parsed_args, command,
|
cmd = build_args(parsed_args, command,
|
||||||
inventory_filename=inventory_filename,
|
inventory_filename=inventory_filename,
|
||||||
extra_vars=extra_vars, tags=tags,
|
extra_vars=extra_vars, tags=tags,
|
||||||
verbose_level=verbose_level,
|
verbose_level=verbose_level,
|
||||||
extra_args=extra_args)
|
extra_args=extra_args,
|
||||||
|
limit=limit)
|
||||||
try:
|
try:
|
||||||
utils.run_command(" ".join(cmd), quiet=quiet, shell=True)
|
utils.run_command(" ".join(cmd), quiet=quiet, shell=True)
|
||||||
except subprocess.CalledProcessError as e:
|
except subprocess.CalledProcessError as e:
|
||||||
|
@ -52,6 +52,7 @@ class TestCase(unittest.TestCase):
|
|||||||
"--kolla-config-path", "/path/to/config",
|
"--kolla-config-path", "/path/to/config",
|
||||||
"-ke", "ev_name1=ev_value1",
|
"-ke", "ev_name1=ev_value1",
|
||||||
"-ki", "/path/to/inventory",
|
"-ki", "/path/to/inventory",
|
||||||
|
"-kl", "host1:host2",
|
||||||
"-kt", "tag1,tag2",
|
"-kt", "tag1,tag2",
|
||||||
]
|
]
|
||||||
parsed_args = parser.parse_args(args)
|
parsed_args = parser.parse_args(args)
|
||||||
@ -63,6 +64,7 @@ class TestCase(unittest.TestCase):
|
|||||||
"--configdir", "/path/to/config",
|
"--configdir", "/path/to/config",
|
||||||
"--passwords", "/path/to/config/passwords.yml",
|
"--passwords", "/path/to/config/passwords.yml",
|
||||||
"-e", "ev_name1=ev_value1",
|
"-e", "ev_name1=ev_value1",
|
||||||
|
"--limit", "host1:host2",
|
||||||
"--tags", "tag1,tag2",
|
"--tags", "tag1,tag2",
|
||||||
]
|
]
|
||||||
expected_cmd = " ".join(expected_cmd)
|
expected_cmd = " ".join(expected_cmd)
|
||||||
@ -79,6 +81,7 @@ class TestCase(unittest.TestCase):
|
|||||||
"--kolla-config-path", "/path/to/config",
|
"--kolla-config-path", "/path/to/config",
|
||||||
"--kolla-extra-vars", "ev_name1=ev_value1",
|
"--kolla-extra-vars", "ev_name1=ev_value1",
|
||||||
"--kolla-inventory", "/path/to/inventory",
|
"--kolla-inventory", "/path/to/inventory",
|
||||||
|
"--kolla-limit", "host1:host2",
|
||||||
"--kolla-tags", "tag1,tag2",
|
"--kolla-tags", "tag1,tag2",
|
||||||
]
|
]
|
||||||
parsed_args = parser.parse_args(args)
|
parsed_args = parser.parse_args(args)
|
||||||
@ -90,6 +93,7 @@ class TestCase(unittest.TestCase):
|
|||||||
"--configdir", "/path/to/config",
|
"--configdir", "/path/to/config",
|
||||||
"--passwords", "/path/to/config/passwords.yml",
|
"--passwords", "/path/to/config/passwords.yml",
|
||||||
"-e", "ev_name1=ev_value1",
|
"-e", "ev_name1=ev_value1",
|
||||||
|
"--limit", "host1:host2",
|
||||||
"--tags", "tag1,tag2",
|
"--tags", "tag1,tag2",
|
||||||
]
|
]
|
||||||
expected_cmd = " ".join(expected_cmd)
|
expected_cmd = " ".join(expected_cmd)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user