From d0c553e8b3a7191514d56cb312552f325c67db90 Mon Sep 17 00:00:00 2001 From: Thierry Parmentelat Date: Wed, 24 Nov 2010 20:01:23 +0100 Subject: [PATCH] review (and fix) the way we retrieve the subject object --- PLC/Methods/DeleteInterfaceTag.py | 6 +++++- PLC/Methods/DeleteNodeTag.py | 6 +++++- PLC/Methods/DeletePersonTag.py | 5 ++++- PLC/Methods/DeleteSiteTag.py | 6 +++++- PLC/Methods/DeleteSliceTag.py | 2 +- PLC/Methods/UpdateInterfaceTag.py | 6 +++++- PLC/Methods/UpdateNodeTag.py | 6 +++++- PLC/Methods/UpdatePersonTag.py | 5 ++++- PLC/Methods/UpdateSiteTag.py | 6 +++++- PLC/Methods/UpdateSliceTag.py | 2 +- 10 files changed, 40 insertions(+), 10 deletions(-) diff --git a/PLC/Methods/DeleteInterfaceTag.py b/PLC/Methods/DeleteInterfaceTag.py index 1bb4aad..b1672a7 100644 --- a/PLC/Methods/DeleteInterfaceTag.py +++ b/PLC/Methods/DeleteInterfaceTag.py @@ -40,7 +40,11 @@ class DeleteInterfaceTag(Method): tag_type_id = interface_tag['tag_type_id'] tag_type = TagTypes (self.api,[tag_type_id])[0] - interface = Interfaces (self.api, interface_tag['interface_id']) + + interfaces = Interfaces (self.api, interface_tag['interface_id']) + if not interfaces: + raise PLCInvalidArgument, "No such interface %d"%interface_tag['interface_id'] + interface=interfaces[0] # check authorizations if 'admin' in self.caller['roles']: diff --git a/PLC/Methods/DeleteNodeTag.py b/PLC/Methods/DeleteNodeTag.py index 48b467f..019670c 100644 --- a/PLC/Methods/DeleteNodeTag.py +++ b/PLC/Methods/DeleteNodeTag.py @@ -42,7 +42,11 @@ class DeleteNodeTag(Method): tag_type_id = node_tag['tag_type_id'] tag_type = TagTypes (self.api,[tag_type_id])[0] - node = Nodes (self.api, node_tag['node_id']) + + nodes = Nodes (self.api, node_tag['node_id']) + if not nodes: + raise PLCInvalidArgument, "No such node %d"%node_tag['node_id'] + node=nodes[0] # check authorizations if 'admin' in self.caller['roles']: diff --git a/PLC/Methods/DeletePersonTag.py b/PLC/Methods/DeletePersonTag.py index ee4f6b3..5597785 100644 --- a/PLC/Methods/DeletePersonTag.py +++ b/PLC/Methods/DeletePersonTag.py @@ -35,7 +35,10 @@ class DeletePersonTag(Method): raise PLCInvalidArgument, "No such person tag %r"%person_tag_id person_tag = person_tags[0] - person = Persons (self.api, person_tag['person_id'])[0] + persons = Persons (self.api, person_tag['person_id']) + if not persons: + raise PLCInvalidArgument, "No such person %d"%person_tag['person_id'] + person=persons[0] # check authorizations if 'admin' in self.caller['roles']: diff --git a/PLC/Methods/DeleteSiteTag.py b/PLC/Methods/DeleteSiteTag.py index 6c31c1d..601b1c0 100644 --- a/PLC/Methods/DeleteSiteTag.py +++ b/PLC/Methods/DeleteSiteTag.py @@ -41,7 +41,11 @@ class DeleteSiteTag(Method): tag_type_id = site_tag['tag_type_id'] tag_type = TagTypes (self.api,[tag_type_id])[0] - site = Sites (self.api, site_tag['site_id']) + + sites = Sites (self.api, site_tag['site_id']) + if not sites: + raise PLCInvalidArgument, "No such site %d"%site_tag['site_id'] + site=sites[0] # check authorizations if 'admin' in self.caller['roles']: diff --git a/PLC/Methods/DeleteSliceTag.py b/PLC/Methods/DeleteSliceTag.py index d433e02..6cb58c3 100644 --- a/PLC/Methods/DeleteSliceTag.py +++ b/PLC/Methods/DeleteSliceTag.py @@ -42,7 +42,7 @@ class DeleteSliceTag(Method): slices = Slices(self.api, [slice_tag['slice_id']]) if not slices: - raise PLCInvalidArgument, "No such slice" + raise PLCInvalidArgument, "No such slice %d"%slice_tag['slice_id'] slice = slices[0] assert slice_tag['slice_tag_id'] in slice['slice_tag_ids'] diff --git a/PLC/Methods/UpdateInterfaceTag.py b/PLC/Methods/UpdateInterfaceTag.py index 1d52ea3..5370f7d 100644 --- a/PLC/Methods/UpdateInterfaceTag.py +++ b/PLC/Methods/UpdateInterfaceTag.py @@ -41,7 +41,11 @@ class UpdateInterfaceTag(Method): tag_type_id = interface_tag['tag_type_id'] tag_type = TagTypes (self.api,[tag_type_id])[0] - interface = Interfaces (self.api, interface_tag['interface_id']) + + interfaces = Interfaces (self.api, interface_tag['interface_id']) + if not interfaces: + raise PLCInvalidArgument, "No such interface %d"%interface_tag['interface_id'] + interface=interfaces[0] # check authorizations if 'admin' in self.caller['roles']: diff --git a/PLC/Methods/UpdateNodeTag.py b/PLC/Methods/UpdateNodeTag.py index d8b8af7..c3b4e28 100644 --- a/PLC/Methods/UpdateNodeTag.py +++ b/PLC/Methods/UpdateNodeTag.py @@ -43,7 +43,11 @@ class UpdateNodeTag(Method): tag_type_id = node_tag['tag_type_id'] tag_type = TagTypes (self.api,[tag_type_id])[0] - node = Nodes (self.api, node_tag['node_id']) + + nodes = Nodes (self.api, node_tag['node_id']) + if not nodes: + raise PLCInvalidArgument, "No such node %d"%node_tag['node_id'] + node=nodes[0] # check authorizations if 'admin' in self.caller['roles']: diff --git a/PLC/Methods/UpdatePersonTag.py b/PLC/Methods/UpdatePersonTag.py index 2a88179..176b22e 100644 --- a/PLC/Methods/UpdatePersonTag.py +++ b/PLC/Methods/UpdatePersonTag.py @@ -36,7 +36,10 @@ class UpdatePersonTag(Method): raise PLCInvalidArgument, "No such person setting %r"%person_tag_id person_tag = person_tags[0] - person = Persons (self.api, person_tag['person_id'])[0] + persons = Persons (self.api, person_tag['person_id']) + if not persons: + raise PLCInvalidArgument, "No such person %d"%person_tag['person_id'] + person=persons[0] # check authorizations if 'admin' in self.caller['roles']: diff --git a/PLC/Methods/UpdateSiteTag.py b/PLC/Methods/UpdateSiteTag.py index 733cb12..fd8f798 100644 --- a/PLC/Methods/UpdateSiteTag.py +++ b/PLC/Methods/UpdateSiteTag.py @@ -42,7 +42,11 @@ class UpdateSiteTag(Method): tag_type_id = site_tag['tag_type_id'] tag_type = TagTypes (self.api,[tag_type_id])[0] - site = Sites (self.api, site_tag['site_id']) + + sites = Sites (self.api, site_tag['site_id']) + if not sites: + raise PLCInvalidArgument, "No such site %d"%site_tag['site_id'] + site=sites[0] # check authorizations if 'admin' in self.caller['roles']: diff --git a/PLC/Methods/UpdateSliceTag.py b/PLC/Methods/UpdateSliceTag.py index 5e1123a..74d0271 100644 --- a/PLC/Methods/UpdateSliceTag.py +++ b/PLC/Methods/UpdateSliceTag.py @@ -44,7 +44,7 @@ class UpdateSliceTag(Method): slices = Slices(self.api, [slice_tag['slice_id']]) if not slices: - raise PLCInvalidArgument, "No such slice" + raise PLCInvalidArgument, "No such slice %d"%slice_tag['slice_id'] slice = slices[0] assert slice_tag['slice_tag_id'] in slice['slice_tag_ids'] -- 2.43.0