Example #1
0
 def _write_network(self, settings):
     # TODO(harlowja) fix this... since this is the ubuntu format
     entries = net_util.translate_network(settings)
     LOG.debug("Translated ubuntu style network settings %s into %s",
               settings, entries)
     # Make the intermediate format as the rhel format...
     nameservers = []
     searchservers = []
     dev_names = entries.keys()
     for (dev, info) in entries.iteritems():
         net_fn = self.network_script_tpl % (dev)
         net_cfg = {
             'DEVICE': dev,
             'NETMASK': info.get('netmask'),
             'IPADDR': info.get('address'),
             'BOOTPROTO': info.get('bootproto'),
             'GATEWAY': info.get('gateway'),
             'BROADCAST': info.get('broadcast'),
             'MACADDR': info.get('hwaddress'),
             'ONBOOT': _make_sysconfig_bool(info.get('auto')),
         }
         rhel_util.update_sysconfig_file(net_fn, net_cfg)
         if 'dns-nameservers' in info:
             nameservers.extend(info['dns-nameservers'])
         if 'dns-search' in info:
             searchservers.extend(info['dns-search'])
     if nameservers or searchservers:
         rhel_util.update_resolve_conf_file(self.resolve_conf_fn,
                                            nameservers, searchservers)
     if dev_names:
         net_cfg = {
             'NETWORKING': _make_sysconfig_bool(True),
         }
         rhel_util.update_sysconfig_file(self.network_conf_fn, net_cfg)
     return dev_names
Example #2
0
 def _write_network(self, settings):
     # TODO(harlowja) fix this... since this is the ubuntu format
     entries = rhel_util.translate_network(settings)
     LOG.debug("Translated ubuntu style network settings %s into %s",
               settings, entries)
     # Make the intermediate format as the rhel format...
     nameservers = []
     searchservers = []
     dev_names = entries.keys()
     for (dev, info) in entries.iteritems():
         net_fn = self.network_script_tpl % (dev)
         net_cfg = {
             'DEVICE': dev,
             'NETMASK': info.get('netmask'),
             'IPADDR': info.get('address'),
             'BOOTPROTO': info.get('bootproto'),
             'GATEWAY': info.get('gateway'),
             'BROADCAST': info.get('broadcast'),
             'MACADDR': info.get('hwaddress'),
             'ONBOOT': _make_sysconfig_bool(info.get('auto')),
         }
         rhel_util.update_sysconfig_file(net_fn, net_cfg)
         if 'dns-nameservers' in info:
             nameservers.extend(info['dns-nameservers'])
         if 'dns-search' in info:
             searchservers.extend(info['dns-search'])
     if nameservers or searchservers:
         rhel_util.update_resolve_conf_file(self.resolve_conf_fn,
                                            nameservers, searchservers)
     if dev_names:
         net_cfg = {
             'NETWORKING': _make_sysconfig_bool(True),
         }
         rhel_util.update_sysconfig_file(self.network_conf_fn, net_cfg)
     return dev_names
Example #3
0
 def apply_locale(self, locale, out_fn=None):
     if not out_fn:
         out_fn = self.locale_conf_fn
     locale_cfg = {
         'RC_LANG': locale,
     }
     rhel_util.update_sysconfig_file(out_fn, locale_cfg)
Example #4
0
 def apply_locale(self, locale, out_fn=None):
     if not out_fn:
         out_fn = self.locale_conf_fn
     locale_cfg = {
         'RC_LANG': locale,
     }
     rhel_util.update_sysconfig_file(out_fn, locale_cfg)
Example #5
0
 def set_timezone(self, tz):
     tz_file = self._find_tz_file(tz)
     # Adjust the sysconfig clock zone setting
     clock_cfg = {"TIMEZONE": str(tz)}
     rhel_util.update_sysconfig_file(self.clock_conf_fn, clock_cfg)
     # This ensures that the correct tz will be used for the system
     util.copy(tz_file, self.tz_local_fn)
