Пример #1
0
    def delete(self, availability_zone_name):
        """Deletes an Availability Zone"""
        context = pecan.request.context.get('octavia_context')

        self._auth_validate_action(context, context.project_id,
                                   constants.RBAC_DELETE)
        if availability_zone_name == constants.NIL_UUID:
            raise exceptions.NotFound(resource='Availability Zone',
                                      id=constants.NIL_UUID)
        serial_session = db_api.get_session(autocommit=False)
        serial_session.connection(
            execution_options={'isolation_level': 'SERIALIZABLE'})
        try:
            self.repositories.availability_zone.delete(
                serial_session, name=availability_zone_name)
            serial_session.commit()
        # Handle when load balancers still reference this availability_zone
        except odb_exceptions.DBReferenceError:
            serial_session.rollback()
            raise exceptions.ObjectInUse(object='Availability Zone',
                                         id=availability_zone_name)
        except sa_exception.NoResultFound:
            serial_session.rollback()
            raise exceptions.NotFound(resource='Availability Zone',
                                      id=availability_zone_name)
        except Exception as e:
            with excutils.save_and_reraise_exception():
                LOG.error('Unknown availability_zone delete exception: %s',
                          str(e))
                serial_session.rollback()
        finally:
            serial_session.close()
Пример #2
0
    def put(self, id, flavor_profile_):
        """Updates a flavor Profile."""
        flavorprofile = flavor_profile_.flavorprofile
        context = pecan.request.context.get('octavia_context')
        self._auth_validate_action(context, context.project_id,
                                   constants.RBAC_PUT)

        # Don't allow changes to the flavor_data or provider_name if it
        # is in use.
        if (not isinstance(flavorprofile.flavor_data, wtypes.UnsetType) or
                not isinstance(flavorprofile.provider_name, wtypes.UnsetType)):
            if self.repositories.flavor.count(context.session,
                                              flavor_profile_id=id) > 0:
                raise exceptions.ObjectInUse(object='Flavor profile', id=id)

        if not isinstance(flavorprofile.flavor_data, wtypes.UnsetType):
            # Do a basic JSON validation on the metadata
            try:
                flavor_data_dict = jsonutils.loads(flavorprofile.flavor_data)
            except Exception:
                raise exceptions.InvalidOption(value=flavorprofile.flavor_data,
                                               option=constants.FLAVOR_DATA)

            if isinstance(flavorprofile.provider_name, wtypes.UnsetType):
                db_flavor_profile = self._get_db_flavor_profile(
                    context.session, id)
                provider_driver = db_flavor_profile.provider_name
            else:
                provider_driver = flavorprofile.provider_name

            # Validate that the provider driver supports the metadata
            driver = driver_factory.get_driver(provider_driver)
            driver_utils.call_provider(driver.name, driver.validate_flavor,
                                       flavor_data_dict)

        lock_session = db_api.get_session(autocommit=False)
        try:
            flavorprofile_dict = flavorprofile.to_dict(render_unsets=False)
            if flavorprofile_dict:
                self.repositories.flavor_profile.update(
                    lock_session, id, **flavorprofile_dict)
            lock_session.commit()
        except Exception:
            with excutils.save_and_reraise_exception():
                lock_session.rollback()

        # Force SQL alchemy to query the DB, otherwise we get inconsistent
        # results
        context.session.expire_all()
        db_flavor_profile = self._get_db_flavor_profile(context.session, id)
        result = self._convert_db_to_type(db_flavor_profile,
                                          profile_types.FlavorProfileResponse)
        return profile_types.FlavorProfileRootResponse(flavorprofile=result)
Пример #3
0
    def delete(self, flavor_id):
        """Deletes a Flavor"""
        context = pecan.request.context.get('octavia_context')

        self._auth_validate_action(context, context.project_id,
                                   constants.RBAC_DELETE)
        try:
            self.repositories.flavor.delete(context.session, id=flavor_id)
        # Handle when load balancers still reference this flavor
        except odb_exceptions.DBReferenceError:
            raise exceptions.ObjectInUse(object='Flavor', id=flavor_id)
        except sa_exception.NoResultFound:
            raise exceptions.NotFound(resource='Flavor', id=flavor_id)
