Get XEN vm instance object reference
964379
def _get_vm(name=None, session=None):
    '''
    
    '''
    if session is None:
        session = _get_session()
    vms = session.xenapi.VM.get_by_name_label(name)
    if len(vms) == 1:
        return vms[0]
    return None
805932
def show_instance(name, call=None):
    '''
    
    '''
    if call != 'action':
        raise SaltCloudSystemExit(
            'The show_instance action must be called with -a or --action.'
        )
    try:
        node = list_nodes_full('function')[name]
    except KeyError:
        log.debug('Failed to get data for node \'%s\'', name)
        node = {}

    __utils__['cloud.cache_node'](node, __active_provider_name__, __opts__)

    return node
1208768
def get instance_reference, keys = nil
    if keys
      uri = Openwsman.epr_uri_for "", instance_reference
      instance_reference = Openwsman::EndPointReference.new(uri, nil, keys)
    end
    puts "@client.get #{instance_reference.class}..." if Wbem.debug
    case instance_reference
    when Openwsman::EndPointReference
      get_by_epr instance_reference
    when String
      get_by_epr Openwsman::EndPointReference.new(instance_reference)
    else
      raise "Unsupported Wbem::get #{instance_reference.class}"
    end
  end
18829
def _provision_vm(name=None, session=None):
    '''
    
    '''
    if session is None:
        session = _get_session()
    log.info('Provisioning VM %s', name)
    vm = _get_vm(name, session)
    task = session.xenapi.Async.VM.provision(vm)
    _run_async_task(task, session)
789111
def load_vm_uuid_by_name(self, si, vcenter_data_model, vm_name):
        
        path = VMLocation.combine([vcenter_data_model.default_datacenter, vm_name])
        paths = path.split('/')
        name = paths[len(paths) - 1]
        path = VMLocation.combine(paths[:len(paths) - 1])
        vm = self.pv_service.find_vm_by_name(si, path, name)
        if not vm:
            raise ValueError('Could not find the vm in the given path: {0}/{1}'.format(path, name))

        if isinstance(vm, vim.VirtualMachine):
            return vm.config.uuid

        raise ValueError('The given object is not a vm: {0}/{1}'.format(path, name))
517752
def get_conn(conn_type):
    '''
    
    '''
    vm_ = get_configured_provider()

    kwargs = vm_.copy()  # pylint: disable=E1103

    kwargs['username'] = vm_['username']
    kwargs['auth_endpoint'] = vm_.get('identity_url', None)
    kwargs['region'] = vm_['compute_region']

    conn = getattr(suop, conn_type)

    return conn(**kwargs)
606508
def get_nics(vm_):
    '''
    
    '''
    with _get_xapi_session() as xapi:
        nic = {}

        vm_rec = _get_record_by_label(xapi, 'VM', vm_)
        if vm_rec is False:
            return False
        for vif in vm_rec['VIFs']:
            vif_rec = _get_record(xapi, 'VIF', vif)
            nic[vif_rec['MAC']] = {
                'mac': vif_rec['MAC'],
                'device': vif_rec['device'],
                'mtu': vif_rec['MTU']
            }

        return nic
1247234
def get instance_reference, keys = nil
    if keys
      namespace = keys.delete(:namespace) || "root/cimv2"
      instance_reference = Sfcc::Cim::ObjectPath.new(namespace, instance_reference)
      keys.each do |k,v|
        instance_reference.add_key k, v
      end
    end
    puts "@client.get #{instance_reference.class}..." if Wbem.debug
    case instance_reference
    when Sfcc::Cim::ObjectPath
      get_by_objectpath instance_reference
    when String
      get_by_objectpath CimxmlClient.parse_object_path(instance_reference)
    else
      raise "Unsupported Wbem::get #{instance_reference.class}"
    end
  end
659231
async def get_vm(self, vm_id):
        '''
        
        '''
        result = await self.nova.servers.get(vm_id)
        return self._map_vm_structure(result["server"])
