summaryrefslogtreecommitdiffstats
path: root/ansible-server/src/main/scripts/BuildHostFile.py
diff options
context:
space:
mode:
authorTaka Cho <takamune.cho@att.com>2019-01-29 09:30:22 -0500
committerTaka Cho <takamune.cho@att.com>2019-01-29 10:07:50 -0500
commitdc4950ba68c4c6dadd530f7f808bbb4c9458571d (patch)
tree7e521574b04db47f5a6f7d2fddd67ab3f3f43904 /ansible-server/src/main/scripts/BuildHostFile.py
parentdc379274e1cb70a2d7506641e4916f10f019e0fe (diff)
alpine build, implement to follow VNF anisble Req
1. change from ubuntu build to alpine build 2, follow the dir path for playbook - pls see JIRA Change-Id: Iaa2f7e3c9fc66542b1bc0751826821276f773efa Issue-ID: CCSDK-1009 Signed-off-by: Taka Cho <takamune.cho@att.com>
Diffstat (limited to 'ansible-server/src/main/scripts/BuildHostFile.py')
-rwxr-xr-xansible-server/src/main/scripts/BuildHostFile.py112
1 files changed, 112 insertions, 0 deletions
diff --git a/ansible-server/src/main/scripts/BuildHostFile.py b/ansible-server/src/main/scripts/BuildHostFile.py
new file mode 100755
index 00000000..20bbc904
--- /dev/null
+++ b/ansible-server/src/main/scripts/BuildHostFile.py
@@ -0,0 +1,112 @@
+'''
+/*-
+* ============LICENSE_START=======================================================
+* ONAP : APPC
+* ================================================================================
+* Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
+* ================================================================================
+* Copyright (C) 2019 Amdocs
+* =============================================================================
+* Licensed under the Apache License, Version 2.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+*
+* http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*
+* ECOMP is a trademark and service mark of AT&T Intellectual Property.
+* ============LICENSE_END=========================================================
+*/
+'''
+
+import os, subprocess
+import sys
+from collections import namedtuple
+import json
+
+import uuid
+import cherrypy
+from cherrypy.lib.httputil import parse_query_string
+from cherrypy.lib import auth_basic
+
+def buildHostsSysCall(JsonInput, run_path, inventory_type):
+
+ cherrypy.log( "***> in BuildHostFile.buildHostSysCall")
+
+ # Build host file in run dir
+ output_file = open(run_path + "/host_file.txt","w")
+
+ #
+ # host vm will be formated based on the inventory_type value passed
+ #
+ cherrypy.log( "*** buildHostsSysCall -> Inventory_type: " + inventory_type)
+
+ # print standard header stuff to file
+ output_file.write ("[host]\n")
+ output_file.write ("localhost ansible_connection=local\n")
+
+ TypeList=[]
+
+ # print vm type then vm & ips
+ for NodeList in JsonInput['NodeList']:
+ #print( "" )
+ #print ("Node: ")
+ #print NodeList
+
+ #need to add check that vnfc-type is present in request
+ if not ('vnfc-type' in NodeList):
+ cherrypy.log( "*** buildHostsSysCall -> vnfc-type Not in NodeList: ")
+ return(-1)
+
+ Type = NodeList['vnfc-type']
+ TypeList.append(Type)
+
+
+ # Optional Floating Address & VIP Element
+ FloatingIP=""
+ NE_ID_VIP=""
+ if ('floating_ip_address-vip' in NodeList) & ('ne_id_vip' in NodeList):
+ FloatingIP = NodeList['floating_ip_address-vip']
+ NE_ID_VIP = NodeList['ne_id_vip']
+ #print ("FloatingIP: " + FloatingIP)
+ #print ("ne_id_vip: " + NE_ID_VIP)
+ output_file.write ("\n[%svip]\n" % Type )
+ if inventory_type == "None":
+ output_file.write ("%s\n" % (FloatingIP) )
+ elif inventory_type == "VNFC":
+ output_file.write ("%s ansible_host=%s\n" % (NE_ID_VIP, FloatingIP) )
+ elif inventory_type == "VM":
+ output_file.write ("%s ansible_host=%s\n" % (NE_ID_VIP[0:13], FloatingIP) )
+
+ output_file.write ("\n[%s]\n" % Type )
+ Site = NodeList['site']
+
+ #print ("Type: " + Type)
+ #print ("Site: " + Site)
+
+ for vm in NodeList['vm-info']:
+ #print ("VM: " )
+ #print (vm)
+ Name = vm['ne_id']
+ IpAddr = vm['fixed_ip_address']
+ #print ("vm: " + Name + ": " + IpAddr)
+ if inventory_type == "None":
+ output_file.write ("%s\n" % (IpAddr) )
+ elif inventory_type == "VNFC":
+ output_file.write ("%s ansible_host=%s\n" % (Name, IpAddr) )
+ elif inventory_type == "VM":
+ output_file.write ("%s ansible_host=%s\n" % (Name[0:13], IpAddr) )
+
+ # print site list
+ output_file.write ("\n[%s:children]\n" % Site )
+ for child_type in TypeList:
+ output_file.write ("%s\n" % child_type)
+
+
+ output_file.close()
+ return(0)