From 693824ba52eca910fc6df760f7d663892bb2b31c Mon Sep 17 00:00:00 2001 From: Tzu-Mainn Chen Date: Fri, 26 Jan 2018 17:01:42 +0000 Subject: add cinder mountpoint to inventory --- playbooks/openstack/inventory.py | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) (limited to 'playbooks/openstack') diff --git a/playbooks/openstack/inventory.py b/playbooks/openstack/inventory.py index 76e658eb7..98ce57c8d 100755 --- a/playbooks/openstack/inventory.py +++ b/playbooks/openstack/inventory.py @@ -76,6 +76,16 @@ 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] + for server in cluster_hosts: ssh_ip_address = server.public_v4 or server.private_v4 hostvars = { @@ -111,9 +121,13 @@ def build_inventory(): if node_labels: hostvars['openshift_node_labels'] = node_labels + # 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]) + inventory['_meta']['hostvars'][server.name] = hostvars return inventory - if __name__ == '__main__': print(json.dumps(build_inventory(), indent=4, sort_keys=True)) -- cgit v1.2.3 From e88c30bd93413f303c9d27d1a26c6e473eb11cb4 Mon Sep 17 00:00:00 2001 From: Tzu-Mainn Chen Date: Mon, 29 Jan 2018 16:02:16 +0100 Subject: code simplification and lint cleanup --- playbooks/openstack/inventory.py | 51 ++++++++++++++++++++++++---------------- 1 file changed, 31 insertions(+), 20 deletions(-) (limited to 'playbooks/openstack') 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 -- cgit v1.2.3 From 138d610441cc5e5837a416dd1fc45c0e8ede27a1 Mon Sep 17 00:00:00 2001 From: Tzu-Mainn Chen Date: Mon, 29 Jan 2018 16:17:36 +0100 Subject: flake cleanup --- playbooks/openstack/inventory.py | 3 +++ 1 file changed, 3 insertions(+) (limited to 'playbooks/openstack') diff --git a/playbooks/openstack/inventory.py b/playbooks/openstack/inventory.py index db4eb9809..d5a8c3e24 100755 --- a/playbooks/openstack/inventory.py +++ b/playbooks/openstack/inventory.py @@ -61,6 +61,7 @@ def base_openshift_inventory(cluster_hosts): return inventory + def get_docker_storage_mountpoints(volumes): '''Check volumes to see if they're being used for docker storage''' docker_storage_mountpoints = {} @@ -73,6 +74,7 @@ def get_docker_storage_mountpoints(volumes): docker_storage_mountpoints[attachment.server_id] = [attachment.device] return docker_storage_mountpoints + def build_inventory(): '''Build the dynamic inventory.''' cloud = shade.openstack_cloud() @@ -140,5 +142,6 @@ def build_inventory(): inventory['_meta']['hostvars'][server.name] = hostvars return inventory + if __name__ == '__main__': print(json.dumps(build_inventory(), indent=4, sort_keys=True)) -- cgit v1.2.3