Example #6
0
 def _write_hostname(self, hostname, out_fn):
     if self._dist_uses_systemd():
         util.subp(['hostnamectl', 'set-hostname', str(hostname)])
     else:
         host_cfg = {
             'HOSTNAME': hostname,
         }
         rhel_util.update_sysconfig_file(out_fn, host_cfg)
Example #7
0
 def set_timezone(self, tz):
     tz_file = self._find_tz_file(tz)
     # Adjust the sysconfig clock zone setting
     clock_cfg = {
         'TIMEZONE': str(tz),
     }
     rhel_util.update_sysconfig_file(self.clock_conf_fn, clock_cfg)
     # This ensures that the correct tz will be used for the system
     util.copy(tz_file, self.tz_local_fn)
Example #8
0
    def _write_network(self, settings):
        # TODO(harlowja) fix this... since this is the ubuntu format
        entries = net_util.translate_network(settings)
        LOG.debug("Translated ubuntu style network settings %s into %s",
                  settings, entries)
        # Match Debian/Ubunto distro functionality of clean slating
        # the network interface configuration.
        # Remove all existing ifcfg-eth* files.  This cleans up files that
        # are left around if you capture an image from a VM with 5 NICs
        # and deploy it with 1 NIC.
        rhel_util.remove_ifcfg_files(self.network_script_dir)
        rhel_util.remove_resolve_conf_file(self.resolve_conf_fn)

        # Make the intermediate format as the rhel format...
        nameservers = []
        searchservers = []
        dev_names = entries.keys()
        for (dev, info) in entries.iteritems():
            net_fn = self.network_script_tpl % (dev)
            net_cfg = {
                'DEVICE': dev,
                'NETMASK': info.get('netmask'),
                'IPADDR': info.get('address'),
                'BOOTPROTO': info.get('bootproto'),
                'BROADCAST': info.get('broadcast'),
                'MACADDR': info.get('hwaddress'),
                'ONBOOT': _make_sysconfig_bool(info.get('auto')),
            }
            if 'mtu' in info:
                net_cfg['MTU'] = info.get('mtu')
            # Remove the existing cfg file so the network configuration
            # is a replacement versus an update to match debian distro
            # functionality.
            if dev != 'lo':
                net_cfg['USERCONTROL'] = 'no'
                net_cfg['NM_CONTROLLED'] = 'no'
            rhel_util.update_sysconfig_file(net_fn, net_cfg)

            if dev == 'eth0':
                default_gateway = info.get('gateway') or ''
            if 'dns-nameservers' in info:
                nameservers.extend(info['dns-nameservers'])
            if 'dns-search' in info:
                searchservers.extend(info['dns-search'])
        if nameservers or searchservers:
            rhel_util.update_resolve_conf_file(self.resolve_conf_fn,
                                               nameservers, searchservers)
        if dev_names:
            net_cfg = {
                'NETWORKING': _make_sysconfig_bool(True),
                'GATEWAY': default_gateway,
            }
            rhel_util.update_sysconfig_file(self.network_conf_fn,
                                            net_cfg,
                                            allow_empty=True)
        return dev_names
Example #9
0
 def apply_locale(self, locale, out_fn=None):
     if self.uses_systemd():
         if not out_fn:
             out_fn = self.systemd_locale_conf_fn
         locale_cfg = {'LANG': locale}
     else:
         if not out_fn:
             out_fn = self.locale_conf_fn
         locale_cfg = {'RC_LANG': locale}
     rhutil.update_sysconfig_file(out_fn, locale_cfg)
Example #10
0
 def apply_locale(self, locale, out_fn=None):
     if self.uses_systemd():
         if not out_fn:
             out_fn = self.systemd_locale_conf_fn
         locale_cfg = {'LANG': locale}
     else:
         if not out_fn:
             out_fn = self.locale_conf_fn
         locale_cfg = {'RC_LANG': locale}
     rhutil.update_sysconfig_file(out_fn, locale_cfg)
