def _get_node_agent_sku()

in src/hpcadvisor/batch_handler.py [0:0]


def _get_node_agent_sku(vm_image):
    """VMIMAGE=almalinux:almalinux-hpc:8-hpc-gen2:latest
    example of output=batch.node.el 8
    """

    _, offer, sku, _ = vm_image.lower().split(":")

    if not batch_client:
        log.critical("batch_client is None")
        sys.exit(1)

    supported_images = batch_client.account.list_supported_images()

    result = None
    for image in supported_images:
        if image.image_reference.offer == offer and image.image_reference.sku == sku:
            log.debug(f"Found image: {image.node_agent_sku_id}")
            result = image.node_agent_sku_id
            break
    if not result:
        log.debug(f"Cannot find node agent sku for {vm_image}")
        log.debug(f"Using backup node agent sku: {backupnodeagent}")
        result = backupnodeagent

    # TODO: store the output as file so we can use the result as cache
    # f = open(batch_supported_images)
    # data = json.load(f)
    #
    # result = [
    #     item["nodeAgentSkuId"]
    #     for item in data
    #     if item["imageReference"]["offer"] == offer
    #     and item["imageReference"]["sku"] == sku
    # ]

    return result