~ubuntu-branches/ubuntu/raring/nova/raring-proposed

« back to all changes in this revision

Viewing changes to nova/virt/disk/api.py

  • Committer: Package Import Robot
  • Author(s): Chuck Short, Adam Gandelman, Chuck Short
  • Date: 2012-11-23 09:04:58 UTC
  • mfrom: (1.1.66)
  • Revision ID: package-import@ubuntu.com-20121123090458-91565o7aev1i1h71
Tags: 2013.1~g1-0ubuntu1
[ Adam Gandelman ]
* debian/control: Ensure novaclient is upgraded with nova,
  require python-keystoneclient >= 1:2.9.0. (LP: #1073289)
* debian/patches/{ubuntu/*, rbd-security.patch}: Dropped, applied
  upstream.
* debian/control: Add python-testtools to Build-Depends.

[ Chuck Short ]
* New upstream version.
* Refreshed debian/patches/avoid_setuptools_git_dependency.patch.
* debian/rules: FTBFS if missing binaries.
* debian/nova-scheudler.install: Add missing rabbit-queues and
  nova-rpc-zmq-receiver.
* Remove nova-volume since it doesnt exist anymore, transition to cinder-*.
* debian/rules: install apport hook in the right place.
* debian/patches/ubuntu-show-tests.patch: Display test failures.
* debian/control: Add depends on genisoimage
* debian/control: Suggest guestmount.
* debian/control: Suggest websockify. (LP: #1076442)
* debian/nova.conf: Disable nova-volume service.
* debian/control: Depend on xen-system-* rather than the hypervisor.
* debian/control, debian/mans/nova-conductor.8, debian/nova-conductor.init,
  debian/nova-conductor.install, debian/nova-conductor.logrotate
  debian/nova-conductor.manpages, debian/nova-conductor.postrm
  debian/nova-conductor.upstart.in: Add nova-conductor service.
* debian/control: Add python-fixtures as a build deps.

Show diffs side-by-side

added added

removed removed

Lines of Context:
33
33
    import crypt
34
34
 
35
35
from nova import exception
36
 
from nova import flags
37
36
from nova.openstack.common import cfg
38
37
from nova.openstack.common import jsonutils
39
38
from nova.openstack.common import log as logging
40
39
from nova import utils
41
 
from nova.virt.disk import guestfs
42
 
from nova.virt.disk import loop
43
 
from nova.virt.disk import nbd
 
40
from nova.virt.disk.mount import guestfs
 
41
from nova.virt.disk.mount import loop
 
42
from nova.virt.disk.mount import nbd
44
43
from nova.virt import images
45
44
 
46
45
 
76
75
                         'The format is <os_type>=<mkfs command>'),
77
76
    ]
78
77
 
79
 
FLAGS = flags.FLAGS
80
 
FLAGS.register_opts(disk_opts)
 
78
CONF = cfg.CONF
 
79
CONF.register_opts(disk_opts)
 
80
CONF.import_opt('pybasedir', 'nova.config')
81
81
 
82
82
_MKFS_COMMAND = {}
83
83
_DEFAULT_MKFS_COMMAND = None
84
84
 
85
85
 
86
 
for s in FLAGS.virt_mkfs:
 
86
for s in CONF.virt_mkfs:
87
87
    # NOTE(yamahata): mkfs command may includes '=' for its options.
88
88
    #                 So item.partition('=') doesn't work here
89
89
    os_type, mkfs_command = s.split('=', 1)
112
112
    :returns: Size (in bytes) of the given disk image as it would be seen
113
113
              by a virtual machine.
114
114
    """
115
 
    size = images.qemu_img_info(path)['virtual size']
116
 
    size = size.split('(')[1].split()[0]
117
 
    return int(size)
 
115
    return images.qemu_img_info(path).virtual_size
118
116
 
119
117
 
120
118
def extend(image, size):
158
156
        utils.execute('touch', target, run_as_root=True)
159
157
        utils.execute('mount', '-o', 'bind', src, target,
160
158
                run_as_root=True)
161
 
        s = os.stat(src)
162
 
        cgroup_info = "b %s:%s rwm\n" % (os.major(s.st_rdev),
163
 
                                         os.minor(s.st_rdev))
164
 
        cgroups_path = ("/sys/fs/cgroup/devices/libvirt/lxc/"
165
 
                        "%s/devices.allow" % instance_name)
166
 
        utils.execute('tee', cgroups_path,
167
 
                      process_input=cgroup_info, run_as_root=True)
168
159
 
169
160
 
170
161
def unbind(target):
190
181
 
191
182
        # As a performance tweak, don't bother trying to
192
183
        # directly loopback mount a cow image.
193
 
        self.handlers = FLAGS.img_handlers[:]
 
184
        self.handlers = CONF.img_handlers[:]
194
185
        if use_cow and 'loop' in self.handlers:
195
186
            self.handlers.remove('loop')
196
187
 
208
199
    @staticmethod
209
200
    def _device_for_path(path):
210
201
        device = None
 
202
        path = os.path.realpath(path)
211
203
        with open("/proc/mounts", 'r') as ifp:
212
204
            for line in ifp:
213
205
                fields = line.split()
214
 
                if fields[1] == os.path.realpath(path):
 
206
                if fields[1] == path:
215
207
                    device = fields[0]
216
208
                    break
217
209
        return device
236
228
    @staticmethod
237
229
    def _handler_class(mode=None, device=None):
238
230
        """Look up the appropriate class to use based on MODE or DEVICE."""
239
 
        for cls in (loop.Mount, nbd.Mount, guestfs.Mount):
 
231
        for cls in (loop.LoopMount, nbd.NbdMount, guestfs.GuestFSMount):
240
232
            if mode and cls.mode == mode:
241
233
                return cls
242
234
            elif device and cls.device_id_string in device: