Exemple #1
0
    def _bring_up_interface(self, device_name):
        if device_name in 'lo':
            return True

        cmd = ['/usr/sbin/chdev', '-l', aix_util.translate_devname(device_name), '-a', 'state=up']
        LOG.debug("Attempting to run bring up interface %s using command %s", device_name, cmd)
        try:
            (_out, err) = util.subp(cmd)
            time.sleep(1)
            if len(err):
                LOG.warn("Running %s resulted in stderr output: %s", cmd, err)
            return True
        except util.ProcessExecutionError:
            util.logexc(LOG, "Running interface command %s failed", cmd)
            return False
Exemple #2
0
    def _bring_down_interface(self, device_name):
        if device_name in 'lo':
            return True

        cmd = [
            '/usr/sbin/chdev', '-l',
            aix_util.translate_devname(device_name), '-a', 'state=down'
        ]
        LOG.debug("Attempting to run bring down interface %s using command %s",
                  device_name, cmd)
        try:
            (_out, err) = util.subp(cmd)
            if len(err):
                LOG.warn("Running %s resulted in stderr output: %s", cmd, err)
            return True
        except util.ProcessExecutionError:
            util.logexc(LOG, "Running interface command %s failed", cmd)
            return False
Exemple #3
0
    def _bring_down_interface(self, device_name):
        if device_name in 'lo':
            return True

        interface = aix_util.translate_devname(device_name)
        if aix_util.get_if_attr(interface, "state") == "down":
            time.sleep(1)
            return True
        else:
            cmd = ['/usr/sbin/chdev', '-l', interface, '-a', 'state=down']
            LOG.debug("Attempting to run bring down interface %s using command %s", device_name, cmd)
            try:
                (_out, err) = util.subp(cmd, rcs=[0, 1])
                time.sleep(1)
                if len(err):
                    LOG.warn("Running %s resulted in stderr output: %s", cmd, err)
                return True
            except util.ProcessExecutionError:
                util.logexc(LOG, "Running interface command %s failed", cmd)
                return False
Exemple #4
0
    def _write_network(self, settings):
        entries = net_util.translate_network(settings)
        aix_util.remove_resolve_conf_file(self.resolve_conf_fn)
        print("Translated ubuntu style network settings %s into %s" %
              (settings, entries))
        # Make the intermediate format as the rhel format...
        nameservers = []
        searchservers = []
        dev_names = entries.keys()
        create_dhcp_file = True
        run_dhcpcd = False
        run_autoconf6 = False
        ipv6_interface = None

        # First, make sure the services starts out uncommented in /etc/rc.tcpip
        aix_util.disable_dhcpcd()
        aix_util.disable_ndpd_host()
        aix_util.disable_autoconf6()

        for (dev, info) in entries.iteritems():
            run_cmd = 0
            chdev_cmd = ['/usr/sbin/chdev']
            log_chdev_cmd = ['/usr/sbin/chdev']

            if dev not in 'lo':
                aix_dev = aix_util.translate_devname(dev)
                if info.get('bootproto') == 'dhcp':
                    aix_util.config_dhcp(aix_dev, info, create_dhcp_file)
                    create_dhcp_file = False
                    run_dhcp = True
                else:
                    chdev_cmd.extend(['-l', aix_dev])
                    log_chdev_cmd.extend(['-l', aix_dev])

                    if info['ipv6'] == True:
                        chdev_opts = {
                            "address": '-anetaddr6=',
                            "netmask": '-aprefixlen=',
                        }
                        run_cmd = 1
                        run_autoconf6 = True

                        if ipv6_interface is None:
                            ipv6_interface = aix_dev
                        else:
                            ipv6_interface = "any"

                    if info['ipv4'] == True:
                        chdev_opts = {
                            "address": '-anetaddr=',
                            "netmask": '-anetmask=',
                        }
                        run_cmd = 1

                    for (key, val) in info.iteritems():
                        if key in chdev_opts and val and isinstance(
                                val, basestring):
                            chdev_cmd.append(chdev_opts[key] + val)
                            log_chdev_cmd.append(chdev_opts[key] + val)
                    chdev_cmd.append("-astate=down")
                    log_chdev_cmd.append("-astate=down")

                    if run_cmd:
                        try:
                            util.subp(chdev_cmd, logstring=log_chdev_cmd)
                        except Exception as e:
                            raise e

                        if info['ipv6'] == True:
                            aix_util.add_route("ipv6", info.get('gateway'))
                        if info['ipv4'] == True:
                            aix_util.add_route("ipv4", info.get('gateway'))

            if 'dns-nameservers' in info:
                nameservers.extend(info['dns-nameservers'])
            if 'dns-search' in info:
                searchservers.extend(info['dns-search'])

        if run_dhcp:
            aix_util.enable_dhcpcd()
        if run_autoconf6:
            aix_util.enable_ndpd_host()
            aix_util.enable_autoconf6(ipv6_interface)

        if nameservers or searchservers:
            aix_util.update_resolve_conf_file(self.resolve_conf_fn,
                                              nameservers, searchservers)
        return dev_names
