Esempio n. 1
0
    def delete(self, flavor_id, tenant_id):
        flavor_logic, utils = di.resolver.unpack(TenantController)
        LOG.info("TenantController - delete tenant: " + str(tenant_id))
        authentication.authorize(request, 'flavor:delete_flavor_tenant')

        try:

            result = flavor_logic.delete_tenant(flavor_id, tenant_id,
                                                request.transaction_id)

            LOG.info("TenantController - tenant deleted: " + str(result))

            event_details = 'Flavor {} tenant {} deleted'.format(
                flavor_id, tenant_id)
            utils.audit_trail('delete tenant',
                              request.transaction_id,
                              request.headers,
                              flavor_id,
                              event_details=event_details)

        except ErrorStatus as exception:
            LOG.log_exception("TenantController - Failed to delete tenant",
                              exception)
            raise err_utils.get_error(request.transaction_id,
                                      message=exception.message,
                                      status_code=exception.status_code)

        except Exception as exception:
            LOG.log_exception("TenantController - Failed to delete tenant",
                              exception)
            raise err_utils.get_error(request.transaction_id,
                                      status_code=500,
                                      error_details=str(exception))
Esempio n. 2
0
    def put(self, flavor_id, tags_wrapper):
        LOG.info("TagsController - update tags of flavor {}".format(flavor_id))
        flavor_logic, utils = di.resolver.unpack(TagsController)
        LOG.info("TagsController - update tags with {} ".format(
            tags_wrapper.tags))
        authentication.authorize(request, 'flavor:replace_flavor_tags')

        try:
            result = flavor_logic.update_tags(flavor_id, tags_wrapper,
                                              request.transaction_id)
            LOG.info("TagsController - tags updated")
            utils.audit_trail('update tags', request.transaction_id,
                              request.headers, flavor_id)
            return result

        except ErrorStatus as exception:
            LOG.log_exception("TagsController - Failed to update tags",
                              exception)
            raise err_utils.get_error(request.transaction_id,
                                      message=exception.message,
                                      status_code=exception.status_code)

        except Exception as exception:
            LOG.log_exception("TagsController - Failed to update tags",
                              exception)
            raise err_utils.get_error(request.transaction_id,
                                      status_code=500,
                                      error_details=str(exception))
Esempio n. 3
0
    def post(self, flavor_id, tags_wrapper):
        flavor_logic, utils = di.resolver.unpack(TagsController)
        LOG.info("TagsController - add tags: " + str(tags_wrapper.tags))

        authentication.authorize(request, 'flavor:add_flavor_tags')

        try:
            result = flavor_logic.add_tags(flavor_id, tags_wrapper,
                                           request.transaction_id)

            LOG.info("TagsController - tags added")
            utils.audit_trail('add tags', request.transaction_id,
                              request.headers, flavor_id)
            return result

        except ErrorStatus as exception:
            LOG.log_exception("TagsController - Failed to add tags", exception)
            raise err_utils.get_error(request.transaction_id,
                                      message=exception.message,
                                      status_code=exception.status_code)
        except Exception as exception:
            LOG.log_exception("TagsController - Failed to add tags", exception)
            raise err_utils.get_error(request.transaction_id,
                                      status_code=500,
                                      error_details=str(exception))
Esempio n. 4
0
    def delete(self, flavor_id, tag_to_delete=None):
        flavor_logic, utils = di.resolver.unpack(TagsController)
        LOG.info("TagsController - delete flavor {} tags".format(flavor_id))
        authentication.authorize(request, 'flavor:delete_flavor_tags')

        try:
            flavor_logic.delete_tags(flavor_id, tag_to_delete,
                                     request.transaction_id)
            LOG.info("TagsController - tags deleted for flavor {}".format(
                flavor_id))
            utils.audit_trail('delete tags', request.transaction_id,
                              request.headers, flavor_id, 'Saved to DB')

        except ErrorStatus as exp:
            LOG.log_exception("TagsController - Failed to delete tags", exp)
            utils.audit_trail('delete tags', request.transaction_id,
                              request.headers, flavor_id)
            raise err_utils.get_error(request.transaction_id,
                                      message=exp.message,
                                      status_code=exp.status_code)
        except Exception as exp:
            LOG.log_exception("TagsController - Failed to delete tags", exp)
            utils.audit_trail('delete tags', request.transaction_id,
                              request.headers, flavor_id)
            raise err_utils.get_error(request.transaction_id,
                                      status_code=500,
                                      error_details=str(exp))

        return
