Exemplo n.º 1
0
 def main(self):
     parser = argparse.ArgumentParser(
         prog='ceph-volume inventory',
         formatter_class=argparse.RawDescriptionHelpFormatter,
         description=self.help,
     )
     parser.add_argument(
         'path',
         nargs='?',
         default=None,
         help=('Report on specific disk'),
     )
     parser.add_argument(
         '--format',
         choices=['plain', 'json', 'json-pretty'],
         default='plain',
         help='Output format',
     )
     parser.add_argument(
         '--filter-for-batch',
         action='store_true',
         help=('Filter devices unsuitable to pass to an OSD service spec, '
               'no effect when <path> is passed'),
         default=False,
     )
     self.args = parser.parse_args(self.argv)
     if self.args.path:
         self.format_report(Device(self.args.path))
     else:
         self.format_report(
             Devices(filter_for_batch=self.args.filter_for_batch))
Exemplo n.º 2
0
Arquivo: dg.py Projeto: gekios/DeepSea
 def _find_data_partition(self) -> str:
     """ Find data partition in all partitions """
     partitions = self.device.sys_api.get('partitions', dict())
     for partition in list(partitions.keys()):
         part = Device(f"/dev/{partition}")
         if part.ceph_disk.type == 'data':
             return part.abspath
     return ''
Exemplo n.º 3
0
    def __call__(self, string):
        device = Device(string)
        if not device.exists:
            raise argparse.ArgumentError(
                None,
                "Unable to proceed with non-existing device: %s" % string)

        return device
Exemplo n.º 4
0
def legacy_encrypted(device):
    """
    Detect if a device was encrypted with ceph-disk or not. In the case of
    encrypted devices, include the type of encryption (LUKS, or PLAIN), and
    infer what the lockbox partition is.

    This function assumes that ``device`` will be a partition.
    """
    if os.path.isdir(device):
        mounts = system.get_mounts(paths=True)
        # yes, rebind the device variable here because a directory isn't going
        # to help with parsing
        device = mounts.get(device, [None])[0]
        if not device:
            raise RuntimeError('unable to determine the device mounted at %s' %
                               device)
    metadata = {
        'encrypted': False,
        'type': None,
        'lockbox': '',
        'device': device
    }
    # check if the device is online/decrypted first
    active_mapper = status(device)
    if active_mapper:
        # normalize a bit to ensure same values regardless of source
        metadata['type'] = active_mapper['type'].lower().strip(
            '12')  # turn LUKS1 or LUKS2 into luks
        metadata['encrypted'] = True if metadata['type'] in ['plain', 'luks'
                                                             ] else False
        # The true device is now available to this function, so it gets
        # re-assigned here for the lockbox checks to succeed (it is not
        # possible to guess partitions from a device mapper device otherwise
        device = active_mapper.get('device', device)
        metadata['device'] = device
    else:
        uuid = get_part_entry_type(device)
        guid_match = constants.ceph_disk_guids.get(uuid, {})
        encrypted_guid = guid_match.get('encrypted', False)
        if encrypted_guid:
            metadata['encrypted'] = True
            metadata['type'] = guid_match['encryption_type']

    # Lets find the lockbox location now, to do this, we need to find out the
    # parent device name for the device so that we can query all of its
    # associated devices and *then* look for one that has the 'lockbox' label
    # on it. Thanks for being awesome ceph-disk
    disk_meta = lsblk(device, abspath=True)
    if not disk_meta:
        return metadata
    parent_device = disk_meta['PKNAME']
    # With the parent device set, we can now look for the lockbox listing associated devices
    devices = [Device(i['NAME']) for i in device_family(parent_device)]
    for d in devices:
        if d.ceph_disk.type == 'lockbox':
            metadata['lockbox'] = d.path
            break
    return metadata
Exemplo n.º 5
0
    def zap_lvm_member(self, device):
        """
        An LVM member may have more than one LV and or VG, for example if it is
        a raw device with multiple partitions each belonging to a different LV

        Device example: /dev/sda
        Requirements: An LV or VG present in the device, making it an LVM member
        """
        for lv in device.lvs:
            self.zap_lv(Device(lv.lv_path))
