Hi All,
Currently i try to automate any tasks over foreman api v2.I want to create
a usergroup, a role and any filtersI 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
Can anybody help?
Regards
mobios
Vollständigen Inhalt anzeigen