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
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