예제 #1
0
 def get_localhost_entry(self):
     entries = _functions.augtool("match", "/files/etc/hosts/*", "")
     for entry in entries:
         ipaddr = _functions.augtool("get", entry + "/ipaddr", "")
         if ipaddr == "127.0.0.1":
             return entry
     return None
예제 #2
0
 def get_localhost_entry(self):
     entries = _functions.augtool("match", "/files/etc/hosts/*", "")
     for entry in entries:
         ipaddr = _functions.augtool("get", entry + "/ipaddr", "")
         if ipaddr == "127.0.0.1":
             return entry
     return None
예제 #3
0
파일: rhevm.py 프로젝트: vikas-lamba/vdsm
 def action(self):
     self.ncs.screen.setColor("BUTTON", "black", "red")
     self.ncs.screen.setColor("ACTBUTTON", "blue", "white")
     if self.root_password_1.value() != "" and self.root_password_2.value(
     ) != "" and self.root_password_1.value() == self.root_password_2.value(
     ):
         set_password(self.root_password_1.value(), "root")
         augtool("set", "/files/etc/ssh/sshd_config/PasswordAuthentication",
                 "yes")
         dn = file('/dev/null', 'w+')
         subprocess.Popen(['/sbin/service', 'sshd', 'restart'],
                          stdout=dn,
                          stderr=dn)
     if len(self.rhevm_server.value()) > 0:
         deployUtil.nodeCleanup()
         if self.verify_rhevm_cert.selected():
             if deployUtil.getRhevmCert(self.rhevm_server.value(),
                                        self.rhevm_server_port.value()):
                 path, dontCare = deployUtil.certPaths('')
                 fp = deployUtil.generateFingerPrint(path)
                 approval = ButtonChoiceWindow(
                     self.ncs.screen,
                     "Certificate Fingerprint:",
                     fp,
                     buttons=['Approve', 'Reject'])
                 if 'reject' == approval:
                     ButtonChoiceWindow(self.ncs.screen,
                                        "Fingerprint rejected",
                                        "RHEV-M Configuration Failed",
                                        buttons=['Ok'])
                     return False
                 else:
                     ovirt_store_config(path)
                     self.ncs.reset_screen_colors()
             else:
                 ButtonChoiceWindow(self.ncs.screen,
                                    "RHEV-M Configuration",
                                    "Failed downloading RHEV-M certificate",
                                    buttons=['Ok'])
                 self.ncs.reset_screen_colors()
         # Stopping vdsm-reg may fail but its ok - its in the case when the menus are run after installation
         deployUtil._logExec([constants.EXT_SERVICE, 'vdsm-reg', 'stop'])
         if write_vdsm_config(self.rhevm_server.value(),
                              self.rhevm_server_port.value()):
             deployUtil._logExec(
                 [constants.EXT_SERVICE, 'vdsm-reg', 'start'])
             ButtonChoiceWindow(self.ncs.screen,
                                "RHEV-M Configuration",
                                "RHEV-M Configuration Successfully Updated",
                                buttons=['Ok'])
             self.ncs.reset_screen_colors()
             return True
         else:
             ButtonChoiceWindow(self.ncs.screen,
                                "RHEV-M Configuration",
                                "RHEV-M Configuration Failed",
                                buttons=['Ok'])
             self.ncs.reset_screen_colors()
             return False
예제 #4
0
파일: log.py 프로젝트: ArchipelProject/Node
def set_logrotate_size(size):
    try:
        _functions.augtool("set", \
                           "/files/etc/logrotate.d/ovirt-node/rule/size", size)
        _functions.ovirt_store_config("/etc/logrotate.d/ovirt-node")
        return True
    except:
        return False
예제 #5
0
파일: log.py 프로젝트: ArchipelProject/Node
def set_logrotate_size(size):
    try:
        _functions.augtool("set", \
                           "/files/etc/logrotate.d/ovirt-node/rule/size", size)
        _functions.ovirt_store_config("/etc/logrotate.d/ovirt-node")
        return True
    except:
        return False
예제 #6
0
파일: log.py 프로젝트: ArchipelProject/Node
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
예제 #7
0
파일: log.py 프로젝트: ArchipelProject/Node
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
예제 #8
0
 def remove_non_localhost(self):
     last_alias = _functions.augtool("get", self.localhost_entry + \
                                     "/alias[" + \
                                     str(self.alias_count) + "]", "")
     while self.alias_count != 0:
         if last_alias == "localhost":
             break
         elif last_alias == "localhost.localdomain":
             break
         _functions.augtool("rm", self.localhost_entry + "/alias[" + \
                       str(self.alias_count) + "]", "")
         self.alias_count = self.alias_count - 1
예제 #9
0
 def remove_non_localhost(self):
     last_alias = _functions.augtool("get", self.localhost_entry + \
                                     "/alias[" + \
                                     str(self.alias_count) + "]", "")
     while self.alias_count != 0:
         if last_alias == "localhost":
             break
         elif last_alias == "localhost.localdomain":
             break
         _functions.augtool("rm", self.localhost_entry + "/alias[" + \
                       str(self.alias_count) + "]", "")
         self.alias_count = self.alias_count - 1
