def get_vmware_hosts(check_esx_path, vcenter, user, password):
 list_host_cmd = [check_esx_path, '-D', vcenter, '-u', user, '-p', password, '-l', 'runtime', '-s', 'listhost']
 print 'Got host list'
 print ' '.join(list_host_cmd)
 p = Popen(list_host_cmd, stdout=PIPE, stderr=PIPE)
 output = p.communicate()
 print 'Exit status', p.returncode
 if (p.returncode == 2):
  print 'Error: check_esx3.pl returnes an error:', output
  raise SystemExit(2)
 parts = output[0].split(':')
 hsts_raw = parts[1].split('|')[0]
 hsts_raw_lst = hsts_raw.split(',')
 hosts = []
 for hst_raw in hsts_raw_lst:
  hst_raw = hst_raw.strip()
  elts = hst_raw.split('(')
  hst = elts[0]
  hosts.append(hst)
 return hosts

def get_vmware_hosts ( check_esx_path , vcenter , user , password ) : list_host_cmd = [ check_esx_path , '-D' , vcenter , '-u' , user , '-p' , password , '-l' , 'runtime' , '-s' , 'listhost' ] print 'Got host list' print ' ' . join ( list_host_cmd ) p = Popen ( list_host_cmd , stdout = PIPE , stderr = PIPE ) output = p . communicate ( ) print 'Exit status' , p . returncode if ( p . returncode == 2 ) : print 'Error: check_esx3.pl returnes an error:' , output raise SystemExit ( 2 ) parts = output [ 0 ] . split ( ':' ) hsts_raw = parts [ 1 ] . split ( '|' ) [ 0 ] hsts_raw_lst = hsts_raw . split ( ',' ) hosts = [ ] for hst_raw in hsts_raw_lst : hst_raw = hst_raw . strip ( ) elts = hst_raw . split ( '(' ) hst = elts [ 0 ] hosts . append ( hst ) return hosts
get a list of all hosts from a vcenter .