API - create new host vm (vmware)

Greetings,

is it possible to create a new host vm on vmware with the foreman api.

On the man page (Foreman) i do not find any commands
for the vmware tab during the host creation:

something like

-d "vm[cpus]=1" -d "vm[memory]=768" -d "vm[memory]=768" -d
"vm[cluster]=test"
-d "vm[folder]=vm/test" -d "vm[network]=VMNetwork77" -d
"vm[datastore]=test"
-d "vm[ds_name]=Hard disk" -d "vm[ds_size]=15" \

The foreman log during the creation wasn't very helpful :slight_smile:

Thanks

Daniel

First off can you create new VMware Hosts from Foreman UI?

If so please post the json generated by your UI actions I can probably give
some suggestion.

路路路 On Monday, March 25, 2013 1:59:47 AM UTC-7, barmeni...@googlemail.com wrote: > > Greetings, > > is it possible to create a new host vm on vmware with the foreman api. > > On the man page (http://theforeman.org/api.html) i do not find any > commands for the vmware tab during the host creation: > > > something like > > -d "vm[cpus]=1" -d "vm[memory]=768" -d "vm[memory]=768" -d > "vm[cluster]=test" \ > -d "vm[folder]=vm/test" -d "vm[network]=VMNetwork77" -d > "vm[datastore]=test" \ > -d "vm[ds_name]=Hard disk" -d "vm[ds_size]=15" \ > > The foreman log during the creation wasn't very helpful :-) > > > Thanks > > Daniel >

Hi Viet,

thanks for the response, here is the log output

tarted POST "/hosts" for xx.x.x.x.x at Wed Mar 27 09:53:33 +0100 2013

Processing by HostsController#create as

Parameters: {"capabilities"=>"build", "authenticity_token"=>"xxxxxxxxx",
"utf8"=>"芒",

"host"=>{"name" =>"barsch", "managed"=>"true", "subnet_id"=>"5",
"architecture_id"=>"1",

"comment"=>"", "compute_resource_id"=>"4",

"compute_attributes"=> {"cpus"=>"1", "cluster"=>"DevOps", "start"=>"1",
"path"=>"/Datencenter/xxxxxx/vm/DevOps",
"interfaces_attributes"=>{"new_interfaces"=>{"_delete"=>"", "network"=>"VM
Network"},

"0"=>{"_delete"=>"", "network"=>"VMNetwork69"}},

"volumes_attributes"=>{"new_volumes"=>{"name"=>"Hard disk",
"size_gb"=>"10", "_delete"=>"", "datastore"=>"Local Disc esxxx.xxx.xxx"},
"0"=>{"name"=>"Hard disk", "size_gb"=>"15", "_delete"=>"",
"datastore"=>"Dev_Ops"}}, "memory_mb"=>"768"}, "provision_method"=>"build",
"overwrite"=>"false", "puppet_proxy_id"=>"3", "updated_at"=>"1364374283",

"mac"=>"", "domain_id"=>"1", "hostgroup_id"=>"2", "build"=>"1",
"medium_id"=>"10", "root_pass"=>"[FILTERED]",

"enabled"=>"1", "ptable_id"=>"11", "is_owned_by"=>"",
"environment_id"=>"3", "progress_report_id"=>"[FILTERED]",

"ip"=>"1xx.xx.xxx.xxx",
"interfaces_attributes"=>{"new_interfaces"=>{"name"=>"", "mac"=>"",
"domain_id"=>"1",

"type"=>"Nic::Managed", "_destroy"=>"false", "ip"=>"",
"provider"=>"IPMI"}}, "model_id"=>"", "puppetclass_ids"=>[""],

"disk"=>"", "operatingsystem_id"=>"3"}}

User Load (0.5ms) SELECT users.* FROM users WHERE users.id = 1

Greetings

Daniel

路路路 Am Dienstag, 26. M盲rz 2013 21:34:28 UTC+1 schrieb Viet Nguyen: > > First off can you create new VMware Hosts from Foreman UI? > > If so please post the json generated by your UI actions I can probably > give some suggestion. > > > > > On Monday, March 25, 2013 1:59:47 AM UTC-7, barmeni...@googlemail.comwrote: >> >> Greetings, >> >> is it possible to create a new host vm on vmware with the foreman api. >> >> On the man page (http://theforeman.org/api.html) i do not find any >> commands for the vmware tab during the host creation: >> >> >> something like >> >> -d "vm[cpus]=1" -d "vm[memory]=768" -d "vm[memory]=768" -d >> "vm[cluster]=test" \ >> -d "vm[folder]=vm/test" -d "vm[network]=VMNetwork77" -d >> "vm[datastore]=test" \ >> -d "vm[ds_name]=Hard disk" -d "vm[ds_size]=15" \ >> >> The foreman log during the creation wasn't very helpful :-) >> >> >> Thanks >> >> Daniel >> >

here is an example how to create a vm using rest api:

unfortunately the vm is not powered on during the build and we need to
provide a mac address at the moment

requestParamCreate = {
:method => :post,
:url => "https://lxxxxx/api/hosts",
:user => "admin",
:password => "xxxxx",
:payload => '{
"host": {
"name": "barsch",
"hostgroup_id": 2,
"environment_id": 4,
"architecture_id": 1,
"operatingsystem_id": 0,
"domain_id": 1,
"mac": "00:xxxxxxxx",
"ptable_id": 11,
"puppet_proxy_id": 1,
"model_id": 1,
"compute_resource_id": 4,
"build": 1,
"enabled": 1,
"managed": 1,
"compute_attributes": {
"cpus": 1,
"cluster": "DevOps",
"start": 1,
"path": "/Datencenter/xxxxx/vm/DevOps",
"interfaces_attributes": {
"new_interfaces": {
"_delete": "",
"network": "VM Network"
},
"0": {
"_delete": "",
"network": "VMNetwork69"
}
},
"volumes_attributes": {
"new_volumes": {
"name": "Hard disk",
"size_gb": 10,
"_delete": "",
"datastore": "Local Disc esxxxxxx"
},
"0": {
"name": "Hard disk",
"size_gb": 15,
"_delete": "",
"datastore": "Dev_Ops"
}
},
"memory_mb": 768
}
}
}',

any ideas??

greetings

daniel

路路路 Am Mittwoch, 27. M盲rz 2013 10:04:29 UTC+1 schrieb barmeni...@googlemail.com: > > Hi Viet, > > thanks for the response, here is the log output > > tarted POST "/hosts" for xx.x.x.x.x at Wed Mar 27 09:53:33 +0100 2013 > > Processing by HostsController#create as > > Parameters: {"capabilities"=>"build", "authenticity_token"=>"xxxxxxxxx", > "utf8"=>"芒", > > "host"=>{"name" =>"barsch", "managed"=>"true", "subnet_id"=>"5", > "architecture_id"=>"1", > > "comment"=>"", "compute_resource_id"=>"4", > > "compute_attributes"=> {"cpus"=>"1", "cluster"=>"DevOps", "start"=>"1", > "path"=>"/Datencenter/xxxxxx/vm/DevOps", > "interfaces_attributes"=>{"new_interfaces"=>{"_delete"=>"", "network"=>"VM > Network"}, > > "0"=>{"_delete"=>"", "network"=>"VMNetwork69"}}, > > "volumes_attributes"=>{"new_volumes"=>{"name"=>"Hard disk", > "size_gb"=>"10", "_delete"=>"", "datastore"=>"Local Disc esxxx.xxx.xxx"}, > "0"=>{"name"=>"Hard disk", "size_gb"=>"15", "_delete"=>"", > "datastore"=>"Dev_Ops"}}, "memory_mb"=>"768"}, "provision_method"=>"build", > "overwrite"=>"false", "puppet_proxy_id"=>"3", "updated_at"=>"1364374283", > > "mac"=>"", "domain_id"=>"1", "hostgroup_id"=>"2", "build"=>"1", > "medium_id"=>"10", "root_pass"=>"[FILTERED]", > > "enabled"=>"1", "ptable_id"=>"11", "is_owned_by"=>"", > "environment_id"=>"3", "progress_report_id"=>"[FILTERED]", > > "ip"=>"1xx.xx.xxx.xxx", > "interfaces_attributes"=>{"new_interfaces"=>{"name"=>"", "mac"=>"", > "domain_id"=>"1", > > "type"=>"Nic::Managed", "_destroy"=>"false", "ip"=>"", > "provider"=>"IPMI"}}, "model_id"=>"", "puppetclass_ids"=>[""], > > "disk"=>"", "operatingsystem_id"=>"3"}} > > User Load (0.5ms) SELECT `users`.* FROM `users` WHERE `users`.`id` = 1 > > Greetings > > Daniel > > > Am Dienstag, 26. M盲rz 2013 21:34:28 UTC+1 schrieb Viet Nguyen: >> >> First off can you create new VMware Hosts from Foreman UI? >> >> If so please post the json generated by your UI actions I can probably >> give some suggestion. >> >> >> >> >> On Monday, March 25, 2013 1:59:47 AM UTC-7, barmeni...@googlemail.comwrote: >>> >>> Greetings, >>> >>> is it possible to create a new host vm on vmware with the foreman api. >>> >>> On the man page (http://theforeman.org/api.html) i do not find any >>> commands for the vmware tab during the host creation: >>> >>> >>> something like >>> >>> -d "vm[cpus]=1" -d "vm[memory]=768" -d "vm[memory]=768" -d >>> "vm[cluster]=test" \ >>> -d "vm[folder]=vm/test" -d "vm[network]=VMNetwork77" -d >>> "vm[datastore]=test" \ >>> -d "vm[ds_name]=Hard disk" -d "vm[ds_size]=15" \ >>> >>> The foreman log during the creation wasn't very helpful :-) >>> >>> >>> Thanks >>> >>> Daniel >>> >>

Not sure about VMware, but I have the code for creating Libvirt (KVM)
virtual machines over the API. It was actually written for building VMs to
test packages, but you can extract the relevant parts easily enough:

This is Ruby code which creates a hash for the new host (setting hostgroup,
compute resource, disk size, and so on) which is then POSTed to Foreman
over the API. No MAC or IP is sent, Foreman can figure that out itself, and
the VM does power on properly.

All being well, you should be able to replace the compute_resource_id
with the id of your VMware CR, and it should work the same.

HTH
Greg

路路路 On 5 April 2013 08:30, Jason Viloria wrote:

Has anyone solved this problem yet? I too am looking at scripting the
creations of vmware guests so as not to have to login to the web
interface. I shall try to experiment creating a json post.

/jason

Hi Greg,

Thanks for that!

After seeing your code, specially the part where you do the create_host ,
it occurred to me that I should look at the POST from production log when i
create a vm via the web interface and do a hail mary test of POSTING
exactly the same thing except modifying the machine name and IP and that
works like a charm.

/Jason

路路路 On Friday, April 5, 2013 12:15:27 PM UTC+2, Greg Sutcliffe wrote: > > On 5 April 2013 08:30, Jason Viloria <jnv...@gmail.com >wrote: > >> >> Has anyone solved this problem yet? I too am looking at scripting the >> creations of vmware guests so as not to have to login to the web >> interface. I shall try to experiment creating a json post. >> >> /jason >> > > Not sure about VMware, but I have the code for creating Libvirt (KVM) > virtual machines over the API. It was actually written for building VMs to > test packages, but you can extract the relevant parts easily enough: > > > https://github.com/GregSutcliffe/foreman_vmbuilder/blob/master/vm_builder.rb#L172 > > This is Ruby code which creates a hash for the new host (setting > hostgroup, compute resource, disk size, and so on) which is then POSTed to > Foreman over the API. No MAC or IP is sent, Foreman can figure that out > itself, and the VM does power on properly. > > All being well, you *should* be able to replace the compute_resource_id > with the id of your VMware CR, and it should work the same. > > HTH > Greg >