1
0
mirror of https://github.com/ansible/awx.git synced 2024-11-01 08:21:15 +03:00

Added vmware support to tasks.

This commit is contained in:
Luke Sneeringer 2014-07-16 14:42:18 -05:00
parent 89f65d8ba0
commit 7548ffc6dd
2 changed files with 100 additions and 30 deletions

View File

@ -837,19 +837,27 @@ class RunInventoryUpdate(BaseTask):
if credential: if credential:
passwords['source_username'] = credential.username passwords['source_username'] = credential.username
passwords['source_password'] = decrypt_field(credential, 'password') passwords['source_password'] = decrypt_field(credential, 'password')
passwords['source_host'] = credential.host
return passwords return passwords
def build_env(self, inventory_update, **kwargs): def build_env(self, inventory_update, **kwargs):
''' """Build environment dictionary for inventory import.
Build environment dictionary for inventory import.
''' This is the mechanism by which any data that needs to be passed
env = super(RunInventoryUpdate, self).build_env(inventory_update, **kwargs) to the inventory update script is set up. In particular, this is how
inventory update is aware of its proper credentials.
"""
env = super(RunInventoryUpdate, self).build_env(inventory_update,
**kwargs)
# Pass inventory source ID to inventory script. # Pass inventory source ID to inventory script.
env['INVENTORY_SOURCE_ID'] = str(inventory_update.inventory_source_id) env['INVENTORY_SOURCE_ID'] = str(inventory_update.inventory_source_id)
# Set environment variables specific to each source. # Set environment variables specific to each source.
passwords = kwargs.get('passwords', {})
if inventory_update.source == 'ec2': if inventory_update.source == 'ec2':
env['AWS_ACCESS_KEY_ID'] = kwargs.get('passwords', {}).get('source_username', '') env['AWS_ACCESS_KEY_ID'] = passwords.get('source_username', '')
env['AWS_SECRET_ACCESS_KEY'] = kwargs.get('passwords', {}).get('source_password', '') env['AWS_SECRET_ACCESS_KEY'] = passwords.get('source_password', '')
env['EC2_INI_PATH'] = kwargs.get('private_data_file', '') env['EC2_INI_PATH'] = kwargs.get('private_data_file', '')
elif inventory_update.source == 'rax': elif inventory_update.source == 'rax':
env['RAX_CREDS_FILE'] = kwargs.get('private_data_file', '') env['RAX_CREDS_FILE'] = kwargs.get('private_data_file', '')
@ -857,48 +865,81 @@ class RunInventoryUpdate(BaseTask):
# Set this environment variable so the vendored package won't # Set this environment variable so the vendored package won't
# complain about not being able to determine its version number. # complain about not being able to determine its version number.
env['PBR_VERSION'] = '0.5.21' env['PBR_VERSION'] = '0.5.21'
elif inventory_update.source == 'vmware':
env['VMWARE_HOST'] = passwords.get('source_host', '')
env['VMWARE_USER'] = passwords.get('source_username', '')
env['VMWARE_PASSWORD'] = passwords.get('source_password', '')
elif inventory_update.source == 'file': elif inventory_update.source == 'file':
# FIXME: Parse source_env to dict, update env. # FIXME: Parse source_env to dict, update env.
pass pass
return env return env
def build_args(self, inventory_update, **kwargs): def build_args(self, inventory_update, **kwargs):
''' """Build the command line argument list for running an inventory
Build command line argument list for running inventory import. import.
''' """
# Get the inventory source and inventory.
inventory_source = inventory_update.inventory_source inventory_source = inventory_update.inventory_source
inventory = inventory_source.group.inventory inventory = inventory_source.group.inventory
# Piece together the initial command to run via. the shell.
args = ['awx-manage', 'inventory_import'] args = ['awx-manage', 'inventory_import']
args.extend(['--inventory-id', str(inventory.pk)]) args.extend(['--inventory-id', str(inventory.pk)])
# Add appropriate arguments for overwrite if the inventory_update
# object calls for it.
if inventory_update.overwrite: if inventory_update.overwrite:
args.append('--overwrite') args.append('--overwrite')
if inventory_update.overwrite_vars: if inventory_update.overwrite_vars:
args.append('--overwrite-vars') args.append('--overwrite-vars')
args.append('--source') args.append('--source')
if inventory_update.source == 'ec2':
ec2_path = self.get_path_to('..', 'plugins', 'inventory', 'ec2.py') # If this is a cloud-based inventory (e.g. from AWS, Rackspace, etc.)
args.append(ec2_path) # then we need to set some extra flags based on settings in
args.extend(['--enabled-var', settings.EC2_ENABLED_VAR]) # Tower.
args.extend(['--enabled-value', settings.EC2_ENABLED_VALUE]) #
args.extend(['--group-filter', settings.EC2_GROUP_FILTER]) # These settings are "per-cloud-provider"; it's entirely possible that
args.extend(['--host-filter', settings.EC2_HOST_FILTER]) # they will be different between cloud providers if a Tower user
if settings.EC2_EXCLUDE_EMPTY_GROUPS: # actively uses more than one.
if inventory_update.source in ('ec2', 'rax', 'vmware'):
# We need to reference the source's code frequently, assign it
# to a shorter variable. :)
src = inventory_update.source
# Get the path to the inventory plugin, and append it to our
# arguments.
plugin_path = self.get_path_to('..', 'plugins', 'inventory',
'%s.py' % src)
args.append(plugin_path)
# Add several options to the shell arguments based on the
# cloud-provider-specific setting in the Tower configuration.
args.extend(['--enabled-var',
getattr(settings, '%s_ENABLED_VAR' % src.upper())])
args.extend(['--enabled-value',
getattr(settings, '%s_ENABLED_VALUE' % src.upper())])
args.extend(['--group-filter',
getattr(settings, '%s_GROUP_FILTER' % src.upper())])
args.extend(['--host-filter',
getattr(settings, '%s_HOST_FILTER' % src.upper())])
# We might have a flag set to exclude empty groups; if we do,
# add that flag to the shell arguments.
if getattr(settings, '%s_EXCLUDE_EMPTY_GROUPS' % src.upper()):
args.append('--exclude-empty-groups') args.append('--exclude-empty-groups')
if settings.EC2_INSTANCE_ID_VAR:
args.extend(['--instance-id-var', settings.EC2_INSTANCE_ID_VAR]) # We might have a flag for an instance ID variable; if we do,
elif inventory_update.source == 'rax': # add it to the shell arguments.
rax_path = self.get_path_to('..', 'plugins', 'inventory', 'rax.py') if getattr(settings, '%s_INSTANCE_ID_VAR' % src.upper()):
args.append(rax_path) args.extend([
args.extend(['--enabled-var', settings.RAX_ENABLED_VAR]) '--instance-id-var',
args.extend(['--enabled-value', settings.RAX_ENABLED_VALUE]) getattr(settings, '%s_INSTANCE_ID_VAR' % src.upper()),
args.extend(['--group-filter', settings.RAX_GROUP_FILTER]) ])
args.extend(['--host-filter', settings.RAX_HOST_FILTER])
if settings.RAX_EXCLUDE_EMPTY_GROUPS:
args.append('--exclude-empty-groups')
if settings.RAX_INSTANCE_ID_VAR:
args.extend(['--instance-id-var', settings.RAX_INSTANCE_ID_VAR])
elif inventory_update.source == 'file': elif inventory_update.source == 'file':
args.append(inventory_update.source_path) args.append(inventory_update.source_path)
verbosity = getattr(settings, 'INVENTORY_UPDATE_VERBOSITY', 1) verbosity = getattr(settings, 'INVENTORY_UPDATE_VERBOSITY', 1)
args.append('-v%d' % verbosity) args.append('-v%d' % verbosity)
if settings.DEBUG: if settings.DEBUG:

View File

@ -347,6 +347,10 @@ RAX_GROUP_FILTER = r'^(?!instance-.+).+$'
RAX_HOST_FILTER = r'^.+$' RAX_HOST_FILTER = r'^.+$'
RAX_EXCLUDE_EMPTY_GROUPS = True RAX_EXCLUDE_EMPTY_GROUPS = True
# ----------------
# -- Amazon EC2 --
# ----------------
# AWS does not appear to provide pretty region names via any API, so store the # AWS does not appear to provide pretty region names via any API, so store the
# list of names here. The available region IDs will be pulled from boto. # list of names here. The available region IDs will be pulled from boto.
# http://docs.aws.amazon.com/general/latest/gr/rande.html#ec2_region # http://docs.aws.amazon.com/general/latest/gr/rande.html#ec2_region
@ -381,6 +385,31 @@ EC2_GROUP_FILTER = r'^(?!i-[a-f0-9]{8,}).+$'
EC2_HOST_FILTER = r'^.+(?<!rds\.amazonaws\.com)$' EC2_HOST_FILTER = r'^.+(?<!rds\.amazonaws\.com)$'
EC2_EXCLUDE_EMPTY_GROUPS = True EC2_EXCLUDE_EMPTY_GROUPS = True
# ------------
# -- VMWare --
# ------------
VMWARE_REGION_NAMES = {}
VMWARE_REGIONS_BLACKLIST = []
# Inventory variable name/values for determining whether a host is
# active in vSphere.
VMWARE_ENABLED_VAR = 'status'
VMWARE_ENABLED_VALUE = 'POWERED ON'
# Inventory variable name containing the unique instance ID.
VMWARE_INSTANCE_ID_VAR = 'guest_id'
# Filter for allowed group and host names when importing inventory
# from EC2.
VMWARE_GROUP_FILTER = r'^.+$'
VMWARE_HOST_FILTER = r'^.+$'
VMWARE_EXCLUDE_EMPTY_GROUPS = True
# ---------------------
# -- Activity Stream --
# ---------------------
# Defaults for enabling/disabling activity stream. # Defaults for enabling/disabling activity stream.
ACTIVITY_STREAM_ENABLED = True ACTIVITY_STREAM_ENABLED = True
ACTIVITY_STREAM_ENABLED_FOR_INVENTORY_SYNC = False ACTIVITY_STREAM_ENABLED_FOR_INVENTORY_SYNC = False