def plug(self, instance, vif): dev = self.get_vif_devname(vif) try: linux_net.create_tap_dev(dev) except processutils.ProcessExecutionError: LOG.exception(_LE("Failed while plugging vif"), instance=instance) kwargs = { 'ip_address': vif['network']['subnets'][0]['ips'][0]['address'], 'vn_id': vif['network']['id'], 'display_name': instance['display_name'], 'hostname': instance['hostname'], 'host': instance['host'], 'vm_project_id': instance['project_id'], 'port_type': self.PORT_TYPE, } try: result = self._vrouter_client.add_port(instance['uuid'], vif['id'], dev, vif['address'], **kwargs) if not result: LOG.exception(_LE("Failed while plugging vif"), instance=instance) except TApplicationException: LOG.exception(_LE("Failed while plugging vif"), instance=instance)
def plug(self, instance, vif): try: dev = self.get_vif_devname(vif) try: if not CONF.contrail.use_userspace_vhost: linux_net.create_tap_dev(dev) except processutils.ProcessExecutionError: LOG.exception(_LE("Failed while plugging vif"), instance=instance) try: virt_type = cfg.CONF.libvirt.virt_type except cfg.NoSuchOptError: virt_type = cfg.CONF.libvirt_type if virt_type == 'lxc': dev = self._create_bridge(dev, instance) ipv4_address = '0.0.0.0' ipv6_address = None subnets = vif['network']['subnets'] for subnet in subnets: ips = subnet['ips'][0] if (ips['version'] == 4): if ips['address'] is not None: ipv4_address = ips['address'] if (ips['version'] == 6): if ips['address'] is not None: ipv6_address = ips['address'] kwargs = { 'ip_address': ipv4_address, 'vn_id': vif['network']['id'], 'display_name': instance['display_name'], 'hostname': instance['hostname'], 'host': instance['host'], 'vm_project_id': instance['project_id'], 'port_type': self.PORT_TYPE, 'ip6_address': ipv6_address, } try: result = self._vrouter_client.add_port(instance['uuid'], vif['id'], dev, vif['address'], **kwargs) if not result: LOG.exception(_LE("Failed while plugging vif"), instance=instance) except TApplicationException: LOG.exception(_LE("Failed while plugging vif"), instance=instance) except Exception as e: from pprint import pformat LOG.error(_("Error in plug: %s locals: %s instance %s" %(str(e), pformat(locals()), pformat(instance) if isinstance(instance, dict) else pformat(instance.__dict__))))
def plug_iovisor(self, instance, vif): """Plug using PLUMgrid IO Visor Driver Connect a network device to their respective Virtual Domain in PLUMgrid Platform. """ super(LibvirtGenericVIFDriver, self).plug(instance, vif) dev = self.get_vif_devname(vif) iface_id = vif['id'] linux_net.create_tap_dev(dev) net_id = vif['network']['id'] tenant_id = instance["project_id"] try: utils.execute('ifc_ctl', 'gateway', 'add_port', dev, run_as_root=True) utils.execute('ifc_ctl', 'gateway', 'ifup', dev, 'access_vm', vif['network']['label'] + "_" + iface_id, vif['address'], 'pgtag2=%s' % net_id, 'pgtag1=%s' % tenant_id, run_as_root=True) except processutils.ProcessExecutionError: LOG.exception(_LE("Failed while plugging vif"), instance=instance)
def _migrate_up(self, engine, version, with_data=False): """migrate up to a new version of the db. We allow for data insertion and post checks at every migration version with special _pre_upgrade_### and _check_### functions in the main test. """ # NOTE(sdague): try block is here because it's impossible to debug # where a failed data migration happens otherwise try: if with_data: data = None pre_upgrade = getattr( self, "_pre_upgrade_%03d" % version, None) if pre_upgrade: data = pre_upgrade(engine) self.migration_api.upgrade(engine, self.REPOSITORY, version) self.assertEqual(version, self.migration_api.db_version(engine, self.REPOSITORY)) if with_data: check = getattr(self, "_check_%03d" % version, None) if check: check(engine, data) except Exception: LOG.error(_LE("Failed to migrate to version %s on engine %s") % (version, engine)) raise
def _inner(): if initial_delay: greenthread.sleep(initial_delay) try: while self._running: start = _ts() self.f(*self.args, **self.kw) end = _ts() if not self._running: break delay = end - start - interval if delay > 0: LOG.warn( _LW('task %(func_name)s run outlasted ' 'interval by %(delay).2f sec'), { 'func_name': repr(self.f), 'delay': delay }) greenthread.sleep(-delay if delay < 0 else 0) except LoopingCallDone as e: self.stop() done.send(e.retvalue) except Exception: LOG.exception(_LE('in fixed duration looping call')) done.send_exception(*sys.exc_info()) return else: done.send(True)
def _inner(): if initial_delay: greenthread.sleep(initial_delay) try: while self._running: idle = self.f(*self.args, **self.kw) if not self._running: break if periodic_interval_max is not None: idle = min(idle, periodic_interval_max) LOG.debug( 'Dynamic looping call %(func_name)s sleeping ' 'for %(idle).02f seconds', { 'func_name': repr(self.f), 'idle': idle }) greenthread.sleep(idle) except LoopingCallDone as e: self.stop() done.send(e.retvalue) except Exception: LOG.exception(_LE('in dynamic looping call')) done.send_exception(*sys.exc_info()) return else: done.send(True)
def _inner(): if initial_delay: greenthread.sleep(initial_delay) try: while self._running: start = _ts() self.f(*self.args, **self.kw) end = _ts() if not self._running: break delay = end - start - interval if delay > 0: LOG.warn( _LW("task %(func_name)s run outlasted " "interval by %(delay).2f sec"), {"func_name": repr(self.f), "delay": delay}, ) greenthread.sleep(-delay if delay < 0 else 0) except LoopingCallDone as e: self.stop() done.send(e.retvalue) except Exception: LOG.exception(_LE("in fixed duration looping call")) done.send_exception(*sys.exc_info()) return else: done.send(True)
def unplug_ovs_hybrid(self, instance, vif): """UnPlug using hybrid strategy Unhook port from OVS, unhook port from bridge, delete bridge, and delete both veth devices. """ super(LibvirtGenericVIFDriver, self).unplug(instance, vif) try: br_name = self.get_br_name(vif['id']) v1_name, v2_name = self.get_veth_pair_names(vif['id']) if linux_net.device_exists(br_name): utils.execute('brctl', 'delif', br_name, v1_name, run_as_root=True) utils.execute('ip', 'link', 'set', br_name, 'down', run_as_root=True) utils.execute('brctl', 'delbr', br_name, run_as_root=True) linux_net.delete_ovs_vif_port(self.get_bridge_name(vif), v2_name) except processutils.ProcessExecutionError: LOG.exception(_LE("Failed while unplugging vif"), instance=instance)
def _inner(): if initial_delay: greenthread.sleep(initial_delay) try: while self._running: start = timeutils.utcnow() self.f(*self.args, **self.kw) end = timeutils.utcnow() if not self._running: break delay = interval - timeutils.delta_seconds(start, end) if delay <= 0: LOG.warn( _LW('task run outlasted interval by %s sec') % -delay) greenthread.sleep(delay if delay > 0 else 0) except LoopingCallDone as e: self.stop() done.send(e.retvalue) except Exception: LOG.exception(_LE('in fixed duration looping call')) done.send_exception(*sys.exc_info()) return else: done.send(True)
def _wait_for_exit_or_signal(self, ready_callback=None): status = None signo = 0 LOG.debug('Full set of CONF:') CONF.log_opt_values(LOG, std_logging.DEBUG) try: if ready_callback: ready_callback() super(ServiceLauncher, self).wait() except SignalExit as exc: signame = _signo_to_signame(exc.signo) LOG.info(_LI('Caught %s, exiting'), signame) status = exc.code signo = exc.signo except SystemExit as exc: status = exc.code finally: self.stop() if rpc: try: rpc.cleanup() except Exception: # We're shutting down, so it doesn't matter at this point. LOG.exception(_LE('Exception during rpc cleanup.')) return status, signo
def run_periodic_tasks(self, context, raise_on_error=False): """Tasks to be run at a periodic interval.""" idle_for = DEFAULT_INTERVAL for task_name, task in self._periodic_tasks: full_task_name = '.'.join([self.__class__.__name__, task_name]) spacing = self._periodic_spacing[task_name] last_run = self._periodic_last_run[task_name] # Check if due, if not skip idle_for = min(idle_for, spacing) if last_run is not None: delta = last_run + spacing - time.time() if delta > 0: idle_for = min(idle_for, delta) continue LOG.debug("Running periodic task %(full_task_name)s", {"full_task_name": full_task_name}) self._periodic_last_run[task_name] = _nearest_boundary( last_run, spacing) try: task(self, context) except Exception as e: if raise_on_error: raise LOG.exception(_LE("Error during %(full_task_name)s: %(e)s"), { "full_task_name": full_task_name, "e": e }) time.sleep(0) return idle_for
def _wrap(self, *args, **kwargs): try: return f(self, *args, **kwargs) except UnicodeEncodeError: raise exception.DBInvalidUnicodeParameter() except sqla_exc.OperationalError as e: _raise_if_db_connection_lost(e, self.bind) _raise_if_deadlock_error(e, self.bind.dialect.name) # NOTE(comstud): A lot of code is checking for OperationalError # so let's not wrap it for now. raise # note(boris-42): We should catch unique constraint violation and # wrap it by our own DBDuplicateEntry exception. Unique constraint # violation is wrapped by IntegrityError. except sqla_exc.IntegrityError as e: # note(boris-42): SqlAlchemy doesn't unify errors from different # DBs so we must do this. Also in some tables (for example # instance_types) there are more than one unique constraint. This # means we should get names of columns, which values violate # unique constraint, from error message. _raise_if_duplicate_entry_error(e, self.bind.dialect.name) raise exception.DBError(e) except Exception as e: LOG.exception(_LE('DB exception wrapped.')) raise exception.DBError(e)
def unplug_iovisor(self, instance, vif): """Unplug using PLUMgrid IO Visor Driver Delete network device and to their respective connection to the Virtual Domain in PLUMgrid Platform. """ super(LibvirtGenericVIFDriver, self).unplug(instance, vif) iface_id = vif['id'] dev = self.get_vif_devname(vif) try: utils.execute('ifc_ctl', 'gateway', 'ifdown', dev, 'access_vm', vif['network']['label'] + "_" + iface_id, vif['address'], run_as_root=True) utils.execute('ifc_ctl', 'gateway', 'del_port', dev, run_as_root=True) linux_net.delete_net_dev(dev) except processutils.ProcessExecutionError: LOG.exception(_LE("Failed while unplugging vif"), instance=instance)
def _wrap(self, *args, **kwargs): try: assert issubclass( self.__class__, sqlalchemy.orm.session.Session ), ('_wrap_db_error() can only be applied to methods of ' 'subclasses of sqlalchemy.orm.session.Session.') return f(self, *args, **kwargs) except UnicodeEncodeError: raise exception.DBInvalidUnicodeParameter() except sqla_exc.OperationalError as e: _raise_if_db_connection_lost(e, self.bind) _raise_if_deadlock_error(e, self.bind.dialect.name) # NOTE(comstud): A lot of code is checking for OperationalError # so let's not wrap it for now. raise # note(boris-42): We should catch unique constraint violation and # wrap it by our own DBDuplicateEntry exception. Unique constraint # violation is wrapped by IntegrityError. except sqla_exc.IntegrityError as e: # note(boris-42): SqlAlchemy doesn't unify errors from different # DBs so we must do this. Also in some tables (for example # instance_types) there are more than one unique constraint. This # means we should get names of columns, which values violate # unique constraint, from error message. _raise_if_duplicate_entry_error(e, self.bind.dialect.name) raise exception.DBError(e) except Exception as e: LOG.exception(_LE('DB exception wrapped.')) raise exception.DBError(e)
def verify_base_size(base, size, base_size=0): """Check that the base image is not larger than size. Since images can't be generally shrunk, enforce this constraint taking account of virtual image size. """ # Note(pbrady): The size and min_disk parameters of a glance # image are checked against the instance size before the image # is even downloaded from glance, but currently min_disk is # adjustable and doesn't currently account for virtual disk size, # so we need this extra check here. # NOTE(cfb): Having a flavor that sets the root size to 0 and having # nova effectively ignore that size and use the size of the # image is considered a feature at this time, not a bug. if size is None: return if size and not base_size: base_size = disk.get_disk_size(base) if size < base_size: msg = _LE('%(base)s virtual size %(base_size)s ' 'larger than flavor root disk size %(size)s') LOG.error(msg % { 'base': base, 'base_size': base_size, 'size': size }) raise exception.FlavorDiskTooSmall()
def clear_logical_volume(path): """Obfuscate the logical volume. :param path: logical volume path """ volume_clear = CONF.libvirt.volume_clear if volume_clear not in ('none', 'shred', 'zero'): LOG.error(_LE("ignoring unrecognized volume_clear='%s' value"), volume_clear) volume_clear = 'zero' if volume_clear == 'none': return volume_clear_size = int(CONF.libvirt.volume_clear_size) * units.Mi volume_size = logical_volume_size(path) if volume_clear_size != 0 and volume_clear_size < volume_size: volume_size = volume_clear_size if volume_clear == 'zero': # NOTE(p-draigbrady): we could use shred to do the zeroing # with -n0 -z, however only versions >= 8.22 perform as well as dd _zero_logical_volume(path, volume_size) elif volume_clear == 'shred': utils.execute('shred', '-n3', '-s%d' % volume_size, path, run_as_root=True) else: raise exception.Invalid( _("volume_clear='%s' is not handled") % volume_clear)
def verify_base_size(base, size, base_size=0): """Check that the base image is not larger than size. Since images can't be generally shrunk, enforce this constraint taking account of virtual image size. """ # Note(pbrady): The size and min_disk parameters of a glance # image are checked against the instance size before the image # is even downloaded from glance, but currently min_disk is # adjustable and doesn't currently account for virtual disk size, # so we need this extra check here. # NOTE(cfb): Having a flavor that sets the root size to 0 and having # nova effectively ignore that size and use the size of the # image is considered a feature at this time, not a bug. if size is None: return if size and not base_size: base_size = disk.get_disk_size(base) if size < base_size: msg = _LE('%(base)s virtual size %(base_size)s ' 'larger than flavor root disk size %(size)s') LOG.error(msg % {'base': base, 'base_size': base_size, 'size': size}) raise exception.FlavorDiskTooSmall()
def _inner(): if initial_delay: greenthread.sleep(initial_delay) try: while self._running: idle = self.f(*self.args, **self.kw) if not self._running: break if periodic_interval_max is not None: idle = min(idle, periodic_interval_max) LOG.debug( "Dynamic looping call %(func_name)s sleeping " "for %(idle).02f seconds", {"func_name": repr(self.f), "idle": idle}, ) greenthread.sleep(idle) except LoopingCallDone as e: self.stop() done.send(e.retvalue) except Exception: LOG.exception(_LE("in dynamic looping call")) done.send_exception(*sys.exc_info()) return else: done.send(True)
def unplug(self, instance, vif): try: dev = self.get_vif_devname(vif) if isinstance(instance, dict): task_state = instance['task_state'] else: task_state = instance._task_state try: self._vrouter_client.delete_port(vif['id']) if task_state == 'rebuilding': self.delete_device(dev) else: # delegate the deletion of tap device to a deffered thread worker_thread = threading.Thread( target=self.delete_device, name='contrailvif', args=(dev,), kwargs={'timeout': 2}) worker_thread.start() except (TApplicationException, processutils.ProcessExecutionError, RuntimeError): LOG.exception(_LE("Failed while unplugging vif"), instance=instance) except Exception as e: from pprint import pformat LOG.error(_("Error in unplug: %s locals: %s instance %s" %(str(e), pformat(locals()), pformat(instance) if isinstance(instance, dict) else pformat(instance.__dict__))))
def inner_func(*args, **kwargs): last_log_time = 0 last_exc_message = None exc_count = 0 while True: try: return infunc(*args, **kwargs) except Exception as exc: this_exc_message = six.u(str(exc)) if this_exc_message == last_exc_message: exc_count += 1 else: exc_count = 1 # Do not log any more frequently than once a minute unless # the exception message changes cur_time = int(time.time()) if (cur_time - last_log_time > 60 or this_exc_message != last_exc_message): logging.exception( _LE('Unexpected exception occurred %d time(s)... ' 'retrying.') % exc_count) last_log_time = cur_time last_exc_message = this_exc_message exc_count = 0 # This should be a very rare event. In case it isn't, do # a sleep. time.sleep(1)
def _wrap(self, *args, **kwargs): try: return f(self, *args, **kwargs) except UnicodeEncodeError: raise exception.DBInvalidUnicodeParameter() except sqla_exc.OperationalError as e: _raise_if_db_connection_lost(e, self.bind) _raise_if_deadlock_error(e, self.bind.dialect.name) # NOTE(comstud): A lot of code is checking for OperationalError # so let's not wrap it for now. raise # note(boris-42): We should catch unique constraint violation and # wrap it by our own DBDuplicateEntry exception. Unique constraint # violation is wrapped by IntegrityError. except sqla_exc.IntegrityError as e: # note(boris-42): SqlAlchemy doesn't unify errors from different # DBs so we must do this. Also in some tables (for example # instance_types) there are more than one unique constraint. This # means we should get names of columns, which values violate # unique constraint, from error message. _raise_if_duplicate_entry_error(e, self.bind.dialect.name) raise exception.DBError(e) except exception.DBError: # note(zzzeek) - if _wrap_db_error is applied to nested functions, # ensure an existing DBError is propagated outwards raise except Exception as e: LOG.exception(_LE("DB exception wrapped.")) raise exception.DBError(e)
def clear_logical_volume(path): """Obfuscate the logical volume. :param path: logical volume path """ volume_clear = CONF.libvirt.volume_clear if volume_clear not in ('none', 'shred', 'zero'): LOG.error(_LE("ignoring unrecognized volume_clear='%s' value"), volume_clear) volume_clear = 'zero' if volume_clear == 'none': return volume_clear_size = int(CONF.libvirt.volume_clear_size) * units.Mi volume_size = logical_volume_size(path) if volume_clear_size != 0 and volume_clear_size < volume_size: volume_size = volume_clear_size if volume_clear == 'zero': # NOTE(p-draigbrady): we could use shred to do the zeroing # with -n0 -z, however only versions >= 8.22 perform as well as dd _zero_logical_volume(path, volume_size) elif volume_clear == 'shred': utils.execute('shred', '-n3', '-s%d' % volume_size, path, run_as_root=True) else: raise exception.Invalid(_("volume_clear='%s' is not handled") % volume_clear)
def run_periodic_tasks(self, context, raise_on_error=False): """Tasks to be run at a periodic interval.""" idle_for = DEFAULT_INTERVAL for task_name, task in self._periodic_tasks: full_task_name = '.'.join([self.__class__.__name__, task_name]) spacing = self._periodic_spacing[task_name] last_run = self._periodic_last_run[task_name] # If a periodic task is _nearly_ due, then we'll run it early idle_for = min(idle_for, spacing) if last_run is not None: delta = last_run + spacing - time.time() if delta > 0.2: idle_for = min(idle_for, delta) continue LOG.debug("Running periodic task %(full_task_name)s", {"full_task_name": full_task_name}) self._periodic_last_run[task_name] = time.time() try: task(self, context) except Exception as e: if raise_on_error: raise LOG.exception(_LE("Error during %(full_task_name)s: %(e)s"), {"full_task_name": full_task_name, "e": e}) time.sleep(0) return idle_for
def _inner(): if initial_delay: greenthread.sleep(initial_delay) try: while self._running: start = timeutils.utcnow() self.f(*self.args, **self.kw) end = timeutils.utcnow() if not self._running: break delay = interval - timeutils.delta_seconds(start, end) if delay <= 0: LOG.warn(_LW('task run outlasted interval by %s sec') % -delay) greenthread.sleep(delay if delay > 0 else 0) except LoopingCallDone as e: self.stop() done.send(e.retvalue) except Exception: LOG.exception(_LE('in fixed duration looping call')) done.send_exception(*sys.exc_info()) return else: done.send(True)
def _remove_base_file(self, base_file): """Remove a single base file if it is old enough. Returns nothing. """ if not os.path.exists(base_file): LOG.debug('Cannot remove %s, it does not exist', base_file) return mtime = os.path.getmtime(base_file) age = time.time() - mtime maxage = CONF.libvirt.remove_unused_resized_minimum_age_seconds if base_file in self.originals: maxage = CONF.remove_unused_original_minimum_age_seconds if age < maxage: LOG.info(_LI('Base file too young to remove: %s'), base_file) else: LOG.info(_LI('Removing base file: %s'), base_file) try: os.remove(base_file) signature = get_info_filename(base_file) if os.path.exists(signature): os.remove(signature) except OSError as e: LOG.error(_LE('Failed to remove %(base_file)s, ' 'error was %(error)s'), {'base_file': base_file, 'error': e})
def release(self): try: self.unlock() self.lockfile.close() LOG.debug('Released file lock "%s"', self.fname) except IOError: LOG.exception(_LE("Could not release the acquired lock `%s`"), self.fname)
def get_ifname_by_pci_address(pci_addr): dev_path = "/sys/bus/pci/devices/%s/net" % (pci_addr) try: dev_info = os.listdir(dev_path) return dev_info.pop() except Exception: LOG.error(_LE("PCI device %s not found") % pci_addr) return None
def unplug(self, instance, vif): dev = self.get_vif_devname(vif) try: self._vrouter_client.delete_port(vif['id']) linux_net.delete_net_dev(dev) except (TApplicationException, processutils.ProcessExecutionError): LOG.exception(_LE("Failed while unplugging vif"), instance=instance)
def unplug_ivs_ethernet(self, instance, vif): """Unplug the VIF by deleting the port from the bridge.""" super(LibvirtGenericVIFDriver, self).unplug(instance, vif) try: linux_net.delete_ivs_vif_port(self.get_vif_devname(vif)) except processutils.ProcessExecutionError: LOG.exception(_LE("Failed while unplugging vif"), instance=instance)
def __exit__(self, exc_type, exc_val, exc_tb): if exc_type is not None: if self.reraise: logging.error(_LE('Original exception being dropped: %s'), traceback.format_exception(self.type_, self.value, self.tb)) return False if self.reraise: six.reraise(self.type_, self.value, self.tb)
def __exit__(self, exc_type, exc_val, exc_tb): if exc_type is not None: if self.reraise: logging.error( _LE('Original exception being dropped: %s'), traceback.format_exception(self.type_, self.value, self.tb)) return False if self.reraise: six.reraise(self.type_, self.value, self.tb)
def run_post(self, name, rv, args, kwargs, f=None): for e in reversed(self.extensions): obj = e.obj post = getattr(obj, 'post', None) if post: LOG.debug("Running %(name)s post-hook: %(obj)s", {'name': name, 'obj': obj}) try: if f: post(f, rv, *args, **kwargs) else: post(rv, *args, **kwargs) except FatalHookException: msg = _LE("Fatal Exception running %(name)s " "post-hook: %(obj)s") LOG.exception(msg, {'name': name, 'obj': obj}) raise except Exception: msg = _LE("Exception running %(name)s post-hook: %(obj)s") LOG.exception(msg, {'name': name, 'obj': obj})
def __init__(self, driver, name, pool=None): client, ioctx = driver._connect_to_rados(pool) try: self.volume = driver.rbd.Image(ioctx, str(name), snapshot=None) except driver.rbd.Error: LOG.exception(_LE("error opening rbd image %s"), name) driver._disconnect_from_rados(client, ioctx) raise self.driver = driver self.client = client self.ioctx = ioctx
def run_pre(self, name, args, kwargs, f=None): for e in self.extensions: obj = e.obj pre = getattr(obj, 'pre', None) if pre: LOG.debug("Running %(name)s pre-hook: %(obj)s", {'name': name, 'obj': obj}) try: if f: pre(f, *args, **kwargs) else: pre(*args, **kwargs) except FatalHookException: msg = _LE("Fatal Exception running %(name)s " "pre-hook: %(obj)s") LOG.exception(msg, {'name': name, 'obj': obj}) raise except Exception: msg = _LE("Exception running %(name)s pre-hook: %(obj)s") LOG.exception(msg, {'name': name, 'obj': obj})
def _read_possible_json(serialized, info_file): try: d = jsonutils.loads(serialized) except ValueError as e: LOG.error(_LE('Error reading image info file %(filename)s: ' '%(error)s'), {'filename': info_file, 'error': e}) d = {} return d
def wrapper(*args, **kwargs): next_interval = self.retry_interval remaining = self.max_retries while True: try: return f(*args, **kwargs) except exception.DBConnectionError as e: if remaining == 0: LOG.exception(_LE('DB exceeded retry limit.')) raise exception.DBError(e) if remaining != -1: remaining -= 1 LOG.exception(_LE('DB connection error.')) # NOTE(vsergeyev): We are using patched time module, so # this effectively yields the execution # context to another green thread. time.sleep(next_interval) if self.inc_retry_interval: next_interval = min(next_interval * 2, self.max_retry_interval)
def _create_bridge(self, dev, instance): """Creating a bridge and returning its name""" br_name = self._get_br_name(dev) try: linux_net.LinuxBridgeInterfaceDriver.ensure_bridge(br_name, dev) linux_net._execute('ip', 'link', 'set', br_name, 'promisc', 'on', run_as_root=True) except processutils.ProcessExecutionError: LOG.exception(_LE("Failed while plugging vif"), instance=instance) return br_name
def connect_volume(self, connection_info, disk_info): """Connect the volume. Returns xml for libvirt.""" conf = vconfig.LibvirtConfigGuestDisk() conf.driver_name = virtutils.pick_disk_driver_name( self.connection._get_hypervisor_version(), self.is_block_dev) conf.source_device = disk_info['type'] conf.driver_format = "raw" conf.driver_cache = "none" conf.target_dev = disk_info['dev'] conf.target_bus = disk_info['bus'] conf.serial = connection_info.get('serial') # Support for block size tuning data = {} if 'data' in connection_info: data = connection_info['data'] if 'logical_block_size' in data: conf.logical_block_size = data['logical_block_size'] if 'physical_block_size' in data: conf.physical_block_size = data['physical_block_size'] # Extract rate_limit control parameters if 'qos_specs' in data and data['qos_specs']: tune_opts = [ 'total_bytes_sec', 'read_bytes_sec', 'write_bytes_sec', 'total_iops_sec', 'read_iops_sec', 'write_iops_sec' ] specs = data['qos_specs'] if isinstance(specs, dict): for k, v in specs.iteritems(): if k in tune_opts: new_key = 'disk_' + k setattr(conf, new_key, v) else: LOG.warn( _LW('Unknown content in connection_info/' 'qos_specs: %s'), specs) # Extract access_mode control parameters if 'access_mode' in data and data['access_mode']: access_mode = data['access_mode'] if access_mode in ('ro', 'rw'): conf.readonly = access_mode == 'ro' else: LOG.error( _LE('Unknown content in ' 'connection_info/access_mode: %s'), access_mode) raise exception.InvalidVolumeAccessMode( access_mode=access_mode) return conf
def connect_volume(self, connection_info, disk_info): """Connect the volume. Returns xml for libvirt.""" conf = vconfig.LibvirtConfigGuestDisk() conf.driver_name = virtutils.pick_disk_driver_name( self.connection.get_hypervisor_version(), self.is_block_dev ) conf.source_device = disk_info['type'] conf.driver_format = "raw" conf.driver_cache = "none" conf.target_dev = disk_info['dev'] conf.target_bus = disk_info['bus'] conf.serial = connection_info.get('serial') # Support for block size tuning data = {} if 'data' in connection_info: data = connection_info['data'] if 'logical_block_size' in data: conf.logical_block_size = data['logical_block_size'] if 'physical_block_size' in data: conf.physical_block_size = data['physical_block_size'] # Extract rate_limit control parameters if 'qos_specs' in data and data['qos_specs']: tune_opts = ['total_bytes_sec', 'read_bytes_sec', 'write_bytes_sec', 'total_iops_sec', 'read_iops_sec', 'write_iops_sec'] specs = data['qos_specs'] if isinstance(specs, dict): for k, v in specs.iteritems(): if k in tune_opts: new_key = 'disk_' + k setattr(conf, new_key, v) else: LOG.warn(_LW('Unknown content in connection_info/' 'qos_specs: %s'), specs) # Extract access_mode control parameters if 'access_mode' in data and data['access_mode']: access_mode = data['access_mode'] if access_mode in ('ro', 'rw'): conf.readonly = access_mode == 'ro' else: LOG.error(_LE('Unknown content in ' 'connection_info/access_mode: %s'), access_mode) raise exception.InvalidVolumeAccessMode( access_mode=access_mode) return conf
def unplug(self, instance, vif): dev = self.get_vif_devname(vif) try: self._vrouter_client.delete_port(vif['id']) #delegate the deletion of tap device to a deffered thread worker_thread = threading.Thread(target=self.delete_device, \ name='contrailvif', args=(dev,)) worker_thread.start() except (TApplicationException, processutils.ProcessExecutionError,\ RuntimeError): LOG.exception(_LE("Failed while unplugging vif"), instance=instance)
def unplug_mlnx_direct(self, instance, vif): super(LibvirtGenericVIFDriver, self).unplug(instance, vif) network = vif['network'] vnic_mac = vif['address'] fabric = network['meta']['physical_network'] try: utils.execute('ebrctl', 'del-port', fabric, vnic_mac, run_as_root=True) except processutils.ProcessExecutionError: LOG.exception(_LE("Failed while unplugging vif"), instance=instance)
def unplug_midonet(self, instance, vif): """Unplug from MidoNet network port Unbind the vif from a MidoNet virtual port. """ super(LibvirtGenericVIFDriver, self).unplug(instance, vif) dev = self.get_vif_devname(vif) port_id = vif['id'] try: utils.execute('mm-ctl', '--unbind-port', port_id, run_as_root=True) linux_net.delete_net_dev(dev) except processutils.ProcessExecutionError: LOG.exception(_LE("Failed while unplugging vif"), instance=instance)
def disconnect_volume(self, connection_info, disk_dev): """Disconnect the volume.""" export = connection_info['data']['export'] mount_path = os.path.join(CONF.libvirt.nfs_mount_point_base, utils.get_hash_str(export)) try: utils.execute('umount', mount_path, run_as_root=True) except processutils.ProcessExecutionError as exc: if 'target is busy' in exc.message: LOG.debug("The NFS share %s is still in use.", export) else: LOG.exception(_LE("Couldn't unmount the NFS share %s"), export)
def _parse_check(rule): """Parse a single base check rule into an appropriate Check object.""" # Handle the special checks if rule == '!': return FalseCheck() elif rule == '@': return TrueCheck() try: kind, match = rule.split(':', 1) except Exception: LOG.exception(_LE("Failed to understand rule %s") % rule) # If the rule is invalid, we'll fail closed return FalseCheck() # Find what implements the check if kind in _checks: return _checks[kind](kind, match) elif None in _checks: return _checks[None](kind, match) else: LOG.error(_LE("No handler for matches of kind %s") % kind) return FalseCheck()
def inner_verify_checksum(): (stored_checksum, stored_timestamp) = read_stored_checksum( base_file, timestamped=True) if stored_checksum: # NOTE(mikal): Checksums are timestamped. If we have recently # checksummed (possibly on another compute node if we are using # shared storage), then we don't need to checksum again. if (stored_timestamp and time.time() - stored_timestamp < CONF.libvirt.checksum_interval_seconds): return True # NOTE(mikal): If there is no timestamp, then the checksum was # performed by a previous version of the code. if not stored_timestamp: write_stored_info(base_file, field='sha1', value=stored_checksum) current_checksum = _hash_file(base_file) if current_checksum != stored_checksum: LOG.error(_LE('image %(id)s at (%(base_file)s): image ' 'verification failed'), {'id': img_id, 'base_file': base_file}) return False else: return True else: LOG.info(_LI('image %(id)s at (%(base_file)s): image ' 'verification skipped, no hash stored'), {'id': img_id, 'base_file': base_file}) # NOTE(mikal): If the checksum file is missing, then we should # create one. We don't create checksums when we download images # from glance because that would delay VM startup. if CONF.libvirt.checksum_base_images and create_if_missing: LOG.info(_LI('%(id)s (%(base_file)s): generating ' 'checksum'), {'id': img_id, 'base_file': base_file}) write_stored_checksum(base_file) return None
def plug_midonet(self, instance, vif): """Plug into MidoNet's network port Bind the vif to a MidoNet virtual port. """ super(LibvirtGenericVIFDriver, self).plug(instance, vif) dev = self.get_vif_devname(vif) port_id = vif['id'] try: linux_net.create_tap_dev(dev) utils.execute('mm-ctl', '--bind-port', port_id, dev, run_as_root=True) except processutils.ProcessExecutionError: LOG.exception(_LE("Failed while plugging vif"), instance=instance)