当前位置: 首页>>代码示例>>Python>>正文


Python Validator.validateInput方法代码示例

本文整理汇总了Python中validator.Validator.validateInput方法的典型用法代码示例。如果您正苦于以下问题:Python Validator.validateInput方法的具体用法?Python Validator.validateInput怎么用?Python Validator.validateInput使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在validator.Validator的用法示例。


在下文中一共展示了Validator.validateInput方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_020_validate_input

# 需要导入模块: from validator import Validator [as 别名]
# 或者: from validator.Validator import validateInput [as 别名]
 def test_020_validate_input(self):
     v = Validator()
     good_line = ['localhost', '127.0.0.1', 'USER_NAME', 'USER_PASSWORD']
     bad_line = ['localhost', '127.0.0.1', 'USER_NAME1', 'USER_PASSWORD1']
     ret, msg = v.validateInput(good_line, ['localhost'])
     self.assertEqual(ret, True)
     ret, msg = v.validateInput(good_line, ['local'])
     self.assertEqual(ret, False)
     ret, msg = v.validateInput(bad_line, ['localhost'])
     self.assertEqual(ret, False)
开发者ID:FourtekIT-incubator,项目名称:openebs,代码行数:12,代码来源:test_validator.py

示例2: main

# 需要导入模块: from validator import Validator [as 别名]
# 或者: from validator.Validator import validateInput [as 别名]
def main():

    """Suppress warnings from deprecated functions (configparser compatibility
    for python 3)"""
    warnings.simplefilter("ignore", category=DeprecationWarning)
    warnings.filterwarnings("ignore")

    """Specify, parse & assign positional (compulsory) & optional arguments for
    the script"""
    arg_parser_description = 'Take the hostfile, logging level and SSH details'
    parser = argparse.ArgumentParser(description=arg_parser_description)

    parser_help_text = "Provide a hostfile in ip,username,password format"
    parser.add_argument("hostfile", help=parser_help_text)

    parser.add_argument("--loglevel", help="Provide a log level. Supported values: (Info,Debug);\
            Default is Info")

    parser.add_argument("--passwordless", help="Setup passwordless SSH with hosts.\
             Supported values: (True,False); Default is False")

    args = parser.parse_args()

    Hosts = args.hostfile

    # Specify SSH details
    key_rsa_path = '~/.ssh/id_rsa.pub'
    key_append_path = '~/.ssh/authorized_keys'
    key_gen_cmd = 'echo -e  "y\n"|ssh-keygen -q -t rsa -N "" -f ~/.ssh/id_rsa'

    # Create the configparser object
    config = configparser.ConfigParser()

    # Specify path for inventory
    current_path = os.path.dirname(os.path.realpath(sys.argv[0]))

    if "ansible/roles/inventory/files" in current_path:
        parent_dirname = os.path.dirname(os.path.dirname(current_path))
        ansible_path = os.path.dirname(parent_dirname)
        ansible_cfg_path = ansible_path + 'ansible.cfg'
        default_inventory_path = ansible_path + '/inventory/'
        try:
            config.read_file(open(ansible_cfg_path))
            inventory_path = ansible_path + config.get('defaults', 'inventory')
        except IOError:
            if os.path.isdir(default_inventory_path) is not True:
                os.makedirs(default_inventory_path)
            inventory_path = default_inventory_path + 'hosts'
    else:
        os.makedirs('inventory')
        default_inventory_path = current_path + '/inventory/'
        inventory_path = default_inventory_path + 'hosts'

    # Define logging levels for script execution
    logfile = '%s/host-status.log' % (default_inventory_path)

    if args.loglevel and args.loglevel.upper() == "DEBUG":
        logging.basicConfig(format='%(asctime)s %(levelname)s: %(message)s',
                            filename=logfile, filemode='a', level=10)
    else:
        logging.basicConfig(format='%(asctime)s %(levelname)s: %(message)s',
                            filename=logfile, filemode='a', level=20)

    # Initiate log file
    clearLogCmd = '> %s' % (logfile)
    executeCmd(clearLogCmd)

    # Initialize dictionary holding supported host codes
    SupportedHostCodes = {
            'localhost': None,
            'mayamaster': 'openebs-mayamasters',
            'mayahost': 'openebs-mayahosts',
            'kubemaster': 'kubernetes-kubemasters',
            'kubeminion': 'kubernetes-kubeminions'
            }

    """Create list of tuples containing individual machine info & initialize
    localhost password"""
    HostList = []
    local_password = None
    v = Validator()
    with open(Hosts, "rb") as fp:
        for i in fp.readlines():
            tmp = i.split(",")
            if tmp[0] != '\n' and "#" not in tmp[0]:
                ret, msg = v.validateInput(tmp, SupportedHostCodes)
                if not ret:
                    print msg
                    exit()

                if tmp[0] == "localhost":
                    local_password = tmp[3].rstrip('\n')
                try:
                    HostList.append((tmp[0], tmp[1],
                                     tmp[2], tmp[3].rstrip('\n')))
                except IndexError as e:
                    info_text = "Unable to parse input, failed with error %s"
                    logging.info(info_text, e)
                    exit()

#.........这里部分代码省略.........
开发者ID:FourtekIT-incubator,项目名称:openebs,代码行数:103,代码来源:generate_inventory.py


注:本文中的validator.Validator.validateInput方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。