X-Git-Url: http://git.onelab.eu/?a=blobdiff_plain;f=PLC%2FMethods%2FAdmGenerateNodeConfFile.py;h=85789bd700a8f9d2753c3a2b1ce42b43dbf67fe9;hb=9143744fff33acd95e056cc0f8a9f3e628dcd72c;hp=0afbabb4e1d0c267ec0cfff7b0add3c1c33f65d7;hpb=e93b72e44b8c848dd5bd050e8c31951f69512157;p=plcapi.git diff --git a/PLC/Methods/AdmGenerateNodeConfFile.py b/PLC/Methods/AdmGenerateNodeConfFile.py index 0afbabb..85789bd 100644 --- a/PLC/Methods/AdmGenerateNodeConfFile.py +++ b/PLC/Methods/AdmGenerateNodeConfFile.py @@ -6,7 +6,7 @@ from PLC.Method import Method from PLC.Parameter import Parameter, Mixed from PLC.Nodes import Node, Nodes from PLC.NodeNetworks import NodeNetwork, NodeNetworks -from PLC.Auth import PasswordAuth +from PLC.Auth import Auth class AdmGenerateNodeConfFile(Method): """ @@ -28,7 +28,7 @@ class AdmGenerateNodeConfFile(Method): roles = ['admin', 'pi', 'tech'] accepts = [ - PasswordAuth(), + Auth(), Mixed(Node.fields['node_id'], Node.fields['hostname']) ] @@ -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