summaryrefslogtreecommitdiff
path: root/nova/virt/disk/mount/api.py
diff options
context:
space:
mode:
authorDaniel P. Berrange <berrange@redhat.com>2014-10-29 18:10:37 +0000
committerDaniel P. Berrange <berrange@redhat.com>2015-06-04 13:47:40 +0100
commit0ea510f5560516bdcbf9167be68be58ea1ee3a41 (patch)
tree2928cf37bdab5036542c87c487c8ad63726ce8aa /nova/virt/disk/mount/api.py
parent79af02046dab23ddb6399adfa8d9785694925be0 (diff)
virt: convert disk mount API to use nova.virt.image.model
Convert the nova.virt.disk.mount classes to use the nova.virt.image.model classes instead of manually passing a filename and image format as parameters. Related-Bug: #1257674 Change-Id: Ibabcf48c95185ba443ef7575590eae6a63e0f8e5
Notes
Notes (review): Verified+2: Jenkins Code-Review+2: Sean Dague <sean@dague.net> Workflow+1: Sean Dague <sean@dague.net> Code-Review+2: Nikola Dipanov <ndipanov@redhat.com> Verified+1: DB Datasets CI <turbo-hipster@lists.rcbops.com> Verified+1: XenProject CI <openstack-ci@xenproject.org> Submitted-by: Jenkins Submitted-at: Wed, 10 Jun 2015 18:55:25 +0000 Reviewed-on: https://review.openstack.org/132021 Project: openstack/nova Branch: refs/heads/master
Diffstat (limited to 'nova/virt/disk/mount/api.py')
-rw-r--r--nova/virt/disk/mount/api.py79
1 files changed, 59 insertions, 20 deletions
diff --git a/nova/virt/disk/mount/api.py b/nova/virt/disk/mount/api.py
index 60a8bbf..b952b96 100644
--- a/nova/virt/disk/mount/api.py
+++ b/nova/virt/disk/mount/api.py
@@ -19,8 +19,10 @@ import time
19from oslo_log import log as logging 19from oslo_log import log as logging
20from oslo_utils import importutils 20from oslo_utils import importutils
21 21
22from nova import exception
22from nova.i18n import _, _LI, _LW 23from nova.i18n import _, _LI, _LW
23from nova import utils 24from nova import utils
25from nova.virt.image import model as imgmodel
24 26
25LOG = logging.getLogger(__name__) 27LOG = logging.getLogger(__name__)
26 28
@@ -37,42 +39,79 @@ class Mount(object):
37 mode = None # to be overridden in subclasses 39 mode = None # to be overridden in subclasses
38 40
39 @staticmethod 41 @staticmethod
40 def instance_for_format(imgfile, mountdir, partition, imgfmt): 42 def instance_for_format(image, mountdir, partition):
41 LOG.debug("Instance for format imgfile=%(imgfile)s " 43 """Get a Mount instance for the image type
42 "mountdir=%(mountdir)s partition=%(partition)s " 44
43 "imgfmt=%(imgfmt)s", 45 :param image: instance of nova.virt.image.model.Image
44 {'imgfile': imgfile, 'mountdir': mountdir, 46 :param mountdir: path to mount the image at
45 'partition': partition, 'imgfmt': imgfmt}) 47 :param partition: partition number to mount
46 if imgfmt == "raw": 48 """
47 LOG.debug("Using LoopMount") 49 LOG.debug("Instance for format image=%(image)s "
48 return importutils.import_object( 50 "mountdir=%(mountdir)s partition=%(partition)s",
49 "nova.virt.disk.mount.loop.LoopMount", 51 {'image': image, 'mountdir': mountdir,
50 imgfile, mountdir, partition) 52 'partition': partition})
53
54 if isinstance(image, imgmodel.LocalFileImage):
55 if image.format == imgmodel.FORMAT_RAW:
56 LOG.debug("Using LoopMount")
57 return importutils.import_object(
58 "nova.virt.disk.mount.loop.LoopMount",
59 image, mountdir, partition)
60 else:
61 LOG.debug("Using NbdMount")
62 return importutils.import_object(
63 "nova.virt.disk.mount.nbd.NbdMount",
64 image, mountdir, partition)
51 else: 65 else:
52 LOG.debug("Using NbdMount") 66 # TODO(berrange) we could mount images of
53 return importutils.import_object( 67 # type LocalBlockImage directly without
54 "nova.virt.disk.mount.nbd.NbdMount", 68 # involving loop or nbd devices
55 imgfile, mountdir, partition) 69 #
70 # We could also mount RBDImage directly
71 # using kernel RBD block dev support.
72 #
73 # This is left as an enhancement for future
74 # motivated developers todo, since raising
75 # an exception is on par with what this
76 # code did historically
77 raise exception.UnsupportedImageModel(
78 image.__class__.__name__)
56 79
57 @staticmethod 80 @staticmethod
58 def instance_for_device(imgfile, mountdir, partition, device): 81 def instance_for_device(image, mountdir, partition, device):
59 LOG.debug("Instance for device imgfile=%(imgfile)s " 82 """Get a Mount instance for the device type
83
84 :param image: instance of nova.virt.image.model.Image
85 :param mountdir: path to mount the image at
86 :param partition: partition number to mount
87 :param device: mounted device path
88 """
89
90 LOG.debug("Instance for device image=%(image)s "
60 "mountdir=%(mountdir)s partition=%(partition)s " 91 "mountdir=%(mountdir)s partition=%(partition)s "
61 "device=%(device)s", 92 "device=%(device)s",
62 {'imgfile': imgfile, 'mountdir': mountdir, 93 {'image': image, 'mountdir': mountdir,
63 'partition': partition, 'device': device}) 94 'partition': partition, 'device': device})
95
64 if "loop" in device: 96 if "loop" in device:
65 LOG.debug("Using LoopMount") 97 LOG.debug("Using LoopMount")
66 return importutils.import_object( 98 return importutils.import_object(
67 "nova.virt.disk.mount.loop.LoopMount", 99 "nova.virt.disk.mount.loop.LoopMount",
68 imgfile, mountdir, partition, device) 100 image, mountdir, partition, device)
69 else: 101 else:
70 LOG.debug("Using NbdMount") 102 LOG.debug("Using NbdMount")
71 return importutils.import_object( 103 return importutils.import_object(
72 "nova.virt.disk.mount.nbd.NbdMount", 104 "nova.virt.disk.mount.nbd.NbdMount",
73 imgfile, mountdir, partition, device) 105 image, mountdir, partition, device)
74 106
75 def __init__(self, image, mount_dir, partition=None, device=None): 107 def __init__(self, image, mount_dir, partition=None, device=None):
108 """Create a new Mount instance
109
110 :param image: instance of nova.virt.image.model.Image
111 :param mount_dir: path to mount the image at
112 :param partition: partition number to mount
113 :param device: mounted device path
114 """
76 115
77 # Input 116 # Input
78 self.image = image 117 self.image = image