Example #11
0
    def _write_network(self, settings):
        # TODO(harlowja) fix this... since this is the ubuntu format
        entries = net_util.translate_network(settings)
        LOG.debug("Translated ubuntu style network settings %s into %s",
                  settings, entries)
        # Match Debian/Ubunto distro functionality of clean slating
        # the network interface configuration.
        # Remove all existing ifcfg-eth* files.  This cleans up files that
        # are left around if you capture an image from a VM with 5 NICs
        # and deploy it with 1 NIC.
        rhel_util.remove_ifcfg_files(self.network_script_dir)
        rhel_util.remove_resolve_conf_file(self.resolve_conf_fn)

        # Make the intermediate format as the rhel format...
        nameservers = []
        searchservers = []
        dev_names = entries.keys()
        for (dev, info) in entries.iteritems():
            net_fn = self.network_script_tpl % (dev)
            net_cfg = {
                'DEVICE': dev,
                'NETMASK': info.get('netmask'),
                'IPADDR': info.get('address'),
                'BOOTPROTO': info.get('bootproto'),
                'BROADCAST': info.get('broadcast'),
                'MACADDR': info.get('hwaddress'),
                'ONBOOT': _make_sysconfig_bool(info.get('auto')),
            }
            if 'mtu' in info:
                net_cfg['MTU'] = info.get('mtu')
            # Remove the existing cfg file so the network configuration
            # is a replacement versus an update to match debian distro
            # functionality.
            if dev != 'lo':
                net_cfg['USERCONTROL'] = 'no'
                net_cfg['NM_CONTROLLED'] = 'no'
            rhel_util.update_sysconfig_file(net_fn, net_cfg)

            if dev == 'eth0':
                default_gateway = info.get('gateway') or ''
            if 'dns-nameservers' in info:
                nameservers.extend(info['dns-nameservers'])
            if 'dns-search' in info:
                searchservers.extend(info['dns-search'])
        if nameservers or searchservers:
            rhel_util.update_resolve_conf_file(self.resolve_conf_fn,
                                               nameservers, searchservers)
        if dev_names:
            net_cfg = {
                'NETWORKING': _make_sysconfig_bool(True),
                'GATEWAY': default_gateway,
            }
            rhel_util.update_sysconfig_file(self.network_conf_fn, net_cfg,
                                            allow_empty=True)
        return dev_names
Example #12
0
def handle(name, cfg, cloud, log, _args):
    # If there isn't a salt key in the configuration don't do anything
    if "salt_minion" not in cfg:
        log.debug(
            "Skipping module named %s, no 'salt_minion' key in configuration",
            name,
        )
        return

    s_cfg = cfg["salt_minion"]
    const = SaltConstants(cfg=s_cfg)

    # Start by installing the salt package ...
    cloud.distro.install_packages(const.pkg_name)

    # Ensure we can configure files at the right dir
    util.ensure_dir(const.conf_dir)

    # ... and then update the salt configuration
    if "conf" in s_cfg:
        # Add all sections from the conf object to minion config file
        minion_config = os.path.join(const.conf_dir, "minion")
        minion_data = safeyaml.dumps(s_cfg.get("conf"))
        util.write_file(minion_config, minion_data)

    if "grains" in s_cfg:
        # add grains to /etc/salt/grains
        grains_config = os.path.join(const.conf_dir, "grains")
        grains_data = safeyaml.dumps(s_cfg.get("grains"))
        util.write_file(grains_config, grains_data)

    # ... copy the key pair if specified
    if "public_key" in s_cfg and "private_key" in s_cfg:
        pki_dir_default = os.path.join(const.conf_dir, "pki/minion")
        if not os.path.isdir(pki_dir_default):
            pki_dir_default = os.path.join(const.conf_dir, "pki")

        pki_dir = s_cfg.get("pki_dir", pki_dir_default)
        with util.umask(0o77):
            util.ensure_dir(pki_dir)
            pub_name = os.path.join(pki_dir, "minion.pub")
            pem_name = os.path.join(pki_dir, "minion.pem")
            util.write_file(pub_name, s_cfg["public_key"])
            util.write_file(pem_name, s_cfg["private_key"])

    # we need to have the salt minion service enabled in rc in order to be
    # able to start the service. this does only apply on FreeBSD servers.
    if cloud.distro.osfamily == "freebsd":
        rhel_util.update_sysconfig_file(
            "/etc/rc.conf", {"salt_minion_enable": "YES"}
        )

    # restart salt-minion. 'service' will start even if not started. if it
    # was started, it needs to be restarted for config change.
    subp.subp(["service", const.srv_name, "restart"], capture=False)
