Example #1
0
def cli():
    while True:
        valid = 0

        signal.signal(signal.SIGINT, Exit_gracefully)
#        except EOFError:
#            bye()
        try:
            readline.parse_and_bind("tab: complete")
            readline.set_completer(complete)
            readline.set_completer_delims(' ')
            cli = str(raw_input(PROMPT))
        except EOFError:
            bye()
        if hist_toggle == 1:
            hfile.write(cli + '\n')
        if 'linode_token' in locals():
            #print("tool")
            pass
        else:
            linode_token = get_linode_key(config)    
            #print("tool")

#This is not just a horrible way to take the commands and arguements, it's also shitty way to sanatize the input for one specific scenario

#I miss perl :(


#Apparently argparse is the solution I'm looking for,I put a simple argparse example in TODO.md        
        cli = re.sub('  ',' ', cli.rstrip())
        if len(cli.split(' ')) ==2:
            command,arguement = cli.split()
            if command == "ip-list":
                api_key = get_linode_key(config)
                print(servers_action.ip_list(api_key,arguement))
                valid = 1
            if command == "linode-shutdown":
                api_key = get_linode_key(config)
                print(servers_action.linode_shutdown(api_key,arguement))
                valid = 1
            if command == "nodebal-node-list":
                api_key = get_linode_key(config)
                print(node_balance.nodebal_node_list(api_key,arguement))
                valid = 1
            if command == "nodebal-config-list":
                api_key = get_linode_key(config)
                print(node_balance.nodebal_config_list(api_key,arguement))
                valid = 1
            if command == "nodebal-create":
                api_key = get_linode_key(config)
                print(node_balance.nodebal_create(api_key,arguement))
                valid = 1

        if len(cli.split(' ')) ==3:
            command,arg_one,arg_two = cli.split()
            if command == "linode-create":
                api_key = get_linode_key(config)
                print(servers_action.linode_create(api_key,arg_one,arg_two))
                valid = 1
 

##########################################################################################
# This starts the single linosh commands
#######################################################################################


        if cli == "list-servers":
            api_key = get_linode_key(config)
            pprint(servers_action.list_servers(api_key))
            valid = 1
        if cli == "avail-datacenters":
            api_key = get_linode_key(config)
            pprint(lin_utility.avail_datacenters(api_key))
            valid = 1
        if cli == "avail-distributions":
            api_key = get_linode_key(config)
            pprint(lin_utility.avail_distributions(api_key))
            valid = 1
        if cli == "avail-stackscripts":
            api_key = get_linode_key(config)
            pprint(lin_utility.avail_stackscripts(api_key))
            valid = 1
        if cli == "avail-plans":
            api_key = get_linode_key(config)
            pprint(lin_utility.avail_plans(api_key))
            valid = 1
        if cli == "nodebal-list":
            api_key = get_linode_key(config)
            pprint(node_balance.nodebal_list(api_key))
            valid = 1
        if cli == "ip-list":
            api_key = get_linode_key(config)
            pprint(servers_action.ip_list(api_key))
            valid = 1 
        if cli == "quit" or cli == "exit":
            hfile.close()
            bye()
        if cli == "help":
            print(help_menu())
            valid = 1


        if valid == 0:
            print("Unrecoginized Command")
Example #2
0
        print(node_balance.nodebal_create(api_key, arguement))
        valid = 1
        bye()

 

if arg_count == 4:
    command = sys.argv[1]
    arg_one = sys.argv[2]
    arg_two = sys.argv[3]
    arg_three = sys.argv[4]
    arg_four = sys.argv[5]

    if command == "linode-create":
        api_key = get_linode_key(config)
        print(servers_action.linode_create(api_key, arg_one, arg_two))
        valid = 1
        bye()


 

if arg_count == 5:
    command = sys.argv[1]
    arg_one = sys.argv[2]
    arg_two = sys.argv[3]
    arg_three = sys.argv[4]
    arg_four = sys.argv[5]

if arg_count == 6:
    command = sys.argv[1]