Ejemplo n.º 1
0
def ovirt_rsyslog(server, port, protocol):
    if server == "":
        disable = "#"
    else:
        disable = ""
    if protocol == "tcp":
        DELIM = "@@"
    else:
        DELIM = "@"

    if _functions.is_valid_ipv6(server):
        server = "[" + server + "]"

    rsyslog_dict = {
        "disable": disable,
        "delim": DELIM,
        "server": server,
        "port": port
    }
    rsyslog_config_out = RSYSLOG_CONFIG_TEMPLATE % rsyslog_dict
    rsyslog_config = open(RSYSLOG_FILE, "w")
    rsyslog_config.write(rsyslog_config_out)
    rsyslog_config.close()
    _functions.system_closefds("/sbin/service rsyslog restart &> /dev/null")
    if _functions.ovirt_store_config("/etc/rsyslog.conf"):
        logger.info("Syslog Configuration Updated")
    return True
Ejemplo n.º 2
0
def ovirt_rsyslog(server, port, protocol):
    if server == "":
        disable = "#"
    else:
        disable = ""
    if protocol == "tcp":
        DELIM = "@@"
    else:
        DELIM = "@"

    if _functions.is_valid_ipv6(server):
        server = "[" + server + "]"

    rsyslog_dict = {
        "disable": disable,
        "delim": DELIM,
        "server": server,
        "port": port
    }
    rsyslog_config_out = RSYSLOG_CONFIG_TEMPLATE % rsyslog_dict
    rsyslog_config = open(RSYSLOG_FILE, "w")
    rsyslog_config.write(rsyslog_config_out)
    rsyslog_config.close()
    _functions.system_closefds("/sbin/service rsyslog restart &> /dev/null")
    if _functions.ovirt_store_config("/etc/rsyslog.conf"):
        logger.info("Syslog Configuration Updated")
    return True
Ejemplo n.º 3
0
def ovirt_netconsole(server, port):
    _functions.augtool("set", \
                       "/files/etc/sysconfig/netconsole/SYSLOGADDR", server)
    _functions.augtool("set", \
                       "/files/etc/sysconfig/netconsole/SYSLOGPORT", port)
    _functions.system_closefds("/sbin/service netconsole restart &> /dev/null")
    if _functions.ovirt_store_config("/etc/sysconfig/netconsole"):
        logger.info("Netconsole Configuration Updated")
    return True
Ejemplo n.º 4
0
def ovirt_netconsole(server, port):
    _functions.augtool("set", \
                       "/files/etc/sysconfig/netconsole/SYSLOGADDR", server)
    _functions.augtool("set", \
                       "/files/etc/sysconfig/netconsole/SYSLOGPORT", port)
    _functions.system_closefds("/sbin/service netconsole restart &> /dev/null")
    if _functions.ovirt_store_config("/etc/sysconfig/netconsole"):
        logger.info("Netconsole Configuration Updated")
    return True
Ejemplo n.º 5
0
def set_iscsi_initiator(initiator_name):
    iscsi_config = open(INITIATOR_FILE, "w")
    iscsi_config.write("InitiatorName=" + initiator_name + "\n")
    iscsi_config.close()
    if _functions.ovirt_store_config(INITIATOR_FILE):
        _functions.logger.info("Initiator name set as: " + initiator_name)
    else:
        _functions.logger.warning("Setting initiator name failed")
    _functions.system_closefds("service iscsid restart &> /dev/null")
 def commit(self):
     if not verifyStringFormat(self.path, "^\/[\w\_\-\s]+(\/[\w\_\-\s]+)*\/?$"):
         return 
     if not os.path.exists(self.path):
         _functions.system_closefds("mkdir -p %s" % self.path)
         _functions.system_closefds("chown 36:36 %s" % self.path)
     else :
         _functions.system_closefds("rm -rf %s &> /dev/null" % self.path)
         _functions.system_closefds("mkdir -p %s &> /dev/null" % self.path)
         _functions.system_closefds("chown 36:36 %s &> /dev/null" % self.path)
 def commit(self):
     if not verifyStringFormat(self.path,
                               "^\/[\w\_\-\s]+(\/[\w\_\-\s]+)*\/?$"):
         return
     if not os.path.exists(self.path):
         _functions.system_closefds("mkdir -p %s" % self.path)
         _functions.system_closefds("chown 36:36 %s" % self.path)
     else:
         _functions.system_closefds("rm -rf %s &> /dev/null" % self.path)
         _functions.system_closefds("mkdir -p %s &> /dev/null" % self.path)
         _functions.system_closefds("chown 36:36 %s &> /dev/null" %
                                    self.path)
Ejemplo n.º 8
0
 def set_ssh_conf(self, path, _):
     try:
         from ocsetup import ocs
         ssh_btn = ocs.page_security.enable_ssh_CheckButton
         check_button_state = ssh_btn.get_active()
         current_state = augtool_get(path)
         if check_button_state is False:
             datautil.augtool_set(path, "no")
         else:
             datautil.augtool_set(path, "yes")
         if ((current_state == "no" and check_button_state is True) or
                 (current_state != "no" and check_button_state is False)):
                 # SSHD CONFIGURE CHANGED, RESTART.
                 system_closefds("service sshd restart &>/dev/null")
     except Exception, e:
         print e
Ejemplo n.º 9
0
 def set_ssh_conf(self, path, _):
     try:
         from ocsetup import ocs
         ssh_btn = ocs.page_security.enable_ssh_CheckButton
         check_button_state = ssh_btn.get_active()
         current_state = augtool_get(path)
         if check_button_state is False:
             datautil.augtool_set(path, "no")
         else:
             datautil.augtool_set(path, "yes")
         if ((current_state == "no" and check_button_state is True) or
             (current_state != "no" and check_button_state is False)):
             # SSHD CONFIGURE CHANGED, RESTART.
             system_closefds("service sshd restart &>/dev/null")
     except Exception, e:
         print e
Ejemplo n.º 10
0
def set_nfsv4_domain(domain):
    idmap_conf = "/etc/idmapd.conf"
    current_domain = get_current_nfsv4_domain()
    _functions.unmount_config(idmap_conf)
    if current_domain.startswith("#"):
        current_domain = "#Domain = %s" % current_domain.replace("# ", "")
        _functions.system("sed -i 's/%s/Domain = %s/g' %s" \
            % (current_domain, domain, idmap_conf))
    else:
        _functions.system("sed -i 's/%s/%s/g' %s" \
            % (current_domain, domain, idmap_conf))
    if _functions.ovirt_store_config(idmap_conf):
        logger.info("NFSv4 domain set as: " + domain)
    else:
        logger.warning("Setting nfsv4 domain failed")
    _functions.system_closefds("service rpcidmapd restart")
    _functions.system_closefds("nfsidmap -c &>/dev/null")
Ejemplo n.º 11
0
def toggle_ssh_access():
    ssh_config = augeas.Augeas("root=/")
    ssh_config.set("/files/etc/ssh/sshd_config",
                   _functions.OVIRT_VARS["ssh_pass_enabled"])
    ssh_config.save()
    _functions.ovirt_store_config("/etc/ssh/sshd_config")
    rc = _functions.system_closefds("service sshd reload")
    return rc