84508
def MI_getInstance(self,
                       env,
                       instanceName,
                       propertyList,
                       cimClass):
        # pylint: disable=invalid-name
        

        logger = env.get_logger()
        logger.log_debug('CIMProvider MI_getInstance called...')
        keyNames = get_keys_from_class(cimClass)
        plist = None
        if propertyList is not None:
            lkns = [kn.lower() for kn in keyNames]
            props = pywbem.NocaseDict()
            plist = [s.lower() for s in propertyList]
            pklist = plist + lkns
            [props.__setitem__(p.name, p) for p in cimClass.properties.values()
             if p.name.lower() in pklist]
        else:
            props = cimClass.properties
        _strip_quals(props)
        model = pywbem.CIMInstance(classname=instanceName.classname,
                                   properties=props,
                                   path=instanceName)
        for k, v in instanceName.keybindings.items():
            type_ = cimClass.properties[k].type

            if type_ != 'reference':
                v = val = pywbem.tocimobj(_type, v)
            model.__setitem__(k, pywbem.CIMProperty(name=k, type=type_,
                                                    value=v))

        rval = self.get_instance(env=env,
                                 model=model,
                                 cim_class=cimClass)
        if self.filter_results:
            filter_instance(rval, plist)
        logger.log_debug('CIMProvider MI_getInstance returning')
        if rval is None:
            raise pywbem.CIMError(pywbem.CIM_ERR_NOT_FOUND, "")
        return rval
1296995
def get(self, name, return_json=False, quiet=False):
    '''
    '''
    from spython.utils import check_install
    check_install()

    # Ensure compatible for singularity prior to 3.0, and after 3.0
    subgroup = "instance.list"

    if 'version 3' in self.version():
        subgroup = ["instance", "list"]

    cmd = self._init_command(subgroup)

    cmd.append(name)
    output = run_command(cmd, quiet=True)

    # Success, we have instances

    if output['return_code'] == 0:

        # Only print the table if we are returning json
        if quiet is False:
            print(''.join(output['message']))

        # Prepare json result from table

        header = ['daemon_name','pid','container_image']
        instances = parse_table(output['message'][0], header)

        # Does the user want instance objects instead?
        listing = []
        if return_json is False:
            for i in instances:
                new_instance = Instance(pid=i['pid'],
                                        name=i['daemon_name'],
                                        image=i['container_image'],
                                        start=False)

                listing.append(new_instance)
            instances = listing

    # Couldn't get UID

    elif output['return_code'] == 255:
        bot.error("Couldn't get UID")
        
    # Return code of 0
    else:
        bot.info('No instances found.')

    # If we are given a name, return just one
    if name is not None and len(instances) == 1:
        instances = instances[0]

    return instances
373788
def get_vm_failfast(self, name, verbose=False, vm_term='VM', path=""):
        
        if verbose:
            print("Finding VirtualMachine named %s..." % name)
        if path:
            vm = self.get_vm(name, path=path)
        else:
            vm = self.get_vm(name)
        if vm is None:
            print("Error: %s '%s' does not exist" % (vm_term, name))
            sys.exit(1)

        if verbose:
            print("Found VirtualMachine: %s Name: %s" % (vm, vm.name))

        return vm
1024817
def show_instance(name, conn=None, call=None):
    '''
    

    '''
    if call != 'action':
        raise SaltCloudSystemExit(
            'The show_instance action must be called with -a or --action.'
        )
    if conn is None:
        conn = get_conn()

    node = conn.get_server(name, bare=True)
    ret = dict(node)
    ret['id'] = node.id
    ret['name'] = node.name
    ret['size'] = conn.get_flavor(node.flavor.id).name
    ret['state'] = node.status
    ret['private_ips'] = _get_ips(node, 'private')
    ret['public_ips'] = _get_ips(node, 'public')
    ret['floating_ips'] = _get_ips(node, 'floating')
    ret['fixed_ips'] = _get_ips(node, 'fixed')
    if isinstance(node.image, six.string_types):
        ret['image'] = node.image
    else:
        ret['image'] = conn.get_image(node.image.id).name
    return ret
869690
def show_instance(name, call=None):
    '''
    
    '''
    if call != 'action':
        raise SaltCloudSystemExit(
            'The show_instance action must be called with -a or --action.'
        )
    node = _get_node(name)
    __utils__['cloud.cache_node'](node, __active_provider_name__, __opts__)
    return node
1084764
def show_instance(vm_name, call=None):
    '''
    
    '''
    if call != 'action':
        raise SaltCloudSystemExit(
            'The show_instance action must be called with -a or --action.'
        )
    conn = get_conn()
    node = _expand_node(conn.ex_get_node(vm_name))
    __utils__['cloud.cache_node'](node, __active_provider_name__, __opts__)
    return node
