5 from pprint import PrettyPrinter
7 # how could this accept a list again ?
9 now=time.strftime("%H:%M:%S", time.localtime())
10 print "*",now,'--',message
12 def pprint(message,spec,depth=2):
13 now=time.strftime("%H:%M:%S", time.localtime())
14 print ">",now,"--",message
15 PrettyPrinter(indent=8,depth=depth).pprint(spec)
17 def show_site_spec (site):
18 print '======== site',site['site_fields']['name']
19 for (k,v) in site.iteritems():
22 print '\t\t','nodes : ',
24 print node['node_fields']['hostname'],'',
30 print user['name'],'',
32 elif k == 'site_fields':
33 print '\t\tlogin_base',':',v['login_base']
34 elif k == 'address_fields':
38 PrettyPrinter(indent=8,depth=2).pprint(v)
40 def show_initscript_spec (initscript):
41 print '======== initscript',initscript['initscript_fields']['name']
43 def show_key_spec (key):
44 print '======== key',key['name']
46 def show_slice_spec (slice):
47 print '======== slice',slice['slice_fields']['name']
48 for (k,v) in slice.iteritems():
61 elif k=='slice_fields':
62 print '\t\tfields',':',
63 print 'max_nodes=',v['max_nodes'],
68 def show_test_spec (message,all_plc_specs):
69 now=time.strftime("%H:%M:%S", time.localtime())
70 print ">",now,"--",message
71 for plc_spec in all_plc_specs:
72 show_test_spec_pass (plc_spec,1)
73 show_test_spec_pass (plc_spec,2)
75 def show_test_spec_pass (plc_spec,passno):
76 for (key,val) in plc_spec.iteritems():
81 elif key=='initscripts':
82 for initscript in val:
83 show_initscript_spec (initscript)
86 show_slice_spec (slice)
91 if key not in ['sites','initscripts','slices','keys']:
92 print '\t',key,':',val
95 now=time.strftime("%H:%M:%S", time.localtime())
96 print "+",now,':',command
97 return os.system("set -x; " + command)
99 # checks whether a given hostname/ip responds to ping
100 ping_timeout_option = None
101 def check_ping (hostname):
102 # check OS (support for macos)
103 global ping_timeout_option
104 if not ping_timeout_option:
105 (status,osname) = commands.getstatusoutput("uname -s")
107 raise Exception, "Cannot figure your OS name"
108 if osname == "Linux":
109 ping_timeout_option="-w"
110 elif osname == "Darwin":
111 ping_timeout_option="-t"
113 command="ping -c 1 %s 1 %s"%(ping_timeout_option,hostname)
114 (status,output) = commands.getstatusoutput(command)