Have anyone tried provisioning VMs using API?


#1

I am looking at the Foreman APIs and wondering if anyone tried provisioning VMs in vCenter using the APIs or any third party automation tool successfully?

Glancing at the API - things like mac address are not yet available till VM is created.

POST /api/hosts
{
  "host": {
    "name": "testhost11",
    "environment_id": 334344675,
    "domain_id": 22495316,
    "ptable_id": 1007981705,
    "medium_id": 980190962,
    "architecture_id": 501905019,
    "operatingsystem_id": 1073012828,
    "puppet_proxy_id": 182953976,
    "compute_resource_id": 980190962,
    "root_pass": "xybxa6JUkz63w",
    "location_id": 255093256,
    "organization_id": 447626438,
    "ip": "10.0.0.20",
    "mac": "52:53:00:1e:85:93",
    "compute_attributes": {
      "cpus": 4,
      "memory": 1024
    }
  }
}

#2

Hi,

something along these lines should work:

{
  "host" : {
    "name" : "examplesrv",
    "location_id" : "2",
    "organization_id" : "1",
    "compute_resource_id" : "1",
    "compute_profile_id" : "1",
    "hostgroup_id" : "52",
    "build" : true,
    "interfaces_attributes" : [ {
      "name" : "examplesrv",
      "managed" : true,
      "primary" : true,
      "provision" : true,
      "subnet_id" : 40,
      "domain_id" : 3,
      "compute_attributes": {"type": "VirtualVmxnet3", "network": "dvportgroup-92874"}
    }, {
      "name" : "examplesrva",
      "managed" : true,
      "primary" : false,
      "provision" : false,
      "subnet_id" : 4,
      "domain_id" : 3,
      "compute_attributes": {"type": "VirtualVmxnet3", "network": "dvportgroup-50944"}
    }, {
      "name" : "examplesrvs",
      "managed" : true,
      "primary" : false,
      "provision" : false,
      "subnet_id" : 6,
      "domain_id" : 3,
      "compute_attributes": {"type": "VirtualVmxnet3", "network": "dvportgroup-50898"}
    }, {
      "name" : "examplesrvn",
      "managed" : true,
      "primary" : false,
      "provision" : false,
      "subnet_id" : 5,
      "domain_id" : 3,
      "compute_attributes": {"type": "VirtualVmxnet3", "network": "dvportgroup-50969"}
    }, {
      "name" : "examplesrvr",
      "managed" : true,
      "primary" : false,
      "provision" : false,
      "subnet_id" : 41,
      "domain_id" : 3,
      "compute_attributes": {"type": "VirtualVmxnet3", "network": "dvportgroup-89279"}
    } ],
    "compute_attributes": {
      "cpus": "48",
      "corespersocket": "1",
      "memory_mb": "1048576",
      "cluster": "examplecluster",
      "guest_id": "rhel7_64Guest",
      "scsi_controller_type": "VirtualLsiLogicController",
      "memoryHotAddEnabled": "1",
      "cpuHotAddEnabled": "1",
      "add_cdrom": "0",
      "start": "0",
      "annotation": "",
      "volumes_attributes": {
        "0": {"_delete": "", "datastore": "myds", "name": "disc 1", "size_gb": "51", "thin": "false", "eager_zero": "false"},
        "1": {"_delete": "", "datastore": "myds", "name": "disc 2", "size_gb": "3300", "thin": "false", "eager_zero": "false"}
      }
    }
  }
}

This is a somewhat dated json, but it was the only one that shows quite a lot of the available options and how to use them. I would guess most if not all of these should still work just fine. You will have to adjust all the ids etc. to your setup of course.
Hope this helps.