def test_synchronized_with_prefix(self): lock_name = 'mylock' lock_pfix = 'mypfix-' foo = lockutils.synchronized_with_prefix(lock_pfix) @foo(lock_name, external=True) def bar(dirpath, pfix, name): return True lock_dir = tempfile.mkdtemp() self.config(lock_path=lock_dir, group='oslo_concurrency') self.assertTrue(bar(lock_dir, lock_pfix, lock_name))
def get_port_synchronized_decorator(lock_prefix): synchronized = lockutils.synchronized_with_prefix(lock_prefix) def _port_synchronized(f): # This decorator synchronizes operations targeting the same port. # The decorated method is expected to accept the port_id argument. def wrapper(*args, **kwargs): call_args = inspect.getcallargs(f, *args, **kwargs) port_id = call_args['port_id'] lock_name = lock_prefix + ('port-lock-%s' % port_id) @synchronized(lock_name) def inner(): return f(*args, **kwargs) return inner() return wrapper return _port_synchronized
import platform import socket import sys from oslo_concurrency import lockutils from oslo_log import log as logging from oslo_utils import importutils from os_brick import exception from os_brick.i18n import _ from os_brick import initiator from os_brick import utils LOG = logging.getLogger(__name__) synchronized = lockutils.synchronized_with_prefix('os-brick-') # List of connectors to call when getting # the connector properties for a host connector_list = [ 'os_brick.initiator.connectors.base.BaseLinuxConnector', 'os_brick.initiator.connectors.iscsi.ISCSIConnector', 'os_brick.initiator.connectors.fibre_channel.FibreChannelConnector', ('os_brick.initiator.connectors.fibre_channel_s390x.' 'FibreChannelConnectorS390X'), ('os_brick.initiator.connectors.fibre_channel_ppc64.' 'FibreChannelConnectorPPC64'), 'os_brick.initiator.connectors.aoe.AoEConnector', 'os_brick.initiator.connectors.remotefs.RemoteFsConnector', 'os_brick.initiator.connectors.rbd.RBDConnector', 'os_brick.initiator.connectors.local.LocalConnector',
import logging import uuid from oslo_concurrency import lockutils from oslo_utils.secretutils import md5 try: from eventlet import sleep except ImportError: from time import sleep from glance_store.i18n import _ LOG = logging.getLogger(__name__) synchronized = lockutils.synchronized_with_prefix('glance_store-') def is_uuid_like(val): """Returns validation of a value as a UUID. For our purposes, a UUID is a canonical form string: aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa """ try: return str(uuid.UUID(val)) == val except (TypeError, ValueError, AttributeError): return False
import six import webob.exc from jacket.storage import exception from jacket.storage.i18n import _, _LE, _LW CONF = cfg.CONF LOG = logging.getLogger(__name__) ISO_TIME_FORMAT = "%Y-%m-%dT%H:%M:%S" PERFECT_TIME_FORMAT = "%Y-%m-%dT%H:%M:%S.%f" VALID_TRACE_FLAGS = {'method', 'api'} TRACE_METHOD = False TRACE_API = False synchronized = lockutils.synchronized_with_prefix('storage-') def find_config(config_path): """Find a configuration file using the given hint. :param config_path: Full or relative path to the config. :returns: Full path of the config, if it exists. :raises: `storage.exception.ConfigNotFound` """ possible_locations = [ config_path, os.path.join(CONF.state_path, "etc", "storage", config_path), os.path.join(CONF.state_path, "etc", config_path), os.path.join(CONF.state_path, config_path),
from oslo_utils import importutils from oslo_utils import netutils from oslo_utils import timeutils import paramiko import retrying import six from manila.common import constants from manila.db import api as db_api from manila import exception from manila.i18n import _ CONF = cfg.CONF LOG = log.getLogger(__name__) synchronized = lockutils.synchronized_with_prefix('manila-') def _get_root_helper(): return 'sudo manila-rootwrap %s' % CONF.rootwrap_config def execute(*cmd, **kwargs): """Convenience wrapper around oslo's execute() function.""" if 'run_as_root' in kwargs and 'root_helper' not in kwargs: kwargs['root_helper'] = _get_root_helper() return processutils.execute(*cmd, **kwargs) def trycmd(*args, **kwargs): """Convenience wrapper around oslo's trycmd() function."""
from alembic import command from alembic import config as alembic_config from alembic import migration from oslo_concurrency import lockutils from oslo_config import cfg from oslo_log import log as logging import sqlalchemy import sqlalchemy.exc import climate.db.migration from climate import tests LOG = logging.getLogger(__name__) CONF = cfg.CONF synchronized = lockutils.synchronized_with_prefix('climate-') def _get_connect_string(backend, user, passwd, database): """Establish connection Try to get a connection with a very specific set of values, if we get these then we'll run the tests, otherwise they are skipped """ if backend == "postgres": backend = "postgresql+psycopg2" elif backend == "mysql": backend = "mysql+mysqldb" else: raise Exception("Unrecognized backend: '%s'" % backend)
from ec2api.api import ec2utils from ec2api.api import internet_gateway as internet_gateway_api from ec2api.api import route_table as route_table_api from ec2api.api import security_group as security_group_api from ec2api.api import subnet as subnet_api from ec2api.api import vpn_gateway as vpn_gateway_api from ec2api import clients from ec2api.db import api as db_api from ec2api import exception from ec2api.i18n import _ CONF = cfg.CONF LOG = logging.getLogger(__name__) synchronized = lockutils.synchronized_with_prefix('ec2api-') """VPC-object related API implementation """ Validator = common.Validator DEFAULT_VPC_CIDR_BLOCK = '172.31.0.0/16' DEFAULT_SUBNET_CIDR_BLOCK = '172.31.0.0/20' def create_vpc(context, cidr_block, instance_tenancy='default'): vpc = _create_vpc(context, cidr_block) return {'vpc': _format_vpc(vpc)}
import types import eventlet from eventlet import tpool from oslo_concurrency import lockutils from oslo_concurrency import processutils from oslo_log import log as logging from oslo_utils import excutils from oslo_utils import reflection from os_win._i18n import _LE LOG = logging.getLogger(__name__) synchronized = lockutils.synchronized_with_prefix('oswin-') def execute(*cmd, **kwargs): """Convenience wrapper around oslo's execute() method.""" return processutils.execute(*cmd, **kwargs) def parse_server_string(server_str): """Parses the given server_string and returns a tuple of host and port. If it's not a combination of host part and port, the port element is an empty string. If the input is invalid expression, return a tuple of two empty strings. """
import retrying import six from <project_name> import exception from <project_name>.i18n import _, _LW CONF = cfg.CONF LOG = logging.getLogger(__name__) ISO_TIME_FORMAT = "%Y-%m-%dT%H:%M:%S" PERFECT_TIME_FORMAT = "%Y-%m-%dT%H:%M:%S.%f" VALID_TRACE_FLAGS = {'method', 'api'} TRACE_METHOD = False TRACE_API = False synchronized = lockutils.synchronized_with_prefix('<project_name>-') def find_config(config_path): """Find a configuration file using the given hint. :param config_path: Full or relative path to the config. :returns: Full path of the config, if it exists. :raises: `<project_name>.exception.ConfigNotFound` """ possible_locations = [ config_path, os.path.join(CONF.state_path, "etc", "<project_name>", config_path), os.path.join(CONF.state_path, "etc", config_path), os.path.join(CONF.state_path, config_path),
# License for the specific language governing permissions and limitations # under the License. import json from oslo_concurrency import lockutils from oslo_concurrency import processutils as putils from oslo_log import log as logging from os_brick import exception from os_brick.i18n import _ from os_brick.initiator.connectors import base from os_brick import utils LOG = logging.getLogger(__name__) synchronized = lockutils.synchronized_with_prefix('os-brick-vrts-hyperscale-') GUID_STR_LEN = 38 class HyperScaleConnector(base.BaseLinuxConnector): """Class implements the os-brick connector for HyperScale volumes.""" def __init__(self, root_helper, driver=None, execute=putils.execute, *args, **kwargs): super(HyperScaleConnector, self).__init__(root_helper, driver=driver,
# License for the specific language governing permissions and limitations # under the License. import json from oslo_concurrency import lockutils from oslo_concurrency import processutils as putils from oslo_log import log as logging from os_brick import exception from os_brick.i18n import _ from os_brick.initiator.connectors import base from os_brick import utils LOG = logging.getLogger(__name__) synchronized = lockutils.synchronized_with_prefix('os-brick-vrts-hyperscale-') class HyperScaleConnector(base.BaseLinuxConnector): """Class implements the os-brick connector for HyperScale volumes.""" def __init__(self, root_helper, driver=None, execute=None, *args, **kwargs): super(HyperScaleConnector, self).__init__( root_helper, driver=driver, execute=execute, *args, **kwargs) def get_volume_paths(self, connection_properties):
from oslo_log import log as logging from oslo_utils import excutils from oslo_utils import importutils from oslo_utils import timeutils import retrying from conveyor import exception from conveyor.i18n import _ from conveyor.i18n import _LE CONF = cfg.CONF LOG = logging.getLogger(__name__) ISO_TIME_FORMAT = "%Y-%m-%dT%H:%M:%S" PERFECT_TIME_FORMAT = "%Y-%m-%dT%H:%M:%S.%f" synchronized = lockutils.synchronized_with_prefix('conveyor-') vgw_update_time = {} vgw_dict = {} # vgw_index is {'az01':1} vgw_index = {} vgw_id_dict = {} vgw_port_dict = {} def get_next_port_for_vgw(vgw_id): global vgw_port_dict port = vgw_port_dict.get(vgw_id) if not port:
# http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the # License for the specific language governing permissions and limitations # under the License. import weakref from oslo_concurrency import lockutils from neutron_lib import constants _synchronized = lockutils.synchronized_with_prefix("neutron-") class _PluginDirectory(object): """A directory of activated plugins in a Neutron Deployment. The directory is bootstrapped by a Neutron Manager running in the context of a Neutron Server process. """ def __init__(self): self._plugins = {} def add_plugin(self, alias, plugin): """Add a plugin of type 'alias'.""" self._plugins[alias] = plugin
from ironic_inspector import introspection_state as istate class ModelBase(models.ModelBase): __table_args__ = {'mysql_engine': "InnoDB", 'mysql_charset': "utf8"} Base = declarative_base(cls=ModelBase) CONF = cfg.CONF _DEFAULT_SQL_CONNECTION = 'sqlite:///ironic_inspector.sqlite' _CTX_MANAGER = None db_opts.set_defaults(CONF, connection=_DEFAULT_SQL_CONNECTION) _synchronized = lockutils.synchronized_with_prefix("ironic-inspector-") class Node(Base): __tablename__ = 'nodes' uuid = Column(String(36), primary_key=True) version_id = Column(String(36), server_default='') state = Column(Enum(*istate.States.all()), nullable=False, default=istate.States.finished, server_default=istate.States.finished) started_at = Column(DateTime, nullable=True) finished_at = Column(DateTime, nullable=True) error = Column(Text, nullable=True) manage_boot = Column(Boolean, nullable=True, default=True)
from keystoneauth1 import exceptions as ks_exc from keystoneauth1 import loading as ks_loading from openstack import connection from openstack import exceptions as sdk_exc from os_service_types import service_types from oslo_concurrency import lockutils from oslo_log import log from cyborg.common import exception from cyborg.common.i18n import _ import cyborg.conf LOG = log.getLogger(__name__) synchronized = lockutils.synchronized_with_prefix('cyborg-') _SERVICE_TYPES = service_types.ServiceTypes() CONF = cyborg.conf.CONF def safe_rstrip(value, chars=None): """Removes trailing characters from a string if that does not make it empty :param value: A string value that will be stripped. :param chars: Characters to remove. :return: Stripped value. """ if not isinstance(value, six.string_types): LOG.warning( "Failed to remove trailing character. Returning "
from zun.api import utils as api_utils from zun.common import clients from zun.common import consts from zun.common.docker_image import reference as docker_image from zun.common import exception from zun.common.i18n import _ from zun.common import privileged import zun.conf from zun.network import neutron from zun import objects CONF = zun.conf.CONF LOG = logging.getLogger(__name__) NETWORK_ATTACH_EXTERNAL = 'network:attach_external_network' synchronized = lockutils.synchronized_with_prefix(consts.NAME_PREFIX) VALID_STATES = { 'commit': [consts.RUNNING, consts.STOPPED, consts.PAUSED], 'delete': [consts.CREATED, consts.ERROR, consts.STOPPED, consts.DELETED, consts.DEAD], 'delete_force': [consts.CREATED, consts.CREATING, consts.ERROR, consts.RUNNING, consts.STOPPED, consts.UNKNOWN, consts.DELETED, consts.DEAD, consts.RESTARTING, consts.REBUILDING], 'delete_after_stop': [consts.RUNNING, consts.CREATED, consts.ERROR, consts.STOPPED, consts.DELETED, consts.DEAD], 'start': [consts.CREATED, consts.STOPPED, consts.ERROR], 'stop': [consts.RUNNING], 'reboot': [consts.CREATED, consts.RUNNING, consts.STOPPED, consts.ERROR], 'rebuild': [consts.CREATED, consts.RUNNING, consts.STOPPED, consts.ERROR],
import retrying import six from cinder import exception from cinder.i18n import _, _LE, _LW CONF = cfg.CONF LOG = logging.getLogger(__name__) ISO_TIME_FORMAT = "%Y-%m-%dT%H:%M:%S" PERFECT_TIME_FORMAT = "%Y-%m-%dT%H:%M:%S.%f" VALID_TRACE_FLAGS = {"method", "api"} TRACE_METHOD = False TRACE_API = False synchronized = lockutils.synchronized_with_prefix("cinder-") def find_config(config_path): """Find a configuration file using the given hint. :param config_path: Full or relative path to the config. :returns: Full path of the config, if it exists. :raises: `cinder.exception.ConfigNotFound` """ possible_locations = [ config_path, os.path.join(CONF.state_path, "etc", "cinder", config_path), os.path.join(CONF.state_path, "etc", config_path), os.path.join(CONF.state_path, config_path),
from oslo_config import cfg from oslo_log import log from oslo_utils import importutils from oslo_utils import timeutils import paramiko import six from meteos.common import constants from meteos.db import api as db_api from meteos import exception from meteos.i18n import _ CONF = cfg.CONF LOG = log.getLogger(__name__) synchronized = lockutils.synchronized_with_prefix('meteos-') def _get_root_helper(): return 'sudo meteos-rootwrap %s' % CONF.rootwrap_config def execute(*cmd, **kwargs): """Convenience wrapper around oslo's execute() function.""" if 'run_as_root' in kwargs and 'root_helper' not in kwargs: kwargs['root_helper'] = _get_root_helper() return processutils.execute(*cmd, **kwargs) def trycmd(*args, **kwargs): """Convenience wrapper around oslo's trycmd() function."""
CONF.register_opts(workarounds_opts, group='workarounds') LOG = logging.getLogger(__name__) # used in limits TIME_UNITS = { 'SECOND': 1, 'MINUTE': 60, 'HOUR': 3600, 'DAY': 86400 } _IS_NEUTRON = None synchronized = lockutils.synchronized_with_prefix('nova-') SM_IMAGE_PROP_PREFIX = "image_" SM_INHERITABLE_KEYS = ( 'min_ram', 'min_disk', 'disk_format', 'container_format', ) def vpn_ping(address, port, timeout=0.05, session_id=None): """Sends a vpn negotiation packet and returns the server session. Returns Boolean indicating whether the vpn_server is listening. Basic packet structure is below. Client packet (14 bytes)::
from ec2api.api import common from ec2api.api import ec2utils from ec2api.api import internet_gateway as internet_gateway_api from ec2api.api import route_table as route_table_api from ec2api.api import security_group as security_group_api from ec2api.api import subnet as subnet_api from ec2api.api import vpn_gateway as vpn_gateway_api from ec2api import clients from ec2api.db import api as db_api from ec2api import exception from ec2api.i18n import _ CONF = cfg.CONF LOG = logging.getLogger(__name__) synchronized = lockutils.synchronized_with_prefix('ec2api-') """VPC-object related API implementation """ Validator = common.Validator DEFAULT_VPC_CIDR_BLOCK = '172.31.0.0/16' DEFAULT_SUBNET_CIDR_BLOCK = '172.31.0.0/20' def create_vpc(context, cidr_block, instance_tenancy='default'): vpc = _create_vpc(context, cidr_block) return {'vpc': _format_vpc(vpc)} def delete_vpc(context, vpc_id):
import nova.conf from nova import exception from nova.i18n import _, _LE, _LW import nova.network from nova import safe_utils profiler = importutils.try_import('osprofiler.profiler') CONF = nova.conf.CONF LOG = logging.getLogger(__name__) _IS_NEUTRON = None synchronized = lockutils.synchronized_with_prefix('nova-') SM_IMAGE_PROP_PREFIX = "image_" SM_INHERITABLE_KEYS = ( 'min_ram', 'min_disk', 'disk_format', 'container_format', ) # Keys which hold large structured data that won't fit in the # size constraints of the system_metadata table, so we avoid # storing and/or loading them. SM_SKIP_KEYS = ( # Legacy names 'mappings', 'block_device_mapping', # Modern names 'img_mappings', 'img_block_device_mapping', ) # Image attributes which Cinder stores in volume image metadata
from oslo_concurrency import lockutils from oslo_concurrency import processutils from oslo_config import cfg from oslo_log import log as logging import six from six.moves import configparser import six.moves.urllib.parse as urlparse from storyboard.db import api as db_api import storyboard.db.migration from storyboard.tests import base LOG = logging.getLogger(__name__) CONF = cfg.CONF synchronized = lockutils.synchronized_with_prefix('storyboard-') def _get_connect_string(backend, user, passwd, database): """Try to get a connection with a very specific set of values, if we get these then we'll run the tests, otherwise they are skipped """ if backend == "mysql": backend = "mysql+pymysql" else: raise Exception("Unrecognized backend: '%s'" % backend) return ("%s://%s:%s@localhost/%s" % (backend, user, passwd, database))
CONF = cfg.CONF CONF.register_opts(monkey_patch_opts) CONF.register_opts(utils_opts) CONF.import_opt("network_api_class", "nova.network") CONF.register_opts(workarounds_opts, group="workarounds") LOG = logging.getLogger(__name__) # used in limits TIME_UNITS = {"SECOND": 1, "MINUTE": 60, "HOUR": 3600, "DAY": 86400} _IS_NEUTRON = None synchronized = lockutils.synchronized_with_prefix("nova-") SM_IMAGE_PROP_PREFIX = "image_" SM_INHERITABLE_KEYS = ("min_ram", "min_disk", "disk_format", "container_format") # Keys which hold large structured data that won't fit in the # size constraints of the system_metadata table, so we avoid # storing and/or loading them. SM_SKIP_KEYS = ( # Legacy names "mappings", "block_device_mapping", # Modern names "img_mappings", "img_block_device_mapping", ) # Image attributes which Cinder stores in volume image metadata
from oslo_log import log as logging import six import threading from hyperv.common.i18n import _, _LE, _LW, _LI # noqa from hyperv.neutron import _common_utils as c_util from hyperv.neutron import constants from hyperv.neutron import exception from hyperv.neutron import nvgre_ops CONF = cfg.CONF CONF.import_group('NVGRE', 'hyperv.neutron.config') LOG = logging.getLogger(__name__) _port_synchronized = c_util.get_port_synchronized_decorator('n-hv-agent-') synchronized = lockutils.synchronized_with_prefix('n-hv-agent-') class HyperVNeutronAgentMixin(object): def __init__(self, conf=None): """Initializes local configuration of the Hyper-V Neutron Agent. :param conf: dict or dict-like object containing the configuration details used by this Agent. If None is specified, default values are used instead. conf format is as follows: { 'host': string, 'AGENT': {'polling_interval': int, 'local_network_vswitch': string, 'physical_network_vswitch_mappings': array,
import retrying import six from delfin import exception from delfin.i18n import _ CONF = cfg.CONF LOG = log.getLogger(__name__) lock = threading.Lock() if hasattr('CONF', 'debug') and CONF.debug: logging.getLogger("paramiko").setLevel(logging.DEBUG) _ISO8601_TIME_FORMAT_SUBSECOND = '%Y-%m-%dT%H:%M:%S.%f' _ISO8601_TIME_FORMAT = '%Y-%m-%dT%H:%M:%S' synchronized = lockutils.synchronized_with_prefix('delfin-') def isotime(at=None, subsecond=False): """Stringify time in ISO 8601 format.""" # Python provides a similar instance method for datetime.datetime objects # called isoformat(). The format of the strings generated by isoformat() # have a couple of problems: # 1) The strings generated by isotime are used in tokens and other public # APIs that we can't change without a deprecation period. The strings # generated by isoformat are not the same format, so we can't just # change to it. # 2) The strings generated by isoformat do not include the microseconds if # the value happens to be 0. This will likely show up as random failures # as parsers may be written to always expect microseconds, and it will
from oslo_utils import timeutils import retrying import six from venus import exception from venus.i18n import _, _LW CONF = cfg.CONF LOG = logging.getLogger(__name__) ISO_TIME_FORMAT = "%Y-%m-%dT%H:%M:%S" PERFECT_TIME_FORMAT = "%Y-%m-%dT%H:%M:%S.%f" VALID_TRACE_FLAGS = {'method', 'api'} TRACE_METHOD = False TRACE_API = False synchronized = lockutils.synchronized_with_prefix('venus-') def find_config(config_path): """Find a configuration file using the given hint. :param config_path: Full or relative path to the config. :returns: Full path of the config, if it exists. :raises: `venus.exception.ConfigNotFound` """ possible_locations = [ config_path, os.path.join(CONF.state_path, "etc", "venus", config_path), os.path.join(CONF.state_path, "etc", config_path), os.path.join(CONF.state_path, config_path),
CONF.register_opts(workarounds_opts, group='workarounds') LOG = logging.getLogger(__name__) # used in limits TIME_UNITS = { 'SECOND': 1, 'MINUTE': 60, 'HOUR': 3600, 'DAY': 86400 } _IS_NEUTRON = None synchronized = lockutils.synchronized_with_prefix('compute-') SM_IMAGE_PROP_PREFIX = "image_" SM_INHERITABLE_KEYS = ( 'min_ram', 'min_disk', 'disk_format', 'container_format', ) # Keys which hold large structured data that won't fit in the # size constraints of the system_metadata table, so we avoid # storing and/or loading them. SM_SKIP_KEYS = ( # Legacy names 'mappings', 'block_device_mapping', # Modern names 'img_mappings', 'img_block_device_mapping', ) # Image attributes which Cinder stores in volume image metadata
# # Licensed under the Apache License, Version 2.0 (the "License"); you may # not use this file except in compliance with the License. You may obtain # a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the # License for the specific language governing permissions and limitations # under the License. from oslo_concurrency import lockutils synchronized = lockutils.synchronized_with_prefix('os-xenapi-') class XenAPISessionObject(object): """Wrapper to make calling and mocking the session easier The XenAPI protocol is an XML RPC API that is based around the XenAPI database, and operations you can do on each of the objects stored in the database, such as VM, SR, VDI, etc. For more details see the XenAPI docs: http://docs.vmd.citrix.com/XenServer/6.2.0/1.0/en_gb/api/ Most, objects like VM, SR, VDI, etc, share a common set of methods: * vm_ref = session.VM.create(vm_rec) * vm_ref = session.VM.get_by_uuid(uuid)
# # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the # License for the specific language governing permissions and limitations # under the License. import weakref from oslo_concurrency import lockutils from neutron_lib.plugins import constants _synchronized = lockutils.synchronized_with_prefix("neutron-") class _PluginDirectory(object): """A directory of activated plugins in a Neutron Deployment. The directory is bootstrapped by a Neutron Manager running in the context of a Neutron Server process. """ def __init__(self): self._plugins = {} def add_plugin(self, alias, plugin): """Add a plugin of type 'alias'.""" self._plugins[alias] = plugin
from webob import exc from dolphin.common import constants # from dolphin.db import api as db_api from dolphin import exception from dolphin.i18n import _ CONF = cfg.CONF LOG = log.getLogger(__name__) if hasattr('CONF', 'debug') and CONF.debug: logging.getLogger("paramiko").setLevel(logging.DEBUG) _ISO8601_TIME_FORMAT_SUBSECOND = '%Y-%m-%dT%H:%M:%S.%f' _ISO8601_TIME_FORMAT = '%Y-%m-%dT%H:%M:%S' synchronized = lockutils.synchronized_with_prefix('dolphin-') def isotime(at=None, subsecond=False): """Stringify time in ISO 8601 format.""" # Python provides a similar instance method for datetime.datetime objects # called isoformat(). The format of the strings generated by isoformat() # have a couple of problems: # 1) The strings generated by isotime are used in tokens and other public # APIs that we can't change without a deprecation period. The strings # generated by isoformat are not the same format, so we can't just # change to it. # 2) The strings generated by isoformat do not include the microseconds if # the value happens to be 0. This will likely show up as random failures # as parsers may be written to always expect microseconds, and it will
from zun.api import utils as api_utils from zun.common import clients from zun.common import consts from zun.common.docker_image import reference as docker_image from zun.common import exception from zun.common.i18n import _ from zun.common import privileged import zun.conf from zun.network import neutron from zun import objects CONF = zun.conf.CONF LOG = logging.getLogger(__name__) NETWORK_ATTACH_EXTERNAL = 'network:attach_external_network' synchronized = lockutils.synchronized_with_prefix(consts.NAME_PREFIX) VALID_STATES = { 'commit': [consts.RUNNING, consts.STOPPED, consts.PAUSED], 'delete': [ consts.CREATED, consts.ERROR, consts.STOPPED, consts.DELETED, consts.DEAD ], 'delete_force': [ consts.CREATED, consts.CREATING, consts.ERROR, consts.RUNNING, consts.STOPPED, consts.UNKNOWN, consts.DELETED, consts.DEAD, consts.RESTARTING, consts.REBUILDING ], 'delete_after_stop': [ consts.RUNNING, consts.CREATED, consts.ERROR, consts.STOPPED, consts.DELETED, consts.DEAD
import six import webob.exc from cinder import exception from cinder.i18n import _, _LE, _LW from cinder import keymgr CONF = cfg.CONF LOG = logging.getLogger(__name__) ISO_TIME_FORMAT = "%Y-%m-%dT%H:%M:%S" PERFECT_TIME_FORMAT = "%Y-%m-%dT%H:%M:%S.%f" VALID_TRACE_FLAGS = {'method', 'api'} TRACE_METHOD = False TRACE_API = False synchronized = lockutils.synchronized_with_prefix('cinder-') def as_int(obj, quiet=True): # Try "2" -> 2 try: return int(obj) except (ValueError, TypeError): pass # Try "2.5" -> 2 try: return int(float(obj)) except (ValueError, TypeError): pass # Eck, not sure what this is then. if not quiet:
from oslo_concurrency import processutils from oslo_config import cfg from oslo_log import log as logging from oslo_utils import importutils from oslo_utils import strutils from oslo_utils import timeutils from oslo_utils import units import six from guts import exception from guts.i18n import _, _LI, _LE CONF = cfg.CONF LOG = logging.getLogger(__name__) synchronized = lockutils.synchronized_with_prefix('guts-') class QemuImgInfo(object): BACKING_FILE_RE = re.compile((r"^(.*?)\s*\(actual\s+path\s*:" r"\s+(.*?)\)\s*$"), re.I) TOP_LEVEL_RE = re.compile(r"^([\w\d\s\_\-]+):(.*)$") SIZE_RE = re.compile(r"(\d*\.?\d+)(\w+)?(\s*\(\s*(\d+)\s+bytes\s*\))?", re.I) def __init__(self, cmd_output=None): details = self._parse(cmd_output or '') self.image = details.get('image') self.backing_file = details.get('backing_file') self.file_format = details.get('file_format') self.virtual_size = details.get('virtual_size')
from webob import exc from manila.common import constants from manila.db import api as db_api from manila import exception from manila.i18n import _ CONF = cfg.CONF LOG = log.getLogger(__name__) if hasattr('CONF', 'debug') and CONF.debug: logging.getLogger("paramiko").setLevel(logging.DEBUG) _ISO8601_TIME_FORMAT_SUBSECOND = '%Y-%m-%dT%H:%M:%S.%f' _ISO8601_TIME_FORMAT = '%Y-%m-%dT%H:%M:%S' synchronized = lockutils.synchronized_with_prefix('manila-') def isotime(at=None, subsecond=False): """Stringify time in ISO 8601 format.""" # Python provides a similar instance method for datetime.datetime objects # called isoformat(). The format of the strings generated by isoformat() # have a couple of problems: # 1) The strings generated by isotime are used in tokens and other public # APIs that we can't change without a deprecation period. The strings # generated by isoformat are not the same format, so we can't just # change to it. # 2) The strings generated by isoformat do not include the microseconds if # the value happens to be 0. This will likely show up as random failures # as parsers may be written to always expect microseconds, and it will
from neutron_lib import constants as n_const from os_win import exceptions as os_win_exc from oslo_concurrency import lockutils from oslo_log import log as logging from oslo_service import loopingcall import six from networking_hyperv.common.i18n import _, _LI, _LE # noqa from networking_hyperv.neutron.agent import base as base_agent from networking_hyperv.neutron import config from networking_hyperv.neutron import constants LOG = logging.getLogger(__name__) CONF = config.CONF _synchronized = lockutils.synchronized_with_prefix('n-hv-agent-') class Layer2Agent(base_agent.BaseAgent): """Contract class for all the layer two agents.""" _AGENT_TOPIC = n_const.L2_AGENT_TOPIC def __init__(self): super(Layer2Agent, self).__init__() self._network_vswitch_map = {} # The following sets contain ports that are to be processed. self._added_ports = set() self._removed_ports = set()
CONF.register_opts(workarounds_opts, group='workarounds') LOG = logging.getLogger(__name__) # used in limits TIME_UNITS = { 'SECOND': 1, 'MINUTE': 60, 'HOUR': 3600, 'DAY': 86400 } _IS_NEUTRON = None synchronized = lockutils.synchronized_with_prefix('patron-') SM_IMAGE_PROP_PREFIX = "image_" SM_INHERITABLE_KEYS = ( 'min_ram', 'min_disk', 'disk_format', 'container_format', ) def vpn_ping(address, port, timeout=0.05, session_id=None): """Sends a vpn negotiation packet and returns the server session. Returns Boolean indicating whether the vpn_server is listening. Basic packet structure is below. Client packet (14 bytes)::
from alembic import command from alembic import config as alembic_config from alembic import migration from oslo_concurrency import lockutils from oslo_config import cfg from oslo_log import log as logging import sqlalchemy import sqlalchemy.exc import blazar.db.migration from blazar import tests LOG = logging.getLogger(__name__) CONF = cfg.CONF synchronized = lockutils.synchronized_with_prefix('blazar-') def _get_connect_string(backend, user, passwd, database): """Establish connection Try to get a connection with a very specific set of values, if we get these then we'll run the tests, otherwise they are skipped """ if backend == "postgres": backend = "postgresql+psycopg2" elif backend == "mysql": backend = "mysql+mysqldb" else: raise Exception("Unrecognized backend: '%s'" % backend)
from oslo_concurrency import lockutils from oslo_config import cfg from oslo_log import log as logging from oslo_utils import excutils from oslo_utils import importutils import six from stevedore import driver from neutron._i18n import _LE from neutron.common import constants as n_const TIME_FORMAT = "%Y-%m-%dT%H:%M:%SZ" LOG = logging.getLogger(__name__) SYNCHRONIZED_PREFIX = 'neutron-' synchronized = lockutils.synchronized_with_prefix(SYNCHRONIZED_PREFIX) class cache_method_results(object): """This decorator is intended for object methods only.""" def __init__(self, func): self.func = func functools.update_wrapper(self, func) self._first_call = True self._not_cached = object() def _get_from_cache(self, target_self, *args, **kwargs): func_name = "%(module)s.%(class)s.%(func_name)s" % { 'module': target_self.__module__, 'class': target_self.__class__.__name__,
from zun.api import utils as api_utils from zun.common import clients from zun.common import consts from zun.common import exception from zun.common.i18n import _ from zun.common import privileged import zun.conf from zun.network import neutron from zun import objects CONF = zun.conf.CONF LOG = logging.getLogger(__name__) NETWORK_ATTACH_EXTERNAL = 'network:attach_external_network' synchronized = lockutils.synchronized_with_prefix('zun-') VALID_STATES = { 'commit': [consts.RUNNING, consts.STOPPED, consts.PAUSED], 'delete': [consts.CREATED, consts.ERROR, consts.STOPPED, consts.DELETED], 'delete_force': [ consts.CREATED, consts.CREATING, consts.ERROR, consts.RUNNING, consts.STOPPED, consts.UNKNOWN, consts.DELETED ], 'delete_after_stop': [ consts.RUNNING, consts.CREATED, consts.ERROR, consts.STOPPED, consts.DELETED ], 'start': [consts.CREATED, consts.STOPPED, consts.ERROR], 'stop': [consts.RUNNING], 'reboot': [consts.CREATED, consts.RUNNING, consts.STOPPED, consts.ERROR],
from oslo_concurrency import lockutils from oslo_config import cfg from networking_bagpipe.bagpipe_bgp.engine import exa def synchronized(method): def synchronized_method(self, *arg, **kws): with self.lock: return method(self, *arg, **kws) return synchronized_method oslo_synchronized = lockutils.synchronized_with_prefix('bagpipe-bgp-') def plural(x): if len(x) > 1: return "s" else: return "" def invert_dict_of_sets(d): '''return inverted dict of sets from original dict original dict possibly containing sets of non-unique hashable items ''' new_d = collections.defaultdict(set)
import socket import struct from oslo_concurrency import lockutils from oslo_log import log as logging import six from os_brick import exception from os_brick.i18n import _ from os_brick import initiator from os_brick.initiator.connectors import base from os_brick import utils LOG = logging.getLogger(__name__) DEVICE_SCAN_ATTEMPTS_DEFAULT = 3 synchronized = lockutils.synchronized_with_prefix('os-brick-') class DISCOConnector(base.BaseLinuxConnector): """Class implements the connector driver for DISCO.""" DISCO_PREFIX = 'dms' def __init__(self, root_helper, driver=None, device_scan_attempts=initiator.DEVICE_SCAN_ATTEMPTS_DEFAULT, *args, **kwargs): """Init DISCO connector.""" super(DISCOConnector, self).__init__( root_helper, driver=driver, device_scan_attempts=device_scan_attempts,
"val": "1024" } }, "GB": { "MB": { "op": "*", "val": "1024" }, "GB": { "op": "*", "val": "1" } } } CONF = cfg.CONF synchronized = lockutils.synchronized_with_prefix(SYNCHRONIZED_PREFIX) class cache_method_results(object): """This decorator is intended for object methods only.""" def __init__(self, func): self.func = func functools.update_wrapper(self, func) self._first_call = True self._not_cached = object() def _get_from_cache(self, target_self, *args, **kwargs): func_name = "%(module)s.%(class)s.%(func_name)s" % { 'module': target_self.__module__, 'class': target_self.__class__.__name__, 'func_name': self.func.__name__,
import eventlet from eventlet import tpool from oslo_concurrency import lockutils from oslo_concurrency import processutils from oslo_log import log as logging from oslo_utils import excutils from oslo_utils import reflection from os_win._i18n import _LE from os_win import exceptions LOG = logging.getLogger(__name__) socket = eventlet.import_patched('socket') synchronized = lockutils.synchronized_with_prefix('oswin-') _WBEM_E_NOT_FOUND = 0x80041002 def execute(*cmd, **kwargs): """Convenience wrapper around oslo's execute() method.""" return processutils.execute(*cmd, **kwargs) def parse_server_string(server_str): """Parses the given server_string and returns a tuple of host and port. If it's not a combination of host part and port, the port element is an empty string. If the input is invalid expression, return a tuple of two empty strings.
from oslo_context import context as common_context from oslo_log import log as logging from oslo_utils import encodeutils from oslo_utils import importutils import paramiko import six from mogan.common import exception from mogan.common.i18n import _ from mogan.common import states from mogan.conf import CONF from mogan import objects LOG = logging.getLogger(__name__) synchronized = lockutils.synchronized_with_prefix('mogan-') profiler = importutils.try_import('osprofiler.profiler') def safe_rstrip(value, chars=None): """Removes trailing characters from a string if that does not make it empty :param value: A string value that will be stripped. :param chars: Characters to remove. :return: Stripped value. """ if not isinstance(value, six.string_types): LOG.warning( "Failed to remove trailing character. Returning " "original object. Supplied object is not a string: "
from ironic_inspector import introspection_state as istate class ModelBase(models.ModelBase): __table_args__ = {'mysql_engine': "InnoDB", 'mysql_charset': "utf8"} Base = declarative_base(cls=ModelBase) CONF = cfg.CONF _DEFAULT_SQL_CONNECTION = 'sqlite:///ironic_inspector.sqlite' _CTX_MANAGER = None db_opts.set_defaults(CONF, connection=_DEFAULT_SQL_CONNECTION) _synchronized = lockutils.synchronized_with_prefix("ironic-inspector-") class Node(Base): __tablename__ = 'nodes' uuid = Column(String(36), primary_key=True) version_id = Column(String(36), server_default='') state = Column(Enum(*istate.States.all()), nullable=False, default=istate.States.finished, server_default=istate.States.finished) started_at = Column(DateTime, nullable=True) finished_at = Column(DateTime, nullable=True) error = Column(Text, nullable=True) manage_boot = Column(Boolean, nullable=True, default=True) # version_id is being tracked in the NodeInfo object