示例#1
0
 def process_args(self):
     self.host = self.get_opt('host')
     self.port = self.get_opt('port')
     # pika library requires int type
     self.port = self.port
     self.user = self.get_opt('user')
     self.password = self.get_opt('password')
     validate_host(self.host)
     validate_port(self.port)
     self.port = int(self.port)
     validate_user(self.user)
     validate_password(self.password)
     self.vhost = self.get_opt('vhost')
     self.vhost = self.vhost if self.vhost else '/'
     validate_chars(self.vhost, 'vhost', r'/\w\._-')
     self.exchange = self.get_opt('exchange')
     if self.exchange:
         validate_chars(self.exchange, 'exchange', r'\w\._-')
     else:
         log_option('exchange', self.exchange)
     self.exchange_type = self.get_opt('exchange_type')
     if self.exchange_type:
         if self.exchange_type not in self.valid_exchange_types:
             self.usage('invalid --exchange-type given, expected one of: {valid_exchange_types}'\
                        .format(valid_exchange_types=', '.join(self.valid_exchange_types)))
     log_option('exchange type', self.exchange_type)
     self.queue = self.get_opt('queue')
     if self.queue:
         validate_chars(self.queue, 'queue', r'\w\._-')
     else:
         log_option('queue', self.queue)
     self.routing_key = self.get_opt('routing_key')
     if not self.routing_key:
         self.routing_key = self.queue
     log_option('routing key', self.routing_key)
     #self.no_ack = self.get_opt('no_ack')
     log_option('no ack', self.no_ack)
     self.connection_attempts = self.get_opt('connection_attempts')
     validate_int(self.connection_attempts,
                  'connection attempts',
                  min_value=1,
                  max_value=10)
     self.connection_attempts = int(self.connection_attempts)
     self.retry_delay = self.get_opt('retry_delay')
     validate_int(self.retry_delay,
                  'retry delay',
                  min_value=0,
                  max_value=10)
     self.retry_delay = int(self.retry_delay)
     self.use_transactions = self.get_opt('use_transactions')
     #self.durable = not self.get_opt('non_durable')
     if self.get_opt('non_durable'):
         self.durable = False
     log_option('non-durable', not self.durable)
     sleep_secs = self.get_opt('sleep')
     if sleep_secs:
         # validation done through property wrapper
         self.sleep_secs = sleep_secs
     log_option('sleep secs', self.sleep_secs)
     self.validate_thresholds()
示例#2
0
 def process_options(self):
     self.no_args()
     self.host = self.get_opt('host')
     self.port = self.get_opt('port')
     validate_host(self.host)
     validate_port(self.port)
     if self.auth:
         self.user = self.get_opt('user')
         self.password = self.get_opt('password')
         if self.auth == 'optional':
             if self.user and self.password:
                 validate_user(self.user)
                 validate_password(self.password)
         else:
             validate_user(self.user)
             validate_password(self.password)
     ssl = self.get_opt('ssl')
     log_option('ssl', ssl)
     if ssl and self.protocol == 'http':
         self.protocol = 'https'
     if self.json:
         # recommended for many systems like CouchDB
         # but breaks Ambari API calls
         #self.headers['Accept'] = 'application/json'
         self.headers['Content-Type'] = 'application/json'
