How to pass vlan variable to vm provisioning request

Hello!
I’m trying to use the “$evm.execute(‘create_provision_request’, *args)” method to create a vm provisioning request
I use the method described in the documentation:
https://pemcg.gitbooks.io/mastering-automation-in-cloudforms-4-2-and-manage/content/creating_provisioning_requests_programmatically/chapter.html

I need to pass a vlan variable, I add it to vm_fields, according to the documentation, but when creating a request it’s ignored (becomes vlan=>nil)
with “placement_auto”=> “true” and “placement_auto” => “false” - the same result

Please help me do this correctly
Unfortunately I didn’t find any more detailed documentation on this issue

log from rails console:

irb(main):131:0> args = [“1.1”, {“name”=>“tmpl_centos7_1908_v1”, “guid”=>“d53e6f88-3a94-4f72-8f1e-26426c9d71fd”}, {“placement_auto”=>“false”,“number_of_vms”=>“1”, “provision_type”=>“vmware”, “vm_name”=>“changeme”, “linux_host_name”=>“changeme”, “vlan”=>“dpg_Automation_VLAN3237”, “number_of_sockets”=>“1”, “cores_per_socket”=>“1”, “vm_memory”=>“1024”, “retirement”=>“2592000”, “retirement_warn”=>“1209600”}, {“user_name”=>“user@test.test”, “owner_first_name”=>“User”, “owner_last_name”=>“UserLN”, “owner_email”=>“user@test.test”}, {“location”=>“sm22”, “environment”=>“cert”, “network_location”=>“dmz”, “machine_type”=>“dbs”}, {“os”=>“centos_linux_7_7”, “flavor”=>“small”, “group_id”=>“1000000000022”, “group_name”=>“miq_admins”, “disk_1_size”=>“25”, “service_id”=>“1000000000230”, “service_guid”=>“e1d3caf8-5169-4775-957d-fb0da823fd76”, “location”=>“sm22”, “environment”=>“cert”, “network_location”=>“dmz”, “machine_type”=>“dbs”}, nil, nil]

=> [“1.1”, {“name”=>“tmpl_centos7_1908_v1”, “guid”=>“d53e6f88-3a94-4f72-8f1e-26426c9d71fd”}, {“placement_auto”=>“false”, “number_of_vms”=>“1”, “provision_type”=>“vmware”, “vm_name”=>“changeme”, “linux_host_name”=>“changeme”, “vlan”=>“dpg_Automation_VLAN3237”, “number_of_sockets”=>“1”, “cores_per_socket”=>“1”, “vm_memory”=>“1024”, “retirement”=>“2592000”, “retirement_warn”=>“1209600”}, {“user_name”=>“user@test.test”, “owner_first_name”=>“User”, “owner_last_name”=>“UserLN”, “owner_email”=>“user@test.test”}, {“location”=>“sm22”, “environment”=>“cert”, “network_location”=>“dmz”, “machine_type”=>“dbs”}, {“os”=>“centos_linux_7_7”, “flavor”=>“small”, “group_id”=>“1000000000022”, “group_name”=>“miq_admins”, “disk_1_size”=>“25”, “service_id”=>“1000000000230”, “service_guid”=>“e1d3caf8-5169-4775-957d-fb0da823fd76”, “location”=>“sm22”, “environment”=>“cert”, “network_location”=>“dmz”, “machine_type”=>“dbs”}, nil, nil]
irb(main):132:0>
irb(main):133:0> request = $evm.execute(‘create_provision_request’, *args)
PostgreSQLAdapter#log_after_checkin, connection_pool: size: 5, connections: 1, in use: 0, waiting_in_queue: 0
PostgreSQLAdapter#log_after_checkout, connection_pool: size: 5, connections: 1, in use: 1, waiting_in_queue: 0
PostgreSQLAdapter#log_after_checkin, connection_pool: size: 5, connections: 1, in use: 0, waiting_in_queue: 0

