[node-patches] Change in ovirt-node[master]: [WIP] Add a blivet based installer module

fabiand at fedoraproject.org fabiand at fedoraproject.org
Wed Mar 5 16:15:40 UTC 2014


Fabian Deutsch has uploaded a new change for review.

Change subject: [WIP] Add a blivet based installer module
......................................................................

[WIP] Add a blivet based installer module

TBD

Change-Id: I0c6ec5fadcb782650ddf2a191883f40a2016e7f1
Signed-off-by: Fabian Deutsch <fabiand at fedoraproject.org>
---
M src/ovirt/node/installer/core/__init__.py
1 file changed, 161 insertions(+), 2 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/ovirt-node refs/changes/40/25440/1

diff --git a/src/ovirt/node/installer/core/__init__.py b/src/ovirt/node/installer/core/__init__.py
index bdc683c..4055702 100644
--- a/src/ovirt/node/installer/core/__init__.py
+++ b/src/ovirt/node/installer/core/__init__.py
@@ -1,7 +1,7 @@
 #!/usr/bin/python
 # -*- coding: utf-8 -*-
 #
-# core.py - Copyright (C) 2013 Red Hat, Inc.
+# __init__.py - Copyright (C) 2013-2014 Red Hat, Inc.
 # Written by Fabian Deutsch <fabiand at redhat.com>
 #
 # This program is free software; you can redistribute it and/or modify
@@ -22,7 +22,9 @@
 """
 Core Installer Plugins
 """
-from ovirt.node import loader
+from ovirt.node import loader, base
+from ovirt.node.utils import Transaction
+import blivet
 
 
 #
@@ -35,3 +37,160 @@
     # Lazy load all plugins in this package
     for plugin in loader.get_modules_in_package(__package__):
         plugin.Plugin(application)
+
+
+class StorageLayout(base.Base):
+    """Specifies how the devices on the host shall be used
+    """
+    REMAINING_SPACE = -1
+
+    label_type = "gpt"
+    overcommit_ratio = 0.5
+
+    boot = None
+    hostvg = None
+    appvg = None
+
+    def __init__(boot_device, hostvg_devices, appvg_devices, verify=True):
+        self.bootloader = Bootloader(boot_device)
+        self.hostvg = HostVG(hostvg_devices)
+        self.appvg = AppVG(appvg_devices)
+        if verify:
+            self.verify()
+
+    class Bootloader(base.Base):
+        device = None
+        boot_size = 512
+        efi_size = 256
+
+    class HostVG(base.Base):
+        devices = None
+        root_size = 512
+        config_size = 5
+        logging_size = 2048
+        swap_size = 0
+        data_size = None
+
+    class AppVG(base.Base):
+        devices = None
+        swap_size = None
+        data_size = None
+
+    def verify(self):
+        self._xcheck_vgs(self.hostvg.devices, self.appvg.devices)
+
+    def _xcheck_vgs(hostpvs, apppvs):
+        """Semi-internal method to allow a better testing
+
+        APPVG and HOSTVG do not overlap:
+        >>> StorageLayout._xcheck_vgs(["/dev/sda"], ["/dev/sdb"])
+        True
+
+        APPVG and HOSTVG do overlap (sda):
+        >>> StorageLayout._xcheck_vgs(["sda"], ["sda", "sdb"])
+        False
+
+        APPVG and HOSTVG do not overlap:
+        >>> StorageLayout._xcheck_vgs([], [])
+        True
+        """
+        assert type(hostpvs) is list
+        assert type(apppvs) is list
+        drives_in_both = set.intersection(set(hostpvs),
+                                          set(apppvs))
+        if drives_in_both:
+            raise RuntimeError("The following drives are members of " +
+                               "APPVG and HOSTVG: %s" % drives_in_both)
+
+
+class Installer(base.Base):
+    """Installer, performs the installation according to a StorageLayout
+    """
+    blivet = None
+
+    def __init__(self):
+        self.blivet = blivet.Blivet()
+
+    @staticmethod
+    def for_layout(storagelayout):
+        pass
+
+    def install(self):
+        tx = self.transaction()
+
+    def transaction(self):
+        tx = Transaction("Installation")
+        tx += self.create_layout_tx()
+        tx += self.copy_image_tx()
+        tx += self.setup_bootloader_tx()
+
+        return tx
+
+    def create_layout_tx(self):
+        # Find all devices
+        self.blivet.devicetree.populate()
+
+        #
+        # Bootloader
+        #
+        bootdisk = b.devicetree.getDeviceByName(self.bootloader.device)
+        b.initializeDisk(bootdisk)
+        bootdev = b.newPartition(grow=True, parents=[bootdisk])
+        b.createDevice(bootdev)
+
+        blivet.partitioning.doPartitioning(b)
+
+        b.doIt()
+
+        #
+        # HostVG
+        #
+        disk1 = b.devicetree.getDeviceByName("disk1")
+        b.initializeDisk(disk1)
+
+        pv = b.newPartition(size=Size(spec="50GiB"), fmt_type="lvmpv")
+        b.createDevice(pv)
+
+        # allocate the partitions (decide where they'll reside)
+        blivet.partitioning.doPartitioning(b)
+
+        vg = b.newVG(parents=[pv])
+        b.createDevice(vg)
+
+        dev = b.newLV(size=Size(spec="5MiB"), parents=[vg], name="Config")
+        b.createDevice(dev)
+
+        dev = b.newLV(size=Size(spec="5MiB"), parents=[vg], name="Data")
+        b.createDevice(dev)
+
+        dev = b.newLV(size=Size(spec="5MiB"), parents=[vg], name="Logging")
+        b.createDevice(dev)
+
+        dev = b.newLV(fmt_type="swap", size=Size(spec="2GiB"), parents=[vg])
+        b.createDevice(dev)
+
+
+class InstallerFactory(base.Base):
+    """Factory which creates an installer from e.g. the kernel cmdline args
+    """
+    def from_kernel_cmdline(self):
+        args = "..."
+        return self.from_cmdline(args)
+
+    def from_cmdline(self, cmdline):
+        # Parse args
+        args = self._parse(cmdline)
+        bootdev = args["nd.foo.boot"]
+        hostpvs = args["nd.foo.hostvg"]
+        apppvs = args["nd.foo.appvg"]
+
+        # Create layout
+        layout = StorageLayout(bootdev, hostpvs, apppvs)
+
+        # Wrap an installer around it
+        installer = Installer.for_layout(layout)
+
+        return installer
+
+    def _parse(self, cmdline):
+        return {}


-- 
To view, visit http://gerrit.ovirt.org/25440
To unsubscribe, visit http://gerrit.ovirt.org/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I0c6ec5fadcb782650ddf2a191883f40a2016e7f1
Gerrit-PatchSet: 1
Gerrit-Project: ovirt-node
Gerrit-Branch: master
Gerrit-Owner: Fabian Deutsch <fabiand at fedoraproject.org>



More information about the node-patches mailing list