Example #1
0
    def post(self, availability_zone_):
        """Creates an Availability Zone."""
        availability_zone = availability_zone_.availability_zone
        context = pecan.request.context.get('octavia_context')
        self._auth_validate_action(context, context.project_id,
                                   constants.RBAC_POST)

        lock_session = db_api.get_session(autocommit=False)
        try:
            availability_zone_dict = availability_zone.to_dict(
                render_unsets=True)
            db_availability_zone = self.repositories.availability_zone.create(
                lock_session, **availability_zone_dict)
            lock_session.commit()
        except odb_exceptions.DBDuplicateEntry:
            lock_session.rollback()
            raise exceptions.RecordAlreadyExists(field='availability zone',
                                                 name=availability_zone.name)
        except Exception:
            with excutils.save_and_reraise_exception():
                lock_session.rollback()
        result = self._convert_db_to_type(
            db_availability_zone,
            availability_zone_types.AvailabilityZoneResponse)
        return availability_zone_types.AvailabilityZoneRootResponse(
            availability_zone=result)
Example #2
0
    def put(self, name, availability_zone_):
        availability_zone = availability_zone_.availability_zone
        context = pecan.request.context.get('octavia_context')
        self._auth_validate_action(context, context.project_id,
                                   constants.RBAC_PUT)
        if name == constants.NIL_UUID:
            raise exceptions.NotFound(resource='Availability Zone',
                                      id=constants.NIL_UUID)
        lock_session = db_api.get_session(autocommit=False)
        try:
            availability_zone_dict = availability_zone.to_dict(
                render_unsets=False)
            if availability_zone_dict:
                self.repositories.availability_zone.update(
                    lock_session, name, **availability_zone_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_availability_zone = self._get_db_availability_zone(
            context.session, name)
        result = self._convert_db_to_type(
            db_availability_zone,
            availability_zone_types.AvailabilityZoneResponse)
        return availability_zone_types.AvailabilityZoneRootResponse(
            availability_zone=result)
Example #3
0
 def get_one(self, name, fields=None):
     """Gets an Availability Zone's detail."""
     context = pecan.request.context.get('octavia_context')
     self._auth_validate_action(context, context.project_id,
                                constants.RBAC_GET_ONE)
     if name == constants.NIL_UUID:
         raise exceptions.NotFound(resource='Availability Zone',
                                   id=constants.NIL_UUID)
     db_availability_zone = self._get_db_availability_zone(
         context.session, name)
     result = self._convert_db_to_type(
         db_availability_zone,
         availability_zone_types.AvailabilityZoneResponse)
     if fields is not None:
         result = self._filter_fields([result], fields)[0]
     return availability_zone_types.AvailabilityZoneRootResponse(
         availability_zone=result)