示例#3
0
    def run(self):
        self.no_args()
        host = self.get_opt('host')
        port = self.get_opt('port')
        user = self.get_opt('user')
        password = self.get_opt('password')
        if self.get_opt('ssl'):
            self.protocol = 'https'
        history_mins = self.get_opt('history_mins')
        num = self.get_opt('num')
        #inventory_id = self.get_opt('id')
        source = self.get_opt('source')
        dest = self.get_opt('dest')
        max_age = self.get_opt('max_age')
        max_runtime = self.get_opt('max_runtime')
        validate_host(host)
        validate_port(port)
        validate_user(user)
        validate_password(password)
        validate_float(history_mins, 'history mins')
        self.history_mins = float(history_mins)
        filter_opts = {}
        if self.history_mins:
            now = datetime.now()
            filter_opts['dateRangeStart'] = datetime.strftime(now - timedelta(minutes=self.history_mins), '%F %H:%M:%S')
            filter_opts['dateRangeEnd'] = datetime.strftime(now, '%F %H:%M:%S')
        if num is not None:
            validate_int(num, 'num ingestions', 1)
        #if inventory_id is not None:
        #    validate_chars(inventory_id, 'ingestion id', r'\w-')
        #    filter_opts['inventoryId'] = inventory_id
        if source is not None:
            log_option('source', source)
            filter_opts['fileName'] = source
        if dest is not None:
            log_option('dest', dest)
            filter_opts['destinationPath'] = dest
        if max_age is not None:
            validate_float(max_age, 'max age', 1)
            max_age = float(max_age)
        if max_runtime is not None:
            validate_float(max_runtime, 'max incomplete runtime', 1)
            max_runtime = float(max_runtime)

        self.url_base = '{protocol}://{host}:{port}/bedrock-app/services/rest'.format(host=host,
                                                                                      port=port,
                                                                                      protocol=self.protocol)
        # auth first, get JSESSIONID cookie
        # cookie jar doesn't work in Python or curl, must extract JSESSIONID to header manually
        #self.jar = cookielib.CookieJar()
        log.info('authenticating to Zaloni Bedrock')
        (_, self.auth_time) = self.req(url='{url_base}/admin/getUserRole'.format(url_base=self.url_base),
                                       # using json instead of constructing string manually,
                                       # this correctly escapes backslashes in password
                                       body=json.dumps({"username": user, "password": password}))
        if self.get_opt('list'):
            self.list_ingestions(num=num)

        self.check_ingestion(num=num, filter_opts=filter_opts, max_age=max_age, max_runtime=max_runtime)
 def run(self):
     validate_host(self.host)
     validate_port(self.port)
     validate_user(self.user)
     validate_password(self.password)
     all_services = self.get_opt('all')
     services_str = self.get_opt('services')
     cancel = self.get_opt('cancel')
     if cancel and (all_services or services_str):
         self.usage(
             'cannot specify --cancel and --services/--all simultaneously' +
             ', --cancel will cancel all pending service checks')
     if all_services and services_str:
         self.usage(
             'cannot specify --all and --services simultaneously, they are mutually exclusive'
         )
     services_requested = []
     if services_str:
         services_requested = [
             service.strip().upper() for service in services_str.split(',')
         ]
     list_clusters = self.get_opt('list_clusters')
     list_services = self.get_opt('list_services')
     clusters = self.get_clusters()
     if list_clusters:
         if self.verbose > 0:
             print('Ambari Clusters:\n')
         print('\n'.join(clusters))
         sys.exit(3)
     if not self.cluster and len(clusters) == 1:
         self.cluster = clusters[0]
         log.info(
             'no --cluster specified, but only one cluster managed by Ambari'
             + ', inferring --cluster=\'%s\'', self.cluster)
     validate_chars(self.cluster, 'cluster', r'\w\s\.-')
     self.services = self.get_services()
     if list_services:
         if self.verbose > 0:
             print('Ambari Services:\n')
         print('\n'.join(self.services))
         sys.exit(3)
     if not services_requested and not all_services and not cancel:
         self.usage('no --services specified, nor was --all requested')
     services_to_check = []
     if all_services:
         services_to_check = self.services
     else:
         for service_requested in services_requested:
             if service_requested not in self.services:
                 die('service \'{0}\' is not in the list of available services in Ambari!'
                     .format(service_requested) +
                     ' Here is the list of services available:\n' +
                     '\n'.join(self.services))
         services_to_check = services_requested
     if cancel:
         self.cancel_service_checks()
     else:
         self.request_service_checks(services_to_check)
