From 394aee2f2bcebad937ea5c9219a21f0c93d4b17c Mon Sep 17 00:00:00 2001 From: Uggla Date: Fri, 25 Sep 2015 23:47:50 +0200 Subject: [PATCH] Initial commit of redfish-client. --- redfish-client/redfish-client.py | 73 ++++++++++++++++++++++++++++++++ 1 file changed, 73 insertions(+) create mode 100644 redfish-client/redfish-client.py diff --git a/redfish-client/redfish-client.py b/redfish-client/redfish-client.py new file mode 100644 index 0000000..a6f9398 --- /dev/null +++ b/redfish-client/redfish-client.py @@ -0,0 +1,73 @@ +# coding=utf-8 + +""" +redfish-client + +Usage: + redfish-client.py [options] config add [] [] + redfish-client.py [options] config del + redfish-client.py [options] config modify (url | login | password) + redfish-client.py [options] config show + redfish-client.py [options] config showall + redfish-client.py (-h | --help) + redfish-client.py --version + + +Options: + -h --help Show this screen. + --version Show version. + --conf_file FILE Configuration file [default: ~/.redfish.conf]. + + +config commands manage the configuration file. + +""" + +import os +import sys +import json +import pprint +import docopt + + +class ConfigFile(object): + def __init__(self, config_file): + # read json file + try: + with open(config_file) as json_data: + self.data = json.load(json_data) + json_data.close() + except IOError as e: + self.data = {"Nodes":{}} + + + +if __name__ == '__main__': + # Get $HOME environment. + HOME = os.getenv('HOME') + + if HOME == '': + print("$HOME environment variable not set, please check your system") + sys.exit(1) + + arguments = docopt.docopt(__doc__, version='redfish-client 0.1') + print(arguments) + + arguments['--conf_file'] = arguments['--conf_file'].replace('~', HOME) + + conf_file = ConfigFile(arguments['--conf_file']) + + + if arguments['config'] == True: + if arguments['showall'] == True: + pprint.pprint(conf_file.data) + elif arguments['add'] == True: + conf_file.data['Nodes'][arguments['']] = {} + conf_file.data['Nodes'][arguments['']]['url'] = arguments[''] + if arguments[''] != None: + conf_file.data['Nodes'][arguments['']]['login'] = arguments[''] + if arguments[''] != None: + conf_file.data['Nodes'][arguments['']]['password'] = arguments[''] + pprint.pprint(conf_file.data) + + \ No newline at end of file