+ # Delay bringing up any bridge devices
+ if dev in bridgeDevices: continue
+
+ if not files_only:
+ logger.verbose('net:InitInterfaces bringing up {}'.format(dev))
+ os.system("/sbin/ifup {}".format(dev))
+
+ # Bring up the bridge devices
+ for bridge in bridgeDevices:
+ if not files_only and bridge in newdevs:
+ logger.verbose('net:InitInterfaces bringing up bridge {}'.format(bridge))
+ os.system("/sbin/ifup {}".format(bridge))
+
+##
+# Prepare the interface details.
+#
+def prepDetails(interface, hostname=''):
+ details = {}
+ details['ONBOOT'] = 'yes'
+ details['USERCTL'] = 'no'
+ # starting with f27, it's OK to use NetworkManager
+ # attempt to work around issues seen starting with f23
+ # details['NM_CONTROLLED'] = 'no'
+ if interface['mac']:
+ details['HWADDR'] = interface['mac']
+ if interface['is_primary']:
+ details['PRIMARY'] = 'yes'
+
+ if interface['method'] == "static":
+ details['BOOTPROTO'] = "static"
+ details['IPADDR'] = interface['ip']
+ details['NETMASK'] = interface['netmask']
+ details['GATEWAY'] = interface['gateway']
+ if interface['is_primary']:
+ if interface['dns1']:
+ details['DNS1'] = interface['dns1']
+ if interface['dns2']:
+ details['DNS2'] = interface['dns2']
+
+ elif interface['method'] == "dhcp":
+ details['BOOTPROTO'] = "dhcp"
+ details['PERSISTENT_DHCLIENT'] = "yes"
+ if interface['hostname']:
+ details['DHCP_HOSTNAME'] = interface['hostname']
+ else:
+ details['DHCP_HOSTNAME'] = hostname
+ if not interface['is_primary']:
+ details['DHCLIENTARGS'] = "-R subnet-mask"
+
+ return details
+
+##
+# Remove duplicate entry from the bridged interface's configuration file.
+#
+def removeBridgedIfaceDetails(details):
+ # TD: Also added secondary IPv4 keys and IPv6 keys to the keys to be removed.
+ allKeys = [ 'PRIMARY', 'PERSISTENT_DHCLIENT', 'DHCLIENTARGS', 'DHCP_HOSTNAME',
+ 'BOOTPROTO', 'IPADDR', 'NETMASK', 'GATEWAY', 'DNS1', 'DNS2',
+ 'IPV6ADDR', 'IPV6_DEFAULTGW', 'IPV6ADDR_SECONDARIES',
+ 'IPV6_AUTOCONF', 'IPV6INIT' ]
+ for i in range(1, 256):
+ allKeys.append('IPADDR' + str(i))
+ allKeys.append('NETMASK' + str(i))
+
+ for key in allKeys:
+ if key in details:
+ del details[key]
+
+ # TD: Also turn off IPv6
+ details['IPV6INIT'] = 'no'
+ details['IPV6_AUTOCONF'] = 'no'
+
+ return details
+
+if __name__ == "__main__":
+ import optparse
+ import sys
+
+ parser = optparse.OptionParser(usage="plnet [-v] [-f] [-p <program>] -r root node_id")
+ parser.add_option("-v", "--verbose", action="store_true", dest="verbose")
+ parser.add_option("-r", "--root", action="store", type="string",
+ dest="root", default=None)
+ parser.add_option("-f", "--files-only", action="store_true",
+ dest="files_only")
+ parser.add_option("-p", "--program", action="store", type="string",
+ dest="program", default="plnet")
+ (options, args) = parser.parse_args()
+ if len(args) != 1 or options.root is None:
+ print sys.argv
+ print >>sys.stderr, "Missing root or node_id"
+ parser.print_help()
+ sys.exit(1)
+
+ node = shell.GetNodes({'node_id': [int(args[0])]})
+ try:
+ interfaces = shell.GetInterfaces({'interface_id': node[0]['interface_ids']})
+ except AttributeError:
+ interfaces = shell.GetNodeNetworks({'nodenetwork_id':node[0]['nodenetwork_ids']})
+ version = 4.2
+
+
+ data = {'hostname': node[0]['hostname'], 'interfaces': interfaces}
+ class logger:
+ def __init__(self, verbose):
+ self.verbosity = verbose
+ def log(self, msg, loglevel=2):
+ if self.verbosity:
+ print msg
+ def verbose(self, msg):
+ self.log(msg, 1)
+ l = logger(options.verbose)
+ InitInterfaces(l, shell, data, options.root, options.files_only)