Exemplo n.º 6
0
    def __call__(self, string):
        device = Device(string)
        error = None
        if not device.exists:
            error = "Unable to proceed with non-existing device: %s" % string
        elif device.has_gpt_headers:
            error = "GPT headers found, they must be removed on: %s" % string

        if error:
            raise argparse.ArgumentError(None, error)

        if self.as_string:
            if device.is_lv:
                # all codepaths expect an lv path to be returned in this format
                return "{}/{}".format(device.vg_name, device.lv_name)
            return string
        return device
Exemplo n.º 7
0
Arquivo: zap.py Projeto: drunkard/ceph
    def zap_lvm_member(self, device):
        """
        An LVM member may have more than one LV and or VG, for example if it is
        a raw device with multiple partitions each belonging to a different LV

        Device example: /dev/sda
        Requirements: An LV or VG present in the device, making it an LVM member
        """
        for lv in device.lvs:
            if lv.lv_name:
                mlogger.info('Zapping lvm member {}. lv_path is {}'.format(device.path, lv.lv_path))
                self.zap_lv(Device(lv.lv_path))
            else:
                vg = api.get_single_vg(filters={'vg_name': lv.vg_name})
                if vg:
                    mlogger.info('Found empty VG {}, removing'.format(vg.vg_name))
                    api.remove_vg(vg.vg_name)
Exemplo n.º 8
0
    def _is_valid_device(self, dev_path):
        device = Device(dev_path)
        error = None
        if not device.exists:
            error = "Unable to proceed with non-existing device: %s" % dev_path
        # FIXME this is not a nice API, this validator was meant to catch any
        # non-existing devices upfront, not check for gpt headers. Now this
        # needs to optionally skip checking gpt headers which is beyond
        # verifying if the device exists. The better solution would be to
        # configure this with a list of checks that can be excluded/included on
        # __init__
        elif device.has_gpt_headers and not self.gpt_ok:
            error = "GPT headers found, they must be removed on: %s" % dev_path

        if error:
            raise argparse.ArgumentError(None, error)

        return device
Exemplo n.º 9
0
def find_associated_devices(osd_id, osd_fsid):
    """
    From an ``osd_id`` and/or an ``osd_fsid``, filter out all the LVs in the
    system that match those tag values, further detect if any partitions are
    part of the OSD, and then return the set of LVs and partitions (if any).
    """
    lv_tags = {}
    lv_tags['ceph.osd_id'] = osd_id
    lv_tags['ceph.osd_fsid'] = osd_fsid

    lvs = api.get_lvs(tags=lv_tags)
    if not lvs:
        mlogger.error(
            'Unable to find any LV for source OSD: id:{} fsid:{}'.format(
                osd_id,  osd_fsid)        )
        raise SystemExit('Unexpected error, terminating')

    devices = set(ensure_associated_lvs(lvs, lv_tags))
    return [(Device(path), type) for path, type in devices if path]
Exemplo n.º 10
0
def find_associated_devices(osd_id=None, osd_fsid=None):
    """
    From an ``osd_id`` and/or an ``osd_fsid``, filter out all the LVs in the
    system that match those tag values, further detect if any partitions are
    part of the OSD, and then return the set of LVs and partitions (if any).
    """
    lv_tags = {}
    if osd_id:
        lv_tags['ceph.osd_id'] = osd_id
    if osd_fsid:
        lv_tags['ceph.osd_fsid'] = osd_fsid
    lvs = api.Volumes()
    lvs.filter(lv_tags=lv_tags)
    if not lvs:
        raise RuntimeError('Unable to find any LV for zapping OSD: %s' % osd_id or osd_fsid)

    devices_to_zap = ensure_associated_lvs(lvs)

    return [Device(path) for path in set(devices_to_zap) if path]
