diff options
author | Lukasz Rajewski <lukasz.rajewski@orange.com> | 2019-06-04 11:13:56 +0200 |
---|---|---|
committer | Lukasz Rajewski <lukasz.rajewski@orange.com> | 2019-06-04 11:17:19 +0200 |
commit | 5163947788dfd249c4fd734c7ad6dff472257363 (patch) | |
tree | 8146d3b52dbc6a841f4041391b6cd4365d84c2ad | |
parent | d4b54ccb35a1fd16725f13e8a690b3becaaba22f (diff) |
Fix result status of ansible playbook execution
buildInventorySysCall is adapted for VNF track and
now is being called during VNF playbook execution
Change-Id: I26644e4c7251bfd63b3c628caee493794aad0098
Signed-off-by: Lukasz Rajewski <lukasz.rajewski@orange.com>
Issue-ID: CCSDK-1371
-rw-r--r-- | ansible-server/src/main/ansible-server/BuildPlaybookParams.py | 66 | ||||
-rwxr-xr-x | ansible-server/src/main/ansible-server/RestServer.py | 3 |
2 files changed, 43 insertions, 26 deletions
diff --git a/ansible-server/src/main/ansible-server/BuildPlaybookParams.py b/ansible-server/src/main/ansible-server/BuildPlaybookParams.py index e3a0b4b5..0ab4a7de 100644 --- a/ansible-server/src/main/ansible-server/BuildPlaybookParams.py +++ b/ansible-server/src/main/ansible-server/BuildPlaybookParams.py @@ -32,7 +32,8 @@ import subprocess import cherrypy -def buildInventorySysCall(ansible_path, ansible_inv, node_list, playbook_dir, target_inv, hostgrouplist, hostnamelist): +def buildInventorySysCall(ansible_path, ansible_inv, node_list, playbook_dir, target_inv, hostgrouplist, hostnamelist, + inventory_names=None): if not node_list: local_node_list = "host" local_credentials = "localhost ansible_connection=local" @@ -61,30 +62,19 @@ def buildInventorySysCall(ansible_path, ansible_inv, node_list, playbook_dir, ta data_inventory_orig[curr_group].append(line) f.close() - for node in node_list: - fail_flag = True - if "[" + node + "]" in data_inventory_orig: - if "[" + node + "]" not in data_inventory_target: - cherrypy.log("RESET", "[" + node + "]") - data_inventory_target["[" + node + "]"] = [] - else: - cherrypy.log("OK", "[" + node + "]") - fail_flag = False - for cred in data_inventory_orig["[" + node + "]"]: - data_inventory_target["[" + node + "]"].append(cred) - else: - for key in data_inventory_orig: - if node + " " in " ".join(data_inventory_orig[key]): - if key not in data_inventory_target: - data_inventory_target[key] = [] - for cred in data_inventory_orig[key]: - if node + " " in cred: - data_inventory_target[key].append(cred) - fail_flag = False - - if fail_flag: - data_inventory_target["[" + node + "]"] = \ - [node + " ansible_connection=ssh ansible_ssh_user=na ansible_ssh_private_key_file=na"] + if inventory_names is None: + for node in node_list: + processSingleNode(node, data_inventory_orig, data_inventory_target) + else: + for nodes_section in node_list: + if ('floating_ip_address-vip' in nodes_section) & ('ne_id_vip' in nodes_section): + if inventory_names == "VNFC" or inventory_names == "VM": + node = nodes_section['ne_id_vip'] + processSingleNode(node, data_inventory_orig, data_inventory_target) + for vm in nodes_section['vm-info']: + node = vm['ne_id'] + if inventory_names == "VNFC" or inventory_names == "VM": + processSingleNode(node, data_inventory_orig, data_inventory_target) f = open(playbook_dir + "/" + target_inv, "w") for key in data_inventory_target: @@ -96,6 +86,32 @@ def buildInventorySysCall(ansible_path, ansible_inv, node_list, playbook_dir, ta f.close() +def processSingleNode(node, data_inventory_orig, data_inventory_target): + fail_flag = True + if "[" + node + "]" in data_inventory_orig: + if "[" + node + "]" not in data_inventory_target: + cherrypy.log("RESET", "[" + node + "]") + data_inventory_target["[" + node + "]"] = [] + else: + cherrypy.log("OK", "[" + node + "]") + fail_flag = False + for cred in data_inventory_orig["[" + node + "]"]: + data_inventory_target["[" + node + "]"].append(cred) + else: + for key in data_inventory_orig: + if node + " " in " ".join(data_inventory_orig[key]): + if key not in data_inventory_target: + data_inventory_target[key] = [] + for cred in data_inventory_orig[key]: + if node + " " in cred: + data_inventory_target[key].append(cred) + fail_flag = False + + if fail_flag: + data_inventory_target["[" + node + "]"] = \ + [node + " ansible_connection=ssh ansible_ssh_user=na ansible_ssh_private_key_file=na"] + + def getPlaybookFile(ansible_path, playbook_name, playbook_type, playbook_dir): # Get playbooks from files diff --git a/ansible-server/src/main/ansible-server/RestServer.py b/ansible-server/src/main/ansible-server/RestServer.py index 8f5aa7ef..d00544de 100755 --- a/ansible-server/src/main/ansible-server/RestServer.py +++ b/ansible-server/src/main/ansible-server/RestServer.py @@ -562,7 +562,8 @@ def process_vnf_playbook(input_json, Id, EnvParameters, time_now): HostFilePath = PlaybookDir + "/" + HostFile cherrypy.log("HostFile: " + HostFilePath) - # buildInventorySysCall(ANSIBLE_PATH, ANSIBLE_INV, NodeList, PlaybookDir, HostFile, hostgrouplist, hostnamelist) + buildInventorySysCall(ANSIBLE_PATH, ANSIBLE_INV, NodeList, PlaybookDir, HostFile, hostgrouplist, hostnamelist, + inventory_names) # if NodeList and InventoryNames need to build host file if HaveInventoryNames and HaveNodeList: |