'planetlab-4_0-branch'.
--- /dev/null
+#
+# Functions for interacting with the events table in the database
+#
+# Tony Mack <tmack@cs.princeton.edu>
+# Copyright (C) 2006 The Trustees of Princeton University
+#
+# $Id: Events.py,v 1.11 2007/01/19 17:50:46 tmack Exp $
+#
+
+from PLC.Faults import *
+from PLC.Parameter import Parameter
+from PLC.Filter import Filter
+from PLC.Debug import profile
+from PLC.Table import Row, Table
+
+class EventObject(Row):
+ """
+ Representation of a row in the event_object table.
+ """
+
+ table_name = 'event_object'
+ primary_key = 'event_id'
+ fields = {
+ 'event_object.event_id': Parameter(int, "Event identifier"),
+ 'person_id': Parameter(int, "Identifier of person responsible for event, if any"),
+ 'node_id': Parameter(int, "Identifier of node responsible for event, if any"),
+ 'fault_code': Parameter(int, "Event fault code"),
+ 'call_name': Parameter(str, "Call responsible for this event"),
+ 'call': Parameter(str, "Call responsible for this event, including paramters"),
+ 'message': Parameter(str, "High level description of this event"),
+ 'runtime': Parameter(float, "Runtime of event"),
+ 'time': Parameter(int, "Date and time that the event took place, in seconds since UNIX epoch", ro = True),
+ 'object_id': Parameter(int, "ID of objects affected by this event"),
+ 'object_type': Parameter(str, "What type of object is this event affecting")
+ }
+
+class EventObjects(Table):
+ """
+ Representation of row(s) from the event_object table in the database.
+ """
+
+ def __init__(self, api, event_filter = None, columns = None):
+ Table.__init__(self, api, EventObject, columns)
+ sql = "SELECT %s FROM event_object, events WHERE True" % \
+ ", ".join(self.columns)
+ if event_filter is not None:
+ if isinstance(event_filter, (list, tuple, set)):
+ event_filter = Filter(EventObject.fields, {'event_id': event_filter})
+ elif isinstance(event_filter, dict):
+ event_filter = Filter(EventObject.fields, event_filter)
+ sql += " AND (%s) " % event_filter.sql(api)
+ sql += " AND events.event_id = event_object.event_id "
+ sql += " ORDER BY %s" % EventObject.primary_key
+ self.selectall(sql)
--- /dev/null
+#
+# Functions for interacting with the initscripts table in the database
+#
+# Tony Mack <tmack@cs.princeton.edu>
+# Copyright (C) 2006 The Trustees of Princeton University
+#
+#
+
+from types import StringTypes
+from PLC.Faults import *
+from PLC.Parameter import Parameter
+from PLC.Filter import Filter
+from PLC.Table import Row, Table
+
+class InitScript(Row):
+ """
+ Representation of a row in the initscripts table. To use,
+ instantiate with a dict of values.
+ """
+
+ table_name = 'initscripts'
+ primary_key = 'initscript_id'
+ join_tables = []
+ fields = {
+ 'initscript_id': Parameter(int, "Initscript identifier"),
+ 'name': Parameter(str, "Initscript name", max = 254),
+ 'enabled': Parameter(bool, "Initscript is active"),
+ 'script': Parameter(str, "Initscript"),
+ }
+
+ def validate_name(self, name):
+ """
+ validates the script name
+ """
+
+ conflicts = InitScripts(self.api, [name])
+ for initscript in conflicts:
+ if 'initscript_id' not in self or self['initscript_id'] != initscript['initscript_id']:
+ raise PLCInvalidArgument, "Initscript name already in use"
+
+ return name
+
+
+class InitScripts(Table):
+ """
+ Representation of the initscipts table in the database.
+ """
+
+ def __init__(self, api, initscript_filter = None, columns = None):
+ Table.__init__(self, api, InitScript, columns)
+
+ sql = "SELECT %s FROM initscripts WHERE True" % \
+ ", ".join(self.columns)
+
+ if initscript_filter is not None:
+ if isinstance(initscript_filter, (list, tuple, set)):
+ # Separate the list into integers and strings
+ ints = filter(lambda x: isinstance(x, (int, long)), initscript_filter)
+ strs = filter(lambda x: isinstance(x, StringTypes), initscript_filter)
+ initscript_filter = Filter(InitScript.fields, {'initscript_id': ints, 'name': strs })
+ sql += " AND (%s)" % initscript_filter.sql(api, "OR")
+ elif isinstance(initscript_filter, dict):
+ initscript_filter = Filter(InitScript.fields, initscript_filter)
+ sql += " AND (%s)" % initscript_filter.sql(api, "AND")
+
+ self.selectall(sql)
--- /dev/null
+from PLC.Faults import *
+from PLC.Method import Method
+from PLC.Parameter import Parameter, Mixed
+from PLC.InitScripts import InitScript, InitScripts
+from PLC.Auth import Auth
+
+can_update = lambda (field, value): field not in \
+ ['initscript_id']
+
+class AddInitScript(Method):
+ """
+ Adds a new initscript. Any fields specified in initscript_fields
+ are used, otherwise defaults are used.
+
+ Returns the new initscript_id (> 0) if successful, faults otherwise.
+ """
+
+ roles = ['admin']
+
+ initscript_fields = dict(filter(can_update, InitScript.fields.items()))
+
+ accepts = [
+ Auth(),
+ initscript_fields
+ ]
+
+ returns = Parameter(int, 'New initscript_id (> 0) if successful')
+
+
+ def call(self, auth, initscript_fields):
+ initscript_fields = dict(filter(can_update, initscript_fields.items()))
+ initscript = InitScript(self.api, initscript_fields)
+ initscript.sync()
+
+ self.event_objects = {'InitScript': [initscript['initscript_id']]}
+
+ return initscript['initscript_id']
--- /dev/null
+from PLC.Methods.GetNodeGroups import GetNodeGroups
+
+class AnonAdmGetNodeGroups(GetNodeGroups):
+ """
+ Deprecated. See GetNodeGroups. All fields are now always returned
+ """
+
+ status = "deprecated"
+
+ def call(self, auth, nodegroup_id_or_name_list = None, return_fields = None):
+ return GetNodeGroups.call(self, auth, nodegroup_id_or_name_list)
--- /dev/null
+from PLC.Faults import *
+from PLC.Method import Method
+from PLC.Parameter import Parameter, Mixed
+from PLC.InitScripts import InitScript, InitScripts
+from PLC.Auth import Auth
+
+class DeleteInitScript(Method):
+ """
+ Deletes an existing initscript.
+
+ Returns 1 if successfuli, faults otherwise.
+ """
+
+ roles = ['admin']
+
+ accepts = [
+ Auth(),
+ InitScript.fields['initscript_id']
+ ]
+
+ returns = Parameter(int, '1 if successful')
+
+
+ def call(self, auth, initscript_id):
+ initscripts = InitScripts(self.api, [initscript_id])
+ if not initscripts:
+ raise PLCInvalidArgument, "No such initscript"
+
+ initscript = initscripts[0]
+ initscript.delete()
+ self.event_objects = {'InitScript': [initscript['initscript_id']]}
+
+ return 1
--- /dev/null
+from PLC.Faults import *
+from PLC.Method import Method
+from PLC.Parameter import Parameter, Mixed
+from PLC.Filter import Filter
+from PLC.EventObjects import EventObject, EventObjects
+from PLC.Auth import Auth
+
+class GetEventObjects(Method):
+ """
+ Returns an array of structs containing details about events and
+ faults. If event_filter is specified and is an array of event
+ identifiers, or a struct of event attributes, only events matching
+ the filter will be returned. If return_fields is specified, only the
+ specified details will be returned.
+ """
+
+ roles = ['admin']
+
+ accepts = [
+ Auth(),
+ Mixed(Filter(EventObject.fields)),
+ Parameter([str], "List of fields to return", nullok = True)
+ ]
+
+ returns = [EventObject.fields]
+
+ def call(self, auth, event_filter = None, return_fields = None):
+ return EventObjects(self.api, event_filter, return_fields)
+
--- /dev/null
+from PLC.Faults import *
+from PLC.Method import Method
+from PLC.Parameter import Parameter, Mixed
+from PLC.Filter import Filter
+from PLC.InitScripts import InitScript, InitScripts
+from PLC.Auth import Auth
+
+class GetInitScripts(Method):
+ """
+ Returns an array of structs containing details about initscripts.
+ If initscript_filter is specified and is an array of initscript
+ identifiers, or a struct of initscript attributes, only initscripts
+ matching the filter will be returned. If return_fields is specified,
+ only the specified details will be returned.
+ """
+
+ roles = ['admin', 'pi', 'user', 'tech', 'node']
+
+ accepts = [
+ Auth(),
+ Mixed([Mixed(InitScript.fields['initscript_id'],
+ InitScript.fields['name'])],
+ Filter(InitScript.fields)),
+ Parameter([str], "List of fields to return", nullok = True)
+ ]
+
+ returns = [InitScript.fields]
+
+
+ def call(self, auth, initscript_filter = None, return_fields = None):
+ return InitScripts(self.api, initscript_filter, return_fields)
--- /dev/null
+from PLC.Faults import *
+from PLC.Method import Method
+from PLC.Parameter import Parameter, Mixed
+from PLC.InitScripts import InitScript, InitScripts
+from PLC.Auth import Auth
+
+can_update = lambda (field, value): field not in \
+ ['initscript_id']
+
+class UpdateInitScript(Method):
+ """
+ Updates an initscript. Only the fields specified in
+ initscript_fields are updated, all other fields are left untouched.
+
+ Returns 1 if successful, faults otherwise.
+ """
+
+ roles = ['admin']
+
+ initscript_fields = dict(filter(can_update, InitScript.fields.items()))
+
+ accepts = [
+ Auth(),
+ InitScript.fields['initscript_id'],
+ initscript_fields
+ ]
+
+ returns = Parameter(int, '1 if successful')
+
+ def call(self, auth, initscript_id, initscript_fields):
+ initscript_fields = dict(filter(can_update, initscript_fields.items()))
+
+ initscripts = InitScripts(self.api, [initscript_id])
+ if not initscripts:
+ raise PLCInvalidArgument, "No such initscript"
+
+ initscript = initscripts[0]
+ initscript.update(initscript_fields)
+ initscript.sync()
+ self.event_objects = {'InitScript': [initscript['initscript_id']]}
+
+ return 1