ia64/xen-unstable

view tools/python/xen/xend/XendAPIStore.py @ 19153:861ebefa7f39

XendAPIStore - do not remove non-existent item

If list is searched and item not found, then don't attempt to delete
the item.

Signed-off-by: Jim Fehlig <jfehlig@novell.com>
author Keir Fraser <keir.fraser@citrix.com>
date Wed Feb 04 11:57:17 2009 +0000 (2009-02-04)
parents ca5bfcd32e13
children c05fa254405d
line source
1 #============================================================================
2 # This library is free software; you can redistribute it and/or
3 # modify it under the terms of version 2.1 of the GNU Lesser General Public
4 # License as published by the Free Software Foundation.
5 #
6 # This library is distributed in the hope that it will be useful,
7 # but WITHOUT ANY WARRANTY; without even the implied warranty of
8 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
9 # Lesser General Public License for more details.
10 #
11 # You should have received a copy of the GNU Lesser General Public
12 # License along with this library; if not, write to the Free Software
13 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
14 #============================================================================
15 # Copyright (C) 2007 Tom Wilkie <tom.wilkie@gmail.com>
16 #============================================================================
17 """
18 This is a place to put instances of XenAPI objects,
19 instead of just holding them in arbitrary places.
21 All objects which subclass XendBase should use this
22 mechanism.
24 You must register both the uuid and type, and get objects
25 by type, to ensure safety
26 """
28 __classes = {}
30 def register(uuid, type, inst):
31 __classes[(uuid, type)] = inst
32 return inst
34 def deregister(uuid, type):
35 old = get(uuid, type)
36 if old is not None:
37 del __classes[(uuid, type)]
38 return old
40 def get(uuid, type):
41 """
42 Get the instances by uuid and type
43 """
44 return __classes.get((uuid, type), None)
46 def get_all(all_type):
47 """
48 Get all instances by type
49 """
50 return [inst
51 for ((uuid, t), inst) in __classes.items()
52 if t == all_type]
54 def get_all_uuid(all_type):
55 """
56 Get all uuids by type
57 """
58 return [uuid
59 for (uuid, t) in __classes.keys()
60 if t == all_type]