Exemple #5
0
    def _write_network(self, settings):
        entries = net_util.translate_network(settings)
        aix_util.remove_resolve_conf_file(self.resolve_conf_fn)
        print("Translated ubuntu style network settings %s into %s" % (settings, entries))
        # Make the intermediate format as the rhel format...
        nameservers = []
        searchservers = []
        dev_names = entries.keys()
        create_dhcp_file = True
        run_dhcpcd = False
        run_autoconf6 = False
        ipv6_interface = None

        # First, make sure the services starts out uncommented in /etc/rc.tcpip 
        aix_util.disable_dhcpcd()
        aix_util.disable_ndpd_host()
        aix_util.disable_autoconf6()
     
        for (dev, info) in entries.iteritems():
            run_cmd = 0
            chdev_cmd = ['/usr/sbin/chdev']
            log_chdev_cmd = ['/usr/sbin/chdev']

            if dev not in 'lo':
                aix_dev = aix_util.translate_devname(dev)
                if info.get('bootproto') == 'dhcp':
                    aix_util.config_dhcp(aix_dev, info, create_dhcp_file)
                    create_dhcp_file = False
                    run_dhcpcd = True
                else:
                    chdev_cmd.extend(['-l', aix_dev])
                    log_chdev_cmd.extend(['-l', aix_dev])

                    if info['ipv6'] == True:
                        chdev_opts = {
                            "address" : '-anetaddr6=',
                            "netmask" : '-aprefixlen=',
                        }
                        run_cmd = 1
                        run_autoconf6 = True

                        if ipv6_interface is None:
                            ipv6_interface = aix_dev
                        else:
                            ipv6_interface = "any"

                    if info['ipv4'] == True:
                        chdev_opts = {
                            "address" : '-anetaddr=',
                            "netmask" : '-anetmask=',
                        }
                        run_cmd = 1

                    for (key, val) in info.iteritems():
                        if key in chdev_opts and val and isinstance(val, basestring):
                            chdev_cmd.append(chdev_opts[key] + val)
                            log_chdev_cmd.append(chdev_opts[key] + val)

                    if run_cmd:
                        try:
                            util.subp(chdev_cmd, logstring=log_chdev_cmd)
                            time.sleep(2)
                        except Exception as e:
                            raise e

                        if 'mtu' in info:
                            util.subp(["/usr/sbin/chdev", "-l", aix_dev, "-amtu=" + info['mtu']], capture=False, rcs=[0, 1])
                            time.sleep(2)
                        if aix_dev == "en0":
                            if info['ipv6'] == True:
                                aix_util.add_route("ipv6", info.get('gateway'))
                            if info['ipv4'] == True:
                                aix_util.add_route("ipv4", info.get('gateway'))

            if 'dns-nameservers' in info:
                nameservers.extend(info['dns-nameservers'])
            if 'dns-search' in info:
                searchservers.extend(info['dns-search'])

        if run_dhcpcd:
            aix_util.enable_dhcpcd()
        if run_autoconf6:
            aix_util.enable_ndpd_host()
            aix_util.enable_autoconf6(ipv6_interface)

        if nameservers or searchservers:
            aix_util.update_resolve_conf_file(self.resolve_conf_fn, nameservers, searchservers)
        return dev_names