Beispiel #1
0
 def configure_dns(self):
     OVIRT_VARS = _functions.parse_defaults()
     if "OVIRT_DNS" in OVIRT_VARS:
         DNS = OVIRT_VARS["OVIRT_DNS"]
         try:
             if DNS is not None:
                 tui_cmt = ("Please make changes through the TUI. " + \
                            "Manual edits to this file will be " + \
                            "lost on reboot")
                 _functions.augtool("set", \
                                    "/files/etc/resolv.conf/#comment[1]", \
                                    tui_cmt)
                 DNS = DNS.split(",")
                 i = 1
                 for server in DNS:
                     logger.debug("Setting DNS server %d: %s" % (i, server))
                     setting = "/files/etc/resolv.conf/nameserver[%s]" % i
                     _functions.augtool("set", setting, server)
                     i = i + i
                 _functions.ovirt_store_config("/etc/resolv.conf")
             else:
                 logger.debug("No DNS servers given.")
         except:
             logger.warn("Failed to set DNS servers")
         finally:
             if len(DNS) < 2:
                 _functions.augtool("rm", \
                                 "/files/etc/resolv.conf/nameserver[2]", "")
             for nic in glob("/etc/sysconfig/network-scripts/ifcfg-*"):
                 if not "ifcfg-lo" in nic:
                     path = "/files%s/PEERDNS" % nic
                     _functions.augtool("set", path, "no")
Beispiel #2
0
    def configure_dns(self):
        logger.warn("Configuring DNS")
        OVIRT_VARS = _functions.parse_defaults()
        have_peerdns = True
        DNS = ""
        if "OVIRT_DNS" in OVIRT_VARS:
            DNS = OVIRT_VARS["OVIRT_DNS"]
            logger.debug("Found DNS key with value '%s'" % DNS)
            try:
                # Write resolv.conf any way, sometimes without servers
                tui_cmt = ("Please make changes through the TUI. " + \
                           "Manual edits to this file will be " + \
                           "lost on reboot")
                _functions.augtool("set", \
                                   "/files/etc/resolv.conf/#comment[1]", \
                                   tui_cmt)
                DNS = [s for s in DNS.split(",") if s]
                i = 1
                for server in DNS:
                    logger.debug("Setting DNS server %d: %s" % (i, server))
                    setting = "/files/etc/resolv.conf/nameserver[%s]" % i
                    _functions.augtool("set", setting, server)
                    # PEERDNS=no is required with manual DNS servers
                    have_peerdns = False
                    i = i + i
                _functions.ovirt_store_config("/etc/resolv.conf")
            except:
                logger.warn("Failed to set DNS servers")

        # Remove all spare DNS servers
        logger.debug("Removing DNS servers")
        if len(DNS) < 2:
            _functions.augtool("rm", "/files/etc/resolv.conf/nameserver[2]",
                               "")
        if len(DNS) < 1:
            _functions.augtool("rm", "/files/etc/resolv.conf/nameserver[1]",
                               "")

        # Set or remove PEERDNS for all ifcfg-*
        for nic in glob("/etc/sysconfig/network-scripts/ifcfg-*"):
            if "ifcfg-lo" in nic:
                continue
            path = "/files%s/PEERDNS" % nic
            if have_peerdns:
                _functions.augtool("rm", path, "")
            else:
                _functions.augtool("set", path, "no")
Beispiel #3
0
    def configure_dns(self):
        logger.warn("Configuring DNS")
        OVIRT_VARS = _functions.parse_defaults()
        have_peerdns = True
        DNS = ""
        if "OVIRT_DNS" in OVIRT_VARS:
            DNS = OVIRT_VARS["OVIRT_DNS"]
            logger.debug("Found DNS key with value '%s'" % DNS)
            try:
                # Write resolv.conf any way, sometimes without servers
                tui_cmt = ("Please make changes through the TUI. " + \
                           "Manual edits to this file will be " + \
                           "lost on reboot")
                _functions.augtool("set", \
                                   "/files/etc/resolv.conf/#comment[1]", \
                                   tui_cmt)
                DNS = [s for s in DNS.split(",") if s]
                i = 1
                for server in DNS:
                    logger.debug("Setting DNS server %d: %s" % (i, server))
                    setting = "/files/etc/resolv.conf/nameserver[%s]" % i
                    _functions.augtool("set", setting, server)
                    # PEERDNS=no is required with manual DNS servers
                    have_peerdns = False
                    i = i + i
                _functions.ovirt_store_config("/etc/resolv.conf")
            except:
                logger.warn("Failed to set DNS servers")

        # Remove all spare DNS servers
        logger.debug("Removing DNS servers")
        if len(DNS) < 2:
            _functions.augtool("rm", "/files/etc/resolv.conf/nameserver[2]", "")
        if len(DNS) < 1:
            _functions.augtool("rm", "/files/etc/resolv.conf/nameserver[1]", "")

        # Set or remove PEERDNS for all ifcfg-*
        for nic in glob("/etc/sysconfig/network-scripts/ifcfg-*"):
            if "ifcfg-lo" in nic:
                continue
            path = "/files%s/PEERDNS" % nic
            if have_peerdns:
                _functions.augtool("rm", path, "")
            else:
                _functions.augtool("set", path, "no")