1305619
def get_vm_id(kwargs=None, call=None):
    '''
    
    '''
    if call == 'action':
        raise SaltCloudSystemExit(
            'The get_vm_id function must be called with -f or --function.'
        )

    if kwargs is None:
        kwargs = {}

    name = kwargs.get('name', None)
    if name is None:
        raise SaltCloudSystemExit(
            'The get_vm_id function requires a name.'
        )

    try:
        ret = list_nodes()[name]['id']
    except KeyError:
        raise SaltCloudSystemExit(
            'The VM \'{0}\' could not be found.'.format(name)
        )

    return ret
1104777
def _get_server(vm_):
    '''
    
    '''
    description = config.get_cloud_config_value(
        'description', vm_, __opts__, default=None,
        search_global=False
    )

    ssh_key = load_public_key(vm_)

    server_type = config.get_cloud_config_value(
        'server_type', vm_, __opts__, default='cloud',
        search_global=False
    )
    vcore = None
    cores_per_processor = None
    ram = None
    fixed_instance_size_id = None
    baremetal_model_id = None

    if 'fixed_instance_size' in vm_:
        fixed_instance_size = get_size(vm_)
        fixed_instance_size_id = fixed_instance_size['id']
    elif 'vm_core' in vm_ and 'cores_per_processor' in vm_ and 'ram' in vm_ and 'hdds' in vm_:
        vcore = config.get_cloud_config_value(
            'vcore', vm_, __opts__, default=None,
            search_global=False
        )
        cores_per_processor = config.get_cloud_config_value(
            'cores_per_processor', vm_, __opts__, default=None,
            search_global=False
        )
        ram = config.get_cloud_config_value(
            'ram', vm_, __opts__, default=None,
            search_global=False
        )
    elif 'baremetal_model_id' in vm_ and server_type == 'baremetal':
        baremetal_model_id = config.get_cloud_config_value(
            'baremetal_model_id', vm_, __opts__, default=None,
            search_global=False
        )
    else:
        raise SaltCloudConfigError("'fixed_instance_size' or 'vcore', "
                                   "'cores_per_processor', 'ram', and 'hdds' "
                                   "must be provided for 'cloud' server. "
                                   "For 'baremetal' server, 'baremetal_model_id'"
                                   "must be provided.")

    appliance_id = config.get_cloud_config_value(
        'appliance_id', vm_, __opts__, default=None,
        search_global=False
    )

    password = config.get_cloud_config_value(
        'password', vm_, __opts__, default=None,
        search_global=False
    )

    firewall_policy_id = config.get_cloud_config_value(
        'firewall_policy_id', vm_, __opts__, default=None,
        search_global=False
    )

    ip_id = config.get_cloud_config_value(
        'ip_id', vm_, __opts__, default=None,
        search_global=False
    )

    load_balancer_id = config.get_cloud_config_value(
        'load_balancer_id', vm_, __opts__, default=None,
        search_global=False
    )

    monitoring_policy_id = config.get_cloud_config_value(
        'monitoring_policy_id', vm_, __opts__, default=None,
        search_global=False
    )

    datacenter_id = config.get_cloud_config_value(
        'datacenter_id', vm_, __opts__, default=None,
        search_global=False
    )

    private_network_id = config.get_cloud_config_value(
        'private_network_id', vm_, __opts__, default=None,
        search_global=False
    )

    power_on = config.get_cloud_config_value(
        'power_on', vm_, __opts__, default=True,
        search_global=False
    )

    public_key = config.get_cloud_config_value(
        'public_key_ids', vm_, __opts__, default=None,
        search_global=False
    )

    # Contruct server object
    return Server(
        name=vm_['name'],
        description=description,
        fixed_instance_size_id=fixed_instance_size_id,
        vcore=vcore,
        cores_per_processor=cores_per_processor,
        ram=ram,
        appliance_id=appliance_id,
        password=password,
        power_on=power_on,
        firewall_policy_id=firewall_policy_id,
        ip_id=ip_id,
        load_balancer_id=load_balancer_id,
        monitoring_policy_id=monitoring_policy_id,
        datacenter_id=datacenter_id,
        rsa_key=ssh_key,
        private_network_id=private_network_id,
        public_key=public_key,
        server_type=server_type,
        baremetal_model_id=baremetal_model_id
    )