~ubuntu-branches/ubuntu/quantal/virtinst/quantal-proposed

« back to all changes in this revision

Viewing changes to virtinst/Storage.py

  • Committer: Bazaar Package Importer
  • Author(s): Marc Deslauriers
  • Date: 2011-02-01 15:40:11 UTC
  • mfrom: (1.3.16 experimental)
  • Revision ID: james.westby@ubuntu.com-20110201154011-op0nusgc240xajvb
Tags: 0.500.5-1ubuntu1
* Merge from debian experimental. Remaining changes:
  - debian/patches/9001_Ubuntu.patch:
     + Updated to add maverick and natty to OS list and enable virtio
       for them.
  - debian/patches/9003-fix-path-to-hvmloader-in-testsuite.patch: adjust
    testsuite for 0001-fix-path-to-hvmloader.patch and
    0002-Fix-path-to-pygrub.patch. (refreshed)
  - debian/control: added acl package to depends.
  - Demote virt-viewer to Suggests, as it's in universe.
  - Recommends libvirt-bin
* Removed patches:
  - debian/patches/9002-libvirt_disk_format.patch: Upstream.

Show diffs side-by-side

added added

removed removed

Lines of Context:
48
48
import libvirt
49
49
import threading
50
50
import time
 
51
import os
51
52
 
52
53
import logging
53
54
from _util import xml_escape as escape
120
121
        Initialize storage object parameters
121
122
        """
122
123
        if object_type not in [self.TYPE_POOL, self.TYPE_VOLUME]:
123
 
            raise ValueError, _("Unknown storage object type: %s") % type
 
124
            raise ValueError(_("Unknown storage object type: %s") % type)
124
125
        self._object_type = object_type
125
126
        self._conn = None
126
127
        self._name = None
181
182
 
182
183
    def _check_name_collision(self, name):
183
184
        ignore = name
184
 
        raise RuntimeError, "Must be implemented in subclass"
 
185
        raise NotImplementedError()
185
186
 
186
187
    # XML Building
187
188
    def _get_storage_xml(self):
188
189
        """
189
190
        Returns the pool/volume specific xml blob
190
191
        """
191
 
        raise RuntimeError, "Must be implemented in subclass"
 
192
        raise NotImplementedError()
192
193
 
193
194
    def _get_perms_xml(self):
194
195
        perms = self.get_perms()
195
196
        if not perms:
196
197
            return ""
197
 
        xml =  "    <permissions>\n" + \
198
 
               "      <mode>0%o</mode>\n" % perms["mode"] + \
199
 
               "      <owner>%d</owner>\n" % perms["owner"] + \
200
 
               "      <group>%d</group>\n" % perms["group"]
 
198
        xml = "    <permissions>\n" + \
 
199
              "      <mode>0%o</mode>\n" % perms["mode"] + \
 
200
              "      <owner>%d</owner>\n" % perms["owner"] + \
 
201
              "      <group>%d</group>\n" % perms["group"]
201
202
 
202
 
        if perms.has_key("label"):
 
203
        if "label" in perms:
203
204
            xml += "      <label>%s</label>\n" % perms["label"]
204
205
 
205
206
        xml += "    </permissions>\n"
260
261
        @type ptype: C{str} member of L{Types}
261
262
        """
262
263
        if ptype not in StoragePool._types:
263
 
            raise ValueError, _("Unknown storage pool type: %s" % ptype)
 
264
            raise ValueError(_("Unknown storage pool type: %s" % ptype))
264
265
        if ptype == StoragePool.TYPE_DIR:
265
266
            return DirectoryPool
266
267
        if ptype == StoragePool.TYPE_FS:
290
291
 
291
292
    def get_pool_type_desc(pool_type):
292
293
        """Return human readable description for passed pool type"""
293
 
        if StoragePool._types.has_key(pool_type):
 
294
        if pool_type in StoragePool._types:
294
295
            return StoragePool._types[pool_type]
295
296
        else:
296
297
            return "%s pool" % pool_type
346
347
                               name=name, conn=conn)
347
348
 
348
349
        if type not in self.get_pool_types():
349
 
            raise ValueError, _("Unknown storage pool type: %s" % type)
 
350
            raise ValueError(_("Unknown storage pool type: %s" % type))
350
351
        self._type = type
351
352
        self._target_path = None
352
353
        self._host = None
376
377
        return self._target_path
377
378
    def set_target_path(self, val):
378
379
        self._validate_path(val)
379
 
        self._target_path = val
 
380
        self._target_path = os.path.abspath(val)
380
381
 
381
382
    # Get/Set methods for use by some pools. Will be registered when applicable
