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


Python ApiResource.echo方法代码示例

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


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

示例1: main

# 需要导入模块: from cm_api.api_client import ApiResource [as 别名]
# 或者: from cm_api.api_client.ApiResource import echo [as 别名]
def main():
    parser = argparse.ArgumentParser(description='Cloudera Manager Shell')
    parser.add_argument('-H', '--host', '--hostname', action='store', dest='hostname', required=True)
    parser.add_argument('-p', '--port', action='store', dest='port', type=int, default=7180)
    parser.add_argument('-u', '--user', '--username',  action='store', dest='username')
    parser.add_argument('-c', '--cluster', action='store', dest='cluster')
    parser.add_argument('--password', action='store', dest='password')
    parser.add_argument('-e', '--execute', action='store', dest='execute')
    parser.add_argument('-s', '--seperator', action='store', dest='seperator')
    parser.add_argument('-t', '--tls', action='store_const', dest='use_tls', const=True, default=False)
    args = parser.parse_args()

    # Check if a username was suplied, if not, prompt the user
    if not args.username:
        args.username = raw_input("Enter Username: ")

    # Check if the password was supplied, if not, prompt the user
    if not args.password:
        args.password = getpass.getpass("Enter Password: ")

    # Attempt to authenticate using the API
    global api
    api = ApiResource(args.hostname, args.port, args.username, args.password, args.use_tls)
    try:
        api.echo("ping")
    except ApiException:
        try:
            api = ApiResource(args.hostname, args.port, args.username, args.password, args.use_tls, version=1)
            api.echo("ping")
        except ApiException:
            print("Unable to Authenticate")
            sys.exit(1)
    except URLError:
        print("Error: Could not connect to %s" % (args.hostname))
        sys.exit(1)

    CONFIG['cluster'] = args.cluster

    # Check if a custom seperator was supplied for the output
    if args.seperator:
        CONFIG['output_type'] = 'custom'
        CONFIG['seperator'] = args.seperator

    # Check if user is attempting non-interactive shell
    if args.execute:
        EXECUTE = True
        shell = ClouderaShell()
        for command in args.execute.split(';'):
            shell.onecmd(command)
        sys.exit(0)

    try:
        ClouderaShell().cmdloop()
    except KeyboardInterrupt:
        sys.stdout.write("\n")
        sys.exit(0)
开发者ID:MrTomerLevi,项目名称:cm_api,代码行数:58,代码来源:cmps.py

示例2: cm_api_resource

# 需要导入模块: from cm_api.api_client import ApiResource [as 别名]
# 或者: from cm_api.api_client.ApiResource import echo [as 别名]
 def cm_api_resource(self):
     ar = None
     try:
         ar = ApiResource(self.cm_host, self.cm_port,
                          self.cm_username, self.cm_password)
         ar.echo('Authenticated')  # Issue a sample request to test the conn
     except ApiException, aexc:
         if aexc.code == 401:
             log.debug("Changing default API username to {0}".format(self.cm_username))
             self.cm_username = self.host_username
             self.cm_password = self.host_password
             ar = ApiResource(self.cm_host, self.cm_port,
                              self.cm_username, self.cm_password)
         else:
             log.error("Api Exception connecting to ClouderaManager: {0}".format(aexc))
开发者ID:kaktus42,项目名称:cloudman,代码行数:17,代码来源:clouderamanager.py


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