Merge "Generate inventory without any overcloud"
This commit is contained in:
commit
09a5e08045
|
@ -52,9 +52,10 @@ opts = [
|
|||
'inventory data. If a comma delimited list '
|
||||
'of stacks is passed, the inventory will '
|
||||
'contain the union of those stacks.')),
|
||||
cfg.ListOpt('stack', help=('This arg has the same effect '
|
||||
'as --plan. If both are specified,'
|
||||
' --stack will take precedence.')),
|
||||
cfg.ListOpt('stack', default=None,
|
||||
help=('This arg has the same effect '
|
||||
'as --plan. If both are specified,'
|
||||
' --stack will take precedence.')),
|
||||
cfg.StrOpt('ansible_ssh_user', default=os.environ.get('ANSIBLE_SSH_USER',
|
||||
'heat-admin')),
|
||||
cfg.StrOpt('undercloud-connection',
|
||||
|
@ -88,8 +89,6 @@ def _parse_config():
|
|||
if configs.auth_url:
|
||||
if '/v2.0' in configs.auth_url:
|
||||
configs.auth_url = configs.auth_url.replace('/v2.0', '/v3')
|
||||
if not configs.plan:
|
||||
configs.plan = ['overcloud']
|
||||
return configs
|
||||
|
||||
|
||||
|
@ -160,9 +159,18 @@ def main():
|
|||
else:
|
||||
raise RuntimeError("No auth provided.")
|
||||
|
||||
inventory_map = {}
|
||||
for _plan in (configs.stack or configs.plan):
|
||||
inventory_map[_plan] = inv.TripleoInventory(
|
||||
# Stack option takes precedence on plan:
|
||||
if configs.stack:
|
||||
plans = configs.stack
|
||||
elif configs.plan:
|
||||
plans = configs.plan
|
||||
else:
|
||||
plans = utils.list_plan_and_stack(
|
||||
utils.get_heat_client(auth_variables),
|
||||
utils.get_swift_client(auth_variables))
|
||||
|
||||
if plans is None:
|
||||
inventory = inv.TripleoInventory(
|
||||
session=utils.get_auth_session(auth_variables),
|
||||
hclient=utils.get_heat_client(auth_variables),
|
||||
auth_url=auth_variables.get('auth_url'),
|
||||
|
@ -170,14 +178,31 @@ def main():
|
|||
project_name=auth_variables.get('project_name'),
|
||||
username=auth_variables.get('username'),
|
||||
ansible_ssh_user=configs.ansible_ssh_user,
|
||||
plan_name=_plan,
|
||||
plan_name=plans,
|
||||
ansible_python_interpreter=configs.ansible_python_interpreter,
|
||||
undercloud_connection=configs.undercloud_connection,
|
||||
undercloud_key_file=configs.undercloud_key_file,
|
||||
host_network=configs.ssh_network,
|
||||
serial=configs.serial)
|
||||
else:
|
||||
inventory_map = {}
|
||||
for _plan in plans:
|
||||
inventory_map[str(_plan)] = inv.TripleoInventory(
|
||||
session=utils.get_auth_session(auth_variables),
|
||||
hclient=utils.get_heat_client(auth_variables),
|
||||
auth_url=auth_variables.get('auth_url'),
|
||||
cacert=auth_variables.get('cacert'),
|
||||
project_name=auth_variables.get('project_name'),
|
||||
username=auth_variables.get('username'),
|
||||
ansible_ssh_user=configs.ansible_ssh_user,
|
||||
plan_name=_plan,
|
||||
ansible_python_interpreter=configs.ansible_python_interpreter,
|
||||
undercloud_connection=configs.undercloud_connection,
|
||||
undercloud_key_file=configs.undercloud_key_file,
|
||||
host_network=configs.ssh_network,
|
||||
serial=configs.serial)
|
||||
|
||||
inventory = invs.TripleoInventories(inventory_map)
|
||||
inventory = invs.TripleoInventories(inventory_map)
|
||||
if configs.list:
|
||||
try:
|
||||
inventory_list = inventory.list()
|
||||
|
|
|
@ -33,3 +33,7 @@ VALIDATION_GROUPS_INFO = (
|
|||
if os.path.exists('/usr/share/ansible/groups.yaml')
|
||||
else os.path.join(DEFAULT_VALIDATIONS_LEGACY_BASEDIR, 'groups.yaml')
|
||||
)
|
||||
|
||||
# TRIPLEO_META_USAGE_KEY is inserted into metadata for containers created in
|
||||
# Swift via SwiftPlanStorageBackend to identify them from other containers
|
||||
TRIPLEO_META_USAGE_KEY = 'x-container-meta-usage-tripleo'
|
||||
|
|
|
@ -25,11 +25,14 @@ except AttributeError:
|
|||
|
||||
from glanceclient import client as glance_client
|
||||
from heatclient import client as heat_client
|
||||
from heatclient import exc as heat_exc
|
||||
from ironicclient import client as ironic_client
|
||||
from keystoneauth1.identity import generic as ks_id
|
||||
from keystoneauth1 import session as ks_session
|
||||
from novaclient import client as nova_client
|
||||
from swiftclient.client import Connection
|
||||
from swiftclient import exceptions as swiftexceptions
|
||||
from tripleo_validations import constants
|
||||
|
||||
|
||||
def get_auth_session(auth_variables):
|
||||
|
@ -57,11 +60,11 @@ def get_auth_session(auth_variables):
|
|||
|
||||
|
||||
def get_swift_client(auth_variables):
|
||||
return Connection(preauthurl=auth_variables.get('undercloud_swift_url'),
|
||||
preauthtoken=auth_variables.get('os_auth_token'),
|
||||
retries=10,
|
||||
starting_backoff=3,
|
||||
max_backoff=120)
|
||||
return Connection(authurl=auth_variables.get('auth_url'),
|
||||
user=auth_variables.get('username'),
|
||||
key=auth_variables.get('password'),
|
||||
auth_version='3',
|
||||
tenant_name=auth_variables.get('project_name'))
|
||||
|
||||
|
||||
def get_nova_client(auth_variables):
|
||||
|
@ -83,6 +86,22 @@ def get_ironic_client(auth_variables):
|
|||
)
|
||||
|
||||
|
||||
def list_plan_and_stack(hclient, swiftclient):
|
||||
try:
|
||||
stacks = [s.stack_name for s in hclient.stacks.list()]
|
||||
except heat_exc.HTTPNotFound:
|
||||
return None
|
||||
try:
|
||||
plan_list = []
|
||||
for ac in swiftclient.get_account()[1]:
|
||||
container = swiftclient.get_container(ac['name'])[0]
|
||||
if constants.TRIPLEO_META_USAGE_KEY in container.keys():
|
||||
plan_list.append(ac['name'])
|
||||
except swiftexceptions.ClientException:
|
||||
return None
|
||||
return list(set(stacks).intersection(list(plan_list)))
|
||||
|
||||
|
||||
def filtered(obj):
|
||||
"""Only return properties of obj whose value can be properly serialized."""
|
||||
return {k: v for k, v in obj.__dict__.items()
|
||||
|
|
Loading…
Reference in New Issue