Some small changes to tower openstack work

1) Favor private addresses in the openstack inventory sync
2) Force refresh
3) use hostId and promote it to the top level vars object so we can
track individual host changes
This commit is contained in:
Matthew Jones
2015-04-20 15:11:06 -04:00
parent e87f90b39b
commit f45d75c06c
4 changed files with 21 additions and 5 deletions

View File

@@ -938,7 +938,7 @@ class RunInventoryUpdate(BaseTask):
username=credential.username, username=credential.username,
password=decrypt_field(credential, "password"), password=decrypt_field(credential, "password"),
project_name=credential.project) project_name=credential.project)
openstack_data = {"clouds": {"devstack": {"auth": openstack_auth}}} openstack_data = {"clouds": {"devstack": {"private": "true", "auth": openstack_auth}}}
return yaml.safe_dump(openstack_data, default_flow_style=False, allow_unicode=True) return yaml.safe_dump(openstack_data, default_flow_style=False, allow_unicode=True)
cp = ConfigParser.ConfigParser() cp = ConfigParser.ConfigParser()

View File

@@ -1898,3 +1898,19 @@ class InventoryUpdatesTest(BaseTransactionTest):
other_inv_src_opts = {'source': 'custom', 'source_script': script_data['id']} other_inv_src_opts = {'source': 'custom', 'source_script': script_data['id']}
with self.current_user(self.super_django_user): with self.current_user(self.super_django_user):
self.put(other_inv_src, other_inv_src_opts, expect=400) self.put(other_inv_src, other_inv_src_opts, expect=400)
def test_update_from_openstack(self):
api_url = getattr(settings, 'TEST_OPENSTACK_HOST', '')
api_user = getattr(settings, 'TEST_OPENSTACK_USER', '')
api_password = getattr(settings, 'TEST_OPENSTACK_PASSWORD', '')
api_project = getattr(settings, 'TEST_OPENSTACK_PROJECT', '')
if not all([api_url, api_user, api_password, api_project]):
self.skipTest("No test openstack credentials defined")
self.create_test_license_file()
credential = Credential.objects.create(kind='openstack',
host=api_url,
username=api_user,
password=api_password,
project=api_project)
inventory_source = self.update_inventory_source(self.group, source='openstack', credential=credential)
self.check_inventory_source(inventory_source)

View File

@@ -56,7 +56,7 @@ class OpenStackInventory(object):
self.openstack_config = os_client_config.config.OpenStackConfig( self.openstack_config = os_client_config.config.OpenStackConfig(
config_files) config_files)
self.clouds = shade.openstack_clouds(self.openstack_config) self.clouds = shade.openstack_clouds(self.openstack_config)
self.refresh = refresh self.refresh = True
self.cache_max_age = self.openstack_config.get_cache_max_age() self.cache_max_age = self.openstack_config.get_cache_max_age()
cache_path = self.openstack_config.get_cache_path() cache_path = self.openstack_config.get_cache_path()
@@ -101,9 +101,9 @@ class OpenStackInventory(object):
continue continue
server_vars = meta['server_vars'] server_vars = meta['server_vars']
hostvars[server.name][ hostvars[server.name]['ansible_ssh_host'] = server_vars['interface_ip']
'ansible_ssh_host'] = server_vars['interface_ip']
hostvars[server.name]['openstack'] = server_vars hostvars[server.name]['openstack'] = server_vars
hostvars[server.name]['hostId'] = server_vars['hostId']
for group in meta['groups']: for group in meta['groups']:
groups[group].append(server.name) groups[group].append(server.name)

View File

@@ -530,7 +530,7 @@ OPENSTACK_ENABLED_VALUE = 'ACTIVE'
OPENSTACK_GROUP_FILTER = r'^.+$' OPENSTACK_GROUP_FILTER = r'^.+$'
OPENSTACK_HOST_FILTER = r'^.+$' OPENSTACK_HOST_FILTER = r'^.+$'
OPENSTACK_EXCLUDE_EMPTY_GROUPS = True OPENSTACK_EXCLUDE_EMPTY_GROUPS = True
OPENSTACK_INSTANCE_ID_VAR = None OPENSTACK_INSTANCE_ID_VAR = "hostId"
# --------------------- # ---------------------
# -- Activity Stream -- # -- Activity Stream --