Allow specifying arbitrary script_args on CLI
Allow the specifying of arbitrary provisioner script install() args on the provisioner create CLI, either overriding or adding additional per-VM arguments to those found in the profile. Reference example is setting a "vm_fqdn" on a per-run basis. Closes #100
This commit is contained in:
@ -195,8 +195,9 @@ def Authenticator(function):
|
||||
# Job functions
|
||||
#
|
||||
@celery.task(bind=True)
|
||||
def create_vm(self, vm_name, profile_name, define_vm=True, start_vm=True):
|
||||
return api_provisioner.create_vm(self, vm_name, profile_name, define_vm=define_vm, start_vm=start_vm)
|
||||
def create_vm(self, vm_name, profile_name, define_vm=True, start_vm=True, script_run_args=[]):
|
||||
print(script_run_args)
|
||||
return api_provisioner.create_vm(self, vm_name, profile_name, define_vm=define_vm, start_vm=start_vm, script_run_args=script_run_args)
|
||||
|
||||
|
||||
##########################################################
|
||||
@ -5974,7 +5975,8 @@ class API_Provisioner_Create_Root(Resource):
|
||||
{ 'name': 'name', 'required': True, 'helpmsg': "A VM name must be specified." },
|
||||
{ 'name': 'profile', 'required': True, 'helpmsg': "A profile name must be specified." },
|
||||
{ 'name': 'define_vm' },
|
||||
{ 'name': 'start_vm' }
|
||||
{ 'name': 'start_vm' },
|
||||
{ 'name': 'arg', 'action': 'append' }
|
||||
])
|
||||
@Authenticator
|
||||
def post(self, reqargs):
|
||||
@ -6005,6 +6007,10 @@ class API_Provisioner_Create_Root(Resource):
|
||||
type: boolean
|
||||
required: false
|
||||
description: Whether to start the VM after provisioning
|
||||
- in: query
|
||||
name: arg
|
||||
type: string
|
||||
description: Script install() function keywork argument in "arg=data" format; may be specified multiple times to add multiple arguments
|
||||
responses:
|
||||
200:
|
||||
description: OK
|
||||
@ -6039,7 +6045,8 @@ class API_Provisioner_Create_Root(Resource):
|
||||
reqargs.get('name', None),
|
||||
reqargs.get('profile', None),
|
||||
define_vm=define_vm,
|
||||
start_vm=start_vm
|
||||
start_vm=start_vm,
|
||||
script_run_args=reqargs.get('arg', []),
|
||||
)
|
||||
return { "task_id": task.id }, 202, { 'Location': Api.url_for(api, API_Provisioner_Status_Element, task_id=task.id) }
|
||||
api.add_resource(API_Provisioner_Create_Root, '/provisioner/create')
|
||||
|
@ -1026,7 +1026,7 @@ def delete_profile(name):
|
||||
#
|
||||
# Main VM provisioning function - executed by the Celery worker
|
||||
#
|
||||
def create_vm(self, vm_name, vm_profile, define_vm=True, start_vm=True):
|
||||
def create_vm(self, vm_name, vm_profile, define_vm=True, start_vm=True, script_run_args=[]):
|
||||
# Runtime imports
|
||||
import time
|
||||
import importlib
|
||||
@ -1542,6 +1542,13 @@ def create_vm(self, vm_name, vm_profile, define_vm=True, start_vm=True):
|
||||
argument_name, argument_data = argument.split('=')
|
||||
script_arguments[argument_name] = argument_data
|
||||
|
||||
# Parse the runtime arguments
|
||||
for argument in script_run_args:
|
||||
argument_name, argument_data = argument.split('=')
|
||||
script_arguments[argument_name] = argument_data
|
||||
|
||||
print("Script arguments: {}".format(script_arguments))
|
||||
|
||||
# Run the script
|
||||
try:
|
||||
installer_script.install(
|
||||
|
Reference in New Issue
Block a user