def start(self): try: self._open_pipe() if self._log_file_path: self._log_file_handle = open(self._log_file_path, 'ab', 1) jobs = [self._read_from_pipe] if self._input_queue and self._connect_event: jobs.append(self._write_to_pipe) for job in jobs: worker = threading.Thread(target=job) worker.setDaemon(True) worker.start() self._workers.append(worker) except Exception as err: msg = (_("Named pipe handler failed to initialize. " "Pipe Name: %(pipe_name)s " "Error: %(err)s") % { 'pipe_name': self._pipe_name, 'err': err }) LOG.error(msg) self.stop() raise exceptions.OSWinException(msg)
def _enable_metrics(self, element, metrics_names=None): if not metrics_names: definition_paths = [None] else: definition_paths = [] for metrics_name in metrics_names: metrics_def = self._metrics_defs.get(metrics_name) if not metrics_def: LOG.warning("Metric not found: %s", metrics_name) continue definition_paths.append(metrics_def.path_()) element_path = element.path_() for definition_path in definition_paths: ret_val = self._metrics_svc.ControlMetrics( Subject=element_path, Definition=definition_path, MetricCollectionEnabled=self._METRICS_ENABLED)[0] if ret_val: err_msg = _("Failed to enable metrics for resource " "%(resource_name)s. " "Return code: %(ret_val)s.") % dict( resource_name=element.ElementName, ret_val=ret_val) raise exceptions.OSWinException(err_msg)
def _get_shared_lib_module(lib_name): if lib_name not in libs: err_msg = _("Unsupported library: %s.") raise exceptions.OSWinException(err_msg % lib_name) module = importlib.import_module('os_win.utils.winapi.libs.%s' % lib_name) return module
def rmtree(self, path): try: shutil.rmtree(path) except exceptions.WindowsError as ex: # NOTE(claudiub): convert it to an OSWinException in order to use # the retry_decorator. raise exceptions.OSWinException(six.text_type(ex), error_code=ex.winerror)
def _unique_result(objects, resource_name): n = len(objects) if n == 0: raise exceptions.NotFound(resource=resource_name) elif n > 1: raise exceptions.OSWinException( _('Duplicate resource name found: %s') % resource_name) else: return objects[0]
def rescan_disks(self): ret = self._conn_storage.Msft_StorageSetting.UpdateHostStorageCache() if isinstance(ret, collections.Iterable): ret = ret[0] if ret: err_msg = _("Rescanning disks failed. Error code: %s.") raise exceptions.OSWinException(err_msg % ret)
def _conn_hgs(self): if not self._conn_hgs_attr: try: namespace = self._HGS_NAMESPACE % self._host self._conn_hgs_attr = self._get_wmi_conn(namespace) except Exception: raise exceptions.OSWinException( _("Namespace %(namespace)s is not supported on this " "Windows version.") % {'namespace': namespace}) return self._conn_hgs_attr
def _conn_msps(self): if not self._conn_msps_attr: try: namespace = self._MSPS_NAMESPACE % self._host self._conn_msps_attr = self._get_wmi_conn(namespace) except Exception: raise exceptions.OSWinException( _("Namespace %(namespace)s not found. Make sure " "FabricShieldedTools feature is installed.") % {'namespace': namespace}) return self._conn_msps_attr
def live_migrate_vm(self, vm_name, dest_host): self.check_live_migration_config() conn_v2_remote = self._get_conn_v2(dest_host) vm = self._get_vm(self._compat_conn, vm_name) rmt_ip_addr_list = self._get_ip_address_list(conn_v2_remote, dest_host) planned_vms = self._get_planned_vms(conn_v2_remote, vm) if len(planned_vms) > 1: err_msg = _("Multiple planned VMs were found for VM %(vm_name)s " "on host %(dest_host)s") raise exceptions.OSWinException( err_msg % dict(vm_name=vm_name, dest_host=dest_host)) elif not planned_vms: # TODO(claudiub): Remove this branch after the livemigrationutils # usage has been updated to create planned VM on the destination # host beforehand. planned_vm = None disk_paths = self._get_physical_disk_paths(vm_name) if disk_paths: vmutils_remote = vmutils.VMUtils(dest_host) disk_paths_remote = self._get_remote_disk_data(vmutils_remote, disk_paths, dest_host) planned_vm = self._create_planned_vm(conn_v2_remote, self._compat_conn, vm, rmt_ip_addr_list, dest_host) self._update_planned_vm_disk_resources( conn_v2_remote, planned_vm, vm_name, disk_paths_remote) else: planned_vm = planned_vms[0] new_resource_setting_data = self._get_vhd_setting_data(vm) self._live_migrate_vm(self._compat_conn, vm, planned_vm, rmt_ip_addr_list, new_resource_setting_data, dest_host)
def _ensure_listener_running(self): if not self._running: raise exceptions.OSWinException( _("Cluster event listener is not running."))