summaryrefslogtreecommitdiffstats
path: root/playbooks/openstack
diff options
context:
space:
mode:
authorTzu-Mainn Chen <tzumainn@redhat.com>2018-01-29 16:02:16 +0100
committerTzu-Mainn Chen <tzumainn@redhat.com>2018-01-29 16:02:16 +0100
commite88c30bd93413f303c9d27d1a26c6e473eb11cb4 (patch)
treed2e3007e182502094a7f22b58f7bb9284d499f4c /playbooks/openstack
parent693824ba52eca910fc6df760f7d663892bb2b31c (diff)
downloadopenshift-e88c30bd93413f303c9d27d1a26c6e473eb11cb4.tar.gz
openshift-e88c30bd93413f303c9d27d1a26c6e473eb11cb4.tar.bz2
openshift-e88c30bd93413f303c9d27d1a26c6e473eb11cb4.tar.xz
openshift-e88c30bd93413f303c9d27d1a26c6e473eb11cb4.zip
code simplification and lint cleanup
Diffstat (limited to 'playbooks/openstack')
-rwxr-xr-xplaybooks/openstack/inventory.py51
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