def get_computer_system_collection():
    """Get the Redfish Computer System Collection.

        Get method to return ComputerSystemCollection JSON when
        /redfish/v1/Systems is requested.

        Returns:
                JSON: JSON with ComputerSystemCollection.
    """
    try:
        # Gets all server hardware
        server_hardware_list = g.oneview_client.server_hardware.get_all()
        if not server_hardware_list:
            raise OneViewRedfishResourceNotFoundError("server-hardware-list",
                                                      "Resource")

        # Build Computer System Collection object and validates it
        csc = ComputerSystemCollection(server_hardware_list)

        # Build redfish json
        json_str = csc.serialize()

        # Build response and returns
        return Response(response=json_str,
                        status=status.HTTP_200_OK,
                        mimetype="application/json")
    except OneViewRedfishResourceNotFoundError as e:
        # In case of error log exception and abort
        logging.exception('Unexpected error: {}'.format(e))
        abort(status.HTTP_404_NOT_FOUND, e.msg)
    except Exception as e:
        # In case of error print exception and abort
        logging.exception(e)
        return abort(status.HTTP_500_INTERNAL_SERVER_ERROR)
    def test_serialize(self):
        # Tests the serialize function result against known result

        try:
            computer_system_collection = ComputerSystemCollection(
                self.server_hardware_list)
        except Exception as e:
            self.fail("Failed to instantiate ComputerSystemCollection class."
                      " Error: {}".format(e))

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

        self.assertEqual(self.computer_system_collection_mockup, result)
    def test_serialize(self):
        # Tests the serialize function result against known result

        zone_ids = [
            "1f0ca9ef-7f81-45e3-9d64-341b46cf87e0-0000000000A66101",
            "1f0ca9ef-7f81-45e3-9d64-341b46cf87e0-0000000000A66102",
            "75871d70-789e-4cf9-8bc8-6f4d73193578"
        ]

        computer_system_collection = ComputerSystemCollection(
            self.server_profile_list, self.server_profile_template_list,
            zone_ids)

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

        self.assertEqualMockup(self.computer_system_collection_mockup, result)
    def test_class_instantiation(self):
        # Tests if class is correctly instantiated and validated

        try:
            computer_system_collection = ComputerSystemCollection(
                self.server_hardware_list)
        except Exception as e:
            self.fail("Failed to instantiate ComputerSystemCollection class."
                      " Error: {}".format(e))
        self.assertIsInstance(computer_system_collection,
                              ComputerSystemCollection)
def get_computer_system_collection():
    """Get the Redfish Computer System Collection.

        Get method to return ComputerSystemCollection JSON when
        /redfish/v1/Systems is requested.

        Returns:
                JSON: JSON with ComputerSystemCollection.
    """
    server_hardware_list = g.oneview_client.server_hardware.get_all(
        filter="NOT 'serverProfileUri' = NULL")

    server_profile_tmpls = \
        g.oneview_client.server_profile_templates.get_all()

    zone_service = ZoneService(g.oneview_client)
    zone_ids = zone_service.get_zone_ids_by_templates(server_profile_tmpls)

    csc = ComputerSystemCollection(server_hardware_list, server_profile_tmpls,
                                   zone_ids)

    return ResponseBuilder.success(csc)