Hosts API fucked up?

I'm starting working with the API and have some troubles (working on 1.5.1
currently)

My goal is to create a host and associate some Puppet classes with params
before the machine get instantiated and registers into Foreman(later, with
some external tools). I do this because I want my boot script call Puppet
that will apply what I'll define using API calls to Foreman.

I'm following the doc :

http://theforeman.org/api.html
POST /api/hosts
Create a host.

ParamsParam nameDescriptionhost *
required
Value: Must be a Hash
host[name] *
required
Value: Must be String*host[environment_id] *
optional
Value: Must be String

The only required arguments are host and host['name'].

So in my custom Foreman Python class I do :
def createHost(self,hostname):
return self.api.post("/api/hosts",{"host":{"name":hostname}})

And I get :
{u'host': {u'errors': {u'operatingsystem_id': [u"can't be blank"],
u'root_pass': [u'should be 8 characters or more', u'should not be blank - consider setting a global or host group default'], u'environment_id':
[u"can't be blank"], u'ptable_id': [u'cant be blank unless a custom partition has been defined'], u'mac': [u'is invalid', u"can't be blank"],
u'architecture_id': [u"can't be blank"]}, u'id': None, u'full_messages':
[u"Environment can't be blank", u'MAC address is invalid', u"MAC address can't be blank", u"Architecture can't be blank", u"Operatingsystem can't be blank", u'Root password should be 8 characters or more', u'Root password should not be blank - consider setting a global or host group default', u'Partition Table cant be blank unless a custom partition has been defined']}}

WTF ?!

Doc says arguments are optional.
API(v1 or v2) says arguments are mandatory.

OFC I'll never be able to pass those arguments, I just don't know them and
don't care about them.

What am I doing wrong ?

Now, now, think about all the children on the list.

··· On Thu, Aug 7, 2014 at 7:08 AM, Vincent Miszczak wrote:

I’m starting working with the API and have some troubles (working on 1.5.1
currently)

My goal is to create a host and associate some Puppet classes with params
before the machine get instantiated and registers into Foreman(later, with
some external tools). I do this because I want my boot script call Puppet
that will apply what I’ll define using API calls to Foreman.

I’m following the doc :

Foreman
POST /api/hosts
Create a host.

ParamsParam nameDescriptionhost *
required
Value: Must be a Hash
host[name] *
required
Value: Must be String*host[environment_id] *
optional
Value: Must be String

The only required arguments are host and host[‘name’].

So in my custom Foreman Python class I do :
def createHost(self,hostname):
return self.api.post("/api/hosts",{“host”:{“name”:hostname}})

And I get :
{u’host’: {u’errors’: {u’operatingsystem_id’: [u"can’t be blank"],
u’root_pass’: [u’should be 8 characters or more’, u’should not be blank - consider setting a global or host group default’], u’environment_id’:
[u"can’t be blank"], u’ptable_id’: [u’cant be blank unless a custom partition has been defined’], u’mac’: [u’is invalid’, u"can’t be blank"],
u’architecture_id’: [u"can’t be blank"]}, u’id’: None, u’full_messages’:
[u"Environment can’t be blank", u’MAC address is invalid’, u"MAC address can’t be blank", u"Architecture can’t be blank", u"Operatingsystem can’t be blank", u’Root password should be 8 characters or more’, u’Root password should not be blank - consider setting a global or host group default’, u’Partition Table cant be blank unless a custom partition has been defined’]}}

WTF ?!

Doc says arguments are optional.
API(v1 or v2) says arguments are mandatory.

OFC I’ll never be able to pass those arguments, I just don’t know them and
don’t care about them.

What am I doing wrong ?


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.


Romeo

Very usefull…
Children are marked optional, I don't want them. What's the point ?