示例#5
0
 def process_options(self):
     self.no_args()
     self.host = self.get_opt('host')
     self.port = self.get_opt('port')
     self.user = self.get_opt('user')
     self.password = self.get_opt('password')
     validate_host(self.host)
     validate_port(self.port)
     validate_user(self.user)
     validate_password(self.password)
     self.process_expected_version_option()
 def process_args(self):
     self.host = self.get_opt('host')
     self.port = self.get_opt('port')
     # pika library requires int type
     self.port = self.port
     self.user = self.get_opt('user')
     self.password = self.get_opt('password')
     validate_host(self.host)
     validate_port(self.port)
     self.port = int(self.port)
     validate_user(self.user)
     validate_password(self.password)
     self.vhost = self.get_opt('vhost')
     self.vhost = self.vhost if self.vhost else '/'
     validate_chars(self.vhost, 'vhost', r'/\w\._-')
     self.exchange = self.get_opt('exchange')
     if self.exchange:
         validate_chars(self.exchange, 'exchange', r'\w\._-')
     else:
         log_option('exchange', self.exchange)
     self.exchange_type = self.get_opt('exchange_type')
     if self.exchange_type:
         if self.exchange_type not in self.valid_exchange_types:
             self.usage('invalid --exchange-type given, expected one of: {valid_exchange_types}'\
                        .format(valid_exchange_types=', '.join(self.valid_exchange_types)))
     log_option('exchange type', self.exchange_type)
     self.queue = self.get_opt('queue')
     if self.queue:
         validate_chars(self.queue, 'queue', r'\w\._-')
     else:
         log_option('queue', self.queue)
     self.routing_key = self.get_opt('routing_key')
     if not self.routing_key:
         self.routing_key = self.queue
     log_option('routing key', self.routing_key)
     #self.no_ack = self.get_opt('no_ack')
     log_option('no ack', self.no_ack)
     self.connection_attempts = self.get_opt('connection_attempts')
     validate_int(self.connection_attempts, 'connection attempts', min_value=1, max_value=10)
     self.connection_attempts = int(self.connection_attempts)
     self.retry_delay = self.get_opt('retry_delay')
     validate_int(self.retry_delay, 'retry delay', min_value=0, max_value=10)
     self.retry_delay = int(self.retry_delay)
     self.use_transactions = self.get_opt('use_transactions')
     #self.durable = not self.get_opt('non_durable')
     if self.get_opt('non_durable'):
         self.durable = False
     log_option('non-durable', not self.durable)
     sleep_secs = self.get_opt('sleep')
     if sleep_secs:
         # validation done through property wrapper
         self.sleep_secs = sleep_secs
     log_option('sleep secs', self.sleep_secs)
     self.validate_thresholds()
 def process_options(self):
     super(PostgreSQLCLI, self).process_options()
     self.host = self.get_opt('host')
     self.host = self.get_opt('host')
     self.user = self.get_opt('user')
     self.password = self.get_opt('password')
     validate_host(self.host)
     validate_port(self.port)
     validate_user(self.user)
     validate_password(self.password)
     self.port = int(self.port)
    def run(self):
        self.no_args()
        host = self.get_opt('host')
        port = self.get_opt('port')
        user = self.get_opt('user')
        password = self.get_opt('password')
        workflow_id = self.get_opt('id')
        workflow_name = self.get_opt('name')
        max_age = self.get_opt('max_age')
        max_runtime = self.get_opt('max_runtime')
        if self.get_opt('ssl'):
            self.protocol = 'https'
        validate_host(host)
        validate_port(port)
        validate_user(user)
        validate_password(password)
        if workflow_id is not None:
            if workflow_name is not None:
                self.usage('cannot specify both --id and --name simultaneously')
            validate_int(workflow_id, 'workflow id', 1)
        elif workflow_name is not None:
            validate_chars(workflow_name, 'workflow name', r'\w-')
        elif self.get_opt('list'):
            pass
        else:
            self.usage('must specify either --name or --id or use --list to find them')
        if max_age is not None:
            validate_float(max_age, 'max age', 1)
            max_age = float(max_age)
        if max_runtime is not None:
            validate_float(max_runtime, 'max runtime', 1)
            max_runtime = float(max_runtime)

        self.url_base = '{protocol}://{host}:{port}/bedrock-app/services/rest'.format(host=host, port=port,
                                                                                      protocol=self.protocol)
        # auth first, get JSESSIONID cookie
        # cookie jar doesn't work in Python or curl, must extract JSESSIONID to header manually
        #self.jar = cookielib.CookieJar()
        log.info('authenticating to Zaloni Bedrock')
        (_, self.auth_time) = self.req(url='{url_base}/admin/getUserRole'.format(url_base=self.url_base),
                                       # using json instead of constructing string manually,
                                       # this correctly escapes backslashes in password
                                       body=json.dumps({"username": user, "password": password}))
        # alternative method
        #session = requests.Session()
        #req = self.req(session,
        #               url='http://%(host)s:%(port)s/bedrock-app/services/rest/%(user)s/getUserRole' % locals(),
        #               method='POST')

        if self.get_opt('list'):
            self.list_workflows()

        self.check_workflow(workflow_name, workflow_id, max_age, max_runtime)
 def run(self):
     validate_host(self.host)
     validate_port(self.port)
     validate_user(self.user)
     validate_password(self.password)
     all_services = self.get_opt('all')
     services_str = self.get_opt('services')
     cancel = self.get_opt('cancel')
     if cancel and (all_services or services_str):
         self.usage('cannot specify --cancel and --services/--all simultaneously' +
                    ', --cancel will cancel all pending service checks')
     if all_services and services_str:
         self.usage('cannot specify --all and --services simultaneously, they are mutually exclusive')
     services_requested = []
     if services_str:
         services_requested = [service.strip().upper() for service in services_str.split(',')]
     list_clusters = self.get_opt('list_clusters')
     list_services = self.get_opt('list_services')
     clusters = self.get_clusters()
     if list_clusters:
         if self.verbose > 0:
             print('Ambari Clusters:\n')
         print('\n'.join(clusters))
         sys.exit(3)
     if not self.cluster and len(clusters) == 1:
         self.cluster = clusters[0]
         log.info('no --cluster specified, but only one cluster managed by Ambari' +
                  ', inferring --cluster=\'%s\'', self.cluster)
     validate_chars(self.cluster, 'cluster', r'\w\s\.-')
     self.services = self.get_services()
     if list_services:
         if self.verbose > 0:
             print('Ambari Services:\n')
         print('\n'.join(self.services))
         sys.exit(3)
     if not services_requested and not all_services and not cancel:
         self.usage('no --services specified, nor was --all requested')
     services_to_check = []
     if all_services:
         services_to_check = self.services
     else:
         for service_requested in services_requested:
             if service_requested not in self.services:
                 die('service \'{0}\' is not in the list of available services in Ambari!'.format(service_requested)
                     + ' Here is the list of services available:\n' + '\n'.join(self.services))
         services_to_check = services_requested
     if cancel:
         self.cancel_service_checks()
     else:
         self.request_service_checks(services_to_check)
