def fix_connections_with_removed_networks(self, server_profile): sp_cons = [] server_hardware = self.oneview_client.server_hardware.get( server_profile.get('serverHardwareUri') ) for connection in server_profile.get('connections'): conn_network_id = common.id_from_uri( connection.get('networkUri') ) if self.get_oneview_network(conn_network_id): sp_cons.append(connection) server_profile['connections'] = sp_cons self.neutron_client.port.check_server_hardware_availability( server_hardware ) previous_power_state = ( self.neutron_client.port.get_server_hardware_power_state( server_hardware ) ) self.neutron_client.port.update_server_hardware_power_state( server_hardware, "Off" ) self.oneview_client.server_profiles.update( resource=server_profile, id_or_uri=server_profile.get('uri') ) self.neutron_client.port.update_server_hardware_power_state( self.oneview_client.server_hardware.get( server_profile.get('serverHardwareUri')), previous_power_state )
def delete_unmapped_oneview_networks(self): session = self.get_session() for network in self.oneview_client.ethernet_networks.get_all(): m = re.search('Neutron \[(.*)\]', network.get('name')) if m: oneview_network_id = common.id_from_uri(network.get('uri')) neutron_network_id = m.group(1) neutron_network = db_manager.get_neutron_network( session, neutron_network_id ) network_segment = db_manager.get_network_segment( session, neutron_network_id ) if neutron_network is None: self.oneview_client.ethernet_networks.delete( oneview_network_id ) self._remove_inconsistence_from_db( session, neutron_network_id, oneview_network_id ) else: physnet = network_segment.get('physical_network') network_type = network_segment.get('network_type') if not self.neutron_client.network.is_uplinkset_mapping( physnet, network_type ): self._delete_connections(neutron_network_id) self.neutron_client.network.delete( session, {'id': neutron_network_id} )
def delete_unmapped_oneview_networks(self): LOG.info("Synchronizing outdated networks in OneView.") session = common.get_database_session() for network in self.oneview_client.ethernet_networks.get_all(): mmanaged_network = re.search(r'Neutron \[(.*)\]', network.get( 'name')) if mmanaged_network: oneview_network_id = common.id_from_uri(network.get('uri')) neutron_network_id = mmanaged_network.group(1) neutron_network = database_manager.get_neutron_network( session, neutron_network_id ) network_segment = database_manager.get_network_segment( session, neutron_network_id ) if not neutron_network: self.oneview_client.ethernet_networks.delete( oneview_network_id ) common.remove_inconsistence_from_db( session, neutron_network_id, oneview_network_id ) # NOTE(nicodemos) network_segment will always exists? # NOTE(mrtenio) network_segments are created by Neutron when # a Network is created. I think we can assume they always # exist else: physnet = network_segment.get('physical_network') network_type = network_segment.get('network_type') if not self.neutron_client.network.is_uplinkset_mapping( physnet, network_type): self._delete_connections(neutron_network_id) self.neutron_client.network.delete( session, {'id': neutron_network_id} )
def create(self, session, network_dict): network_id = network_dict.get('id') network_seg_id = network_dict.get('provider:segmentation_id') physical_network = network_dict.get('provider:physical_network') network_type = network_dict.get('provider:network_type') mapping_type = self._get_network_mapping_type(physical_network, network_type) if not self.is_uplinkset_mapping(physical_network, network_type): LOG.warning( "The network %s is not mapped in OneView " "configuration file.", network_id) return if database_manager.get_neutron_oneview_network(session, network_id): LOG.warning("The network %s is already created.", network_id) return if not mapping_type: LOG.warning("The network: %s type is not supported.", network_id) return mappings = [] oneview_network_id = None if mapping_type == common.UPLINKSET_MAPPINGS_TYPE: network_type = 'tagged' if network_seg_id else 'untagged' oneview_network = self._create_network_on_oneview( name="Neutron [" + network_id + "]", network_type=network_type.capitalize(), seg_id=network_seg_id) oneview_network_id = common.id_from_uri(oneview_network.get('uri')) try: mappings = self._add_to_ligs(network_type, physical_network, oneview_network.get('uri')) except Exception: LOG.warning("Network Creation failed, deleting OneView " "Network: %s" % oneview_network_id) self.oneview_client.ethernet_networks.delete(oneview_network) raise exceptions.NetworkCreationException() else: oneview_network_id = self.flat_net_mappings.get(physical_network) database_manager.map_neutron_network_to_oneview( session, network_id, oneview_network_id, mapping_type == common.UPLINKSET_MAPPINGS_TYPE, mappings) LOG.info("Network %s created.", network_id)
def _get_uplinksets_from_lig(self, network_type, lig_list): lig_ids = lig_list[0::2] uplinksets = [] for uplink_name in lig_list[1::2]: uplinks = self.oneview_client.uplink_sets.get_by( 'name', uplink_name) for uplink in uplinks: logical_interconnect = ( self.oneview_client.logical_interconnects.get( uplink.get('logicalInterconnectUri'))) logical_interconnect_group_id = common.id_from_uri( logical_interconnect.get('logicalInterconnectGroupUri')) if logical_interconnect_group_id in lig_ids and uplink.get( 'ethernetNetworkType').lower() == network_type: uplinksets.append(uplink) return uplinksets
def create(self, session, network_dict): network_id = network_dict.get('id') network_seg_id = network_dict.get('provider:segmentation_id') physical_network = network_dict.get('provider:physical_network') network_type = network_dict.get('provider:network_type') mapping_type = self._get_network_mapping_type(physical_network, network_type) if not self.is_uplinkset_mapping(physical_network, network_type): return if db_manager.get_neutron_oneview_network(session, network_id): return if mapping_type == common.MAPPING_TYPE_NONE: return mappings = [] oneview_network_id = None if mapping_type == common.UPLINKSET_MAPPINGS_TYPE: network_type = 'tagged' if network_seg_id else 'untagged' oneview_network = self._create_network_on_oneview( name="Neutron [" + network_id + "]", network_type=network_type.capitalize(), seg_id=network_seg_id) oneview_network_id = common.id_from_uri(oneview_network.get('uri')) mappings = self._add_to_ligs(network_type, physical_network, oneview_network) elif mapping_type == common.FLAT_NET_MAPPINGS_TYPE: oneview_network_id = self.flat_net_mappings.get(physical_network) else: LOG.warning("Network Type unsupported") db_manager.map_neutron_network_to_oneview( session, network_id, oneview_network_id, mapping_type == common.UPLINKSET_MAPPINGS_TYPE, mappings) LOG.info("Network %s created.", network_id)