def get_vm_of_host(check_esx_path, vcenter, host, user, password):
 print 'Listing host', host
 list_vm_cmd = [check_esx_path, '-D', vcenter, '-H', host, '-u', user, '-p', password, '-l', 'runtime', '-s', 'list']
 print ' '.join(list_vm_cmd)
 p = Popen(list_vm_cmd, stdout=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(':')
 if (len(parts) < 2):
  return None
 vms_raw = parts[1].split('|')[0]
 vms_raw_lst = vms_raw.split(',')
 lst = []
 for vm_raw in vms_raw_lst:
  vm_raw = vm_raw.strip()
  elts = vm_raw.split('(')
  vm = elts[0]
  lst.append(vm)
 return lst

def get_vm_of_host ( check_esx_path , vcenter , host , user , password ) : print 'Listing host' , host list_vm_cmd = [ check_esx_path , '-D' , vcenter , '-H' , host , '-u' , user , '-p' , password , '-l' , 'runtime' , '-s' , 'list' ] print ' ' . join ( list_vm_cmd ) p = Popen ( list_vm_cmd , stdout = 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 ( ':' ) if ( len ( parts ) < 2 ) : return None vms_raw = parts [ 1 ] . split ( '|' ) [ 0 ] vms_raw_lst = vms_raw . split ( ',' ) lst = [ ] for vm_raw in vms_raw_lst : vm_raw = vm_raw . strip ( ) elts = vm_raw . split ( '(' ) vm = elts [ 0 ] lst . append ( vm ) return lst
get a list of all virtual machines on a specific host .