예제 #1
0
 def get_all(self):
     """Get all available storage devices attached to this system
     """
     if self._fake_devices:
         return self._fake_devices
     from ovirtnode.ovirtfunctions import translate_multipath_device
     dev_names, disk_dict = self._storage.get_udev_devices()
     devices = {}
     for _dev in dev_names:
         dev = translate_multipath_device(_dev)
         self.logger.debug("Checking device %s (%s)" % (dev, _dev))
         if dev in devices:
             self.logger.warning("Device is already in dict: %s" % dev)
             continue
         if dev not in disk_dict:
             self.logger.warning("Device in names but not in dict: " +
                                 "%s" % dev)
             continue
         if dev == self.live_disk_name():
             self.logger.info("Ignoring device " +
                              "%s it's the live media" % dev)
             continue
         infos = disk_dict[dev].split(",", 5)
         device = Device(dev, *infos)
         device.name = os.path.basename(device.name).replace(" ", "")
         device.name = translate_multipath_device(device.name)
         if device.name in devices:
             self.logger.debug("Device with same name already " +
                               "exists: %s" % device.name)
         devices[device.path] = device
     return devices
예제 #2
0
 def get_all(self):
     """Get all available storage devices attached to this system
     """
     if self._fake_devices:
         return self._fake_devices
     from ovirtnode.ovirtfunctions import translate_multipath_device
     dev_names, disk_dict = self._storage.get_udev_devices()
     devices = {}
     for _dev in dev_names:
         dev = translate_multipath_device(_dev)
         self.logger.debug("Checking device %s (%s)" % (dev, _dev))
         if dev in devices:
             self.logger.warning("Device is already in dict: %s" % dev)
             continue
         if dev not in disk_dict:
             self.logger.warning("Device in names but not in dict: " +
                                 "%s" % dev)
             continue
         if dev == self.live_disk_name():
             self.logger.info("Ignoring device " +
                              "%s it's the live media" % dev)
             continue
         infos = disk_dict[dev].split(",", 5)
         device = Device(dev, *infos)
         device.name = os.path.basename(device.name).replace(" ", "")
         device.name = translate_multipath_device(device.name)
         if device.name in devices:
             self.logger.debug("Device with same name already " +
                               "exists: %s" % device.name)
         devices[device.path] = device
     return devices
예제 #3
0
 def cross_check_host_app(self):
     logger.debug("Doing cross-check (if a device is a member of appvg " +
                  "and hostvg)")
     hostvg_drives = self.HOSTVGDRIVE.strip(",").split(",")
     if self.ROOTDRIVE:
         hostvg_drives.append(self.ROOTDRIVE)
     # Translate to DM name as APPVG is using it
     hostvg_drives = [_functions.translate_multipath_device(drv)
                      for drv in hostvg_drives]
     return Storage._xcheck_vgs(hostvg_drives, self.APPVGDRIVE)
예제 #4
0
 def get_all(self):
     """Get all available storage devices attached to this system
     """
     if self._fake_devices:
         return self._fake_devices
     from ovirtnode.ovirtfunctions import translate_multipath_device
     from ovirtnode.ovirtfunctions import subprocess_closefds
     dev_names, disk_dict = self._storage.get_udev_devices()
     devices = {}
     for _dev in dev_names:
         dev = translate_multipath_device(_dev)
         self.logger.debug("Checking device %s (%s)" % (dev, _dev))
         disk_type_cmd = ["lsblk", "-ino", "TYPE", dev, "--nodeps"]
         disk_type_popen = subprocess_closefds(disk_type_cmd,
                                               stdout=subprocess.PIPE,
                                               stderr=subprocess.STDOUT)
         dev_type, dev_type_err = disk_type_popen.communicate()
         if not dev_type.strip() in ("disk", "mpath"):
             self.logger.warning("Type is %s" % dev_type)
             self.logger.warning("Device is not disk %s" % dev)
             continue
         if dev in devices:
             self.logger.warning("Device is already in dict: %s" % dev)
             continue
         if dev not in disk_dict:
             self.logger.warning("Device in names but not in dict: " +
                                 "%s" % dev)
             continue
         if dev == self.live_disk_name():
             self.logger.info("Ignoring device " +
                              "%s it's the live media" % dev)
             continue
         infos = disk_dict[dev].split(",", 5)
         device = Device(dev, *infos)
         device.name = os.path.basename(device.name).replace(" ", "")
         device.name = translate_multipath_device(device.name)
         if device.name in devices:
             self.logger.debug("Device with same name already " +
                               "exists: %s" % device.name)
         devices[device.path] = device
     return devices
예제 #5
0
 def get_all(self):
     """Get all available storage devices attached to this system
     """
     if self._fake_devices:
         return self._fake_devices
     from ovirtnode.ovirtfunctions import translate_multipath_device
     from ovirtnode.ovirtfunctions import subprocess_closefds
     dev_names, disk_dict = self._storage.get_udev_devices()
     devices = {}
     for _dev in dev_names:
         dev = translate_multipath_device(_dev)
         self.logger.debug("Checking device %s (%s)" % (dev, _dev))
         disk_type_cmd = ["lsblk", "-ino", "TYPE", dev, "--nodeps"]
         disk_type_popen = subprocess_closefds(disk_type_cmd,
                                               stdout=subprocess.PIPE,
                                               stderr=subprocess.STDOUT)
         dev_type, dev_type_err = disk_type_popen.communicate()
         if not dev_type.strip() in ("disk", "mpath"):
             self.logger.warning("Type is %s" % dev_type)
             self.logger.warning("Device is not disk %s" % dev)
             continue
         if dev in devices:
             self.logger.warning("Device is already in dict: %s" % dev)
             continue
         if dev not in disk_dict:
             self.logger.warning("Device in names but not in dict: " +
                                 "%s" % dev)
             continue
         if dev == self.live_disk_name():
             self.logger.info("Ignoring device " +
                              "%s it's the live media" % dev)
             continue
         infos = disk_dict[dev].split(",", 5)
         device = Device(dev, *infos)
         device.name = os.path.basename(device.name).replace(" ", "")
         device.name = translate_multipath_device(device.name)
         if device.name in devices:
             self.logger.debug("Device with same name already " +
                               "exists: %s" % device.name)
         devices[device.path] = device
     return devices
