From 6525120c157b9bdf19453cbf9888c12118d3995c Mon Sep 17 00:00:00 2001 From: Matthew Jones Date: Mon, 13 Apr 2015 15:05:58 -0400 Subject: [PATCH] model and task support for launching openstack inventory updates --- awx/main/constants.py | 2 +- awx/main/models/base.py | 2 +- awx/main/models/credential.py | 1 + awx/main/models/inventory.py | 6 ++++++ awx/main/tasks.py | 12 ++++++++++++ awx/plugins/inventory/openstack.py | 2 +- awx/settings/defaults.py | 9 +++++++++ 7 files changed, 31 insertions(+), 3 deletions(-) diff --git a/awx/main/constants.py b/awx/main/constants.py index 6db7db00de..d4f84af91f 100644 --- a/awx/main/constants.py +++ b/awx/main/constants.py @@ -1,5 +1,5 @@ # Copyright (c) 2014 AnsibleWorks, Inc. # All Rights Reserved. -CLOUD_PROVIDERS = ('azure', 'ec2', 'gce', 'rax', 'vmware') +CLOUD_PROVIDERS = ('azure', 'ec2', 'gce', 'rax', 'vmware', 'openstack') SCHEDULEABLE_PROVIDERS = CLOUD_PROVIDERS + ('custom',) diff --git a/awx/main/models/base.py b/awx/main/models/base.py index 891c5292cf..039f805629 100644 --- a/awx/main/models/base.py +++ b/awx/main/models/base.py @@ -55,7 +55,7 @@ PERMISSION_TYPE_CHOICES = [ (PERM_JOBTEMPLATE_CREATE, _('Create a Job Template')), ] -CLOUD_INVENTORY_SOURCES = ['ec2', 'rax', 'vmware', 'gce', 'azure', 'custom'] +CLOUD_INVENTORY_SOURCES = ['ec2', 'rax', 'vmware', 'gce', 'azure', 'openstack', 'custom'] class VarsDictProperty(object): diff --git a/awx/main/models/credential.py b/awx/main/models/credential.py index 6a2f838b97..334b464d68 100644 --- a/awx/main/models/credential.py +++ b/awx/main/models/credential.py @@ -34,6 +34,7 @@ class Credential(PasswordFieldsModel, CommonModelNameNotUnique): ('vmware', _('VMware vCenter')), ('gce', _('Google Compute Engine')), ('azure', _('Microsoft Azure')), + ('openstack', _('Openstack')), ] BECOME_METHOD_CHOICES = [ diff --git a/awx/main/models/inventory.py b/awx/main/models/inventory.py index a9140eff49..c5f177abec 100644 --- a/awx/main/models/inventory.py +++ b/awx/main/models/inventory.py @@ -740,6 +740,7 @@ class InventorySourceOptions(BaseModel): ('gce', _('Google Compute Engine')), ('azure', _('Microsoft Azure')), ('vmware', _('VMware vCenter')), + ('openstack', _('Openstack')), ('custom', _('Custom Script')), ] @@ -963,6 +964,11 @@ class InventorySourceOptions(BaseModel): """ return [('all', 'All')] + @classmethod + def get_openstack_region_choices(self): + """I don't think openstack has regions""" + return [('all', 'All')] + def clean_credential(self): if not self.source: return None diff --git a/awx/main/tasks.py b/awx/main/tasks.py index 87ddbebc64..4d176c8506 100644 --- a/awx/main/tasks.py +++ b/awx/main/tasks.py @@ -20,6 +20,7 @@ import urlparse import uuid from distutils.version import LooseVersion as Version import dateutil.parser +import yaml # Pexpect import pexpect @@ -931,6 +932,15 @@ class RunInventoryUpdate(BaseTask): credential = inventory_update.credential return decrypt_field(credential, 'ssh_key_data') + if inventory_update.source == 'openstack': + credential = inventory_update.credential + openstack_auth = dict(auth_url=credential.host, + username=credential.username, + password=decrypt_field(credential, "password"), + project_name=credential.project) + openstack_data = {"clouds": {"devstack": {"auth": openstack_auth}}} + return yaml.safe_dump(openstack_data, default_flow_style=False, allow_unicode=True) + cp = ConfigParser.ConfigParser() # Build custom ec2.ini for ec2 inventory script to use. if inventory_update.source == 'ec2': @@ -1051,6 +1061,8 @@ class RunInventoryUpdate(BaseTask): env['GCE_EMAIL'] = passwords.get('source_username', '') env['GCE_PROJECT'] = passwords.get('source_project', '') env['GCE_PEM_FILE_PATH'] = kwargs['private_data_file'] + elif inventory_update.source == 'openstack': + env['OPENSTACK_CONFIG_FILE'] = kwargs.get('private_data_file', '') elif inventory_update.source == 'file': # FIXME: Parse source_env to dict, update env. pass diff --git a/awx/plugins/inventory/openstack.py b/awx/plugins/inventory/openstack.py index 491c192f99..54309007b6 100755 --- a/awx/plugins/inventory/openstack.py +++ b/awx/plugins/inventory/openstack.py @@ -153,4 +153,4 @@ def main(): if __name__ == '__main__': - main() \ No newline at end of file + main() diff --git a/awx/settings/defaults.py b/awx/settings/defaults.py index 3610879c02..9f361faed8 100644 --- a/awx/settings/defaults.py +++ b/awx/settings/defaults.py @@ -522,6 +522,15 @@ AZURE_HOST_FILTER = r'^.+$' AZURE_EXCLUDE_EMPTY_GROUPS = True AZURE_INSTANCE_ID_VAR = None +# --------------------- +# ----- OpenStack ----- +# --------------------- +OPENSTACK_ENABLED_VAR = 'status' +OPENSTACK_ENABLED_VALUE = 'ACTIVE' +OPENSTACK_GROUP_FILTER = r'^.+$' +OPENSTACK_HOST_FILTER = r'^.+$' +OPENSTACK_EXCLUDE_EMPTY_GROUPS = True +OPENSTACK_INSTANCE_ID_VAR = None # --------------------- # -- Activity Stream --