Example #13
0
 def _write_hostname(self, hostname, filename):
     # systemd will never update previous-hostname for us, so
     # we need to do it ourselves
     if self.uses_systemd() and filename.endswith("/previous-hostname"):
         util.write_file(filename, hostname)
     elif self.uses_systemd():
         subp.subp(["hostnamectl", "set-hostname", str(hostname)])
     else:
         host_cfg = {
             "HOSTNAME": hostname,
         }
         rhel_util.update_sysconfig_file(filename, host_cfg)
Example #14
0
 def apply_locale(self, locale, out_fn=None):
     if self.uses_systemd():
         if not out_fn:
             out_fn = self.systemd_locale_conf_fn
         out_fn = self.systemd_locale_conf_fn
     else:
         if not out_fn:
             out_fn = self.locale_conf_fn
     locale_cfg = {
         "LANG": locale,
     }
     rhel_util.update_sysconfig_file(out_fn, locale_cfg)
Example #15
0
 def apply_locale(self, locale, out_fn=None):
     if self._dist_uses_systemd():
         if not out_fn:
             out_fn = self.systemd_locale_conf_fn
         out_fn = self.systemd_locale_conf_fn
     else:
         if not out_fn:
             out_fn = self.locale_conf_fn
     locale_cfg = {
         'LANG': locale,
     }
     rhel_util.update_sysconfig_file(out_fn, locale_cfg)
Example #16
0
 def _write_hostname(self, hostname, out_fn):
     # systemd will never update previous-hostname for us, so
     # we need to do it ourselves
     if self.uses_systemd() and out_fn.endswith('/previous-hostname'):
         util.write_file(out_fn, hostname)
     elif self.uses_systemd():
         util.subp(['hostnamectl', 'set-hostname', str(hostname)])
     else:
         host_cfg = {
             'HOSTNAME': hostname,
         }
         rhel_util.update_sysconfig_file(out_fn, host_cfg)
Example #17
0
 def _write_hostname(self, hostname, out_fn):
     # systemd will never update previous-hostname for us, so
     # we need to do it ourselves
     if self.uses_systemd() and out_fn.endswith('/previous-hostname'):
         util.write_file(out_fn, hostname)
     elif self.uses_systemd():
         util.subp(['hostnamectl', 'set-hostname', str(hostname)])
     else:
         host_cfg = {
             'HOSTNAME': hostname,
         }
         rhel_util.update_sysconfig_file(out_fn, host_cfg)