예제 #6
0
    def get_udev_devices(self):
        self.disk_dict = {}
        client = gudev.Client(['block'])
        for device in client.query_by_subsystem("block"):
            dev_name = device.get_property("DEVNAME")
            dev_bus = device.get_property("ID_BUS")
            dev_model = device.get_property("ID_MODEL")
            dev_serial = device.get_property("ID_SERIAL")
            dev_desc = device.get_property("ID_SCSI_COMPAT")
            dev_size_cmd = "sfdisk -s %s 2>/dev/null" % dev_name
            dev_size = _functions.subprocess_closefds(dev_size_cmd,
                                                      shell=True,
                                                      stdout=subprocess.PIPE,
                                                      stderr=subprocess.STDOUT)
            dev_size = dev_size.stdout.read()
            size_failed = 0
            if not device.get_property("ID_CDROM"):
                try:
                    dev_size = int(dev_size) / 1024 / 1024
                except:
                    size_failed = 1
            if not dev_desc:
                if "/dev/vd" in dev_name:
                    dev_desc = "virtio disk"
                elif dev_serial is not None:
                    dev_desc = dev_serial
                else:
                    dev_desc = "unknown"
            if (not device.get_property("ID_CDROM")
                    and not "/dev/dm-" in dev_name
                    and not "/dev/loop" in dev_name and size_failed == 0):
                dev_name = _functions.translate_multipath_device(dev_name)
                busmap = { \
                    "usb": "USB Device          ", \
                    "ata": "Local / FibreChannel", \
                    "scsi": "Local / FibreChannel", \
                    "cciss": "CCISS               " \
                }
                if dev_bus in busmap:
                    dev_bus = busmap[dev_bus]
                elif "/dev/vd" in dev_name:
                    dev_bus = "Local (Virtio)      "
                else:
                    dev_bus = "                    "

                self.disk_dict[dev_name] = "%s,%s,%s,%s,%s,%s" % (
                    dev_bus, dev_name, dev_size, dev_desc, dev_serial,
                    dev_model)
        devs = self.get_dev_name()
        return (sorted(devs), self.disk_dict)
