Finds all enabled and disabled VM-VM Affinity and Anti-Affinity rules, involving the given Virtual Machine.

@param vm The vm whose rules need to be looked up.
@return Array of rule info
@throws RuntimeFault
@throws RemoteException
@since 6.0
436265
public ClusterRuleInfo[] findRulesForVm(VirtualMachine vm) throws RuntimeFault, RemoteException {
        return getVimService().findRulesForVm(getMOR(), vm.getMOR());
    }
1281436
@Override
    public @Nonnull Iterable<String> launchMany(final @Nonnull VMLaunchOptions withLaunchOptions, final @Nonnegative int count) throws CloudException, InternalException {
        if( count < 1 ) {
            throw new InternalException("Invalid attempt to launch less than 1 virtual machine (requested " + count + ").");
        }
        if( count == 1 ) {
            return Collections.singleton(launch(withLaunchOptions).getProviderVirtualMachineId());
        }
        final List<Future<String>> results = new ArrayList<Future<String>>();

        // windows on GCE follows same naming constraints as regular instances, 1-62 lower and numbers, must begin with a letter.
        NamingConstraints c = NamingConstraints.getAlphaNumeric(1, 63).withNoSpaces().withRegularExpression("(?:[a-z](?:[-a-z0-9]{0,61}[a-z0-9])?)").lowerCaseOnly().constrainedBy('-');
        String baseHost = c.convertToValidName(withLaunchOptions.getHostName(), Locale.US);

        if( baseHost == null ) {
            baseHost = withLaunchOptions.getHostName();
        }
        for (int i = 1; i <= count; i++) {
            String hostName = c.incrementName(baseHost, i);
            String friendlyName = withLaunchOptions.getFriendlyName() + "-" + i;
            VMLaunchOptions options = withLaunchOptions.copy(hostName == null ? withLaunchOptions.getHostName() + "-" + i : hostName, friendlyName);

            results.add(launchAsync(options));
        }

        PopulatorThread<String> populator = new PopulatorThread<String>(new JiteratorPopulator<String>() {
            @Override
            public void populate( @Nonnull Jiterator<String> iterator ) throws Exception {
                List<Future<String>> original = results;
                List<Future<String>> copy = new ArrayList<Future<String>>();
                Exception exception = null;
                boolean loaded = false;

                while( !original.isEmpty() ) {
                    for( Future<String> result : original ) {
                        if( result.isDone() ) {
                            try {
                                iterator.push(result.get());
                                loaded = true;
                            } catch( Exception e ) {
                                exception = e;
                            }
                        }
                        else {
                            copy.add(result);
                        }
                    }
                    original = copy;
                    // copy has to be a new list else we'll get into concurrently modified list state
                    copy = new ArrayList<Future<String>>();
                }
                if( exception != null && !loaded ) {
                    throw exception;
                }
            }
        });

        populator.populate();
        return populator.getResult();
    }
168975
private synchronized VirtualMachine getAttachedVirtualMachine() throws VirtualMachineException {
        if (PID == null) {
            // Java Attach requires a PID.
            return null;
        }

        if (vm == null) {
            vm = createVirtualMachine();
        }
        return vm.isAttached() ? vm : null;
    }
476934
public static vm_template[] get(nitro_service client) throws Exception
	{
		vm_template resource = new vm_template();
		resource.validate("get");
		return (vm_template[]) resource.get_resources(client);
	}
844166
def _getManagedObjectsInstances(self, varBinds, **context):
        
        rspVarBinds = context['rspVarBinds']
        varBindsMap = context['varBindsMap']

        rtrVarBinds = []

        for idx, varBind in enumerate(varBinds):
            name, val = varBind
            if (exval.noSuchObject.isSameTypeWith(val) or
                    exval.noSuchInstance.isSameTypeWith(val)):
                varBindsMap[len(rtrVarBinds)] = varBindsMap.pop(idx, idx)
                rtrVarBinds.append(varBind)

            else:
                rspVarBinds[varBindsMap.pop(idx, idx)] = varBind

        if rtrVarBinds:
            snmpEngine = context['snmpEngine']

            # Need to unwind stack, can't recurse any more
            def callLater(*args):
                snmpEngine.transportDispatcher.unregisterTimerCbFun(callLater)
                mgmtFun = context['mgmtFun']
                mgmtFun(*varBinds, **context)

            snmpEngine.transportDispatcher.registerTimerCbFun(callLater, 0.01)

        else:
            return rspVarBinds
632674
private static boolean isVMMultidexCapable() {
        boolean isMultidexCapable = false;
        String vmVersion = System.getProperty("java.vm.version");
        try {
            Matcher matcher = Pattern.compile("(\\d+)\\.(\\d+)(\\.\\d+)?").matcher(vmVersion);
            if (matcher.matches()) {
                int major = Integer.parseInt(matcher.group(1));
                int minor = Integer.parseInt(matcher.group(2));
                isMultidexCapable = (major > 2) || ((major == 2) && (minor >= 1));
            }
        } catch (Exception ignore) {
        }
        String multidex = isMultidexCapable ? "has Multidex support" : "does not have Multidex support";
        Log.i(AndServer.TAG, String.format("VM with version %s %s.", vmVersion, multidex));
        return false;
    }
