debuggers.hg

view tools/python/xen/xend/XendStorageRepository.py @ 0:7d21f7218375

Exact replica of unstable on 051908 + README-this
author Mukesh Rathor
date Mon May 19 15:34:57 2008 -0700 (2008-05-19)
parents
children b22f9ab1716a
line source
1 #!/usr/bin/python
2 #============================================================================
3 # This library is free software; you can redistribute it and/or
4 # modify it under the terms of version 2.1 of the GNU Lesser General Public
5 # License as published by the Free Software Foundation.
6 #
7 # This library is distributed in the hope that it will be useful,
8 # but WITHOUT ANY WARRANTY; without even the implied warranty of
9 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
10 # Lesser General Public License for more details.
11 #
12 # You should have received a copy of the GNU Lesser General Public
13 # License along with this library; if not, write to the Free Software
14 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
15 #============================================================================
16 # Copyright (C) 2006, 2007 XenSource Ltd.
17 #============================================================================
18 #
19 # Abstract class for XendStorageRepositories
20 #
22 import threading
23 import sys
25 from XendError import XendError
26 from XendVDI import *
27 from XendPBD import XendPBD
29 XEND_STORAGE_NO_MAXIMUM = sys.maxint
31 class XendStorageRepository:
32 """ Base class for Storage Repos. """
34 def __init__(self, uuid,
35 sr_type = "unknown",
36 name_label = 'Unknown',
37 name_description = 'Not Implemented',
38 storage_max = XEND_STORAGE_NO_MAXIMUM):
39 """
40 @keyword storage_max: Maximum disk space to use in bytes.
41 @type storage_max: int
43 @ivar storage_free: storage space free for this repository
44 @ivar images: mapping of all the images.
45 @type images: dictionary by image uuid.
46 @ivar lock: lock to provide thread safety.
47 """
49 # XenAPI Parameters
50 self.uuid = uuid
51 self.type = sr_type
52 self.name_label = name_label
53 self.name_description = name_description
54 self.images = {}
56 self.physical_size = storage_max
57 self.physical_utilisation = 0
58 self.virtual_allocation = 0
59 self.content_type = ''
61 self.lock = threading.RLock()
63 def get_record(self, transient = True):
64 retval = {'uuid': self.uuid,
65 'name_label': self.name_label,
66 'name_description': self.name_description,
67 'virtual_allocation': self.virtual_allocation,
68 'physical_utilisation': self.physical_utilisation,
69 'physical_size': self.physical_size,
70 'type': self.type,
71 'content_type': self.content_type,
72 'VDIs': self.images.keys()}
73 if not transient:
74 retval ['PBDs'] = XendPBD.get_by_SR(self.uuid)
75 return retval
78 def is_valid_vdi(self, vdi_uuid):
79 return (vdi_uuid in self.images)
81 def get_vdi_by_uuid(self, image_uuid):
82 self.lock.acquire()
83 try:
84 return self.images.get(image_uuid)
85 finally:
86 self.lock.release()
88 def get_vdi_by_name_label(self, label):
89 self.lock.acquire()
90 try:
91 for image_uuid, image in self.images.items():
92 if image.name_label == label:
93 return image_uuid
94 return None
95 finally:
96 self.lock.release()
98 def get_vdis(self):
99 return self.images.keys()
101 def create_vdi(self, vdi_struct):
102 raise NotImplementedError()
104 def destroy_vdi(self, vdi_struct):
105 raise NotImplementedError()