Esempio n. 5
0
    def post(self, flavor_id, region_wrapper):
        flavor_logic, utils = di.resolver.unpack(RegionController)

        LOG.info("RegionController - add regions: " + str(region_wrapper))
        authentication.authorize(request, 'flavor:add_flavor_regions')

        try:
            result = flavor_logic.add_regions(flavor_id, region_wrapper,
                                              request.transaction_id)

            LOG.info("RegionController - regions added: " + str(result))

            event_details = 'Flavor {} regions: {} added'.format(
                flavor_id, [r.name for r in region_wrapper.regions])
            utils.audit_trail('add regions',
                              request.transaction_id,
                              request.headers,
                              flavor_id,
                              event_details=event_details)
            return result

        except ErrorStatus as exception:
            LOG.log_exception("RegionController - Failed to add region",
                              exception)
            raise err_utils.get_error(request.transaction_id,
                                      message=exception.message,
                                      status_code=exception.status_code)

        except Exception as exception:
            LOG.log_exception("RegionController - Failed to add region",
                              exception)
            raise err_utils.get_error(request.transaction_id,
                                      status_code=500,
                                      error_details=str(exception))
Esempio n. 6
0
    def get(self, flavor_id):
        flavor_logic, utils = di.resolver.unpack(OsExtraSpecsController)

        LOG.info(
            "OsExtraSpecsController - get all extra specs for flavor: {} ".
            format(flavor_id))
        authentication.authorize(request, 'flavor:get_flavor_extra_specs')

        try:
            result = flavor_logic.get_extra_specs_uuid(flavor_id,
                                                       request.transaction_id)
            LOG.info(
                "OsExtraSpecsController - GOT extra specs: {} ".format(result))
            utils.audit_trail("get extra specs", request.transaction_id,
                              request.headers, flavor_id)
            return result

        except ErrorStatus as exception:
            LOG.log_exception(
                "OsExtraSpecsController - Failed to get extra specs",
                exception)
            raise err_utils.get_error(request.transaction_id,
                                      message=exception.message,
                                      status_code=exception.status_code)

        except Exception as exception:
            LOG.log_exception(
                "OsExtraSpecsController - Failed to get extra specs",
                exception)
            raise err_utils.get_error(request.transaction_id,
                                      status_code=500,
                                      error_details=str(exception))
Esempio n. 7
0
    def post(self, flavor_id, extra_specs_wrapper):
        flavor_logic, utils = di.resolver.unpack(OsExtraSpecsController)
        LOG.info("OsExtraSpecsController - add extra specs: " +
                 str(extra_specs_wrapper.os_extra_specs))
        authentication.authorize(request, 'flavor:add_flavor_extra_specs')

        try:
            # for backward_compatibility
            extra_specs_wrapper = self._extra_specs_redefined(
                extra_specs_wrapper)

            result = flavor_logic.add_extra_specs(flavor_id,
                                                  extra_specs_wrapper,
                                                  request.transaction_id)
            LOG.info("OsExtraSpecsController - extra specs added ")
            utils.audit_trail('add extra specs', request.transaction_id,
                              request.headers, flavor_id)
            return result

        except ErrorStatus as exception:
            LOG.log_exception(
                "OsExtraSpecsController - Failed to add extra specs",
                exception)
            raise err_utils.get_error(request.transaction_id,
                                      message=exception.message,
                                      status_code=exception.status_code)

        except Exception as exception:
            LOG.log_exception(
                "OsExtraSpecsController - Failed to add extra specs",
                exception)
            raise err_utils.get_error(request.transaction_id,
                                      status_code=500,
                                      error_details=str(exception))
