def _validate_segment(self, context, network_id, segment_id, action=None):
        query = context.session.query(models_v2.Subnet.segment_id)
        query = query.filter(models_v2.Subnet.network_id == network_id)
        associated_segments = set(row.segment_id for row in query)
        if None in associated_segments and len(associated_segments) > 1:
            raise segment_exc.SubnetsNotAllAssociatedWithSegments(
                network_id=network_id)

        if action == 'update':
            # Check the current state of segments and subnets on the network
            # before allowing migration from non-routed to routed network.
            if query.count() > 1:
                raise segment_exc.SubnetsNotAllAssociatedWithSegments(
                    network_id=network_id)
            if (None not in associated_segments and
                    segment_id not in associated_segments):
                raise segment_exc.SubnetSegmentAssociationChangeNotAllowed()

            query = context.session.query(segment_model.NetworkSegment.id)
            query = query.filter(
                segment_model.NetworkSegment.network_id == network_id)
            if query.count() > 1:
                raise segment_exc.NoUpdateSubnetWhenMultipleSegmentsOnNetwork(
                    network_id=network_id)

        if segment_id:
            segment = network_obj.NetworkSegment.get_object(context,
                                                            id=segment_id)
            if segment.network_id != network_id:
                raise segment_exc.NetworkIdsDontMatch(
                    subnet_network=network_id,
                    segment_id=segment_id)
            if segment.is_dynamic:
                raise segment_exc.SubnetCantAssociateToDynamicSegment()
Esempio n. 2
0
    def _validate_segment(self, context, network_id, segment_id, action=None,
                          old_segment_id=None):
        segments = subnet_obj.Subnet.get_values(
            context, 'segment_id', network_id=network_id)
        associated_segments = set(segments)
        if None in associated_segments and len(associated_segments) > 1:
            raise segment_exc.SubnetsNotAllAssociatedWithSegments(
                network_id=network_id)

        if action == 'update' and old_segment_id != segment_id:
            # Check the current state of segments and subnets on the network
            # before allowing migration from non-routed to routed network.
            if len(segments) > 1:
                raise segment_exc.SubnetsNotAllAssociatedWithSegments(
                    network_id=network_id)
            if (None not in associated_segments and
                    segment_id not in associated_segments):
                raise segment_exc.SubnetSegmentAssociationChangeNotAllowed()

            if network_obj.NetworkSegment.count(
                    context, network_id=network_id) > 1:
                raise segment_exc.NoUpdateSubnetWhenMultipleSegmentsOnNetwork(
                    network_id=network_id)

        if segment_id:
            segment = network_obj.NetworkSegment.get_object(context,
                                                            id=segment_id)
            if segment.network_id != network_id:
                raise segment_exc.NetworkIdsDontMatch(
                    subnet_network=network_id,
                    segment_id=segment_id)
            if segment.is_dynamic:
                raise segment_exc.SubnetCantAssociateToDynamicSegment()
Esempio n. 3
0
    def _validate_segment(self,
                          context,
                          network_id,
                          segment_id,
                          action=None,
                          old_segment_id=None,
                          requested_service_types=None,
                          subnet_id=None):
        # NOTE(zigo): If we're creating a network:routed subnet (here written
        # as: const.DEVICE_OWNER_ROUTED), then the created subnet must be
        # removed from the segment list, otherwise its segment ID will be
        # returned as None, and SubnetsNotAllAssociatedWithSegments will be
        # raised.
        if (action == 'create' and requested_service_types
                and const.DEVICE_OWNER_ROUTED in requested_service_types):
            to_create_subnet_id = subnet_id
        else:
            to_create_subnet_id = None

        segments = subnet_obj.Subnet.get_subnet_segment_ids(
            context,
            network_id,
            ignored_service_type=const.DEVICE_OWNER_ROUTED,
            subnet_id=to_create_subnet_id)

        associated_segments = set(segments)
        if None in associated_segments and len(associated_segments) > 1:
            raise segment_exc.SubnetsNotAllAssociatedWithSegments(
                network_id=network_id)

        if action == 'update' and old_segment_id != segment_id:
            # Check the current state of segments and subnets on the network
            # before allowing migration from non-routed to routed network.
            if len(segments) > 1:
                raise segment_exc.SubnetsNotAllAssociatedWithSegments(
                    network_id=network_id)
            if (None not in associated_segments
                    and segment_id not in associated_segments):
                raise segment_exc.SubnetSegmentAssociationChangeNotAllowed()

            if network_obj.NetworkSegment.count(context,
                                                network_id=network_id) > 1:
                raise segment_exc.NoUpdateSubnetWhenMultipleSegmentsOnNetwork(
                    network_id=network_id)

        if segment_id:
            segment = network_obj.NetworkSegment.get_object(context,
                                                            id=segment_id)
            if segment.network_id != network_id:
                raise segment_exc.NetworkIdsDontMatch(
                    subnet_network=network_id, segment_id=segment_id)
            if segment.is_dynamic:
                raise segment_exc.SubnetCantAssociateToDynamicSegment()
Esempio n. 4
0
    def _validate_segment(self, context, network_id, segment_id):
        query = context.session.query(models_v2.Subnet.segment_id)
        query = query.filter(models_v2.Subnet.network_id == network_id)
        associated_segments = set(row.segment_id for row in query)
        if None in associated_segments and len(associated_segments) > 1:
            raise segment_exc.SubnetsNotAllAssociatedWithSegments(
                network_id=network_id)

        if segment_id:
            segment = network_obj.NetworkSegment.get_object(context,
                                                            id=segment_id)
            if segment.network_id != network_id:
                raise segment_exc.NetworkIdsDontMatch(
                    subnet_network=network_id, segment_id=segment_id)
            if segment.is_dynamic:
                raise segment_exc.SubnetCantAssociateToDynamicSegment()