コード例 #1
0
    def _createConfFile(self, conf, name, ipv4, ipv6, mtu=None, **kwargs):
        """ Create ifcfg-* file with proper fields per device """
        cfg = 'DEVICE=%s\n' % pipes.quote(name)
        cfg += conf
        if ipv4.address:
            cfg += 'IPADDR=%s\n' % pipes.quote(ipv4.address)
            cfg += 'NETMASK=%s\n' % pipes.quote(ipv4.netmask)
            if ipv4.gateway:
                cfg += 'GATEWAY=%s\n' % pipes.quote(ipv4.gateway)
            # According to manual the BOOTPROTO=none should be set
            # for static IP
            cfg += 'BOOTPROTO=none\n'
        elif ipv4.bootproto:
            cfg += 'BOOTPROTO=%s\n' % pipes.quote(ipv4.bootproto)
            if (ipv4.bootproto == 'dhcp' and
                    os.path.exists(os.path.join(NET_PATH, name))):
                # Ask dhclient to stop any dhclient running for the device
                dhclient.kill_dhclient(name)
        if mtu:
            cfg += 'MTU=%d\n' % mtu
        if ipv4.defaultRoute is not None:
            cfg += 'DEFROUTE=%s\n' % _to_ifcfg_bool(ipv4.defaultRoute)
        cfg += 'NM_CONTROLLED=no\n'
        enable_ipv6 = ipv6.address or ipv6.ipv6autoconf or ipv6.dhcpv6
        cfg += 'IPV6INIT=%s\n' % _to_ifcfg_bool(enable_ipv6)
        if enable_ipv6:
            if ipv6.address is not None:
                cfg += 'IPV6ADDR=%s\n' % pipes.quote(ipv6.address)
                if ipv6.gateway is not None:
                    cfg += 'IPV6_DEFAULTGW=%s\n' % pipes.quote(ipv6.gateway)
            elif ipv6.dhcpv6:
                cfg += 'DHCPV6C=yes\n'
            cfg += 'IPV6_AUTOCONF=%s\n' % _to_ifcfg_bool(ipv6.ipv6autoconf)
        BLACKLIST = ['TYPE', 'NAME', 'DEVICE', 'VLAN', 'bondingOptions',
                     'force', 'blockingdhcp', 'custom',
                     'connectivityCheck', 'connectivityTimeout',
                     'implicitBonding', 'delay', 'onboot', 'forward_delay',
                     'DELAY', 'ONBOOT']
        for k in set(kwargs.keys()).difference(set(BLACKLIST)):
            if re.match('^[a-zA-Z_]\w*$', k):
                cfg += '%s=%s\n' % (k.upper(), pipes.quote(kwargs[k]))
            else:
                logging.debug('ignoring variable %s', k)

        ifcfg_file = NET_CONF_PREF + name
        hook_dict = {'ifcfg_file': ifcfg_file,
                     'config': cfg}
        hook_return = hooks.before_ifcfg_write(hook_dict)
        cfg = hook_return['config']
        self.writeConfFile(ifcfg_file, cfg)
        hooks.after_ifcfg_write(hook_return)
コード例 #2
0
    def _createConfFile(self, conf, name, ipv4, ipv6, mtu, nameservers,
                        **kwargs):
        """ Create ifcfg-* file with proper fields per device """
        cfg = 'DEVICE=%s\n' % pipes.quote(name)
        cfg += conf
        if ipv4.address:
            cfg += 'IPADDR=%s\n' % pipes.quote(ipv4.address)
            cfg += 'NETMASK=%s\n' % pipes.quote(ipv4.netmask)
            if ipv4.defaultRoute and ipv4.gateway:
                cfg += 'GATEWAY=%s\n' % pipes.quote(ipv4.gateway)
            # According to manual the BOOTPROTO=none should be set
            # for static IP
            cfg += 'BOOTPROTO=none\n'
        elif ipv4.bootproto:
            cfg += 'BOOTPROTO=%s\n' % pipes.quote(ipv4.bootproto)

        # FIXME: Move this out, it is unrelated to a conf file creation.
        if os.path.exists(os.path.join(NET_PATH, name)):
            # Ask dhclient to stop any dhclient running for the device
            dhclient.kill(name)
            address.flush(name)

        if mtu:
            cfg += 'MTU=%d\n' % mtu
        is_default_route = ipv4.defaultRoute and (ipv4.gateway or
                                                  ipv4.bootproto == 'dhcp')
        cfg += 'DEFROUTE=%s\n' % _to_ifcfg_bool(is_default_route)
        cfg += 'NM_CONTROLLED=no\n'
        enable_ipv6 = ipv6.address or ipv6.ipv6autoconf or ipv6.dhcpv6
        cfg += 'IPV6INIT=%s\n' % _to_ifcfg_bool(enable_ipv6)
        if enable_ipv6:
            if ipv6.address is not None:
                cfg += 'IPV6ADDR=%s\n' % pipes.quote(ipv6.address)
                if ipv6.gateway is not None:
                    cfg += 'IPV6_DEFAULTGW=%s\n' % pipes.quote(ipv6.gateway)
            elif ipv6.dhcpv6:
                cfg += 'DHCPV6C=yes\n'
            cfg += 'IPV6_AUTOCONF=%s\n' % _to_ifcfg_bool(ipv6.ipv6autoconf)
        if nameservers:
            for i, nameserver in enumerate(nameservers[0:2], 1):
                cfg += 'DNS{}={}\n'.format(i, nameserver)

        ifcfg_file = NET_CONF_PREF + name
        hook_dict = {'ifcfg_file': ifcfg_file,
                     'config': cfg}
        hook_return = hooks.before_ifcfg_write(hook_dict)
        cfg = hook_return['config']
        self.writeConfFile(ifcfg_file, cfg)
        hooks.after_ifcfg_write(hook_return)
