Example #1
0
    def delete(self, session, port_dict):
        local_link_information_list = common.local_link_information_from_port(
            port_dict)
        neutron_port_id = port_dict.get('id')

        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

        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)
            mac_address = port_dict.get('mac_address')
            connection = self._connection_with_mac_address(
                server_profile.get('connections'), mac_address)
            if connection:
                LOG.debug("There is Connection %s available.", connection)
                server_profile.get('connections').remove(connection)
            else:
                LOG.debug("There is no Connection available.")

            self._check_oneview_entities_availability(server_hardware)
            self._update_oneview_entities(server_hardware, server_profile)
            LOG.info("The requested port was deleted successfully.")
Example #2
0
    def create_connection(self):
        """Recreate connection that were deleted on Oneview.

        Calls method to fix critical connections in the Server Profile that
        will be used.
        """
        session = self.get_session()

        for port, port_binding in db_manager.get_port_with_binding_profile(
            session
        ):
            port_dict = common.port_dict_for_port_creation(
                port.get('network_id'),
                port_binding.get('vnic_type'),
                port.get('mac_address'),
                jsonutils.loads(port_binding.get('profile'))
            )
            local_link_info = common.local_link_information_from_port(
                port_dict)
            server_hardware_id = (
                common.server_hardware_from_local_link_information_list(
                    self.oneview_client, local_link_info))
            server_profile = (
                self.neutron_client.port.server_profile_from_server_hardware(
                    server_hardware_id
                )
            )
            neutron_oneview_network = db_manager.list_neutron_oneview_network(
                session, neutron_network_id=port.get('network_id')
            )
            connection_updated = False
            if len(neutron_oneview_network) > 0:
                oneview_uri = "/rest/ethernet-networks/" + (
                    neutron_oneview_network[0].oneview_network_id
                )
                self.fix_connections_with_removed_networks(
                    server_profile
                )
                for c in server_profile.get('connections'):
                    if c.get('mac') == port.get('mac_address'):
                        connection_updated = True
                        if c.get('networkUri') != oneview_uri:
                            self.update_connection(
                                oneview_uri, server_profile, c)
            if not connection_updated:
                self.neutron_client.port.create(session, port_dict)
Example #3
0
    def _delete_connections(self, neutron_network_id):
        session = self.get_session()
        for port, port_binding in (
            db_manager.get_port_with_binding_profile_by_net(
                session, neutron_network_id
            )
        ):
            port_dict = common.port_dict_for_port_creation(
                port.get('network_id'), port_binding.get('vnic_type'),
                port.get('mac_address'),
                jsonutils.loads(port_binding.get('profile'))
            )
            local_link_info = common.local_link_information_from_port(
                port_dict)
            server_hardware = (
                common.server_hardware_from_local_link_information_list(
                    self.oneview_client, local_link_info))

            server_profile = (
                self.neutron_client.port.server_profile_from_server_hardware(
                    server_hardware
                )
            )

            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")

            for connection in server_profile.get('connections'):
                if connection.get('mac') == port.get('mac_address'):
                    self._remove_connection(
                        server_profile, connection.get('id')
                    )
            self.neutron_client.port.update_server_hardware_power_state(
                server_hardware, previous_power_state
            )
Example #4
0
        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
Example #5
0
    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)
Example #6
0
    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)