def _allocate_local_vlan_mapping(self, context, network_id, host, segment, nw_name): local_vlan_id = self.vlan_pool.allocate_local_vlan(host, network_id) if local_vlan_id is None: return None local_seg = self._create_segment(context._plugin_context, segment.get('network_id'), segment.get('physical_network'), 'vlan', local_vlan_id, 1, context.host, False) try: kaloom_db.create_network_host_vlan_mapping(network_id, host, local_seg.get('id'), local_vlan_id, nw_name) except Exception as e: LOG.error( "Error create_network_host_vlan_mapping VLAN=%d for host=%s, network=%s, err_msg: %s", local_vlan_id, host, network_id, e) #clear record on vlan reservation kaloom_db.delete_vlan_reservation(host=host, vlan_id=local_vlan_id) return None LOG.info( "LOCAL VLAN NOT FOUND: ALLOCATING VLAN %d host, network (%s,%s)" % (local_vlan_id, host, network_id)) local_vlan_mapping = type('local_vlan_mapping', (object, ), { 'vlan_id': local_vlan_id, 'segment_id': local_seg.get('id') }) return local_vlan_mapping
def remove_local_vlan_mapping(local_vlan_mapping): if local_vlan_mapping: kaloom_db.delete_host_vlan_mapping( network_id=local_vlan_mapping.network_id, host=local_vlan_mapping.host) #clear record on vlan reservation kaloom_db.delete_vlan_reservation(host=local_vlan_mapping.host, vlan_id=local_vlan_mapping.vlan_id)
def _clean_local_vlan_mappings(self, network_id): """ When a network is deleted, remove all residual mappings for Local VLAN """ mappings = kaloom_db.get_all_vlan_mappings_for_network(network_id) for m in mappings: kaloom_db.delete_host_vlan_mapping(network_id=m.network_id, host=m.host) #clear record on vlan reservation mappings = kaloom_db.get_all_vlan_reservations_for_network(network_id) for m in mappings: kaloom_db.delete_vlan_reservation(host=m.host, vlan_id=m.vlan_id)