コード例 #3
0
ファイル: ifcfg.py プロジェクト: EdDev/vdsm
    def _createConfFile(self, conf, name, ipv4, ipv6, mtu, nameservers,
                        **kwargs):
        """ Create ifcfg-* file with proper fields per device """
        cfg = 'DEVICE=%s\n' % pipes.quote(name)
        cfg += conf
        if ipv4.address:
            cfg += 'IPADDR=%s\n' % pipes.quote(ipv4.address)
            cfg += 'NETMASK=%s\n' % pipes.quote(ipv4.netmask)
            if ipv4.defaultRoute and ipv4.gateway:
                cfg += 'GATEWAY=%s\n' % pipes.quote(ipv4.gateway)
            # According to manual the BOOTPROTO=none should be set
            # for static IP
            cfg += 'BOOTPROTO=none\n'
        elif ipv4.bootproto:
            cfg += 'BOOTPROTO=%s\n' % pipes.quote(ipv4.bootproto)

        # FIXME: Move this out, it is unrelated to a conf file creation.
        if os.path.exists(os.path.join(NET_PATH, name)):
            # Ask dhclient to stop any dhclient running for the device
            dhclient.kill(name)
            address.flush(name)

        if mtu:
            cfg += 'MTU=%d\n' % mtu
        is_default_route = ipv4.defaultRoute and (ipv4.gateway or
                                                  ipv4.bootproto == 'dhcp')
        cfg += 'DEFROUTE=%s\n' % _to_ifcfg_bool(is_default_route)
        cfg += 'NM_CONTROLLED=no\n'
        enable_ipv6 = ipv6.address or ipv6.ipv6autoconf or ipv6.dhcpv6
        cfg += 'IPV6INIT=%s\n' % _to_ifcfg_bool(enable_ipv6)
        if enable_ipv6:
            if ipv6.address is not None:
                cfg += 'IPV6ADDR=%s\n' % pipes.quote(ipv6.address)
                if ipv6.gateway is not None:
                    cfg += 'IPV6_DEFAULTGW=%s\n' % pipes.quote(ipv6.gateway)
            elif ipv6.dhcpv6:
                cfg += 'DHCPV6C=yes\n'
            cfg += 'IPV6_AUTOCONF=%s\n' % _to_ifcfg_bool(ipv6.ipv6autoconf)
        if nameservers:
            for i, nameserver in enumerate(nameservers[0:2], 1):
                cfg += 'DNS{}={}\n'.format(i, nameserver)

        ifcfg_file = NET_CONF_PREF + name
        hook_dict = {'ifcfg_file': ifcfg_file,
                     'config': cfg}
        hook_return = hooks.before_ifcfg_write(hook_dict)
        cfg = hook_return['config']
        self.writeConfFile(ifcfg_file, cfg)
        hooks.after_ifcfg_write(hook_return)
