X-Git-Url: http://git.onelab.eu/?a=blobdiff_plain;f=PLC%2FMethods%2FBootUpdateNode.py;h=4589d513a7a4570e77d89eb032e288b970939c66;hb=5e02c827f0b3c3c21dcaf3892aa6561dedc4b3cc;hp=5c1762afe7e8b365b5659e2fe8eab764204342e7;hpb=d22aea71d8cd39db72394cad0b8943b387fc3b4b;p=plcapi.git diff --git a/PLC/Methods/BootUpdateNode.py b/PLC/Methods/BootUpdateNode.py index 5c1762a..4589d51 100644 --- a/PLC/Methods/BootUpdateNode.py +++ b/PLC/Methods/BootUpdateNode.py @@ -1,9 +1,10 @@ +# $Id$ from PLC.Faults import * from PLC.Method import Method from PLC.Parameter import Parameter, Mixed -from PLC.Auth import Auth, BootAuth +from PLC.Auth import Auth, BootAuth, SessionAuth from PLC.Nodes import Node, Nodes -from PLC.NodeNetworks import NodeNetwork, NodeNetworks +from PLC.Interfaces import Interface, Interfaces can_update = lambda (field, value): field in \ ['method', 'mac', 'gateway', 'network', @@ -19,19 +20,17 @@ class BootUpdateNode(Method): roles = ['node'] - nodenetwork_fields = dict(filter(can_update, NodeNetwork.fields.items())) + interface_fields = dict(filter(can_update, Interface.fields.items())) accepts = [ - BootAuth(), + Mixed(BootAuth(), SessionAuth()), {'boot_state': Node.fields['boot_state'], - 'primary_network': nodenetwork_fields, + 'primary_network': interface_fields, 'ssh_host_key': Node.fields['ssh_rsa_key']} ] returns = Parameter(int, '1 if successful') - object_type = 'Node' - def call(self, auth, node_fields): # Update node state if node_fields.has_key('boot_state'): @@ -39,28 +38,33 @@ class BootUpdateNode(Method): if node_fields.has_key('ssh_host_key'): self.caller['ssh_rsa_key'] = node_fields['ssh_host_key'] - # Update primary node network state + # Update primary interface state if node_fields.has_key('primary_network'): primary_network = node_fields['primary_network'] - if 'nodenetwork_id' not in primary_network: - raise PLCInvalidArgument, "Node network not specified" - if primary_network['nodenetwork_id'] not in self.caller['nodenetwork_ids']: - raise PLCInvalidArgument, "Node network not associated with calling node" + if 'interface_id' not in primary_network: + raise PLCInvalidArgument, "Interface not specified" + if primary_network['interface_id'] not in self.caller['interface_ids']: + raise PLCInvalidArgument, "Interface not associated with calling node" + + interfaces = Interfaces(self.api, [primary_network['interface_id']]) + if not interfaces: + raise PLCInvalidArgument, "No such interface %r"%interface_id + interface = interfaces[0] - nodenetworks = NodeNetworks(self.api, [primary_network['nodenetwork_id']]) - if not nodenetworks: - raise PLCInvalidArgument, "No such node network" - nodenetwork = nodenetworks[0] + if not interface['is_primary']: + raise PLCInvalidArgument, "Not the primary interface on record" - if not nodenetwork['is_primary']: - raise PLCInvalidArgument, "Not the primary node network on record" + interface_fields = dict(filter(can_update, primary_network.items())) + interface.update(interface_fields) + interface.sync(commit = False) - nodenetwork_fields = dict(filter(can_update, primary_network.items())) - nodenetwork.update(nodenetwork_fields) - nodenetwork.sync(commit = False) + # indicate that node has booted & contacted PLC. + if isinstance(self.caller, Node): + node = self.caller + node.update_last_contact() self.caller.sync(commit = True) - self.message = "Node updated: %s" % ", ".join(node_fields.keys()) + self.message = "Node updated: %s" % ", ".join(node_fields.keys()) return 1