Ejemplo n.º 12
0
def set_nfsv4_domain(domain):
    idmap_conf = "/etc/idmapd.conf"
    current_domain = get_current_nfsv4_domain()
    _functions.unmount_config(idmap_conf)
    if current_domain.startswith("#"):
        current_domain = "#Domain = %s" % current_domain.replace("# ","")
        _functions.system("sed -i 's/%s/Domain = %s/g' %s" \
            % (current_domain, domain, idmap_conf))
    else:
        _functions.system("sed -i '/^Domain/ s/%s/%s/g' %s" \
            % (current_domain, domain, idmap_conf))
    if _functions.ovirt_store_config(idmap_conf):
        logger.info("NFSv4 domain set as: " + domain)
    else:
        logger.warning("Setting nfsv4 domain failed")
    _functions.system_closefds("service rpcidmapd restart")
    _functions.system_closefds("nfsidmap -c &>/dev/null")
Ejemplo n.º 13
0
def toggle_ssh_access():
    ssh_config = augeas.Augeas("root=/")
    ssh_config.set("/files/etc/ssh/sshd_config",
                   _functions.OVIRT_VARS["ssh_pass_enabled"])
    ssh_config.save()
    _functions.ovirt_store_config("/etc/ssh/sshd_config")
    rc = _functions.system_closefds("service sshd reload")
    return rc
Ejemplo n.º 14
0
    def save_ntp_configuration(self):
        _functions.ovirt_store_config(self.NTP_CONFIG_FILE)

        ntproot = "/files/etc/ntp.conf"
        ntpconf = "rm %s\n" % ntproot
        ntpconf += "set %s/driftfile /var/lib/ntp/drift\n" % ntproot
        ntpconf += "set %s/includefile /etc/ntp/crypto/pw\n" % ntproot
        ntpconf += "set %s/keys /etc/ntp/keys" % ntproot
        ntpconf = ntpconf.split("\n")
        for line in ntpconf:
            try:
                oper, key, value = line.split()
                _functions.augtool(oper, key, value)
            except:
                oper, key = line.split()
                _functions.augtool(oper, key, "")

        if "OVIRT_NTP" in OVIRT_VARS:
            SERVERS = [s for s in OVIRT_VARS["OVIRT_NTP"].split(",") if s]
            for n in [1, 2]:
                _functions.augtool("rm", \
                                   "/files/etc/ntp.conf/server[%d]" % n, "")
            for idx, server in enumerate(SERVERS):
                n = idx + 1  # Augeas starts at 1
                _functions.augtool("set", \
                                   "/files/etc/ntp.conf/server[%d]" % n, server)
            _functions.system_closefds("service ntpd stop &> /dev/null")
            _functions.system_closefds("service ntpdate start &> /dev/null")
            _functions.system_closefds("service ntpd start &> /dev/null")
Ejemplo n.º 15
0
    def save_ntp_configuration(self):
        _functions.ovirt_store_config(self.NTP_CONFIG_FILE)

        ntproot = "/files/etc/ntp.conf"
        ntpconf = "rm %s\n" % ntproot
        ntpconf += "set %s/driftfile /var/lib/ntp/drift\n" % ntproot
        ntpconf += "set %s/includefile /etc/ntp/crypto/pw\n" % ntproot
        ntpconf += "set %s/keys /etc/ntp/keys" % ntproot
        ntpconf = ntpconf.split("\n")
        for line in ntpconf:
            try:
                oper, key, value = line.split()
                _functions.augtool(oper, key, value)
            except:
                oper, key = line.split()
                _functions.augtool(oper, key, "")

        if "OVIRT_NTP" in OVIRT_VARS:
            SERVERS = [s for s in OVIRT_VARS["OVIRT_NTP"].split(",") if s]
            for n in [1, 2]:
                _functions.augtool("rm", \
                                   "/files/etc/ntp.conf/server[%d]" % n, "")
            for idx, server in enumerate(SERVERS):
                n = idx + 1  # Augeas starts at 1
                _functions.augtool("set", \
                                   "/files/etc/ntp.conf/server[%d]" % n, server)
            _functions.system_closefds("service ntpd stop &> /dev/null")
            _functions.system_closefds("service ntpdate start &> /dev/null")
            _functions.system_closefds("service ntpd start &> /dev/null")
Ejemplo n.º 16
0
 def c():
     cmd = "engine-setup --config=/home/mujun/ovirt_config/20141230183208-setup.conf"
     out = ""
     current = 0
     try:
         import pdb
         pdb.set_trace()
         for line in process.pipe_async(cmd):
             print line
             if line == ""  or line == None :
                 break
             line = ''.join(filter(lambda x: x, line.split('\033[0;31m')))
             line = ''.join(filter(lambda x: x, line.split('\033[32m')))
             line = ''.join(filter(lambda x: x, line.split('\033[0m')))
             out += line
     #    if "icmp_req" in line:
     #        current += 100.0 / float(count)
             current += 1
             if current%7 == 0:
                 current =0
                 out = ""
                 
     #        self.widgets["ping.progress"].current(current)
             with open('/root/abc','a+') as f:
                 f.writelines('Result :\n\n%s' %out)
             self.widgets["ping.result"].text("Result:\n\n %s" % out)
             if isRun():
                 _functions.system_closefds("rm -rf /etc/ovirt-engine/engine-setup.conf &> /dev/null")
                 _functions.system_closefds("engine-setup --gen-answer-file=/etc/ovirt-engine/engine-setup.conf &> /dev/null")
                 _functions.system_closefds("sed -i 1d /etc/ovirt-engine/engine-setup.conf &> /dev/null")
     #self.logger.debug(out)
     except:
         import traceback
         traceback.print_exc()
Ejemplo n.º 17
0
    def save_ntp_configuration(self):
        ntproot = "/files/etc/ntp.conf"
        ntpconf = "rm %s\n" % ntproot
        ntpconf += "set %s/driftfile /var/lib/ntp/drift\n" % ntproot
        ntpconf += "set %s/includefile /etc/ntp/crypto/pw\n" % ntproot
        ntpconf += "set %s/keys /etc/ntp/keys" % ntproot
        ntpconf = ntpconf.split("\n")
        for line in ntpconf:
            try:
                oper, key, value = line.split()
                _functions.augtool(oper, key, value)
            except:
                oper, key = line.split()
                _functions.augtool(oper, key, "")

        if "OVIRT_NTP" in OVIRT_VARS:
            offset = 1
            SERVERS = OVIRT_VARS["OVIRT_NTP"].split(",")
            for server in SERVERS:
                if offset == 1:
                    _functions.augtool("set", \
                                       "/files/etc/ntp.conf/server[1]", server)
                elif offset == 2:
                    _functions.augtool("set", \
                                       "/files/etc/ntp.conf/server[2]", server)
                offset = offset + 1
            _functions.system_closefds("service ntpd stop &> /dev/null")
            _functions.system_closefds("service ntpdate start &> /dev/null")
            _functions.system_closefds("service ntpd start &> /dev/null")
