Beispiel #1
0
def generate_routes(routes):
    script = '# Generated by press v%s\n' % get_press_version()
    d = OrderedDict()
    for idx in range(len(routes)):
        i = ipaddress.ip_network(routes[idx]['cidr'])
        d['ADDRESS%d' % idx] = str(i.network_address)
        d['NETMASK%d' % idx] = i.netmask
        d['GATEWAY%d' % idx] = routes[idx]['gateway']
    for k, v in d.items():
        script += '%s=%s\n' % (k, v)
    return script
Beispiel #2
0
    def write_resolvconf(self):
        network_configuration = self.press_configuration.get(
            'networking', dict())
        dns_config = network_configuration.get('dns')
        if not dns_config:
            log.warn('Static DNS configuration is missing')
            return
        header = '# Generated by Press v%s\n' % package.get_press_version()
        log.info('Writing resolv.conf')
        search_domains = dns_config.get('search')
        nameservers = dns_config.get('nameservers')

        if nameservers or search_domains:
            for domain in search_domains:
                header += 'search %s\n' % domain

            for nameserver in nameservers:
                header += 'nameserver %s\n' % nameserver

            deployment.write(self.join_root('/etc/resolv.conf'), header)
        else:
            log.warn('No nameservers or search domains are defined')
 def generate_static_routes(routes):
     script = '# Generated by press v%s\n' % get_press_version()
     for idx in range(len(routes)):
         script += 'any net %s gw %s\n' % (routes[idx]['cidr'],
                                           routes[idx]['gateway'])
     return script
Beispiel #4
0
from collections import OrderedDict

from press import helpers
from press.helpers.package import get_press_version

# TODO: Form base class for sysconfig/network-scripts under redhat

log = logging.getLogger(__name__)

# Type: func
lookup_methods = {
    'mac': helpers.networking.get_device_by_mac,
    'dev': helpers.networking.get_device_by_dev
}

config_header = '# Generated by press v{0}\n'.format(get_press_version())


class InterfaceTemplate(OrderedDict):
    def __init__(self,
                 device,
                 type='Ethernet',
                 bootproto='none',
                 default_route=False,
                 ipv4_failure_fatal=False,
                 ipv6init=True,
                 ipv6_autoconf=False,
                 ipv6_failure_fatal=False,
                 uid='',
                 name='',
                 on_boot=True,