Example #18
0
 def _write_network(self, settings):
     # TODO(harlowja) fix this... since this is the ubuntu format
     entries = net_util.translate_network(settings)
     LOG.debug("Translated ubuntu style network settings %s into %s",
               settings, entries)
     # Make the intermediate format as the rhel format...
     nameservers = []
     searchservers = []
     dev_names = entries.keys()
     use_ipv6 = False
     for (dev, info) in entries.items():
         net_fn = self.network_script_tpl % (dev)
         net_cfg = {
             'DEVICE': dev,
             'NETMASK': info.get('netmask'),
             'IPADDR': info.get('address'),
             'BOOTPROTO': info.get('bootproto'),
             'GATEWAY': info.get('gateway'),
             'BROADCAST': info.get('broadcast'),
             'MACADDR': info.get('hwaddress'),
             'ONBOOT': _make_sysconfig_bool(info.get('auto')),
         }
         if info.get('inet6'):
             use_ipv6 = True
             net_cfg.update({
                 'IPV6INIT':
                 _make_sysconfig_bool(True),
                 'IPV6ADDR':
                 info.get('ipv6').get('address'),
                 'IPV6_DEFAULTGW':
                 info.get('ipv6').get('gateway'),
             })
         rhel_util.update_sysconfig_file(net_fn, net_cfg)
         if 'dns-nameservers' in info:
             nameservers.extend(info['dns-nameservers'])
         if 'dns-search' in info:
             searchservers.extend(info['dns-search'])
     if nameservers or searchservers:
         rhel_util.update_resolve_conf_file(self.resolve_conf_fn,
                                            nameservers, searchservers)
     if dev_names:
         net_cfg = {
             'NETWORKING': _make_sysconfig_bool(True),
         }
         # If IPv6 interface present, enable ipv6 networking
         if use_ipv6:
             net_cfg['NETWORKING_IPV6'] = _make_sysconfig_bool(True)
             net_cfg['IPV6_AUTOCONF'] = _make_sysconfig_bool(False)
         rhel_util.update_sysconfig_file(self.network_conf_fn, net_cfg)
     return dev_names
Example #19
0
 def set_timezone(self, tz):
     tz_file = self._find_tz_file(tz)
     if self.uses_systemd():
         # Currently, timedatectl complains if invoked during startup
         # so for compatibility, create the link manually.
         util.del_file(self.tz_local_fn)
         util.sym_link(tz_file, self.tz_local_fn)
     else:
         # Adjust the sysconfig clock zone setting
         clock_cfg = {
             'ZONE': str(tz),
         }
         rhel_util.update_sysconfig_file(self.clock_conf_fn, clock_cfg)
         # This ensures that the correct tz will be used for the system
         util.copy(tz_file, self.tz_local_fn)
Example #20
0
 def set_timezone(self, tz):
     tz_file = self._find_tz_file(tz)
     if self._dist_uses_systemd():
         # Currently, timedatectl complains if invoked during startup
         # so for compatibility, create the link manually.
         util.del_file(self.tz_local_fn)
         util.sym_link(tz_file, self.tz_local_fn)
     else:
         # Adjust the sysconfig clock zone setting
         clock_cfg = {
             'ZONE': str(tz),
         }
         rhel_util.update_sysconfig_file(self.clock_conf_fn, clock_cfg)
         # This ensures that the correct tz will be used for the system
         util.copy(tz_file, self.tz_local_fn)
Example #21
0
    def apply_locale(self, locale, out_fn=None):
        # This has a dependancy on glibc-i18n, user need to manually install it
        # and enable the option in cloud.cfg
        if not out_fn:
            out_fn = self.systemd_locale_conf_fn

        locale_cfg = {
            "LANG": locale,
        }

        rhutil.update_sysconfig_file(out_fn, locale_cfg)

        # rhutil will modify /etc/locale.conf
        # For locale change to take effect, reboot is needed or we can restart
        # systemd-localed. This is equivalent of localectl
        cmd = ["systemctl", "restart", "systemd-localed"]
        self.exec_cmd(cmd)