示例#10
0
 def process_options(self):
     self.host = self.get_opt("host")
     self.port = self.get_opt("port")
     self.user = self.get_opt("user")
     self.password = self.get_opt("password")
     validate_host(self.host)
     validate_port(self.port)
     validate_user(self.user)
     validate_password(self.password)
     ssl = self.get_opt("ssl")
     log_option("ssl", ssl)
     if ssl:
         self.protocol = "https"
     self.validate_thresholds(simple="lower", optional=True)
 def process_options(self):
     self.host = self.get_opt('host')
     self.port = self.get_opt('port')
     self.user = self.get_opt('user')
     self.password = self.get_opt('password')
     validate_host(self.host)
     validate_port(self.port)
     validate_user(self.user)
     validate_password(self.password)
     ssl = self.get_opt('ssl')
     log_option('ssl', ssl)
     if ssl:
         self.protocol = 'https'
     self.validate_thresholds(simple='lower', optional=True)
示例#12
0
 def process_options(self):
     self.no_args()
     self.host = self.get_opt('host')
     self.port = self.get_opt('port')
     self.user = self.get_opt('user')
     self.password = self.get_opt('password')
     validate_host(self.host)
     validate_user(self.user)
     validate_password(self.password)
     validate_port(self.port)
     use_ssl = self.get_opt('use_ssl')
     log_option('ssl', use_ssl)
     if use_ssl and self.protocol == 'http':
         self.protocol = 'https'
 def process_options(self):
     self.no_args()
     self.host = self.get_opt('host')
     self.port = self.get_opt('port')
     self.user = self.get_opt('user')
     self.password = self.get_opt('password')
     self._all = self.get_opt('all')
     self.workflow_id = self.get_opt('id')
     self.workflow_name = self.get_opt('name')
     self.max_age = self.get_opt('max_age')
     self.max_runtime = self.get_opt('max_runtime')
     self.min_runtime = self.get_opt('min_runtime')
     if self.get_opt('ssl'):
         self.protocol = 'https'
     validate_host(self.host)
     validate_port(self.port)
     validate_user(self.user)
     validate_password(self.password)
     if self._all and (self.workflow_name is not None
                       or self.workflow_id is not None):
         self.usage(
             'cannot specify both --all and --name/--id simultaneously')
     if self.workflow_id is not None:
         if self.workflow_name is not None:
             self.usage(
                 'cannot specify both --id and --name simultaneously')
         validate_int(self.workflow_id, 'workflow id', 1)
         self.workflow_id = int(self.workflow_id)
     elif self.workflow_name is not None:
         validate_chars(self.workflow_name, 'workflow name', r'\w\s-')
     elif self._all:
         pass
     elif self.get_opt('list'):
         pass
     else:
         self.usage(
             'must specify one of --name / --id / --all or use --list to find workflow names/IDs to specify'
         )
     if self.max_age is not None:
         validate_float(self.max_age, 'max age', 1)
         self.max_age = float(self.max_age)
     if self.max_runtime is not None:
         validate_float(self.max_runtime, 'max runtime', 1)
         self.max_runtime = float(self.max_runtime)
     if self.min_runtime is not None:
         validate_float(self.min_runtime, 'min runtime', 0)
         self.min_runtime = float(self.min_runtime)
         if self.max_runtime is not None and self.min_runtime > self.max_runtime:
             self.usage(
                 '--min-runtime cannot be greater than --max-runtime!')
 def process_options(self):
     self.host = self.get_opt('host')
     self.port = self.get_opt('port')
     self.user = self.get_opt('user')
     self.password = self.get_opt('password')
     validate_host(self.host)
     validate_port(self.port)
     validate_user(self.user)
     validate_password(self.password)
     ssl = self.get_opt('ssl')
     log_option('ssl', ssl)
     if ssl:
         self.protocol = 'https'
     self.validate_thresholds(simple='lower', optional=True)
