def list_vms(search=None, verbose=False):
 ret = (OrderedDict() if verbose else [])
 client = salt.client.get_local_client(__opts__['conf_file'])
 try:
  vmadm_args = {}
  vmadm_args['order'] = 'uuid,alias,hostname,state,type,cpu_cap,vcpus,ram'
  if search:
   vmadm_args['search'] = search
  for cn in client.cmd_iter('G@virtual:physical and G@os:smartos', 'vmadm.list', kwarg=vmadm_args, tgt_type='compound'):
   if (not cn):
    continue
   node = next(cn.iterkeys())
   if ((not isinstance(cn[node], dict)) or ('ret' not in cn[node]) or (not isinstance(cn[node]['ret'], dict))):
    continue
   for vm in cn[node]['ret'].keys():
    vmcfg = cn[node]['ret'][vm]
    if verbose:
     ret[vm] = OrderedDict()
     ret[vm]['hostname'] = vmcfg['hostname']
     ret[vm]['alias'] = vmcfg['alias']
     ret[vm]['computenode'] = node
     ret[vm]['state'] = vmcfg['state']
     ret[vm]['resources'] = OrderedDict()
     ret[vm]['resources']['memory'] = vmcfg['ram']
     if (vmcfg['type'] == 'KVM'):
      ret[vm]['resources']['cpu'] = '{0:.2f}'.format(int(vmcfg['vcpus']))
     elif (vmcfg['cpu_cap'] != ''):
      ret[vm]['resources']['cpu'] = '{0:.2f}'.format((int(vmcfg['cpu_cap']) / 100))
    else:
     ret.append(vm)
 except SaltClientError as client_error:
  return '{0}'.format(client_error)
 if (not verbose):
  ret = sorted(ret)
 return ret

def list_vms ( search = None , verbose = False ) : ret = ( OrderedDict ( ) if verbose else [ ] ) client = salt . client . get_local_client ( __opts__ [ 'conf_file' ] ) try : vmadm_args = { } vmadm_args [ 'order' ] = 'uuid,alias,hostname,state,type,cpu_cap,vcpus,ram' if search : vmadm_args [ 'search' ] = search for cn in client . cmd_iter ( 'G@virtual:physical and G@os:smartos' , 'vmadm.list' , kwarg = vmadm_args , tgt_type = 'compound' ) : if ( not cn ) : continue node = next ( cn . iterkeys ( ) ) if ( ( not isinstance ( cn [ node ] , dict ) ) or ( 'ret' not in cn [ node ] ) or ( not isinstance ( cn [ node ] [ 'ret' ] , dict ) ) ) : continue for vm in cn [ node ] [ 'ret' ] . keys ( ) : vmcfg = cn [ node ] [ 'ret' ] [ vm ] if verbose : ret [ vm ] = OrderedDict ( ) ret [ vm ] [ 'hostname' ] = vmcfg [ 'hostname' ] ret [ vm ] [ 'alias' ] = vmcfg [ 'alias' ] ret [ vm ] [ 'computenode' ] = node ret [ vm ] [ 'state' ] = vmcfg [ 'state' ] ret [ vm ] [ 'resources' ] = OrderedDict ( ) ret [ vm ] [ 'resources' ] [ 'memory' ] = vmcfg [ 'ram' ] if ( vmcfg [ 'type' ] == 'KVM' ) : ret [ vm ] [ 'resources' ] [ 'cpu' ] = '{0:.2f}' . format ( int ( vmcfg [ 'vcpus' ] ) ) elif ( vmcfg [ 'cpu_cap' ] != '' ) : ret [ vm ] [ 'resources' ] [ 'cpu' ] = '{0:.2f}' . format ( ( int ( vmcfg [ 'cpu_cap' ] ) / 100 ) ) else : ret . append ( vm ) except SaltClientError as client_error : return '{0}' . format ( client_error ) if ( not verbose ) : ret = sorted ( ret ) return ret
returns a list of vms associated with a given service instance .