On 11/14/2016 01:01 PM, mobios wrote:
*Hi All,*
*Currently i try to automate any tasks over foreman api v2.
I want to create a usergroup, a role and any filters
I already done to create a usergroup and a role code snippet below.*
## Usergroup creation
usergroupurl="https://#{user}:#{password}@localhost/api/v2/usergroups"
def checkusergroup(usergroupurl, usergroup, user, password)
restget = RestClient.get "#{usergroupurl}"
if restget.include?(usergroup)
return true
else
return false
end
end
def setusergroup(usergroupurl, usergroup, user, password)
body = { :usergroup => {
:name => "#{usergroup}"
}
}
response = RestClient.post("#{usergroupurl}", body.to_json,
{:content_type => 'application/json', :accept => 'application/json'})
end
unless checkusergroup(usergroupurl, usergroup, user, password)
setusergroup(usergroupurl, usergroup, user, password)
end
## Role creation
rolesurl="https://#{user}:#{password}@localhost/api/v2/roles"
def checkroles(rolesurl, role, user, password)
restget = RestClient.get "#{rolesurl}"
if restget.include?(role)
return true
else
return false
end
end
def setrole(rolesurl, role, user, password)
body = { :role => {
:name => "#{role}"
}
}
response = RestClient.post("#{rolesurl}", body.to_json, {:content_type
=> 'application/json', :accept => 'application/json'})
end
unless checkroles(rolesurl, role , user, password)
setrole(rolesurl, role, user, password)
end
*_Unfortunately i have problems to create my own filter. (code below)_*
hostfilterurl="https://#{user}:#{password}@localhost/api/v2/filters/"
def sethostfilter(hostfilterurl, role, user, password)
body = { :filter => {
:role_id => "700"
}
}
response = RestClient.post("#{hostfilterurl}", body.to_json,
{:content_type => 'application/json', :accept => 'application/json'})
end
sethostfilter(hostfilterurl, role, user, password)
*/In this case i get always a errormessage./*
*/Message: 422 Unprocessable Entity/*
Hello,
check body of the error response. It contains error messages that should
give you hint about what's wrong.
Alternatively you can look into server log files
(/var/log/foreman/production.log).
BTW check out project apipie-bindings [1]. It can be helpful if you're
writing a ruby script that integrates with foreman api.
Regards
Tomas
[1] https://github.com/Apipie/apipie-bindings
Can anybody help?
Regards
mobios
Vollständigen Inhalt anzeigen
--
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 [email protected]
<mailto:[email protected]>.
To post to this group, send email to [email protected]
<mailto:[email protected]>.
Visit this group at https://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 [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/foreman-users.
For more options, visit https://groups.google.com/d/optout.