11 def parse_json_file(json_path):
12 with open(json_path, 'r') as json_file:
13 data = json.load(json_file)
17 def check_network_interfaces():
18 for interface in netifaces.interfaces():
19 if(sys.platform != 'win32' or netifaces.ifaddresses(interface)[-1000][0]['addr'] != '00:00:00:00:00:00:00:e0'):
20 while 2 not in netifaces.ifaddresses(interface).keys() and 23 not in netifaces.ifaddresses(interface).keys():
21 print "Still waiting for interface:", interface
22 time.sleep(TIME_INTERVAL)
25 def check_connectivity():
26 if sys.platform.startswith('linux'):
27 ping_str = "ping -c 1 "
28 elif sys.platform == 'cygwin' or sys.platform == 'win32':
29 ping_str = "ping -n 1 "
31 while os.system(ping_str + component_ip) != 0:
32 print "No connectivity to", component_ip, "waiting", TIME_INTERVAL, "seconds"
33 time.sleep(TIME_INTERVAL)
36 def check_cinder_mounts():
37 if sys.platform.startswith('linux'):
38 meta_data = parse_json_file('/meta.js')
39 elif sys.platform == 'cygwin' or sys.platform == 'win32':
40 meta_data = parse_json_file('c:\\meta.js')
44 for info in meta_data:
45 if info.startswith('mount'):
48 if sys.platform.startswith('linux'):
49 cinder_attached = os.popen('ls /dev/disk/by-id/virtio* | wc -l').read()
50 elif sys.platform == 'cygwin' or sys.platform == 'win32':
51 cinder_attached = os.popen("wmic diskdrive get DeviceID | find /i \"PHYSICALDRIVE\" | find /V \"0\" /C").read()
53 while (int(cinder_attached) < cinder_count) and (cinder_count != 0):
54 print "Missing a cinder mount, waiting", TIME_INTERVAL, "seconds"
55 time.sleep(TIME_INTERVAL)
57 if sys.platform.startswith('linux'):
58 cinder_attached = os.popen('ls /dev/disk/by-id/virtio* | wc -l').read()
60 elif sys.platform == 'cygwin' or sys.platform == 'win32':
61 cinder_attached = os.popen(
62 "wmic diskdrive get DeviceID | find /i \"PHYSICALDRIVE\" | find /V \"0\" /C").read()
64 if int(cinder_attached) == cinder_count:
65 print "All cinder are attached and ready to be formatted and mounted"
69 check_network_interfaces()
72 if component_ip is not None:
75 print "All resources are ready"
78 if __name__ == "__main__":
79 parser = argparse.ArgumentParser(description='This script is waiting for network and volume resources to come up')
80 parser.add_argument('-m', '--component_ip', metavar='component_ip', type=str, help='The component ip', required=False)
81 args = parser.parse_args()
82 component_ip = args.component_ip
83 globals().update(args.__dict__)