Set up cli executor for salt command lin

This commit is contained in:
Thomas S Hatch 2011-03-09 10:48:35 -07:00
parent 08fbf0a0af
commit cf8897e280

54
salt/cli/__init__.py Normal file
View file

@ -0,0 +1,54 @@
'''
The management of salt command line utilities are stored in here
'''
# Import python libs
import optparse
import os
import sys
# Import salt components
import salt.client
class SaltCMD(object):
'''
The execution of a salt command happens here
'''
def __init__(self):
'''
Cretae a SaltCMD object
'''
self.opts = self.__parse()
def __parse(self):
'''
Parse the command line
'''
parser = optparse.OptionParser()
parser.add_option('-t',
'--timeout',
default=5,
dest='timeout',
help='Set the return timeout for batch jobs')
options, args = parser.parse_args()
opts = {}
opts['timeout'] = options.timeout
opts['tgt'] = args[1]
opts['fun'] = args[2]
opts['arg'] = args[3:]
return opts
def run(self):
'''
Execute the salt command line
'''
local = salt.client.LocalClient()
print local.cmd(self.opts['tgt'],
self.opts['fun'],
self.opts['arg'],
self.opts['timeout'])