Add create and status functions
This commit is contained in:
parent
41766febe6
commit
aa2bb7c94c
|
@ -583,15 +583,46 @@ def profile_remove(config, name):
|
|||
|
||||
return retvalue, response.json()['message']
|
||||
|
||||
def profile_info(config, profile):
|
||||
def vm_create(config, name, profile):
|
||||
"""
|
||||
Get information about profile
|
||||
Create a new VM named {name} with profile {profile}
|
||||
|
||||
API endpoint: GET /api/v1/provisioner/profile/{profile}
|
||||
API endpoint: POST /api/v1/provisioner/create
|
||||
API_arguments: name={name}, profile={profile}
|
||||
API schema: {message}
|
||||
"""
|
||||
request_uri = get_request_uri(config, '/provisioner/create')
|
||||
response = requests.post(
|
||||
request_uri,
|
||||
params={
|
||||
'name': name,
|
||||
'profile': profile
|
||||
}
|
||||
)
|
||||
|
||||
if config['debug']:
|
||||
print('API endpoint: POST {}'.format(request_uri))
|
||||
print('Response code: {}'.format(response.status_code))
|
||||
print('Response headers: {}'.format(response.headers))
|
||||
|
||||
if response.status_code == 202:
|
||||
retvalue = True
|
||||
retdata = 'Task ID: {}'.format(response.json()['task_id'])
|
||||
else:
|
||||
retvalue = False
|
||||
retdata = response.json()['message']
|
||||
|
||||
return retvalue, retdata
|
||||
|
||||
def task_status(config, task_id):
|
||||
"""
|
||||
Get information about provisioner job {task_id}
|
||||
|
||||
API endpoint: GET /api/v1/provisioner/status
|
||||
API arguments:
|
||||
API schema: {json_data_object}
|
||||
"""
|
||||
request_uri = get_request_uri(config, '/provisioner/profile/{profile}'.format(profile=profile))
|
||||
request_uri = get_request_uri(config, '/provisioner/status/{task_id}'.format(task_id=task_id))
|
||||
response = requests.get(
|
||||
request_uri
|
||||
)
|
||||
|
@ -602,9 +633,26 @@ def profile_info(config, profile):
|
|||
print('Response headers: {}'.format(response.headers))
|
||||
|
||||
if response.status_code == 200:
|
||||
return True, response.json()[0]
|
||||
retvalue = True
|
||||
respjson = response.json()
|
||||
job_state = respjson['state']
|
||||
if job_state == 'PENDING':
|
||||
retdata = 'Job state: PENDING'
|
||||
if job_state == 'RUNNING':
|
||||
retdata = 'Job state: RUNNING\nStage: {}/{}\nStatus: {}'.format(
|
||||
respjson['current'],
|
||||
respjson['total'],
|
||||
respjson['status']
|
||||
)
|
||||
if job_state == 'FAILED':
|
||||
retdata = 'Job state: FAILED\nStatus: {}'.format(
|
||||
respjson['status']
|
||||
)
|
||||
else:
|
||||
return False, response.json()['message']
|
||||
retvalue = False
|
||||
retdata = response.json()['message']
|
||||
|
||||
return retvalue, retdata
|
||||
|
||||
#
|
||||
# Format functions
|
||||
|
|
|
@ -2810,6 +2810,37 @@ def provisioner_profile_remove(name):
|
|||
cleanup(retcode, retdata)
|
||||
|
||||
|
||||
###############################################################################
|
||||
# pvc provisioner create
|
||||
###############################################################################
|
||||
@click.command(name='create', short_help='Create new VM.')
|
||||
@click.argument(
|
||||
'name'
|
||||
)
|
||||
@click.argument(
|
||||
'profile'
|
||||
)
|
||||
def provisioner_create(name, profile):
|
||||
"""
|
||||
Create a new VM NAME with profile PROFILE.
|
||||
"""
|
||||
retcode, retdata = pvc_provisioner.vm_create(config, name, profile)
|
||||
cleanup(retcode, retdata)
|
||||
|
||||
|
||||
###############################################################################
|
||||
# pvc provisioner status
|
||||
###############################################################################
|
||||
@click.command(name='status', short_help='Show status of provisioner job.')
|
||||
@click.argument(
|
||||
'job'
|
||||
)
|
||||
def provisioner_status(job):
|
||||
"""
|
||||
Show status of provisioner job JOB.
|
||||
"""
|
||||
retcode, retdata = pvc_provisioner.task_status(config, job)
|
||||
cleanup(retcode, retdata)
|
||||
|
||||
|
||||
|
||||
|
@ -3039,6 +3070,8 @@ cli_provisioner.add_command(provisioner_template)
|
|||
cli_provisioner.add_command(provisioner_userdata)
|
||||
cli_provisioner.add_command(provisioner_script)
|
||||
cli_provisioner.add_command(provisioner_profile)
|
||||
cli_provisioner.add_command(provisioner_create)
|
||||
cli_provisioner.add_command(provisioner_status)
|
||||
|
||||
cli.add_command(cli_cluster)
|
||||
cli.add_command(cli_node)
|
||||
|
|
Loading…
Reference in New Issue