3 * ============LICENSE_START=======================================================
5 * ================================================================================
6 * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
7 * ================================================================================
8 * Copyright (C) 2019 Amdocs
9 * =============================================================================
10 * Licensed under the Apache License, Version 2.0 (the "License");
11 * you may not use this file except in compliance with the License.
12 * You may obtain a copy of the License at
14 * http://www.apache.org/licenses/LICENSE-2.0
16 * Unless required by applicable law or agreed to in writing, software
17 * distributed under the License is distributed on an "AS IS" BASIS,
18 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
19 * See the License for the specific language governing permissions and
20 * limitations under the License.
22 * ============LICENSE_END=========================================================
28 from collections import namedtuple
33 from cherrypy.lib.httputil import parse_query_string
34 from cherrypy.lib import auth_basic
36 def buildHostsSysCall(JsonInput, run_path, inventory_type):
38 cherrypy.log( "***> in BuildHostFile.buildHostSysCall")
40 # Build host file in run dir
41 output_file = open(run_path + "/host_file.txt","w")
44 # host vm will be formated based on the inventory_type value passed
46 cherrypy.log( "*** buildHostsSysCall -> Inventory_type: " + inventory_type)
48 # print standard header stuff to file
49 output_file.write ("[host]\n")
50 output_file.write ("localhost ansible_connection=local\n")
54 # print vm type then vm & ips
55 for NodeList in JsonInput['NodeList']:
60 #need to add check that vnfc-type is present in request
61 if not ('vnfc-type' in NodeList):
62 cherrypy.log( "*** buildHostsSysCall -> vnfc-type Not in NodeList: ")
65 Type = NodeList['vnfc-type']
69 # Optional Floating Address & VIP Element
72 if ('floating_ip_address-vip' in NodeList) & ('ne_id_vip' in NodeList):
73 FloatingIP = NodeList['floating_ip_address-vip']
74 NE_ID_VIP = NodeList['ne_id_vip']
75 #print ("FloatingIP: " + FloatingIP)
76 #print ("ne_id_vip: " + NE_ID_VIP)
77 output_file.write ("\n[%svip]\n" % Type )
78 if inventory_type == "None":
79 output_file.write ("%s\n" % (FloatingIP) )
80 elif inventory_type == "VNFC":
81 output_file.write ("%s ansible_host=%s\n" % (NE_ID_VIP, FloatingIP) )
82 elif inventory_type == "VM":
83 output_file.write ("%s ansible_host=%s\n" % (NE_ID_VIP[0:13], FloatingIP) )
85 output_file.write ("\n[%s]\n" % Type )
86 Site = NodeList['site']
88 #print ("Type: " + Type)
89 #print ("Site: " + Site)
91 for vm in NodeList['vm-info']:
95 IpAddr = vm['fixed_ip_address']
96 #print ("vm: " + Name + ": " + IpAddr)
97 if inventory_type == "None":
98 output_file.write ("%s\n" % (IpAddr) )
99 elif inventory_type == "VNFC":
100 output_file.write ("%s ansible_host=%s\n" % (Name, IpAddr) )
101 elif inventory_type == "VM":
102 output_file.write ("%s ansible_host=%s\n" % (Name[0:13], IpAddr) )
105 output_file.write ("\n[%s:children]\n" % Site )
106 for child_type in TypeList:
107 output_file.write ("%s\n" % child_type)