Ejemplo n.º 18
0
        def c():
            cmd = "engine-setup --config=/home/mujun/ovirt_config/20141230183208-setup.conf"
            out = ""
            current = 0
            try:
                import pdb
                pdb.set_trace()
                for line in process.pipe_async(cmd):
                    print line
                    if line == "" or line == None:
                        break
                    line = ''.join(
                        filter(lambda x: x, line.split('\033[0;31m')))
                    line = ''.join(filter(lambda x: x, line.split('\033[32m')))
                    line = ''.join(filter(lambda x: x, line.split('\033[0m')))
                    out += line
                    #    if "icmp_req" in line:
                    #        current += 100.0 / float(count)
                    current += 1
                    if current % 7 == 0:
                        current = 0
                        out = ""

            #        self.widgets["ping.progress"].current(current)
                    with open('/root/abc', 'a+') as f:
                        f.writelines('Result :\n\n%s' % out)
                    self.widgets["ping.result"].text("Result:\n\n %s" % out)
                    if isRun():
                        _functions.system_closefds(
                            "rm -rf /etc/ovirt-engine/engine-setup.conf &> /dev/null"
                        )
                        _functions.system_closefds(
                            "engine-setup --gen-answer-file=/etc/ovirt-engine/engine-setup.conf &> /dev/null"
                        )
                        _functions.system_closefds(
                            "sed -i 1d /etc/ovirt-engine/engine-setup.conf &> /dev/null"
                        )
            #self.logger.debug(out)
            except:
                import traceback
                traceback.print_exc()
Ejemplo n.º 19
0
 def commit(self):
     _functions.system_closefds("echo %s > /tmp/password" % (self.passwd))
     _functions.system_closefds("engine-manage-domains -action=add -domain=%s \
                     -user=admin -interactive -provider=ActiveDirectory -addPermissions -passwordFile=/tmp/password \
                      &> /dev/null" % (self.domain))
Ejemplo n.º 20
0
    def get_dev_name(self):
        devices = []
        # list separator
        for d in os.listdir("/sys/block/"):
            if re.match("^[hsv]+d", d):
                devices.append("/dev/%s" % d)
            byid_list_cmd = ("find /dev/disk/by-id -mindepth 1 -not -name " +
                            "'*-part*' 2>/dev/null")
            byid_list = _functions.subprocess_closefds(byid_list_cmd,
                                            shell=True,
                                            stdout=subprocess.PIPE,
                                            stderr=subprocess.STDOUT)
            byid_list_output, byid_list_err = byid_list.communicate()
        for d in byid_list_output.split():
            d = os.readlink(d)
            d_basename = os.path.basename(d)
            udev_cmd = ("udevadm info --name=/dev/" + d_basename +
                        " --query=property | grep -q ^ID_BUS: &>>/dev/null")
            if _functions.system_closefds(udev_cmd):
                devices.append("/dev/%s" % d_basename)
        # FIXME: workaround for detecting cciss devices
        if os.path.exists("/dev/cciss"):
            for d in os.listdir("/dev/cciss"):
                if not re.match("p[0-9]+\$", d):
                    devices.append("/dev/cciss/%s" % d)

        # include multipath devices
        mpath_sets = ""
        devs_to_remove = {}
        multipath_list_cmd = "dmsetup ls --target=multipath | cut -f1"
        multipath_list = _functions.subprocess_closefds(multipath_list_cmd,
                                             shell=True,
                                             stdout=subprocess.PIPE,
                                             stderr=subprocess.STDOUT)
        multipath_list_output, multipath_list_err = multipath_list.communicate()

        for d in multipath_list_output.split():
            devices.append("/dev/mapper/%s" % d)
            sd_devs = ""
            sd_devs = self.get_multipath_deps(d)

            dm_dev_cmd = ("multipath -ll \"%s\" | grep \"%s\" | " +
                          "sed -r 's/^.*(dm-[0-9]+ ).*$/\\1/'") % (d, d)
            dm_dev = _functions.subprocess_closefds(dm_dev_cmd, shell=True,
                                         stdout=subprocess.PIPE,
                                         stderr=subprocess.STDOUT)
            dm_dev_output, dm_dev_err = dm_dev.communicate()
            [devs_to_remove.update({d: True}) for d in sd_devs.split()]
            mpath_sets = ("%s %s %s" % (mpath_sets, sd_devs,
                                        dm_dev_output))

        logger.debug("Multipath sets are %s" % mpath_sets)
        logger.debug("Removing the following from the list of disks, because "
                     "they're part of a multipath set: %s" % sorted(
                         devs_to_remove))

        # Remove /dev/sd* devices that are part of a multipath device
        dev_list = set()
        for d in devices:
            if (os.path.basename(d) not in devs_to_remove and
                    not "/dev/dm-" in d):
                dev_list.add(d)

        return list(dev_list)
Ejemplo n.º 21
0
 def commit(self):
     _functions.system_closefds("sed -i '/%s %s/d' /etc/hosts" % (self.ip,self.hostname))
     _functions.system_closefds("sed -i '$a\%s %s' /etc/hosts" % (self.ip,self.hostname))
Ejemplo n.º 22
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
Ejemplo n.º 23
0
def set_sasl_password(user, password):
    _functions.system_closefds("saslpasswd2 -a libvirt -p %s") % user
Ejemplo n.º 24
0
 def commit(self):
     _functions.system_closefds("echo %s > /tmp/password" % (self.passwd))
     _functions.system_closefds(
         "engine-manage-domains -action=add -domain=%s \
                     -user=admin -interactive -provider=ActiveDirectory -addPermissions -passwordFile=/tmp/password \
                      &> /dev/null" % (self.domain))
