mirror of
https://github.com/saltstack/salt.git
synced 2025-04-17 10:10:20 +00:00
Set up cli executor for salt command lin
This commit is contained in:
parent
08fbf0a0af
commit
cf8897e280
1 changed files with 54 additions and 0 deletions
54
salt/cli/__init__.py
Normal file
54
salt/cli/__init__.py
Normal 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'])
|
||||
|
Loading…
Add table
Reference in a new issue