Exemplo n.º 11
0
    def zap_raw_device(self, device):
        """
        Any whole (raw) device passed in as input will be processed here,
        checking for LVM membership and partitions (if any).

        Device example: /dev/sda
        Requirements: None
        """
        if not self.args.destroy:
            # the use of dd on a raw device causes the partition table to be
            # destroyed
            mlogger.warning(
                '--destroy was not specified, but zapping a whole device will remove the partition table'
            )

        # look for partitions and zap those
        for part_name in device.sys_api.get('partitions', {}).keys():
            self.zap_partition(Device('/dev/%s' % part_name))

        wipefs(device.abspath)
        zap_data(device.abspath)
Exemplo n.º 12
0
 def main(self):
     parser = argparse.ArgumentParser(
         prog='ceph-volume inventory',
         formatter_class=argparse.RawDescriptionHelpFormatter,
         description=self.help,
     )
     parser.add_argument(
         'path',
         nargs='?',
         default=None,
         help=('Report on specific disk'),
     )
     parser.add_argument(
         '--format',
         choices=['plain', 'json', 'json-pretty'],
         default='plain',
         help='Output format',
     )
     self.args = parser.parse_args(self.argv)
     if self.args.path:
         self.format_report(Device(self.args.path))
     else:
         self.format_report(Devices())
Exemplo n.º 13
0
    def __call__(self, string):
        device = Device(string)
        error = None
        if not device.exists:
            error = "Unable to proceed with non-existing device: %s" % string
        # FIXME this is not a nice API, this validator was meant to catch any
        # non-existing devices upfront, not check for gpt headers. Now this
        # needs to optionally skip checking gpt headers which is beyond
        # verifying if the device exists. The better solution would be to
        # configure this with a list of checks that can be excluded/included on
        # __init__
        elif device.has_gpt_headers and not self.gpt_ok:
            error = "GPT headers found, they must be removed on: %s" % string

        if error:
            raise argparse.ArgumentError(None, error)

        if self.as_string:
            if device.is_lv:
                # all codepaths expect an lv path to be returned in this format
                return "{}/{}".format(device.vg_name, device.lv_name)
            return string
        return device
Exemplo n.º 14
0
 def get_report(self):
     if self.args.path:
         return Device(self.args.path).json_report()
     else:
         return Devices(
             filter_for_batch=self.args.filter_for_batch).json_report()
Exemplo n.º 15
0
 def get_report(self):
     if self.args.path:
         return Device(self.args.path).json_report()
     else:
         return Devices().json_report()
Exemplo n.º 16
0
    def main(self):
        sub_command_help = dedent("""
        Scan running OSDs, an OSD directory (or data device) for files and configurations
        that will allow to take over the management of the OSD.

        Scanned OSDs will get their configurations stored in
        /etc/ceph/osd/<id>-<fsid>.json

        For an OSD ID of 0 with fsid of ``a9d50838-e823-43d6-b01f-2f8d0a77afc2``
        that could mean a scan command that looks like::

            ceph-volume lvm scan /var/lib/ceph/osd/ceph-0

        Which would store the metadata in a JSON file at::

            /etc/ceph/osd/0-a9d50838-e823-43d6-b01f-2f8d0a77afc2.json

        To scan all running OSDs:

            ceph-volume simple scan

        To a scan a specific running OSD:

            ceph-volume simple scan /var/lib/ceph/osd/{cluster}-{osd id}

        And to scan a device (mounted or unmounted) that has OSD data in it, for example /dev/sda1

            ceph-volume simple scan /dev/sda1

        Scanning a device or directory that belongs to an OSD not created by ceph-disk will be ingored.
        """)
        parser = argparse.ArgumentParser(
            prog='ceph-volume simple scan',
            formatter_class=argparse.RawDescriptionHelpFormatter,
            description=sub_command_help,
        )

        parser.add_argument(
            '-f', '--force',
            action='store_true',
            help='If OSD has already been scanned, the JSON file will be overwritten'
        )

        parser.add_argument(
            '--stdout',
            action='store_true',
            help='Do not save to a file, output metadata to stdout'
        )

        parser.add_argument(
            'osd_path',
            metavar='OSD_PATH',
            type=arg_validators.OSDPath(),
            nargs='?',
            default=None,
            help='Path to an existing OSD directory or OSD data partition'
        )

        args = parser.parse_args(self.argv)
        paths = []
        if args.osd_path:
            paths.append(args.osd_path)
        else:
            osd_ids = systemctl.get_running_osd_ids()
            for osd_id in osd_ids:
                paths.append("/var/lib/ceph/osd/{}-{}".format(
                    conf.cluster,
                    osd_id,
                ))

        # Capture some environment status, so that it can be reused all over
        self.device_mounts = system.get_mounts(devices=True)
        self.path_mounts = system.get_mounts(paths=True)

        for path in paths:
            args.osd_path = path
            device = Device(args.osd_path)
            if device.is_partition:
                if device.ceph_disk.type != 'data':
                    label = device.ceph_disk.partlabel
                    msg = 'Device must be the ceph data partition, but PARTLABEL reported: "%s"' % label
                    raise RuntimeError(msg)

            self.encryption_metadata = encryption.legacy_encrypted(args.osd_path)
            self.is_encrypted = self.encryption_metadata['encrypted']

            device = Device(self.encryption_metadata['device'])
            if not device.is_ceph_disk_member:
                terminal.warning("Ignoring %s because it's not a ceph-disk created osd." % path)
            else:
                self.scan(args)