Ejemplo n.º 25
0
def get_system_nics():
    # Re-trigger udev for rhbz#866584
    for sysfspath in glob("/sys/class/net/*"):
        _functions.system_closefds("udevadm test %s > /dev/null 2> /dev/null" % quote(sysfspath))

    client = _functions.gudev.Client(['net'])
    configured_nics = 0
    ntp_dhcp = 0
    nic_dict = {}
    for device in client.query_by_subsystem("net"):
        try:
            dev_interface = device.get_property("INTERFACE")
            dev_vendor = device.get_property("ID_VENDOR_FROM_DATABASE")
            dev_type = device.get_property("DEVTYPE")
            dev_path = device.get_property("DEVPATH")

            if (dev_interface == "lo" or \
                dev_interface.startswith("bond") or \
                dev_interface.startswith("sit") or \
                dev_interface.startswith("vnet") or \
                "." in dev_interface or \
                dev_type == "bridge"):
                logger.info("Skipping interface '%s'" % dev_interface)
                continue
            else:
                logger.info("Gathering informations for '%s'" % dev_interface)

            try:
                dev_vendor = dev_vendor.replace(",", "")
            except AttributeError:
                logger.debug("2. vendor approach: %s" % dev_vendor)
                try:
                    # rhevh workaround since udev version
                    # doesn't have vendor info
                    dev_path = dev_path.split('/')
                    if "virtio" in dev_path[4]:
                        pci_dev = dev_path[3].replace("0000:", "")
                    else:
                        pci_dev = dev_path[4].replace("0000:", "")
                    pci_lookup_cmd = (("lspci|grep '%s'|awk -F \":\" " % pci_dev) +
                                     "{'print $3'}")
                    pci_lookup = _functions.subprocess_closefds(pci_lookup_cmd,
                                 shell=True, stdout=subprocess.PIPE,
                                 stderr=subprocess.STDOUT)
                    dev_vendor = pci_lookup.stdout.read().strip()
                except:
                    dev_vendor = "unknown"
                    logger.debug("3. vendor approach: %s" % dev_vendor)
            try:
                dev_vendor = dev_vendor.replace(",", "")
            except AttributeError:
                dev_vendor = "unknown"
                logger.debug("4. vendor approach: %s" % dev_vendor)

            dev_vendor = _functions.pad_or_trim(25, dev_vendor)
            dev_driver = ""
            try:
                dev_driver = os.readlink("/sys/class/net/" + dev_interface + \
                                         "/device/driver")
                dev_driver = os.path.basename(dev_driver)
            except Exception as e:
                logger.debug("Exception while determining NIC driver: %s" % (
                             repr(e)))
            nic_addr_file = open("/sys/class/net/" + dev_interface + \
                                 "/address")
            dev_address = nic_addr_file.read().strip()
            cmd = ("/files/etc/sysconfig/network-scripts/" + \
                   "ifcfg-%s/BOOTPROTO") % str(dev_interface)
            dev_bootproto = _functions.augtool_get(cmd)
            type_cmd = ("/files/etc/sysconfig/network-scripts/" + \
                        "ifcfg-%s/TYPE") % str(dev_interface)
            bridge_cmd = ("/files/etc/sysconfig/network-scripts/" + \
                          "ifcfg-%s/BRIDGE") % str(dev_interface)
            dev_bridge = _functions.augtool_get(bridge_cmd)

            # check for vlans
            logger.debug("checking for vlan")
            vlans = glob("/etc/sysconfig/network-scripts/ifcfg-%s.*" %
                                                                 dev_interface)
            if (len(vlans) > 0):
                dev_conf_status = "Configured  "
                vlanid = vlans[0].split(".")[-1]
                logger.debug("found vlan %s" % vlanid)

                # if no bridge in nic, check clan-nic for bridge
                if not dev_bridge:
                    vlancfg = "ifcfg-%s.%s" % (str(dev_interface), vlanid)
                    cmd = ("/files/etc/sysconfig/network-scripts/%s/" +
                           "BRIDGE") % vlancfg
                    dev_bridge = augtool_get(cmd)
                    logger.debug("Getting bridge '%s' from vlan: %s" % (
                                                              dev_bridge, cmd))

            if dev_bootproto is None:
                logger.debug("Looking for bootproto in %s" % dev_bridge)
                cmd = ("/files/etc/sysconfig/network-scripts/" + \
                       "ifcfg-%s/BOOTPROTO") % str(dev_bridge)
                dev_bootproto = _functions.augtool_get(cmd)
                if dev_bootproto is None:
                    dev_bootproto = "Disabled"
                    dev_conf_status = "Unconfigured"
                else:
                    dev_conf_status = "Configured  "
            else:
                dev_conf_status = "Configured  "
            if dev_conf_status == "Configured  ":
                configured_nics = configured_nics + 1
        except Exception as e:
            logger.warning("Error while determining NICs: %s" % repr(e))

        nic_info = "%s,%s,%s,%s,%s,%s,%s" % ( \
                   dev_interface, dev_bootproto, \
                   dev_vendor, dev_address, \
                   dev_driver, dev_conf_status, \
                   dev_bridge)
        logger.debug("NIC info: %s" % nic_info)
        nic_dict[dev_interface] = nic_info

        if dev_bootproto == "dhcp":
            ntp_dhcp = 1
    return nic_dict, configured_nics, ntp_dhcp
Ejemplo n.º 26
0
    def save_network_configuration(self):
        _functions.aug.load()
        net_configured = 0
        _functions.augtool_workdir_list = "ls %s/augtool-* >/dev/null"
        logger.info("Configuring network for NIC %s" % self.CONFIGURED_NIC)
        # Wee need to bring down all network stuff, with the current network
        # config, before we change the config. Otherwise the interfaces can
        # not be brought down correctly.
        logger.info("Stopping Network services")
        _functions.system("service network stop")
        # FIXME can't this be done further down were we remove the bridges?
        for vlan in get_system_vlans():
            # XXX wrong match e.g. eth10.1 with eth1
            if self.CONFIGURED_NIC in vlan:
                _functions.system_closefds("vconfig rem " + vlan + \
                                           "&> /dev/null")
                _functions.ovirt_safe_delete_config(self.IFSCRIPTS_PATH + vlan)
                _functions.system_closefds("rm -rf " + \
                                           self.IFSCRIPTS_PATH + vlan)

        # All old config files are gone, the new ones are created step by step

        logger.debug("Removing persisted network configs")
        # This should cover NICs, VLANs and bridges
        for script in glob("%s*" % (self.IFSCRIPTS_PATH)):
            if not _functions.is_persisted(script):
                continue
            logger.debug("Removing Script: " + script)
            _functions.ovirt_safe_delete_config(script)
        _functions.aug.load()

        logger.debug("Updating interface config")
        for line in self.IF_CONFIG:
            logger.debug(line)
            try:
                oper, key, value = line.split()
                _functions.augtool(oper, key, value)
            except:
                oper, key = line.split()
                _functions.augtool(oper, key, "")

        logger.debug("Updating bridge config")
        if not self.disabled_nic == 1:
            for line in self.BR_CONFIG:
                logger.debug(line)
                try:
                    oper, key, value = line.split()
                    _functions.augtool(oper, key, value)
                except:
                    try:
                        oper, key = line.split()
                        _functions.augtool(oper, key, "")
                    except:
                        pass

            logger.debug("Updating VLAN config")
            for line in self.VL_CONFIG.split("\n"):
                logger.debug(line)
                try:
                    oper, key, value = line.split()
                    _functions.augtool(oper, key, value)
                except:
                    try:
                        oper, key = line.split()
                        _functions.augtool(oper, key, "")
                    except:
                        pass

        # preserve current MAC mappings for *all physical* network interfaces
        logger.debug("Preserving current MAC mappings")
        for nicdev in glob('/sys/class/net/*/device'):
            nic = nicdev.split('/')[4]
            if nic != self.CONFIGURED_NIC:
                f = open('/sys/class/net/%s/address' % nic)
                mac = f.read().strip()
                f.close()
                if len(mac) > 0:
                    logger.debug("Mapping for %s" % nic)
                    self.CONFIGURED_NICS.append(nic)
                    nicroot = "%s%s" % (self.IFCONFIG_FILE_ROOT, nic)
                    # XXX _functions.augtool does save every time!
                    _functions.augtool("set", "%s/DEVICE" % nicroot, nic)
                    _functions.augtool("set", "%s/HWADDR" % nicroot, mac)
                    _functions.augtool("set", "%s/ONBOOT" % nicroot, "no")

        logger.debug("Storing configured NICs")
        net_configured = 1
        for nic in self.CONFIGURED_NICS:
            logger.debug("Storing %s" % nic)
            _functions.ovirt_store_config("%s%s" % (self.IFSCRIPTS_PATH, nic))
        _functions.ovirt_store_config(self.NTP_CONFIG_FILE)
        if self.disabled_nic == 1:
            _functions.augtool("set", \
                               "/files/etc/sysconfig/network/NETWORKING", "no")
        else:
            _functions.augtool("set", \
                               "/files/etc/sysconfig/network/NETWORKING", "yes")
        _functions.ovirt_store_config("/etc/sysconfig/network")
        _functions.ovirt_store_config("/etc/hosts")

        # Copy the initial net rules to a file that get's not
        # overwritten at each boot, rhbz#773495
        rulesfile = "/etc/udev/rules.d/70-persistent-net.rules"
        newrulesfile = "/etc/udev/rules.d/71-persistent-node-net.rules"
        if os.path.exists(rulesfile):
            _functions.system_closefds("cp %s %s >> /var/log/ovirt.log" % (
                                                                rulesfile,
                                                                newrulesfile))
            _functions.ovirt_store_config(newrulesfile)

            # Eventully it makes sense to rename the NICs
            #system_closefds("sed -ic 's/NAME=\"eth/NAME=\"eth00/' " +
            #                 "/etc/udev/rules.d/71-persistent-node-net.rules")



        logger.info("Network configured successfully")
        if net_configured == 1:
            logger.info("Stopping Network services")
            _functions.system_closefds("service network stop &> /dev/null")
            _functions.system_closefds("service ntpd stop &> /dev/null")
            # XXX eth assumed in breth
            brctl_cmd = "ip --details --oneline link " \
                "| awk -F':' '/^[0-9]: br[ep]/ {print $2}'"
            brctl = _functions.subprocess_closefds(brctl_cmd, shell=True,
                                                   stdout=subprocess.PIPE,
                                        stderr=subprocess.STDOUT)
            brctl_output = brctl.stdout.read()
            for i in brctl_output.split():
                if_down_cmd = "ifconfig %s down &> /dev/null" % i
                _functions.system_closefds(if_down_cmd)
                del_br_cmd = "ip link delete %s type bridge &> /dev/null" % i
                _functions.system_closefds(del_br_cmd)
            logger.info("Starting Network service")
            _functions.system_closefds("service network start &> /dev/null")
            _functions.system_closefds("service ntpdate start &> /dev/null")
            _functions.system_closefds("service ntpd start &> /dev/null")
            # rhbz#745541
            _functions.system_closefds("service rpcbind start &> /dev/null")
            _functions.system_closefds("service nfslock start &> /dev/null")
            _functions.system_closefds("service rpcidmapd start &> /dev/null")
            _functions.system_closefds("service rpcgssd start &> /dev/null")
            if "NTP" in OVIRT_VARS:
                logger.info("Testing NTP Configuration")
                _functions.test_ntp_configuration()
