Merge remote-tracking branch 'origin/pycurl' into planetlab-4_0-branch
[plcapi.git] / PLC / Methods / AdmGenerateNodeConfFile.py
index a2c7dbd..85789bd 100644 (file)
@@ -37,11 +37,14 @@ class AdmGenerateNodeConfFile(Method):
 
     def call(self, auth, node_id_or_hostname):
         # Get node information
-        nodes = Nodes(self.api, [node_id_or_hostname]).values()
+        nodes = Nodes(self.api, [node_id_or_hostname])
         if not nodes:
             raise PLCInvalidArgument, "No such node"
         node = nodes[0]
 
+        if node['peer_id'] is not None:
+            raise PLCInvalidArgument, "Not a local node"
+
         # If we are not an admin, make sure that the caller is a
         # member of the site at which the node is located.
         if 'admin' not in self.caller['roles']:
@@ -50,7 +53,7 @@ class AdmGenerateNodeConfFile(Method):
 
        # Get node networks for this node
         primary = None
-        nodenetworks = NodeNetworks(self.api, node['nodenetwork_ids']).values()
+        nodenetworks = NodeNetworks(self.api, node['nodenetwork_ids'])
         for nodenetwork in nodenetworks:
             if nodenetwork['is_primary']:
                 primary = nodenetwork
@@ -69,6 +72,8 @@ class AdmGenerateNodeConfFile(Method):
         bytes = random.sample(xrange(0, 256), 32)
         # Base64 encode their string representation
         node['key'] = base64.b64encode("".join(map(chr, bytes)))
+        # XXX Boot Manager cannot handle = in the key
+        node['key'] = node['key'].replace("=", "")
         # Save it
         node.sync()
 
@@ -90,7 +95,7 @@ class AdmGenerateNodeConfFile(Method):
             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']
+            file += 'IP_DNS2="%s"\n' % (primary['dns2'] or "")
 
         file += 'HOST_NAME="%s"\n' % host
         file += 'DOMAIN_NAME="%s"\n' % domain