Exemplo n.º 17
0
def get_(disk_path) -> dict:
    """ Get a json report for a given device """
    return Device(disk_path).json_report()
Exemplo n.º 18
0
Arquivo: dg.py Projeto: gekios/DeepSea
 def __init__(self, path):
     self.path = path
     self.device = Device(self.path)
     self.error = ''
Exemplo n.º 19
0
 def get_device(self, dev_path):
     self._device = Device(dev_path)
     self.dev_path = dev_path
Exemplo n.º 20
0
    def main(self):
        sub_command_help = dedent("""
        Scan an OSD directory (or data device) for files and configurations
        that will allow to take over the management of the OSD.

        Scanned OSDs will get their configurations stored in
        /etc/ceph/osd/<id>-<fsid>.json

        For an OSD ID of 0 with fsid of ``a9d50838-e823-43d6-b01f-2f8d0a77afc2``
        that could mean a scan command that looks like::

            ceph-volume lvm scan /var/lib/ceph/osd/ceph-0

        Which would store the metadata in a JSON file at::

            /etc/ceph/osd/0-a9d50838-e823-43d6-b01f-2f8d0a77afc2.json

        To a scan an existing, running, OSD:

            ceph-volume simple scan /var/lib/ceph/osd/{cluster}-{osd id}

        And to scan a device (mounted or unmounted) that has OSD data in it, for example /dev/sda1

            ceph-volume simple scan /dev/sda1
        """)
        parser = argparse.ArgumentParser(
            prog='ceph-volume simple scan',
            formatter_class=argparse.RawDescriptionHelpFormatter,
            description=sub_command_help,
        )

        parser.add_argument(
            '-f',
            '--force',
            action='store_true',
            help=
            'If OSD has already been scanned, the JSON file will be overwritten'
        )

        parser.add_argument(
            '--stdout',
            action='store_true',
            help='Do not save to a file, output metadata to stdout')

        parser.add_argument(
            'osd_path',
            metavar='OSD_PATH',
            type=arg_validators.OSDPath(),
            nargs='?',
            help='Path to an existing OSD directory or OSD data partition')

        if len(self.argv) == 0:
            print(sub_command_help)
            return

        args = parser.parse_args(self.argv)
        device = Device(args.osd_path)
        if device.is_partition:
            if device.ceph_disk.type != 'data':
                label = device.ceph_disk.partlabel
                msg = 'Device must be the ceph data partition, but PARTLABEL reported: "%s"' % label
                raise RuntimeError(msg)

        # Capture some environment status, so that it can be reused all over
        self.device_mounts = system.get_mounts(devices=True)
        self.path_mounts = system.get_mounts(paths=True)
        self.encryption_metadata = encryption.legacy_encrypted(args.osd_path)
        self.is_encrypted = self.encryption_metadata['encrypted']

        self.scan(args)