Ejemplo n.º 27
0
 def confirm_cmd(self, obj):
     warn_message = "Warn %s" % obj.get_label()
     resp_id = ConfirmDialog(message=warn_message).run_and_close()
     if resp_id == gtk.RESPONSE_OK:
         cmd = ("_".join(obj.get_label().split())).lower()
         system_closefds(exec_extra_buttons_cmds[cmd])
Ejemplo n.º 28
0
 def confirm_cmd(self, obj):
     warn_message = "Warn %s" % obj.get_label()
     resp_id = ConfirmDialog(message=warn_message).run_and_close()
     if resp_id == gtk.RESPONSE_OK:
         cmd = ('_'.join(obj.get_label().split())).lower()
         system_closefds(exec_extra_buttons_cmds[cmd])
Ejemplo n.º 29
0
    def get_dev_name(self):
        devices = []
        # list separator
        for d in os.listdir("/sys/block/"):
            if re.match("^[hsv]+d", d):
                devices.append("/dev/%s" % d)
            byid_list_cmd = ("find /dev/disk/by-id -mindepth 1 -not -name " +
                            "'*-part*' 2>/dev/null")
            byid_list = _functions.subprocess_closefds(byid_list_cmd,
                                            shell=True,
                                            stdout=subprocess.PIPE,
                                            stderr=subprocess.STDOUT)
            byid_list_output, byid_list_err = byid_list.communicate()
        for d in byid_list_output.split():
            d = os.readlink(d)
            d_basename = os.path.basename(d)
            udev_cmd = ("udevadm info --name=/dev/" + d_basename +
                        " --query=property | grep -q ^ID_BUS: &>>/dev/null")
            if _functions.system_closefds(udev_cmd):
                devices.append("/dev/%s" % d_basename)
        # FIXME: workaround for detecting cciss devices
        if os.path.exists("/dev/cciss"):
            for d in os.listdir("/dev/cciss"):
                if not re.match("p[0-9]+\$", d):
                    devices.append("/dev/cciss/%s" % d)

        # include multipath devices
        devs_to_remove = ""
        multipath_list_cmd = "dmsetup ls --target=multipath | cut -f1"
        multipath_list = _functions.subprocess_closefds(multipath_list_cmd,
                                             shell=True,
                                             stdout=subprocess.PIPE,
                                             stderr=subprocess.STDOUT)
        multipath_list_output, multipath_list_err = multipath_list.communicate()

        for d in multipath_list_output.split():
            devices.append("/dev/mapper/%s" % d)
            sd_devs = ""
            sd_devs = self.get_multipath_deps(d)

            dm_dev_cmd = ("multipath -ll \"%s\" | grep \"%s\" | " +
                          "sed -r 's/^.*(dm-[0-9]+ ).*$/\\1/'") % (d, d)
            dm_dev = _functions.subprocess_closefds(dm_dev_cmd, shell=True,
                                         stdout=subprocess.PIPE,
                                         stderr=subprocess.STDOUT)
            dm_dev_output, dm_dev_err = dm_dev.communicate()
            devs_to_remove = ("%s %s %s" % (devs_to_remove, sd_devs,
                                          dm_dev_output))
        # Remove /dev/sd* devices that are part of a multipath device
        dev_list = []
        for d in devices:
            if (os.path.basename(d) not in devs_to_remove and
                    not "/dev/dm-" in d):
                dev_list.append(d)

        for dev in dev_list:
            if dev_list.count(dev) > 1:
                count = dev_list.count(dev)
                while (count > 1):
                    dev_list.remove(dev)
                    count = count - 1
        return dev_list