788419
public boolean vmExists(final String vmOrUuid) {
        String[] lines = execute("list", "vms").split("\\s");
        for (String line : lines) {
            if (line.endsWith("{" + vmOrUuid + "}") || line.startsWith("\"" + vmOrUuid + "\""))
                return true;
        }
        return false;
    }
596734
def get_sequence_rule_enablers_by_search(self, sequence_rule_enabler_query, sequence_rule_enabler_search):
        """"""
        # Implemented from azosid template for -
        # osid.resource.ResourceSearchSession.get_resources_by_search_template
        if not self._can('search'):
            raise PermissionDenied()
        return self._provider_session.get_sequence_rule_enablers_by_search(sequence_rule_enabler_query, sequence_rule_enabler_search)
890198
def _determine_resource_pool(session, vm_):
    '''
    
    '''
    resource_pool = ''
    if 'resource_pool' in vm_.keys():
        resource_pool = _get_pool(vm_['resource_pool'], session)
    else:
        pool = session.xenapi.pool.get_all()
        if not pool:
            resource_pool = None
        else:
            first_pool = session.xenapi.pool.get_all()[0]
            resource_pool = first_pool
    pool_record = session.xenapi.pool.get_record(resource_pool)
    log.debug('resource pool: %s', pool_record['name_label'])
    return resource_pool
1130180
public List<BindingInfo> getBindingsBySource(String vhost, String exchange) {
    final String x = exchange.equals("") ? "amq.default" : exchange;
    final URI uri = uriWithPath("./exchanges/" + encodePathSegment(vhost) +
        "/" + encodePathSegment(x) + "/bindings/source");
    return Arrays.asList(this.rt.getForObject(uri, BindingInfo[].class));
  }
649553
def get_vm_ports(port_id=None):
    """"""
    return get_ports(device_owners=[n_const.DEVICE_OWNER_COMPUTE_PREFIX,
                                    t_const.TRUNK_SUBPORT_OWNER],
                     vnic_type=portbindings.VNIC_NORMAL, port_id=port_id)
1365936
public static vm_device[] get_filtered(nitro_service service, String filter) throws Exception
	{
		vm_device obj = new vm_device();
		options option = new options();
		option.set_filter(filter);
		vm_device[] response = (vm_device[]) obj.getfiltered(service, option);
		return response;
	}
852772
def get_nexusvm_bindings(vlan_id, instance_id):
    """"""
    LOG.debug("get_nexusvm_bindings() called")
    return _lookup_all_nexus_bindings(instance_id=instance_id,
                                      vlan_id=vlan_id)
616279
def vsan_supported(service_instance):
    '''
    
    '''
    try:
        api_version = service_instance.content.about.apiVersion
    except vim.fault.NoPermission as exc:
        log.exception(exc)
        raise VMwareApiError('Not enough permissions. Required privilege: '
                             '{0}'.format(exc.privilegeId))
    except vim.fault.VimFault as exc:
        log.exception(exc)
        raise VMwareApiError(exc.msg)
    except vmodl.RuntimeFault as exc:
        log.exception(exc)
        raise VMwareRuntimeError(exc.msg)
    if int(api_version.split('.')[0]) < 6:
        return False
    return True
980310
def is_connection_to_a_vcenter(service_instance):
    '''
    
    '''
    try:
        api_type = service_instance.content.about.apiType
    except vim.fault.NoPermission as exc:
        log.exception(exc)
        raise salt.exceptions.VMwareApiError(
            'Not enough permissions. Required privilege: '
            '{}'.format(exc.privilegeId))
    except vim.fault.VimFault as exc:
        log.exception(exc)
        raise salt.exceptions.VMwareApiError(exc.msg)
    except vmodl.RuntimeFault as exc:
        log.exception(exc)
        raise salt.exceptions.VMwareRuntimeError(exc.msg)
    log.trace('api_type = %s', api_type)
    if api_type == 'VirtualCenter':
        return True
    elif api_type == 'HostAgent':
        return False
    else:
        raise salt.exceptions.VMwareApiError(
            'Unexpected api type \'{0}\' . Supported types: '
            '\'VirtualCenter/HostAgent\''.format(api_type))
1066032
public static List<Domain> getRunningDomains(Connect libvirt) {
        try {
            List<Domain> domains = new ArrayList<>();
            int[] ids = libvirt.listDomains();
            for (int id : ids) {
                domains.add(libvirt.domainLookupByID(id));
            }
            return domains;
        } catch (LibvirtException e) {
            throw new LibvirtRuntimeException("Unable to list defined domains", e);
        }
    }
335084
protected static Properties getAgentProperties() {
    try {
      Class<?> clazz = Class.forName("sun.misc.VMSupport");
      Method m = clazz.getDeclaredMethod("getAgentProperties");
      m.setAccessible(true);
      Properties p = (Properties)m.invoke(null);
      return p;
    } catch (Throwable t) {
      return null;
    }   
  }