色粉盒撒娇 发表于 2018-8-1 09:55:49

指定saltstack的任务id-fly天地

# 在parse_args方法返回前,调用这个方法  
if hasattr(options,'jid'):
  
   self._check_jid(options.jid)
  
return options, args
  

  
# 检查jid的合法性
  
def _check_jid(self,jid=''):
  
      try:
  
            if jid == '':
  
                pass
  
            elif len(jid) != 20:
  
                raise optparse.OptionValueError('jid needs 20 length and is numberic str,like "20140903143821048459"')
  
            else:
  
                import re
  
                if not re.match(r'\d{20}',jid):
  
                  raise optparse.OptionValueError('jid needs 20 length and is numberic str,like "20140903143821048459"')
  
      except optparse.OptionValueError,e:
  
            print(e)
  
            sys.exit(1)
页: [1]
查看完整版本: 指定saltstack的任务id-fly天地