Ejemplo n.º 30
0
def get_system_nics():
    # Re-trigger udev for rhbz#866584
    for sysfspath in glob("/sys/class/net/*"):
        _functions.system_closefds("udevadm test %s > /dev/null 2> /dev/null" %
                                   sysfspath)

    client = _functions.gudev.Client(['net'])
    configured_nics = 0
    ntp_dhcp = 0
    nic_dict = {}
    for device in client.query_by_subsystem("net"):
        try:
            dev_interface = device.get_property("INTERFACE")
            dev_vendor = device.get_property("ID_VENDOR_FROM_DATABASE")
            dev_type = device.get_property("DEVTYPE")
            dev_path = device.get_property("DEVPATH")

            if (dev_interface == "lo" or \
                dev_interface.startswith("bond") or \
                dev_interface.startswith("sit") or \
                dev_interface.startswith("vnet") or \
                "." in dev_interface or \
                dev_type == "bridge"):
                logger.info("Skipping interface '%s'" % dev_interface)
                continue
            else:
                logger.info("Gathering informations for '%s'" % dev_interface)

            try:
                dev_vendor = dev_vendor.replace(",", "")
            except AttributeError:

                logger.debug("2. vendor approach: %s" % dev_vendor)
                try:
                    # rhevh workaround since udev version
                    # doesn't have vendor info
                    dev_path = dev_path.split('/')
                    if "virtio" in dev_path[4]:
                        pci_dev = dev_path[3].replace("0000:", "")
                    else:
                        pci_dev = dev_path[4].replace("0000:", "")
                    pci_lookup_cmd = (
                        ("lspci|grep '%s'|awk -F \":\" " % pci_dev) +
                        "{'print $3'}")
                    pci_lookup = _functions.subprocess_closefds(
                        pci_lookup_cmd,
                        shell=True,
                        stdout=subprocess.PIPE,
                        stderr=subprocess.STDOUT)
                    dev_vendor = pci_lookup.stdout.read().strip()
                except:
                    dev_vendor = "unknown"
                    logger.debug("3. vendor approach: %s" % dev_vendor)
            try:
                dev_vendor = dev_vendor.replace(",", "")
            except AttributeError:
                dev_vendor = "unknown"
                logger.debug("4. vendor approach: %s" % dev_vendor)

            dev_vendor = _functions.pad_or_trim(25, dev_vendor)
            dev_driver = ""
            try:
                dev_driver = os.readlink("/sys/class/net/" + dev_interface + \
                                         "/device/driver")
                dev_driver = os.path.basename(dev_driver)
            except Exception as e:
                logger.debug("Exception while determining NIC driver: %s" %
                             (repr(e)))
            nic_addr_file = open("/sys/class/net/" + dev_interface + \
                                 "/address")
            dev_address = nic_addr_file.read().strip()
            cmd = ("/files/etc/sysconfig/network-scripts/" + \
                   "ifcfg-%s/BOOTPROTO") % str(dev_interface)
            dev_bootproto = _functions.augtool_get(cmd)
            type_cmd = ("/files/etc/sysconfig/network-scripts/" + \
                        "ifcfg-%s/TYPE") % str(dev_interface)
            bridge_cmd = ("/files/etc/sysconfig/network-scripts/" + \
                          "ifcfg-%s/BRIDGE") % str(dev_interface)
            dev_bridge = _functions.augtool_get(bridge_cmd)

            # check for vlans
            logger.debug("checking for vlan")
            vlans = glob("/etc/sysconfig/network-scripts/ifcfg-%s.*" %
                         dev_interface)
            if (len(vlans) > 0):
                dev_conf_status = "Configured  "
                vlanid = vlans[0].split(".")[-1]
                logger.debug("found vlan %s" % vlanid)

                # if no bridge in nic, check clan-nic for bridge
                if not dev_bridge:
                    vlancfg = "ifcfg-%s.%s" % (str(dev_interface), vlanid)
                    cmd = ("/files/etc/sysconfig/network-scripts/%s/" +
                           "BRIDGE") % vlancfg
                    dev_bridge = augtool_get(cmd)
                    logger.debug("Getting bridge '%s' from vlan: %s" %
                                 (dev_bridge, cmd))

            if dev_bootproto is None:
                logger.debug("Looking for bootproto in %s" % dev_bridge)
                cmd = ("/files/etc/sysconfig/network-scripts/" + \
                       "ifcfg-%s/BOOTPROTO") % str(dev_bridge)
                dev_bootproto = _functions.augtool_get(cmd)
                if dev_bootproto is None:
                    dev_bootproto = "Disabled"
                    dev_conf_status = "Unconfigured"
                else:
                    dev_conf_status = "Configured  "
            else:
                dev_conf_status = "Configured  "
            if dev_conf_status == "Configured  ":
                configured_nics = configured_nics + 1
        except Exception as e:
            logger.warning("Error while determining NICs: %s" % repr(e))

        nic_info = "%s,%s,%s,%s,%s,%s,%s" % ( \
                   dev_interface, dev_bootproto, \
                   dev_vendor, dev_address, \
                   dev_driver, dev_conf_status, \
                   dev_bridge)
        logger.debug("NIC info: %s" % nic_info)
        nic_dict[dev_interface] = nic_info

        if dev_bootproto == "dhcp":
            ntp_dhcp = 1
    return nic_dict, configured_nics, ntp_dhcp
Ejemplo n.º 31
0
    def create_appvg(self):
        logger.info("Creating LVM partition(s) for AppVG")
        physical_vols = []
        logger.debug("APPVGDRIVE: " + ' '.join(self.APPVGDRIVE))
        logger.debug("SWAP2_SIZE: " + str(self.SWAP2_SIZE))
        logger.debug("DATA2_SIZE: " + str(self.DATA2_SIZE))
        for drv in self.APPVGDRIVE:
            _functions.wipe_partitions(drv)
            self.reread_partitions(drv)
            logger.info("Labeling Drive: " + drv)
            appvgpart = "1"
            while True:
                parted_cmd = ("parted -s \"" + drv + "\" \"mklabel " +
                              self.LABEL_TYPE +
                              " mkpart primary ext2 2048s -1 set " +
                              appvgpart + " lvm on print\"")
                _functions.system(parted_cmd)
                self.reread_partitions(drv)
                if (os.path.exists(drv + appvgpart) or
                    os.path.exists(drv + "p" + appvgpart)):
                    break

            partpv = drv + appvgpart
            if not os.path.exists(partpv):
                # e.g. /dev/cciss/c0d0p2
                partpv = drv + "p" + appvgpart
            logger.info("Creating physical volume")
            if not os.path.exists(partpv):
                logger.error(partpv + " is not available!")
                return False
            dd_cmd = "dd if=/dev/zero of=\"" + partpv + "\" bs=1024k count=1"
            logger.info(dd_cmd)
            _functions.system(dd_cmd)
            _functions.system("pvcreate -ff -y \"" + partpv + "\"")
            physical_vols.append(partpv)

        logger.info("Creating volume group AppVG")
        is_first = True
        for drv in physical_vols:
            if is_first:
                _functions.system("vgcreate AppVG \"" + drv + "\"")
                is_first = False
            else:
                _functions.system("vgextend AppVG \"" + drv + "\"")

        if self.SWAP2_SIZE > 0:
            logger.info("Creating swap2 partition")
            lv_cmd = ("lvcreate --name Swap2 --size \"" +
                      str(self.SWAP2_SIZE) + "M\" /dev/AppVG")
            logger.debug(lv_cmd)
            _functions.system(lv_cmd)
            if "OVIRT_CRYPT_SWAP2" in _functions.OVIRT_VARS:
                _functions.system_closefds("echo \"SWAP2 /dev/AppVG/Swap2 " +
                                "/dev/mapper/ovirt-crypt-swap2 " +
                                _functions.OVIRT_VARS["OVIRT_CRYPT_SWAP2"] +
                                "\" >> /etc/ovirt-crypttab")
            else:
                _functions.system("mkswap -L \"SWAP2\" /dev/AppVG/Swap2")
                _functions.system_closefds("echo \"/dev/AppVG/Swap2 " + \
                                "swap swap defaults 0 0\" >> /etc/fstab")

        use_data = "1"
        if self.DATA2_SIZE == -1:
            logger.info("Creating data2 partition with remaining free space")
            _functions.system("lvcreate --name Data2 -l 100%FREE /dev/AppVG")
            use_data = 0
        elif self.DATA2_SIZE > 0:
            logger.info("Creating data2 partition")
            _functions.system("lvcreate --name Data2 --size " + \
                              str(self.DATA2_SIZE) +
                   "M /dev/AppVG")
            use_data = 0

        if use_data == 0:
            _functions.system("mke2fs -j -t ext4 /dev/AppVG/Data2 " + \
                              "-L \"DATA2\"")
            _functions.system("tune2fs -c 0 -i 0 /dev/AppVG/Data2")
            _functions.system_closefds("echo \"/dev/AppVG/Data2 /data2 ext4 " +
                            "defaults,noatime 0 0\" >> /etc/fstab")
            logger.info("Mounting data2 partition")
            _functions.mount_data2()
            logger.info("Completed AppVG!")
            return True
