model and task support for launching openstack inventory updates

This commit is contained in:
Matthew Jones
2015-04-13 15:05:58 -04:00
parent c1dc55fceb
commit 6525120c15
7 changed files with 31 additions and 3 deletions

View File

@@ -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',)

View File

@@ -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):

View File

@@ -34,6 +34,7 @@ class Credential(PasswordFieldsModel, CommonModelNameNotUnique):
('vmware', _('VMware vCenter')),
('gce', _('Google Compute Engine')),
('azure', _('Microsoft Azure')),
('openstack', _('Openstack')),
]
BECOME_METHOD_CHOICES = [

View File

@@ -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

View File

@@ -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

View File

@@ -153,4 +153,4 @@ def main():
if __name__ == '__main__':
main()
main()

View File

@@ -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 --