예제 #7
0
    def get_udev_devices(self):
        self.disk_dict = {}
        client = gudev.Client(['block'])
        for device in client.query_by_subsystem("block"):
            dev_name = device.get_property("DEVNAME")
            dev_bus = device.get_property("ID_BUS")
            dev_model = device.get_property("ID_MODEL")
            dev_serial = device.get_property("ID_SERIAL")
            dev_desc = device.get_property("ID_SCSI_COMPAT")
            dev_size_cmd = "sfdisk -s %s 2>/dev/null" % dev_name
            dev_size_popen = _functions.subprocess_closefds(dev_size_cmd, shell=True,
                       stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
            dev_size, dev_size_err = dev_size_popen.communicate()
            size_failed = 0
            if not device.get_property("ID_CDROM"):
                try:
                    dev_size = int(dev_size) / 1024 / 1024
                except:
                    size_failed = 1
            if not dev_desc:
                if "/dev/vd" in dev_name:
                    dev_desc = "virtio disk"
                elif dev_serial is not None:
                    dev_desc = dev_serial
                else:
                    dev_desc = "unknown"
            if (not device.get_property("ID_CDROM") and
                    not "/dev/dm-" in dev_name and
                    not "/dev/loop" in dev_name and size_failed == 0):
                dev_name = _functions.translate_multipath_device(dev_name)
                busmap = { \
                    "usb": "USB Device          ", \
                    "ata": "Local / FibreChannel", \
                    "scsi": "Local / FibreChannel", \
                    "cciss": "CCISS               " \
                }
                if dev_bus in busmap:
                    dev_bus = busmap[dev_bus]
                elif "/dev/vd" in dev_name:
                    dev_bus = "Local (Virtio)      "
                else:
                    dev_bus = "                    "

                self.disk_dict[dev_name] = "%s,%s,%s,%s,%s,%s" % (dev_bus,
                                            dev_name, dev_size, dev_desc,
                                            dev_serial, dev_model)
        devs = self.get_dev_name()
        return (sorted(devs), self.disk_dict)
예제 #8
0
    def perform_partitioning(self):
        if self.HOSTVGDRIVE is None and not _functions.is_iscsi_install():
            logger.error("\nNo storage device selected.")
            return False

        if self.BOOTDRIVE is None and _functions.is_iscsi_install():
            logger.error("No storage device selected.")
            return False

        if not self.cross_check_host_app():
            logger.error("Skip disk partitioning, AppVG overlaps with HostVG")
            return False

        if _functions.has_fakeraid(self.HOSTVGDRIVE):
            if not handle_fakeraid(self.HOSTVGDRIVE):
                return False
        if _functions.has_fakeraid(self.ROOTDRIVE):
            if not handle_fakeraid(self.ROOTDRIVE):
                return False

        logger.info("Saving parameters")
        _functions.unmount_config("/etc/default/ovirt")
        if not self.check_partition_sizes():
            return False

        # Check for still remaining HostVGs this can be the case when
        # Node was installed on a disk not given in storage_init
        # rhbz#872114
        existing_vgs = str(_functions.passthrough("vgs"))
        for vg in existing_vgs.split("\n"):
            vg = vg.strip()
            if "HostVG" in str(vg):
                logger.error("An existing installation was found or not " +
                     "all VGs could be removed.  " +
                     "Please manually cleanup the storage using " +
                     "standard disk tools.")
                return False

        logger.info("Removing old LVM partitions")
        # HostVG must not exist at this point
        # we wipe only foreign LVM here
        logger.info("Wiping LVM on HOSTVGDRIVE %s" % self.HOSTVGDRIVE)
        if not self.wipe_lvm_on_disk(self.HOSTVGDRIVE):
            logger.error("Wiping LVM on %s Failed" % self.HOSTVGDRIVE)
            return False
        logger.info("Wiping LVM on ROOTDRIVE %s" % self.ROOTDRIVE)
        if not self.wipe_lvm_on_disk(self.ROOTDRIVE):
            logger.error("Wiping LVM on %s Failed" % self.ROOTDRIVE)
            return False
        logger.info("Wiping LVM on BOOTDRIVE %s" % self.BOOTDRIVE)
        if not self.wipe_lvm_on_disk(self.BOOTDRIVE):
            logger.error("Wiping LVM on %s Failed" % self.BOOTDRIVE)
            return False
        logger.debug("Old LVM partitions should be gone.")
        logger.debug(_functions.passthrough("vgdisplay -v"))

        self.boot_size_si = self.BOOT_SIZE * (1024 * 1024) / (1000 * 1000)
        if _functions.is_iscsi_install():
            if "OVIRT_ISCSI_NAME" in _functions.OVIRT_VARS:
                iscsi_name = _functions.OVIRT_VARS["OVIRT_ISCSI_NAME"]
                set_iscsi_initiator(iscsi_name)
            # login to target and setup disk
            get_targets = ("iscsiadm -m discovery -p %s:%s -t sendtargets" %
                           (_functions.OVIRT_VARS["OVIRT_ISCSI_TARGET_HOST"],
                           _functions.OVIRT_VARS["OVIRT_ISCSI_TARGET_PORT"]))
            _functions.system(get_targets)
            before_login_drvs = self.get_dev_name()
            logger.debug(before_login_drvs)
            login_cmd = ("iscsiadm -m node -T %s -p %s:%s -l" %
                        (_functions.OVIRT_VARS["OVIRT_ISCSI_TARGET_NAME"],
                        _functions.OVIRT_VARS["OVIRT_ISCSI_TARGET_HOST"],
                        _functions.OVIRT_VARS["OVIRT_ISCSI_TARGET_PORT"]))
            _functions.system(login_cmd)
            _functions.system("multipath -r")
            after_login_drvs = self.get_dev_name()
            logger.debug(after_login_drvs)
            logger.info("iSCSI enabled, partitioning boot drive: %s" %
                        self.BOOTDRIVE)
            _functions.wipe_partitions(self.BOOTDRIVE)
            self.reread_partitions(self.BOOTDRIVE)
            logger.info("Creating boot partition")
            parted_cmd = "parted %s -s \"mklabel %s\"" % (self.BOOTDRIVE,
                                                          self.LABEL_TYPE)
            _functions.system(parted_cmd)
            self.create_efi_partition()
            boot_end_mb = self.EFI_SIZE + self.BOOT_SIZE
            parted_cmd = ("parted \"%s\" -s \"mkpart primary ext2 %sM %sM\"" %
                         (self.BOOTDRIVE, self.EFI_SIZE, boot_end_mb))
            _functions.system(parted_cmd)
            parted_cmd = ("parted \"%s\" -s \"mkpart primary ext2 %sM %sM\"" %
                         (self.BOOTDRIVE , boot_end_mb, boot_end_mb + self.BOOT_SIZE))
            _functions.system(parted_cmd)
            parted_cmd = ("parted \"" + self.BOOTDRIVE + "\" -s \"set 1 " +
                         "boot on\"")
            _functions.system(parted_cmd)
            self.reread_partitions(self.BOOTDRIVE)
            partboot = self.BOOTDRIVE + "2"
            partbootbackup = self.BOOTDRIVE + "3"

            if not os.path.exists(partboot):
                logger.debug("%s does not exist" % partboot)
                partboot = self.BOOTDRIVE + "p2"
                partbootbackup = self.BOOTDRIVE + "p3"

            # sleep to ensure filesystems are created before continuing
            _functions.system("udevadm settle")
            _functions.system("mke2fs \"" + str(partboot) + "\" -L Boot")
            _functions.system("tune2fs -c 0 -i 0 \"" + str(partboot) + "\"")
            _functions.system("ln -snf \"" + partboot + \
                              "\" /dev/disk/by-label/Boot")
            _functions.system("mke2fs \"" + str(partbootbackup) + \
                              "\" -L BootBackup")
            _functions.system("tune2fs -c 0 -i 0 \"" + \
                              str(partbootbackup) + "\"")
            _functions.system("ln -snf \"" + partbootbackup +
                   "\" /dev/disk/by-label/BootBackup")
            self.ISCSIDRIVE = _functions.translate_multipath_device(
                               _functions.OVIRT_VARS["OVIRT_ISCSI_INIT"])
            logger.debug(self.ISCSIDRIVE)
            if self.create_iscsiroot():
                logger.info("iSCSI Root Partitions Created")
                if self.create_hostvg():
                    if len(self.APPVGDRIVE) > 0:
                        self.create_appvg()
                    logger.info("Completed!")
                    return True

        if ("OVIRT_ROOT_INSTALL" in _functions.OVIRT_VARS and
                  _functions.OVIRT_VARS["OVIRT_ROOT_INSTALL"] == "y" and not \
                      _functions.is_iscsi_install()):
            logger.info("Partitioning root drive: " + self.ROOTDRIVE)
            _functions.wipe_partitions(self.ROOTDRIVE)
            self.reread_partitions(self.ROOTDRIVE)
            logger.info("Labeling Drive: " + self.ROOTDRIVE)
            parted_cmd = ("parted \"" + self.ROOTDRIVE + "\" -s \"mklabel " +
                         self.LABEL_TYPE + "\"")
            _functions.passthrough(parted_cmd, logger.debug)
            logger.debug("Creating Root and RootBackup Partitions")
            if _functions.is_efi_boot():
                self.create_efi_partition()
            else:
                # create partition labeled bios_grub
                parted_cmd = ("parted \"" + self.ROOTDRIVE +
                             "\" -s \"mkpart primary 1M " +
                             str(self.EFI_SIZE) + "M\"")
                _functions.passthrough(parted_cmd, logger.debug)
                parted_cmd = ("parted \"" + self.ROOTDRIVE +
                             "\" -s \"set 1 bios_grub on\"")
                _functions.passthrough(parted_cmd, logger.debug)
            parted_cmd = ("parted \"" + self.ROOTDRIVE +
                         "\" -s \"mkpart primary ext2 " + str(self.EFI_SIZE) +
                         "M " + str(self.Root_end) + "M\"")
            _functions.passthrough(parted_cmd, logger.debug)
            parted_cmd = ("parted \"" + self.ROOTDRIVE +
                         "\" -s \"mkpart primary ext2 " +
                         str(self.Root_end) + "M " +
                         str(self.RootBackup_end) + "M\"")
            logger.debug(parted_cmd)
            _functions.system(parted_cmd)
            _functions.system("sync ; udevadm settle ; partprobe")
            parted_cmd = ("parted \"" + self.ROOTDRIVE +
                         "\" -s \"set 2 boot on\"")
            logger.debug(parted_cmd)
            _functions.system(parted_cmd)
            # force reload some cciss devices will fail to mkfs
            _functions.system("multipath -r &>/dev/null")
            self.reread_partitions(self.ROOTDRIVE)
            partroot = self.ROOTDRIVE + "2"
            partrootbackup = self.ROOTDRIVE + "3"
            if not os.path.exists(partroot):
                partroot = self.ROOTDRIVE + "p2"
                partrootbackup = self.ROOTDRIVE + "p3"
            _functions.system("mke2fs \"" + partroot + "\" -L Root")
            _functions.system("tune2fs -c 0 -i 0 \"" + partroot + "\"")
            _functions.system("ln -snf \"" + partrootbackup +
                   "\" /dev/disk/by-label/RootBackup")
            _functions.system("mke2fs \"" + partrootbackup + \
                              "\" -L RootBackup")
            _functions.system("tune2fs -c 0 -i 0 \"" + partrootbackup + "\"")
        hostvg1 = self.HOSTVGDRIVE.split(",")[0]
        self.reread_partitions(self.ROOTDRIVE)
        if self.ROOTDRIVE != hostvg1:
            _functions.system("parted \"" + hostvg1 + "\" -s \"mklabel " +
                   self.LABEL_TYPE + "\"")
        if self.create_hostvg():
            if len(self.APPVGDRIVE) > 0:
                self.create_appvg()
        else:
            return False
        if ("OVIRT_CRYPT_SWAP2" in _functions.OVIRT_VARS or
            "OVIRT_CRYPT_SWAP" in _functions.OVIRT_VARS):
            _functions.ovirt_store_config("/etc/ovirt-crypttab")
        return True
예제 #9
0
    def create_hostvg(self):
        logger.info("Creating LVM partition")
        self.physical_vols = []
        for drv in self.HOSTVGDRIVE.strip(",").split(","):
            drv = _functions.translate_multipath_device(drv)
            if drv != "":
                if self.ROOTDRIVE == drv and not _functions.is_iscsi_install():
                    self.reread_partitions(self.ROOTDRIVE)
                    parted_cmd = ("parted \"" + drv + "\" -s \"mkpart " +
                                  "primary ext2 " + str(self.RootBackup_end) +
                                  "M -1\"")
                    logger.debug(parted_cmd)
                    _functions.system(parted_cmd)
                    hostvgpart = "4"
                elif self.BOOTDRIVE == drv:
                    parted_cmd = ("parted \"" + drv + "\" -s \"mkpart " +
                                  "primary ext2 " + str(self.boot_size_si * 2) +
                                  " -1\"")
                    logger.debug(parted_cmd)
                    _functions.system(parted_cmd)
                    hostvgpart = "3"
                    self.ROOTDRIVE = self.BOOTDRIVE
                elif self.ISCSIDRIVE == drv:
                    parted_cmd = ("parted \"" + drv + "\" -s \"mkpart " +
                                  "primary ext2 " + str(self.ROOT_SIZE * 2) +
                                  " -1\"")
                    logger.debug(parted_cmd)
                    _functions.system(parted_cmd)
                    hostvgpart = "3"
                else:
                    _functions.system("parted \"" + drv + "\" -s \"mklabel " +
                            self.LABEL_TYPE + "\"")
                    parted_cmd = ("parted \"" + drv + "\" -s \"mkpart " +
                                  "primary ext2 1M -1 \"")
                    logger.debug(parted_cmd)
                    _functions.system(parted_cmd)
                    hostvgpart = "1"
                logger.info("Toggling LVM on")
                parted_cmd = ("parted \"" + drv + "\" -s \"set " +
                              str(hostvgpart) + " lvm on\"")
                logger.debug(parted_cmd)
                _functions.system(parted_cmd)
                _functions.system("parted \"" + self.ROOTDRIVE + \
                                  "\" -s \"print\"")
                _functions.system("udevadm settle 2> /dev/null || " + \
                                  "udevsettle &>/dev/null")
                # sync GPT to the legacy MBR partitions
                if ("OVIRT_INSTALL_ROOT" in _functions.OVIRT_VARS and
                     _functions.OVIRT_VARS["OVIRT_INSTALL_ROOT"] == "y"):
                    if self.LABEL_TYPE == "gpt":
                        logger.info("Running gptsync to create legacy mbr")
                        _functions.system("gptsync \"" + \
                                          self.ROOTDRIVE + "\"")

                self.physical_vols.append((drv, hostvgpart))
        drv_count = 0
        logger.debug(self.physical_vols)
        for drv, hostvgpart in self.physical_vols:
            partpv = None
            logger.info("Creating physical volume on (%s, %s)" % (drv,
                        hostvgpart))
            for _drv in self.HOSTVGDRIVE.strip(",").split(","):
                self.reread_partitions(_drv)
            i = 15
            while i > 0 and partpv is None:
                # e.g. /dev/cciss/c0d0p2
                for _partpv in [drv + hostvgpart, drv + "p" + hostvgpart]:
                    if os.path.exists(_partpv):
                        partpv = _partpv
                        break
                    logger.info(_partpv + " is not available!")
                i -= 1
                time.sleep(1)
            if i is 0:
                return False
            assert(partpv is not None)

            if not _functions.system("dd if=/dev/zero of=\"" + partpv +
                          "\" bs=1024k count=1"):
                logger.error("Failed to wipe lvm partition")
                return False
            if not _functions.system("pvcreate -ff -y \"" + partpv + "\""):
                logger.error("Failed to pvcreate on " + partpv)
                return False
            if drv_count < 1:
                logger.info("Creating volume group on " + partpv)
                if not _functions.system("vgcreate /dev/HostVG \"" + \
                                         partpv + "\""):
                    logger.error("Failed to vgcreate /dev/HostVG on " + partpv)
                    return False
            else:
                logger.info("Extending volume group on " + partpv)
                if not _functions.system("vgextend /dev/HostVG \"" + \
                                         partpv + "\""):
                    logger.error("Failed to vgextend /dev/HostVG on " + partpv)
                    return False
            drv_count = drv_count + 1
        if self.SWAP_SIZE > 0:
            logger.info("Creating swap partition")
            _functions.system("lvcreate --name Swap --size " + \
                              str(self.SWAP_SIZE) + "M /dev/HostVG")
            _functions.system("mkswap -L \"SWAP\" /dev/HostVG/Swap")
            _functions.system_closefds("echo \"/dev/HostVG/Swap swap swap " +
                            "defaults 0 0\" >> /etc/fstab")
            if "OVIRT_CRYPT_SWAP" in _functions.OVIRT_VARS:
                _functions.system_closefds("echo \"SWAP /dev/HostVG/Swap " +
                                "/dev/mapper/ovirt-crypt-swap " +
                                _functions.OVIRT_VARS["OVIRT_CRYPT_SWAP"] +
                                "\" >> /etc/ovirt-crypttab")
        if self.CONFIG_SIZE > 0:
            logger.info("Creating config partition")
            _functions.system("lvcreate --name Config --size " +
                    str(self.CONFIG_SIZE) + "M /dev/HostVG")
            _functions.system("mke2fs -j -t ext4 /dev/HostVG/Config " + \
                              "-L \"CONFIG\"")
            _functions.system("tune2fs -c 0 -i 0 /dev/HostVG/Config")
        if self.LOGGING_SIZE > 0:
            logger.info("Creating log partition")
            _functions.system("lvcreate --name Logging --size " +
                    str(self.LOGGING_SIZE) + "M /dev/HostVG")
            _functions.system("mke2fs -j -t ext4 /dev/HostVG/Logging " + \
                              "-L \"LOGGING\"")
            _functions.system("tune2fs -c 0 -i 0 /dev/HostVG/Logging")
            _functions.system_closefds("echo \"/dev/HostVG/Logging " + \
                            "/var/log ext4 defaults,noatime 0 0\" >> " + \
                            "/etc/fstab")
        use_data = 1
        if self.DATA_SIZE == -1:
            logger.info("Creating data partition with remaining free space")
            _functions.system("lvcreate --name Data -l 100%FREE /dev/HostVG")
            use_data = 0
        elif self.DATA_SIZE > 0:
            logger.info("Creating data partition")
            _functions.system("lvcreate --name Data --size " + \
                              str(self.DATA_SIZE) + "M /dev/HostVG")
            use_data = 0
        if use_data == 0:
            _functions.system("mke2fs -j -t ext4 /dev/HostVG/Data -L \"DATA\"")
            _functions.system("tune2fs -c 0 -i 0 /dev/HostVG/Data")
            _functions.system_closefds("echo \"/dev/HostVG/Data /data ext4 " +
                            "defaults,noatime 0 0\" >> /etc/fstab")
            _functions.system_closefds("echo \"/data/images " + \
                            "/var/lib/libvirt/images bind bind 0 0\" >> " + \
                            "/etc/fstab")
            _functions.system_closefds("echo \"/data/core " + \
                            "/var/log/core bind bind 0 0\" >> /etc/fstab")

        logger.info("Mounting config partition")
        _functions.mount_config()
        if os.path.ismount("/config"):
            _functions.ovirt_store_config("/etc/fstab")
        # remount /var/log from tmpfs to HostVG/Logging
        _functions.unmount_logging()
        _functions.mount_logging()
        if use_data == 0:
            logger.info("Mounting data partition")
            _functions.mount_data()
        logger.info("Completed HostVG Setup!")
        return True
예제 #10
0
    def __init__(self):
        logger = logging.getLogger(_functions.PRODUCT_SHORT)
        logger.propagate = False
        OVIRT_VARS = _functions.parse_defaults()
        self.overcommit = 0.5
        self.BOOT_SIZE = 512
        self.ROOT_SIZE = 512
        self.CONFIG_SIZE = 5
        self.LOGGING_SIZE = 2048
        self.EFI_SIZE = 256
        self.SWAP_SIZE = 0
        self.MIN_SWAP_SIZE = 5
        self.MIN_LOGGING_SIZE = 5
        self.SWAP2_SIZE = 0
        self.DATA2_SIZE = 0
        self.BOOTDRIVE = ""
        self.HOSTVGDRIVE = ""
        self.APPVGDRIVE = []
        self.ISCSIDRIVE = ""
        # -1 indicates data partition should use remaining disk
        self.DATA_SIZE = -1
        # gpt or msdos partition table type
        self.LABEL_TYPE = "gpt"
        if "OVIRT_INIT" in OVIRT_VARS:
            _functions.OVIRT_VARS["OVIRT_INIT"] = \
                                _functions.OVIRT_VARS["OVIRT_INIT"].strip(",")
            if "," in _functions.OVIRT_VARS["OVIRT_INIT"]:
                disk_count = 0
                init = _functions.OVIRT_VARS["OVIRT_INIT"].strip(",").split(",")
                for disk in init:
                    skip = False
                    translated_disk = _functions.translate_multipath_device(disk)
                    if disk_count < 1:
                        self.ROOTDRIVE = translated_disk
                        if len(init) == 1:
                            self.HOSTVGDRIVE = translated_disk
                        disk_count = disk_count + 1
                    else:
                        for hostvg in self.HOSTVGDRIVE.split(","):
                            if hostvg == translated_disk:
                                skip = True
                                break
                        if not skip:
                            self.HOSTVGDRIVE += ("%s," % translated_disk) \
                                if translated_disk else ""
            else:
                self.ROOTDRIVE = _functions.translate_multipath_device(
                                    _functions.OVIRT_VARS["OVIRT_INIT"])
                self.HOSTVGDRIVE = _functions.translate_multipath_device(
                                    _functions.OVIRT_VARS["OVIRT_INIT"])
            if _functions.is_iscsi_install():
                logger.info(self.BOOTDRIVE)
                logger.info(self.ROOTDRIVE)
                self.BOOTDRIVE = _functions.translate_multipath_device( \
                                                                self.ROOTDRIVE)
        if "OVIRT_OVERCOMMIT" in OVIRT_VARS:
            self.overcommit = OVIRT_VARS["OVIRT_OVERCOMMIT"]
        if "OVIRT_VOL_SWAP_SIZE" in OVIRT_VARS:
            if int(OVIRT_VARS["OVIRT_VOL_SWAP_SIZE"]) < self.MIN_SWAP_SIZE:
                logger.error("Swap size is smaller than minimum required + "
                             "size of: %s" % self.MIN_SWAP_SIZE)
                print ("\n\nSwap size is smaller than minimum required " +
                      "size of: %s" % self.MIN_SWAP_SIZE)
                #return False
                sys.exit(1)
            else:
                self.SWAP_SIZE = _functions.OVIRT_VARS["OVIRT_VOL_SWAP_SIZE"]
        else:
            self.SWAP_SIZE = _functions.calculate_swap_size( \
                                 float(self.overcommit))
        for i in ['OVIRT_VOL_BOOT_SIZE', 'OVIRT_VOL_ROOT_SIZE',
                  'OVIRT_VOL_CONFIG_SIZE', 'OVIRT_VOL_LOGGING_SIZE',
                  'OVIRT_VOL_DATA_SIZE', 'OVIRT_VOL_SWAP2_SIZE',
                  'OVIRT_VOL_DATA2_SIZE', 'OVIRT_VOL_EFI_SIZE']:
            i_short = i.replace("OVIRT_VOL_", "MIN_")
            if not i_short in self.__dict__:
                i_short = i_short.replace("MIN_", "")
            if i in OVIRT_VARS:
                if int(OVIRT_VARS[i]) < int(self.__dict__[i_short]):
                    logger.error(("%s is smaller than minimum required size " +
                                 "of: %s") % (i, self.__dict__[i_short]))
                    print (("\n%s is smaller than minimum required size of: " +
                          "%s") % (i, self.__dict__[i_short]))
                    #return False
                logger.info(("Setting value for %s to %s " %
                           (self.__dict__[i_short], _functions.OVIRT_VARS[i])))
                i_short = i_short.replace("MIN_", "")
                self.__dict__[i_short] = int(OVIRT_VARS[i])
            else:
                logger.info("Using default value for: %s" % i_short)
        self.RootBackup_end = self.ROOT_SIZE * 2 + self.EFI_SIZE
        self.Root_end = self.EFI_SIZE + self.ROOT_SIZE

        if "OVIRT_INIT_APP" in OVIRT_VARS:
            if self.SWAP2_SIZE != 0 or self.DATA2_SIZE != 0:
                for drv in _functions.OVIRT_VARS["OVIRT_INIT_APP"].split(","):
                    DRIVE = _functions.translate_multipath_device(drv)
                    self.APPVGDRIVE.append(DRIVE)
        else:
            if self.SWAP2_SIZE != 0 or self.DATA2_SIZE != 0:
                logger.error("Missing device parameter for AppVG: " +
                             "unable to partition any disk")
예제 #11
0
 def translate_device_name(self, dev):
     from ovirtnode.ovirtfunctions import translate_multipath_device
     return translate_multipath_device(dev)
예제 #12
0
파일: storage.py 프로젝트: bretep/Node
    def perform_partitioning(self):
        if self.HOSTVGDRIVE is None and not _functions.is_iscsi_install():
            logger.error("\nNo storage device selected.")
            return False

        if self.BOOTDRIVE is None and _functions.is_iscsi_install():
            logger.error("No storage device selected.")
            return False

        if _functions.has_fakeraid(self.HOSTVGDRIVE):
            if not handle_fakeraid(self.HOSTVGDRIVE):
                return False
        if _functions.has_fakeraid(self.ROOTDRIVE):
            if not handle_fakeraid(self.ROOTDRIVE):
                return False

        logger.info("Saving parameters")
        _functions.unmount_config("/etc/default/ovirt")
        if not self.check_partition_sizes():
            return False
        logger.info("Removing old LVM partitions")
        # HostVG must not exist at this point
        # we wipe only foreign LVM here
        logger.info("Wiping LVM on HOSTVGDRIVE %s" % self.HOSTVGDRIVE)
        if not self.wipe_lvm_on_disk(self.HOSTVGDRIVE):
            logger.error("Wiping LVM on %s Failed" % self.HOSTVGDRIVE)
            return False
        logger.info("Wiping LVM on ROOTDRIVE %s" % self.ROOTDRIVE)
        if not self.wipe_lvm_on_disk(self.ROOTDRIVE):
            logger.error("Wiping LVM on %s Failed" % self.ROOTDRIVE)
            return False
        logger.info("Wiping LVM on BOOTDRIVE %s" % self.BOOTDRIVE)
        if not self.wipe_lvm_on_disk(self.BOOTDRIVE):
            logger.error("Wiping LVM on %s Failed" % self.BOOTDRIVE)
            return False
        logger.debug("Old LVM partitions should be gone.")
        logger.debug(_functions.passthrough("vgdisplay -v"))

        self.boot_size_si = self.BOOT_SIZE * (1024 * 1024) / (1000 * 1000)
        if _functions.is_iscsi_install():
            # login to target and setup disk"
            get_targets = ("iscsiadm -m discovery -p %s:%s -t sendtargets" %
                           (_functions.OVIRT_VARS["OVIRT_ISCSI_TARGET_HOST"],
                           _functions.OVIRT_VARS["OVIRT_ISCSI_TARGET_PORT"]))
            _functions.system(get_targets)
            before_login_drvs = self.get_dev_name()
            logger.debug(before_login_drvs)
            login_cmd = ("iscsiadm -m node -T %s -p %s:%s -l" %
                        (_functions.OVIRT_VARS["OVIRT_ISCSI_TARGET_NAME"],
                        _functions.OVIRT_VARS["OVIRT_ISCSI_TARGET_HOST"],
                        _functions.OVIRT_VARS["OVIRT_ISCSI_TARGET_PORT"]))
            _functions.system(login_cmd)
            _functions.system("multipath -r")
            after_login_drvs = self.get_dev_name()
            logger.debug(after_login_drvs)
            logger.info("iSCSI enabled, partitioning boot drive: %s" %
                        self.BOOTDRIVE)
            _functions.wipe_partitions(self.BOOTDRIVE)
            self.reread_partitions(self.BOOTDRIVE)
            logger.info("Creating boot partition")
            parted_cmd = "parted %s -s \"mklabel %s\"" % (self.BOOTDRIVE,
                                                          self.LABEL_TYPE)
            _functions.system(parted_cmd)
            parted_cmd = ("parted \"%s\" -s \"mkpart primary ext2 1M 256M\"" %
                       self.BOOTDRIVE)
            _functions.system(parted_cmd)
            parted_cmd = ("parted \"%s\" -s \"mkpart primary ext2 256M " +
                          "512M\"") % self.BOOTDRIVE
            _functions.system(parted_cmd)
            parted_cmd = ("parted \"" + self.BOOTDRIVE + "\" -s \"set 1 " +
                         "boot on\"")
            _functions.system(parted_cmd)
            self.reread_partitions(self.BOOTDRIVE)
            partboot = self.BOOTDRIVE + "1"
            if not os.path.exists(partboot):
                logger.debug("%s does not exist" % partboot)
                partboot = self.BOOTDRIVE + "p1"
            partbootbackup = self.BOOTDRIVE + "2"
            if not os.path.exists(partbootbackup):
                logger.debug("%s does not exist" % partbootbackup)
                partbootbackup = self.BOOTDRIVE + "p2"
            # sleep to ensure filesystems are created before continuing
            _functions.system("udevadm settle")
            time.sleep(10)
            _functions.system("mke2fs \"" + str(partboot) + "\" -L Boot")
            _functions.system("tune2fs -c 0 -i 0 \"" + str(partboot) + "\"")
            _functions.system("ln -snf \"" + partboot + \
                              "\" /dev/disk/by-label/Boot")
            _functions.system("mke2fs \"" + str(partbootbackup) + \
                              "\" -L BootBackup")
            _functions.system("tune2fs -c 0 -i 0 \"" + \
                              str(partbootbackup) + "\"")
            _functions.system("ln -snf \"" + partbootbackup +
                   "\" /dev/disk/by-label/BootBackup")
            self.ISCSIDRIVE = _functions.translate_multipath_device(
                               _functions.OVIRT_VARS["OVIRT_ISCSI_INIT"])
            logger.debug(self.ISCSIDRIVE)
            if self.create_iscsiroot():
                logger.info("iSCSI Root Partitions Created")
                if self.create_hostvg():
                    logger.info("Completed!")
                    return True

        if ("OVIRT_ROOT_INSTALL" in _functions.OVIRT_VARS and
                  _functions.OVIRT_VARS["OVIRT_ROOT_INSTALL"] == "y"):
            logger.info("Partitioning root drive: " + self.ROOTDRIVE)
            _functions.wipe_partitions(self.ROOTDRIVE)
            self.reread_partitions(self.ROOTDRIVE)
            logger.info("Labeling Drive: " + self.ROOTDRIVE)
            parted_cmd = ("parted \"" + self.ROOTDRIVE + "\" -s \"mklabel " +
                         self.LABEL_TYPE + "\"")
            _functions.passthrough(parted_cmd, logger.debug)
            logger.debug("Creating Root and RootBackup Partitions")
            # efi partition should at 0M
            if _functions.is_efi_boot():
                parted_cmd = ("parted \"" + self.ROOTDRIVE +
                             "\" -s \"mkpart EFI 1M " +
                             str(self.EFI_SIZE) + "M\"")
                _functions.passthrough(parted_cmd, logger.debug)
            else:
                # create partition labeled bios_grub
                parted_cmd = ("parted \"" + self.ROOTDRIVE +
                             "\" -s \"mkpart primary 1M " +
                             str(self.EFI_SIZE) + "M\"")
                _functions.passthrough(parted_cmd, logger.debug)
                parted_cmd = ("parted \"" + self.ROOTDRIVE +
                             "\" -s \"set 1 bios_grub on\"")
                _functions.passthrough(parted_cmd, logger.debug)
            parted_cmd = ("parted \"" + self.ROOTDRIVE +
                         "\" -s \"mkpart primary ext2 " + str(self.EFI_SIZE) +
                         "M " + str(self.Root_end) + "M\"")
            _functions.passthrough(parted_cmd, logger.debug)
            parted_cmd = ("parted \"" + self.ROOTDRIVE +
                         "\" -s \"mkpart primary ext2 " +
                         str(self.Root_end) + "M " +
                         str(self.RootBackup_end) + "M\"")
            logger.debug(parted_cmd)
            _functions.system(parted_cmd)
            parted_cmd = ("parted \"" + self.ROOTDRIVE +
                         "\" -s \"set 2 boot on\"")
            logger.debug(parted_cmd)
            _functions.system(parted_cmd)
            # sleep to ensure filesystems are created before continuing
            time.sleep(5)
            # force reload some cciss devices will fail to mkfs
            _functions.system("multipath -r &>/dev/null")
            self.reread_partitions(self.ROOTDRIVE)
            partefi = self.ROOTDRIVE + "1"
            partroot = self.ROOTDRIVE + "2"
            partrootbackup = self.ROOTDRIVE + "3"
            if not os.path.exists(partroot):
                partefi = self.ROOTDRIVE + "p1"
                partroot = self.ROOTDRIVE + "p2"
                partrootbackup = self.ROOTDRIVE + "p3"
            if _functions.is_efi_boot():
                _functions.system("ln -snf \"" + partefi + \
                                  "\" /dev/disk/by-label/EFI")
                _functions.system("mkfs.vfat \"" + partefi + "\"")
            _functions.system("ln -snf \"" + partroot + \
                              "\" /dev/disk/by-label/Root")
            _functions.system("mke2fs \"" + partroot + "\" -L Root")
            _functions.system("tune2fs -c 0 -i 0 \"" + partroot + "\"")
            _functions.system("ln -snf \"" + partrootbackup +
                   "\" /dev/disk/by-label/RootBackup")
            _functions.system("mke2fs \"" + partrootbackup + \
                              "\" -L RootBackup")
            _functions.system("tune2fs -c 0 -i 0 \"" + partrootbackup + "\"")
        hostvg1 = self.HOSTVGDRIVE.split(",")[0]
        self.reread_partitions(self.ROOTDRIVE)
        if self.ROOTDRIVE != hostvg1:
            _functions.system("parted \"" + hostvg1 + "\" -s \"mklabel " +
                   self.LABEL_TYPE + "\"")
        if self.create_hostvg():
            if len(self.APPVGDRIVE) > 0:
                self.create_appvg()
        else:
            return False
        if ("OVIRT_CRYPT_SWAP2" in _functions.OVIRT_VARS or
            "OVIRT_CRYPT_SWAP" in _functions.OVIRT_VARS):
            _functions.ovirt_store_config("/etc/ovirt-crypttab")
        return True
예제 #13
0
파일: storage.py 프로젝트: bretep/Node
    def __init__(self):
        logger = logging.getLogger(_functions.PRODUCT_SHORT)
        logger.propagate = False
        OVIRT_VARS = _functions.parse_defaults()
        self.overcommit = 0.5
        self.BOOT_SIZE = 50
        self.ROOT_SIZE = 256
        self.CONFIG_SIZE = 5
        self.LOGGING_SIZE = 2048
        self.EFI_SIZE = 256
        self.SWAP_SIZE = 0
        self.MIN_SWAP_SIZE = 5
        self.SWAP2_SIZE = 0
        self.DATA2_SIZE = 0
        self.BOOTDRIVE = ""
        self.HOSTVGDRIVE = ""
        self.APPVGDRIVE = []
        self.ISCSIDRIVE = ""
        # -1 indicates data partition should use remaining disk
        self.DATA_SIZE = -1
        # gpt or msdos partition table type
        self.LABEL_TYPE = "gpt"
        if "OVIRT_INIT" in OVIRT_VARS:
            _functions.OVIRT_VARS["OVIRT_INIT"] = \
                                _functions.OVIRT_VARS["OVIRT_INIT"].strip(",")
            if "," in _functions.OVIRT_VARS["OVIRT_INIT"]:
                disk_count = 0
                for disk in _functions.OVIRT_VARS["OVIRT_INIT"].split(","):
                    skip = False
                    if disk_count < 1:
                        self.ROOTDRIVE = disk
                        disk_count = disk_count + 1
                        self.HOSTVGDRIVE = disk
                    else:
                        for hostvg in self.HOSTVGDRIVE.split(","):
                            if hostvg == disk:
                                skip = True
                                break
                        if not skip:
                            self.HOSTVGDRIVE = self.HOSTVGDRIVE + "," + disk
            else:
                self.ROOTDRIVE = _functions.translate_multipath_device(
                                    _functions.OVIRT_VARS["OVIRT_INIT"])
                self.HOSTVGDRIVE = _functions.translate_multipath_device(
                                    _functions.OVIRT_VARS["OVIRT_INIT"])
            if _functions.is_iscsi_install():
                logger.info(self.BOOTDRIVE)
                logger.info(self.ROOTDRIVE)
                self.BOOTDRIVE = _functions.translate_multipath_device( \
                                                                self.ROOTDRIVE)
        mem_size_cmd = "awk '/MemTotal:/ { print $2 }' /proc/meminfo"
        mem_size_mb = _functions.subprocess_closefds(mem_size_cmd, shell=True,
                                          stdout=subprocess.PIPE,
                                          stderr=subprocess.STDOUT)
        MEM_SIZE_MB = mem_size_mb.stdout.read()
        MEM_SIZE_MB = int(MEM_SIZE_MB) / 1024
        # we multiply the overcommit coefficient by 10 then divide the
        # product by 10 to avoid decimals in the result
        OVERCOMMIT_SWAP_SIZE = int(MEM_SIZE_MB) * self.overcommit * 10 / 10
        # add to the swap the amounts from
        # http://kbase.redhat.com/faq/docs/DOC-15252
        MEM_SIZE_GB = int(MEM_SIZE_MB) / 1024
        if MEM_SIZE_GB < 4:
            BASE_SWAP_SIZE = 2048
        elif MEM_SIZE_GB < 16:
            BASE_SWAP_SIZE = 4096
        elif MEM_SIZE_GB < 64:
            BASE_SWAP_SIZE = 8192
        else:
            BASE_SWAP_SIZE = 16384
        if "OVIRT_VOL_SWAP_SIZE" in OVIRT_VARS:
            if int(OVIRT_VARS["OVIRT_VOL_SWAP_SIZE"]) < self.MIN_SWAP_SIZE:
                logger.error("Swap size is smaller than minimum required + "
                             "size of: %s" % self.MIN_SWAP_SIZE)
                print ("\n\nSwap size is smaller than minimum required " +
                      "size of: %s" % self.MIN_SWAP_SIZE)
                return False
                sys.exit(1)
            else:
                self.SWAP_SIZE = _functions.OVIRT_VARS["OVIRT_VOL_SWAP_SIZE"]
        else:
            self.SWAP_SIZE = int(BASE_SWAP_SIZE) + int(OVERCOMMIT_SWAP_SIZE)
        for i in ['OVIRT_VOL_BOOT_SIZE', 'OVIRT_VOL_ROOT_SIZE',
                  'OVIRT_VOL_CONFIG_SIZE', 'OVIRT_VOL_LOGGING_SIZE',
                  'OVIRT_VOL_DATA_SIZE', 'OVIRT_VOL_SWAP2_SIZE',
                  'OVIRT_VOL_DATA2_SIZE']:
            i_short = i.replace("OVIRT_VOL_", "")
            if i in OVIRT_VARS:
                if int(OVIRT_VARS[i]) < int(self.__dict__[i_short]):
                    logger.error("%s is smaller than minimum required size " +
                                 "of: %s" % (i, self.__dict__[i_short]))
                    print ("\n%s is smaller than minimum required size of: " +
                          "%s" % (i, self.__dict__[i_short]))
                    return False
                logging.info(("Setting value for %s to %s " %
                           (self.__dict__[i_short], _functions.OVIRT_VARS[i])))
                self.__dict__[i_short] = int(OVIRT_VARS[i])
            else:
                logging.info("Using default value for: %s" % i_short)
        self.RootBackup_end = self.ROOT_SIZE * 2 + self.EFI_SIZE
        self.Root_end = self.EFI_SIZE + self.ROOT_SIZE

        if "OVIRT_INIT_APP" in OVIRT_VARS:
            if self.SWAP2_SIZE != 0 or self.DATA2_SIZE != 0:
                for drv in _functions.OVIRT_VARS["OVIRT_INIT_APP"].split(","):
                    DRIVE = _functions.translate_multipath_device(drv)
                    self.APPVGDRIVE.append(DRIVE)
            if not self.cross_check_host_app:
                logger.error("Skip disk partitioning, " +
                             "AppVG overlaps with HostVG")
                return False
        else:
            if self.SWAP2_SIZE != 0 or self.DATA2_SIZE != 0:
                logger.error("Missing device parameter for AppVG: " +
                             "unable to partition any disk")
                return False