2 from PLC.Faults import *
3 from PLC.Method import Method
4 from PLC.Parameter import Parameter, Mixed
5 from PLC.Auth import Auth, BootAuth, SessionAuth
6 from PLC.Nodes import Node, Nodes
8 can_update = ['run_level']
10 class ReportRunlevel(Method):
14 roles = ['node', 'admin']
17 Mixed(BootAuth(), SessionAuth(), Auth()),
18 {'run_level': Node.fields['run_level'],
20 Mixed(Node.fields['node_id'],
21 Node.fields['hostname'])
24 returns = Parameter(int, '1 if successful')
26 def call(self, auth, report_fields, node_id_or_hostname=None):
28 if not isinstance(self.caller, Node):
30 if 'admin' not in self.caller['roles']:
31 raise PLCPermissionDenied, "Not allowed to update node run_level"
33 nodes = Nodes(self.api, [node_id_or_hostname])
35 raise PLCInvalidArgument, "No such node"
41 node.update_last_contact()
42 for field in can_update:
43 if field in report_fields:
44 node.update({field : report_fields[field]})
46 node.sync(commit=True)
48 self.message = "Node Runlevel Report : %s" % ", ".join(report_fields.keys())