Return the bcache UUID of a block device.
    If no device is given, the Cache UUID is returned.

    CLI example:

    .. code-block:: bash

        salt '*' bcache.uuid
        salt '*' bcache.uuid /dev/sda
        salt '*' bcache.uuid bcache0
4141
def uuid(dev=None):
    '''
    

    '''
    try:
        if dev is None:
            # take the only directory in /sys/fs/bcache and return it's basename
            return list(salt.utils.path.os_walk('/sys/fs/bcache/'))[0][1][0]
        else:
            # basename of the /sys/block/{dev}/bcache/cache symlink target
            return os.path.basename(_bcsys(dev, 'cache'))
    except Exception:
        return False
1035433
def dev_cache(self, device, key=None):
        """"""
        device_cache = self._cache.get(CONST.DEVICES, {}).get(device.device_id)

        if device_cache and key:
            return device_cache.get(key)

        return device_cache
1372640
def get_block(block_id, api_code=None):
    

    resource = 'rawblock/' + block_id
    if api_code is not None:
        resource += '?api_code=' + api_code
    response = util.call_api(resource)
    json_response = json.loads(response)
    return Block(json_response)
299295
def _get_hash_by_shell():
    '''
    
    '''
    id_ = __opts__.get('id', '')
    id_hash = None
    py_ver = sys.version_info[:2]
    if py_ver >= (3, 3):
        # Python 3.3 enabled hash randomization, so we need to shell out to get
        # a reliable hash.
        id_hash = __salt__['cmd.run']([sys.executable, '-c', 'print(hash("{0}"))'.format(id_)],
                                      env={'PYTHONHASHSEED': '0'})
        try:
            id_hash = int(id_hash)
        except (TypeError, ValueError):
            log.debug('Failed to hash the ID to get the server_id grain. Result of hash command: %s', id_hash)
            id_hash = None
    if id_hash is None:
        # Python < 3.3 or error encountered above
        id_hash = hash(id_)

    return abs(id_hash % (2 ** 31))
281919
function getDeviceId(req) {

        // NOTE: client_id and client_secret are deprecated so eventually remove
        var deviceId = req.headers['x-device-id'];
        var deviceSecret = req.headers['x-device-secret'];

        // if client ID and secret don't exist, then no device
        if (!deviceId || !deviceSecret) { return null; }

        // else we have a device, so check the sha hash
        var shasum = crypto.createHash('md5').update(deviceId + config.security.device.salt);
        var digest = shasum.digest('hex');

        // if the digest is not the same as the secret, request is unauthorized
        if (digest !== deviceSecret) {
            log.error('Invalid device ' + deviceId + ' with secret ' + deviceSecret, null);
            return null;
        }
        // else the device is valid, so set it and move on
        else {
            return deviceId;
        }
    }
1298895
def eth_getBlockTransactionCountByHash(self, bhash):
        
        response = yield from self.rpc_call('eth_getBlockTransactionCountByHash',
                                            [bhash])
        if response:
            return hex_to_dec(response)
        return response
332105
def get_vlan_assignment_uuid(self):
        
        vlan_uuid_cmd = self.cli_commands['resource-pool']
        if vlan_uuid_cmd:
            return self._run_eos_cmds(commands=vlan_uuid_cmd)[0]
        return None
926883
def get_server(self, UUID):
        
        server, IPAddresses, storages = self.get_server_data(UUID)

        return Server(
            server,
            ip_addresses=IPAddresses,
            storage_devices=storages,
            populated=True,
            cloud_manager=self
        )
646939
def get_server_data(self, UUID):
        
        data = self.get_request('/server/{0}'.format(UUID))
        server = data['server']

        # Populate subobjects
        IPAddresses = IPAddress._create_ip_address_objs(server.pop('ip_addresses'),
                                                          cloud_manager=self)

        storages = Storage._create_storage_objs(server.pop('storage_devices'),
                                                cloud_manager=self)

        return server, IPAddresses, storages
563096
def local_machine_uuid():
    

    result = subprocess.check_output(
        'hal-get-property --udi '
        '/org/freedesktop/Hal/devices/computer '
        '--key system.hardware.uuid'.split()
        ).strip()

    return uuid.UUID(hex=result)
959433
def _get_template_pool_lock(self, id):
        """"""
        try:
            return self._hosting_device_locks[id]
        except KeyError:
            self._hosting_device_locks[id] = threading.Lock()
            return self._hosting_device_locks.get(id)
346206
def get_identity_document(current_block: dict, uid: str, salt: str, password: str) -> Identity:
    

    # get current block BlockStamp
    timestamp = BlockUID(current_block['number'], current_block['hash'])

    # create keys from credentials
    key = SigningKey.from_credentials(salt, password)

    # create identity document
    identity = Identity(
        version=10,
        currency=current_block['currency'],
        pubkey=key.pubkey,
        uid=uid,
        ts=timestamp,
        signature=None
    )

    # sign document
    identity.sign([key])

    return identity
967457
def ensure_block_device(block_device):
    '''
    
    '''
    _none = ['None', 'none', None]
    if (block_device in _none):
        error_out('prepare_storage(): Missing required input: block_device=%s.'
                  % block_device)

    if block_device.startswith('/dev/'):
        bdev = block_device
    elif block_device.startswith('/'):
        _bd = block_device.split('|')
        if len(_bd) == 2:
            bdev, size = _bd
        else:
            bdev = block_device
            size = DEFAULT_LOOPBACK_SIZE
        bdev = ensure_loopback_device(bdev, size)
    else:
        bdev = '/dev/%s' % block_device

    if not is_block_device(bdev):
        error_out('Failed to locate valid block device at %s' % bdev)

    return bdev
127122
def get_connectware_id(self, use_cached=True):
        """"""
        device_json = self.get_device_json(use_cached)
        return device_json.get("devConnectwareId")
893575
def get_keyid(keyname):
    '''
    
    '''
    if not keyname:
        return None
    keypairs = list_keypairs(call='function')
    keyid = keypairs[keyname]['id']
    if keyid:
        return keyid
    raise SaltCloudNotFound('The specified ssh key could not be found.')
666441
def get_uid(user=None):
    '''
    
    '''
    if not HAS_PWD:
        return None
    elif user is None:
        try:
            return os.geteuid()
        except AttributeError:
            return None
    else:
        try:
            return pwd.getpwnam(user).pw_uid
        except KeyError:
            return None
1126427
def get_current_block_hash(self, is_full: bool = False) -> str:
        
        payload = self.generate_json_rpc_payload(RpcMethod.GET_CURRENT_BLOCK_HASH)
        response = self.__post(self.__url, payload)
        if is_full:
            return response
        return response['result']