Exemple #1
0
def get_network_device_function_collection(uuid, device_id):
    """Get the Redfish Network Interfaces Collection.

    Return NetworkDeviceFunctionCollection Redfish JSON.
    """
    try:
        server_hardware = g.oneview_client.server_hardware.get(uuid)

        ndfc = NetworkDeviceFunctionCollection(device_id, server_hardware)

        json_str = ndfc.serialize()

        return Response(response=json_str,
                        status=status.HTTP_200_OK,
                        mimetype="application/json")

    except HPOneViewException as e:
        if e.oneview_response['errorCode'] == "RESOURCE_NOT_FOUND":
            logging.warning('Server hardware UUID {} not found'.format(uuid))
            abort(status.HTTP_404_NOT_FOUND, "Server hardware not found")
        elif e.msg.find("server-hardware") >= 0:
            logging.exception('OneView Exception while looking for '
                              'server hardware: {}'.format(e))
            abort(status.HTTP_500_INTERNAL_SERVER_ERROR)
        else:
            logging.exception('Unexpected OneView Exception: {}'.format(e))
            abort(status.HTTP_500_INTERNAL_SERVER_ERROR)
    except Exception as e:
        # In case of error print exception and abort
        logging.exception('Unexpected error: {}'.format(e))
        return abort(status.HTTP_500_INTERNAL_SERVER_ERROR)
    def test_serialize(self):
        # Tests the serialize function result against known result

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

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

        self.assertEqual(self.network_device_function_collection_mockup,
                         result)
Exemple #3
0
def get_network_device_function_collection(uuid, device_id):
    """Get the Redfish Network Interfaces Collection.

    Return NetworkDeviceFunctionCollection Redfish JSON.
    """

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

    ndfc = NetworkDeviceFunctionCollection(device_id, server_hardware)

    return ResponseBuilder.success(ndfc)
    def test_class_instantiation(self):
        # Tests if class is correctly instantiated and validated

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