Пример #4
0
    def _validate_update_fp(self, context, id, flavorprofile):
        if flavorprofile.name is None:
            raise exceptions.InvalidOption(value=None, option=constants.NAME)
        if flavorprofile.provider_name is None:
            raise exceptions.InvalidOption(value=None,
                                           option=constants.PROVIDER_NAME)
        if flavorprofile.flavor_data is None:
            raise exceptions.InvalidOption(value=None,
                                           option=constants.FLAVOR_DATA)

        # Don't allow changes to the flavor_data or provider_name if it
        # is in use.
        if (not isinstance(flavorprofile.flavor_data, wtypes.UnsetType) or
                not isinstance(flavorprofile.provider_name, wtypes.UnsetType)):
            if self.repositories.flavor.count(context.session,
                                              flavor_profile_id=id) > 0:
                raise exceptions.ObjectInUse(object='Flavor profile', id=id)
Пример #5
0
    def delete(self, flavor_profile_id):
        """Deletes a Flavor Profile"""
        context = pecan.request.context.get('octavia_context')

        self._auth_validate_action(context, context.project_id,
                                   constants.RBAC_DELETE)

        # Don't allow it to be deleted if it is in use by a flavor
        if self.repositories.flavor.count(
                context.session, flavor_profile_id=flavor_profile_id) > 0:
            raise exceptions.ObjectInUse(object='Flavor profile',
                                         id=flavor_profile_id)

        try:
            self.repositories.flavor_profile.delete(context.session,
                                                    id=flavor_profile_id)
        except sa_exception.NoResultFound:
            raise exceptions.NotFound(resource='Flavor profile',
                                      id=flavor_profile_id)
Пример #6
0
    def _validate_update_azp(self, context, id, availability_zone_profile):
        if availability_zone_profile.name is None:
            raise exceptions.InvalidOption(value=None, option=constants.NAME)
        if availability_zone_profile.provider_name is None:
            raise exceptions.InvalidOption(
                value=None, option=constants.PROVIDER_NAME)
        if availability_zone_profile.availability_zone_data is None:
            raise exceptions.InvalidOption(
                value=None, option=constants.AVAILABILITY_ZONE_DATA)

        # Don't allow changes to the availability_zone_data or provider_name if
        # it is in use.
        if (not isinstance(availability_zone_profile.availability_zone_data,
                           wtypes.UnsetType) or
                not isinstance(availability_zone_profile.provider_name,
                               wtypes.UnsetType)):
            if self.repositories.availability_zone.count(
                    context.session, availability_zone_profile_id=id) > 0:
                raise exceptions.ObjectInUse(
                    object='Availability Zone Profile', id=id)
Пример #7
0
    def delete(self, availability_zone_profile_id):
        """Deletes an Availability Zone Profile"""
        context = pecan_request.context.get('octavia_context')

        self._auth_validate_action(context, context.project_id,
                                   constants.RBAC_DELETE)
        if availability_zone_profile_id == constants.NIL_UUID:
            raise exceptions.NotFound(resource='Availability Zone Profile',
                                      id=constants.NIL_UUID)
        # Don't allow it to be deleted if it is in use by an availability zone
        if self.repositories.availability_zone.count(
                context.session,
                availability_zone_profile_id=availability_zone_profile_id) > 0:
            raise exceptions.ObjectInUse(object='Availability Zone Profile',
                                         id=availability_zone_profile_id)
        try:
            self.repositories.availability_zone_profile.delete(
                context.session, id=availability_zone_profile_id)
        except sa_exception.NoResultFound:
            raise exceptions.NotFound(resource='Availability Zone Profile',
                                      id=availability_zone_profile_id)