From c04b31221c8db70996cf1b1770dc6e1c12d0a15b Mon Sep 17 00:00:00 2001 From: smbaker Date: Mon, 23 Apr 2012 16:32:47 -0700 Subject: [PATCH] bring over GetBootMedium --- PLC/Methods/GetBootMedium.py | 39 +++++++++++++++++++++++++++++------- 1 file changed, 32 insertions(+), 7 deletions(-) diff --git a/PLC/Methods/GetBootMedium.py b/PLC/Methods/GetBootMedium.py index 7225b12..c2e60a5 100644 --- a/PLC/Methods/GetBootMedium.py +++ b/PLC/Methods/GetBootMedium.py @@ -9,6 +9,8 @@ from PLC.Method import Method from PLC.Parameter import Parameter, Mixed from PLC.Auth import Auth +from PLC.IpAddresses import IpAddress, IpAddresses +from PLC.Routes import Route, Routes from PLC.Nodes import Node, Nodes from PLC.Interfaces import Interface, Interfaces from PLC.InterfaceTags import InterfaceTag, InterfaceTags @@ -215,13 +217,36 @@ class GetBootMedium(Method): file += 'IP_METHOD="%s"\n' % primary['method'] if primary['method'] == 'static': - file += 'IP_ADDRESS="%s"\n' % primary['ip'] - file += 'IP_GATEWAY="%s"\n' % primary['gateway'] - file += 'IP_NETMASK="%s"\n' % primary['netmask'] - file += 'IP_NETADDR="%s"\n' % primary['network'] - file += 'IP_BROADCASTADDR="%s"\n' % primary['broadcast'] - file += 'IP_DNS1="%s"\n' % primary['dns1'] - file += 'IP_DNS2="%s"\n' % (primary['dns2'] or "") + # FIXME: We currently get the first ip address + # only. plnode.txt depends on interface having a single ip + # address. We assume that the first ip address in the + # primary interface will be the primary ip address. This + # assumumption is probably not the right way to go... - baris + routes = Routes(self.api, {'node_id': primary['node_id']}) + default_route = [r for r in routes if r['subnet'] == u'0.0.0.0/0'] + gateway = "" + if default_route: + gateway = default_route[0]['next_hop'] + + node = Nodes(self.api, primary['node_id'])[0] + dns = node['dns'].split(',') + dns1 = None + dns2 = None + if dns: + dns1 = dns[0] + if len(dns) > 1: + dns2 = dns[1] + + ip_addresses = IpAddresses(self.api, primary['ip_address_ids']) + if ip_addresses: + primary_ip_address = ip_addresses[0] + file += 'IP_ADDRESS="%s"\n' % primary_ip_address['ip_addr'] + file += 'IP_GATEWAY="%s"\n' % gateway + file += 'IP_NETMASK="%s"\n' % primary_ip_address['netmask'] + file += 'IP_NETADDR=""\n' + file += 'IP_BROADCASTADDR=""\n' + file += 'IP_DNS1="%s"\n' % (dns1 or "") + file += 'IP_DNS2="%s"\n' % (dns2 or "") file += 'HOST_NAME="%s"\n' % host file += 'DOMAIN_NAME="%s"\n' % domain -- 2.43.0