예제 #10
0
파일: network.py 프로젝트: bretep/Node
def convert_to_biosdevname():
    if not "BIOSDEVNAMES_CONVERSION" in OVIRT_VARS:
        # check for appropriate bios version
        cmd="dmidecode|grep SMBIOS|awk {'print $2'}"
        proc = _functions.passthrough(cmd, log_func=logger.debug)
        ver = proc.stdout.split()[0]
        if not float(ver) >= 2.6:
            logger.debug("Skipping biosdevname conversion, SMBIOS too old")
            augtool("set", "/files/etc/default/ovirt/BIOSDEVNAMES_CONVERSION", "y")
            return
        nics = {}
        cmd = "biosdevname -d"
        biosdevname, err = subprocess.Popen(cmd, shell=True,
                                          stdout=subprocess.PIPE).communicate()
        biosdevname_output = biosdevname.splitlines()

        for line in biosdevname_output:
            if line is not None:
                if "BIOS device:" in line:
                    nic = line.split()[2]
                if "Permanent" in line:
                    mac = line.split()[2]
                    nics[mac.upper()] = nic
        logger.debug(nics)
        scripts_path = "/etc/sysconfig/network-scripts"
        logger.debug(glob(scripts_path + "/ifcfg-*"))
        for file in glob(scripts_path + "/ifcfg-*"):
            logger.debug("Processing %s" % file)
            # get mac for matching
            existing_mac = _functions.augtool_get("/files/" + file + "/HWADDR")
            # check dictionary for mac
            if not existing_mac is None and existing_mac.upper() in nics:
                old_nic_script = os.path.basename(file)
                new_nic_name = nics[existing_mac.upper()]
                logger.debug("Found %s in %s" % (existing_mac, file))
                # change device name within script file
                logger.debug("Setting to new device name: %s" % new_nic_name)
                _functions.augtool("set", \
                                   "/files" + file + "/DEVICE", new_nic_name)
                new_nic_file = "%s/ifcfg-%s" % (scripts_path, new_nic_name)
                cmd = "cp %s %s" % (file, new_nic_file)
                _functions.remove_config(file)
                if _functions.system(cmd):
                    logging.debug("Conversion on %s to %s succeed" % (file,
                                  new_nic_file))
                    _functions.ovirt_store_config(new_nic_file)
                else:
                    return False
        _functions.system("service network restart")
        _functions.augtool("set", \
                       "/files/etc/default/ovirt/BIOSDEVNAMES_CONVERSION", "y")
        _functions.ovirt_store_config("/etc/default/ovirt")
    return True
예제 #11
0
def ovirt_netconsole(server, port):
    _functions.augtool("set", \
                       "/files/etc/sysconfig/netconsole/SYSLOGADDR", server)
    _functions.augtool("set", \
                       "/files/etc/sysconfig/netconsole/SYSLOGPORT", port)
    try:
        system.service("netconsole", "restart")
    except:
        raise RuntimeError("Failed to restart netconsole service. "
                           "Is the host resolvable?")
    if _functions.ovirt_store_config("/etc/sysconfig/netconsole"):
        logger.info("Netconsole Configuration Updated")
    return True
예제 #12
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")
예제 #13
0
파일: network.py 프로젝트: bretep/Node
    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")
예제 #14
0
파일: network.py 프로젝트: bretep/Node
 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")
예제 #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")
예제 #16
0
파일: engine.py 프로젝트: ekohl/vdsm
 def action(self):
     self.ncs.screen.setColor("BUTTON", "black", "red")
     self.ncs.screen.setColor("ACTBUTTON", "blue", "white")
     if self.root_password_1.value() != "" and self.root_password_2.value() != "" and self.root_password_1.value() == self.root_password_2.value():
         set_password(self.root_password_1.value(), "root")
         augtool("set", "/files/etc/ssh/sshd_config/PasswordAuthentication", "yes")
         dn = file('/dev/null', 'w+')
         subprocess.Popen(['/sbin/service', 'sshd', 'restart'], stdout=dn, stderr=dn)
     if len(self.rhevm_server.value()) > 0:
         deployUtil.nodeCleanup()
         if self.verify_rhevm_cert.selected():
             if deployUtil.getRhevmCert(self.rhevm_server.value(),  self.rhevm_server_port.value()):
                 path, dontCare = deployUtil.certPaths('')
                 fp = deployUtil.generateFingerPrint(path)
                 approval = ButtonChoiceWindow(self.ncs.screen,
                             "Certificate Fingerprint:",
                             fp, buttons = ['Approve', 'Reject'])
                 if 'reject' == approval:
                     ButtonChoiceWindow(self.ncs.screen, "Fingerprint rejected", "oVirt Engine Configuration Failed", buttons = ['Ok'])
                     return False
                 else:
                     ovirt_store_config(path)
                     self.ncs.reset_screen_colors()
             else:
                 ButtonChoiceWindow(self.ncs.screen, "oVirt Engine Configuration", "Failed downloading oVirt Engine certificate", buttons = ['Ok'])
                 self.ncs.reset_screen_colors()
         # Stopping vdsm-reg may fail but its ok - its in the case when the menus are run after installation
         deployUtil._logExec([constants.EXT_SERVICE, 'vdsm-reg', 'stop'])
         if write_vdsm_config(self.rhevm_server.value(), self.rhevm_server_port.value()):
             deployUtil._logExec([constants.EXT_SERVICE, 'vdsm-reg',
                 'start'])
             ButtonChoiceWindow(self.ncs.screen, "oVirt Engine Configuration", "oVirt Engine Configuration Successfully Updated", buttons = ['Ok'])
             self.ncs.reset_screen_colors()
             return True
         else:
             ButtonChoiceWindow(self.ncs.screen, "oVirt Engine Configuration", "oVirt Engine Configuration Failed", buttons = ['Ok'])
             self.ncs.reset_screen_colors()
             return False