Ejemplo n.º 32
0
    def on_merge(self, effective_changes):
        """Applies the changes to the plugins model, will do all required logic
        Normally on_merge is called by pushing the SaveButton instance, in this
        case it is called by on_change
        """

        #if "ping.address" in self._model:
        #    addr = self._model["ping.address"]
        #    count = self._model["ping.count"]
        #    self.logger.debug("Pinging %s" % addr)

        #    cmd = "ping"
        #    if valid.IPv6Address().validate(addr):
        #        cmd = "ping6"

        #cmd = "%s -c %s %s" % (cmd, count, addr)
        changes = Changeset(self.pending_changes(False))
        if changes.contains_any(["ping.do_ping"]):
            #_functions.system_closefds("cat - /etc/ovirt-engine/engine-setup.conf <<< [general] > \
            #                        /etc/ovirt-engine/engine-setup.conf.temp")
            
            cmd = "engine-setup --config="+self.filename
            out = ""
            current = 0
            try:
                for line in process.pipe_async(cmd):
                    if line == ""  or line == None :
                        break
                    line = ''.join(filter(lambda x: x, line.split('\033[0;31m')))
                    line = ''.join(filter(lambda x: x, line.split('\033[32m')))
                    line = ''.join(filter(lambda x: x, line.split('\033[0m')))
                    out += line
            #    if "icmp_req" in line:
            #        current += 100.0 / float(count)
                    current += 1
                    if current%7 == 0:
                        current =0
                        out = ""
                        
            #        self.widgets["ping.progress"].current(current)
                    #with open('/root/abc','a+') as f:
                    #    f.writelines('Result :\n\n%s' %out)
                    self.widgets["ping.result"].text("Result:\n\n %s" % out)
                    if isRun():
                        _functions.system_closefds("rm -rf /etc/ovirt-engine/engine-setup.conf &> /dev/null")
                        _functions.system_closefds("engine-setup --gen-answer-file=/etc/ovirt-engine/engine-setup.conf &> /dev/null")
                        _functions.system_closefds("sed -i 1d /etc/ovirt-engine/engine-setup.conf &> /dev/null")
                        
                
            #self.logger.debug(out)
            except:
                pass
            
            #self._miscEncrypted()
            #shutil.copy(cfile, file+'c')
            self.widgets["ping.result"].text('')
            self.widgets["ping.result"].text("Operate successfully")
            

        elif changes.contains_any(["ping.cancel"]):
            plugin_type = engine_page.Plugin
            self.application.switch_to_plugin(plugin_type)
Ejemplo n.º 33
0
def set_sasl_password(user, password):
    _functions.system_closefds("saslpasswd2 -a libvirt -p %s") % user
Ejemplo n.º 34
0
    def on_merge(self, effective_changes):
        self.logger.info("Saving engine stuff")
        changes = Changeset(self.pending_changes(False))
        effective_model = Changeset(self.model())
        effective_model.update(effective_changes)

        self.logger.debug("Changes: %s" % changes)
        self.logger.debug("Effective Model: %s" % effective_model)
        if changes.contains_any(["action.fetch_options"]):

            http_port = effective_model.values_for(["engine_cfg.httpPORT"])[0]
            https_port = effective_model.values_for(["engine_cfg.httpsPORT"
                                                     ])[0]
            auth_pass = effective_model.values_for(["engine_cfg.authPASS"])[0]
            org_license = effective_model.values_for(["engine_cfg.license"])[0]
            host_fqdn = effective_model.values_for(["engine_cfg.hostFQDN"])[0]
            db_local_pass = effective_model.values_for(
                ["engine_cfg.adminPASS"])[0]
            org_name = effective_model.values_for(["engine_cfg.orgNAME"])[0]
            nfs_mp = effective_model.values_for(["engine_cfg.isoPATH"])[0]
            pieces={"OVESETUP_CONFIG/httpPort":http_port,'OVESETUP_CONFIG/httpsPort':\
                                         https_port,"OVESETUP_CONFIG/adminPassword":auth_pass,\
                                         "ORG_LICENSE":org_license,'OVESETUP_DB/password':db_local_pass,\
                                         "OVESETUP_PKI/organization":org_name,'OVESETUP_CONFIG/isoDomainMountPoint':nfs_mp}
            if not auth_pass:
                pieces.update({'TUI_change_admin': False})
            self.engine_config.update(**pieces)

            self._fp_dialog = AdvanceOptionsDialog(
                self,
                'Engine Advance Options:',
                app_mode=self.cfg["OVESETUP_CONFIG/applicationMode"],
                db_type=self.cfg["OVESETUP_CONFIG/storageIsLocal"],
                config_nfs=self.cfg["OVESETUP_SYSTEM/nfsConfigEnabled"],
                firewall=self.cfg["OVESETUP_CONFIG/firewallManager"],
                dc_type=self.cfg["OVESETUP_CONFIG/storageType"])
            return self._fp_dialog
        elif changes.contains_any(["action.reset"]):
            _functions.system_closefds(
                "rm -rf /etc/ovirt-engine/engine-setup.conf &> /dev/null")
            _functions.system_closefds(
                "engine-setup --gen-answer-file=/etc/ovirt-engine/engine-setup.conf &> /dev/null"
            )
            _functions.system_closefds(
                "sed -i 1d /etc/ovirt-engine/engine-setup.conf &> /dev/null")
        elif changes.contains_any(["dialog.options.save"]):
            #LOGGER.debug("dialog.options.save................................!!!!")
            args = effective_model.values_for(self._options_details_group)
            self._advance_configure(*args)
            self._fp_dialog.close()

        if effective_changes.contains_any(["action.register"]):
            self.logger.debug("engine setup")
            #txs += [ActivateVDSM()]
            http_port = effective_model.values_for(["engine_cfg.httpPORT"])[0]

            https_port = effective_model.values_for(["engine_cfg.httpsPORT"
                                                     ])[0]
            auth_pass = effective_model.values_for(["engine_cfg.authPASS"])[0]
            org_license = effective_model.values_for(["engine_cfg.license"])[0]
            host_fqdn = effective_model.values_for(["engine_cfg.hostFQDN"])[0]
            db_local_pass = effective_model.values_for(
                ["engine_cfg.adminPASS"])[0]
            org_name = effective_model.values_for(["engine_cfg.orgNAME"])[0]
            nfs_mp = effective_model.values_for(["engine_cfg.isoPATH"])[0]
            self.cfg = self.engine_config.retrieve()
            if self.cfg['OVESETUP_SYSTEM/nfsConfigEnabled']:
                if not nfs_mp:
                    return
            pieces={"OVESETUP_CONFIG/httpPort":http_port,'OVESETUP_CONFIG/httpsPort':\
                                         https_port,"OVESETUP_CONFIG/adminPassword":auth_pass,\
                                         "ORG_LICENSE":org_license,'OVESETUP_DB/password':db_local_pass,\
                                         "OVESETUP_PKI/organization":org_name,'OVESETUP_CONFIG/isoDomainMountPoint':nfs_mp}
            if not auth_pass:
                pieces.update({"TUI_change_admin": False})
            self.engine_config.update(**pieces)

            #args = effective_model.values_for(self._options_details_group)
            #self._advance_configure(*args)
            plugin_type = setup.Plugin
            self.cfg = self.engine_config.retrieve()
            plugin_type.environment = self.cfg
            plugin_type.filename = self.fn
            self.application.switch_to_plugin(plugin_type)
            return
        #if len(txs) > 0:
        #    progress_dialog = ui.TransactionProgressDialog("dialog.txs", txs,
        #                                                   self)
        #    progress_dialog.run()

        # VDSM messes with logging, and we just reset it
        #    app.configure_logging()

        # Acts like a page reload
        return self.ui_content()