=> #<MiqAeServiceMiqProvisionRequest:0x82cf904 @object=#<MiqProvisionRequest id: 1000000000505, description: “Provision from [tmpl_centos7_1908_v1] to [rbjetdbs…”, approval_state: “pending_approval”, type: “MiqProvisionRequest”, created_on: “2020-05-22 08:18:38”, updated_on: “2020-05-22 08:18:41”, fulfilled_on: nil, requester_id: 1000000000004, requester_name: “User UserLN”, request_type: “template”, request_state: “pending”, message: “VM Provisioning - Request Created”, status: “Ok”, options: {:use_pre_dialog=>false, :request_type=>“template”, :initial_pass=>true, :owner_email=>“user@test.test”, :placement_auto=>[false, 0], :src_vm_id=>[1000000000002, “tmpl_centos7_1908_v1”], :miq_request_dialog_name=>“miq_provision_vmware_dialogs_template_no_required_fields”, :owner_phone=>nil, :owner_country=>nil, :owner_phone_mobile=>nil, :owner_title=>nil, :owner_first_name=>“User”, :owner_manager=>nil, :owner_address=>nil, :owner_company=>nil, :owner_last_name=>“UserLN”, :owner_manager_mail=>nil, :owner_city=>nil, :owner_department=>nil, :owner_load_ldap=>nil, :owner_manager_phone=>nil, :owner_state=>nil, :owner_office=>nil, :owner_zip=>nil, :request_notes=>nil, :vm_tags=>[1000000000233, 1000000000023, 1000000000061, 1000000000238], :customization_template_script=>nil, :dns_servers=>nil, :sysprep_organization=>nil, :sysprep_password=>nil, :sysprep_server_license_mode=>[“perServer”, “Per server”], :ldap_ous=>[nil, nil], :sysprep_timezone=>[nil, nil], :dns_suffixes=>nil, :sysprep_product_id=>nil, :sysprep_identification=>[“domain”, “Domain”], :sysprep_per_server_max_connections=>“5”, :sysprep_computer_name=>nil, :sysprep_workgroup_name=>“WORKGROUP”, :sysprep_spec_override=>[false, 0], :addr_mode=>[“dhcp”, “DHCP”], :linux_host_name=>“changeme”, :sysprep_domain_admin=>nil, :sysprep_change_sid=>[true, 1], :sysprep_domain_name=>[nil, nil], :sysprep_upload_file=>nil, :gateway=>nil, :ip_addr=>nil, :linux_domain_name=>nil, :sysprep_domain_password=>nil, :sysprep_auto_logon=>[true, 1], :sysprep_enabled=>[“fields”, “Specification”], :sysprep_delete_accounts=>[false, 0], :sysprep_upload_text=>nil, :wins_servers=>nil, :subnet_mask=>nil, :sysprep_full_name=>nil, :sysprep_auto_logon_count=>[1, “1”], :root_password=>nil, :hostname=>nil, :placement_cluster_name=>[nil, nil], :cluster_filter=>[nil, nil], :host_filter=>[nil, nil], :ds_filter=>[nil, nil], :rp_filter=>[nil, nil], :placement_folder_name=>[nil, nil], :placement_rp_name=>[nil, nil], :placement_dc_name=>[nil, nil], :number_of_vms=>[1, “1”], :vm_description=>nil, :vm_prefix=>nil, :vm_name=>“changeme”, :pxe_server_id=>[nil, nil], :host_name=>nil, :provision_type=>[“vmware”, “VMware”], :linked_clone=>[nil, nil], :snapshot=>[nil, nil], :vm_filter=>[nil, nil], :schedule_type=>[“immediately”, “Immediately on Approval”], :vm_auto_start=>[true, 1], :schedule_time=>2020-05-23 11:18:37 +0300, :retirement=>nil, :retirement_warn=>[1209600, “2 Weeks”], :vlan=>nil, :mac_address=>nil, :disk_format=>[“unchanged”, “Default”], :cpu_limit=>-1, :memory_limit=>-1, :number_of_sockets=>[1, “1”], :cores_per_socket=>[1, “1”], :cpu_reserve=>0, :vm_memory=>“1024”, :memory_reserve=>0, :network_adapters=>[1, “1”], :placement_host_name=>[nil, nil], :placement_ds_name=>[nil, nil], :src_vm_nics=>[“Network adapter 1”], :src_vm_lans=>[“dpg_Automation_VLAN3237”], :customize_enabled=>[“enabled”], :src_ems_id=>[1000000000002, “DC2 DMZ vCenter”], :placement_storage_profile=>nil, :auto_approve=>false, :ws_values=>{:os=>“centos_linux_7_7”, :flavor=>“small”, :group_id=>“1000000000022”, :group_name=>“miq_admins”, :disk_1_size=>“25”, :service_id=>“1000000000230”, :service_guid=>“e1d3caf8-5169-4775-957d-fb0da823fd76”, :location=>“sm22”, :environment=>“cert”, :network_location=>“dmz”, :machine_type=>“dbs”}, :ws_ems_custom_attributes=>{}, :ws_miq_custom_attributes=>{}, :requester_group=>“miq_admins”, :owner_group=>nil, :delivered_on=>nil}, userid: “user@test.test”, source_id: 1000000000002, source_type: “VmOrTemplate”, destination_id: nil, destination_type: nil, tenant_id: 1000000000001, service_order_id: nil, process: true, cancelation_status: nil>, @virtual_columns=[“href_slug”, “provision_type”, “reason”, “region_description”, “region_number”, “request_type_display”, “resource_type”, “stamped_on”, “state”, “v_allowed_tags”, “v_approved_by”, “v_approved_by_email”, “v_workflow_class”], @associations=[“approvers”, “destination”, “eligible_clusters”, “eligible_customization_templates”, “eligible_folders”, “eligible_hosts”, “eligible_iso_images”, “eligible_pxe_images”, “eligible_pxe_servers”, “eligible_resource_pools”, “eligible_storages”, “eligible_windows_images”, “miq_approvals”, “miq_provisions”, “miq_request”, “miq_request_tasks”, “requester”, “resource”, “service_order”, “source”, “tenant”, “vm_template”, “workflow”]>
irb(main):134:0>

