Provision VMware VM programmitically via args


#1

Hi there,

I’m currently trying to provision a vmware vm programmtically as described in the Automation book. Link

I created my args and executed the command as described but I always get the following error:

RuntimeError: Provision failed for the following reasons:
‘Network/Virtual Network’ is required

I don’t know what to do about this error. My args list looks like this, specifics are redacted but I think that a certain parameter value is missing.

arg1 = version

args = [‘1.1’]

arg2 = templateFields

args << {‘name’ => ‘template-name’,
‘request_type’ => ‘template’}

arg3 = vmFields

args << {‘vm_name’ => ‘vm_name’,
‘number_of_vms’ => ‘1’,
‘placement_cluster_name’ => ‘cluster-name’,
‘vlan’ => “vlan-name”,
‘network’ => “dvs-name”,
‘is_dvs’ => ‘true’,
‘portgroupName’ => ‘pg-name’,
‘vm_memory’ => ‘1024’,
‘sysprep_computer_name’ => ‘vm-name’,
‘ip_addr’ => ‘ip-addr’,
‘provision_type’ => ‘vmware’,
‘network_adapters’ => ‘1’}

arg4 = requester

args << {‘owner_email’ => ‘email@company.com’,
‘owner_first_name’ => ‘first’,
‘owner_last_name’ => ‘last’}

arg5 = tags

args << nil

arg6 = additionalValues (ws_values)

args << {‘network’ => ‘dvs-name’ }

arg7 = emsCustomAttributes

args << nil

arg8 = miqCustomAttributes

args << nil

Any help is appreciated.


#2

Update:

I stumbled upon this Code Snippet

def validate_field_data(dialog_tab, dialog_group)
return if !required? && @value.blank? || !visible
return “#{dialog_tab.label}/#{dialog_group.label}/#{label} is required” if required? && @value.blank?
return “#{dialog_tab.label}/#{dialog_group.label}/#{label} must be an integer” if value_supposed_to_be_int?

# currently only regex is supported
rule = validator_rule if validator_type == ‘regex’

return unless rule
“#{dialog_tab.label}/#{dialog_group.label}/#{label} is invalid” unless @value.to_s =~ /#{rule}/
end

and therefore I looked up my preconfigured provisioning dialogs and found this part

:network:
 :description: Network
:fields:
  :vlan:
   :values_from:
       :options:
        :dvs: true
        :vlans: true
      :method: :allowed_vlans
    :description: Virtual Network
    :required: true
    :display: :edit
    :data_type: :string
  :mac_address:
    :description: MAC Address
    :required: false
    :display: :hide
    :data_type: :string

So I’m still trying to figure out which params and values are required in the args.