(most) all functions now take SessionAuth in addition to PasswordAuth
[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     accepts = [BootAuth()]
15     returns = {
16         'hostname': Node.fields['hostname'],
17         'boot_state': Node.fields['boot_state'],
18         'model': Node.fields['model'],
19         'networks': [NodeNetwork.fields],
20         'session': Session.fields['session_id'],
21         }
22
23     def call(self, auth, update_fields):
24         details = {
25             'hostname': self.caller['hostname'],
26             'boot_state': self.caller['boot_state'],
27             'model': self.caller['model'],
28             }
29
30         # Generate a new session value
31         session = Session(self.api)
32         session.sync(commit = False)
33         session.add_node(self.caller, commit = True)
34
35         details['session'] = session['session_id']
36
37         if self.caller['nodenetwork_ids']:
38             details['networks'] = NodeNetworks(self.api, self.caller['nodenetwork_ids']).values()
39
40         return details
41