def create_oneview_networks_from_neutron(self): LOG.info("Synchronizing Neutron networks not in OneView.") session = common.get_database_session() for network, network_segment in ( database_manager.list_networks_and_segments_with_physnet( session)): net_id = network.get('id') neutron_oneview_network = ( database_manager.get_neutron_oneview_network( session, net_id)) if neutron_oneview_network: oneview_network = self.get_oneview_network( neutron_oneview_network.oneview_network_id ) if not oneview_network: common.remove_inconsistence_from_db( session, neutron_oneview_network.neutron_network_id, neutron_oneview_network.oneview_network_id ) else: continue physical_network = network_segment.get('physical_network') network_type = network_segment.get('network_type') segmentation_id = network_segment.get('segmentation_id') network_dict = common.network_dict_for_network_creation( physical_network, network_type, net_id, segmentation_id ) self.neutron_client.network.create(session, network_dict)
def create_oneview_networks_from_neutron(self): session = self.get_session() for network, network_segment in ( db_manager.list_networks_and_segments_with_physnet(session) ): net_id = network.get('id') neutron_oneview_network = db_manager.get_neutron_oneview_network( session, net_id ) if neutron_oneview_network: oneview_network = self.get_oneview_network( neutron_oneview_network.oneview_network_id ) if not oneview_network: self._remove_inconsistence_from_db( session, neutron_oneview_network.neutron_network_id, neutron_oneview_network.oneview_network_id ) physical_network = network_segment.get('physical_network') network_type = network_segment.get('network_type') segmentation_id = network_segment.get('segmentation_id') network_dict = common.network_dict_for_network_creation( physical_network, network_type, net_id, segmentation_id ) self.neutron_client.network.create(session, network_dict)
def _is_port_valid_to_reflect_on_oneview(self, session, port_dict, local_link_information_list): def is_local_link_information_valid(local_link_information_list): if not local_link_information_list: return False if len(local_link_information_list) > 1: LOG.warning( "'local_link_information' must have only one value") return False switch_info = common.switch_info_from_local_link_information_list( local_link_information_list) if not switch_info: LOG.warning( "'local_link_information' must contain 'switch_info'.") return False server_hardware = ( common.server_hardware_from_local_link_information_list( self.oneview_client, local_link_information_list)) server_hardware_id = server_hardware.get('uuid') if strutils.is_valid_boolstr(switch_info.get('bootable')): bootable = strutils.bool_from_string( switch_info.get('bootable')) else: bootable = switch_info.get('bootable') if not (server_hardware_id or bootable): LOG.warning("'local_link_information' must contain " "'server_hardware_id' and 'bootable'.") return False if not isinstance(bootable, bool): LOG.warning("'bootable' must be a boolean.") return False return True vnic_type = port_dict.get('binding:vnic_type') network_id = port_dict.get('network_id') neutron_oneview_network = db_manager.get_neutron_oneview_network( session, network_id) if vnic_type != 'baremetal': return False if not neutron_oneview_network: return False return is_local_link_information_valid(local_link_information_list)
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 delete(self, session, network_dict): network_id = network_dict.get('id') neutron_oneview_network = database_manager.get_neutron_oneview_network( session, network_id) if neutron_oneview_network is None: return oneview_network_id = neutron_oneview_network.oneview_network_id if neutron_oneview_network.manageable: self.oneview_client.ethernet_networks.delete(oneview_network_id) database_manager.delete_neutron_oneview_network( session, neutron_network_id=network_id) database_manager.delete_oneview_network_lig( session, oneview_network_id=oneview_network_id) LOG.info("Network %s deleted", oneview_network_id)
def is_port_valid_to_reflect_on_oneview(session, port_dict, local_link_information): vnic_type = port_dict.get('binding:vnic_type') port_id = port_dict.get("id") if vnic_type != 'baremetal': LOG.warning("'vnic_type' of the port %s must be baremetal" % port_id) return False network_id = port_dict.get('network_id') neutron_oneview_network = database_manager.get_neutron_oneview_network( session, network_id) if not neutron_oneview_network: LOG.warning("There is no network created for the port %s" % port_id) return False return _is_local_link_information_valid(port_id, local_link_information)
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)
def create(self, session, port_dict): network_id = port_dict.get('network_id') neutron_port_id = port_dict.get('id') network_segment = database_manager.get_network_segment( session, network_id) physical_network = network_segment.get('physical_network') network_type = network_segment.get('network_type') if not self.is_uplinkset_mapping(physical_network, network_type): LOG.warning( "The port's network %s is not mapping in OneView " "configuration file", network_id) return local_link_information_list = common.local_link_information_from_port( port_dict) if not common.is_port_valid_to_reflect_on_oneview( session, port_dict, local_link_information_list): LOG.warning("Port %s is not valid to reflect on OneView.", neutron_port_id) return neutron_oneview_network = database_manager.get_neutron_oneview_network( session, network_id) network_uri = common.network_uri_from_id( neutron_oneview_network.oneview_network_id) server_hardware = ( common.server_hardware_from_local_link_information_list( self.oneview_client, local_link_information_list)) server_profile = common.server_profile_from_server_hardware( self.oneview_client, server_hardware) if server_profile: LOG.info("There is Server Profile %s available.", server_profile) mac_address = port_dict.get('mac_address') if common.is_rack_server(server_hardware): LOG.warning("The server hardware %s is a rack server.", server_hardware.get('uuid')) return port_id = common.port_id_from_mac(server_hardware, mac_address) connections = server_profile.get('connections') existing_connections = [ connection for connection in connections if connection.get('portId') == port_id ] switch_info = common.switch_info_from_local_link_information_list( local_link_information_list) bootable = switch_info.get('bootable') boot_priority = common.get_boot_priority(server_profile, bootable) if not boot_priority: LOG.warning("The server profile: %s already has PXE primary " "and secondary bootable connections." % server_profile.get('uuid')) return create_new_connection = True for connection in existing_connections: if connection.get('mac').upper() == mac_address.upper(): connection['networkUri'] = network_uri create_new_connection = False if create_new_connection: server_profile['connections'].append({ 'name': "NeutronPort[%s]" % mac_address, 'portId': port_id, 'networkUri': network_uri, 'boot': { 'priority': boot_priority }, 'functionType': 'Ethernet' }) common.check_oneview_entities_availability(self.oneview_client, server_hardware) self._update_oneview_entities(server_hardware, server_profile) LOG.info("The requested connection %s was updated/created.", port_id)
def create(self, session, port_dict): network_id = port_dict.get('network_id') neutron_port_id = port_dict.get('id') network_segment = db_manager.get_network_segment(session, network_id) physical_network = network_segment.get('physical_network') network_type = network_segment.get('network_type') if not self.is_uplinkset_mapping(physical_network, network_type): LOG.warning("Port %s is not mapping in OneView conf", network_id) return local_link_information_list = common.local_link_information_from_port( port_dict) if not self._is_port_valid_to_reflect_on_oneview( session, port_dict, local_link_information_list): LOG.warning("Port %s is not valid to reflect on OneView.", neutron_port_id) return neutron_oneview_network = db_manager.get_neutron_oneview_network( session, network_id) network_uri = common.network_uri_from_id( neutron_oneview_network.oneview_network_id) switch_info = common.switch_info_from_local_link_information_list( local_link_information_list) server_hardware = ( common.server_hardware_from_local_link_information_list( self.oneview_client, local_link_information_list)) server_profile = self.server_profile_from_server_hardware( server_hardware) if server_profile: LOG.info("There is Server Profile %s available.", server_profile) bootable = switch_info.get('bootable') mac_address = port_dict.get('mac_address') if common.is_rack_server(server_hardware): LOG.info("The server %s is a rack server.", server_hardware) return port_id = self._port_id_from_mac(server_hardware, mac_address) connections = server_profile.get('connections') existing_connections = [ connection for connection in connections if connection.get('portId') == port_id ] for connection in existing_connections: if connection.get('mac').upper() == mac_address.upper(): server_profile['connections'].remove(connection) boot_priority = self._get_boot_priority(server_profile, bootable) server_profile['connections'].append({ 'name': "NeutronPort[" + mac_address + "]", 'portId': port_id, 'networkUri': network_uri, 'boot': { 'priority': boot_priority }, 'functionType': 'Ethernet' }) self._check_oneview_entities_availability(server_hardware) self._update_oneview_entities(server_hardware, server_profile) LOG.info("The requested connection %s was created.", port_id)