Ejemplo n.º 1
0
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: "******"Enter Password: "******"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)
Ejemplo n.º 2
0
 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))
Ejemplo n.º 3
0
 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))
Ejemplo n.º 4
0
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: "******"Enter Password: "******"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)