예제 #1
0
def _add_segment_host_mapping_for_segment(resource, event, trigger,
                                          context, segment):
    if not segment.physical_network:
        return
    cp = manager.NeutronManager.get_plugin()
    check_segment_for_agent = getattr(cp, 'check_segment_for_agent', None)
    if not hasattr(cp, 'get_agents') or not check_segment_for_agent:
        # not an agent-supporting plugin
        registry.unsubscribe(_add_segment_host_mapping_for_segment,
                             resources.SEGMENT, events.PRECOMMIT_CREATE)
        return
    hosts = {agent['host'] for agent in cp.get_agents(context)
             if check_segment_for_agent(segment, agent)}
    map_segment_to_hosts(context, segment.id, hosts)
예제 #2
0
def _add_segment_host_mapping_for_segment(resource, event, trigger,
                                          context, segment):
    if not segment.physical_network:
        return
    cp = manager.NeutronManager.get_plugin()
    check_segment_for_agent = getattr(cp, 'check_segment_for_agent', None)
    if not hasattr(cp, 'get_agents') or not check_segment_for_agent:
        # not an agent-supporting plugin
        registry.unsubscribe(_add_segment_host_mapping_for_segment,
                             resources.SEGMENT, events.PRECOMMIT_CREATE)
        return
    hosts = {agent['host'] for agent in cp.get_agents(context)
             if check_segment_for_agent(segment, agent)}
    map_segment_to_hosts(context, segment.id, hosts)
예제 #3
0
    def _test_segment_host_mapping(self):
        # Disable the callback to update SegmentHostMapping by default, so
        # that update_segment_host_mapping is the only path to add the mapping
        registry.unsubscribe(
            self.mech_driver._add_segment_host_mapping_for_segment, resources.SEGMENT, events.PRECOMMIT_CREATE
        )
        host = "hostname"
        with self.network() as network:
            network = network["network"]
        segment1 = self._test_create_segment(
            network_id=network["id"], physical_network="phys_net1", segmentation_id=200, network_type="vlan"
        )["segment"]

        self._test_create_segment(network_id=network["id"], segmentation_id=200, network_type="geneve")["segment"]
        self.mech_driver.update_segment_host_mapping(host, ["phys_net1"])
        segments_host_db = self._get_segments_for_host(host)
        self.assertEqual({segment1["id"]}, set(segments_host_db))
        return network["id"], host
예제 #4
0
파일: db.py 프로젝트: fcxliang/lzf5-study
def _add_segment_host_mapping_for_segment(resource, event, trigger,
                                          context, segment):
    if not context.session.is_active:
        # The session might be in partial rollback state, due to errors in
        # peer callback. In that case, there is no need to add the mapping.
        # Just return here.
        return

    if not segment.physical_network:
        return
    cp = manager.NeutronManager.get_plugin()
    check_segment_for_agent = getattr(cp, 'check_segment_for_agent', None)
    if not hasattr(cp, 'get_agents') or not check_segment_for_agent:
        # not an agent-supporting plugin
        registry.unsubscribe(_add_segment_host_mapping_for_segment,
                             resources.SEGMENT, events.PRECOMMIT_CREATE)
        return
    hosts = {agent['host'] for agent in cp.get_agents(context)
             if check_segment_for_agent(segment, agent)}
    map_segment_to_hosts(context, segment.id, hosts)
예제 #5
0
파일: db.py 프로젝트: sebrandon1/neutron
def _add_segment_host_mapping_for_segment(resource, event, trigger,
                                          context, segment):
    if not context.session.is_active:
        # The session might be in partial rollback state, due to errors in
        # peer callback. In that case, there is no need to add the mapping.
        # Just return here.
        return

    if not segment.physical_network:
        return
    cp = manager.NeutronManager.get_plugin()
    check_segment_for_agent = getattr(cp, 'check_segment_for_agent', None)
    if not hasattr(cp, 'get_agents') or not check_segment_for_agent:
        # not an agent-supporting plugin
        registry.unsubscribe(_add_segment_host_mapping_for_segment,
                             resources.SEGMENT, events.PRECOMMIT_CREATE)
        return
    hosts = {agent['host'] for agent in cp.get_agents(context)
             if check_segment_for_agent(segment, agent)}
    map_segment_to_hosts(context, segment.id, hosts)
예제 #6
0
    def _test_segment_host_mapping(self):
        # Disable the callback to update SegmentHostMapping by default, so
        # that update_segment_host_mapping is the only path to add the mapping
        registry.unsubscribe(
            self.mech_driver._add_segment_host_mapping_for_segment,
            resources.SEGMENT, events.PRECOMMIT_CREATE)
        host = 'hostname'
        with self.network() as network:
            network = network['network']
        segment1 = self._test_create_segment(network_id=network['id'],
                                             physical_network='phys_net1',
                                             segmentation_id=200,
                                             network_type='vlan')['segment']

        self._test_create_segment(network_id=network['id'],
                                  segmentation_id=200,
                                  network_type='geneve')['segment']
        self.mech_driver.update_segment_host_mapping(host, ['phys_net1'])
        segments_host_db = self._get_segments_for_host(host)
        self.assertEqual({segment1['id']}, set(segments_host_db))
        return network['id'], host
    def _test_segment_host_mapping(self):
        # Disable the callback to update SegmentHostMapping by default, so
        # that update_segment_host_mapping is the only path to add the mapping
        registry.unsubscribe(
            self.mech_driver._add_segment_host_mapping_for_segment,
            resources.SEGMENT, events.PRECOMMIT_CREATE)
        host = 'hostname'
        with self.network() as network:
            network = network['network']
        segment1 = self._test_create_segment(
            network_id=network['id'], physical_network='phys_net1',
            segmentation_id=200, network_type='vlan')['segment']

        self._test_create_segment(
            network_id=network['id'],
            segmentation_id=200,
            network_type='geneve')['segment']
        self.mech_driver.update_segment_host_mapping(host, ['phys_net1'])
        segments_host_db = self._get_segments_for_host(host)
        self.assertEqual({segment1['id']}, set(segments_host_db))
        return network['id'], host