X-Git-Url: http://git.onelab.eu/?a=blobdiff_plain;f=PLC%2FMethods%2FAddPCU.py;h=02fb2967accfeecb6986c7110f63eed42b5f13b8;hb=b2b1bed64f7427ec6a84fbb28250cba8f922c462;hp=d311e378506e501d4d3c7f123ffeb86bf4b9a037;hpb=f8e0c71d96dce99eff25e5bb6bdf941468e897a2;p=plcapi.git diff --git a/PLC/Methods/AddPCU.py b/PLC/Methods/AddPCU.py index d311e37..02fb296 100644 --- a/PLC/Methods/AddPCU.py +++ b/PLC/Methods/AddPCU.py @@ -1,12 +1,14 @@ +# $Id$ +# $URL$ 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 \ - ['hostname', 'protocol', + ['ip', 'hostname', 'protocol', 'username', 'password', 'model', 'notes'] @@ -23,27 +25,23 @@ class AddPCU(Method): roles = ['admin', 'pi', 'tech'] - update_fields = dict(filter(can_update, PCU.fields.items())) + pcu_fields = dict(filter(can_update, PCU.fields.items())) accepts = [ - PasswordAuth(), + Auth(), Mixed(Site.fields['site_id'], Site.fields['login_base']), - PCU.fields['ip'], - update_fields + pcu_fields ] returns = Parameter(int, 'New pcu_id (> 0) if successful') - - event_type = 'Add' - object_type = 'PCU' - object_ids = [] - def call(self, auth, site_id_or_login_base, ip, 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, [site_id_or_login_base]).values() + sites = Sites(self.api, [site_id_or_login_base]) if not sites: raise PLCInvalidArgument, "No such site" site = sites[0] @@ -54,8 +52,12 @@ class AddPCU(Method): pcu = PCU(self.api, pcu_fields) pcu['site_id'] = site['site_id'] - pcu['ip'] = ip pcu.sync() - self.object_ids = [pcu['pcu_id']] + + # Logging variables + self.event_objects = {'Site': [site['site_id']], + 'PCU': [pcu['pcu_id']]} + self.message = 'PCU %d added site %s' % \ + (pcu['pcu_id'], site['site_id']) return pcu['pcu_id']