Repository URL to install this package:
Version:
6.0.1.dev7 ▾
|
# vim: tabstop=4 shiftwidth=4 softtabstop=4
# Copyright (c) 2013 TrilioData, Inc.
# All Rights Reserved.
"""WorkloadMgr base exception handling.
Includes decorator for re-raising WorkloadMgr-type exceptions.
SHOULD include dedicated exception logging.
"""
from oslo_config import cfg
import webob.exc
from workloadmgr.openstack.common.gettextutils import _
from workloadmgr import flags
from workloadmgr.openstack.common import log as logging
LOG = logging.getLogger(__name__)
exc_log_opts = [
cfg.BoolOpt('fatal_exception_format_errors',
default=False,
help='make exception message format errors fatal'),
]
FLAGS = flags.FLAGS
FLAGS.register_opts(exc_log_opts)
class ConvertedException(webob.exc.WSGIHTTPException):
def __init__(self, code=0, title="", explanation=""):
self.code = code
self.title = title
self.explanation = explanation
super(ConvertedException, self).__init__()
class ProcessExecutionError(IOError):
def __init__(self, stdout=None, stderr=None, exit_code=None, cmd=None,
description=None):
self.exit_code = exit_code
self.stderr = stderr
self.stdout = stdout
self.cmd = cmd
self.description = description
if description is None:
description = _('Unexpected error while running command.')
if exit_code is None:
exit_code = '-'
message = _('%(description)s\nCommand: %(cmd)s\n'
'Exit code: %(exit_code)s\nStdout: %(stdout)r\n'
'Stderr: %(stderr)r') % locals()
IOError.__init__(self, message)
class Error(Exception):
pass
class DBError(Error):
"""Wraps an implementation specific exception."""
def __init__(self, inner_exception=None):
self.inner_exception = inner_exception
super(DBError, self).__init__(str(inner_exception))
def wrap_db_error(f):
def _wrap(*args, **kwargs):
try:
return f(*args, **kwargs)
except UnicodeEncodeError:
raise InvalidUnicodeParameter()
except Exception as e:
LOG.exception(_('DB exception wrapped.'))
raise DBError(e)
_wrap.__name__ = f.__name__
return _wrap
class WorkloadMgrException(Exception):
"""Base WorkloadMgr Exception
To correctly use this class, inherit from it and define
a 'message' property. That message will get printf'd
with the keyword arguments provided to the constructor.
"""
message = _("Error: {reason}")
code = 500
headers = {}
safe = False
def __init__(self, message=None, **kwargs):
self.kwargs = kwargs
if 'code' not in self.kwargs:
try:
self.kwargs['code'] = self.code
except AttributeError:
pass
if not message:
try:
message = self.message.format_map(kwargs)
except Exception as e:
# kwargs doesn't match a variable in the message
# log the issue and the kwargs
LOG.exception(_('Exception in string format operation'))
LOG.error("The message: {}".format(self.message))
LOG.error("The attributes: {}".format(kwargs))
if FLAGS.fatal_exception_format_errors:
raise e
else:
# at least get the core message out if something happened
message = self.message
super(WorkloadMgrException, self).__init__(message)
class InvalidState(WorkloadMgrException):
message = _("Invalid state") + ": {reason}"
class ErrorOccurred(WorkloadMgrException):
message = "{reason}"
class GlanceConnectionFailed(WorkloadMgrException):
message = _("Connection to glance failed: {reason}")
class NotAuthorized(WorkloadMgrException):
message = _("Not authorized.")
code = 403
class AdminRequired(NotAuthorized):
message = _("User does not have admin privileges")
class PolicyNotAuthorized(NotAuthorized):
message = _("Policy doesn't allow {action} to be performed.")
class ImageNotAuthorized(WorkloadMgrException):
message = _("Not authorized for image {image_id}.")
class Invalid(WorkloadMgrException):
message = _("Unacceptable parameters: {reason}")
code = 400
class Forbidden(WorkloadMgrException):
message = _("You are not authorized to use {action}.")
class AuthorizationFailure(WorkloadMgrException):
message = _("Authorization failed.")
class MissingCredentialError(WorkloadMgrException):
msg_fmt = _("Missing required credential: {required}")
class InvalidSnapshot(Invalid):
message = _("Invalid snapshot: {reason}")
class InvalidWorkload(Invalid):
message = _("Invalid workload: {reason}")
class InvalidRequest(Invalid):
message = _("The request is invalid. {reason}")
class InvalidResults(Invalid):
message = _("The results are invalid.")
class InvalidInput(Invalid):
message = _("Invalid input received: {reason}")
class InvalidVolume(Invalid):
message = _("Invalid volume: {reason}")
class InvalidContentType(Invalid):
message = _("Invalid content type {content_type}.")
class InvalidUnicodeParameter(Invalid):
message = _("Invalid Parameter: "
"Unicode is not supported by the current database.")
# Cannot be templated as the error syntax varies.
# msg needs to be constructed when raised.
class InvalidParameterValue(Invalid):
message = _("{err}")
class ServiceUnavailable(Invalid):
message = _("Service is unavailable at this time.")
class ImageUnacceptable(Invalid):
message = _("Image {image_id} is unacceptable: {reason}")
class InvalidUUID(Invalid):
message = _("Expected a uuid but received {uuid}.")
class NotFound(WorkloadMgrException):
message = _("Resource could not be found.")
code = 404
safe = True
class VolumeNotFound(NotFound):
message = _("Volume {volume_id} could not be found.")
class InvalidImageRef(Invalid):
message = _("Invalid image href {image_href}.")
class ImageNotFound(NotFound):
message = _("Image {image_id} could not be found.")
class ServiceNotFound(NotFound):
message = _("Service {service_id} could not be found.")
class ServiceNotFoundOnHost(NotFound):
message = _("Service {topic} on host {host} could not be found.")
class HostNotFound(NotFound):
message = _("Host {host} could not be found.")
class SchedulerHostFilterNotFound(NotFound):
message = _("Scheduler Host Filter {filter_name} could not be found.")
class SchedulerHostWeigherNotFound(NotFound):
message = _("Scheduler Host Weigher {weigher_name} could not be found.")
class HostBinaryNotFound(NotFound):
message = _("Could not find binary {binary} on host {host}.")
class InvalidReservationExpiration(Invalid):
message = _("Invalid reservation expiration {expire}.")
class InvalidQuotaValue(Invalid):
message = _("Change would make usage less than 0 for the following "
"resources: {unders}")
class QuotaNotFound(NotFound):
message = _("Quota could not be found")
class QuotaResourceUnknown(QuotaNotFound):
message = _("Unknown quota resources {unknown}.")
class ProjectQuotaNotFound(QuotaNotFound):
message = _("Quota for project {project_id} could not be found.")
class QuotaClassNotFound(QuotaNotFound):
message = _("Quota class {class_name} could not be found.")
class QuotaUsageNotFound(QuotaNotFound):
message = _("Quota usage for project {project_id} could not be found.")
class ReservationNotFound(QuotaNotFound):
message = _("Quota reservation {uuid} could not be found.")
class OverQuota(WorkloadMgrException):
message = _("Quota exceeded for resources: {overs}")
class FileNotFound(NotFound):
message = _("File {file_path} could not be found.")
class ClassNotFound(NotFound):
message = _("Class {class_name} could not be found: {exception}")
class NotAllowed(WorkloadMgrException):
message = _("Action not allowed.")
class Duplicate(WorkloadMgrException):
message = _("Duplicate Entries not allowed.")
class MigrationError(WorkloadMgrException):
message = _("Migration error: {reason}")
class MalformedRequestBody(WorkloadMgrException):
message = _("Malformed message body: {reason}")
class ConfigNotFound(NotFound):
message = _("Could not find config at {path}")
class PasteAppNotFound(NotFound):
message = _("Could not load paste app '{name}' from {path}")
class NoValidHost(WorkloadMgrException):
message = _("No valid host was found. {reason}")
class WillNotSchedule(WorkloadMgrException):
message = _("Host {host} is not up or doesn't exist.")
class QuotaError(WorkloadMgrException):
message = _("Quota exceeded: code={code}")
code = 413
headers = {'Retry-After': 0}
safe = True
class QuotaLimitExceededError(Invalid):
message = _("Maximum allowed quota exceeded, contact the admin")
class SnapshotLimitExceeded(QuotaError):
message = _("Maximum number of snapshots allowed ({allowed}) exceeded")
class UnknownCmd(Invalid):
message = _("Unknown or unsupported command {cmd}")
class MalformedResponse(Invalid):
message = _("Malformed response to command {cmd}: {reason}")
class BadHTTPResponseStatus(WorkloadMgrException):
message = _("Bad HTTP response status {status}")
class InstanceNotFound(NotFound):
message = _("Instance {instance_id} could not be found.")
class ImageCopyFailure(Invalid):
message = _("Failed to copy image to volume")
class WorkloadTypesNotFound(NotFound):
message = _("WorkloadTypes could not be found.")
class WorkloadTypeNotFound(NotFound):
message = _("WorkloadType {workload_type_id} could not be found.")
class WorkloadsNotFound(NotFound):
message = _("Workloads could not be found.")
class WorkloadNotFound(NotFound):
message = _("Workload {workload_id} could not be found.")
class WorkloadVMsNotFound(NotFound):
message = _("WorkloadVMs of {workload_id} could not be found.")
class WorkloadVMNotFound(NotFound):
message = _("WorkloadVM {workload_vm_id} could not be found.")
class WorkloadAlreadyExist(WorkloadMgrException):
message = _("Workload Already Exist.")
class SnapshotsOfHostNotFound(NotFound):
message = _("Snapshots for host: {host} could not be found.")
class SnapshotsNotFound(NotFound):
message = _("Snapshots could not be found.")
class SnapshotsOfWorkloadNotFound(NotFound):
message = _("Snapshots of {workload_id} could not be found.")
class SnapshotNotFound(NotFound):
message = _("Snapshot {snapshot_id} could not be found.")
class SnapshotVMsNotFound(NotFound):
message = _("SnapshotVMs of {snapshot_id} could not be found.")
class SnapshotVMNotFound(NotFound):
message = _("SnapshotVM {snapshot_vm_id} could not be found.")
class SnapshotResourcesNotFound(NotFound):
message = _("Snapshot Resources of {snapshot_id} could not be found.")
class SnapshotVMResourcesNotFound(NotFound):
message = _(
"SnapshotVMResources of VM {snapshot_vm_id} Snapshot {snapshot_id} could not be found.")
class SnapshotVMResourceNotFound(NotFound):
message = _(
"SnapshotVMResource {snapshot_vm_resource_id} could not be found.")
class SnapshotVMResourceWithNameNotFound(NotFound):
message = _(
"SnapshotVMResource {resource_name} of VM {snapshot_vm_id} Snapshot {snapshot_id} could not be found.")
class SnapshotVMResourceWithPITNotFound(NotFound):
message = _(
"SnapshotVMResource {resource_pit_id} of VM {snapshot_vm_id} Snapshot {snapshot_id} could not be found.")
class VMDiskResourceSnapsNotFound(NotFound):
message = _(
"VMDiskResourceSnaps of SnapshotVMResource {snapshot_vm_resource_id} could not be found.")
class VMDiskResourceSnapNotFound(NotFound):
message = _(
"VMDiskResourceSnap {vm_disk_resource_snap_id} could not be found.")
class VMDiskResourceSnapTopNotFound(NotFound):
message = _(
"Top VMDiskResourceSnap of Snapshot VM Resource {snapshot_vm_resource_id} could not be found.")
class VMNetworkResourceSnapsNotFound(NotFound):
message = _(
"VMNetworkResourceSnaps of SnapshotVMResource {snapshot_vm_resource_id} could not be found.")
class VMNetworkResourceSnapNotFound(NotFound):
message = _(
"VMNetworkResourceSnap {vm_network_resource_snap_id} could not be found.")
class VMSecurityGroupRuleSnapsNotFound(NotFound):
message = _(
"VMSecurityGroupRuleSnaps of VMSecurityGroupSnap {vm_security_group_snap_id} could not be found.")
class VMSecurityGroupRuleSnapNotFound(NotFound):
message = _(
"VMSecurityGroupRuleSnap {vm_security_group_rule_snap_id} of VMSecurityGroup {vm_security_group_snap_id} could not be found.")
class RestoresNotFound(NotFound):
message = _("Restores could not be found.")
class RestoresOfSnapshotNotFound(NotFound):
message = _("Restores of {snapshot_id} could not be found.")
class RestoreNotFound(NotFound):
message = _("Restore {restore_id} could not be found.")
class RestoredVMsNotFound(NotFound):
message = _("RestoredVMs of {restore_id} could not be found.")
class RestoredVMNotFound(NotFound):
message = _("RestoredVM {restored_vm_id} could not be found.")
class RestoredResourcesNotFound(NotFound):
message = _("Restored Resources of {restore_id} could not be found.")
class RestoredVMResourcesNotFound(NotFound):
message = _(
"RestoredVMResources of VM {restore_vm_id} Restore {restore_id} could not be found.")
class RestoredVMResourceNotFound(NotFound):
message = _(
"RestoredVMResource {restore_vm_resource_id} could not be found.")
class RestoredVMResourceWithNameNotFound(NotFound):
message = _(
"RestoredVMResource {resource_name} of VM {restore_vm_id} Restore {restore_id} could not be found.")
class RestoredVMResourceWithIdNotFound(NotFound):
message = _("RestoredVMResource {id} is not be found.")
class AllowedQuotaNotFound(NotFound):
message = _("AllowedQuota {allowed_quota_id} could not be found.")
class QuotaTypeNotFound(NotFound):
message = _("Quota type id {quota_type_id} could not be found.")
class InvalidRestoreOptions(Invalid):
message = _("Invalid restore options: {reason}")
class SwiftConnectionFailed(WorkloadMgrException):
message = _("Connection to swift failed: {reason}")
class DatastoreNotFound(NotFound):
message = _("Could not find the datastore.")
class ResourcePoolNotFound(NotFound):
message = _("Could not find the resourcepool.")
class VMFolderNotFound(NotFound):
message = _("Could not find the vmfolder.")
class VMNotFound(NotFound):
message = _("Could not find the VM.")
class NetworkNotFound(NotFound):
message = _("Could not find the Network.")
class InstanceSuspendFailure(Invalid):
msg_fmt = _("Failed to suspend instance: {reason}")
class InstanceResumeFailure(Invalid):
msg_fmt = _("Failed to resume instance: {reason}.")
class InstancePowerOffFailure(Invalid):
msg_fmt = _("Failed to power off instance: {reason}.")
class DatacenterNotFound(NotFound):
message = _("Could not find the Datacenter.")
class SettingNotFound(NotFound):
message = _("Setting {setting_name} could not be found.")
class VaultStorageNotFound(NotFound):
message = _("Vault Storage {vault_storage_id} could not be found.")
class TaskNotFound(NotFound):
message = _("Task {task_id} could not be found.")
class FileSearchNotFound(NotFound):
message = _("File Search {search_id} could not be found.")
class InvalidLicense(Invalid):
pass
class InternalError(Invalid):
pass
class TransferNotFound(NotFound):
message = _("Transfer {transfer_id} could not be found.")
class TransferNotAllowed(Invalid):
message = _(
"Transfer {workload_id} is not allowed within the same cloud.")
class MediaNotSupported(Invalid):
message = _("Transfer {media} is not allowed within the same cloud.")
class BackupTargetOffline(Invalid):
message = _("Backup {endpoint} is offline. Cannot be accessed")
class InvalidNFSMountPoint(Invalid):
message = "{reason}"
class ProjectNotFound(NotFound):
message = _("Project {project_id} could not be found.")
class UserNotFound(NotFound):
message = _("User {user_id} could not be found.")
class RoleNotFound(NotFound):
message = _("User {user_id} does not have role '{role_name}' on "
"project {project_id}")
class ConfigWorkloadNotFound(NotFound):
message = _("Config Workload {id} could not be found.")
class ConfigBackupNotFound(NotFound):
message = _("Config backup {backup_id} could not be found.")
class PolicyNotFound(NotFound):
message = _("Policy {policy_id} could not be found.")
class PolicyFieldNotFound(NotFound):
message = _("Policy field {policy_field_id} could not be found.")
class PolicyValueNotFound(NotFound):
message = _("Policy field value {policy_value_id} could not be found.")
class PolicyAssignmentNotFound(NotFound):
message = _(
"Policy assignment {policy_assignment_id} could not be found.")
class NetworkResourcesNotFound(NotFound):
message = _("No network resources found for snapshot {snapshot_id}")
class NetworkResourceNotFound(NotFound):
message = _("Network Resource {resource_id} could not be found.")
class ScheduledJobsNotFound(NotFound):
message = _("No schedule job found for workload {workload_id}. Error {code}")
class MigrationPlanNotFound(NotFound):
message = _("MigrationPlan {migration_plan_id} is not found.")
class MigrationPlansNotFound(NotFound):
message = _("No migration plans to import found.")
class MigrationPlanVMsNotFound(NotFound):
message = _("MigrationPlan VMs {migration_plan_id} is not found.")
class MigrationNotFound(NotFound):
message = _("Migration {migration_id} is not found.")
class MigrationPlanVMNetworkResourceNotFound(NotFound):
message = _("MigrationPlanVMNetworkResourceNotFound {migration_plan_vm_network_resource_id} is not found.")
class MigrationPlanVMSecurityGroupRuleNotFound(NotFound):
message = _("MigrationPlanVMSecurityGroupRuleResourceNotFound {migration_plan_vm_security_group_id} is not found.")
class MigrationPlanVMDiskResourceNotFound(NotFound):
message = _("MigrationPlanVMDiskNotFound {migration_plan_vm_disk_resource_id} is not found.")
class LicenseNotFound(NotFound):
message = _("License not found, Please apply the license and accept the agreement.")
class EulaNotFound(NotFound):
message = _("License agreement required, Pleas re-apply the license and accept the agreement.")
class MigrationVMResourcesNotFound(NotFound):
message = _("Migration VM resources for {migration_id} is not found.")
class BackupTargetNotFound(NotFound):
message = _("Backup target {backup_target_id} could not be found.")
class BackupTargetTypeNotFound(NotFound):
message = _("Backup target type {backup_target_type_id} could not be found.")
class BackupTargetTypeByNameNotFound(NotFound):
message = _("Backup target type {backup_target_type_name} could not be found.")
class BackupTargetTypeUpdateNotAllowed(Invalid):
message = _("Backup target of Backup target type: {backup_target_type_id} cannot be updated.")
class BackupTargetTypeDefaultUpdateNotAllowed(Invalid):
message = _("Default Backup target type: {backup_target_type_id} cannot be updated.")
class BackupTargetTypeDefaultDeleteNotAllowed(Invalid):
message = _("Default Backup target type: {backup_target_type_id} cannot be deleted.")
class BackupTargetTypeNameDuplicateNotAllowed(Invalid):
message = _("backup target type name: {backup_target_type_name} already exists. Please choose different name.")
class BackupTargetDefaultTypeNotFound(NotFound):
message = _("Backup target type Default could not be found.")