Esempio n. 8
0
    def delete(self, flavor_id, extra_spec=None):
        flavor_logic, utils = di.resolver.unpack(OsExtraSpecsController)
        LOG.info("OsExtraSpecsController - delete flavor {} extra spec".format(
            flavor_id))
        authentication.authorize(request, 'flavor:delete_flavor_extra_specs')

        try:
            flavor_logic.delete_extra_specs(flavor_id, request.transaction_id,
                                            extra_spec)
            LOG.info(
                "OsExtraSpecsController - extra spec was deleted for  flavor {} c"
                .format(flavor_id))
            utils.audit_trail('delete extra spec', request.transaction_id,
                              request.headers, flavor_id)
            return

        except ErrorStatus as exception:
            LOG.log_exception(
                "OsExtraSpecsController - Failed to delete extra specs",
                exception)
            raise err_utils.get_error(request.transaction_id,
                                      message=exception.message,
                                      status_code=exception.status_code)

        except Exception as exception:
            LOG.log_exception(
                "OsExtraSpecsController - Failed to delete extra specs",
                exception)
            raise err_utils.get_error(request.transaction_id,
                                      status_code=500,
                                      error_details=str(exception))
Esempio n. 9
0
    def get(self, flavor_uuid_or_name):
        flavor_logic, utils = di.resolver.unpack(FlavorController)
        LOG.info("FlavorController - GetFlavorDetails: uuid or name is " +
                 flavor_uuid_or_name)
        authentication.authorize(request, 'flavor:get_one')

        try:
            result = flavor_logic.get_flavor_by_uuid_or_name(
                flavor_uuid_or_name)
            LOG.info("FlavorController - GetFlavorDetails finished well: " +
                     str(result))
            return result

        except ErrorStatus as exception:
            LOG.log_exception("FlavorController - Failed to GetFlavorDetails",
                              exception)
            raise err_utils.get_error(request.transaction_id,
                                      message=exception.message,
                                      status_code=exception.status_code)

        except Exception as exception:
            LOG.log_exception("FlavorController - Failed to GetFlavorDetails",
                              exception)
            raise err_utils.get_error(request.transaction_id,
                                      status_code=500,
                                      error_details=str(exception))
Esempio n. 10
0
    def delete(self, flavor_uuid=None):
        authentication.authorize(request, 'flavor:delete')
        flavor_logic, utils = di.resolver.unpack(FlavorController)

        try:
            LOG.info("FlavorController - delete: uuid is " + flavor_uuid)
            flavor_logic.delete_flavor_by_uuid(flavor_uuid)
            LOG.info("FlavorController - delete flavor finished well")

            event_details = 'Flavor {} deleted'.format(flavor_uuid)
            utils.audit_trail('delete flavor by uuid',
                              request.transaction_id,
                              request.headers,
                              flavor_uuid,
                              event_details=event_details)

        except ErrorStatus as exception:
            LOG.log_exception("FlavorController - Failed to delete flavor",
                              exception)
            raise err_utils.get_error(request.transaction_id,
                                      message=exception.message,
                                      status_code=exception.status_code)

        except Exception as exception:
            LOG.log_exception("FlavorController - Failed to delete flavor",
                              exception)
            raise err_utils.get_error(request.transaction_id,
                                      status_code=500,
                                      error_details=str(exception))
Esempio n. 11
0
    def get_all(self,
                visibility=None,
                region=None,
                tenant=None,
                series=None,
                starts_with=None,
                contains=None,
                alias=None):
        flavor_logic, utils = di.resolver.unpack(FlavorController)
        LOG.info("FlavorController - GetFlavorlist")
        authentication.authorize(request, 'flavor:get_all')

        try:
            result = flavor_logic.get_flavor_list_by_params(
                visibility, region, tenant, series, starts_with, contains,
                alias)

            return result
        except ErrorStatus as exception:
            LOG.log_exception("FlavorController - Failed to GetFlavorlist",
                              exception)
            raise err_utils.get_error(request.transaction_id,
                                      message=exception.message,
                                      status_code=exception.status_code)

        except Exception as exception:
            LOG.log_exception("FlavorController - Failed to GetFlavorlist",
                              exception)
            raise err_utils.get_error(request.transaction_id,
                                      status_code=500,
                                      error_details=str(exception))
