5 from socket import getfqdn
6 from sys import platform
10 PARSER = argparse.ArgumentParser()
11 PARSER.add_argument("manager_ip", help="The IPv4 Address where one can read the MaveriQConductor.")
12 PARSER.add_argument("--mockupfile", type=str, help="The path of the json mockupfile to use.")
13 ARGS = PARSER.parse_args()
15 URL = "http://{0}:8084/MaveriQConductor/machine/create".format(ARGS.manager_ip)
16 URL_AVAIL = "http://{0}:8084/MaveriQConductor/isReady".format(ARGS.manager_ip)
18 'Accept': 'text/plain',
19 'Content-type': 'application/json',
24 "$$OAM_NET_IP$$": "oam_private_network_ip",
25 "$$BACKEND_NET_IP$$": "backend_interconnect_network_ip",
26 "$$PACKET_MIRROR_NET_IP$$": "packet_mirror_network_ip",
27 "$$CDR_NET_IP$$": "cdr_network_ip",
28 "$$VERTICA_NET_IP$$": "vertica_private_network_ip",
29 "$$PACKET_INTERNAL_NET_IP$$": "packet_internal_network_ip",
30 "$$OAM_PROTECTED_NET_IP$$": "oam_protected_network_ip"
34 def map_ips_to_networks(p_meta_data):
36 for network_name in NETWORK_MAP.keys():
37 if NETWORK_MAP[network_name] in p_meta_data:
38 network_to_ip[network_name] = str(p_meta_data[NETWORK_MAP[network_name]])
42 def check_availability():
44 while is_connected is False:
46 if requests.get(URL_AVAIL, headers={'Connection': 'close'}).status_code is 200:
49 except requests.exceptions.ConnectionError:
53 def post_request(p_json_data, p_headers):
54 req = requests.post(url=URL, data=p_json_data, headers=p_headers)
55 return req.status_code
58 def multiple_replace(regex_dictionary, text):
59 regex = re.compile("(%s)" % "|".join(map(re.escape, regex_dictionary.keys())))
61 lambda x: regex_dictionary[x.string[x.start():x.end()]], text
66 # Depending on platform, load the dependencies and meta.js files.
68 with open(ARGS.mockupfile, 'r') as mockup_file:
69 mockup_file_data = mockup_file.read()
70 return post_request(mockup_file_data, HEADERS)
72 if platform.startswith('linux'):
73 with open(r'/root/dependencies.json', 'r') as json_file:
74 json_data = json_file.read()
75 with open(r'/meta.js', 'r') as json_file:
76 meta_data = json.load(json_file)
78 elif platform == 'cygwin' or platform == 'win32':
79 with open(r'c:\\dependencies.json', 'r') as json_file:
80 json_data = json_file.read()
81 with open(r'c:\\meta.js', 'r') as json_file:
82 meta_data = json.load(json_file)
86 raise Exception('Unsupported platform')
87 # Build dictionary mapping each IP to network.
88 regex_dict = map_ips_to_networks(meta_data)
89 regex_dict['$$HOSTNAME$$'] = getfqdn()
91 # Perform any replacement needed.
92 json_data = multiple_replace(regex_dict, json_data)
95 return post_request(p_json_data=json_data, p_headers=HEADERS)