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 * ECOMP is a trademark and service mark of AT&T Intellectual Property.
23 * ============LICENSE_END=========================================================
29 from collections import namedtuple
34 from cherrypy.lib.httputil import parse_query_string
35 from cherrypy.lib import auth_basic
37 def buildHostsSysCall(JsonInput, run_path, inventory_type):
39 cherrypy.log( "***> in BuildHostFile.buildHostSysCall")
41 # Build host file in run dir
42 output_file = open(run_path + "/host_file.txt","w")
45 # host vm will be formated based on the inventory_type value passed
47 cherrypy.log( "*** buildHostsSysCall -> Inventory_type: " + inventory_type)
49 # print standard header stuff to file
50 output_file.write ("[host]\n")
51 output_file.write ("localhost ansible_connection=local\n")
55 # print vm type then vm & ips
56 for NodeList in JsonInput['NodeList']:
61 #need to add check that vnfc-type is present in request
62 if not ('vnfc-type' in NodeList):
63 cherrypy.log( "*** buildHostsSysCall -> vnfc-type Not in NodeList: ")
66 Type = NodeList['vnfc-type']
70 # Optional Floating Address & VIP Element
73 if ('floating_ip_address-vip' in NodeList) & ('ne_id_vip' in NodeList):
74 FloatingIP = NodeList['floating_ip_address-vip']
75 NE_ID_VIP = NodeList['ne_id_vip']
76 #print ("FloatingIP: " + FloatingIP)
77 #print ("ne_id_vip: " + NE_ID_VIP)
78 output_file.write ("\n[%svip]\n" % Type )
79 if inventory_type == "None":
80 output_file.write ("%s\n" % (FloatingIP) )
81 elif inventory_type == "VNFC":
82 output_file.write ("%s ansible_host=%s\n" % (NE_ID_VIP, FloatingIP) )
83 elif inventory_type == "VM":
84 output_file.write ("%s ansible_host=%s\n" % (NE_ID_VIP[0:13], FloatingIP) )
86 output_file.write ("\n[%s]\n" % Type )
87 Site = NodeList['site']
89 #print ("Type: " + Type)
90 #print ("Site: " + Site)
92 for vm in NodeList['vm-info']:
96 IpAddr = vm['fixed_ip_address']
97 #print ("vm: " + Name + ": " + IpAddr)
98 if inventory_type == "None":
99 output_file.write ("%s\n" % (IpAddr) )
100 elif inventory_type == "VNFC":
101 output_file.write ("%s ansible_host=%s\n" % (Name, IpAddr) )
102 elif inventory_type == "VM":
103 output_file.write ("%s ansible_host=%s\n" % (Name[0:13], IpAddr) )
106 output_file.write ("\n[%s:children]\n" % Site )
107 for child_type in TypeList:
108 output_file.write ("%s\n" % child_type)