X-Git-Url: http://git.onelab.eu/?a=blobdiff_plain;f=PLC%2FMethods%2FAddPCU.py;h=2d5b034be737bef41ed132d39e042b3512958f3b;hb=3a24db70ba35a4ffb85d5e7c761b5dbc87b93e40;hp=253407973deed6f23af769d9ff36016150d78a08;hpb=ed7fa1ebf97ec2f88f18f8fa538e46c6ae9525c4;p=plcapi.git diff --git a/PLC/Methods/AddPCU.py b/PLC/Methods/AddPCU.py index 2534079..2d5b034 100644 --- a/PLC/Methods/AddPCU.py +++ b/PLC/Methods/AddPCU.py @@ -2,12 +2,11 @@ from PLC.Faults import * from PLC.Method import Method from PLC.Parameter import Parameter, Mixed from PLC.PCUs import PCU, PCUs -from PLC.Auth import PasswordAuth +from PLC.Auth import Auth from PLC.Sites import Site, Sites can_update = lambda (field, value): field in \ - ['site_id', - 'ip', 'hostname', 'protocol', + ['ip', 'hostname', 'protocol', 'username', 'password', 'model', 'notes'] @@ -27,21 +26,20 @@ class AddPCU(Method): pcu_fields = dict(filter(can_update, PCU.fields.items())) accepts = [ - PasswordAuth(), + Auth(), + Mixed(Site.fields['site_id'], + Site.fields['login_base']), pcu_fields ] returns = Parameter(int, 'New pcu_id (> 0) if successful') - event_type = 'Add' - object_type = 'PCU' - object_ids = [] - def call(self, auth, pcu_fields = {}): + def call(self, auth, site_id_or_login_base, pcu_fields): pcu_fields = dict(filter(can_update, pcu_fields.items())) # Get associated site details - sites = Sites(self.api, [pcu_fields['site_id']]).values() + sites = Sites(self.api, [site_id_or_login_base]) if not sites: raise PLCInvalidArgument, "No such site" site = sites[0] @@ -51,8 +49,12 @@ class AddPCU(Method): raise PLCPermissionDenied, "Not allowed to add a PCU to that site" pcu = PCU(self.api, pcu_fields) + pcu['site_id'] = site['site_id'] pcu.sync() + # Logging variables self.object_ids = [site['site_id'], pcu['pcu_id']] + self.message = 'PCU %d added site %s' % \ + (pcu['pcu_id'], site['site_id']) return pcu['pcu_id']