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

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

Add xen and xen-common

  • Property svn:mime-type set to text/script
File size: 3.5 KB
Line 
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#
21
22import threading
23import sys
24
25from XendError import XendError
26from XendVDI import *
27from XendPBD import XendPBD
28
29XEND_STORAGE_NO_MAXIMUM = sys.maxint
30
31class XendStorageRepository:
32    """ Base class for Storage Repos. """
33
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
42
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        """
48
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 = {}
55
56        self.physical_size = storage_max
57        self.physical_utilisation = 0
58        self.virtual_allocation = 0
59        self.content_type = ''
60 
61        self.lock = threading.RLock()
62
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
76
77
78    def is_valid_vdi(self, vdi_uuid):
79        return (vdi_uuid in self.images)
80
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()
87
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()
97
98    def get_vdis(self):
99        return self.images.keys()
100
101    def create_vdi(self, vdi_struct):
102        raise NotImplementedError()
103
104    def destroy_vdi(self, vdi_struct):
105        raise NotImplementedError()
Note: See TracBrowser for help on using the repository browser.