382
383
    def get_source_path(self):
383
384
        return self._source_path
384
385
    def set_source_path(self, val):
385
386
        self._validate_path(val)
386
 
        self._source_path = val
 
387
        self._source_path = os.path.abspath(val)
387
388
 
388
389
    def get_host(self):
389
390
        return self._host
412
413
                                name))
413
414
 
414
415
    def _get_default_target_path(self):
415
 
        raise RuntimeError, "Must be implemented in subclass"
 
416
        raise NotImplementedError()
416
417
 
417
418
    # XML Building
418
419
    def _get_target_xml(self):
419
 
        raise RuntimeError, "Must be implemented in subclass"
 
420
        raise NotImplementedError()
420
421
 
421
422
    def _get_source_xml(self):
422
 
        raise RuntimeError, "Must be implemented in subclass"
 
423
        raise NotImplementedError()
423
424
 
424
425
    def _get_storage_xml(self):
425
426
        src_xml = ""
727
728
    def install(self, meter=None, create=False, build=False):
728
729
        if build and not self.source_path:
729
730
            raise ValueError(_("Must explicitly specify source path if "
730
 
                               "building' pool"))
 
731
                               "building pool"))
731
732
        return StoragePool.install(self, meter=meter, create=create,
732
733
                                   build=build)
733
734
 
1056
1057
        return self._pool
1057
1058
    def set_pool(self, newpool):
1058
1059
        if not isinstance(newpool, libvirt.virStoragePool):
1059
 
            raise ValueError, _("'pool' must be a virStoragePool instance.")
 
1060
            raise ValueError(_("'pool' must be a virStoragePool instance."))
1060
1061
        if newpool.info()[0] != libvirt.VIR_STORAGE_POOL_RUNNING:
1061
 
            raise ValueError, _("pool '%s' must be active." % newpool.name())
 
1062
            raise ValueError(_("pool '%s' must be active." % newpool.name()))
1062
1063
        self._pool = newpool
1063
1064
    pool = property(get_pool, set_pool)
1064
1065
 
1109
1110
 
1110
1111
    # xml building functions
1111
1112
    def _get_target_xml(self):
1112
 
        raise RuntimeError, "Must be implemented in subclass"
 
1113
        raise NotImplementedError()
1113
1114
 
1114
1115
    def _get_source_xml(self):
1115
 
        raise RuntimeError, "Must be implemented in subclass"
 
1116
        raise NotImplementedError()
1116
1117
 
1117
1118
    def _get_storage_xml(self):
1118
1119
        src_xml = ""
1214
1215
            return (True, _("There is not enough free space on the storage "
1215
1216
                            "pool to create the volume. "
1216
1217
                            "(%d M requested allocation > %d M available)" % \
1217
 
                            ((self.allocation/(1024*1024)),
1218
 
                             (avail/(1024*1024)))))
 
1218
                            ((self.allocation / (1024 * 1024)),
 
1219
                             (avail / (1024 * 1024)))))
1219
1220
        elif self.capacity > avail:
1220
1221
            return (False, _("The requested volume capacity will exceed the "
1221
1222
                             "available pool space when the volume is fully "
1222
1223
                             "allocated. "
1223
1224
                             "(%d M requested capacity > %d M available)" % \
1224
 
                             ((self.capacity/(1024*1024)),
1225
 
                              (avail/(1024*1024)))))
 
1225
                             ((self.capacity / (1024 * 1024)),
 
1226
                              (avail / (1024 * 1024)))))
1226
1227
        return (False, "")
1227
1228
 
1228
1229
class FileVolume(StorageVolume):
1231
1232
    """
1232
1233
    _file_type = VIR_STORAGE_VOL_FILE
1233
1234
 
1234
 
    formats = ["raw", "bochs", "cloop", "cow", "dmg", "iso", "qcow",\
 
1235
    formats = ["raw", "bochs", "cloop", "cow", "dmg", "iso", "qcow",
1235
1236
               "qcow2", "vmdk", "vpc"]
1236
1237
 
1237
1238
    # Register applicable property methods from parent class
1328
1329
        self._file_type = typ
1329
1330
        self._format = fmt
1330
1331
 
 
1332
    def _get_target_xml(self):
 
1333
        return ""
 
1334
    def _get_source_xml(self):
 
1335
        return ""
 
1336
 
1331
1337
    def get_xml_config(self):
1332
1338
        xml  = self.input_vol.XMLDesc(0)
1333
1339
        newxml = _util.set_xml_path(xml, "/volume/name", self.name)
1341
1347
#
1342
1348
#    def __init__(self, *args, **kwargs):
1343
1349
#        raise NotImplementedError
1344