Changing the Environment Placement variables either in a service template or provisioning

Hello,

I am looking at changing some environment variables at provisioning time such as datastore placement and folder placement in a vmware provision from an API call.

I have been searching for a couple hours and have not found anything concrete yet.
I have tried

  1. Provisioning method via API ( but the environment placements cannot be set directly)
  2. I was thinking of editing the environment options right before executing a service_template deployment to get around this, but it seems like the environment placement options are not accessible from there either.

Any help would be appreciated!

I believe I have found out how to do this through the service templates. I would have loved to do this with the VM_Provisioning calls, but it sets everything to auto-placement, It appears you can still try do do this with provisioning based on a post from pemcg, but I did not want to make it complicated and go down the path of making a customization method in the state machine.

Dialog variables seem to be the vehicle that can traverse across the service-template to the provisioning state. As long as you can find the mapping of the ids for each placement item like VM folder, cluster you can set it with just the ID. It seems to be working.

Heres an example if anyone is trying to do this via APIs.

{
“action”: “order”,
“resource”: {
“href”: “https://cloudformsdev.domain.local/api/service_templates/4000000000001”,
“dialog_service_name”: “SNOW Requested - Bens-API-Test18”,
“dialog_vm_name”: “ecl-tuma-s18”,
“dialog_vlan”: “dvs_DS-CTN-V108-10.49.32.0_20-Main_Container_Network”,
“dialog_cores_per_socket” : “3”,
“dialog_vm_memory” : “5120”,
“dialog_vm_description” : “A new API method for provisioning and placement”,
“dialog_placement_ds_name” : 4000000000007,
“dialog_placement_dc_name” : 4000000000047,
“dialog_placement_folder_name” : 4000000000007,
“dialog_placement_cluster_name” : 4000000000002,
“dialog_placement_rp_name” : 4000000000002
}
}

In case you are wondering how to get these IDs for the items you can traverse the api tree and find it.
Example for datastores:
GET call for https://cloudformsdev.domain.local/api/data_stores?expand=resources&attributes=name,id

You can also see all of the field names by doing a simple GET call to the service template
https://cloudformsdev.domain.local/api/service_templates/4000000000001

Anyway, I hope this helps someone. I probably spent about 5 hours getting to this point.

1 Like

If you didn’t specifically need a service created, you could just issue a POST to the /api/provision_requests REST endpoint and specify the placement options in the vm_fields section.

A useful tool can be the tools/rebuild_provision_request.rb script on the appliance as this lets you see the contents of the options hash from a previous provisioning operation.

For example:

# rails runner tools/rebuild_provision_request.rb -r 84 -q

{"version"=>"1.1",
 "template_fields"=>
  {"guid"=>"279e8970-8ed3-11e6-98a1-001a4aa01502",
   "name"=>"rhel72-generic",
   "request_type"=>"template"},
 "vm_fields"=>
  {"root_password"=>"v2:{fg4jbx7,sj*****I+NA+w==}",
   "customization_template_id"=>9,
   "addr_mode"=>"static",
   "hostname"=>"engdbsrv004.bit63.net",
   "placement_auto"=>false,
   "placement_cluster_name"=>1,
   "placement_dc_name"=>2,
...

Hope this helps,
pemcg