#!/usr/bin/python3

# Copyright (c) 2018, NVIDIA CORPORATION.  All rights reserved.
#
# NVIDIA CORPORATION and its licensors retain all intellectual property
# and proprietary rights in and to this software, related documentation
# and any modifications thereto.  Any use, reproduction, disclosure or
# distribution of this software and related documentation without an express
# license agreement from NVIDIA CORPORATION is strictly prohibited.

import importlib
import sys
import os

# CLI to configure data array on DGX station and DGX server.

def main(argv):

    if not os.geteuid() == 0:
        sys.exit("Script must be run as root")

    raid_path = "/usr/share/dgx/raid-config"

    if not os.path.exists(raid_path):
        sys.exit(raid_path + " not found")

    #
    # Prepend the current working directory to the search
    # path so importlib can find our raid modules quickly
    #
    sys.path.insert(0, raid_path)

    raid_configurator = None

    manifest_path = raid_path + "/" + "plat_manifest.json"
    plat_manifest_module = importlib.import_module("plat_manifest")
    plat_manifest = plat_manifest_module.PlatManifest(manifest_path)
    platform = plat_manifest.get_platform_profile()

    if platform == None:
        print("Platform not supported")
        return 1

    raid_configurator = platform.get_raid_configurator(sys.argv[0])

    msg = []
    rc = raid_configurator.run_configurator(argv, msg)

    if  len(msg) > 0:
        print(msg[0])

    return rc

if __name__ == "__main__":
    main(sys.argv[1:])


