summaryrefslogtreecommitdiffstats
path: root/nova/virt
diff options
context:
space:
mode:
authorMichael Still <mikal@stillhq.com>2012-10-23 14:25:25 -0700
committerMichael Still <mikal@stillhq.com>2012-10-25 09:20:46 +1100
commit0d4e6dbe6f17d0a8d0f93833c1ea70f79944d945 (patch)
treecdd80ba89da8567c5e1abc82a0ede862d6dd578d /nova/virt
parent86b91474d16fb9842bb75dc7ebd1af364cc8a058 (diff)
Migrate to fileutils and lockutils.
Migrate nova to using openstack-common's file and lock utilities. Resolves bug 1063230. Change-Id: I1a4c87856bc08cd33b61d7098ed856baa4583654
Diffstat (limited to 'nova/virt')
-rw-r--r--nova/virt/baremetal/driver.py10
-rw-r--r--nova/virt/configdrive.py3
-rw-r--r--nova/virt/firewall.py6
-rw-r--r--nova/virt/hyperv/vmops.py4
-rw-r--r--nova/virt/libvirt/driver.py7
-rw-r--r--nova/virt/libvirt/imagebackend.py16
-rw-r--r--nova/virt/libvirt/utils.py3
-rw-r--r--nova/virt/libvirt/volume.py5
8 files changed, 33 insertions, 21 deletions
diff --git a/nova/virt/baremetal/driver.py b/nova/virt/baremetal/driver.py
index 544e38c17..166eacba6 100644
--- a/nova/virt/baremetal/driver.py
+++ b/nova/virt/baremetal/driver.py
@@ -42,6 +42,8 @@ from nova import exception
from nova import flags
from nova import notifications
from nova.openstack.common import cfg
+from nova.openstack.common import fileutils
+from nova.openstack.common import lockutils
from nova.openstack.common import log as logging
from nova import utils
from nova.virt.baremetal import dom
@@ -303,10 +305,10 @@ class BareMetalDriver(driver.ComputeDriver):
if not os.path.exists(target):
base_dir = os.path.join(FLAGS.instances_path, '_base')
if not os.path.exists(base_dir):
- utils.ensure_tree(base_dir)
+ fileutils.ensure_tree(base_dir)
base = os.path.join(base_dir, fname)
- @utils.synchronized(fname)
+ @lockutils.synchronized(fname, 'nova-')
def call_if_not_exists(base, fetch_func, *args, **kwargs):
if not os.path.exists(base):
fetch_func(target=base, *args, **kwargs)
@@ -331,7 +333,7 @@ class BareMetalDriver(driver.ComputeDriver):
fname + suffix)
# ensure directories exist and are writable
- utils.ensure_tree(basepath(suffix=''))
+ fileutils.ensure_tree(basepath(suffix=''))
utils.execute('chmod', '0777', basepath(suffix=''))
LOG.info(_('instance %s: Creating image'), inst['name'],
@@ -339,7 +341,7 @@ class BareMetalDriver(driver.ComputeDriver):
if FLAGS.baremetal_type == 'lxc':
container_dir = '%s/rootfs' % basepath(suffix='')
- utils.ensure_tree(container_dir)
+ fileutils.ensure_tree(container_dir)
# NOTE(vish): No need add the suffix to console.log
libvirt_utils.write_to_file(basepath('console.log', ''), '', 007)
diff --git a/nova/virt/configdrive.py b/nova/virt/configdrive.py
index 86ef13ed0..7b4cb718b 100644
--- a/nova/virt/configdrive.py
+++ b/nova/virt/configdrive.py
@@ -24,6 +24,7 @@ import tempfile
from nova import exception
from nova import flags
from nova.openstack.common import cfg
+from nova.openstack.common import fileutils
from nova.openstack.common import log as logging
from nova import utils
from nova import version
@@ -66,7 +67,7 @@ class ConfigDriveBuilder(object):
def _add_file(self, path, data):
filepath = os.path.join(self.tempdir, path)
dirname = os.path.dirname(filepath)
- utils.ensure_tree(dirname)
+ fileutils.ensure_tree(dirname)
with open(filepath, 'w') as f:
f.write(data)
diff --git a/nova/virt/firewall.py b/nova/virt/firewall.py
index 3e2ba5d33..d066a9c21 100644
--- a/nova/virt/firewall.py
+++ b/nova/virt/firewall.py
@@ -24,8 +24,8 @@ from nova import network
from nova.network import linux_net
from nova.openstack.common import cfg
from nova.openstack.common import importutils
+from nova.openstack.common import lockutils
from nova.openstack.common import log as logging
-from nova import utils
from nova.virt import netutils
@@ -430,7 +430,7 @@ class IptablesFirewallDriver(FirewallDriver):
self.do_refresh_instance_rules(instance)
self.iptables.apply()
- @utils.synchronized('iptables', external=True)
+ @lockutils.synchronized('iptables', 'nova-', external=True)
def _inner_do_refresh_rules(self, instance, ipv4_rules,
ipv6_rules):
self.remove_filters_for_instance(instance)
@@ -453,7 +453,7 @@ class IptablesFirewallDriver(FirewallDriver):
self._do_refresh_provider_fw_rules()
self.iptables.apply()
- @utils.synchronized('iptables', external=True)
+ @lockutils.synchronized('iptables', 'nova-', external=True)
def _do_refresh_provider_fw_rules(self):
"""Internal, synchronized version of refresh_provider_fw_rules."""
self._purge_provider_fw_rules()
diff --git a/nova/virt/hyperv/vmops.py b/nova/virt/hyperv/vmops.py
index 8c86016c2..92d9a408a 100644
--- a/nova/virt/hyperv/vmops.py
+++ b/nova/virt/hyperv/vmops.py
@@ -27,8 +27,8 @@ from nova import db
from nova import exception
from nova import flags
from nova.openstack.common import cfg
+from nova.openstack.common import lockutils
from nova.openstack.common import log as logging
-from nova import utils
from nova.virt.hyperv import baseops
from nova.virt.hyperv import constants
from nova.virt.hyperv import vmutils
@@ -595,7 +595,7 @@ class VMOps(baseops.BaseOps):
If cow is True, it will make a CoW image instead of a copy.
"""
- @utils.synchronized(fname)
+ @lockutils.synchronized(fname, 'nova-')
def call_if_not_exists(path, fn, *args, **kwargs):
if not os.path.exists(path):
fn(target=path, *args, **kwargs)
diff --git a/nova/virt/libvirt/driver.py b/nova/virt/libvirt/driver.py
index 34d667c16..1df29c50e 100644
--- a/nova/virt/libvirt/driver.py
+++ b/nova/virt/libvirt/driver.py
@@ -67,6 +67,7 @@ from nova import flags
from nova.image import glance
from nova.openstack.common import cfg
from nova.openstack.common import excutils
+from nova.openstack.common import fileutils
from nova.openstack.common import importutils
from nova.openstack.common import jsonutils
from nova.openstack.common import log as logging
@@ -841,7 +842,7 @@ class LibvirtDriver(driver.ComputeDriver):
# Export the snapshot to a raw image
snapshot_directory = FLAGS.libvirt_snapshots_directory
- utils.ensure_tree(snapshot_directory)
+ fileutils.ensure_tree(snapshot_directory)
with utils.tempdir(dir=snapshot_directory) as tmpdir:
try:
out_path = os.path.join(tmpdir, snapshot_name)
@@ -1258,7 +1259,7 @@ class LibvirtDriver(driver.ComputeDriver):
return image(fname, image_type='raw')
# ensure directories exist and are writable
- utils.ensure_tree(basepath(suffix=''))
+ fileutils.ensure_tree(basepath(suffix=''))
LOG.info(_('Creating image'), instance=instance)
libvirt_utils.write_to_file(basepath('libvirt.xml'), libvirt_xml)
@@ -1267,7 +1268,7 @@ class LibvirtDriver(driver.ComputeDriver):
container_dir = os.path.join(FLAGS.instances_path,
instance['name'],
'rootfs')
- utils.ensure_tree(container_dir)
+ fileutils.ensure_tree(container_dir)
# NOTE(dprince): for rescue console.log may already exist... chown it.
self._chown_console_log_for_instance(instance['name'])
diff --git a/nova/virt/libvirt/imagebackend.py b/nova/virt/libvirt/imagebackend.py
index 040884e17..3dc8e2037 100644
--- a/nova/virt/libvirt/imagebackend.py
+++ b/nova/virt/libvirt/imagebackend.py
@@ -22,6 +22,8 @@ import os
from nova import flags
from nova.openstack.common import cfg
from nova.openstack.common import excutils
+from nova.openstack.common import fileutils
+from nova.openstack.common import lockutils
from nova import utils
from nova.virt.disk import api as disk
from nova.virt.libvirt import config
@@ -112,7 +114,8 @@ class Image(object):
:filename: Name of the file in the image directory
:size: Size of created image in bytes (optional)
"""
- @utils.synchronized(filename, external=True, lock_path=self.lock_path)
+ @lockutils.synchronized(filename, 'nova-', external=True,
+ lock_path=self.lock_path)
def call_if_not_exists(target, *args, **kwargs):
if not os.path.exists(target):
fetch_func(target=target, *args, **kwargs)
@@ -120,7 +123,7 @@ class Image(object):
if not os.path.exists(self.path):
base_dir = os.path.join(FLAGS.instances_path, '_base')
if not os.path.exists(base_dir):
- utils.ensure_tree(base_dir)
+ fileutils.ensure_tree(base_dir)
base = os.path.join(base_dir, filename)
self.create_image(call_if_not_exists, base, size,
@@ -143,7 +146,8 @@ class Raw(Image):
instance, name)
def create_image(self, prepare_template, base, size, *args, **kwargs):
- @utils.synchronized(base, external=True, lock_path=self.lock_path)
+ @lockutils.synchronized(base, 'nova-', external=True,
+ lock_path=self.lock_path)
def copy_raw_image(base, target, size):
libvirt_utils.copy_image(base, target)
if size:
@@ -170,7 +174,8 @@ class Qcow2(Image):
instance, name)
def create_image(self, prepare_template, base, size, *args, **kwargs):
- @utils.synchronized(base, external=True, lock_path=self.lock_path)
+ @lockutils.synchronized(base, 'nova-', external=True,
+ lock_path=self.lock_path)
def copy_qcow2_image(base, target, size):
qcow2_base = base
if size:
@@ -216,7 +221,8 @@ class Lvm(Image):
self.sparse = FLAGS.libvirt_sparse_logical_volumes
def create_image(self, prepare_template, base, size, *args, **kwargs):
- @utils.synchronized(base, external=True, lock_path=self.lock_path)
+ @lockutils.synchronized(base, 'nova-', external=True,
+ lock_path=self.lock_path)
def create_lvm_image(base, size):
base_size = disk.get_disk_size(base)
resize = size > base_size
diff --git a/nova/virt/libvirt/utils.py b/nova/virt/libvirt/utils.py
index 782eec2bd..fe54cacec 100644
--- a/nova/virt/libvirt/utils.py
+++ b/nova/virt/libvirt/utils.py
@@ -28,6 +28,7 @@ from lxml import etree
from nova import exception
from nova import flags
from nova.openstack.common import cfg
+from nova.openstack.common import fileutils
from nova.openstack.common import jsonutils
from nova.openstack.common import log as logging
from nova import utils
@@ -523,7 +524,7 @@ def write_stored_info(target, field=None, value=None):
return
info_file = get_info_filename(target)
- utils.ensure_tree(os.path.dirname(info_file))
+ fileutils.ensure_tree(os.path.dirname(info_file))
d = read_stored_info(info_file)
d[field] = value
diff --git a/nova/virt/libvirt/volume.py b/nova/virt/libvirt/volume.py
index 2a018c724..fd10f431b 100644
--- a/nova/virt/libvirt/volume.py
+++ b/nova/virt/libvirt/volume.py
@@ -22,6 +22,7 @@ import time
from nova import exception
from nova import flags
+from nova.openstack.common import lockutils
from nova.openstack.common import log as logging
from nova import utils
from nova.virt.libvirt import config
@@ -123,7 +124,7 @@ class LibvirtISCSIVolumeDriver(LibvirtVolumeDriver):
'-v', property_value)
return self._run_iscsiadm(iscsi_properties, iscsi_command, **kwargs)
- @utils.synchronized('connect_volume')
+ @lockutils.synchronized('connect_volume', 'nova-')
def connect_volume(self, connection_info, mount_device):
"""Attach the volume to instance_name"""
iscsi_properties = connection_info['data']
@@ -193,7 +194,7 @@ class LibvirtISCSIVolumeDriver(LibvirtVolumeDriver):
sup = super(LibvirtISCSIVolumeDriver, self)
return sup.connect_volume(connection_info, mount_device)
- @utils.synchronized('connect_volume')
+ @lockutils.synchronized('connect_volume', 'nova-')
def disconnect_volume(self, connection_info, mount_device):
"""Detach the volume from instance_name"""
sup = super(LibvirtISCSIVolumeDriver, self)