Example #22
0
 def _write_network(self, settings):
     # Convert debian settings to ifcfg format
     entries = net_util.translate_network(settings)
     LOG.debug("Translated ubuntu style network settings %s into %s",
               settings, entries)
     # Make the intermediate format as the suse format...
     nameservers = []
     searchservers = []
     dev_names = entries.keys()
     for (dev, info) in entries.items():
         net_fn = self.network_script_tpl % (dev)
         route_fn = self.route_conf_tpl % (dev)
         mode = None
         if info.get('auto', None):
             mode = 'auto'
         else:
             mode = 'manual'
         bootproto = info.get('bootproto', None)
         gateway = info.get('gateway', None)
         net_cfg = {
             'BOOTPROTO': bootproto,
             'BROADCAST': info.get('broadcast'),
             'GATEWAY': gateway,
             'IPADDR': info.get('address'),
             'LLADDR': info.get('hwaddress'),
             'NETMASK': info.get('netmask'),
             'STARTMODE': mode,
             'USERCONTROL': 'no'
         }
         if dev != 'lo':
             net_cfg['ETHTOOL_OPTIONS'] = ''
         else:
             net_cfg['FIREWALL'] = 'no'
         rhutil.update_sysconfig_file(net_fn, net_cfg, True)
         if gateway and bootproto == 'static':
             default_route = 'default    %s' % gateway
             util.write_file(route_fn, default_route, 0o644)
         if 'dns-nameservers' in info:
             nameservers.extend(info['dns-nameservers'])
         if 'dns-search' in info:
             searchservers.extend(info['dns-search'])
     if nameservers or searchservers:
         rhutil.update_resolve_conf_file(self.resolve_conf_fn,
                                         nameservers, searchservers)
     return dev_names
Example #23
0
 def _write_network(self, settings):
     # Convert debian settings to ifcfg format
     entries = rhel_util.translate_network(settings)
     LOG.debug("Translated ubuntu style network settings %s into %s",
               settings, entries)
     # Make the intermediate format as the suse format...
     nameservers = []
     searchservers = []
     dev_names = entries.keys()
     for (dev, info) in entries.iteritems():
         net_fn = self.network_script_tpl % (dev)
         mode = info.get('auto')
         if mode and mode.lower() == 'true':
             mode = 'auto'
         else:
             mode = 'manual'
         net_cfg = {
             'BOOTPROTO': info.get('bootproto'),
             'BROADCAST': info.get('broadcast'),
             'GATEWAY': info.get('gateway'),
             'IPADDR': info.get('address'),
             'LLADDR': info.get('hwaddress'),
             'NETMASK': info.get('netmask'),
             'STARTMODE': mode,
             'USERCONTROL': 'no'
         }
         if dev != 'lo':
             net_cfg['ETHERDEVICE'] = dev
             net_cfg['ETHTOOL_OPTIONS'] = ''
         else:
             net_cfg['FIREWALL'] = 'no'
         rhel_util.update_sysconfig_file(net_fn, net_cfg, True)
         if 'dns-nameservers' in info:
             nameservers.extend(info['dns-nameservers'])
         if 'dns-search' in info:
             searchservers.extend(info['dns-search'])
     if nameservers or searchservers:
         rhel_util.update_resolve_conf_file(self.resolve_conf_fn,
                                            nameservers, searchservers)
     return dev_names
Example #24
0
 def _write_network(self, settings):
     # Convert debian settings to ifcfg format
     entries = net_util.translate_network(settings)
     LOG.debug("Translated ubuntu style network settings %s into %s", settings, entries)
     # Make the intermediate format as the suse format...
     nameservers = []
     searchservers = []
     dev_names = entries.keys()
     for (dev, info) in entries.items():
         net_fn = self.network_script_tpl % (dev)
         mode = info.get("auto")
         if mode and mode.lower() == "true":
             mode = "auto"
         else:
             mode = "manual"
         net_cfg = {
             "BOOTPROTO": info.get("bootproto"),
             "BROADCAST": info.get("broadcast"),
             "GATEWAY": info.get("gateway"),
             "IPADDR": info.get("address"),
             "LLADDR": info.get("hwaddress"),
             "NETMASK": info.get("netmask"),
             "STARTMODE": mode,
             "USERCONTROL": "no",
         }
         if dev != "lo":
             net_cfg["ETHERDEVICE"] = dev
             net_cfg["ETHTOOL_OPTIONS"] = ""
         else:
             net_cfg["FIREWALL"] = "no"
         rhel_util.update_sysconfig_file(net_fn, net_cfg, True)
         if "dns-nameservers" in info:
             nameservers.extend(info["dns-nameservers"])
         if "dns-search" in info:
             searchservers.extend(info["dns-search"])
     if nameservers or searchservers:
         rhel_util.update_resolve_conf_file(self.resolve_conf_fn, nameservers, searchservers)
     return dev_names
Example #25
0
    def apply_locale(self, locale, out_fn=None):
        if self.uses_systemd():
            if not out_fn:
                out_fn = self.systemd_locale_conf_fn
        else:
            if not out_fn:
                out_fn = self.locale_conf_fn
        locale_cfg = {
            'LANG': locale,
        }
        rhutil.update_sysconfig_file(out_fn, locale_cfg)

        # rhutil will modify /etc/locale.conf
        # For locale change to take effect, reboot is needed or we can restart systemd-localed
        # This is equivalent of localectl
        cmd = ['systemctl', 'restart', 'systemd-localed']
        LOG.debug("Attempting to restart localed using command %s", cmd)
        try:
            (_out, err) = util.subp(cmd)
            if len(err):
                LOG.warn("Running %s resulted in stderr output: %s", cmd, err)
        except util.ProcessExecutionError:
            util.logexc(LOG, "Restart of localed using command %s failed", cmd)
Example #26
0
 def _write_hostname(self, hostname, filename):
     rhel_util.update_sysconfig_file(filename, {'hostname': hostname})
Example #27
0
    def _write_network(self, settings):
        # Convert debian settings to ifcfg format
        entries = net_util.translate_network(settings)
        LOG.debug("Translated ubuntu style network settings %s into %s",
                  settings, entries)

        # Match Debian/Ubunto distro functionality of clean slating
        # the network interface configuration.
        # Remove all existing ifcfg-eth* files.  This cleans up files that
        # are left around if you capture an image from a VM with 5 NICs
        # and deploy it with 1 NIC.
        rhel_util.remove_ifcfg_files(self.network_script_dir)
        rhel_util.remove_resolve_conf_file(self.resolve_conf_fn)
        util.del_file(self.routes_fn)

        # Make the intermediate format as the suse format...
        nameservers = []
        searchservers = []
        dev_names = entries.keys()
        mac_addrs = []
        for (dev, info) in entries.iteritems():
            mac_addrs.append(info.get('hwaddress'))
            net_fn = self.network_script_tpl % (dev)
            mode = info.get('auto')
            if mode:
                mode = 'auto'
            else:
                mode = 'manual'
            net_cfg = {}
            net_cfg['BOOTPROTO'] = info.get('bootproto')
            net_cfg['BROADCAST'] = info.get('broadcast')
            net_cfg['LLADDR'] = info.get('hwaddress')
            net_cfg['STARTMODE'] = mode
            if info['ipv6']:
                prefix = info.get('netmask')
                ipv6addr = info.get('address')
                net_cfg['IPADDR_0'] = ipv6addr
                net_cfg['PREFIXLEN_0'] = prefix
                net_cfg['LABEL_0'] = '0'
            if info['ipv4']:
                net_cfg['NETMASK'] = info.get('netmask')
                net_cfg['IPADDR'] = info.get('address')
            if dev != 'lo':
                # net_cfg['ETHERDEVICE'] = dev
                net_cfg['ETHTOOL_OPTIONS'] = ''
                net_cfg['USERCONTROL'] = 'no'
                net_cfg['NM_CONTROLLED'] = 'no'
                net_cfg['BRIDGE'] = 'yes'
            else:
                net_cfg['FIREWALL'] = 'no'
            if dev == 'eth0' and info.get('gateway'):
                self._write_default_route(self.routes_fn, info.get('gateway'))
            if 'mtu' in info:
                net_cfg['MTU'] = info.get('mtu')

            # Remove the existing cfg file so the network configuration
            # is a replacement versus an update to match debian distro
            # functionality.
            if dev != 'lo':
                util.del_file(net_fn)
            rhel_util.update_sysconfig_file(net_fn, net_cfg, True)
            if 'dns-nameservers' in info:
                nameservers.extend(info['dns-nameservers'])
            if 'dns-search' in info:
                searchservers.extend(info['dns-search'])
        if nameservers or searchservers:
            rhel_util.update_resolve_conf_file(self.resolve_conf_fn,
                                               nameservers, searchservers)
        return dev_names, mac_addrs
