#!/usr/bin/python

"""
This module contains the deployment configuration data for Python scripts and TK demo
Deployment states can be added and removed as long as these defines data structures
are maintained and a script is provided to execute when entering a new state.
For each state defined, each of the dictionaries must have an entry for the state.
Control the order and inclusion of a state in the deployment sequence with the use
of the 'NEXTSTATE' variables in the dicStateInfo disctionary.
Python, Linux, and Windows shell scripts are supported. 
See return value and STATESCRIPT descriptions below.
"""

import os, os.path
from config import DeployPath

if os.environ.has_key('TKDEMO'):
    TKDEMO = os.environ['TKDEMO']
else:
    TKDEMO = 0
if os.environ.has_key('TKTEST'):
    TKTEST = os.environ['TKTEST']
else:
    TKTEST = 0

# Deployment state defines:
# these values are maintained in NV RAM to be preserved across required reboots
# to enable the correct resumption of deployment state processing
Sflash  = 1
Sconfig = 2
Sdisk   = 3
Sraid   = 4
Sos     = 5
Snet    = 6
Srestore = 7
FINISHED = 8

# Deployment script return values:
ATSTATE = 0 # successful transition to requested state
FAILURE = 1 # can't achieve desired state
UPDATE  = 102 # update required
REFRESH = 103 # refresh of System Info required
REBOOT  = 104 # reboot required to achieve state
UNSUPPORTED = 105 # state can't be acheived because it is unsupported on platform or OS

DeploymentStates = [
    Sflash,
    Sconfig,
    Sdisk,
    Sraid,
    Sos,
    Snet,
    Srestore,
    FINISHED
]
if TKDEMO:
    # scriptWidgets = [showBtn, runBtn, and label widget instances, label text ]
    dicTKdemoInfo = {
        Sflash  :[0,0,0,'flash BIOS and/or FW'],
        Sconfig :[0,0,0,'configure BIOS and/or FW'],
        Sdisk   :[0,0,0,'configure hard drives'],
        Sraid   :[0,0,0,'create a RAID'],
        Sos     :[0,0,0,'install an OS'],
        Snet    :[0,0,0,'set OS network parameters'],
        Srestore:[0,0,0,'restore factory defaults']
    }
# Deployment info list offset defines:
# NEXTSTATE is the new state that is transitioned to
# by the successful completion of the current state stript
NEXTSTATE   = 0
#STATESCRIPT is the script name run in the current state.
# All scripts must include the full path.
# Windows and Linux shell scripts should not have an extension.
# '.cmd' or '.sh' is appended to the script name and run in its directory.
# Python scripts must end in '.py' and they don't have to be in PYTHONPATH 
# Python scripts are imported and the 'runState()' function is called.
# See the definition of the script return value defines above
STATESCRIPT = 1
#STATEMSG   stdout message when entering state
STATEMSG    = 2
#STATELOGMSG log INFO message when entering state
STATELOGMSG = 3

if TKTEST:
    dicStateInfo = {
        Sflash  :[Sconfig,os.path.join(DeployPath,'doc','customDeployment',"demoTest.py"),"Flashing BIOS and/or FW","Deployment is in the Sflash state"],
        Sconfig :[Sdisk,os.path.join(DeployPath,'doc','customDeployment',"demoTest.py"),"Configuring BIOS and/or FW","Deployment is in the Sconfig state"],
        Sdisk   :[Sraid,os.path.join(DeployPath,'doc','customDeployment',"demoTest.py"),"Configuring hard drives","Deployment is in the Sdisk state"],
        Sraid   :[FINISHED,os.path.join(DeployPath,'doc','customDeployment',"demoTest.py"),"Creating a RAID","Deployment is in the Sraid state"],
        Sos     :[FINISHED,os.path.join(DeployPath,'doc','customDeployment',"demoTest.py"),"Installing an OS","Deployment is in the Sos state"],
        Snet    :[FINISHED,os.path.join(DeployPath,'doc','customDeployment',"demoTest"),"Setting network parameters","Deployment is in the Snet state"],
        Srestore :[FINISHED,os.path.join(DeployPath,'doc','customDeployment',"demoTest.py"),"Restoring factory defaults","Deployment is in the Srestore state"],
        FINISHED :[0,'',"Deployment is finished","Deployment is finished"]
    }
else:
    dicStateInfo = {
        Sflash  :[Sconfig,os.path.join(DeployPath,'doc',"flash.py"),"Flashing BIOS and/or FW","Deployment is in the Sflash state"],
        Sconfig :[Sdisk,os.path.join(DeployPath,'doc',"configFW.py"),"Configuring BIOS and/or FW","Deployment is in the Sconfig state"],
        Sdisk   :[Sraid,os.path.join(DeployPath,'doc','customDeployment',"demoTest.py"),"Configuring hard drives","Deployment is in the Sdisk state"],
        Sraid   :[FINISHED,os.path.join(DeployPath,'doc',"raid.py"),"Creating a RAID","Deployment is in the Sraid state"],
        Sos     :[FINISHED,os.path.join(DeployPath,'doc',"Sos.py"),"Installing an OS","Deployment is in the Sos state"],
        Snet    :[FINISHED,os.path.join(DeployPath,'doc',"demoTest"),"Setting network parameters","Deployment is in the Snet state"],
        Srestore :[FINISHED,os.path.join(DeployPath,'doc',"demoTest"),"Restoring factory defaults","Deployment is in the Srestore state"],
        FINISHED :[0,'',"Deployment is finished","Deployment is finished"]
    }

