source: trunk/packages/xen-3.1/xen-3.1/tools/python/xen/xend/XendAPIStore.py @ 34

Last change on this file since 34 was 34, checked in by hartmans, 18 years ago

Add xen and xen-common

File size: 1.8 KB
Line 
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"""
18This is a place to put instances of XenAPI objects,
19instead of just holding them in arbitrary places.
20
21All objects which subclass XendBase should use this
22mechanism.
23
24You must register both the uuid and type, and get objects
25by type, to ensure safety
26"""
27
28__classes = {}
29
30def register(uuid, type, inst):
31    __classes[(uuid, type)] = inst
32    return inst
33
34def deregister(uuid, type):
35    old = get(uuid, type)
36    del __classes[(uuid, type)]
37    return old
38
39def get(uuid, type):
40    """
41    Get the instances by uuid and type
42    """
43    return __classes.get((uuid, type), None)
44
45def get_all(all_type):
46    """
47    Get all instances by type
48    """
49    return [inst
50            for ((uuid, t), inst) in __classes.items()
51            if t == all_type]       
52
53def get_all_uuid(all_type):
54    """
55    Get all uuids by type
56    """
57    return [uuid
58            for (uuid, t) in __classes.keys()
59            if t == all_type]
Note: See TracBrowser for help on using the repository browser.