From f9fccd55027823377d984b70f129854e9e8524da Mon Sep 17 00:00:00 2001 From: Oscar Krause Date: Mon, 14 Apr 2025 20:05:10 +0200 Subject: [PATCH] implemented product_mapping support --- app/main.py | 20 +- app/static/product_mapping.json | 643 ++++++++++++++++++++++++++++++++ app/util.py | 31 ++ test/main.py | 7 +- 4 files changed, 693 insertions(+), 8 deletions(-) create mode 100644 app/static/product_mapping.json diff --git a/app/main.py b/app/main.py index 36a2641..a30d205 100644 --- a/app/main.py +++ b/app/main.py @@ -22,7 +22,7 @@ from starlette.middleware.cors import CORSMiddleware from starlette.responses import StreamingResponse, JSONResponse as JSONr, HTMLResponse as HTMLr, Response, RedirectResponse from orm import Origin, Lease, init as db_init, migrate -from util import PrivateKey, PublicKey, load_file, Cert +from util import PrivateKey, PublicKey, load_file, Cert, ProductMapping # Load variables load_dotenv('../version.env') @@ -52,6 +52,8 @@ LEASE_RENEWAL_DELTA = timedelta(days=int(env('LEASE_EXPIRE_DAYS', 90)), hours=in CLIENT_TOKEN_EXPIRE_DELTA = relativedelta(years=12) CORS_ORIGINS = str(env('CORS_ORIGINS', '')).split(',') if (env('CORS_ORIGINS')) else [f'https://{DLS_URL}'] DT_FORMAT = '%Y-%m-%dT%H:%M:%S.%fZ' +PRODUCT_MAPPING = ProductMapping(filename=join(dirname(__file__), 'static/product_mapping.json')) + jwt_encode_key = jwk.construct(INSTANCE_KEY_RSA.pem(), algorithm=ALGORITHMS.RS256) jwt_decode_key = jwk.construct(INSTANCE_KEY_PUB.pem(), algorithm=ALGORITHMS.RS256) @@ -679,28 +681,34 @@ async def leasing_v1_lessor(request: Request): origin_ref = token.get('origin_ref') scope_ref_list = j.get('scope_ref_list') + lease_proposal_list = j.get('lease_proposal_list') logger.info(f'> [ create ]: {origin_ref}: create leases for scope_ref_list {scope_ref_list}') - lease_result_list = [] - # todo: for lease_proposal in lease_proposal_list for scope_ref in scope_ref_list: # if scope_ref not in [ALLOTMENT_REF]: # return JSONr(status_code=500, detail=f'no service instances found for scopes: ["{scope_ref}"]') + pass + lease_result_list = [] + for lease_proposal in lease_proposal_list: lease_ref = str(uuid4()) expires = cur_time + LEASE_EXPIRE_DELTA + + product_name = lease_proposal.get('product').get('name') + feature_name = PRODUCT_MAPPING.get_feature_name(product_name=product_name) + lease_result_list.append({ "error": None, # https://docs.nvidia.com/license-system/latest/nvidia-license-system-user-guide/index.html "lease": { "created": cur_time.strftime(DT_FORMAT), - "expires": expires.strftime(DT_FORMAT), - "feature_name": "GRID-Virtual-WS", # todo + "expires": expires.strftime(DT_FORMAT), # todo: lease_proposal.get('duration') => "P0Y0M0DT12H0M0S + "feature_name": feature_name, "lease_intent_id": None, "license_type": "CONCURRENT_COUNTED_SINGLE", "metadata": None, "offline_lease": False, # todo - "product_name": "NVIDIA RTX Virtual Workstation", # todo + "product_name": product_name, "recommended_lease_renewal": LEASE_RENEWAL_PERIOD, "ref": lease_ref, }, diff --git a/app/static/product_mapping.json b/app/static/product_mapping.json new file mode 100644 index 0000000..1235e31 --- /dev/null +++ b/app/static/product_mapping.json @@ -0,0 +1,643 @@ +{ + "product": [ + { + "xid": "c0ce7114-d8a5-40d4-b8b0-df204f4ff631", + "product_family_xid": "bda4d909-2cdb-11ec-9838-061a22468b59", + "identifier": "NVIDIA-vComputeServer-9.0", + "name": "NVIDIA-vComputeServer-9.0", + "description": null + }, + { + "xid": "2a99638e-493f-424b-bc3a-629935307490", + "product_family_xid": "bda4d909-2cdb-11ec-9838-061a22468b59", + "identifier": "vGaming_Flexera_License-0.1", + "name": "vGaming_Flexera_License-0.1", + "description": null + }, + { + "xid": "a013d60c-3cd6-4e61-ae51-018b5e342178", + "product_family_xid": "bda4d909-2cdb-11ec-9838-061a22468b59", + "identifier": "GRID-Virtual-Apps-3.0", + "name": "GRID-Virtual-Apps-3.0", + "description": null + }, + { + "xid": "bb99c6a3-81ce-4439-aef5-9648e75dd878", + "product_family_xid": "bda4d909-2cdb-11ec-9838-061a22468b59", + "identifier": "GRID-vGaming-NLS-Metered-8.0", + "name": "GRID-vGaming-NLS-Metered-8.0", + "description": null + }, + { + "xid": "c653e131-695c-4477-b77c-42ade3dcb02c", + "product_family_xid": "bda4d909-2cdb-11ec-9838-061a22468b59", + "identifier": "GRID-Virtual-WS-Ext-2.0", + "name": "GRID-Virtual-WS-Ext-2.0", + "description": null + }, + { + "xid": "6fc224ef-e0b5-467b-9bbb-d31c9eb7c6fc", + "product_family_xid": "bda4d909-2cdb-11ec-9838-061a22468b59", + "identifier": "GRID-vGaming-8.0", + "name": "GRID-vGaming-8.0", + "description": null + }, + { + "xid": "3c88888d-ebf3-4df7-9e86-c97d5b29b997", + "product_family_xid": "bda4d909-2cdb-11ec-9838-061a22468b59", + "identifier": "GRID-Virtual-PC-2.0", + "name": "GRID-Virtual-PC-2.0", + "description": null + }, + { + "xid": "66744b41-1fff-49be-a5a6-4cbd71b1117e", + "product_family_xid": "bda4d909-2cdb-11ec-9838-061a22468b59", + "identifier": "NVAIE_Licensing-1.0", + "name": "NVAIE_Licensing-1.0", + "description": null + }, + { + "xid": "1d4e9ebc-a78c-41f4-a11a-de38a467b2ba", + "product_family_xid": "bda4d909-2cdb-11ec-9838-061a22468b59", + "identifier": "NVIDIA-vComputeServer NLS Metered-9.0", + "name": "NVIDIA-vComputeServer NLS Metered-9.0", + "description": null + }, + { + "xid": "2152f8aa-d17b-46f5-8f5f-6f8c0760ce9c", + "product_family_xid": "bda4d909-2cdb-11ec-9838-061a22468b59", + "identifier": "vGaming_FB_License-0.1", + "name": "vGaming_FB_License-0.1", + "description": null + }, + { + "xid": "54cbe0e8-7b35-4068-b058-e11f5b367c66", + "product_family_xid": "bda4d909-2cdb-11ec-9838-061a22468b59", + "identifier": "Quadro-Virtual-DWS-5.0", + "name": "Quadro-Virtual-DWS-5.0", + "description": null + }, + { + "xid": "07a1d2b5-c147-48bc-bf44-9390339ca388", + "product_family_xid": "bda4d909-2cdb-11ec-9838-061a22468b59", + "identifier": "GRID-Virtual-WS-2.0", + "name": "GRID-Virtual-WS-2.0", + "description": null + }, + { + "xid": "82d7a5f0-0c26-11ef-b3b6-371045c70906", + "product_family_xid": "bda4d909-2cdb-11ec-9838-061a22468b59", + "identifier": "vGaming_Flexera_License-0.1", + "name": "vGaming_Flexera_License-0.1", + "description": null + }, + { + "xid": "bdfbde00-2cdb-11ec-9838-061a22468b59", + "product_family_xid": "bda4d909-2cdb-11ec-9838-061a22468b59", + "identifier": "NVIDIA Virtual Applications", + "name": "NVIDIA Virtual Applications", + "description": null + }, + { + "xid": "bdfbe16d-2cdb-11ec-9838-061a22468b59", + "product_family_xid": "bda4d909-2cdb-11ec-9838-061a22468b59", + "identifier": "NVIDIA Virtual PC", + "name": "NVIDIA Virtual PC", + "description": null + }, + { + "xid": "bdfbe308-2cdb-11ec-9838-061a22468b59", + "product_family_xid": "bda4d909-2cdb-11ec-9838-061a22468b59", + "identifier": "NVIDIA RTX Virtual Workstation", + "name": "NVIDIA RTX Virtual Workstation", + "description": null + }, + { + "xid": "bdfbe405-2cdb-11ec-9838-061a22468b59", + "product_family_xid": "bda4d909-2cdb-11ec-9838-061a22468b59", + "identifier": "NVIDIA vGaming", + "name": "NVIDIA vGaming", + "description": null + }, + { + "xid": "bdfbe509-2cdb-11ec-9838-061a22468b59", + "product_family_xid": "bda4d909-2cdb-11ec-9838-061a22468b59", + "identifier": "GRID Virtual Applications", + "name": "GRID Virtual Applications", + "description": null + }, + { + "xid": "bdfbe5c6-2cdb-11ec-9838-061a22468b59", + "product_family_xid": "bda4d909-2cdb-11ec-9838-061a22468b59", + "identifier": "GRID Virtual PC", + "name": "GRID Virtual PC", + "description": null + }, + { + "xid": "bdfbe6e8-2cdb-11ec-9838-061a22468b59", + "product_family_xid": "bda4d909-2cdb-11ec-9838-061a22468b59", + "identifier": "Quadro Virtual Data Center Workstation", + "name": "Quadro Virtual Data Center Workstation", + "description": null + }, + { + "xid": "bdfbe7c8-2cdb-11ec-9838-061a22468b59", + "product_family_xid": "bda4d909-2cdb-11ec-9838-061a22468b59", + "identifier": "GRID vGaming", + "name": "GRID vGaming", + "description": null + }, + { + "xid": "bdfbe884-2cdb-11ec-9838-061a22468b59", + "product_family_xid": "bda4d909-2cdb-11ec-9838-061a22468b59", + "identifier": "NVIDIA Virtual Compute Server", + "name": "NVIDIA Virtual Compute Server", + "description": null + }, + { + "xid": "f09b5c33-5c07-11ed-9fa6-061a22468b59", + "product_family_xid": "bda4d909-2cdb-11ec-9838-061a22468b59", + "identifier": "NVIDIA OVE Licensing", + "name": "NVIDIA Omniverse Nucleus", + "description": null + } + ], + "product_fulfillment": [ + { + "xid": "cf0a5330-b583-4d9f-84bb-cfc8ce0917bb", + "product_xid": "07a1d2b5-c147-48bc-bf44-9390339ca388", + "qualifier_specification": null, + "evaluation_order_index": 0 + }, + { + "xid": "90d0f05f-9431-4a15-86e7-740a4f08d457", + "product_xid": "1d4e9ebc-a78c-41f4-a11a-de38a467b2ba", + "qualifier_specification": null, + "evaluation_order_index": 0 + }, + { + "xid": "327385dd-4ba8-4b3c-bc56-30bcf58ae9a3", + "product_xid": "2152f8aa-d17b-46f5-8f5f-6f8c0760ce9c", + "qualifier_specification": null, + "evaluation_order_index": 0 + }, + { + "xid": "6733f2cc-0736-47ee-bcc8-20c4c624ce37", + "product_xid": "2a99638e-493f-424b-bc3a-629935307490", + "qualifier_specification": null, + "evaluation_order_index": 0 + }, + { + "xid": "f35396a9-24f8-44b6-aa6a-493b335f4d56", + "product_xid": "3c88888d-ebf3-4df7-9e86-c97d5b29b997", + "qualifier_specification": null, + "evaluation_order_index": 0 + }, + { + "xid": "6c7981d3-7192-4bfd-b7ec-ea2ad0b466dc", + "product_xid": "54cbe0e8-7b35-4068-b058-e11f5b367c66", + "qualifier_specification": null, + "evaluation_order_index": 0 + }, + { + "xid": "9bd09610-6190-4684-9be6-3d9503833e80", + "product_xid": "66744b41-1fff-49be-a5a6-4cbd71b1117e", + "qualifier_specification": null, + "evaluation_order_index": 0 + }, + { + "xid": "a4282e5b-ea08-4e0a-b724-7f4059ba99de", + "product_xid": "6fc224ef-e0b5-467b-9bbb-d31c9eb7c6fc", + "qualifier_specification": null, + "evaluation_order_index": 0 + }, + { + "xid": "5cf793fc-1fb3-45c0-a711-d3112c775cbe", + "product_xid": "a013d60c-3cd6-4e61-ae51-018b5e342178", + "qualifier_specification": null, + "evaluation_order_index": 0 + }, + { + "xid": "eb2d39a4-6370-4464-8a6a-ec3f42c69cb5", + "product_xid": "bb99c6a3-81ce-4439-aef5-9648e75dd878", + "qualifier_specification": null, + "evaluation_order_index": 0 + }, + { + "xid": "e9df1c70-7fac-4c84-b54c-66e922b9791a", + "product_xid": "c0ce7114-d8a5-40d4-b8b0-df204f4ff631", + "qualifier_specification": null, + "evaluation_order_index": 0 + }, + { + "xid": "6a4d5bcd-7b81-4e22-a289-ce3673e5cabf", + "product_xid": "c653e131-695c-4477-b77c-42ade3dcb02c", + "qualifier_specification": null, + "evaluation_order_index": 0 + }, + { + "xid": "9e162d3c-0c26-11ef-b3b6-371045c70906", + "product_xid": "82d7a5f0-0c26-11ef-b3b6-371045c70906", + "qualifier_specification": null, + "evaluation_order_index": 0 + }, + { + "xid": "be2769b9-2cdb-11ec-9838-061a22468b59", + "product_xid": "bdfbde00-2cdb-11ec-9838-061a22468b59", + "qualifier_specification": null, + "evaluation_order_index": 0 + }, + { + "xid": "be276d7b-2cdb-11ec-9838-061a22468b59", + "product_xid": "bdfbe16d-2cdb-11ec-9838-061a22468b59", + "qualifier_specification": null, + "evaluation_order_index": 0 + }, + { + "xid": "be276efe-2cdb-11ec-9838-061a22468b59", + "product_xid": "bdfbe308-2cdb-11ec-9838-061a22468b59", + "qualifier_specification": null, + "evaluation_order_index": 0 + }, + { + "xid": "be276ff0-2cdb-11ec-9838-061a22468b59", + "product_xid": "bdfbe405-2cdb-11ec-9838-061a22468b59", + "qualifier_specification": null, + "evaluation_order_index": 0 + }, + { + "xid": "be2770af-2cdb-11ec-9838-061a22468b59", + "product_xid": "bdfbe509-2cdb-11ec-9838-061a22468b59", + "qualifier_specification": null, + "evaluation_order_index": 0 + }, + { + "xid": "be277164-2cdb-11ec-9838-061a22468b59", + "product_xid": "bdfbe5c6-2cdb-11ec-9838-061a22468b59", + "qualifier_specification": null, + "evaluation_order_index": 0 + }, + { + "xid": "be277214-2cdb-11ec-9838-061a22468b59", + "product_xid": "bdfbe6e8-2cdb-11ec-9838-061a22468b59", + "qualifier_specification": null, + "evaluation_order_index": 0 + }, + { + "xid": "be2772c8-2cdb-11ec-9838-061a22468b59", + "product_xid": "bdfbe7c8-2cdb-11ec-9838-061a22468b59", + "qualifier_specification": null, + "evaluation_order_index": 0 + }, + { + "xid": "be277379-2cdb-11ec-9838-061a22468b59", + "product_xid": "bdfbe884-2cdb-11ec-9838-061a22468b59", + "qualifier_specification": null, + "evaluation_order_index": 0 + }, + { + "xid": "c4284597-5c09-11ed-9fa6-061a22468b59", + "product_xid": "f09b5c33-5c07-11ed-9fa6-061a22468b59", + "qualifier_specification": null, + "evaluation_order_index": 0 + } + ], + "product_fulfillment_feature": [ + { + "xid": "9ca32d2b-736e-4e4f-8f5a-895a755b4c41", + "product_fulfillment_xid": "5cf793fc-1fb3-45c0-a711-d3112c775cbe", + "feature_identifier": "GRID-Virtual-Apps", + "feature_version": "3.0", + "license_type_identifier": "CONCURRENT_COUNTED_SINGLE", + "evaluation_order_index": 0 + }, + { + "xid": "d8b25329-f47f-43dc-a278-f2d38f9e939b", + "product_fulfillment_xid": "f35396a9-24f8-44b6-aa6a-493b335f4d56", + "feature_identifier": "GRID-Virtual-PC", + "feature_version": "2.0", + "license_type_identifier": "CONCURRENT_COUNTED_SINGLE", + "evaluation_order_index": 0 + }, + { + "xid": "e7102df8-d88a-4bd0-aa79-9a53d8b77888", + "product_fulfillment_xid": "cf0a5330-b583-4d9f-84bb-cfc8ce0917bb", + "feature_identifier": "GRID-Virtual-WS", + "feature_version": "2.0", + "license_type_identifier": "CONCURRENT_COUNTED_SINGLE", + "evaluation_order_index": 0 + }, + { + "xid": "30761db3-0afe-454d-b284-efba6d9b13a3", + "product_fulfillment_xid": "6a4d5bcd-7b81-4e22-a289-ce3673e5cabf", + "feature_identifier": "GRID-Virtual-WS-Ext", + "feature_version": "2.0", + "license_type_identifier": "CONCURRENT_COUNTED_SINGLE", + "evaluation_order_index": 0 + }, + { + "xid": "10fd7701-83ae-4caf-a27f-75880fab23f6", + "product_fulfillment_xid": "a4282e5b-ea08-4e0a-b724-7f4059ba99de", + "feature_identifier": "GRID-vGaming", + "feature_version": "8.0", + "license_type_identifier": "CONCURRENT_COUNTED_SINGLE", + "evaluation_order_index": 0 + }, + { + "xid": "cbd61276-fb1e-42e1-b844-43e94465da8f", + "product_fulfillment_xid": "9bd09610-6190-4684-9be6-3d9503833e80", + "feature_identifier": "NVAIE_Licensing", + "feature_version": "1.0", + "license_type_identifier": "CONCURRENT_COUNTED_SINGLE", + "evaluation_order_index": 0 + }, + { + "xid": "6b1c74b5-1511-46ee-9f12-8bc6d5636fef", + "product_fulfillment_xid": "90d0f05f-9431-4a15-86e7-740a4f08d457", + "feature_identifier": "NVIDIA-vComputeServer NLS Metered", + "feature_version": "9.0", + "license_type_identifier": "CONCURRENT_COUNTED_SINGLE", + "evaluation_order_index": 0 + }, + { + "xid": "db53af09-7295-48b7-b927-24b23690c959", + "product_fulfillment_xid": "e9df1c70-7fac-4c84-b54c-66e922b9791a", + "feature_identifier": "NVIDIA-vComputeServer", + "feature_version": "9.0", + "license_type_identifier": "CONCURRENT_COUNTED_SINGLE", + "evaluation_order_index": 0 + }, + { + "xid": "1f62be61-a887-4e54-a34e-61cfa7b2db30", + "product_fulfillment_xid": "6c7981d3-7192-4bfd-b7ec-ea2ad0b466dc", + "feature_identifier": "Quadro-Virtual-DWS", + "feature_version": "5.0", + "license_type_identifier": "CONCURRENT_COUNTED_SINGLE", + "evaluation_order_index": 0 + }, + { + "xid": "8a4b5e98-f1ca-4c18-b0d4-8f4f9f0462e2", + "product_fulfillment_xid": "327385dd-4ba8-4b3c-bc56-30bcf58ae9a3", + "feature_identifier": "vGaming_FB_License", + "feature_version": "0.1", + "license_type_identifier": "CONCURRENT_COUNTED_SINGLE", + "evaluation_order_index": 0 + }, + { + "xid": "be531e98-2cdb-11ec-9838-061a22468b59", + "product_fulfillment_xid": "be2769b9-2cdb-11ec-9838-061a22468b59", + "feature_identifier": "GRID-Virtual-Apps", + "feature_version": "3.0", + "license_type_identifier": "CONCURRENT_COUNTED_SINGLE", + "evaluation_order_index": 0 + }, + { + "xid": "be53219e-2cdb-11ec-9838-061a22468b59", + "product_fulfillment_xid": "be276d7b-2cdb-11ec-9838-061a22468b59", + "feature_identifier": "GRID-Virtual-PC", + "feature_version": "2.0", + "license_type_identifier": "CONCURRENT_COUNTED_SINGLE", + "evaluation_order_index": 0 + }, + { + "xid": "be5322f0-2cdb-11ec-9838-061a22468b59", + "product_fulfillment_xid": "be276d7b-2cdb-11ec-9838-061a22468b59", + "feature_identifier": "Quadro-Virtual-DWS", + "feature_version": "5.0", + "license_type_identifier": "CONCURRENT_COUNTED_SINGLE", + "evaluation_order_index": 1 + }, + { + "xid": "be5323d8-2cdb-11ec-9838-061a22468b59", + "product_fulfillment_xid": "be276d7b-2cdb-11ec-9838-061a22468b59", + "feature_identifier": "GRID-Virtual-WS", + "feature_version": "2.0", + "license_type_identifier": "CONCURRENT_COUNTED_SINGLE", + "evaluation_order_index": 2 + }, + { + "xid": "be5324a6-2cdb-11ec-9838-061a22468b59", + "product_fulfillment_xid": "be276d7b-2cdb-11ec-9838-061a22468b59", + "feature_identifier": "GRID-Virtual-WS-Ext", + "feature_version": "2.0", + "license_type_identifier": "CONCURRENT_COUNTED_SINGLE", + "evaluation_order_index": 3 + }, + { + "xid": "be532568-2cdb-11ec-9838-061a22468b59", + "product_fulfillment_xid": "be276efe-2cdb-11ec-9838-061a22468b59", + "feature_identifier": "Quadro-Virtual-DWS", + "feature_version": "5.0", + "license_type_identifier": "CONCURRENT_COUNTED_SINGLE", + "evaluation_order_index": 0 + }, + { + "xid": "be532630-2cdb-11ec-9838-061a22468b59", + "product_fulfillment_xid": "be276efe-2cdb-11ec-9838-061a22468b59", + "feature_identifier": "GRID-Virtual-WS", + "feature_version": "2.0", + "license_type_identifier": "CONCURRENT_COUNTED_SINGLE", + "evaluation_order_index": 1 + }, + { + "xid": "be5326e7-2cdb-11ec-9838-061a22468b59", + "product_fulfillment_xid": "be276efe-2cdb-11ec-9838-061a22468b59", + "feature_identifier": "GRID-Virtual-WS-Ext", + "feature_version": "2.0", + "license_type_identifier": "CONCURRENT_COUNTED_SINGLE", + "evaluation_order_index": 2 + }, + { + "xid": "be5327a7-2cdb-11ec-9838-061a22468b59", + "product_fulfillment_xid": "be276ff0-2cdb-11ec-9838-061a22468b59", + "feature_identifier": "GRID-vGaming", + "feature_version": "8.0", + "license_type_identifier": "CONCURRENT_COUNTED_SINGLE", + "evaluation_order_index": 0 + }, + { + "xid": "be532923-2cdb-11ec-9838-061a22468b59", + "product_fulfillment_xid": "be2770af-2cdb-11ec-9838-061a22468b59", + "feature_identifier": "GRID-Virtual-Apps", + "feature_version": "3.0", + "license_type_identifier": "CONCURRENT_COUNTED_SINGLE", + "evaluation_order_index": 0 + }, + { + "xid": "be5329e0-2cdb-11ec-9838-061a22468b59", + "product_fulfillment_xid": "be277164-2cdb-11ec-9838-061a22468b59", + "feature_identifier": "GRID-Virtual-PC", + "feature_version": "2.0", + "license_type_identifier": "CONCURRENT_COUNTED_SINGLE", + "evaluation_order_index": 0 + }, + { + "xid": "be532aa0-2cdb-11ec-9838-061a22468b59", + "product_fulfillment_xid": "be277164-2cdb-11ec-9838-061a22468b59", + "feature_identifier": "Quadro-Virtual-DWS", + "feature_version": "5.0", + "license_type_identifier": "CONCURRENT_COUNTED_SINGLE", + "evaluation_order_index": 1 + }, + { + "xid": "be532b5c-2cdb-11ec-9838-061a22468b59", + "product_fulfillment_xid": "be277164-2cdb-11ec-9838-061a22468b59", + "feature_identifier": "GRID-Virtual-WS", + "feature_version": "2.0", + "license_type_identifier": "CONCURRENT_COUNTED_SINGLE", + "evaluation_order_index": 2 + }, + { + "xid": "be532c19-2cdb-11ec-9838-061a22468b59", + "product_fulfillment_xid": "be277164-2cdb-11ec-9838-061a22468b59", + "feature_identifier": "GRID-Virtual-WS-Ext", + "feature_version": "2.0", + "license_type_identifier": "CONCURRENT_COUNTED_SINGLE", + "evaluation_order_index": 3 + }, + { + "xid": "be532ccb-2cdb-11ec-9838-061a22468b59", + "product_fulfillment_xid": "be277214-2cdb-11ec-9838-061a22468b59", + "feature_identifier": "Quadro-Virtual-DWS", + "feature_version": "5.0", + "license_type_identifier": "CONCURRENT_COUNTED_SINGLE", + "evaluation_order_index": 0 + }, + { + "xid": "be532d92-2cdb-11ec-9838-061a22468b59", + "product_fulfillment_xid": "be277214-2cdb-11ec-9838-061a22468b59", + "feature_identifier": "GRID-Virtual-WS", + "feature_version": "2.0", + "license_type_identifier": "CONCURRENT_COUNTED_SINGLE", + "evaluation_order_index": 1 + }, + { + "xid": "be532e45-2cdb-11ec-9838-061a22468b59", + "product_fulfillment_xid": "be277214-2cdb-11ec-9838-061a22468b59", + "feature_identifier": "GRID-Virtual-WS-Ext", + "feature_version": "2.0", + "license_type_identifier": "CONCURRENT_COUNTED_SINGLE", + "evaluation_order_index": 2 + }, + { + "xid": "be532efa-2cdb-11ec-9838-061a22468b59", + "product_fulfillment_xid": "be2772c8-2cdb-11ec-9838-061a22468b59", + "feature_identifier": "GRID-vGaming", + "feature_version": "8.0", + "license_type_identifier": "CONCURRENT_COUNTED_SINGLE", + "evaluation_order_index": 0 + }, + { + "xid": "be53306d-2cdb-11ec-9838-061a22468b59", + "product_fulfillment_xid": "be277379-2cdb-11ec-9838-061a22468b59", + "feature_identifier": "NVIDIA-vComputeServer", + "feature_version": "9.0", + "license_type_identifier": "CONCURRENT_COUNTED_SINGLE", + "evaluation_order_index": 0 + }, + { + "xid": "be533228-2cdb-11ec-9838-061a22468b59", + "product_fulfillment_xid": "be277379-2cdb-11ec-9838-061a22468b59", + "feature_identifier": "NVIDIA-vComputeServer NLS Metered", + "feature_version": "9.0", + "license_type_identifier": "CONCURRENT_UNCOUNTED_SINGLE", + "evaluation_order_index": 2 + }, + { + "xid": "be5332f6-2cdb-11ec-9838-061a22468b59", + "product_fulfillment_xid": "be277379-2cdb-11ec-9838-061a22468b59", + "feature_identifier": "NVAIE_Licensing", + "feature_version": "1.0", + "license_type_identifier": "CONCURRENT_COUNTED_SINGLE", + "evaluation_order_index": 3 + }, + { + "xid": "15ff4f16-57a8-4593-93ec-58352a256f12", + "product_fulfillment_xid": "eb2d39a4-6370-4464-8a6a-ec3f42c69cb5", + "feature_identifier": "GRID-vGaming-NLS-Metered", + "feature_version": "8.0", + "license_type_identifier": "CONCURRENT_COUNTED_SINGLE", + "evaluation_order_index": 3 + }, + { + "xid": "0c1552ca-3ef8-11ed-9fa6-061a22468b59", + "product_fulfillment_xid": "be276ff0-2cdb-11ec-9838-061a22468b59", + "feature_identifier": "vGaming_Flexera_License", + "feature_version": "0.1", + "license_type_identifier": "CONCURRENT_COUNTED_SINGLE", + "evaluation_order_index": 1 + }, + { + "xid": "31c3be8c-5c0a-11ed-9fa6-061a22468b59", + "product_fulfillment_xid": "c4284597-5c09-11ed-9fa6-061a22468b59", + "feature_identifier": "OVE_Licensing", + "feature_version": "1.0", + "license_type_identifier": "CONCURRENT_COUNTED_SINGLE", + "evaluation_order_index": 0 + }, + { + "xid": "6caeb4cf-360f-11ee-b67d-02f279bf2bff", + "product_fulfillment_xid": "be277379-2cdb-11ec-9838-061a22468b59", + "feature_identifier": "NVAIE_Licensing", + "feature_version": "2.0", + "license_type_identifier": "CONCURRENT_COUNTED_SINGLE", + "evaluation_order_index": 4 + }, + { + "xid": "7fb1d01d-3f0e-11ed-9fa6-061a22468b59", + "product_fulfillment_xid": "be276ff0-2cdb-11ec-9838-061a22468b59", + "feature_identifier": "vGaming_FB_License", + "feature_version": "0.1", + "license_type_identifier": "CONCURRENT_COUNTED_SINGLE", + "evaluation_order_index": 2 + }, + { + "xid": "8eabcb08-3f0e-11ed-9fa6-061a22468b59", + "product_fulfillment_xid": "be2772c8-2cdb-11ec-9838-061a22468b59", + "feature_identifier": "vGaming_FB_License", + "feature_version": "0.1", + "license_type_identifier": "CONCURRENT_COUNTED_SINGLE", + "evaluation_order_index": 2 + }, + { + "xid": "a1dfe741-3e49-11ed-9fa6-061a22468b59", + "product_fulfillment_xid": "be2772c8-2cdb-11ec-9838-061a22468b59", + "feature_identifier": "vGaming_Flexera_License", + "feature_version": "0.1", + "license_type_identifier": "CONCURRENT_COUNTED_SINGLE", + "evaluation_order_index": 1 + }, + { + "xid": "be53286a-2cdb-11ec-9838-061a22468b59", + "product_fulfillment_xid": "be276ff0-2cdb-11ec-9838-061a22468b59", + "feature_identifier": "GRID-vGaming-NLS-Metered", + "feature_version": "8.0", + "license_type_identifier": "CONCURRENT_UNCOUNTED_SINGLE", + "evaluation_order_index": 3 + }, + { + "xid": "be532fb2-2cdb-11ec-9838-061a22468b59", + "product_fulfillment_xid": "be2772c8-2cdb-11ec-9838-061a22468b59", + "feature_identifier": "GRID-vGaming-NLS-Metered", + "feature_version": "8.0", + "license_type_identifier": "CONCURRENT_UNCOUNTED_SINGLE", + "evaluation_order_index": 3 + }, + { + "xid": "be533144-2cdb-11ec-9838-061a22468b59", + "product_fulfillment_xid": "be277379-2cdb-11ec-9838-061a22468b59", + "feature_identifier": "Quadro-Virtual-DWS", + "feature_version": "0.0", + "license_type_identifier": "CONCURRENT_COUNTED_SINGLE", + "evaluation_order_index": 1 + }, + { + "xid": "bf105e18-0c26-11ef-b3b6-371045c70906", + "product_fulfillment_xid": "9e162d3c-0c26-11ef-b3b6-371045c70906", + "feature_identifier": "vGaming_Flexera_License", + "feature_version": "0.1", + "license_type_identifier": "CONCURRENT_COUNTED_SINGLE", + "evaluation_order_index": 0 + } + ] +} diff --git a/app/util.py b/app/util.py index 9287336..a8288de 100644 --- a/app/util.py +++ b/app/util.py @@ -153,3 +153,34 @@ class NV: 'is_latest': is_latest, } return None + + +class ProductMapping: + + def __init__(self, filename: str): + with open(filename, 'r') as file: + self.data = json_loads(file.read()) + + + def get_feature_name(self, product_name: str) -> (str, str): + product = self.__get_product(product_name) + product_fulfillment = self.__get_product_fulfillment(product.get('xid')) + feature = self.__get_product_fulfillment_feature(product_fulfillment.get('xid')) + + return feature.get('feature_identifier') + + + def __get_product(self, product_name: str): + product_list = self.data.get('product') + return next(filter(lambda _: _.get('identifier') == product_name, product_list)) + + + def __get_product_fulfillment(self, product_xid: str): + product_fulfillment_list = self.data.get('product_fulfillment') + return next(filter(lambda _: _.get('product_xid') == product_xid, product_fulfillment_list)) + + def __get_product_fulfillment_feature(self, product_fulfillment_xid: str): + feature_list = self.data.get('product_fulfillment_feature') + features = list(filter(lambda _: _.get('product_fulfillment_xid') == product_fulfillment_xid, feature_list)) + features.sort(key=lambda _: _.get('evaluation_order_index')) + return features[0] diff --git a/test/main.py b/test/main.py index d3ef989..f9c44d6 100644 --- a/test/main.py +++ b/test/main.py @@ -201,7 +201,7 @@ def test_leasing_v1_lessor(): }, 'lease_proposal_list': [{ 'license_type_qualifiers': {'count': 1}, - 'product': {'name': 'NVIDIA RTX Virtual Workstation'} + 'product': {'name': 'NVIDIA Virtual Applications'} }], 'proposal_evaluation_mode': 'ALL_OF', 'scope_ref_list': [ALLOTMENT_REF] @@ -219,6 +219,9 @@ def test_leasing_v1_lessor(): assert len(lease_result_list) == 1 assert len(lease_result_list[0]['lease']['ref']) == 36 assert str(UUID(lease_result_list[0]['lease']['ref'])) == lease_result_list[0]['lease']['ref'] + assert lease_result_list[0]['lease']['product_name'] == 'NVIDIA Virtual Applications' + assert lease_result_list[0]['lease']['feature_name'] == 'GRID-Virtual-Apps' + def test_leasing_v1_lessor_lease(): @@ -275,7 +278,7 @@ def test_leasing_v1_lessor_lease_remove(): }, 'lease_proposal_list': [{ 'license_type_qualifiers': {'count': 1}, - 'product': {'name': 'NVIDIA RTX Virtual Workstation'} + 'product': {'name': 'NVIDIA Virtual Applications'} }], 'proposal_evaluation_mode': 'ALL_OF', 'scope_ref_list': [ALLOTMENT_REF]