··· Le jeudi 7 août 2014 21:54:09 UTC+2, Romeo Theriault a écrit : > > Now, now, think about all the children on the list. > > > On Thu, Aug 7, 2014 at 7:08 AM, Vincent Miszczak > wrote: > >> I'm starting working with the API and have some troubles (working on >> 1.5.1 currently) >> >> My goal is to create a host and associate some Puppet classes with params >> before the machine get instantiated and registers into Foreman(later, with >> some external tools). I do this because I want my boot script call Puppet >> that will apply what I'll define using API calls to Foreman. >> >> I'm following the doc : >> >> http://theforeman.org/api.html >> POST /api/hosts >> Create a host. >> >> Params Param nameDescription *host * >> required >> Value: Must be a Hash *host[name] * >> required >> Value: Must be String *host[environment_id] * >> optional >> Value: Must be String >> >> The only required arguments are host and host['name']. >> >> So in my custom Foreman Python class I do : >> def createHost(self,hostname): >> return self.api.post("/api/hosts",{"host":{"name":hostname}}) >> >> And I get : >> {u'host': {u'errors': {u'operatingsystem_id': [u"can't be blank"], >> u'root_pass': [u'should be 8 characters or more', u'should not be blank - >> consider setting a global or host group default'], u'environment_id': >> [u"can't be blank"], u'ptable_id': [u'cant be blank unless a custom >> partition has been defined'], u'mac': [u'is invalid', u"can't be blank"], >> u'architecture_id': [u"can't be blank"]}, u'id': None, u'full_messages': >> [u"Environment can't be blank", u'MAC address is invalid', u"MAC address >> can't be blank", u"Architecture can't be blank", u"Operatingsystem can't be >> blank", u'Root password should be 8 characters or more', u'Root password >> should not be blank - consider setting a global or host group default', >> u'Partition Table cant be blank unless a custom partition has been >> defined']}} >> >> WTF ?! >> >> Doc says arguments are optional. >> API(v1 or v2) says arguments are mandatory. >> >> OFC I'll never be able to pass those arguments, I just don't know them >> and don't care about them. >> >> What am I doing wrong ? >> >> -- >> 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. >> > > > > -- > Romeo >

This api is a bit tricky. The documentation is correct in this case. You
can pre-set most of the attributes in hostgroup which complicates the thing.

Really only name and environment_id is mandatory if you specify
hostgroup id. And then it depends on what has been set in the hostgroup.
Some parameters are required only for certain compute resources.

I'd recommend either doing the task via hammer [1] first and then
running it with hammer -d to see what data are being sent to the
server. Or try sending basic json as you did, read the response and
complete missing required fields.

Regards
Tomas

[1]

··· On 08/07/2014 07:08 PM, Vincent Miszczak wrote: > I'm starting working with the API and have some troubles (working on > 1.5.1 currently) > > My goal is to create a host and associate some Puppet classes with > params before the machine get instantiated and registers into > Foreman(later, with some external tools). I do this because I want my > boot script call Puppet that will apply what I'll define using API calls > to Foreman. > > I'm following the doc : > > http://theforeman.org/api.html > > > POST /api/hosts > Create a host. > > > Params > > Param name Description > *host * > required > Value: Must be a Hash > *host[name] * > required > Value: Must be String > *host[environment_id] * > optional > Value: Must be String > > > The only required arguments are host and host['name']. > > So in my custom Foreman Python class I do : > def createHost(self,hostname): > return self.api.post("/api/hosts",{"host":{"name":hostname}}) > > And I get : > {u'host': {u'errors': {u'operatingsystem_id': [u"can't be blank"], > u'root_pass': [u'should be 8 characters or more', u'should not be blank > - consider setting a global or host group default'], u'environment_id': > [u"can't be blank"], u'ptable_id': [u'cant be blank unless a custom > partition has been defined'], u'mac': [u'is invalid', u"can't be > blank"], u'architecture_id': [u"can't be blank"]}, u'id': None, > u'full_messages': [u"Environment can't be blank", u'MAC address is > invalid', u"MAC address can't be blank", u"Architecture can't be blank", > u"Operatingsystem can't be blank", u'Root password should be 8 > characters or more', u'Root password should not be blank - consider > setting a global or host group default', u'Partition Table cant be blank > unless a custom partition has been defined']}} > > WTF ?! > > Doc says arguments are optional. > API(v1 or v2) says arguments are mandatory. > > OFC I'll never be able to pass those arguments, I just don't know them > and don't care about them. > > What am I doing wrong ? >

It was a joke :slight_smile: I've never created hosts via the api, but I just tried it
with curl using v2 of the api (using just the "name" parameter) and it
tells me this:

