svn keywords
[plcapi.git] / PLC / Methods / BootGetNodeDetails.py
1 # $Id$
2 # $URL$
3 from PLC.Method import Method
4 from PLC.Parameter import Parameter, Mixed
5 from PLC.Auth import BootAuth
6 from PLC.Nodes import Node, Nodes
7 from PLC.Interfaces import Interface, Interfaces
8 from PLC.Sessions import Session, Sessions
9
10 class BootGetNodeDetails(Method):
11     """
12     Returns a set of details about the calling node, including a new
13     node session value.
14     """
15
16     roles = ['node']
17
18     accepts = [BootAuth()]
19
20     returns = {
21         'hostname': Node.fields['hostname'],
22         'boot_state': Node.fields['boot_state'],
23         'model': Node.fields['model'],
24         'networks': [Interface.fields],
25         'session': Session.fields['session_id'],
26         }
27
28     def call(self, auth):
29         details = {
30             'hostname': self.caller['hostname'],
31             'boot_state': self.caller['boot_state'],
32             # XXX Boot Manager cannot unmarshal None
33             'model': self.caller['model'] or "",
34             }
35
36         # Generate a new session value
37         session = Session(self.api)
38         session.sync(commit = False)
39         session.add_node(self.caller, commit = True)
40
41         details['session'] = session['session_id']
42
43         if self.caller['interface_ids']:
44             details['networks'] = Interfaces(self.api, self.caller['interface_ids'])
45             # XXX Boot Manager cannot unmarshal None
46             for network in details['networks']:
47                 for field in network:
48                     if network[field] is None:
49                         if isinstance(network[field], (int, long)):
50                             network[field] = -1
51                         else:
52                             network[field] = ""
53
54         self.message = "Node request boot_state (%s) and networks" % \
55                 (details['boot_state'])
56         return details
57