X-Git-Url: http://git.onelab.eu/?a=blobdiff_plain;f=PLC%2FMethods%2FGetBootMedium.py;h=c2e60a50f3e046229200a777bd2505cc7b31d8c6;hb=c04b31221c8db70996cf1b1770dc6e1c12d0a15b;hp=7225b126c1ca38100b1f9ff64acce80315d65712;hpb=f1b4415be5ba4be9941d25b531c46696b377fa3a;p=plcapi.git 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