Hammer -> API

**Problem:Creating VMware VM from template through Foreman API

**Expected outcome:VM created through API

**Foreman and Proxy versions:1.19

Foreman and Proxy plugin versions:

Other relevant data:
I can successfully create a VM using the following hammer command, how do I hit the API with these same values?
hammer host create --name vmhostname --hostgroup-id 1 --provision-method ‘image’ --compute-attributes “start=1”

Thanks! 

Hi @ThurgoodB,
the easiest way would be to see what hammer actually sends to the API. You can check in the server side in /var/log/foreman/production.log or in hammer output in --debug mode: hammer --debug host create --name vmhostname --hostgroup-id 1 --provision-method ‘image’ --compute-attributes “start=1”, please note the --debug is right after hammer as it is a global option.

In a hammer log you could see something similar to:

[ INFO 2019-02-12T12:45:38 API] POST /api/hosts
[DEBUG 2019-02-12T12:45:38 API] Params: {
        "location_id" => 2,
    "organization_id" => 1,
               "host" => {
                                 "name" => "vmhostname",
                          "location_id" => 2,
                      "organization_id" => 1,
                      "puppetclass_ids" => [],
                         "hostgroup_id" => 1,
                     "provision_method" => "image",
                   "compute_attributes" => {
                        "“start" => "1”",
            "volumes_attributes" => {}
        },
             "content_facet_attributes" => {},
        "subscription_facet_attributes" => {},
                                "build" => true,
                              "managed" => true,
                              "enabled" => true,
                            "overwrite" => true,
                "interfaces_attributes" => []
    }
}

The listed parameters you can send to our API using curl or any other tool you prefer. More details on how to use the API can be found in Foreman :: Manual.

Regards,
Martin

1 Like