CONF.register_opts(util_opts)
+def set_defaults(lock_path):
+ cfg.set_defaults(util_opts, lock_path=lock_path)
+
+
class _InterProcessLock(object):
"""Lock implementation which allows multiple locks, working around
issues like bugs.debian.org/cgi-bin/bugreport.cgi?bug=632857 and does
# to have a laughable 10 attempts "blocking" mechanism.
self.trylock()
return self
- except IOError, e:
+ except IOError as e:
if e.errno in (errno.EACCES, errno.EAGAIN):
# external locks synchronise things like iptables
# updates - give it some time to prevent busy spinning
return retval
return inner
return wrap
+
+
+def synchronized_with_prefix(lock_file_prefix):
+ """Partial object generator for the synchronization decorator.
+
+ Redefine @synchronized in each project like so::
+
+ (in nova/utils.py)
+ from nova.openstack.common import lockutils
+
+ synchronized = lockutils.synchronized_with_prefix('nova-')
+
+
+ (in nova/foo.py)
+ from nova import utils
+
+ @utils.synchronized('mylock')
+ def bar(self, *args):
+ ...
+
+ The lock_file_prefix argument is used to provide lock files on disk with a
+ meaningful prefix. The prefix should end with a hyphen ('-') if specified.
+ """
+
+ return functools.partial(synchronized, lock_file_prefix=lock_file_prefix)
from cinder import flags
from cinder.openstack.common import excutils
from cinder.openstack.common import importutils
+from cinder.openstack.common import lockutils
from cinder.openstack.common import log as logging
from cinder.openstack.common import timeutils
PERFECT_TIME_FORMAT = "%Y-%m-%dT%H:%M:%S.%f"
FLAGS = flags.FLAGS
+synchronized = lockutils.synchronized_with_prefix('cinder-')
+
def find_config(config_path):
"""Find a configuration file using the given hint.
from suds.sax import text
from cinder import exception
-from cinder.openstack.common import lockutils
from cinder.openstack.common import log as logging
+from cinder import utils
from cinder.volume import driver
from cinder.volume.drivers.netapp.api import NaApiError
from cinder.volume.drivers.netapp.api import NaElement
self.discovered_datasets.append(ds)
return ds
- @lockutils.synchronized('netapp_dfm', 'cinder-', True)
+ @utils.synchronized('netapp_dfm', external=True)
def _provision(self, name, description, project, ss_type, size):
"""Provision a LUN through provisioning manager.
return None
return volume_type['name']
- @lockutils.synchronized('netapp_dfm', 'cinder-', True)
+ @utils.synchronized('netapp_dfm', external=True)
def _remove_destroy(self, name, project):
"""Remove the LUN from the dataset, also destroying it.
from cinder import context
from cinder import exception
-from cinder.openstack.common import lockutils
from cinder.openstack.common import log as logging
from cinder import utils
from cinder.volume import volume_types
return status
- @lockutils.synchronized('3parclone', 'cinder-', True)
+ @utils.synchronized('3parclone', external=True)
def create_cloned_volume(self, volume, src_vref, client):
try:
from oslo.config import cfg
from cinder import exception
-from cinder.openstack.common import lockutils
from cinder.openstack.common import log as logging
+from cinder import utils
import cinder.volume.driver
from cinder.volume.drivers.san.hp import hp_3par_common as hpcommon
from cinder.volume.drivers.san import san
"""Returns an error if prerequisites aren't met."""
self._check_flags()
- @lockutils.synchronized('3par-vol', 'cinder-', True)
+ @utils.synchronized('3par-vol', external=True)
def create_volume(self, volume):
metadata = self.common.create_volume(volume, self.client)
return {'metadata': metadata}
self.client)
return {'metadata': new_vol}
- @lockutils.synchronized('3par-vol', 'cinder-', True)
+ @utils.synchronized('3par-vol', external=True)
def delete_volume(self, volume):
self.common.delete_volume(volume, self.client)
- @lockutils.synchronized('3par-vol', 'cinder-', True)
+ @utils.synchronized('3par-vol', external=True)
def create_volume_from_snapshot(self, volume, snapshot):
"""
Creates a volume from a snapshot.
"""
self.common.create_volume_from_snapshot(volume, snapshot, self.client)
- @lockutils.synchronized('3par-snap', 'cinder-', True)
+ @utils.synchronized('3par-snap', external=True)
def create_snapshot(self, snapshot):
self.common.create_snapshot(snapshot, self.client)
- @lockutils.synchronized('3par-snap', 'cinder-', True)
+ @utils.synchronized('3par-snap', external=True)
def delete_snapshot(self, snapshot):
self.common.delete_snapshot(snapshot, self.client)
- @lockutils.synchronized('3par-attach', 'cinder-', True)
+ @utils.synchronized('3par-attach', external=True)
def initialize_connection(self, volume, connector):
"""Assigns the volume to a server.
'target_wwn': ports['FC']}}
return info
- @lockutils.synchronized('3par-attach', 'cinder-', True)
+ @utils.synchronized('3par-attach', external=True)
def terminate_connection(self, volume, connector, force):
"""
Driver entry point to unattach a volume from an instance.
return host
- @lockutils.synchronized('3par-exp', 'cinder-', True)
+ @utils.synchronized('3par-exp', external=True)
def create_export(self, context, volume):
pass
- @lockutils.synchronized('3par-exp', 'cinder-', True)
+ @utils.synchronized('3par-exp', external=True)
def ensure_export(self, context, volume):
pass
- @lockutils.synchronized('3par-exp', 'cinder-', True)
+ @utils.synchronized('3par-exp', external=True)
def remove_export(self, context, volume):
pass
from hp3parclient import exceptions as hpexceptions
from cinder import exception
-from cinder.openstack.common import lockutils
from cinder.openstack.common import log as logging
+from cinder import utils
import cinder.volume.driver
from cinder.volume.drivers.san.hp import hp_3par_common as hpcommon
from cinder.volume.drivers.san import san
"""Returns an error if prerequisites aren't met."""
self._check_flags()
- @lockutils.synchronized('3par-vol', 'cinder-', True)
+ @utils.synchronized('3par-vol', external=True)
def create_volume(self, volume):
metadata = self.common.create_volume(volume, self.client)
self.configuration.iscsi_port),
'metadata': new_vol}
- @lockutils.synchronized('3par-vol', 'cinder-', True)
+ @utils.synchronized('3par-vol', external=True)
def delete_volume(self, volume):
self.common.delete_volume(volume, self.client)
- @lockutils.synchronized('3par-vol', 'cinder-', True)
+ @utils.synchronized('3par-vol', external=True)
def create_volume_from_snapshot(self, volume, snapshot):
"""
Creates a volume from a snapshot.
"""
self.common.create_volume_from_snapshot(volume, snapshot, self.client)
- @lockutils.synchronized('3par-snap', 'cinder-', True)
+ @utils.synchronized('3par-snap', external=True)
def create_snapshot(self, snapshot):
self.common.create_snapshot(snapshot, self.client)
- @lockutils.synchronized('3par-snap', 'cinder-', True)
+ @utils.synchronized('3par-snap', external=True)
def delete_snapshot(self, snapshot):
self.common.delete_snapshot(snapshot, self.client)
- @lockutils.synchronized('3par-attach', 'cinder-', True)
+ @utils.synchronized('3par-attach', external=True)
def initialize_connection(self, volume, connector):
"""Assigns the volume to a server.
}
return info
- @lockutils.synchronized('3par-attach', 'cinder-', True)
+ @utils.synchronized('3par-attach', external=True)
def terminate_connection(self, volume, connector, force):
"""
Driver entry point to unattach a volume from an instance.
return host
- @lockutils.synchronized('3par-exp', 'cinder-', True)
+ @utils.synchronized('3par-exp', external=True)
def create_export(self, context, volume):
pass
- @lockutils.synchronized('3par-exp', 'cinder-', True)
+ @utils.synchronized('3par-exp', external=True)
def ensure_export(self, context, volume):
pass
- @lockutils.synchronized('3par-exp', 'cinder-', True)
+ @utils.synchronized('3par-exp', external=True)
def remove_export(self, context, volume):
pass
from cinder import manager
from cinder.openstack.common import excutils
from cinder.openstack.common import importutils
-from cinder.openstack.common import lockutils
from cinder.openstack.common import log as logging
from cinder.openstack.common import timeutils
from cinder.openstack.common import uuidutils
from cinder import quota
+from cinder import utils
from cinder.volume.configuration import Configuration
from cinder.volume import utils as volume_utils
from cinder.volume import volume_types
def attach_volume(self, context, volume_id, instance_uuid, mountpoint):
"""Updates db to show volume is attached"""
- @lockutils.synchronized(volume_id, 'cinder-', external=True)
+ @utils.synchronized(volume_id, external=True)
def do_attach():
# check the volume status before attaching
volume = self.db.volume_get(context, volume_id)