def gen_conf(self):
        netconf = {}
        netconf['version'] = 2
        netconf['ethernets'] = {}

        ethernets = {}
        for mac, dev in self.ifaces.items():
            mac = mac.lower()

            # c_dev stores name in context 'ETHX' for this device.
            # dev stores the current system name.
            c_dev = self.context_devname.get(mac, dev)

            devconf = {}

            # Set MAC address
            devconf['match'] = {'macaddress': mac}

            # Set IPv4 address
            devconf['addresses'] = []
            mask = self.get_mask(c_dev)
            prefix = str(net.mask_to_net_prefix(mask))
            devconf['addresses'].append(
                self.get_ip(c_dev, mac) + '/' + prefix)

            # Set IPv6 Global and ULA address
            addresses6 = self.get_ip6(c_dev)
            if addresses6:
                prefix6 = self.get_ip6_prefix(c_dev)
                devconf['addresses'].extend(
                    [i + '/' + prefix6 for i in addresses6])

            # Set IPv4 default gateway
            gateway = self.get_gateway(c_dev)
            if gateway:
                devconf['gateway4'] = gateway

            # Set IPv6 default gateway
            gateway6 = self.get_gateway6(c_dev)
            if gateway6:
                devconf['gateway6'] = gateway6

            # Set DNS servers and search domains
            nameservers = self.get_nameservers(c_dev)
            if nameservers:
                devconf['nameservers'] = nameservers

            # Set MTU size
            mtu = self.get_mtu(c_dev)
            if mtu:
                devconf['mtu'] = mtu

            ethernets[dev] = devconf

        netconf['ethernets'] = ethernets
        return(netconf)
Ejemplo n.º 2
0
    def gen_conf(self):
        netconf = {}
        netconf['version'] = 2
        netconf['ethernets'] = {}

        ethernets = {}
        for mac, dev in self.ifaces.items():
            mac = mac.lower()

            # c_dev stores name in context 'ETHX' for this device.
            # dev stores the current system name.
            c_dev = self.context_devname.get(mac, dev)

            devconf = {}

            # Set MAC address
            devconf['match'] = {'macaddress': mac}

            # Set IPv4 address
            devconf['addresses'] = []
            mask = self.get_mask(c_dev)
            prefix = str(net.mask_to_net_prefix(mask))
            devconf['addresses'].append(
                self.get_ip(c_dev, mac) + '/' + prefix)

            # Set IPv6 Global and ULA address
            addresses6 = self.get_ip6(c_dev)
            if addresses6:
                prefix6 = self.get_ip6_prefix(c_dev)
                devconf['addresses'].extend(
                    [i + '/' + prefix6 for i in addresses6])

            # Set IPv4 default gateway
            gateway = self.get_gateway(c_dev)
            if gateway:
                devconf['gateway4'] = gateway

            # Set IPv6 default gateway
            gateway6 = self.get_gateway6(c_dev)
            if gateway6:
                devconf['gateway6'] = gateway6

            # Set DNS servers and search domains
            nameservers = self.get_nameservers(c_dev)
            if nameservers:
                devconf['nameservers'] = nameservers

            # Set MTU size
            mtu = self.get_mtu(c_dev)
            if mtu:
                devconf['mtu'] = mtu

            ethernets[dev] = devconf

        netconf['ethernets'] = ethernets
        return(netconf)