and what happened:

[root@rb-miq-r1-a1 vmdb]# rails runner tools/rebuild_provision_request.rb -r 1000000000505 -q

{“version”=>“1.1”,
“template_fields”=>
{“guid”=>“d53e6f88-3a94-4f72-8f1e-26426c9d71fd”,
“name”=>“tmpl_centos7_1908_v1”,
“request_type”=>“template”},
“vm_fields”=>
{“sysprep_server_license_mode”=>“perServer”,
“sysprep_identification”=>“domain”,
“sysprep_per_server_max_connections”=>“5”,
“sysprep_workgroup_name”=>“WORKGROUP”,
“addr_mode”=>“dhcp”,
“linux_host_name”=>“changeme”,
“sysprep_change_sid”=>true,
“sysprep_auto_logon”=>true,
“sysprep_enabled”=>“fields”,
“sysprep_auto_logon_count”=>1,
“placement_auto”=>false,
“number_of_vms”=>1,
“vm_name”=>“changeme”,
“provision_type”=>“vmware”,
“vm_auto_start”=>true,
“retirement_warn”=>1209600,
“disk_format”=>“unchanged”,
“cpu_limit”=>-1,
“memory_limit”=>-1,
“number_of_sockets”=>1,
“cores_per_socket”=>1,
“cpu_reserve”=>0,
“vm_memory”=>“1024”,
“memory_reserve”=>0,
“network_adapters”=>1},
“requester”=>
{“owner_first_name”=>“User”,
“owner_last_name”=>“UserLN”,
“owner_email”=>“user@test.test”},
“tags”=>
{“network_location”=>“dmz”,
“environment”=>“cert”,
“location”=>“sm22”,
“machine_type”=>“dbs”},
“additional_values”=>
{:os=>“centos_linux_7_7”,
:flavor=>“small”,
:group_id=>“1000000000022”,
:group_name=>“miq_admins”,
:disk_1_size=>“25”,
:service_id=>“1000000000230”,
:service_guid=>“e1d3caf8-5169-4775-957d-fb0da823fd76”,
:location=>“sm22”,
:environment=>“cert”,
:network_location=>“dmz”,
:machine_type=>“dbs”},
“ems_custom_attributes”=>{},
“miq_custom_attributes”=>{}}
[root@rb-miq-r1-a1 vmdb]#

I’d try running a similar provisioning request interactively from Lifecycle -> Provision VM, selecting the same network, and then see what the vlan value looks like in the options hash from that request. Then you’ll have an idea of what to aim for in your hand-rolled arguments to create_provision_request.

pemcg

Thanks for the advice! I checked difference between the request for an interactive call on your advice, it turned out to be simple - I forgot to add “dvs_” to the name of the port group
This was difficult to catch, i.e. exception handling in this case did not output any errors, but simply did not add a variable to the request
Problem solved)