Example #1
0
    def delete_network_segment_range(self, context, id):
        """Check segment reference on network segment range deletion."""
        with db_api.CONTEXT_WRITER.using(context):
            network_segment_range = self._get_network_segment_range(
                context, id)
            range_data = network_segment_range.to_dict()

            if range_data['default']:
                # TODO(kailun): To use
                #  range_exc.NetworkSegmentRangeDefaultReadOnly when the
                #  neutron-lib patch https://review.openstack.org/640777 is
                #  merged and released.
                message = _("Network Segment Range %s is a "
                            "default segment range which could not be "
                            "updated or deleted.") % id
                raise lib_exc.BadRequest(resource=range_def.RESOURCE_NAME,
                                         msg=message)

            if self._is_network_segment_range_referenced(context, range_data):
                # TODO(kailun): To use
                #  range_exc.NetworkSegmentRangeReferencedByProject when the
                #  neutron-lib patch https://review.openstack.org/640777 is
                #  merged and released.
                message = _("Network Segment Range %s is referenced by "
                            "one or more tenant networks.") % id
                raise lib_exc.InUse(resource=range_def.RESOURCE_NAME,
                                    msg=message)
            network_segment_range.delete()

        self.type_manager.update_network_segment_range_allocations(
            network_segment_range['network_type'])
Example #2
0
    def update_network_segment_range(self, context, id, network_segment_range):
        """Check existing network segment range impact on range updates."""
        updated_range_data = network_segment_range['network_segment_range']
        with db_api.CONTEXT_WRITER.using(context):
            network_segment_range = self._get_network_segment_range(
                context, id)
            existing_range_data = network_segment_range.to_dict()

            if existing_range_data['default']:
                # TODO(kailun): To use
                #  range_exc.NetworkSegmentRangeDefaultReadOnly when the
                #  neutron-lib patch https://review.openstack.org/640777 is
                #  merged and released.
                message = _("Network Segment Range %s is a "
                            "default segment range which could not be "
                            "updated or deleted.") % id
                raise lib_exc.BadRequest(resource=range_def.RESOURCE_NAME,
                                         msg=message)

            if self._are_allocated_segments_in_range_impacted(
                    context,
                    existing_range=existing_range_data,
                    updated_range=updated_range_data):
                # TODO(kailun): To use
                #  range_exc.NetworkSegmentRangeReferencedByProject when the
                #  neutron-lib patch https://review.openstack.org/640777 is
                #  merged and released.
                message = _("Network Segment Range %s is referenced by "
                            "one or more tenant networks.") % id
                raise lib_exc.InUse(resource=range_def.RESOURCE_NAME,
                                    msg=message)

            new_range_data = self._add_unchanged_range_attributes(
                updated_range_data, existing_range_data)
            self._validate_network_segment_range_eligible(new_range_data)
            network_segment_range.update_fields(new_range_data)
            network_segment_range.update()

        self.type_manager.update_network_segment_range_allocations(
            network_segment_range['network_type'])
        return network_segment_range.to_dict()