コード例 #4
0
ファイル: ifcfg.py プロジェクト: mykaul/vdsm
    def _createConfFile(self, conf, name, ipv4, ipv6, mtu=None, **kwargs):
        """ Create ifcfg-* file with proper fields per device """
        cfg = 'DEVICE=%s\n' % pipes.quote(name)
        cfg += conf
        if ipv4.address:
            cfg += 'IPADDR=%s\n' % pipes.quote(ipv4.address)
            cfg += 'NETMASK=%s\n' % pipes.quote(ipv4.netmask)
            if ipv4.gateway:
                cfg += 'GATEWAY=%s\n' % pipes.quote(ipv4.gateway)
            # According to manual the BOOTPROTO=none should be set
            # for static IP
            cfg += 'BOOTPROTO=none\n'
        elif ipv4.bootproto:
            cfg += 'BOOTPROTO=%s\n' % pipes.quote(ipv4.bootproto)
            if (ipv4.bootproto == 'dhcp' and
                    os.path.exists(os.path.join(NET_PATH, name))):
                # Ask dhclient to stop any dhclient running for the device
                dhclient.kill_dhclient(name)
        if mtu:
            cfg += 'MTU=%d\n' % mtu
        if ipv4.defaultRoute is not None:
            cfg += 'DEFROUTE=%s\n' % _to_ifcfg_bool(ipv4.defaultRoute)
        cfg += 'NM_CONTROLLED=no\n'
        enable_ipv6 = ipv6.address or ipv6.ipv6autoconf or ipv6.dhcpv6
        cfg += 'IPV6INIT=%s\n' % _to_ifcfg_bool(enable_ipv6)
        if enable_ipv6:
            if ipv6.address is not None:
                cfg += 'IPV6ADDR=%s\n' % pipes.quote(ipv6.address)
                if ipv6.gateway is not None:
                    cfg += 'IPV6_DEFAULTGW=%s\n' % pipes.quote(ipv6.gateway)
            elif ipv6.dhcpv6:
                cfg += 'DHCPV6C=yes\n'
            cfg += 'IPV6_AUTOCONF=%s\n' % _to_ifcfg_bool(ipv6.ipv6autoconf)

        ifcfg_file = NET_CONF_PREF + name
        hook_dict = {'ifcfg_file': ifcfg_file,
                     'config': cfg}
        hook_return = hooks.before_ifcfg_write(hook_dict)
        cfg = hook_return['config']
        self.writeConfFile(ifcfg_file, cfg)
        hooks.after_ifcfg_write(hook_return)
コード例 #5
0
ファイル: ifcfg.py プロジェクト: fancyKai/vdsm
    def _createConfFile(self, conf, name, ipv4, ipv6, mtu=None, **kwargs):
        """ Create ifcfg-* file with proper fields per device """
        cfg = "DEVICE=%s\n" % pipes.quote(name)
        cfg += conf
        if ipv4.address:
            cfg += "IPADDR=%s\n" % pipes.quote(ipv4.address)
            cfg += "NETMASK=%s\n" % pipes.quote(ipv4.netmask)
            if ipv4.gateway:
                cfg += "GATEWAY=%s\n" % pipes.quote(ipv4.gateway)
            # According to manual the BOOTPROTO=none should be set
            # for static IP
            cfg += "BOOTPROTO=none\n"
        elif ipv4.bootproto:
            cfg += "BOOTPROTO=%s\n" % pipes.quote(ipv4.bootproto)
            if ipv4.bootproto == "dhcp" and os.path.exists(os.path.join(NET_PATH, name)):
                # Ask dhclient to stop any dhclient running for the device
                dhclient.kill_dhclient(name)
        if mtu:
            cfg += "MTU=%d\n" % mtu
        if ipv4.defaultRoute is not None:
            cfg += "DEFROUTE=%s\n" % _to_ifcfg_bool(ipv4.defaultRoute)
        cfg += "NM_CONTROLLED=no\n"
        enable_ipv6 = ipv6.address or ipv6.ipv6autoconf or ipv6.dhcpv6
        cfg += "IPV6INIT=%s\n" % _to_ifcfg_bool(enable_ipv6)
        if enable_ipv6:
            if ipv6.address is not None:
                cfg += "IPV6ADDR=%s\n" % pipes.quote(ipv6.address)
                if ipv6.gateway is not None:
                    cfg += "IPV6_DEFAULTGW=%s\n" % pipes.quote(ipv6.gateway)
            elif ipv6.dhcpv6:
                cfg += "DHCPV6C=yes\n"
            cfg += "IPV6_AUTOCONF=%s\n" % _to_ifcfg_bool(ipv6.ipv6autoconf)
        BLACKLIST = [
            "TYPE",
            "NAME",
            "DEVICE",
            "VLAN",
            "bondingOptions",
            "force",
            "blockingdhcp",
            "custom",
            "connectivityCheck",
            "connectivityTimeout",
            "implicitBonding",
            "delay",
            "onboot",
            "forward_delay",
            "DELAY",
            "ONBOOT",
        ]
        for k in set(kwargs.keys()).difference(set(BLACKLIST)):
            if re.match("^[a-zA-Z_]\w*$", k):
                cfg += "%s=%s\n" % (k.upper(), pipes.quote(kwargs[k]))
            else:
                logging.debug("ignoring variable %s", k)

        ifcfg_file = NET_CONF_PREF + name
        hook_dict = {"ifcfg_file": ifcfg_file, "config": cfg}
        hook_return = hooks.before_ifcfg_write(hook_dict)
        cfg = hook_return["config"]
        self.writeConfFile(ifcfg_file, cfg)
        hooks.after_ifcfg_write(hook_return)