Beispiel #1
0
    def create_region(self, region_ref, initiator=None):
        # Check duplicate ID
        try:
            self.get_region(region_ref['id'])
        except exception.RegionNotFound:  # nosec
            # A region with the same id doesn't exist already, good.
            pass
        else:
            msg = _('Duplicate ID, %s.') % region_ref['id']
            raise exception.Conflict(type='region', details=msg)

        # NOTE(lbragstad,dstanek): The description column of the region
        # database cannot be null. So if the user doesn't pass in a
        # description or passes in a null description then set it to an
        # empty string.
        if region_ref.get('description') is None:
            region_ref['description'] = ''
        try:
            ret = self.driver.create_region(region_ref)
        except exception.NotFound:
            parent_region_id = region_ref.get('parent_region_id')
            raise exception.RegionNotFound(region_id=parent_region_id)

        notifications.Audit.created(self._REGION, ret['id'], initiator)
        COMPUTED_CATALOG_REGION.invalidate()
        return ret
 def delete_region(self, region_id):
     try:
         ret = self.driver.delete_region(region_id)
         self.get_region.invalidate(self, region_id)
         return ret
     except exception.NotFound:
         raise exception.RegionNotFound(region_id=region_id)
Beispiel #3
0
 def delete_region(self, region_id, initiator=None):
     try:
         ret = self.driver.delete_region(region_id)
         notifications.Audit.deleted(self._REGION, region_id, initiator)
         self.get_region.invalidate(self, region_id)
         return ret
     except exception.NotFound:
         raise exception.RegionNotFound(region_id=region_id)
Beispiel #4
0
    def create_region(self, region_ref):
        # Check duplicate ID
        try:
            self.get_region(region_ref['id'])
        except exception.RegionNotFound:
            pass
        else:
            msg = _('Duplicate ID, %s.') % region_ref['id']
            raise exception.Conflict(type='region', details=msg)

        try:
            return self.driver.create_region(region_ref)
        except exception.NotFound:
            parent_region_id = region_ref.get('parent_region_id')
            raise exception.RegionNotFound(region_id=parent_region_id)
    def create_region(self, region_ref):
        # Check duplicate ID
        try:
            self.get_region(region_ref['id'])
        except exception.RegionNotFound:
            pass
        else:
            msg = _('Duplicate ID, %s.') % region_ref['id']
            raise exception.Conflict(type='region', details=msg)

        # NOTE(lbragstad): The description column of the region database
        # can not be null. So if the user doesn't pass in a description then
        # set it to an empty string.
        region_ref.setdefault('description', '')
        try:
            return self.driver.create_region(region_ref)
        except exception.NotFound:
            parent_region_id = region_ref.get('parent_region_id')
            raise exception.RegionNotFound(region_id=parent_region_id)
Beispiel #6
0
 def get_region(self, region_id):
     try:
         return self.driver.get_region(region_id)
     except exception.NotFound:
         raise exception.RegionNotFound(region_id=region_id)
Beispiel #7
0
 def _get_region(self, session, region_id):
     ref = session.query(Region).get(region_id)
     if not ref:
         raise exception.RegionNotFound(region_id=region_id)
     return ref
Beispiel #8
0
 def get_region(self, region_id):
     if region_id in self.templates:
         return {'id': region_id, 'description': '', 'parent_region_id': ''}
     raise exception.RegionNotFound(region_id=region_id)
Beispiel #9
0
 def create_region(self, region_id, region_ref):
     try:
         return self.driver.create_region(region_id, region_ref)
     except exception.NotFound:
         parent_region_id = region_ref.get('parent_region_id')
         raise exception.RegionNotFound(region_id=parent_region_id)