Beispiel #4
0
 def __init__(self):
     OVIRT_VARS = _functions.parse_defaults()
     self.WORKDIR = tempfile.mkdtemp()
     self.IFSCRIPTS_PATH = "/etc/sysconfig/network-scripts/ifcfg-"
     self.IFCONFIG_FILE_ROOT = "/files%s" % self.IFSCRIPTS_PATH
     self.NTP_CONFIG_FILE = "/etc/ntp.conf"
     self.NTPSERVERS = ""
     self.CONFIGURED_NIC = ""
     self.CONFIGURED_NICS = []
     self.IF_CONFIG = ""
     self.BR_CONFIG = ""
     self.VL_CONFIG = ""
     self.VLAN_ID = ""
     self.VL_ROOT = ""
     self.VL_FILENAME = ""
     self.nic = ""
     self.bridge = ""
     self.vlan_id = ""
Beispiel #5
0
 def __init__(self):
     OVIRT_VARS = _functions.parse_defaults()
     self.WORKDIR = tempfile.mkdtemp()
     self.IFSCRIPTS_PATH = "/etc/sysconfig/network-scripts/ifcfg-"
     self.IFCONFIG_FILE_ROOT = "/files%s" % self.IFSCRIPTS_PATH
     self.NTP_CONFIG_FILE = "/etc/ntp.conf"
     self.NTPSERVERS = ""
     self.CONFIGURED_NIC = ""
     self.CONFIGURED_NICS = []
     self.IF_CONFIG = ""
     self.BR_CONFIG = ""
     self.VL_CONFIG = ""
     self.VLAN_ID = ""
     self.VL_ROOT = ""
     self.VL_FILENAME = ""
     self.nic = ""
     self.bridge = ""
     self.vlan_id = ""
Beispiel #6
0
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
# MA  02110-1301, USA.  A copy of the GNU General Public License is
# also available at http://www.gnu.org/copyleft/gpl.html.

import ovirtnode.ovirtfunctions as _functions
import ovirt.node.utils.system as _system
import ovirtnode.iscsi as _iscsi
import shutil
import traceback
import os
import stat
import subprocess
import re
import time
import logging
OVIRT_VARS = _functions.parse_defaults()
from ovirtnode.storage import Storage

logger = logging.getLogger(_functions.PRODUCT_SHORT)


class Install:
    def __init__(self):
        logger.propagate = False
        self.disk = None
        self.partN = -1
        self.s = Storage()
        self.efi_hd = ""

    def kernel_image_copy(self):
        if (not _functions.system("cp -p /live/" + self.syslinux + \
    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")
Beispiel #8
0
# MA  02110-1301, USA.  A copy of the GNU General Public License is
# also available at http://www.gnu.org/copyleft/gpl.html.

import ovirtnode.ovirtfunctions as _functions
import ovirt.node.utils.system as _system
import ovirtnode.iscsi as _iscsi
import shutil
import traceback
import os
import stat
import subprocess
import re
import time
import logging
import tempfile
OVIRT_VARS = _functions.parse_defaults()

from itertools import combinations
from ovirtnode.storage import Storage
from rpmUtils.miscutils import compareVerOnly

logger = logging.getLogger(__name__)


class Install:
    def __init__(self):
        logger.addHandler(logging.NullHandler())
        logger.propagate = False
        self.disk = None
        self.partN = -1
        self.s = Storage()
Beispiel #9
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 = 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