Bug 1308830 - Include examples for high-level API bindings
Include examples for high-level API bindings
Status: CLOSED CURRENTRELEASE
Product: Red Hat Satellite 6
Classification: Red Hat
Component: Docs API Guide (Show other bugs)
6.1.6
Unspecified Unspecified
medium Severity medium (vote)
: GA
: 6.2
Assigned To: Stephen Wadeley
Lucie Jirakova
:
Depends On:
Blocks:
  Show dependency treegraph
 
Reported: 2016-02-16 04:01 EST by Evgeni Golov
Modified: 2017-01-18 01:20 EST (History)
4 users (show)

See Also:
Fixed In Version:
Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of:
Environment:
Last Closed: 2017-01-18 01:20:19 EST
Type: Bug
Regression: ---
Mount Type: ---
Documentation: ---
CRM:
Verified Versions:
Category: ---
oVirt Team: ---
RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: ---


Attachments (Terms of Use)
Apipie bindings example (1.91 KB, application/x-ruby)
2017-01-10 11:47 EST, Tomas Strachota
no flags Details

  None (edit)
Description Evgeni Golov 2016-02-16 04:01:54 EST
Document URL: 
https://access.redhat.com/documentation/en-US/Red_Hat_Satellite/6.1/html/API_Guide/chap-Red_Hat_Satellite-API_Guide-Examples.html

Section Number and Name: 
Chapter 4. Examples, all Sections

Describe the issue:
Currently the examples show how to talk to the API using "plain" Ruby and Python. While this is good and should be definitely kept, I think we also should add some higher level examples.

Suggestions for improvement: 

For Ruby I can think adding Apipie Bindings would be great.
Apipie Bindings (rubygem-apipie-bindings in sat6-tools, upstream: https://github.com/Apipie/apipie-bindings) allows to fetch the API definition from the Satellite directly and then generates proper calls on demand.
e.g. to fetch the Orgs from Satellite:
  require 'apipie-bindings'
  url = 'https://satellite6.example.com/api/'
  username = 'admin'
  password = 'changeme'
  api = ApipieBindings::API.new({:uri => url, :username => username, :password => password, :api_version => '2'})
  req = api.resource(:organizations).call(:index)
  # do something with req['results']

For Python NailGun (https://github.com/SatelliteQE/nailgun, not packaged in RHEL yet) could be a great addition (in the future).
There are a couple of good examples at https://nailgun.readthedocs.org/en/latest/examples.html

Additional information: 
Plain Ruby/Python examples should be kept as they can run "everywhere" and have no dependencies.
Comment 1 Evgeni Golov 2016-11-27 04:27:30 EST
Upstream docs are going to have this too:
http://projects.theforeman.org/issues/17469
https://github.com/theforeman/theforeman.org/pull/754
Comment 2 Evgeni Golov 2016-11-28 11:22:45 EST
And that's now live: https://theforeman.org/manuals/1.13/#5.1.9UsingApipie-Bindings
Comment 3 Stephen Wadeley 2016-11-30 04:16:41 EST
Hello

Thank you for raising this bug
Comment 4 Stephen Wadeley 2017-01-06 06:30:44 EST
Hello Tomas

As discussed in our meeting:

Please provide some APIPIE examples to match the examples we currently have in the API guide[1]

Thank you

[1] https://access.redhat.com/documentation/en/red-hat-satellite/6.2/paged/api-guide/chapter-4-getting-started-with-the-red-hat-satellite-api#sect-API_Guide-API_Examples_Using_Curl
Comment 5 Tomas Strachota 2017-01-10 11:47 EST
Created attachment 1239155 [details]
Apipie bindings example

Please find the apipie bindings examples attached.
Comment 6 Tomas Strachota 2017-01-10 11:57:44 EST
Please note that the attached examples are intended to be used with sat 6.2. Let me know if 6.1 version is needed too.

Btw I discovered the current examples in 6.2 docs are broken:
https://bugzilla.redhat.com/show_bug.cgi?id=1411892
Comment 7 Stephen Wadeley 2017-01-11 02:56:54 EST
(In reply to Tomas Strachota from comment #6)
> Please note that the attached examples are intended to be used with sat 6.2.
Thank you very much Tomas
> Let me know if 6.1 version is needed too.
I don't think that will be necessary, thank you.

> 
> Btw I discovered the current examples in 6.2 docs are broken:
> https://bugzilla.redhat.com/show_bug.cgi?id=1411892

Thank you for noticing and for raising that bug.
Comment 8 Stephen Wadeley 2017-01-11 04:24:49 EST
Hello Tomas

Please check this line is correct:

  prior_env_id = call_api(:lifecycle_environments, :create, {"name" => environment, "organization_id" => org_id, "prior_id" => prior_env_id, 'organization_id' => org_id })['id']


I ask because "organization_id" is duplicated.


Than you
Comment 9 Tomas Strachota 2017-01-11 04:40:36 EST
Nice catch, it should have been:

prior_env_id = call_api(:lifecycle_environments, :create, {"name" => environment, "organization_id" => org_id, "prior_id" => prior_env_id })['id']

It doesn't break functionality but the second organization_id is redundant. Just remove it, please.
Comment 10 Stephen Wadeley 2017-01-11 05:16:38 EST
Thank you Tomas

Another question; I want to change localhost in this bit:

# Create an instance of apipie bindings
@api = ApipieBindings::API.new({
  :uri => 'https://localhost/',
  :username => 'admin',
  :password => 'changeme',
  :api_version => 2
})

To:
https://satellite6.example.com
or
https://satellite6.example.com/katello/api/v2/

Thank you
Comment 11 Evgeni Golov 2017-01-11 05:17:27 EST
https://satellite6.example.com

the rest is auto-detected by apipie :)
Comment 12 Stephen Wadeley 2017-01-11 05:19:21 EST
(In reply to Evgeni Golov from comment #11)
> https://satellite6.example.com
> 
> the rest is auto-detected by apipie :)

thank you
Comment 15 Tomas Strachota 2017-01-11 06:06:58 EST
Stephen,
the correct version would be: 'https://satellite6.example.com/' 
Localhost is remnant from my testing.
Comment 23 Andrew Dahms 2017-01-18 01:20:19 EST
This content is now live on the Customer Portal.

Closing.

Note You need to log in before you can comment on or make changes to this bug.