Red Hat Satellite engineering is moving the tracking of its product development work on Satellite to Red Hat Jira (issues.redhat.com). If you're a Red Hat customer, please continue to file support cases via the Red Hat customer portal. If you're not, please head to the "Satellite project" in Red Hat Jira and file new tickets here. Individual Bugzilla bugs will be migrated starting at the end of May. If you cannot log in to RH Jira, please consult article #7032570. That failing, please send an e-mail to the RH Jira admins at rh-issues@redhat.com to troubleshoot your issue as a user management inquiry. The email creates a ServiceNow ticket with Red Hat. Individual Bugzilla bugs that are migrated will be moved to status "CLOSED", resolution "MIGRATED", and set with "MigratedToJIRA" in "Keywords". The link to the successor Jira issue will be found under "Links", have a little "two-footprint" icon next to it, and direct you to the "Satellite project" in Red Hat Jira (issue links are of type "https://issues.redhat.com/browse/SAT-XXXX", where "X" is a digit). This same link will be available in a blue banner at the top of the page informing you that that bug has been migrated.
Bug 1308830 - Include examples for high-level API bindings
Summary: Include examples for high-level API bindings
Keywords:
Status: CLOSED CURRENTRELEASE
Alias: None
Product: Red Hat Satellite
Classification: Red Hat
Component: Docs API Guide
Version: 6.1.6
Hardware: Unspecified
OS: Unspecified
medium
medium
Target Milestone: Unspecified
Assignee: Stephen Wadeley
QA Contact: Lucie Jirakova
URL:
Whiteboard:
Depends On:
Blocks:
TreeView+ depends on / blocked
 
Reported: 2016-02-16 09:01 UTC by Evgeni Golov
Modified: 2019-09-26 14:43 UTC (History)
4 users (show)

Fixed In Version:
Doc Type: Bug Fix
Doc Text:
Clone Of:
Environment:
Last Closed: 2017-01-18 06:20:19 UTC
Target Upstream Version:
Embargoed:


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

Description Evgeni Golov 2016-02-16 09:01:54 UTC
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 09:27:30 UTC
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 16:22:45 UTC
And that's now live: https://theforeman.org/manuals/1.13/#5.1.9UsingApipie-Bindings

Comment 3 Stephen Wadeley 2016-11-30 09:16:41 UTC
Hello

Thank you for raising this bug

Comment 4 Stephen Wadeley 2017-01-06 11:30:44 UTC
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 16:47:04 UTC
Created attachment 1239155 [details]
Apipie bindings example

Please find the apipie bindings examples attached.

Comment 6 Tomas Strachota 2017-01-10 16:57:44 UTC
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 07:56:54 UTC
(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 09:24:49 UTC
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 09:40:36 UTC
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 10:16:38 UTC
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 10:17:27 UTC
https://satellite6.example.com

the rest is auto-detected by apipie :)

Comment 12 Stephen Wadeley 2017-01-11 10:19:21 UTC
(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 11:06:58 UTC
Stephen,
the correct version would be: 'https://satellite6.example.com/' 
Localhost is remnant from my testing.

Comment 23 Andrew Dahms 2017-01-18 06:20:19 UTC
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.