def get_network_interface(uuid, device_id):
    """Get the Redfish NetworkInterface for a given UUID and device_id.

        Return NetworkInterface Redfish JSON for a given hardware UUID
        and device_id.

        Parameters:
            uuid: the UUID of the server_hardware
            device_id: The id of the network device

        Returns:
            JSON: Redfish json with NetworkInterface

        Exceptions:
            When hardware is not found calls abort(404)
            When other errors occur calls abort(500)

    """
    try:
        device_id_validation = int(device_id)

        server_hardware = g.oneview_client.server_hardware.get(uuid)

        if (device_id_validation - 1) < 0 or (device_id_validation - 1) >= \
                len(server_hardware["portMap"]["deviceSlots"]):
            raise OneViewRedfishResourceNotFoundError(device_id,
                                                      "Network interface")

        ni = NetworkInterface(device_id, server_hardware)

        json_str = ni.serialize()

        return Response(response=json_str,
                        status=status.HTTP_200_OK,
                        mimetype="application/json")
    except ValueError:
        # Failed to convert device_id to int
        logging.exception(
            "Failed to convert device id {} to integer.".format(device_id))
        abort(status.HTTP_404_NOT_FOUND, "Network interface not found")
    except OneViewRedfishResourceNotFoundError as e:
        logging.exception(e.msg)
        abort(status.HTTP_404_NOT_FOUND, e.msg)
    except HPOneViewException as e:
        # In case of error log exception and abort
        logging.exception(e)
        if e.oneview_response['errorCode'] == "RESOURCE_NOT_FOUND":
            abort(status.HTTP_404_NOT_FOUND, "Server hardware not found")
        else:
            abort(status.HTTP_500_INTERNAL_SERVER_ERROR)
    except Exception as e:
        # In case of error log exception and abort
        logging.exception('Unexpected error: {}'.format(e))
        abort(status.HTTP_500_INTERNAL_SERVER_ERROR)
Пример #2
0
    def test_serialize(self):
        # Tests the serialize function result against known result

        device_id = "3"

        network_interface = \
            NetworkInterface(device_id,
                             self.server_profile,
                             self.server_hardware)

        result = json.loads(network_interface.serialize())

        self.assertEqualMockup(self.network_interface_mockup, result)
Пример #3
0
    def test_serialize(self):
        # Tests the serialize function result against known result

        try:
            network_interface = \
                NetworkInterface(self.device_id, self.server_hardware)
        except Exception as e:
            self.fail("Failed to instantiate NetworkInterfaceCollection class."
                      " Error: {}".format(e))

        try:
            result = json.loads(network_interface.serialize())
        except Exception as e:
            self.fail("Failed to serialize. Error: ".format(e))

        self.assertEqual(self.network_interface_mockup, result)
Пример #4
0
    def test_class_instantiation(self):
        # Tests if class is correctly instantiated and validated

        try:
            network_interface = \
                NetworkInterface(self.device_id, self.server_hardware)
        except Exception as e:
            self.fail("Failed to instantiate NetworkInterface class."
                      " Error: {}".format(e))
        self.assertIsInstance(network_interface, NetworkInterface)
def get_network_interface(server_profile_uuid, device_id):
    """Get the Redfish NetworkInterface for a given UUID and device_id.

        Return NetworkInterface Redfish JSON for a given hardware UUID
        and device_id.

        Parameters:
            server_profile_uuid: the UUID of the server profile
            device_id: The id of the network device

        Returns:
            JSON: Redfish json with NetworkInterface

        Exceptions:
            When server profile or hardware is not found calls abort(404)
            When other errors occur calls abort(500)

    """
    try:
        device_id_validation = int(device_id)

        profile = g.oneview_client.server_profiles.get_by_id(
            server_profile_uuid).data
        server_hardware = g.oneview_client.server_hardware\
            .get_by_uri(profile["serverHardwareUri"]).data

        if (device_id_validation - 1) < 0 or (device_id_validation - 1) >= \
                len(server_hardware["portMap"]["deviceSlots"]):
            abort(status.HTTP_404_NOT_FOUND,
                  "Network interface id {} not found.".format(device_id))

        ni = NetworkInterface(device_id, profile, server_hardware)

        return ResponseBuilder.success(ni)

    except ValueError:
        # Failed to convert device_id to int
        logging.exception(
            "Failed to convert device id {} to integer.".format(device_id))
        abort(status.HTTP_404_NOT_FOUND, "Network interface not found")