- add node to accepted roles
[plcapi.git] / PLC / Methods / BootGetNodeDetails.py
1 from PLC.Method import Method
2 from PLC.Parameter import Parameter, Mixed
3 from PLC.Auth import BootAuth
4 from PLC.Nodes import Node, Nodes
5 from PLC.NodeNetworks import NodeNetwork, NodeNetworks
6 from PLC.Sessions import Session, Sessions
7
8 class BootGetNodeDetails(Method):
9     """
10     Returns a set of details about the calling node, including a new
11     node session value.
12     """
13
14     roles = ['node']
15
16     accepts = [BootAuth()]
17
18     returns = {
19         'hostname': Node.fields['hostname'],
20         'boot_state': Node.fields['boot_state'],
21         'model': Node.fields['model'],
22         'networks': [NodeNetwork.fields],
23         'session': Session.fields['session_id'],
24         }
25
26     def call(self, auth):
27         details = {
28             'hostname': self.caller['hostname'],
29             'boot_state': self.caller['boot_state'],
30             'model': self.caller['model'],
31             }
32
33         # Generate a new session value
34         session = Session(self.api)
35         session.sync(commit = False)
36         session.add_node(self.caller, commit = True)
37
38         details['session'] = session['session_id']
39
40         if self.caller['nodenetwork_ids']:
41             details['networks'] = NodeNetworks(self.api, self.caller['nodenetwork_ids']).values()
42
43         return details
44