def main(): command_opt = cfg.SubCommandOpt('command', title='Command', help=_('Available commands'), handler=add_command_parsers) CONF.register_cli_opt(command_opt) service.prepare_service(sys.argv) CONF.command.func()
class ESILeapException(Exception): msg_fmt = _('An unknown exception occurred.') code = http_client.INTERNAL_SERVER_ERROR 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.msg_fmt % kwargs except Exception: message = self.msg_fmt self.message = message super(ESILeapException, self).__init__(message)
class ESILeapException(Exception): msg_fmt = _("An unknown exception occurred.") code = 500 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.msg_fmt % kwargs except Exception: message = self.msg_fmt self.message = message super(ESILeapException, self).__init__(message)
def add_command_parsers(subparsers): command_object = DBCommand() parser = subparsers.add_parser( 'create_schema', help=_('Create the database schema.')) parser.set_defaults(func=command_object.create_schema) parser = subparsers.add_parser( 'upgrade', help=_('Upgrade the database.')) parser.set_defaults(func=command_object.upgrade) parser.add_argument('--revision', nargs='?') parser = subparsers.add_parser( 'downgrade', help=_('Downgrade the database.')) parser.set_defaults(func=command_object.downgrade) parser.add_argument('--revision', nargs='?') parser = subparsers.add_parser( 'stamp', help=_('Stamp the database with provided revision.')) parser.set_defaults(func=command_object.stamp) parser.add_argument('--revision', nargs='?') parser = subparsers.add_parser( 'revision', help=_('Creates template for migration')) parser.set_defaults(func=command_object.revision) parser.add_argument('-m', '--message') parser.add_argument('--autogenerate', action='store_true') parser = subparsers.add_parser( 'version', help=_('Print the current version information and exit.')) parser.set_defaults(func=command_object.version)
class ContractNoOfferUUID(ESILeapException): msg_fmt = _("Cannot create contract without parameter offer_uuid.")
class HTTPForbidden(ESILeapException): code = http_client.FORBIDDEN msg_fmt = _('Access was denied to %(rule)s.')
class ContractNotFound(ESILeapException): msg_fmt = _("Contract with name or uuid %(contract_id)s not found.")
class ResourceNoPermission(ESILeapException): msg_fmt = _("You do not have permissions on " "%(resource_type)s %(resource_uuid)s.")
class InvalidTimeAPICommand(ESILeapException): msg_fmt = _("Attempted to get %(resource)s resource without providing " "both a valid Start Time and End Time. " "Start Time must be strictly less than End Time. " "Got %(start_time)s, %(end_time)s")
class OfferNotFound(ESILeapException): msg_fmt = _("Offer with name or uuid %(offer_uuid)s not found.")
class OfferNotAvailable(ESILeapException): msg_fmt = _("Offer %(offer_uuid)s does not have status " "'available'. Got offer status '%(status)s'.")
class LeaseNoOfferUUID(ESILeapException): msg_fmt = _('Cannot create lease without parameter offer_uuid.')
class LeaseNoTimeAvailabilities(ESILeapException): msg_fmt = _('Lease %(lease_uuid)s has no availabilities at given ' 'time range %(start_time)s, %(end_time)s.')
class LeaseNotActive(ESILeapException): msg_fmt = _('Lease with name or uuid %(lease_id)s not active.')
class LeaseNotFound(ESILeapException): msg_fmt = _('Lease with name or uuid %(lease_id)s not found.')
class LeaseDuplicateName(ESILeapException): msg_fmt = _('Duplicate leases with name %(name)s.')
class LeaseNoPermission(ESILeapException): msg_fmt = _('You do not have permissions on ' 'lease %(lease_uuid)s.')
class HTTPResourceForbidden(ESILeapException): code = http_client.FORBIDDEN msg_fmt = _('Access was denied to %(resource_type)s %(resource)s.')
class OfferNoPermission(ESILeapException): msg_fmt = _("You do not have permissions on " "offer %(offer_uuid)s.")
class OfferNotAvailable(ESILeapException): msg_fmt = _('Offer %(offer_uuid)s does not have status ' '"available". Got offer status "%(status)s".')
class OfferDuplicateName(ESILeapException): msg_fmt = _("Duplicate offers with name %(name)s.")
class InvalidTimeRange(ESILeapException): msg_fmt = _("Attempted to create %(resource)s resource with an invalid " "Start Time %(start_time)s and End Time %(end_time)s.")
class OfferNoTimeAvailabilities(ESILeapException): msg_fmt = _("Offer %(offer_uuid)s has no availabilities at given " "time range %(start_time)s, %(end_time)s.")
class ResourceNoPermissionTime(ESILeapException): msg_fmt = _('You do not have permissions on ' '%(resource_type)s %(resource_uuid)s for the time range ' '%(start_time)s - %(end_time)s.')
class ProjectNoPermission(ESILeapException): msg_fmt = _("You do not have permissions on project %(project_id)s.")
class ContractNoPermission(ESILeapException): msg_fmt = _("You do not have permissions on " "contract %(contract_uuid)s.")
class ResourceTypeUnknown(ESILeapException): msg_fmt = _("%(resource_type)s resource type unknown.")
class ContractDuplicateName(ESILeapException): msg_fmt = _("Duplicate contracts with name %(name)s.")
class InvalidAvailabilityAPICommand(ESILeapException): msg_fmt = _("Attempted to get an offer resource without providing " "both a valid Availability Start Time and Availability " "End Time. Availability Start Time must be strictly " "less than Availability End Time. " "Got %(a_start)s, %(a_end)s")
class InvalidTimeRange(ESILeapException): msg_fmt = _('Attempted to create %(resource)s resource with an invalid ' 'Start Time and End Time. Start Time must be strictly less ' 'than End Time. Got %(start_time)s, %(end_time)s.')