Example #1
0
    def update_segment_host_mapping(self, host, phy_nets):
        """Update SegmentHostMapping in DB"""
        if not host:
            return

        ctx = n_context.get_admin_context()
        segments = segment_service_db.get_segments_with_phys_nets(ctx, phy_nets)

        available_seg_ids = {segment["id"] for segment in segments if segment["network_type"] in ("flat", "vlan")}

        segment_service_db.update_segment_host_mapping(ctx, host, available_seg_ids)
Example #2
0
    def update_segment_host_mapping(self, host, phy_nets):
        """Update SegmentHostMapping in DB"""
        if not host:
            return

        ctx = n_context.get_admin_context()
        segments = segment_service_db.get_segments_with_phys_nets(
            ctx, phy_nets)

        available_seg_ids = {
            segment['id'] for segment in segments
            if segment['network_type'] in ('flat', 'vlan')}

        segment_service_db.update_segment_host_mapping(
            ctx, host, available_seg_ids)
Example #3
0
 def test_update_segment_host_mapping(self):
     ctx = context.get_admin_context()
     host = 'host1'
     physnets = ['phys_net1']
     with self.network() as network:
         network = network['network']
     segment = self._test_create_segment(
         network_id=network['id'], physical_network='phys_net1',
         segmentation_id=200, network_type=p_constants.TYPE_VLAN)['segment']
     self._test_create_segment(
         network_id=network['id'], physical_network='phys_net2',
         segmentation_id=201, network_type=p_constants.TYPE_VLAN)['segment']
     segments = db.get_segments_with_phys_nets(ctx, physnets)
     segment_ids = {segment['id'] for segment in segments}
     db.update_segment_host_mapping(ctx, host, segment_ids)
     segments_host_db = self._get_segments_for_host(host)
     self.assertEqual(1, len(segments_host_db))
     self.assertEqual(segment['id'],
                      segments_host_db[segment['id']]['segment_id'])
     self.assertEqual(host, segments_host_db[segment['id']]['host'])
Example #4
0
 def test_update_segment_host_mapping(self):
     ctx = context.get_admin_context()
     host = 'host1'
     physnets = ['phys_net1']
     with self.network() as network:
         network = network['network']
     segment = self._test_create_segment(
         network_id=network['id'],
         physical_network='phys_net1',
         segmentation_id=200,
         network_type=p_constants.TYPE_VLAN)['segment']
     self._test_create_segment(
         network_id=network['id'],
         physical_network='phys_net2',
         segmentation_id=201,
         network_type=p_constants.TYPE_VLAN)['segment']
     segments = db.get_segments_with_phys_nets(ctx, physnets)
     segment_ids = {segment['id'] for segment in segments}
     db.update_segment_host_mapping(ctx, host, segment_ids)
     segments_host_db = self._get_segments_for_host(host)
     self.assertEqual(1, len(segments_host_db))
     self.assertEqual(segment['id'],
                      segments_host_db[segment['id']]['segment_id'])
     self.assertEqual(host, segments_host_db[segment['id']]['host'])