Add support for Mirantis Cloud Platform. 83/42883/8
authorTaseer Ahmed <taseer94@gmail.com>
Mon, 16 Oct 2017 09:47:28 +0000 (14:47 +0500)
committerTaseer Ahmed <taseer94@gmail.com>
Mon, 16 Oct 2017 09:47:28 +0000 (14:47 +0500)
JIRA: QTIP-261

Change-Id: Ied9c3d91b25bc8dad7deb0cf30f83cd2b7855a92
Signed-off-by: Taseer Ahmed <taseer94@gmail.com>
qtip/ansible_library/modules/mcp.py [new file with mode: 0644]
qtip/cli/commands/cmd_project.py
resources/ansible_roles/qtip-generator/defaults/main.yml
resources/ansible_roles/qtip-generator/files/compute/group_vars/all.yml
resources/ansible_roles/qtip/tasks/gather-facts-mcp.yml [new file with mode: 0644]

diff --git a/qtip/ansible_library/modules/mcp.py b/qtip/ansible_library/modules/mcp.py
new file mode 100644 (file)
index 0000000..21be7bc
--- /dev/null
@@ -0,0 +1,105 @@
+#!/usr/bin/python
+
+###############################################################
+# Copyright (c) 2017 ZTE Corporation and others
+# taseer94@gmail.com
+#
+# All rights reserved. This program and the accompanying materials
+# are made available under the terms of the Apache License, Version 2.0
+# which accompanies this distribution, and is available at
+# http://www.apache.org/licenses/LICENSE-2.0
+##############################################################################
+
+import json
+from collections import defaultdict
+
+from ansible.module_utils.basic import AnsibleModule
+
+ANSIBLE_METADATA = {'metadata_version': '1.0',
+                    'status': ['preview'],
+                    'supported_by': 'community'}
+
+DOCUMENTATION = '''
+---
+module: mcp
+short_description: collecting facts from mcp environments
+description:
+    - Use this module to create a dynamic inventory from salt master (mcp).
+version_added: "1.0"
+author: "Taseer Ahmed (@Taseer)"
+options:
+notes:
+requirements:
+    - Host 'salt-master' is in ~/.ssh/config
+'''
+
+RETURN = '''
+ansible_facts:
+  description: facts collected for ansible
+  returned: success
+  type: dictionary
+  contains:
+    hosts:
+      description: host grouped by hostname, cluster, role and manufacture
+      type: dict
+    hosts_meta:
+      description: hosts meta data indexed by hostname
+      type: dict
+'''
+
+EXAMPLES = '''
+---
+- hosts: salt-master
+  tasks:
+  - name: collect facts of mcp hosts
+    mcp:
+  - debug: var=hostvars
+  - name: add compute node to ansible inventory
+    add_host:
+      name: "{{ hosts_meta[item]['ip'] }}"
+      groups: mcp-compute
+      ansible_user: root
+      ansible_ssh_common_args: '-o StrictHostKeyChecking=No -o ProxyJump=salt-master'
+    with_items: "{{ hosts.compute }}"
+- hosts: mcp-compute
+  tasks:
+  - name: check ssh connection
+    ping:
+'''
+
+
+def generate_inventory(nodes):
+    """Generate ansible inventory from node list in json format"""
+    hosts = defaultdict(list)
+    hosts_meta = {}
+    node_meta = {}
+
+    for key, value in nodes.iteritems():
+        if isinstance(value, dict):
+            for k, v in value.iteritems():
+                if k == "fqdn_ip4":
+                    node_meta['ansible_ssh_host'] = v[0]
+        node_meta['ansible_user'] = 'root'
+        hosts_meta[key] = node_meta
+        hosts['compute-nodes'].append(node_meta['ansible_ssh_host'])
+
+    return {'hosts': hosts, 'hosts_meta': hosts_meta}
+
+
+def main():
+    module = AnsibleModule(argument_spec=dict())
+
+    cmd = [module.get_bin_path('salt', True), '-C', '-t 5', '--static', '--out=json', 'cmp*', 'grains.item',
+           'fqdn_ip4', 'host']
+    (rc, out, err) = module.run_command(cmd)
+
+    if rc is not None and rc != 0:
+        return module.fail_json(msg=err)
+
+    nodes = json.loads(out)
+
+    module.exit_json(changed=False, ansible_facts=generate_inventory(nodes))
+
+
+if __name__ == '__main__':
+    main()
index 325594a..2836fa6 100644 (file)
@@ -50,7 +50,7 @@ def cli():
               default='opnfv-pod',
               help='Name of pod under test')
 @click.option('--installer-type',
-              type=click.Choice(['apex', 'fuel', 'manual']),
+              type=click.Choice(['apex', 'fuel', 'manual', 'mcp']),
               prompt='OPNFV Installer Type',
               default='manual',
               help='OPNFV installer')
index 527da6f..f6714b8 100644 (file)
@@ -14,6 +14,7 @@ installer_group:
   manual: dummy-group
   fuel: fuel-masters
   apex: apex-underclouds
+  mcp: salt-masters
 
 project_name: 'qtip-project'
 project_template: 'compute'
diff --git a/resources/ansible_roles/qtip/tasks/gather-facts-mcp.yml b/resources/ansible_roles/qtip/tasks/gather-facts-mcp.yml
new file mode 100644 (file)
index 0000000..5aed9e7
--- /dev/null
@@ -0,0 +1,14 @@
+##############################################################################
+# Copyright (c) 2017 ZTE Corporation and others.
+# taseer94@gmail.com
+#
+# All rights reserved. This program and the accompanying materials
+# are made available under the terms of the Apache License, Version 2.0
+# which accompanies this distribution, and is available at
+# http://www.apache.org/licenses/LICENSE-2.0
+##############################################################################
+
+---
+
+- name: gathering facts for mcp slave nodes
+  mcp:
\ No newline at end of file