Unable to create host using api v2 (foreman 1.7)

Hi, first I would like to thank you for developing foreman. It seems great.
It is very easy to create a host. Probably it is very easy to create using
api (v2) too but it seems I miss something constantly. I hope you can help
me.

I create a host through web ui with the following configuration:
Name: testCentOsImageBased
No Host Group
Deploy on: cmptrsrc_VMWare (VMWare)
Environment: production
No puppet CA
No puppet Master

··· --- Domain: localdomain --- Architecture: x86_64 Operating system: CentOS 6.5 Provisioning Method: Image Based (CentOs6_5img)

I am able to create this host. ( after applying this feature
Feature #1945: Better VMWare support for non-clusters setup - Foreman )

According to apiV2, I set my host config as follow:
host.setName(“CGCentOs”);
host.setEnvironmentId(“1”);
host.setDomainId(“1”);
host.setArchitectureId(“1”);
host.setOperatingsystemId(“1”);
host.setComputeResourceId(“1”);

And tailing production.log gives:
domain_id is not allowed as nested parameter for hosts

This is the case for some other parameters too. And It seems that I need to
give image somehow, I have checked request of web ui while creating host
but I could’nt applied extra parametes very successfully to apiV2 create
host request.

Is there any workaround except pulling develop branch? I use 1.7-stable
version currently.

Thank you in advance.

As a workaroud I tried to define a hostgroup,

  1. A hostgroup with only specific environment

    Host host = new Host();
    host.setName("CGCentOs");
    host.setHostgroupId(1);
    host.setDomainId(1);
    host.setArchitectureId(1);
    host.setOperatingsystemId(1);
    host.setComputeResourceId(1);

It gives:

Processing by Api::V2::HostsController#create as JSON
Parameters: {"name"=>"CGCentOs", "capabilities"=>nil, "parameters"=>nil,
"interfaces"=>nil, "puppetclasses"=>nil, "domain_id"=>1,
"architecture_id"=>1, "operatingsystem_id"=>1, "hostgroup_id"=>1,
"compute_resource_id"=>1, "all_puppetclasses"=>nil, "config_groups"=>nil,
"apiv"=>"v2", :host=>{"name"=>"CGCentOs", "domain_id"=>1,
"architecture_id"=>1, "operatingsystem_id"=>1, "hostgroup_id"=>1,
"compute_resource_id"=>1}}
Expire fragment views/tabs_and_title_records-3 (0.1ms)
Authorized user admin(Admin User)
domain_id is not allowed as nested parameter for hosts. Allowed parameters
are hostgroup_id, location_id, organization_id, environment_id
(RuntimeError)

So I specify domain_id in hostgroup too, it becomes

2.A hostgroup with specific environment and domain_id

    Host host = new Host();
    host.setName("CGCentOs");
    host.setHostgroupId(1);    
    host.setArchitectureId(1); 
    host.setOperatingsystemId(1); 
    host.setComputeResourceId(1);

It gives:
Parameters: {"name"=>"CGCentOs", "capabilities"=>nil, "parameters"=>nil,
"interfaces"=>nil, "puppetclasses"=>nil, "architecture_id"=>1,
"operatingsystem_id"=>1, "hostgroup_id"=>1, "compute_resource_id"=>1,
"all_puppetclasses"=>nil, "config_groups"=>nil, "apiv"=>"v2",
:host=>{"name"=>"CGCentOs", "architecture_id"=>1, "operatingsystem_id"=>1,
"hostgroup_id"=>1, "compute_resource_id"=>1}}
Authorized user admin(Admin User)
architecture_id is not allowed as nested parameter for hosts. Allowed
parameters are hostgroup_id, location_id, organization_id, environment_id
(RuntimeError)

  1. I add architecture_id to host group
    Host host = new Host();
    host.setName("CGCentOs");
    host.setHostgroupId(1);
    host.setOperatingsystemId(1);
    host.setComputeResourceId(1);

It gives:

Parameters: {"name"=>"CGCentOs", "capabilities"=>nil, "parameters"=>nil,
"interfaces"=>nil, "puppetclasses"=>nil, "operatingsystem_id"=>1,
"hostgroup_id"=>1, "compute_resource_id"=>1, "all_puppetclasses"=>nil,
"config_groups"=>nil, "apiv"=>"v2", :host=>{"name"=>"CGCentOs",
"operatingsystem_id"=>1, "hostgroup_id"=>1, "compute_resource_id"=>1}}
Authorized user admin(Admin User)
operatingsystem_id is not allowed as nested parameter for hosts. Allowed
parameters are hostgroup_id, location_id, organization_id, environment_id
(RuntimeError)

  1. I add operatingsystem_id to host group
    Host host = new Host();
    host.setName("CGCentOs");
    host.setHostgroupId(1);
    host.setComputeResourceId(1);

It gives:
Processing by Api::V2::HostsController#create as JSON
Parameters: {"name"=>"CGCentOs", "capabilities"=>nil, "parameters"=>nil,
"interfaces"=>nil, "puppetclasses"=>nil, "hostgroup_id"=>1,
"compute_resource_id"=>1, "all_puppetclasses"=>nil, "config_groups"=>nil,
"apiv"=>"v2", :host=>{"name"=>"CGCentOs", "hostgroup_id"=>1,
"compute_resource_id"=>1}}
Expire fragment views/tabs_and_title_records-3 (0.6ms)
Authorized user admin(Admin User)
compute_resource_id is not allowed as nested parameter for hosts. Allowed
parameters are hostgroup_id, location_id, organization_id, environment_id
(RuntimeError)

  1. I can't add compute_resource id to hostgroup… i just remove the line…
    Host host = new Host();
    host.setName("CGCentOs");
    host.setHostgroupId(1);

It gives:
Processing by Api::V2::HostsController#create as JSON
Parameters: {"name"=>"CGCentOs", "capabilities"=>nil, "parameters"=>nil,
"interfaces"=>nil, "puppetclasses"=>nil, "hostgroup_id"=>1,
"all_puppetclasses"=>nil, "config_groups"=>nil, "apiv"=>"v2",
:host=>{"name"=>"CGCentOs", "hostgroup_id"=>1}}
Authorized user admin(Admin User)
Unprocessable entity Host::Managed (id: new):
MAC address is not a valid MAC address
MAC address can't be blank
Partition Table cant be blank unless a custom partition has been defined

I was expecting this because, coumpute resource defines its virtuality…
So, compute profiles and compute resources seem tight couple

I try this:
Host host = new Host();
host.setName("CGCentOs");
host.setHostgroupId(1);
host.setComputeProfileId(3);

It gives:
Processing by Api::V2::HostsController#create as JSON
Parameters: {"name"=>"CGCentOs", "capabilities"=>nil, "parameters"=>nil,
"interfaces"=>nil, "puppetclasses"=>nil, "hostgroup_id"=>1,
"compute_profile_id"=>3, "all_puppetclasses"=>nil, "config_groups"=>nil,
"apiv"=>"v2", :host=>{"name"=>"CGCentOs", "hostgroup_id"=>1,
"compute_profile_id"=>3}}
Authorized user admin(Admin User)
compute_profile_id is not allowed as nested parameter for hosts. Allowed
parameters are hostgroup_id, location_id, organization_id, environment_id
(RuntimeError)

I created a new compute profile and it appeared in the edit hos group
pane… so retrying:
Host host = new Host();
host.setName("CGCentOs");
host.setHostgroupId(1);

Again MAC adress problem:
Processing by Api::V2::HostsController#create as JSON
Parameters: {"name"=>"CGCentOs", "capabilities"=>nil, "parameters"=>nil,
"interfaces"=>nil, "puppetclasses"=>nil, "hostgroup_id"=>1,
"all_puppetclasses"=>nil, "config_groups"=>nil, "apiv"=>"v2",
:host=>{"name"=>"CGCentOs", "hostgroup_id"=>1}}
Expire fragment views/tabs_and_title_records-3 (0.1ms)
Authorized user admin(Admin User)
Unprocessable entity Host::Managed (id: new):
MAC address is not a valid MAC address
MAC address can't be blank
Partition Table cant be blank unless a custom partition has been defined

Also the 1.7 doc says that "Assuming the defaults are suitable, the host
has now been defined solely by selecting a host group and a profile."
http://theforeman.org/manuals/1.7/index.html#5.AdvancedForeman

At that point I don't have much to do more
I hope you can help me more

Using the software I wrote, at the end of the day, I just want to create a
centos virtual machine from a template with specific cpu/ram/hard disk
capacity, nothing more

··· On Wednesday, January 21, 2015 at 9:38:40 AM UTC+2, Mete Ozguz wrote: > > Hi, first I would like to thank you for developing foreman. It seems > great. It is very easy to create a host. Probably it is very easy to create > using api (v2) too but it seems I miss something constantly. I hope you can > help me. > > I create a host through web ui with the following configuration: > Name: testCentOsImageBased > No Host Group > Deploy on: cmptrsrc_VMWare (VMWare) > Environment: production > No puppet CA > No puppet Master > --- > Domain: localdomain > --- > Architecture: x86_64 > Operating system: CentOS 6.5 > Provisioning Method: Image Based (CentOs6_5img) > > I am able to create this host. ( after applying this feature > http://projects.theforeman.org/issues/1945 ) > > According to apiV2, I set my host config as follow: > host.setName("CGCentOs"); > host.setEnvironmentId("1"); > host.setDomainId("1"); > host.setArchitectureId("1"); > host.setOperatingsystemId("1"); > host.setComputeResourceId("1"); > > And tailing production.log gives: > domain_id is not allowed as nested parameter for hosts > > This is the case for some other parameters too. And It seems that I need > to give image somehow, I have checked request of web ui while creating host > but I could'nt applied extra parametes very successfully to apiV2 create > host request. > > Is there any workaround except pulling develop branch? I use 1.7-stable > version currently. > > Thank you in advance. > >

> Hi, first I would like to thank you for developing foreman. It seems
> great. It is very easy to create a host. Probably it is very easy to create
> using api (v2) too but it seems I miss something constantly. I hope you can
> help me.
>
> I create a host through web ui with the following configuration:
> Name: testCentOsImageBased
> No Host Group
> Deploy on: cmptrsrc_VMWare (VMWare)
> Environment: production
> No puppet CA
> No puppet Master
> —
> Domain: localdomain
> —
> Architecture: x86_64
> Operating system: CentOS 6.5
> Provisioning Method: Image Based (CentOs6_5img)
>
> I am able to create this host. ( after applying this feature
> Feature #1945: Better VMWare support for non-clusters setup - Foreman )
>
> According to apiV2, I set my host config as follow:
> host.setName("CGCentOs");
> host.setEnvironmentId("1");
> host.setDomainId("1");
> host.setArchitectureId("1");
> host.setOperatingsystemId("1");
> host.setComputeResourceId("1");
>
> And tailing production.log gives:
> domain_id is not allowed as nested parameter for hosts
>

since you are using some sort of a wrapper (java?) it appears you are
sending more parameters then you should, espcally pameters that are type of
a domain (which makes no sense to create a domain parameter in a host
creation context).

it would help if you show the logs when you actually POST the request, but
it seems like a flaw in the code calling the api.

hope this helps,
Ohad

··· On Wed, Jan 21, 2015 at 9:38 AM, Mete Ozguz wrote:

This is the case for some other parameters too. And It seems that I need
to give image somehow, I have checked request of web ui while creating host
but I could’nt applied extra parametes very successfully to apiV2 create
host request.

Is there any workaround except pulling develop branch? I use 1.7-stable
version currently.

Thank you in advance.


You received this message because you are subscribed to the Google Groups
"Foreman users" group.
To unsubscribe from this group and stop receiving emails from it, send an
email to foreman-users+unsubscribe@googlegroups.com.
To post to this group, send email to foreman-users@googlegroups.com.
Visit this group at http://groups.google.com/group/foreman-users.
For more options, visit https://groups.google.com/d/optout.

Yeah, I have created pojos using http://www.jsonschema2pojo.org/ and the
example in
Foreman v2 <http://theforeman.org/api/apidoc/v2.html&gt; /
Hosts <http://theforeman.org/api/apidoc/v2/hosts.html&gt;/
create.
You can find the pojo and the log as attachment
I point out that creating pojos from api examples worked very well (maybe
until now :slight_smile: )

Host.java (7.75 KB)

··· On Wednesday, January 21, 2015 at 9:45:03 AM UTC+2, ohad wrote: > > > > On Wed, Jan 21, 2015 at 9:38 AM, Mete Ozguz > wrote: > >> Hi, first I would like to thank you for developing foreman. It seems >> great. It is very easy to create a host. Probably it is very easy to create >> using api (v2) too but it seems I miss something constantly. I hope you can >> help me. >> >> I create a host through web ui with the following configuration: >> Name: testCentOsImageBased >> No Host Group >> Deploy on: cmptrsrc_VMWare (VMWare) >> Environment: production >> No puppet CA >> No puppet Master >> --- >> Domain: localdomain >> --- >> Architecture: x86_64 >> Operating system: CentOS 6.5 >> Provisioning Method: Image Based (CentOs6_5img) >> >> I am able to create this host. ( after applying this feature >> http://projects.theforeman.org/issues/1945 ) >> >> According to apiV2, I set my host config as follow: >> host.setName("CGCentOs"); >> host.setEnvironmentId("1"); >> host.setDomainId("1"); >> host.setArchitectureId("1"); >> host.setOperatingsystemId("1"); >> host.setComputeResourceId("1"); >> >> And tailing production.log gives: >> domain_id is not allowed as nested parameter for hosts >> > > since you are using some sort of a wrapper (java?) it appears you are > sending more parameters then you should, espcally pameters that are type of > a domain (which makes no sense to create a domain parameter in a host > creation context). > > it would help if you show the logs when you actually POST the request, but > it seems like a flaw in the code calling the api. > > hope this helps, > Ohad > >> >> This is the case for some other parameters too. And It seems that I need >> to give image somehow, I have checked request of web ui while creating host >> but I could'nt applied extra parametes very successfully to apiV2 create >> host request. >> >> Is there any workaround except pulling develop branch? I use 1.7-stable >> version currently. >> >> Thank you in advance. >> >> >> -- >> You received this message because you are subscribed to the Google Groups >> "Foreman users" group. >> To unsubscribe from this group and stop receiving emails from it, send an >> email to foreman-user...@googlegroups.com . >> To post to this group, send email to forema...@googlegroups.com >> . >> Visit this group at http://groups.google.com/group/foreman-users. >> For more options, visit https://groups.google.com/d/optout. >> > >