示例#15
0
 def process_options(self):
     self.no_args()
     self.host = self.get_opt('host')
     self.port = self.get_opt('port')
     validate_host(self.host)
     validate_port(self.port)
     if self.auth:
         self.user = self.get_opt('user')
         self.password = self.get_opt('password')
         validate_user(self.user)
         validate_password(self.password)
     ssl = self.get_opt('ssl')
     log_option('ssl', ssl)
     if ssl and self.protocol == 'http':
         self.protocol = 'https'
 def process_options(self):
     self.no_args()
     self.host = self.get_opt('host')
     self.port = self.get_opt('port')
     self.user = self.get_opt('user')
     self.password = self.get_opt('password')
     validate_host(self.host)
     validate_port(self.port)
     validate_user(self.user)
     validate_password(self.password)
     ssl = self.get_opt('ssl')
     log_option('ssl', ssl)
     if ssl:
         self.protocol = 'https'
     self.process_expected_version_option()
 def process_options(self):
     self.no_args()
     self.host = self.get_opt('host')
     self.port = self.get_opt('port')
     self.user = self.get_opt('user')
     self.password = self.get_opt('password')
     validate_host(self.host)
     validate_port(self.port)
     validate_user(self.user)
     validate_password(self.password)
     ssl = self.get_opt('ssl')
     log_option('ssl', ssl)
     if ssl:
         self.protocol = 'https'
     self.process_expected_version_option()
