diff options
author | Tzu-Mainn Chen <tzumainn@redhat.com> | 2018-01-29 16:02:16 +0100 |
---|---|---|
committer | Tzu-Mainn Chen <tzumainn@redhat.com> | 2018-01-29 16:02:16 +0100 |
commit | e88c30bd93413f303c9d27d1a26c6e473eb11cb4 (patch) | |
tree | d2e3007e182502094a7f22b58f7bb9284d499f4c | |
parent | 693824ba52eca910fc6df760f7d663892bb2b31c (diff) | |
download | openshift-e88c30bd93413f303c9d27d1a26c6e473eb11cb4.tar.gz openshift-e88c30bd93413f303c9d27d1a26c6e473eb11cb4.tar.bz2 openshift-e88c30bd93413f303c9d27d1a26c6e473eb11cb4.tar.xz openshift-e88c30bd93413f303c9d27d1a26c6e473eb11cb4.zip |
code simplification and lint cleanup
-rwxr-xr-x | playbooks/openstack/inventory.py | 51 |
1 files changed, 31 insertions, 20 deletions
diff --git a/playbooks/openstack/inventory.py b/playbooks/openstack/inventory.py index 98ce57c8d..db4eb9809 100755 --- a/playbooks/openstack/inventory.py +++ b/playbooks/openstack/inventory.py @@ -15,18 +15,10 @@ import json import shade -def build_inventory(): - '''Build the dynamic inventory.''' - cloud = shade.openstack_cloud() - +def base_openshift_inventory(cluster_hosts): + '''Set the base openshift inventory.''' inventory = {} - # TODO(shadower): filter the servers based on the `OPENSHIFT_CLUSTER` - # environment variable. - cluster_hosts = [ - server for server in cloud.list_servers() - if 'metadata' in server and 'clusterid' in server.metadata] - masters = [server.name for server in cluster_hosts if server.metadata['host-type'] == 'master'] @@ -67,6 +59,32 @@ def build_inventory(): inventory['dns'] = {'hosts': dns} inventory['lb'] = {'hosts': load_balancers} + return inventory + +def get_docker_storage_mountpoints(volumes): + '''Check volumes to see if they're being used for docker storage''' + docker_storage_mountpoints = {} + for volume in volumes: + if volume.metadata.get('purpose') == "openshift_docker_storage": + for attachment in volume.attachments: + if attachment.server_id in docker_storage_mountpoints: + docker_storage_mountpoints[attachment.server_id].append(attachment.device) + else: + docker_storage_mountpoints[attachment.server_id] = [attachment.device] + return docker_storage_mountpoints + +def build_inventory(): + '''Build the dynamic inventory.''' + cloud = shade.openstack_cloud() + + # TODO(shadower): filter the servers based on the `OPENSHIFT_CLUSTER` + # environment variable. + cluster_hosts = [ + server for server in cloud.list_servers() + if 'metadata' in server and 'clusterid' in server.metadata] + + inventory = base_openshift_inventory(cluster_hosts) + for server in cluster_hosts: if 'group' in server.metadata: group = server.metadata.group @@ -77,14 +95,7 @@ def build_inventory(): inventory['_meta'] = {'hostvars': {}} # cinder volumes used for docker storage - docker_storage_volume_mountpoints = {} - for volume in cloud.list_volumes(): - if 'purpose' in volume.metadata and volume.metadata.purpose == "openshift_docker_storage": - for attachment in volume.attachments: - if attachment.server_id in docker_storage_volume_mountpoints: - docker_storage_volume_mountpoints[attachment.server_id].append(attachment.device) - else: - docker_storage_volume_mountpoints[attachment.server_id] = [attachment.device] + docker_storage_mountpoints = get_docker_storage_mountpoints(cloud.list_volumes()) for server in cluster_hosts: ssh_ip_address = server.public_v4 or server.private_v4 @@ -123,8 +134,8 @@ def build_inventory(): # check for attached docker storage volumes if 'os-extended-volumes:volumes_attached' in server: - if server.id in docker_storage_volume_mountpoints: - hostvars['docker_storage_volume_mountpoints'] = ' '.join(docker_storage_volume_mountpoints[server.id]) + if server.id in docker_storage_mountpoints: + hostvars['docker_storage_mountpoints'] = ' '.join(docker_storage_mountpoints[server.id]) inventory['_meta']['hostvars'][server.name] = hostvars return inventory |