Ejemplo n.º 35
0
 def commit(self):
     _functions.system_closefds("sed -i '/%s %s/d' /etc/hosts" %
                                (self.ip, self.hostname))
     _functions.system_closefds("sed -i '$a\%s %s' /etc/hosts" %
                                (self.ip, self.hostname))
Ejemplo n.º 36
0
    def save_network_configuration(self):
        _functions.aug.load()
        net_configured = 0
        _functions.augtool_workdir_list = "ls %s/augtool-* >/dev/null"
        logger.info("Configuring network for NIC %s" % self.CONFIGURED_NIC)
        # Wee need to bring down all network stuff, with the current network
        # config, before we change the config. Otherwise the interfaces can
        # not be brought down correctly.
        logger.info("Stopping Network services")
        _functions.system("service network stop")
        # FIXME can't this be done further down were we remove the bridges?
        for vlan in get_system_vlans():
            # XXX wrong match e.g. eth10.1 with eth1
            if self.CONFIGURED_NIC in vlan:
                _functions.system_closefds("vconfig rem " + vlan + \
                                           "&> /dev/null")
                _functions.ovirt_safe_delete_config(self.IFSCRIPTS_PATH + vlan)
                _functions.system_closefds("rm -rf " + \
                                           self.IFSCRIPTS_PATH + vlan)

        # All old config files are gone, the new ones are created step by step

        logger.debug("Removing persisted network configs")
        # This should cover NICs, VLANs and bridges
        for script in glob("%s*" % (self.IFSCRIPTS_PATH)):
            #print script
            #print 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa'
            if not _functions.is_persisted(script):
                continue
            logger.debug("Removing Script: " + script)
            _functions.ovirt_safe_delete_config(script)
        _functions.aug.load()

        logger.debug("Updating interface config")
        for line in self.IF_CONFIG:
            logger.debug(line)
            try:
                oper, key, value = line.split()
                _functions.augtool(oper, key, value)
            except:
                oper, key = line.split()
                _functions.augtool(oper, key, "")

        logger.debug("Updating bridge config")
        if not self.disabled_nic == 1:
            for line in self.BR_CONFIG:
                logger.debug(line)
                try:
                    oper, key, value = line.split()
                    _functions.augtool(oper, key, value)
                except:
                    try:
                        oper, key = line.split()
                        _functions.augtool(oper, key, "")
                    except:
                        pass

            logger.debug("Updating VLAN config")
            for line in self.VL_CONFIG.split("\n"):
                logger.debug(line)
                try:
                    oper, key, value = line.split()
                    _functions.augtool(oper, key, value)
                except:
                    try:
                        oper, key = line.split()
                        _functions.augtool(oper, key, "")
                    except:
                        pass

        # preserve current MAC mappings for *all physical* network interfaces
        logger.error("Preserving current MAC mappings")
        for nicdev in glob('/sys/class/net/*/device'):
            nic = nicdev.split('/')[4]
            if nic != self.CONFIGURED_NIC:
                f = open('/sys/class/net/%s/address' % nic)
                mac = f.read().strip()
                f.close()
                if len(mac) > 0:
                    logger.debug("Mapping for %s" % nic)
                    self.CONFIGURED_NICS.append(nic)
                    nicroot = "%s%s" % (self.IFCONFIG_FILE_ROOT, nic)
                    # XXX _functions.augtool does save every time!
                    _functions.augtool("set", "%s/DEVICE" % nicroot, nic)
                    _functions.augtool("set", "%s/HWADDR" % nicroot, mac)
                    _functions.augtool("set", "%s/ONBOOT" % nicroot, "no")

        logger.debug("Storing configured NICs")
        net_configured = 1
        for nic in self.CONFIGURED_NICS:
            logger.debug("Storing %s" % nic)
            _functions.ovirt_store_config("%s%s" % (self.IFSCRIPTS_PATH, nic))
        _functions.ovirt_store_config(self.NTP_CONFIG_FILE)
        if self.disabled_nic == 1:
            _functions.augtool("set", \
                               "/files/etc/sysconfig/network/NETWORKING", "no")
        else:
            _functions.augtool("set", \
                               "/files/etc/sysconfig/network/NETWORKING", "yes")
        _functions.ovirt_store_config("/etc/sysconfig/network")
        _functions.ovirt_store_config("/etc/hosts")

        # Copy the initial net rules to a file that get's not
        # overwritten at each boot, rhbz#773495
        rulesfile = "/etc/udev/rules.d/70-persistent-net.rules"
        newrulesfile = "/etc/udev/rules.d/71-persistent-node-net.rules"
        if os.path.exists(rulesfile):
            _functions.system_closefds("cp %s %s >> /var/log/ovirt.log" %
                                       (rulesfile, newrulesfile))
            _functions.ovirt_store_config(newrulesfile)

            # Eventully it makes sense to rename the NICs
            #system_closefds("sed -ic 's/NAME=\"eth/NAME=\"eth00/' " +
            #                 "/etc/udev/rules.d/71-persistent-node-net.rules")

        logger.info("Network configured successfully")
        if net_configured == 1:
            logger.info("Stopping Network services")
            _functions.system_closefds("service network stop &> /dev/null")
            _functions.system_closefds("service ntpd stop &> /dev/null")
            # XXX eth assumed in breth
            brctl_cmd = "brctl show| awk 'NR>1 && /^br[ep]/ {print $1}'"
            brctl = _functions.subprocess_closefds(brctl_cmd,
                                                   shell=True,
                                                   stdout=subprocess.PIPE,
                                                   stderr=subprocess.STDOUT)
            brctl_output = brctl.stdout.read()
            for i in brctl_output.split():
                if_down_cmd = "ifconfig %s down &> /dev/null" % i
                _functions.system_closefds(if_down_cmd)
                del_br_cmd = "brctl delbr %s &> /dev/null" % i
                _functions.system_closefds(del_br_cmd)
            logger.info("Starting Network service")
            _functions.system_closefds("service network start &> /dev/null")
            _functions.system_closefds("service ntpdate start &> /dev/null")
            _functions.system_closefds("service ntpd start &> /dev/null")
            # rhbz#745541
            _functions.system_closefds("service rpcbind start &> /dev/null")
            _functions.system_closefds("service nfslock start &> /dev/null")
            _functions.system_closefds("service rpcidmapd start &> /dev/null")
            _functions.system_closefds("service rpcgssd start &> /dev/null")
            if "NTP" in OVIRT_VARS:
                logger.info("Testing NTP Configuration")
                _functions.test_ntp_configuration()