示例#18
0
    def process_args(self):
        options, args = self.options, self.args

        log.setLevel(logging.WARN)
        if options.verbose > 1:
            log.setLevel(logging.DEBUG)
        elif options.verbose:
            log.setLevel(logging.INFO)
        # log.info('verbose level: %s' % options.verbose)

        try:
            validate_host(options.host)
            validate_port(options.port)
            validate_user(options.user)
            validate_password(options.password)
            if options.dir:
                validate_dirname(options.dir, 'blueprints')
            if options.file:
                if options.push:
                    validate_file(options.file, 'blueprint')
                if options.create_cluster:
                    validate_file(options.file, 'cluster hosts mapping')
        except InvalidOptionException as _:
            self.usage(_)

        if self.args:
            self.usage('additional args detected')

        if options.get and options.blueprint and options.cluster:
            self.usage(
                '--blueprint/--cluster are mutually exclusive when using --get'
            )
        elif options.push and options.create_cluster:
            self.usage('--push and --create-cluster are mutually exclusive')
        elif options.create_cluster and not options.cluster:
            self.usage(
                '--create-cluster requires specifying the name via --cluster')
        elif options.list_blueprints + options.list_clusters + options.list_hosts > 1:
            self.usage('can only use one --list switch at a time')
        elif options.file and (options.get
                               and not (options.blueprint or options.cluster)):
            self.usage("cannot specify --file without --blueprint/--cluster as it's only used " + \
                       "when getting or pushing a single blueprint")
        elif options.file and (options.push and not (options.create_cluster
                                                     or options.blueprint)):
            self.usage("cannot specify --file without --blueprint/--create-cluster as it's only used " + \
                       "when getting or pushing a single blueprint or creating a cluster based on the blueprint")
        return options, args
示例#19
0
 def process_options(self):
     host = self.get_opt('host')
     port = self.get_opt('port')
     self.user = self.get_opt('user')
     self.password = self.get_opt('password')
     validate_host(host)
     validate_port(port)
     if self.user is not None:
         validate_user(self.user)
     if self.password is not None:
         validate_password(self.password)
     if self.get_opt('ssl'):
         log_option('ssl', 'True')
         self.protocol = 'https'
     self.url_base = '{protocol}://{host}:{port}/v2'.format(
         protocol=self.protocol, host=host, port=port)
