示例#1
0
    def run(self, args):

        # parse arguments and form connection 
        parser = common.get_parser()
        parser.add_option('-t', '--template', dest='template', 
            default=None, type='int')
        (options, args) = parser.parse_args()
        if options.template is None:
            raise common.BaseException("--template is required")

        # test API connection
        handle = common.connect(options)

        # get the job template
        jt_url = "/api/v1/job_templates/%d/" % options.template
        data = handle.get(jt_url)
        id = data.pop('id')

        # add some more info needed to start the job
        # NOTE: a URL to launch job templates directly
        # may be added later, but this is basically a copy of the job template
        # data to the jobs resource, which is also fine.

        now = str(datetime.datetime.now())
        data.update(dict(
            name = 'cli job invocation started at %s' % now,
            verbosity = 0,
        ))

        # post a new job

        jt_jobs_url = "%sjobs/" % jt_url
        job_result = handle.post(jt_jobs_url, data)

        # get the parameters needed to start the job (if any)
        # prompt for values unless given on command line (FIXME)

        print "URL=%s" % jt_jobs_url

        job_id = job_result['id']
        job_start_url = "/api/v1/jobs/%d/start/" % job_id
        job_start_info = handle.get(job_start_url)
        start_data = {}
        for password in job_start_info.get('passwords_needed_to_start', []):
            value = getpass.getpass('%s: ' % password)
            start_data[password] = value

        # start the job 
        job_start_result = handle.post(job_start_url, start_data)
        print common.dump(job_start_result) 

        # TODO: optional status polling (FIXME)

        return 0
示例#2
0
    def run(self, args):

        # parse arguments and form connection
        parser = common.get_parser()
        parser.add_option("-t", "--template", dest="template", default=None, type="int")
        (options, args) = parser.parse_args()
        if options.template is None:
            raise common.BaseException("--template is required")

        # test API connection
        handle = common.connect(options)

        # get the job template
        jt_url = "/api/v1/job_templates/%d/" % options.template
        data = handle.get(jt_url)
        id = data.pop("id")

        # add some more info needed to start the job
        # NOTE: a URL to launch job templates directly
        # may be added later, but this is basically a copy of the job template
        # data to the jobs resource, which is also fine.

        now = str(datetime.datetime.now())
        data.update(dict(name="cli job invocation started at %s" % now, verbosity=0))

        # post a new job

        jt_jobs_url = "%sjobs/" % jt_url
        job_result = handle.post(jt_jobs_url, data)

        # get the parameters needed to start the job (if any)
        # prompt for values unless given on command line (FIXME)

        print "URL=%s" % jt_jobs_url

        job_id = job_result["id"]
        job_start_url = "/api/v1/jobs/%d/start/" % job_id
        job_start_info = handle.get(job_start_url)
        start_data = {}
        for password in job_start_info.get("passwords_needed_to_start", []):
            value = getpass.getpass("%s: " % password)
            start_data[password] = value

        # start the job
        job_start_result = handle.post(job_start_url, start_data)
        print common.dump(job_start_result)

        # TODO: optional status polling (FIXME)

        return 0
示例#3
0
    def run(self, args):

        parser = common.get_parser()
        # parser.add_option('-f', '--foo', dest='foo', default=None, type='str')

        (options, args) = parser.parse_args()
        handle = common.connect(options)

        data = handle.get('/api/v1/config/')

        output = dict(cli_version=awx_cli.__version__,
                      server_version=data['version'])
        print common.dump(output)

        return 0
示例#4
0
    def run(self, args):
 
        parser = common.get_parser()
        # parser.add_option('-f', '--foo', dest='foo', default=None, type='str')

        (options, args) = parser.parse_args()
        handle = common.connect(options)
 
        data = handle.get('/api/v1/config/')

        output = dict(
           cli_version = awx_cli.__version__,
           server_version = data['version']
        )
        print common.dump(output)

        return 0