-# $Id$
-# $URL$
import random
import base64
import os
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
# renew the key and save it on the database
if renew_key:
node['key'] = compute_key()
+ node.update_last_download(commit=False)
node.sync()
# Generate node configuration file suitable for BootCD
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
node_id=node['node_id']
# no support for deployment-based BootCD's, use kvariants instead
- node_pldistro = GetNodePldistro (self.api).call(auth, node_id)
+ node_pldistro = GetNodePldistro (self.api,self.caller).call(auth, node_id)
if node_pldistro: pldistro = node_pldistro
- node_fcdistro = GetNodeFcdistro (self.api).call(auth, node_id)
+ node_fcdistro = GetNodeFcdistro (self.api,self.caller).call(auth, node_id)
if node_fcdistro: fcdistro = node_fcdistro
- node_arch = GetNodeArch (self.api).call(auth,node_id)
+ node_arch = GetNodeArch (self.api,self.caller).call(auth,node_id)
if node_arch: arch = node_arch
return (pldistro,fcdistro,arch)
raise PLCInvalidArgument, "File %s not under %s"%(filename,self.WORKDIR)
### output should not exist (concurrent runs ..)
+ # numerous reports of issues with this policy
+ # looks like people sometime suspend/cancel their download
+ # and this leads to the old file sitting in there forever
+ # so, if the file is older than 5 minutes, we just trash
+ grace=5
+ if os.path.exists(filename) and (time.time()-os.path.getmtime(filename)) >= (grace*60):
+ os.unlink(filename)
if os.path.exists(filename):
- raise PLCInvalidArgument, "Resulting file %s already exists"%filename
+ raise PLCInvalidArgument, "Resulting file %s already exists - please try again in %d minutes"%\
+ (filename,grace)
### we can now safely create the file,
### either we are admin or under a controlled location