示例#20
0
 def process_options(self):
     self.no_args()
     self.host = self.get_opt('host')
     self.port = self.get_opt('port')
     validate_host(self.host)
     validate_port(self.port)
     if self.auth and self.get_opt('kerberos'):
         self.auth = 'kerberos'
     if self.auth:
         self.user = self.get_opt('user')
         self.password = self.get_opt('password')
         if self.auth == 'optional':
             if self.user and self.password:
                 validate_user(self.user)
                 validate_password(self.password)
         elif self.auth == 'kerberos':
             if os.getenv('KRB5_CLIENT_KTNAME'):
                 log.debug('kerberos enabled, will try to use keytab at %s',
                           os.getenv('KRB5_CLIENT_KTNAME'))
                 # if using KRB5_CLIENT_KTNAME to kinit avoid clobbering the same TGT cache /tmp/krb5cc_{uid}
                 # as that may be used by different programs kinit'd different keytabs
                 os.environ[
                     'KRB5CCNAME'] = '/tmp/krb5cc_{euid}_{basename}'.format(
                         euid=os.geteuid(), basename=prog)
         else:
             validate_user(self.user)
             validate_password(self.password)
     ssl_noverify = self.get_opt('ssl_noverify')
     if ssl_noverify:
         log_option('ssl no verify', 'true')
         ssl = 1
         os.environ['SSL_NO_VERIFY'] = '1'
         # doesn't work, probably too late after instantiation
         #if not os.getenv('PYTHONWARNINGS'):
         #    os.environ['PYTHONWARNINGS'] = 'ignore:Unverified HTTPS request'
         urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)
     else:
         ssl = self.get_opt('ssl')
         log_option('ssl', ssl)
     if ssl and self.protocol == 'http':
         self.protocol = 'https'
     if self.json:
         # recommended for many systems like CouchDB
         # but breaks Ambari API calls
         #self.headers['Accept'] = 'application/json'
         self.headers['Content-Type'] = 'application/json'
 def process_options(self):
     self.no_args()
     self.host = self.get_opt('host')
     self.port = self.get_opt('port')
     self.user = self.get_opt('user')
     self.password = self.get_opt('password')
     self._all = self.get_opt('all')
     self.workflow_id = self.get_opt('id')
     self.workflow_name = self.get_opt('name')
     self.max_age = self.get_opt('max_age')
     self.max_runtime = self.get_opt('max_runtime')
     self.min_runtime = self.get_opt('min_runtime')
     if self.get_opt('ssl'):
         self.protocol = 'https'
     validate_host(self.host)
     validate_port(self.port)
     validate_user(self.user)
     validate_password(self.password)
     if self._all and (self.workflow_name is not None or self.workflow_id is not None):
         self.usage('cannot specify both --all and --name/--id simultaneously')
     if self.workflow_id is not None:
         if self.workflow_name is not None:
             self.usage('cannot specify both --id and --name simultaneously')
         validate_int(self.workflow_id, 'workflow id', 1)
         self.workflow_id = int(self.workflow_id)
     elif self.workflow_name is not None:
         validate_chars(self.workflow_name, 'workflow name', r'\w\s-')
     elif self._all:
         pass
     elif self.get_opt('list'):
         pass
     else:
         self.usage('must specify one of --name / --id / --all or use --list to find workflow names/IDs to specify')
     if self.max_age is not None:
         validate_float(self.max_age, 'max age', 1)
         self.max_age = float(self.max_age)
     if self.max_runtime is not None:
         validate_float(self.max_runtime, 'max runtime', 1)
         self.max_runtime = float(self.max_runtime)
     if self.min_runtime is not None:
         validate_float(self.min_runtime, 'min runtime', 0)
         self.min_runtime = float(self.min_runtime)
         if self.max_runtime is not None and self.min_runtime > self.max_runtime:
             self.usage('--min-runtime cannot be greater than --max-runtime!')