Example #28
0
 def _update_rc_conf(self, settings, target=None):
     fn = util.target_path(target, self.rc_conf_fn)
     rhel_util.update_sysconfig_file(fn, settings)
Example #29
0
    def _write_network(self, settings):
        # Convert debian settings to ifcfg format
        entries = net_util.translate_network(settings)
        LOG.debug("Translated ubuntu style network settings %s into %s",
                  settings, entries)

        # Match Debian/Ubunto distro functionality of clean slating
        # the network interface configuration.
        # Remove all existing ifcfg-eth* files.  This cleans up files that
        # are left around if you capture an image from a VM with 5 NICs
        # and deploy it with 1 NIC.
        rhel_util.remove_ifcfg_files(self.network_script_dir)
        rhel_util.remove_resolve_conf_file(self.resolve_conf_fn)
        util.del_file(self.routes_fn)

        # Make the intermediate format as the suse format...
        nameservers = []
        searchservers = []
        dev_names = entries.keys()
        mac_addrs = []
        for (dev, info) in entries.iteritems():
            mac_addrs.append(info.get('hwaddress'))
            net_fn = self.network_script_tpl % (dev)
            mode = info.get('auto')
            if mode:
                mode = 'auto'
            else:
                mode = 'manual'
            net_cfg = {}
            net_cfg['BOOTPROTO'] = info.get('bootproto')
            net_cfg['BROADCAST'] = info.get('broadcast')
            net_cfg['LLADDR'] = info.get('hwaddress')
            net_cfg['STARTMODE'] = mode
            if info['ipv6']:
                prefix = info.get('netmask')
                ipv6addr = info.get('address')
                net_cfg['IPADDR_0'] = ipv6addr
                net_cfg['PREFIXLEN_0'] = prefix
                net_cfg['LABEL_0'] = '0'
            if info['ipv4']:
                net_cfg['NETMASK'] = info.get('netmask')
                net_cfg['IPADDR'] = info.get('address')
            if dev != 'lo':
                # net_cfg['ETHERDEVICE'] = dev
                net_cfg['ETHTOOL_OPTIONS'] = ''
                net_cfg['USERCONTROL'] = 'no'
                net_cfg['NM_CONTROLLED'] = 'no'
                net_cfg['BRIDGE'] = 'yes'
            else:
                net_cfg['FIREWALL'] = 'no'
            if dev == 'eth0' and info.get('gateway'):
                self._write_default_route(self.routes_fn, info.get('gateway'))
            if 'mtu' in info:
                net_cfg['MTU'] = info.get('mtu')

            # Remove the existing cfg file so the network configuration
            # is a replacement versus an update to match debian distro
            # functionality.
            if dev != 'lo':
                util.del_file(net_fn)
            rhel_util.update_sysconfig_file(net_fn, net_cfg, True)
            if 'dns-nameservers' in info:
                nameservers.extend(info['dns-nameservers'])
            if 'dns-search' in info:
                searchservers.extend(info['dns-search'])
        if nameservers or searchservers:
            rhel_util.update_resolve_conf_file(self.resolve_conf_fn,
                                               nameservers, searchservers)
        return dev_names, mac_addrs