{
"error": {"id":null,"errors":{"name":["is
invalid"],"environment_id":["can't be blank","can't be
blank"]},"full_messages":["Name is invalid","Environment can't be
blank","Enviro
}

which is also marked as optional… so I'm not sure what the deal is. I
can see requiring the environment but not sure why your error is telling
you all of those values are required. Someone with more knowledge will have
to comment on this.

··· On Thu, Aug 7, 2014 at 9:55 AM, Vincent Miszczak wrote:

Very usefull…
Children are marked optional, I don’t want them. What’s the point ?

Le jeudi 7 août 2014 21:54:09 UTC+2, Romeo Theriault a écrit :

Now, now, think about all the children on the list.

On Thu, Aug 7, 2014 at 7:08 AM, Vincent Miszczak vincent....@gmail.com >> wrote:

I’m starting working with the API and have some troubles (working on
1.5.1 currently)

My goal is to create a host and associate some Puppet classes with
params before the machine get instantiated and registers into
Foreman(later, with some external tools). I do this because I want my boot
script call Puppet that will apply what I’ll define using API calls to
Foreman.

I’m following the doc :

Foreman
POST /api/hosts
Create a host.

Params Param nameDescription *host *
required
Value: Must be a Hash *host[name] *
required
Value: Must be String *host[environment_id] *
optional
Value: Must be String

The only required arguments are host and host[‘name’].

So in my custom Foreman Python class I do :
def createHost(self,hostname):
return self.api.post("/api/hosts",{“host”:{“name”:hostname}})

And I get :
{u’host’: {u’errors’: {u’operatingsystem_id’: [u"can’t be blank"],
u’root_pass’: [u’should be 8 characters or more’, u’should not be blank - consider setting a global or host group default’], u’environment_id’:
[u"can’t be blank"], u’ptable_id’: [u’cant be blank unless a custom partition has been defined’], u’mac’: [u’is invalid’, u"can’t be blank"],
u’architecture_id’: [u"can’t be blank"]}, u’id’: None, u’full_messages’:
[u"Environment can’t be blank", u’MAC address is invalid’, u"MAC address can’t be blank", u"Architecture can’t be blank", u"Operatingsystem can’t be blank", u’Root password should be 8 characters or more’, u’Root password should not be blank - consider setting a global or host group default’, u’Partition Table cant be blank unless a custom partition has been defined’]}}

WTF ?!

Doc says arguments are optional.
API(v1 or v2) says arguments are mandatory.

OFC I’ll never be able to pass those arguments, I just don’t know them
and don’t care about them.

What am I doing wrong ?


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.


Romeo


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.


Romeo

Sorry I still don't get the joke. It just looks broken. Any folk on this ?
It's very annoying when you think having it in production by next week…
I'd like to fix it myself but I'm not a Ruby guy :confused:

··· Le jeudi 7 août 2014 22:16:27 UTC+2, Romeo Theriault a écrit : > > It was a joke :) I've never created hosts via the api, but I just tried it > with curl using v2 of the api (using just the "name" parameter) and it > tells me this: > > { > "error": {"id":null,"errors":{"name":["is > invalid"],"environment_id":["can't be blank","can't be > blank"]},"full_messages":["Name is invalid","Environment can't be > blank","Enviro > } > > which is also marked as optional.... so I'm not sure what the deal is. I > can see requiring the environment but not sure why your error is telling > you all of those values are required. Someone with more knowledge will have > to comment on this. > > > On Thu, Aug 7, 2014 at 9:55 AM, Vincent Miszczak > wrote: > >> Very usefull.... >> Children are marked optional, I don't want them. What's the point ? >> >> Le jeudi 7 août 2014 21:54:09 UTC+2, Romeo Theriault a écrit : >>> >>> Now, now, think about all the children on the list. >>> >>> >>> On Thu, Aug 7, 2014 at 7:08 AM, Vincent Miszczak >>> wrote: >>> >>>> I'm starting working with the API and have some troubles (working on >>>> 1.5.1 currently) >>>> >>>> My goal is to create a host and associate some Puppet classes with >>>> params before the machine get instantiated and registers into >>>> Foreman(later, with some external tools). I do this because I want my boot >>>> script call Puppet that will apply what I'll define using API calls to >>>> Foreman. >>>> >>>> I'm following the doc : >>>> >>>> http://theforeman.org/api.html >>>> POST /api/hosts >>>> Create a host. >>>> >>>> Params Param nameDescription *host * >>>> required >>>> Value: Must be a Hash *host[name] * >>>> required >>>> Value: Must be String *host[environment_id] * >>>> optional >>>> Value: Must be String >>>> >>>> The only required arguments are host and host['name']. >>>> >>>> So in my custom Foreman Python class I do : >>>> def createHost(self,hostname): >>>> return self.api.post("/api/hosts",{"host":{"name":hostname}}) >>>> >>>> And I get : >>>> {u'host': {u'errors': {u'operatingsystem_id': [u"can't be blank"], >>>> u'root_pass': [u'should be 8 characters or more', u'should not be blank - >>>> consider setting a global or host group default'], u'environment_id': >>>> [u"can't be blank"], u'ptable_id': [u'cant be blank unless a custom >>>> partition has been defined'], u'mac': [u'is invalid', u"can't be blank"], >>>> u'architecture_id': [u"can't be blank"]}, u'id': None, u'full_messages': >>>> [u"Environment can't be blank", u'MAC address is invalid', u"MAC address >>>> can't be blank", u"Architecture can't be blank", u"Operatingsystem can't be >>>> blank", u'Root password should be 8 characters or more', u'Root password >>>> should not be blank - consider setting a global or host group default', >>>> u'Partition Table cant be blank unless a custom partition has been >>>> defined']}} >>>> >>>> WTF ?! >>>> >>>> Doc says arguments are optional. >>>> API(v1 or v2) says arguments are mandatory. >>>> >>>> OFC I'll never be able to pass those arguments, I just don't know them >>>> and don't care about them. >>>> >>>> What am I doing wrong ? >>>> >>>> -- >>>> 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. >>>> >>> >>> >>> >>> -- >>> Romeo >>> >> -- >> 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. >> > > > > -- > Romeo >

Hi,

Actually there are a lot of mandatory parameters.
I usually create a host manually and read the production.log . The hash
from the log gives you a good start for creating a host via API.

By the way if you are using python, you can check foreman module from pypi.

Regards,

··· 2014-08-07 23:37 GMT+02:00 Vincent Miszczak :

Sorry I still don’t get the joke. It just looks broken. Any folk on this ?
It’s very annoying when you think having it in production by next week…
I’d like to fix it myself but I’m not a Ruby guy :confused:

Le jeudi 7 août 2014 22:16:27 UTC+2, Romeo Theriault a écrit :

It was a joke :slight_smile: I’ve never created hosts via the api, but I just tried
it with curl using v2 of the api (using just the “name” parameter) and it
tells me this:

{
“error”: {“id”:null,“errors”:{“name”:[“is invalid”],“environment_id”:[“can’t
be blank”,“can’t be blank”]},“full_messages”:[“Name is
invalid”,“Environment can’t be blank”,"Enviro
}

which is also marked as optional… so I’m not sure what the deal is. I
can see requiring the environment but not sure why your error is telling
you all of those values are required. Someone with more knowledge will have
to comment on this.

On Thu, Aug 7, 2014 at 9:55 AM, Vincent Miszczak vincent....@gmail.com >> wrote:

Very usefull…
Children are marked optional, I don’t want them. What’s the point ?

Le jeudi 7 août 2014 21:54:09 UTC+2, Romeo Theriault a écrit :

Now, now, think about all the children on the list.

On Thu, Aug 7, 2014 at 7:08 AM, Vincent Miszczak <vincent....@gmail.com >>>> > wrote:

I’m starting working with the API and have some troubles (working on
1.5.1 currently)

My goal is to create a host and associate some Puppet classes with
params before the machine get instantiated and registers into
Foreman(later, with some external tools). I do this because I want my boot
script call Puppet that will apply what I’ll define using API calls to
Foreman.

I’m following the doc :

Foreman
POST /api/hosts
Create a host.

Params Param nameDescription *host *
required
Value: Must be a Hash *host[name] *
required
Value: Must be String *host[environment_id] *
optional
Value: Must be String

The only required arguments are host and host[‘name’].

So in my custom Foreman Python class I do :
def createHost(self,hostname):
return self.api.post("/api/hosts",{“host”:{“name”:hostname}})

And I get :
{u’host’: {u’errors’: {u’operatingsystem_id’: [u"can’t be blank"],
u’root_pass’: [u’should be 8 characters or more’, u’should not be blank - consider setting a global or host group default’], u’environment_id’:
[u"can’t be blank"], u’ptable_id’: [u’cant be blank unless a custom partition has been defined’], u’mac’: [u’is invalid’, u"can’t be blank"],
u’architecture_id’: [u"can’t be blank"]}, u’id’: None, u’full_messages’:
[u"Environment can’t be blank", u’MAC address is invalid’, u"MAC address can’t be blank", u"Architecture can’t be blank", u"Operatingsystem can’t be blank", u’Root password should be 8 characters or more’, u’Root password should not be blank - consider setting a global or host group default’, u’Partition Table cant be blank unless a custom partition has been defined’]}}

WTF ?!

Doc says arguments are optional.
API(v1 or v2) says arguments are mandatory.

OFC I’ll never be able to pass those arguments, I just don’t know them
and don’t care about them.

What am I doing wrong ?


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.


Romeo


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.


Romeo


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.

I'd say the docs are not up to date (not even in the latest com, certainly
environment and other values are mandatory. I'd recommend you to just try
to clear out all validation errors, and try out hammer-cli-foreman (
https://github.com/theforeman/hammer-cli-foreman) :slight_smile:

Feel free to change the docs here -

··· On Fri, Aug 8, 2014 at 12:14 AM, Iakov Gan wrote:

Hi,

Actually there are a lot of mandatory parameters.
I usually create a host manually and read the production.log . The hash
from the log gives you a good start for creating a host via API.

By the way if you are using python, you can check foreman module from
pypi.

Regards,

2014-08-07 23:37 GMT+02:00 Vincent Miszczak vincent.miszczak@gmail.com:

Sorry I still don’t get the joke. It just looks broken. Any folk on this ?

It’s very annoying when you think having it in production by next week…
I’d like to fix it myself but I’m not a Ruby guy :confused:

Le jeudi 7 août 2014 22:16:27 UTC+2, Romeo Theriault a écrit :

It was a joke :slight_smile: I’ve never created hosts via the api, but I just tried
it with curl using v2 of the api (using just the “name” parameter) and it
tells me this:

{
“error”: {“id”:null,“errors”:{“name”:[“is
invalid”],“environment_id”:[“can’t be blank”,“can’t be
blank”]},“full_messages”:[“Name is invalid”,“Environment can’t be
blank”,"Enviro
}

which is also marked as optional… so I’m not sure what the deal is. I
can see requiring the environment but not sure why your error is telling
you all of those values are required. Someone with more knowledge will have
to comment on this.

On Thu, Aug 7, 2014 at 9:55 AM, Vincent Miszczak vincent....@gmail.com >>> wrote:

Very usefull…
Children are marked optional, I don’t want them. What’s the point ?

Le jeudi 7 août 2014 21:54:09 UTC+2, Romeo Theriault a écrit :

Now, now, think about all the children on the list.

On Thu, Aug 7, 2014 at 7:08 AM, Vincent Miszczak < >>>>> vincent....@gmail.com> wrote:

I’m starting working with the API and have some troubles (working on
1.5.1 currently)

My goal is to create a host and associate some Puppet classes with
params before the machine get instantiated and registers into
Foreman(later, with some external tools). I do this because I want my boot
script call Puppet that will apply what I’ll define using API calls to
Foreman.

I’m following the doc :

Foreman
POST /api/hosts
Create a host.

Params Param nameDescription *host *
required
Value: Must be a Hash *host[name] *
required
Value: Must be String *host[environment_id] *
optional
Value: Must be String

The only required arguments are host and host[‘name’].

So in my custom Foreman Python class I do :
def createHost(self,hostname):
return self.api.post("/api/hosts",{“host”:{“name”:hostname}})

And I get :
{u’host’: {u’errors’: {u’operatingsystem_id’: [u"can’t be blank"],
u’root_pass’: [u’should be 8 characters or more’, u’should not be blank - consider setting a global or host group default’], u’environment_id’:
[u"can’t be blank"], u’ptable_id’: [u’cant be blank unless a custom partition has been defined’], u’mac’: [u’is invalid’, u"can’t be blank"],
u’architecture_id’: [u"can’t be blank"]}, u’id’: None, u’full_messages’:
[u"Environment can’t be blank", u’MAC address is invalid’, u"MAC address can’t be blank", u"Architecture can’t be blank", u"Operatingsystem can’t be blank", u’Root password should be 8 characters or more’, u’Root password should not be blank - consider setting a global or host group default’, u’Partition Table cant be blank unless a custom partition has been defined’]}}

WTF ?!

Doc says arguments are optional.
API(v1 or v2) says arguments are mandatory.

OFC I’ll never be able to pass those arguments, I just don’t know
them and don’t care about them.

What am I doing wrong ?


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.


Romeo


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.


Romeo


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.


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.


Daniel Lobato

@elobatoss
blog.daniellobato.me
daniellobato.me

GPG: http://keys.gnupg.net/pks/lookup?op=get&search=0x7A92D6DD38D6DE30

Damn,

I've been planning for a deployment process reading the doc, and this is
quiet frustrating because it was supposed to be easy.
I'll take a look to suggested tools.

I don't think the ticket you created is correct.
First the problem exists with API v1.
Second to me the core problem is not the doc, it's the API. I don't want to
pass those arguments because I simply don't have/don't need them. They will
be populated when my created host first run Puppet.

··· Le vendredi 8 août 2014 00:46:48 UTC+2, Daniel Lobato a écrit : > > I'd say the docs are not up to date (not even in the latest com, certainly > environment and other values are mandatory. I'd recommend you to just try > to clear out all validation errors, and try out hammer-cli-foreman ( > https://github.com/theforeman/hammer-cli-foreman) :) > > Feel free to change the docs here - > https://github.com/theforeman/foreman/blob/develop/app/controllers/api/v2/hosts_controller.rb > - and submit a Pull Request. > I've opened a Redmine issue to keep track of this - > http://projects.theforeman.org/issues/6997 , thanks for raising this in > the list. > > > On Fri, Aug 8, 2014 at 12:14 AM, Iakov Gan > wrote: > >> Hi, >> >> Actually there are a lot of mandatory parameters. >> I usually create a host manually and read the production.log . The hash >> from the log gives you a good start for creating a host via API. >> >> By the way if you are using python, you can check foreman module from >> pypi. >> >> Regards, >> >> >> >> 2014-08-07 23:37 GMT+02:00 Vincent Miszczak > >: >> >> Sorry I still don't get the joke. It just looks broken. Any folk on this >>> ? It's very annoying when you think having it in production by next week... >>> I'd like to fix it myself but I'm not a Ruby guy :/ >>> >>> Le jeudi 7 août 2014 22:16:27 UTC+2, Romeo Theriault a écrit : >>>> >>>> It was a joke :) I've never created hosts via the api, but I just tried >>>> it with curl using v2 of the api (using just the "name" parameter) and it >>>> tells me this: >>>> >>>> { >>>> "error": {"id":null,"errors":{"name":["is >>>> invalid"],"environment_id":["can't be blank","can't be >>>> blank"]},"full_messages":["Name is invalid","Environment can't be >>>> blank","Enviro >>>> } >>>> >>>> which is also marked as optional.... so I'm not sure what the deal is. >>>> I can see requiring the environment but not sure why your error is telling >>>> you all of those values are required. Someone with more knowledge will have >>>> to comment on this. >>>> >>>> >>>> On Thu, Aug 7, 2014 at 9:55 AM, Vincent Miszczak >>> > wrote: >>>> >>>>> Very usefull.... >>>>> Children are marked optional, I don't want them. What's the point ? >>>>> >>>>> Le jeudi 7 août 2014 21:54:09 UTC+2, Romeo Theriault a écrit : >>>>>> >>>>>> Now, now, think about all the children on the list. >>>>>> >>>>>> >>>>>> On Thu, Aug 7, 2014 at 7:08 AM, Vincent Miszczak < >>>>>> vincent....@gmail.com> wrote: >>>>>> >>>>>>> I'm starting working with the API and have some troubles (working on >>>>>>> 1.5.1 currently) >>>>>>> >>>>>>> My goal is to create a host and associate some Puppet classes with >>>>>>> params before the machine get instantiated and registers into >>>>>>> Foreman(later, with some external tools). I do this because I want my boot >>>>>>> script call Puppet that will apply what I'll define using API calls to >>>>>>> Foreman. >>>>>>> >>>>>>> I'm following the doc : >>>>>>> >>>>>>> http://theforeman.org/api.html >>>>>>> POST /api/hosts >>>>>>> Create a host. >>>>>>> >>>>>>> Params Param nameDescription *host * >>>>>>> required >>>>>>> Value: Must be a Hash *host[name] * >>>>>>> required >>>>>>> Value: Must be String *host[environment_id] * >>>>>>> optional >>>>>>> Value: Must be String >>>>>>> >>>>>>> The only required arguments are host and host['name']. >>>>>>> >>>>>>> So in my custom Foreman Python class I do : >>>>>>> def createHost(self,hostname): >>>>>>> return self.api.post("/api/hosts",{"h >>>>>>> ost":{"name":hostname}}) >>>>>>> >>>>>>> And I get : >>>>>>> {u'host': {u'errors': {u'operatingsystem_id': [u"can't be blank"], >>>>>>> u'root_pass': [u'should be 8 characters or more', u'should not be blank - >>>>>>> consider setting a global or host group default'], u'environment_id': >>>>>>> [u"can't be blank"], u'ptable_id': [u'cant be blank unless a custom >>>>>>> partition has been defined'], u'mac': [u'is invalid', u"can't be blank"], >>>>>>> u'architecture_id': [u"can't be blank"]}, u'id': None, u'full_messages': >>>>>>> [u"Environment can't be blank", u'MAC address is invalid', u"MAC address >>>>>>> can't be blank", u"Architecture can't be blank", u"Operatingsystem can't be >>>>>>> blank", u'Root password should be 8 characters or more', u'Root password >>>>>>> should not be blank - consider setting a global or host group default', >>>>>>> u'Partition Table cant be blank unless a custom partition has been >>>>>>> defined']}} >>>>>>> >>>>>>> WTF ?! >>>>>>> >>>>>>> Doc says arguments are optional. >>>>>>> API(v1 or v2) says arguments are mandatory. >>>>>>> >>>>>>> OFC I'll never be able to pass those arguments, I just don't know >>>>>>> them and don't care about them. >>>>>>> >>>>>>> What am I doing wrong ? >>>>>>> >>>>>>> -- >>>>>>> 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. >>>>>>> >>>>>> >>>>>> >>>>>> >>>>>> -- >>>>>> Romeo >>>>>> >>>>> -- >>>>> 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. >>>>> >>>> >>>> >>>> >>>> -- >>>> Romeo >>>> >>> -- >>> 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. >>> >> >> -- >> 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. >> > > > > -- > Daniel Lobato > > @elobatoss > blog.daniellobato.me > daniellobato.me > > GPG: http://keys.gnupg.net/pks/lookup?op=get&search=0x7A92D6DD38D6DE30 >

I figured out a way to do what I want :

return self.api.post("/api/v2/hosts",{"host":{"name":hostname,
"managed":"false",
"environment_id":1

                                              }})

Parameters(but environement_id) are not required if host is not managed.

··· Le vendredi 8 août 2014 10:09:29 UTC+2, Vincent Miszczak a écrit : > > Damn, > > I've been planning for a deployment process reading the doc, and this is > quiet frustrating because it was supposed to be easy. > I'll take a look to suggested tools. > > I don't think the ticket you created is correct. > First the problem exists with API v1. > Second to me the core problem is not the doc, it's the API. I don't want > to pass those arguments because I simply don't have/don't need them. They > will be populated when my created host first run Puppet. > > > > > Le vendredi 8 août 2014 00:46:48 UTC+2, Daniel Lobato a écrit : >> >> I'd say the docs are not up to date (not even in the latest com, >> certainly environment and other values are mandatory. I'd recommend you to >> just try to clear out all validation errors, and try out hammer-cli-foreman >> (https://github.com/theforeman/hammer-cli-foreman) :) >> >> Feel free to change the docs here - >> https://github.com/theforeman/foreman/blob/develop/app/controllers/api/v2/hosts_controller.rb >> - and submit a Pull Request. >> I've opened a Redmine issue to keep track of this - >> http://projects.theforeman.org/issues/6997 , thanks for raising this in >> the list. >> >> >> On Fri, Aug 8, 2014 at 12:14 AM, Iakov Gan wrote: >> >>> Hi, >>> >>> Actually there are a lot of mandatory parameters. >>> I usually create a host manually and read the production.log . The hash >>> from the log gives you a good start for creating a host via API. >>> >>> By the way if you are using python, you can check foreman module from >>> pypi. >>> >>> Regards, >>> >>> >>> >>> 2014-08-07 23:37 GMT+02:00 Vincent Miszczak : >>> >>> Sorry I still don't get the joke. It just looks broken. Any folk on this >>>> ? It's very annoying when you think having it in production by next week... >>>> I'd like to fix it myself but I'm not a Ruby guy :/ >>>> >>>> Le jeudi 7 août 2014 22:16:27 UTC+2, Romeo Theriault a écrit : >>>>> >>>>> It was a joke :) I've never created hosts via the api, but I just >>>>> tried it with curl using v2 of the api (using just the "name" parameter) >>>>> and it tells me this: >>>>> >>>>> { >>>>> "error": {"id":null,"errors":{"name":["is >>>>> invalid"],"environment_id":["can't be blank","can't be >>>>> blank"]},"full_messages":["Name is invalid","Environment can't be >>>>> blank","Enviro >>>>> } >>>>> >>>>> which is also marked as optional.... so I'm not sure what the deal is. >>>>> I can see requiring the environment but not sure why your error is telling >>>>> you all of those values are required. Someone with more knowledge will have >>>>> to comment on this. >>>>> >>>>> >>>>> On Thu, Aug 7, 2014 at 9:55 AM, Vincent Miszczak < >>>>> vincent....@gmail.com> wrote: >>>>> >>>>>> Very usefull.... >>>>>> Children are marked optional, I don't want them. What's the point ? >>>>>> >>>>>> Le jeudi 7 août 2014 21:54:09 UTC+2, Romeo Theriault a écrit : >>>>>>> >>>>>>> Now, now, think about all the children on the list. >>>>>>> >>>>>>> >>>>>>> On Thu, Aug 7, 2014 at 7:08 AM, Vincent Miszczak < >>>>>>> vincent....@gmail.com> wrote: >>>>>>> >>>>>>>> I'm starting working with the API and have some troubles (working >>>>>>>> on 1.5.1 currently) >>>>>>>> >>>>>>>> My goal is to create a host and associate some Puppet classes with >>>>>>>> params before the machine get instantiated and registers into >>>>>>>> Foreman(later, with some external tools). I do this because I want my boot >>>>>>>> script call Puppet that will apply what I'll define using API calls to >>>>>>>> Foreman. >>>>>>>> >>>>>>>> I'm following the doc : >>>>>>>> >>>>>>>> http://theforeman.org/api.html >>>>>>>> POST /api/hosts >>>>>>>> Create a host. >>>>>>>> >>>>>>>> Params Param nameDescription *host * >>>>>>>> required >>>>>>>> Value: Must be a Hash *host[name] * >>>>>>>> required >>>>>>>> Value: Must be String *host[environment_id] * >>>>>>>> optional >>>>>>>> Value: Must be String >>>>>>>> >>>>>>>> The only required arguments are host and host['name']. >>>>>>>> >>>>>>>> So in my custom Foreman Python class I do : >>>>>>>> def createHost(self,hostname): >>>>>>>> return self.api.post("/api/hosts",{"h >>>>>>>> ost":{"name":hostname}}) >>>>>>>> >>>>>>>> And I get : >>>>>>>> {u'host': {u'errors': {u'operatingsystem_id': [u"can't be blank"], >>>>>>>> u'root_pass': [u'should be 8 characters or more', u'should not be blank - >>>>>>>> consider setting a global or host group default'], u'environment_id': >>>>>>>> [u"can't be blank"], u'ptable_id': [u'cant be blank unless a custom >>>>>>>> partition has been defined'], u'mac': [u'is invalid', u"can't be blank"], >>>>>>>> u'architecture_id': [u"can't be blank"]}, u'id': None, u'full_messages': >>>>>>>> [u"Environment can't be blank", u'MAC address is invalid', u"MAC address >>>>>>>> can't be blank", u"Architecture can't be blank", u"Operatingsystem can't be >>>>>>>> blank", u'Root password should be 8 characters or more', u'Root password >>>>>>>> should not be blank - consider setting a global or host group default', >>>>>>>> u'Partition Table cant be blank unless a custom partition has been >>>>>>>> defined']}} >>>>>>>> >>>>>>>> WTF ?! >>>>>>>> >>>>>>>> Doc says arguments are optional. >>>>>>>> API(v1 or v2) says arguments are mandatory. >>>>>>>> >>>>>>>> OFC I'll never be able to pass those arguments, I just don't know >>>>>>>> them and don't care about them. >>>>>>>> >>>>>>>> What am I doing wrong ? >>>>>>>> >>>>>>>> -- >>>>>>>> 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. >>>>>>>> >>>>>>> >>>>>>> >>>>>>> >>>>>>> -- >>>>>>> Romeo >>>>>>> >>>>>> -- >>>>>> 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. >>>>>> >>>>> >>>>> >>>>> >>>>> -- >>>>> Romeo >>>>> >>>> -- >>>> 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. >>>> >>> >>> -- >>> 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. >>> >> >> >> >> -- >> Daniel Lobato >> >> @elobatoss >> blog.daniellobato.me >> daniellobato.me >> >> GPG: http://keys.gnupg.net/pks/lookup?op=get&search=0x7A92D6DD38D6DE30 >> >