示例#22
0
    def process_args(self):
        options, args = self.options, self.args

        log.setLevel(logging.WARN)
        if options.verbose > 1:
            log.setLevel(logging.DEBUG)
        elif options.verbose:
            log.setLevel(logging.INFO)
        # log.info('verbose level: %s' % options.verbose)

        try:
            validate_host(options.host)
            validate_port(options.port)
            validate_user(options.user)
            validate_password(options.password)
            if options.dir:
                validate_dirname(options.dir, 'blueprints')
            if options.file:
                if options.push:
                    validate_file(options.file, 'blueprint')
                if options.create_cluster:
                    validate_file(options.file, 'cluster hosts mapping')
        except InvalidOptionException as _:
            self.usage(_)

        if self.args:
            self.usage('additional args detected')

        if options.get and options.blueprint and options.cluster:
            self.usage('--blueprint/--cluster are mutually exclusive when using --get')
        elif options.push and options.create_cluster:
            self.usage('--push and --create-cluster are mutually exclusive')
        elif options.create_cluster and not options.cluster:
            self.usage('--create-cluster requires specifying the name via --cluster')
        elif options.list_blueprints + options.list_clusters + options.list_hosts > 1:
            self.usage('can only use one --list switch at a time')
        elif options.file and (options.get and not (options.blueprint or options.cluster)):
            self.usage("cannot specify --file without --blueprint/--cluster as it's only used " + \
                       "when getting or pushing a single blueprint")
        elif options.file and (options.push and not (options.create_cluster or options.blueprint)):
            self.usage("cannot specify --file without --blueprint/--create-cluster as it's only used " + \
                       "when getting or pushing a single blueprint or creating a cluster based on the blueprint")
        return options, args
    def run(self):
        self.no_args()
        host = self.get_opt('host')
        port = self.get_opt('port')
        user = self.get_opt('user')
        password = self.get_opt('password')
        self._all = self.get_opt('all')
        workflow_id = self.get_opt('id')
        workflow_name = self.get_opt('name')
        max_age = self.get_opt('max_age')
        max_runtime = self.get_opt('max_runtime')
        if self.get_opt('ssl'):
            self.protocol = 'https'
        validate_host(host)
        validate_port(port)
        validate_user(user)
        validate_password(password)
        if workflow_id is not None:
            if workflow_name is not None:
                self.usage(
                    'cannot specify both --id and --name simultaneously')
            validate_int(workflow_id, 'workflow id', 1)
            workflow_id = int(workflow_id)
        elif workflow_name is not None:
            validate_chars(workflow_name, 'workflow name', r'\w\s-')
        elif self.get_opt('list'):
            pass
        else:
            self.usage(
                'must specify one of --name / --id / --all or use --list to find workflow names/IDs to specify'
            )
        if max_age is not None:
            validate_float(max_age, 'max age', 1)
            max_age = float(max_age)
        if max_runtime is not None:
            validate_float(max_runtime, 'max runtime', 1)
            max_runtime = float(max_runtime)

        self.url_base = '{protocol}://{host}:{port}/bedrock-app/services/rest'.format(
            host=host, port=port, protocol=self.protocol)
        # auth first, get JSESSIONID cookie
        # cookie jar doesn't work in Python or curl, must extract JSESSIONID to header manually
        #self.jar = cookielib.CookieJar()
        log.info('authenticating to Zaloni Bedrock')
        (_, self.auth_time) = self.req(
            url='{url_base}/admin/getUserRole'.format(url_base=self.url_base),
            # using json instead of constructing string manually,
            # this correctly escapes backslashes in password
            body=json.dumps({
                "username": user,
                "password": password
            }))
        # alternative method
        #session = requests.Session()
        #req = self.req(session,
        #               url='http://%(host)s:%(port)s/bedrock-app/services/rest/%(user)s/getUserRole' % locals(),
        #               method='POST')

        if self.get_opt('list'):
            self.list_workflows()

        if self._all:
            workflows = self.get_workflows()
            if not workflows or len(workflows) == 0:
                qquit('UNKNOWN', 'no workflows found')
            results = {}
            try:
                for workflow in workflows:
                    result = self.check_workflow(workflow['wfName'], None)
                    if result is None:
                        results['No Runs'] = results.get('None', 0)
                        results['No Runs'] += 1
                        continue
                    results[result] = results.get(result, 0)
                    results[result] += 1
                self.msg = 'Zaloni workflows: '
                for result in results:
                    self.msg += "'{0}' = {1}, ".format(result, results[result])
                self.msg = self.msg.rstrip(', ')
            except KeyError as _:
                qquit(
                    'UNKNOWN',
                    'parsing workflows for --all failed: {0}. '.format(_) +
                    support_msg_api())
        else:
            self.check_workflow(workflow_name, workflow_id, max_age,
                                max_runtime)