"""
The 'Specs' dictionaries are the chassis dictionaries for flashing BIOS and
BMC firmware. A dictionary entry contains the target BIOS and BMC firmware
versions and the resources needed by the utilities to flash the versions.
All supported PDK chassis have a dictionary entry in each of these dictionaries.

This Python dictionaries are intended to be edited according to the deployment needs
The dictionary entry format is:
    'chassis':['resource_set']
the 'chassis' must be unique to the dictionary
'resource_set' is:
    'BIOS_Version', 'BMCFW_Version', required_resources
required_resources is:
    [update_packages_list],update_configuration_file,[setMaster_options_list] | chassis_specific_file

"""
# chassis dictionary entry indices:
UPDATEBIOS    = 0 # compare to query: ret, build = systemMgr.queryProperty(0,'IntelBIOSID','BuildID','',{})
UPDATEMGMT    = 1 # compare to query: ret, BMCver = systemMgr.queryProperty(0,'SDR','BMC version','',{})
                  # compare to query: ret, AMTver = systemMgr.queryProperty(0,'AMT','Flash version','',{})
UPDATEZIPS    = 2 # one or more zip packages for updating the system
UPDATECONFIG  = 3 # 
UPDATEMASTER  = 4 # MASTER file or defines for OFU
chassisSpecs = {
    'TIGW1U'  : ['0091','0.20',['SHB26_912018.zip'],'flashupdt.TIGW1U.912018.cfg',['NI_FRUSDR','FRU','SDR','NI_POWER','AC_PSM','BMC_TAM','TAM_AAS','NI_FRU','NI_ASSET']],
    'NSW1U'   : ['0091','0.20',['SHB26_912018.zip'],'flashupdt.NSW1U.912018.cfg',['NI_FRUSDR','FRU','SDR','NI_POWER','AC_PSM','NI_FRU','NI_ASSET']],
    'NSC2U'   : ['0091','0.64',['STA16_916412.zip'],'flashupdt.NSC2U.916412.cfg',['NI_FRUSDR','FRU','SDR','NI_POWER','AC_PSM','NI_FRU','NI_ASSET']],
    'TIGH2U'  : ['0091','0.64',['STA16_916412.zip'],'flashupdt.TIGH2U.916412.cfg',['NI_FRUSDR','FRU','SDR','NI_POWER','AC_PSM','BMC_TAM','TAM_AAS','NI_FRU','NI_ASSET']],
    'NSN2U'   : ['0016','0.19',['R0016.zip','BMC_0019.zip'],'flashupdt.NSC2U.cfg',['NI_FRUSDR','FRU','SDR','NI_POWER','AC_PSM','NI_FRU','NI_ASSET']],
    'SR2500LX': ['0085','0.62',['S5000PAL_DOS_Update_Pkg_85_62_47.zip','SR2500_HSC205.zip'],'flashupdt.SR2500LX.cfg','MASTER.SR2500LX.AC.CFG'],
    'S3000'   : ['0046','1.5.0',['S3000AH_BIOS_Release_0046.zip'],'flashupdt.46.cfg','flash_150.bin']
}
chassisRestoreSpecs = {
    'TIGW1U'  : ['0084','0.17',['SHB18_841715.zip'],'flashupdt.TIGW1U.841715.cfg',['NI_FRUSDR','FRU','SDR','NI_POWER','AC_PSM','BMC_TAM','TAM_AAS','NI_FRU','NI_ASSET']],
    'NSW1U'   : ['0084','0.17',['SHB18_841715.zip'],'flashupdt.NSW1U.841715.cfg',['NI_FRUSDR','FRU','SDR','NI_POWER','AC_PSM','NI_FRU','NI_ASSET']],
#    'TIGW1U'  : ['0079','0.16',['SHB17_791612.zip'],'flashupdt.TIGW1U.restore.cfg','MASTER.TIGW1U.ACrestore.CFG'],
#    'NSW1U'   : ['0079','0.16',['SHB17_791612.zip'],'flashupdt.NSW1U.restore.cfg','MASTER.NSW1U.ACrestore.CFG'],
    'NSC2U'   : ['0084','0.62',['STA10_846211.zip'],'flashupdt.NSC2U.846211.cfg',['NI_FRUSDR','FRU','SDR','NI_POWER','AC_PSM','NI_FRU','NI_ASSET']],
    'TIGH2U'  : ['0084','0.62',['STA10_846211.zip'],'flashupdt.TIGH2U.846211.cfg',['NI_FRUSDR','FRU','SDR','NI_POWER','AC_PSM','BMC_TAM','TAM_AAS','NI_FRU','NI_ASSET']],
#    'NSC2U'   : ['0079','0.59',['STA08_795906.zip'],'flashupdt.NSC2U.restore.cfg','MASTER.NSC2U.ACrestore.CFG'],
#    'TIGH2U'  : ['0079','0.59',['STA08_795906.zip'],'flashupdt.TIGH2U.restore.cfg','MASTER.TIGH2U.AC.CFG'],
    'NSN2U'   : ['0014','0.17',['R0014.zip','BMC_0017.zip'],'flashupdt.NSC2U.cfg',['NI_FRUSDR','FRU','SDR','NI_POWER','AC_PSM','NI_FRU','NI_ASSET']],
    'SR2500LX': ['0079','0.59',['AL_06_25_2007.zip'],'flashupdt.SR2500LX.restore.cfg','MASTER.SR2500LX.AC.CFG'],
    'S3000'   : ['0042','1.3.11',['S3000AH_BIOS_R42.zip'],'flashupdt.42.cfg','TekoaE.bin']
}
