- if from_files:
-
- # Get credentials from file
-
- data_inventory_orig = {}
- data_inventory_target = {}
- curr_group = None
-
- print "***>", ansible_path + "/" + ansible_inv
- f = open(ansible_path + "/" + ansible_inv, "r")
- for line in f:
- line = line.rstrip()
-
- if len(line)> 0:
- if '#' not in line:
- if "[" in line and "]" in line:
- data_inventory_orig[line] = []
- curr_group = line
- else:
- data_inventory_orig[curr_group].append(line)
- f.close()
-
- for node in NodeList:
- Fail = True
- if "[" + node + "]" in data_inventory_orig:
- if not "[" + node + "]" in data_inventory_target:
-
- print "RESET", "[" + node + "]"
- data_inventory_target["[" + node + "]"] = []
- else:
- print "OK", "[" + node + "]"
- Fail = 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 not key 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 = False
-
- if Fail:
- data_inventory_target["["+node+"]"] = \
- [node + " ansible_connection=ssh ansible_ssh_user=na ansible_ssh_private_key_file=na"]
-
- AnsibleInvFail = False
-
- f = open(PlaybookDir + "/" + AnsibleInv, "w")
- for key in data_inventory_target:
- f.write(key + "\n")
- for rec in data_inventory_target[key]:
- hostgrouplist.append(key.replace("[", '').replace("]", ''))
- hostnamelist.append(rec.split(' ')[0])
- f.write(rec + "\n")
- f.close()
-
- else:
-
- # Get credentials from mySQL
-
- sqlintf = AnsibleSql.mySql (host, user, passwd,
- db)
- if sqlintf.con:
- MySqlConFail = False
- errorCode, diag = readCredentials (sqlintf,
- NodeList)
-
- print errorCode, diag
- if len (diag) > 0:
- f = open(PlaybookDir + "/" + AnsibleInv,
- "w")
- AnsibleInvFail = False
- # [hostgroup, hostname, credentials]
- for i in range(len(diag)):
- f.write('[' + diag[i][0] + ']' + "\n")
- f.write(diag[i][1]+ " " + diag[i][2] + "\n\n")
- hostgrouplist.append(diag[i][0])
- hostnamelist.append(diag[i][1])
- f.close()
- else:
- MySqlConFailCause = sqlintf.error
- sqlintf.Close()
+ #location of host file - Default
+ HostFile = PlaybookDir + "/inventory/" + VNF_instance + "hosts"
+ cherrypy.log("HostFile: " + HostFile)
+
+ # if NodeList and InventoryNames need to build host file
+ if HaveInventoryNames & HaveNodeList:
+ cherrypy.log("Build host file from NodeList")
+ ret = buildHostsSysCall (input_json, PlaybookDir, inventory_names)
+ if (ret < 0):
+ cherrypy.log("Returning Error: Not running Playbook")
+ return {"StatusCode": 105,
+ "StatusMessage": "NodeList: Missing vnfc-type field"}
+
+ # Having been built now copy new file to correct file
+ shutil.copy(PlaybookDir + "/host_file.txt", HostFile)
+ cherrypy.log("Copying Generated host file to: " + HostFile)