--- /dev/null
+from PLC.Faults import *
+from PLC.Method import Method
+from PLC.Parameter import Parameter, Mixed
+from PLC.PCUProtocolTypes import PCUProtocolType, PCUProtocolTypes
+from PLC.PCUTypes import PCUType, PCUTypes
+from PLC.Auth import Auth
+
+can_update = lambda (field, value): field in \
+ ['pcu_type_id', 'port', 'protocol', 'supported']
+
+class AddPCUProtocolType(Method):
+ """
+ Adds a new pcu protocol type.
+
+ Returns the new pcu_protocol_type_id (> 0) if successful, faults otherwise.
+ """
+
+ roles = ['admin']
+
+ protocol_type_fields = dict(filter(can_update, PCUProtocolType.fields.items()))
+
+ accepts = [
+ Auth(),
+ Mixed(PCUType.fields['pcu_type_id'],
+ PCUType.fields['model']),
+ protocol_type_fields
+ ]
+
+ returns = Parameter(int, 'New pcu_protocol_type_id (> 0) if successful')
+
+ def call(self, auth, pcu_type_id_or_model, protocol_type_fields):
+
+ # Check if pcu type exists
+ pcu_types = PCUTypes(self.api, [pcu_type_id_or_model])
+ if not pcu_types:
+ raise PLCInvalidArgument, "No such pcu type"
+ pcu_type = pcu_types[0]
+
+
+ # Check if this port is already used
+ if 'port' not in protocol_type_fields:
+ raise PLCInvalidArgument, "Must specify a port"
+ else:
+ protocol_types = PCUProtocolTypes(self.api, {'pcu_type_id': pcu_type['pcu_type_id']})
+ for protocol_type in protocol_types:
+ if protocol_type['port'] == protocol_type_fields['port']:
+ raise PLCInvalidArgument, "Port alreay in use"
+
+ protocol_type_fields = dict(filter(can_update, protocol_type_fields.items()))
+ protocol_type = PCUProtocolType(self.api, protocol_type_fields)
+ protocol_type['pcu_type_id'] = pcu_type['pcu_type_id']
+ protocol_type.sync()
+ self.event_object = {'PCUProtocolType': [protocol_type['pcu_protocol_type_id']]}
+
+ return protocol_type['pcu_protocol_type_id']
--- /dev/null
+from PLC.Faults import *
+from PLC.Method import Method
+from PLC.Parameter import Parameter, Mixed
+from PLC.PCUTypes import PCUType, PCUTypes
+from PLC.Auth import Auth
+
+can_update = lambda (field, value): field in \
+ ['model', 'name']
+
+class AddPCUType(Method):
+ """
+ Adds a new pcu type.
+
+ Returns the new pcu_type_id (> 0) if successful, faults otherwise.
+ """
+
+ roles = ['admin']
+
+ pcu_type_fields = dict(filter(can_update, PCUType.fields.items()))
+
+ accepts = [
+ Auth(),
+ pcu_type_fields
+ ]
+
+ returns = Parameter(int, 'New pcu_type_id (> 0) if successful')
+
+
+ def call(self, auth, pcu_type_fields):
+ pcu_type_fields = dict(filter(can_update, pcu_type_fields.items()))
+ pcu_type = PCUType(self.api, pcu_type_fields)
+ pcu_type.sync()
+ self.event_object = {'PCUType': [pcu_type['pcu_type_id']]}
+
+ return pcu_type['pcu_type_id']
--- /dev/null
+from PLC.Faults import *
+from PLC.Method import Method
+from PLC.Parameter import Parameter, Mixed
+from PLC.PCUProtocolTypes import PCUProtocolType, PCUProtocolTypes
+from PLC.Auth import Auth
+
+class DeletePCUProtocolType(Method):
+ """
+ Deletes a PCU protocol type.
+
+ Returns 1 if successful, faults otherwise.
+ """
+
+ roles = ['admin']
+
+ accepts = [
+ Auth(),
+ PCUProtocolType.fields['pcu_protocol_type_id']
+ ]
+
+ returns = Parameter(int, '1 if successful')
+
+
+ def call(self, auth, protocol_type_id):
+ protocol_types = PCUProtocolTypes(self.api, [protocol_type_id])
+ if not protocol_types:
+ raise PLCInvalidArgument, "No such pcu protocol type"
+
+ protocol_type = protocol_types[0]
+ protocol_type.delete()
+ self.event_objects = {'PCUProtocolType': [protocol_type['pcu_protocol_type_id']]}
+
+ return 1
--- /dev/null
+from PLC.Faults import *
+from PLC.Method import Method
+from PLC.Parameter import Parameter, Mixed
+from PLC.PCUTypes import PCUType, PCUTypes
+from PLC.Auth import Auth
+
+class DeletePCUType(Method):
+ """
+ Deletes a PCU type.
+
+ Returns 1 if successful, faults otherwise.
+ """
+
+ roles = ['admin']
+
+ accepts = [
+ Auth(),
+ PCUType.fields['pcu_type_id']
+ ]
+
+ returns = Parameter(int, '1 if successful')
+
+
+ def call(self, auth, pcu_type_id):
+ pcu_types = PCUTypes(self.api, [pcu_type_id])
+ if not pcu_types:
+ raise PLCInvalidArgument, "No such pcu type"
+
+ pcu_type = pcu_types[0]
+ pcu_type.delete()
+ self.event_objects = {'PCUType': [pcu_type['pcu_type_id']]}
+
+ return 1
--- /dev/null
+from PLC.Faults import *
+from PLC.Method import Method
+from PLC.Parameter import Parameter, Mixed
+from PLC.PCUProtocolTypes import PCUProtocolType, PCUProtocolTypes
+from PLC.Auth import Auth
+from PLC.Filter import Filter
+
+class GetPCUProtocolTypes(Method):
+ """
+ Returns an array of PCU Types.
+ """
+
+ roles = ['admin', 'pi', 'user', 'tech', 'node']
+
+ accepts = [
+ Auth(),
+ Mixed([PCUProtocolType.fields['pcu_type_id']],
+ Filter(PCUProtocolType.fields)),
+ Parameter([str], "List of fields to return", nullok = True)
+ ]
+
+ returns = [PCUProtocolType.fields]
+
+
+ def call(self, auth, protocol_type_filter = None, return_fields = None):
+
+ #Must query at least pcu_type_id
+ if return_fields is not None and 'pcu_protocol_type_id' not in return_fields:
+ return_fields.append('pcu_protocol_type_id')
+ added_fields = ['pcu_protocol_type_id']
+ else:
+ added_fields = []
+
+ protocol_types = PCUProtocolTypes(self.api, protocol_type_filter, return_fields)
+
+ for added_field in added_fields:
+ for protocol_type in protocol_types:
+ del protocol_type[added_field]
+
+ return protocol_types
--- /dev/null
+from PLC.Faults import *
+from PLC.Method import Method
+from PLC.Parameter import Parameter, Mixed
+from PLC.PCUTypes import PCUType, PCUTypes
+from PLC.Auth import Auth
+from PLC.Filter import Filter
+
+class GetPCUTypes(Method):
+ """
+ Returns an array of PCU Types.
+ """
+
+ roles = ['admin', 'pi', 'user', 'tech', 'node']
+
+ accepts = [
+ Auth(),
+ Mixed([PCUType.fields['pcu_type_id'],
+ PCUType.fields['model']],
+ Filter(PCUType.fields)),
+ Parameter([str], "List of fields to return", nullok = True)
+ ]
+
+ returns = [PCUType.fields]
+
+
+ def call(self, auth, pcu_type_filter = None, return_fields = None):
+
+ #Must query at least pcu_type_id
+ if return_fields is not None:
+ added_fields = []
+ if 'pcu_type_id' not in return_fields:
+ return_fields.append('pcu_type_id')
+ added_fields.append('pcu_type_id')
+ if 'pcu_protocol_types' in return_fields and \
+ 'pcu_protocol_type_ids' not in return_fields:
+ return_fields.append('pcu_protocol_type_ids')
+ added_fields.append('pcu_protocol_type_ids')
+ else:
+ added_fields = []
+
+ pcu_types = PCUTypes(self.api, pcu_type_filter, return_fields)
+
+ # remove added fields and protocol_types
+ for added_field in added_fields:
+ for pcu_type in pcu_types:
+ del pcu_type[added_field]
+
+ return pcu_types
--- /dev/null
+from PLC.Faults import *
+from PLC.Method import Method
+from PLC.Parameter import Parameter, Mixed
+from PLC.PCUProtocolTypes import PCUProtocolType, PCUProtocolTypes
+from PLC.Auth import Auth
+
+can_update = lambda (field, value): field in \
+ ['pcu_type_id', 'port', 'protocol', 'supported']
+
+class UpdatePCUProtocolType(Method):
+ """
+ Updates a pcu protocol type. Only the fields specified in
+ port_typee_fields are updated, all other fields are left untouched.
+
+ Returns 1 if successful, faults otherwise.
+ """
+
+ roles = ['admin']
+
+ protocol_type_fields = dict(filter(can_update, PCUProtocolType.fields.items()))
+
+ accepts = [
+ Auth(),
+ PCUProtocolType.fields['pcu_protocol_type_id'],
+ protocol_type_fields
+ ]
+
+ returns = Parameter(int, '1 if successful')
+
+ def call(self, auth, protocol_type_id, protocol_type_fields):
+ protocol_type_fields = dict(filter(can_update, protocol_type_fields.items()))
+
+ protocol_types = PCUProtocolTypes(self.api, [protocol_type_id])
+ if not protocol_types:
+ raise PLCInvalidArgument, "No such pcu protocol type"
+
+ protocol_type = protocol_types[0]
+ protocol_type.update(protocol_type_fields)
+ protocol_type.sync()
+ self.event_objects = {'PCUProtocolType': [protocol_type['pcu_protocol_type_id']]}
+ return 1
--- /dev/null
+from PLC.Faults import *
+from PLC.Method import Method
+from PLC.Parameter import Parameter, Mixed
+from PLC.PCUTypes import PCUType, PCUTypes
+from PLC.Auth import Auth
+
+can_update = lambda (field, value): field in \
+ ['model', 'name']
+
+class UpdatePCUType(Method):
+ """
+ Updates a PCU type. Only the fields specified in
+ pcu_typee_fields are updated, all other fields are left untouched.
+
+ Returns 1 if successful, faults otherwise.
+ """
+
+ roles = ['admin']
+
+ pcu_type_fields = dict(filter(can_update, PCUType.fields.items()))
+
+ accepts = [
+ Auth(),
+ PCUType.fields['pcu_type_id'],
+ pcu_type_fields
+ ]
+
+ returns = Parameter(int, '1 if successful')
+
+ def call(self, auth, pcu_type_id, pcu_type_fields):
+ pcu_type_fields = dict(filter(can_update, pcu_type_fields.items()))
+
+ pcu_types = PCUTypes(self.api, [pcu_type_id])
+ if not pcu_types:
+ raise PLCInvalidArgument, "No such pcu type"
+
+ pcu_type = pcu_types[0]
+ pcu_type.update(pcu_type_fields)
+ pcu_type.sync()
+ self.event_objects = {'PCUType': [pcu_type['pcu_type_id']]}
+
+ return 1