Confirm block_device, create as loopback if necessary.

    :param block_device: str: Full path of block device to ensure.

    :returns: str: Full path of ensured block device.
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
1304385
def _sanity_check_query_root_block(ir_blocks):
    """"""
    if not isinstance(ir_blocks[0], QueryRoot):
        raise AssertionError(u'The first block was not QueryRoot: {}'.format(ir_blocks))
    for block in ir_blocks[1:]:
        if isinstance(block, QueryRoot):
            raise AssertionError(u'Found QueryRoot after the first block: {}'.format(ir_blocks))
195991
def _sign_block(self, block):
        
        block_header = block.block_header
        header_bytes = block_header.SerializeToString()
        signature = self._identity_signer.sign(header_bytes)
        block.set_signature(signature)
        return block
1350258
def get_secret_registration_block_by_secrethash(
            self,
            secrethash: SecretHash,
            block_identifier: BlockSpecification,
    ) -> Optional[BlockNumber]:
        
        result = self.proxy.contract.functions.getSecretRevealBlockHeight(
            secrethash,
        ).call(block_identifier=block_identifier)

        # Block 0 either represents the genesis block or an empty entry in the
        # secret mapping. This is important for custom genesis files used while
        # testing. To avoid problems the smart contract can be added as part of
        # the genesis file, however it's important for its storage to be
        # empty.
        if result == 0:
            return None

        return result
560774
async def SetMachineBlockDevices(self, machine_block_devices):
        '''
        
        '''
        # map input types to rpc msg
        _params = dict()
        msg = dict(type='DiskManager',
                   request='SetMachineBlockDevices',
                   version=2,
                   params=_params)
        _params['machine-block-devices'] = machine_block_devices
        reply = await self.rpc(msg)
        return reply
404909
def get_block_count(self, is_full: bool = False) -> int or dict:
        
        payload = self.generate_json_rpc_payload(RpcMethod.GET_BLOCK_COUNT)
        response = self.__post(self.__url, payload)
        if is_full:
            return response
        return response['result']
926284
def is_mapped_luks_device(dev):
    
    _, dirs, _ = next(os.walk(
        '/sys/class/block/{}/holders/'
        .format(os.path.basename(os.path.realpath(dev))))
    )
    is_held = len(dirs) > 0
    return is_held and is_luks_device(dev)
123741
def backup_restore(cls, block_id, impl, working_dir):
        
        backup_dir = config.get_backups_directory(impl, working_dir)
        backup_paths = cls.get_backup_paths(block_id, impl, working_dir)
        for p in backup_paths:
            assert os.path.exists(p), "No such backup file: {}".format(p)

        for p in cls.get_state_paths(impl, working_dir):
            pbase = os.path.basename(p)
            backup_path = os.path.join(backup_dir, pbase + (".bak.{}".format(block_id)))
            log.debug("Restoring '{}' to '{}'".format(backup_path, p))
            shutil.copy(backup_path, p)
    
        return True
472159
def _ensure_device_active(self, device):
        '''
        '''

        act = device.tm.cm.devices.device.load(
            name=get_device_info(device).name,
            partition=self.partition
        )
        if act.failoverState != 'active':
            msg = "A device in the cluster was not in the 'Active' state."
            raise UnexpectedDeviceGroupState(msg)
145607
def confirm(bool, &block)
      blk = "lambda { #{bool} }"
      
      self.send_remote(:add_listener, :confirm) { blk }
      block.call
      self.send_remote(:remove_listener, :confirm, lambda {blk})
    end
234265
def get_block_statuses(self, block_ids):
        
        try:
            return [
                (block_id.hex(),
                 self._chain_controller.block_validation_result(
                     block_id.hex()))
                for block_id in block_ids
            ]
        except KeyError as key_error:
            raise UnknownBlock(key_error.args[0])
1147193
function getInfoBlock (device, location, callback) {
    getFeatureReport(location, 33, function (err, buffer) {
        if (typeof(err) !== 'undefined')
        {
            callback(err);
            return;
        }

        var result = '',
        i, l;

        for (i = 1, l = buffer.length; i < l; i++) {
            if (i === 0) break;
            result += String.fromCharCode(buffer[i]);
        }

        callback(err, result);
    });
}
610460
def get_block_height(self, is_full: bool = False) -> int or dict:
        
        response = self.get_block_count(is_full=True)
        response['result'] -= 1
        if is_full:
            return response
        return response['result']
1354748
def have_all_block_data(self):
        
        if not (self.num_blocks_received == self.num_blocks_requested):
            log.debug("num blocks received = %s, num requested = %s" % (self.num_blocks_received, self.num_blocks_requested))
            return False

        return True
205317
def Verify(self):
        
        if not self.Hash.ToBytes() == GetGenesis().Hash.ToBytes():
            return False

        bc = GetBlockchain()

        if not bc.ContainsBlock(self.Index):
            return False

        if self.Index > 0:
            prev_header = GetBlockchain().GetHeader(self.PrevHash.ToBytes())

            if prev_header is None:
                return False

            if prev_header.Index + 1 != self.Index:
                return False

            if prev_header.Timestamp >= self.Timestamp:
                return False

        # this should be done to actually verify the block
        if not Helper.VerifyScripts(self):
            return False

        return True
1367785
def device_add(self, mountpoint, *device):
        
        if len(device) == 0:
            return

        args = {
            'mountpoint': mountpoint,
            'devices': device,
        }

        self._device_chk.check(args)

        self._client.sync('btrfs.device_add', args)
1327795
def get(self, block_id):
        

        pool = current_app.config['bigchain_pool']

        with pool() as bigchain:
            block = bigchain.get_block(block_id=block_id)

        if not block:
            return make_error(404)

        return block