예제 #17
0
def convert_to_biosdevname():
    if not "BIOSDEVNAMES_CONVERSION" in OVIRT_VARS:
        # check for appropriate bios version
        cmd = "dmidecode|grep SMBIOS|awk {'print $2'}"
        proc = _functions.passthrough(cmd, log_func=logger.debug)
        ver = proc.stdout.split()[0]
        if not float(ver) >= 2.6:
            logger.debug("Skipping biosdevname conversion, SMBIOS too old")
            _functions.augtool(
                "set", "/files/etc/default/ovirt/BIOSDEVNAMES_CONVERSION", "y")
            return
        nics = {}
        cmd = "biosdevname -d"
        biosdevname, err = subprocess.Popen(
            cmd, shell=True, stdout=subprocess.PIPE).communicate()
        biosdevname_output = biosdevname.splitlines()

        for line in biosdevname_output:
            if line is not None:
                if "BIOS device:" in line:
                    nic = line.split()[2]
                if "Permanent" in line:
                    mac = line.split()[2]
                    nics[mac.upper()] = nic
        logger.debug(nics)
        scripts_path = "/etc/sysconfig/network-scripts"
        logger.debug(glob(scripts_path + "/ifcfg-*"))
        for file in glob(scripts_path + "/ifcfg-*"):
            logger.debug("Processing %s" % file)
            # get mac for matching
            existing_mac = _functions.augtool_get("/files/" + file + "/HWADDR")
            # check dictionary for mac
            if not existing_mac is None and existing_mac.upper() in nics:
                old_nic_script = os.path.basename(file)
                new_nic_name = nics[existing_mac.upper()]
                logger.debug("Found %s in %s" % (existing_mac, file))
                # change device name within script file
                logger.debug("Setting to new device name: %s" % new_nic_name)
                _functions.augtool("set", \
                                   "/files" + file + "/DEVICE", new_nic_name)
                new_nic_file = "%s/ifcfg-%s" % (scripts_path, new_nic_name)
                cmd = "cp %s %s" % (file, new_nic_file)
                _functions.remove_config(file)
                if _functions.system(cmd):
                    logging.debug("Conversion on %s to %s succeed" %
                                  (file, new_nic_file))
                    _functions.ovirt_store_config(new_nic_file)
                else:
                    return False
        _functions.system("service network restart")
        _functions.augtool("set", \
                       "/files/etc/default/ovirt/BIOSDEVNAMES_CONVERSION", "y")
        _functions.ovirt_store_config("/etc/default/ovirt")
    return True
예제 #18
0
def augtool_set(key, val):
    augtool('rm', key, "")
    augtool('set', key, val)
예제 #19
0
def augtool_set(key, val):
    augtool('rm', key, "")
    augtool('set', key, val)
예제 #20
0
 def get_num_localhost_aliases(self):
     if self.localhost_entry:
         aliases = _functions.augtool("match", self.localhost_entry + \
                                      "/alias", "")
         return len(aliases)
     return 0
예제 #21
0
 def add_localhost_alias(self, alias):
     self.alias_count = self.alias_count + 1
     _functions.augtool("set", self.localhost_entry + "/alias[" + \
                    str(self.alias_count) + "]", alias)
예제 #22
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()
예제 #23
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")
예제 #24
0
 def add_localhost_alias(self, alias):
     self.alias_count = self.alias_count + 1
     _functions.augtool("set", self.localhost_entry + "/alias[" + \
                    str(self.alias_count) + "]", alias)
예제 #25
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")
예제 #26
0
 def get_num_localhost_aliases(self):
     if self.localhost_entry:
         aliases = _functions.augtool("match", self.localhost_entry + \
                                      "/alias", "")
         return len(aliases)
     return 0
예제 #27
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()