Esempio n. 12
0
    def post(self, flavors):
        flavor_logic, utils = di.resolver.unpack(FlavorController)
        uuid = "FailedToGetFromUUIDGen"
        LOG.info("FlavorController - Createflavor: " + str(flavors))
        authentication.authorize(request, 'flavor:create')

        try:

            if not flavors.flavor.id:
                uuid = utils.make_uuid()
            else:
                try:
                    uuid = utils.create_existing_uuid(
                        flavor_logic.get_fixed_uuid(flavors.flavor.id))
                except TypeError:
                    LOG.error("UUID already exist")
                    raise ErrorStatus(409, 'UUID already exists')

            result = flavor_logic.create_flavor(flavors, uuid,
                                                request.transaction_id)

            LOG.info("FlavorController - Flavor Created: " + str(result))

            event_details = 'Flavor {} created in regions: {}, tenants: {} with visibility: {}'.format(
                uuid, [r.name for r in flavors.flavor.regions],
                flavors.flavor.tenants, flavors.flavor.visibility)
            utils.audit_trail('create flavor',
                              request.transaction_id,
                              request.headers,
                              uuid,
                              event_details=event_details)
            return result

        except ErrorStatus as exception:
            LOG.log_exception("FlavorController - Failed to CreateFlavor",
                              exception)
            raise err_utils.get_error(request.transaction_id,
                                      message=exception.message,
                                      status_code=exception.status_code)

        except ValueError as exception:
            LOG.log_exception("FlavorController - Failed to CreateFlavor",
                              exception)
            raise err_utils.get_error(request.transaction_id,
                                      status_code=400,
                                      error_details=exception.message)

        except Exception as exception:
            LOG.log_exception("FlavorController - Failed to CreateFlavor",
                              exception)
            raise err_utils.get_error(request.transaction_id,
                                      status_code=500,
                                      error_details=exception.message)
Esempio n. 13
0
    def post(self, flavor_id, tenant_wrapper):
        flavor_logic, utils = di.resolver.unpack(TenantController)
        LOG.info("TenantController - add tenants: " + str(tenant_wrapper))
        authentication.authorize(request, 'flavor:add_flavor_tenants')

        try:
            result = flavor_logic.add_tenants(flavor_id, tenant_wrapper,
                                              request.transaction_id)

            LOG.info("TenantController - tenants added: " + str(result))

            event_details = 'Flavor {} tenants: {} added'.format(
                flavor_id, tenant_wrapper.tenants)
            utils.audit_trail('add tenants',
                              request.transaction_id,
                              request.headers,
                              flavor_id,
                              event_details=event_details)
            return result

        except ValueError as exception:
            LOG.log_exception("TenantController - Failed to add tenants",
                              exception)
            raise err_utils.get_error(request.transaction_id,
                                      message=exception.message,
                                      status_code=400)

        except ErrorStatus as exception:
            LOG.log_exception("TenantController - Failed to add tenants",
                              exception)
            raise err_utils.get_error(request.transaction_id,
                                      message=exception.message,
                                      status_code=exception.status_code)

        except Exception as exception:
            LOG.log_exception("TenantController - Failed to add tenants",
                              exception)
            raise err_utils.get_error(request.transaction_id,
                                      status_code=500,
                                      error_details=str(exception))
Esempio n. 14
0
    def get(self, flavor_id):
        flavor_logic, utils = di.resolver.unpack(TagsController)
        LOG.info("TagsController - get tags of flavor {}".format(flavor_id))
        authentication.authorize(request, 'flavor:get_flavor_tags')

        try:
            result = flavor_logic.get_tags(flavor_id)
            LOG.debug("TagsController - got tags successfully")
            utils.audit_trail('get tags', request.transaction_id,
                              request.headers, flavor_id)
            return TagsWrapper(result)

        except ErrorStatus as exception:
            LOG.log_exception("TagsController - Failed to get tags", exception)
            raise err_utils.get_error(request.transaction_id,
                                      message=exception.message,
                                      status_code=exception.status_code)

        except Exception as exception:
            LOG.log_exception("TagsController - Failed to get tags", exception)
            raise err_utils.get_error(request.transaction_id,
                                      status_code=500,
                                      error_details=str(exception))