API ガイド
Satellite の Representational State Transfer (REST) API 使用のためのリファレンスドキュメント
概要
第1章 Red Hat Satellite API について
1.1. Red Hat Satellite API
注記
https://satellite6.example.com/apidoc/v2.html (satellite6.example.com は Satellite サーバーのホスト名に置き換えてください) の Satellite サーバーからご利用いただけます。Satellite 6 API のバージョン 1 と 2 が提供されていますが、Red Hat がサポートしているのはバージョン 2 のみである点に注意してください。
- 幅広いクライアントサポート: HTTP 対応のあらゆるプログラミング言語/フレームワーク/システムで使用することが可能です。
- 自己記述型: 詳しい情報の多くは実行時に確認できるため、クライアントアプリケーションに必要な仮想化インフラストラクチャーの知識は最小限で済みます。
- リソースベースのモデル: リソースベースの REST モデルにより仮想化プラットフォームを自然な形で管理することが可能です。
- エンタープライズ IT システムとの統合
- サードパーティー製のアプリケーションとの統合
- 自動メンテナンスやエラーチェックなどのタスクの実行
- スクリプトによる反復タスクの自動化
1.2. Representational State Transfer
GET、POST、PUT、DELETE などの標準的な HTTP メソッドで操作を実行します。これにより、クライアントとサーバー間のステートレスな通信が提供され、各要求は他の要求に依存せずに機能し、その要求を完了するために必要な情報をすべて含みます。
1.3. Hammer CLI ツールと Satellite API の比較
hammer -d organization list など、Hammer で発行した API の呼び出しを検査するには -d オプションを使用します)。API での変更は自動的に Hammer に適用されますが、API を直接使用するスクリプトは手動で更新する必要があります。
第2章 API リファレンス
https://satellite6.example.com/apidoc/v2.html (satellite6.example.com は Satellite サーバーのホスト名に置き換えてください) の Satellite サーバーからご利用いただけます。Satellite 6 API のバージョン 1 と 2 が提供されていますが、Red Hat がサポートしているのはバージョン 2 のみである点に注意してください。
2.1. API 構文の理解
HTTP_VERB API_ROUTEなどのように、HTTP の動詞の後に API ルートまたはパスの形式となっています。API が使用する HTTP の動詞は、GET、POST、PUT、DELETE です。例については、
http://satellite6.example.com/apidoc/v2/hosts.html の API リファレンスドキュメントの HOST セクションを参照してください。API 構文および curl コマンドに精通している場合にはこの章は飛ばしてください。
curl の man ページでは curl [options] [URL...]などの基本構文が紹介されています。このガイドで使用するオプションには
-X, --request command などが含まれます。command は HTTP の動詞に置き換えてください。
HTTP 動詞 (GET) の使用
GET /api/hosts など、API HOST セクションからの例と curl 構文を組み合わせると curl -X GET https://satellite6.example.com/api/hostsといったコマンドになります。Satellite は、API への接続には HTTPS のみをサポートし、一定の形式の認証が必要です。
-u オプションで名前を、-k オプションで SSL のピア証明書検証を省略する必要があります。
$ curl -X GET -k -u sat_username https://satellite6.example.com/api/hosts
Enter host password for user 'sat_username':
{
"total": 2,
"subtotal": 2,
"page": 1,
"per_page": 20,
"search": null,
"sort": {
"by": null,
"order": null
},
"results":
出力省略
API からの上記の応答により合計の結果数が 2 つで、以下のような 2 つの結果が返されたこと、またこれは結果の 1 ページ目で、ページごとの最大結果数は 20 に設定されていることが分かります。これについては「JSON 応答形式の理解」でさらに詳しく説明しています。
:parameter などのように、コロンが先頭にきてその後に用語が含まれるというものがあります。以下に例を示します。GET /api/hosts/:idこれらは API ルートパラメーターで、適切な値に置き換える必要があります。ルートパラメーターは、コロンで始まり
id で終わります。
注記
v2 を使用する必要はありません。
HTTP 動詞 (POST) の使用
-d, --data オプションの後に、{} カッコで閉じた JSON 形式の引用データを使用してデータをインラインに含めることができます。または、引用なしの JSON 形式のデータはファイルに含めることができ、curl コマンドの @ オプションを使用して指定することができます (例: -d @file.json)。
json_verify ツールと json_reformat ツールが含まれています。
json_verify ツールを使用すると、以下のように JSON ファイルの妥当性を確認することができます。
$ json_verify < test_file.json
json.tool: curl API_call | python -m json.toolのようにパイプすることができます。または、:
curl API_call | json_reformatのように、
json_reformat ツールを使用してください。出力形式は「JSON 応答形式の理解」で説明しています。
POST /katello/api/activation_keysが含まれます。
POST /katello/api/activation_keys コマンドの形式の一例です。
curl -X POST -k -u sat_username:sat_password \ -d @file_of_json-formatted_data \ https://satellite6.example.com/katello/api/activation_keys
activation-key.json などのテストファイルを作成します。
{"organization_id":1, "name":"TestKey", "description":"Just for testing"}
$Web UI でこのエントリーを表示するには、 → の順に移動します。変更を加えた後は、ページを再読込するのを忘れないでください。curl -H "Accept:application/json,version=2" \-H "Content-Type:application/json" -X POST \-u sat_username:sat_password -k \-d @activation-key.json \https://satellite6.example.com/katello/api/activation_keys | json_reformat{ "id": 2, "name": "TestKey", "description": "Just for testing", "unlimited_hosts": true, "auto_attach": true, "content_view_id": null, "environment_id": null, "usage_count": 0, "user_id": 3, "max_hosts": null, "release_version": null, "service_level": null, "content_overrides": [ ], "organization": { "name": "Default Organization", "label": "Default_Organization", "id": 1 }, "created_at": "2017-02-16 12:37:47 UTC", "updated_at": "2017-02-16 12:37:48 UTC", "content_view": null, "environment": null, "products": null, "host_collections": [ ], "permissions": { "view_activation_keys": true, "edit_activation_keys": true, "destroy_activation_keys": true } }
HTTP 動詞 (PUT) の使用
-d, --data オプションの後に、{} カッコで閉じた JSON 形式の引用データを使用してデータをインラインに含めることができます。または、引用なしの JSON 形式のデータはファイルに含めることができ、curl コマンドの @ オプションを使用して指定することができます (例: -d @file.json)。
PUT /katello/api/activation_keys/:idのように、アクティベーションキーを更新するエントリーがあります。
curl -X PUT -k -u sat_username:sat_password \ -d @file_of_json-formatted_data \ https://satellite6.example.com/katello/api/activation_keys/:id:id は、更新するアクティベーションキーの ID に置き換えます。同じ値で PUT コマンドを複数回使用しても、エントリーは複数 作成されません。
{"organization_id":1, "name":"TestKey", "description":"Just for testing","max_hosts":"10" }
以下のコマンドを使用して、JSON ファイルに変更を適用します。
$curl -H "Accept:application/json,version=2" \-H "Content-Type:application/json" -X PUT \-u sat_username:sat_password -k \-d @activation-key.json \https://satellite6.example.com/katello/api/activation_keys/2{ "id": 2, "name": "TestKey", "description": "Just for testing", "unlimited_hosts": false, "auto_attach": true, "content_view_id": null, "environment_id": null, "usage_count": 0, "user_id": 3, "max_hosts": 10, "release_version": null, "service_level": null, "content_overrides": [ ], "organization": { "name": "Default Organization", "label": "Default_Organization", "id": 1 }, "created_at": "2017-02-16 12:37:47 UTC", "updated_at": "2017-02-16 12:46:17 UTC", "content_view": null, "environment": null, "products": null, "host_collections": [ ], "permissions": { "view_activation_keys": true, "edit_activation_keys": true, "destroy_activation_keys": true } }
HTTP 動詞 (DELETE) の使用
curl -X DELETE -k -u sat_username:sat_password \ https://satellite6.example.com/katello/api/activation_keys/:id:id は削除するアクティベーションキーの ID に置き換えます。以下に例を示します。
$curl -H "Accept:application/json,version=2" \-H "Content-Type:application/json" -X DELETE \-u admin:RedHat1! -k \https://satellite6.example.com/katello/api/activation_keys/2 | json_reformat出力省略 "started_at": "2017-02-16 12:58:17 UTC", "ended_at": "2017-02-16 12:58:18 UTC", "state": "stopped", "result": "success", "progress": 1.0, "input": { "activation_key": { "id": 2, "name": "TestKey"出力省略
API エラーメッセージと API リファレンスの関連付け
Nested_Resource.Attribute_Nameこれは、API リファレンスで使用する以下の形式に変換されます。
Resource[Nested_Resource_attributes][Attribute_Name_id]
2.2. JSON 応答形式の理解
json.tool モジュールにかけると、人間がより判読しやすい形式で出力されます。
コレクション用の JSON 応答形式
GET /api/domains を使用した場合のドメイン一覧のコレクション JSON 応答形式です。出力は、結果セクションがより簡単に確認できるように json.tool でパイプしています。
$ curl -X GET -k -u admin:password https://satellite6.example.com/api/domains | python -m json.tool
{
"total": 3,
"subtotal": 3,
"page": 1,
"per_page": 20,
"search": null,
"sort": {
"by": null,
"order": null
},
"results": [
{
"id": 23,
"name": "qa.lab.example.com",
"fullname": "QA",
"dns_id": 10,
"created_at": "2013-08-13T09:02:31Z",
"updated_at": "2013-08-13T09:02:31Z"
},
{
"id": 25,
"name": "sat.lab.example.com",
"fullname": "SATLAB",
"dns_id": 8,
"created_at": "2013-08-13T08:32:48Z",
"updated_at": "2013-08-14T07:04:03Z"
},
{
"id": 32,
"name": "hr.lab.example.com",
"fullname": "HR",
"dns_id": 8,
"created_at": "2013-08-16T08:32:48Z",
"updated_at": "2013-08-16T07:04:03Z"
}
]
}total— 検索パラメーターなしのオブジェクトの合計数subtotal— 検索パラメーターを指定して返されたオブジェクト数 (検索がない場合には、累計は合計と同じになります)page— ページ数per_page— ページごとに返す最大数limit— コレクションの応答で返すオブジェクトの指定数offset— コレクションを返す前に省略するオブジェクト数search—scoped_scopedの構文をベースにした検索文字列sortby— コレクションをソートするためのフィールドorder— ソート順 (ASC は昇順、DESC は降順)
results— オブジェクトのコレクション
単一オブジェクトの JSON 応答形式
:id または :name が必要です。:name は一意識別子として常に使用できるわけではありませんが、:id は常に使用できる点に注意してください。単一オブジェクトの JSON 応答形式には、オブジェクトの属性のみが含まれます。
GET /api/domains/23 または GET /api/domains/qa.lab.example.com を使用時の単一オブジェクト JSON 応答形式です。
$ curl -X GET -k -u admin:password https://satellite6.example.com/api/domains/23 | python -m json.tool
{
"id": 23,
"name": "qa.lab.example.com",
"fullname": "QA",
"dns_id": 10,
"created_at": "2013-08-13T09:02:31Z",
"updated_at": "2013-08-13T09:02:31Z"
}第3章 API 呼び出しの認証
3.1. SSL 認証の使用
- 以下のオプションの 1 つを使用して、通信する Satellite サーバー (satellite6.example.com) からの証明書を取得します。
- SSH を使用して証明書を取得するには、以下のコマンドを実行します。
$
scp root@satellite6.example.com:/var/www/html/pub/katello-server-ca.crt ./ - Satellite サーバーで直接コマンドを実行する場合は、以下のコマンドを実行してローカルで利用可能なコピーから証明書を取得します。
$
cp /var/www/html/pub/katello-server-ca.crt ./ - HTTP を使用して証明書を取得するには、以下のコマンドを実行します。
$
curl -O http://satellite6.example.com/pub/katello-server-ca.crt警告
暗号化されていない HTTP 接続を使用して証明書を取得すると、セキュリティーリスクにさらされる可能性があります。
- クライアント上の証明書を証明局として使用して、Satellite サーバーの ID を検証します。
$
curl -X GET -u sat_username:sat_password \-H "Accept:application/json" --cacert katello-server-ca.crt \https://satellite6.example.com/katello/api/organizationsGETはデフォルトのアクションであるため、-X GET属性はここでは省略可能です。 - Network Security Services (NSS) データベースを作成して証明書を保存します。
$
certutil -N -d sql:$HOME/.pki/nssdbEnter a password which will be used to encrypt your keys. The password should be at least 8 characters long, and should contain at least one non-alphabetic character. Enter new password: Re-enter password:NSS データベースがすでに存在する場合には、以下のようにパスワードが求められます。Enter Password or Pin for "NSS Certificate DB":
- 以下のコマンドを使用して、NSS データベースに永続的に証明書を追加します。
$
certutil -d sql:$HOME/.pki/nssdb -A -t TC -n "Red Hat Satellite" \-i katello-server-ca.crtこれで、NSS データベースに証明書がインポートされ、要求ごとに--cacertオプションを指定する必要がなくなります。これは、以下のようにテストできます。$
curl -X GET -u sat_username:sat_password https://satellite6.example.com/api/v2/hosts{ "total": 2, ..., "results": [ ... ] }出力省略
3.2. HTTP 認証の使用
重要
3.3. OAuth 認証の使用
3.3.1. OAuth の認証
/etc/foreman/settings.yaml の設定ファイルに保存されており、 → → の順に移動して Web UI から表示できます。 とは、すべての OAuth クライアントが使用するトークンのことです。Web UI の特定の値は変更できません。これらの値は satellite-installer スクリプトに新しいオプションをもう一度指定して実行することでのみ変更可能です。ファイルを手動で変更した内容はアップグレード時に失われてしまう点に注意してください。以下のコマンドを実行して、OAuth 関連のインストーラーオプションすべてを表示します。
# satellite-installer --full-help | grep oauth
/etc/foreman/settings.yaml の を false に設定します。要求を行ったユーザーを指定するには、この設定オプションを true に設定します。これにより、クライアントは FOREMAN-USER ヘッダーに既存の Foreman ユーザーのログインを指定して送信することができます。
重要
3.3.2. OAuth 要求の作成
curl を使用した OAuth 要求がどのように機能するか理解いただけるように一例を紹介しています。
例3.1 OAuth 要求の例: curl の使用
$上記の例では、アーキテクチャーが OAuth を使用してリストされ、認証されます。この要求は、User1 のユーザーとしてログインを試行します。マッピングが Foreman の設定で有効な場合、結果にはユーザー User1 のみに表示可能なアーキテクチャーのみが含まれます。署名が手動で作成された場合には、curl 'https://satellite6.example.com/api/architectures' \-H 'Content-Type: application/json' \-H 'Accept: application/json,version=2' \-H 'FOREMAN-USER: User1' \-H 'Authorization: OAuth oauth_version="1.0",oauth_consumer_key="secretkey",oauth_signature_method="hmac-sha1",oauth_timestamp=1321473112,oauth_signature=Il8hR8/ogj/XVuOqMPB9qNjSy6E='
oauth_timestamp を変更すると変更されるはずです。また、署名はすべてのパラメーター、HTTP メソッド、URI の変更に反映されます。そのため、OAuth クライアントライブラリーを使用して OAuth パラメーターを構築することを推奨します。
第4章 Red Hat Satellite API の使用開始
url = 'https://satellite6.example.com/api/v2/' capsule_url = 'https://capsule.example.com:8443/api/v2/' katello_url = 'https://satellite6.example.com/katello/api/v2/'
/etc/rhsm/rhsm.conf ファイルにある [server] セクションの port エントリーをもとに、API にアクセスする際に必要な、正しいポートを判断することができます。これらの値を使用して、スクリプトを完全に自動化して、使用するポートを検証する必要性をなくすことができます。
4.1. curl を使用した API の例
curl を使用して Satellite API でさまざまなタスクを実行する方法について説明します。
4.1.1. シンプルなクエリーの実行
curl を使用して Satellite デプロイメントの情報を検索する方法を説明します。以下の例には、実際のコマンドと、サンプルの出力、ユーザー名やパスワードの値の例などが含まれます。デプロイメントごとに結果は異なります。また、以下の例では python -m json.tool コマンドを使用して出力をフォーマットしています。
注記
-k (セキュアではありません) オプションを使用して証明書チェックを省略することができます。
-u username:password の形式を使用するか、パスワードを追加していない場合にはコマンドでパスワードの入力が求められます。コマンドの一部としてパスワードを追加すると shell の履歴に残り、セキュリティーリスクとなる可能性があるため、Red Hat ではこれは推奨していません。以下の例では、単純化の目的としてのみ、パスワードをコマンドに含めています。
curl で -s (サイレント) オプションを使用する場合は、進捗バーやエラーメッセージが表示されないので注意してください。
以下は、リソースの一覧を返す基本的なクエリーです。このような要求は、メタデータでラップされたデータ一覧を返しますが、他の要求タイプでは実際のオブジェクトのみを返します。
$ curl -X GET -s -k -u sat_username:sat_password https://satellite6.example.com/api/v2/hosts | python -m json.tool
{
"total" => 2,
"subtotal" => 2,
"page" => 1,
"per_page" => 1000,
"search" => nil,
"sort" => {
"by" => nil,
"order" => nil
},
"results" => [
...
}
例4.1 ユーザーの一覧表示
$ curl -X GET -s -k -u sat_username:sat_password https://satellite6.example.com/api/users
{
"total": 1,
"subtotal": 1,
"page": 1,
"per_page": 20,
"search": null,
"sort": {
"by": null,
"order": null
},
"results": [{"firstname":"Admin","lastname":"User","mail":"root@example.com","admin":true,"auth_source_id":1,"auth_source_name":"Internal","timezone":null,"locale":null,"last_login_on":"2017-02-08 23:25:51 UTC","created_at":"2017-01-09 12:10:02 UTC","updated_at":"2017-02-08 23:25:51 UTC","id":3,"login":"admin","default_location":null,"locations":[],"default_organization":{"id":1,"name":"Default Organization","title":"Default Organization","description":null},"organizations":[]}]
}
以下のクエリーは、ホスト satellite6.example.com の情報を返します。
$ curl -X GET -s -k -u sat_username:sat_password https://satellite6.example.com/api/v2/hosts/satellite6.example.com | python -m json.tool
{
"all_puppetclasses": [],
"architecture_id": 1,
"architecture_name": "x86_64",
"build": false,
"capabilities": [
"build"
],
"certname": "satellite6.example.com",
"comment": null,
"compute_profile_id": null,
...
}
以下のクエリーは、ホスト satellite6.example.com の全ファクトを返します。
$ curl -X GET -s -k -u sat_username:sat_password https://satellite6.example.com/api/v2/hosts/satellite6.example.com/facts | python -m json.tool
{
...
"results": {
"satellite6.example.com": {
"augeasversion": "1.0.0",
"bios_release_date": "01/01/2007",
"bios_version": "0.5.1",
"blockdevice_sr0_size": "1073741312",
"facterversion": "1.7.6",
...
}以下のクエリーは、「example」というパターンと一致するホストすべてを返します。
$ curl -X GET -s -k -u sat_username:sat_password https://satellite6.example.com/api/v2/hosts?search=example | python -m json.tool
{
...
"results": [
{
"name": "satellite6.example.com",
...
}
],
"search": "example",
...
}以下のクエリーは、「production」環境内の全ホストを返します。
$ curl -X GET -s -k -u sat_username:sat_password https://satellite6.example.com/api/v2/hosts?search=environment=production | python -m json.tool
{
...
"results": [
{
"environment_name": "production",
"name": "satellite6.example.com",
...
}
],
"search": "environment=production",
...
}以下のクエリーでは、「RHEV Hypervisor」というモデル名を持つホストすべてが返されます。
$ curl -X GET -s -k -u sat_username:sat_password https://satellite6.example.com/api/v2/hosts?search=model=\"RHEV+Hypervisor\" | python -m json.tool
{
...
"results": [
{
"model_id": 1,
"model_name": "RHEV Hypervisor",
"name": "satellite6.example.com",
...
}
],
"search": "model=\"RHEV Hypervisor\"",
...
}
4.1.2. リソースの作成および変更
Accept:version=2 を使用するのと同じです。URL の指定が優先されます。
$ curl -H "Accept:application/json,version=2" \
-H "Content-Type:application/json" -X POST \
-u username:password -k \
-d json-formatted-data https://satellite6.example.com
$ curl -H "Accept:application/json,version=2" \
-H "Content-Type:application/json" -X POST -u sat_username:sat_password \
-k -d "{\"architecture\":{\"name\":\"i686\"}}" \
https://satellite6.example.com/api/architectures{"name":"i686","id":3,"created_at":"2015-10-29T13:21:09Z","updated_at":"2015-10-29T13:21:09Z","operatingsystems":[],"images":[]}$ curl -X GET -u sat_username:sat_password -k https://satellite6.example.com/api/v2/architectures | python -m json.tool
{
"page": 1,
"per_page": 20,
"results": [
{
"created_at": "2015-04-02T05:29:46Z",
"id": 2,
"name": "i386",
"updated_at": "2015-04-02T05:29:46Z"
},
{
"created_at": "2015-04-02T05:29:46Z",
"id": 1,
"name": "x86_64",
"updated_at": "2015-04-02T05:29:46Z"
},
{
"created_at": "2015-11-04T19:40:15Z",
"id": 3,
"name": "i686",
"updated_at": "2015-11-04T19:40:15Z"
}
],
"search": null,
"sort": {
"by": null,
"order": null
},
"subtotal": 3,
"total": 3
}hammer を使用して結果を検証することも可能です。
$ hammer -u sat_username -p sat_password architecture list ---|------- ID | NAME ---|------- 2 | i386 1 | x86_64 3 | i686 ---|-------
例4.2 新しいユーザーの作成
$curl -H "Accept:application/json,version=2" \-H "Content-Type:application/json" -X POST \-u sat_username:sat_password -k \-d "{\"firstname\":\"Test\",\"lastname\":\"API-User\",\"mail\":\"test@example.com\",\"login\":\"test_api\",\"password\":\"123456\",\"auth_source_id\":1}" \https://satellite6.example.com/api/users
4.1.2.1. Satellite サーバーへのコンテンツのアップロード
curl を使用して、Satellite サーバーに大容量ファイルをアップロードしてインポートする方法を説明します。このプロセスには 4 つの手順が含まれます。
- アップロード要求を作成します。
- コンテンツをアップロードします。
- コンテンツをインポートします。
- アップロード要求を削除します。
手順4.1 Satellite サーバーへのコンテンツのアップロード
- アップロード要求を作成します。デプロイメントに適したサンプルパラメーターを変更するようにしてください。
$ curl -H "Accept:application/json,version=2" \ -H "Content-Type:application/json" \ -X POST \ -u sat_username:sat_password -k -d "{}" \ https://satellite6.example.com/katello/api/repositories/3/content_uploadsこのコマンドは、以下のようなupload_idを返します。{"upload_id":"0be156b1-f373-4cad-89d0-924f8f4491d2","_href":"/pulp/api/v2/content/uploads/0be156b1-f373-4cad-89d0-924f8f4491d2/"} - コンテンツをアップロードします。データのアップロード時には、正しい MIME タイプを使用していることを確認します。Satellite 6 に対する要求にはほぼ、「application/json」の MIME タイプが使用されます。
upload_idと MIME タイプ、他のパラメーターを組み合わせてコンテンツをアップロードします。$ curl -H "Accept:application/json,version=2" \ -H "Content-Type:multipart/form-data" \ -X PUT \ -u sat_username:sat_password \ -k --data-urlencode "content@/home/sat6user/rpmbuild/RPMS/noarch/python-scripttest-1.1.1-1.fc21.noarch.rpm" \ --data-urlencode offset=0 \ https://satellite6.example.com/katello/api/repositories/3/content_uploads/0be156b1-f373-4cad-89d0-924f8f4491d2 - Satellite サーバーにコンテンツをアップロードした後に、適切なリポジトリーにそのコンテンツをインポートする必要があります。この手順を完了するまで、Satellite サーバーではこの新しいコンテンツは認識されません。
$ curl -H "Accept:application/json,version=2" \ -H "Content-Type:application/json" \ -X PUT \ -u sat_username:sat_password \ -k -d "{\"upload_ids\":[\"0be156b1-f373-4cad-89d0-924f8f4491d2\"]}" \ https://satellite6.example.com/katello/api/repositories/3/import_uploads - コンテンツのアップロードおよびインポートが正常に完了したら、アップロード要求を削除することができます。削除することで、アップロード中に使用した一時的なディスク領域を解放することができます。
$ curl -H "Accept:application/json,version=2" \ -H "Content-Type:application/json" \ -X DELETE -d "{}" \ -u sat_username:sat_password \ -k https://satellite6.example.com/katello/api/repositories/3/content_uploads/0be156b1-f373-4cad-89d0-924f8f4491d2
例4.3 30 MB よりも大きいコンテンツのアップロード
- サンプルモジュールをダウンロードします。
$ wget https://forgeapi.puppetlabs.com/v3/files/theforeman-foreman-5.0.1.tar.gz?_ga=1.267255502.1792403825.1430297670 -O theforeman-foreman-5.0.1.tar.gz
50,000 バイトのチャンクにモジュールを分割します。$ split --bytes 50000 --numeric-suffixes --suffix-length=1 theforeman-foreman-5.0.1.tar.gz foreman_module.
結果ファイルを表示します。$ ls -la theforeman-foreman-5.0.1.tar.gz foreman_module.* -rw-r--r--. 1 root root 50000 Nov 4 04:42 foreman_module.0 -rw-r--r--. 1 root root 32928 Nov 4 04:42 foreman_module.1 -rw-r--r--. 1 root root 82928 Nov 4 04:41 theforeman-foreman-5.0.1.tar.gz
- 新規アップロード要求を作成します (これは Satellite サーバーでの
catと同じです)。$ curl -H "Accept:application/json,version=2" \ -H "Content-Type:application/json" \ -X POST \ -u sat_username:sat_password -k -d "{}" \ https://ibm-vm01.example.com/katello/api/repositories/2/content_uploads上記のコマンドはアップロード ID を返します。{"upload_id":"9585528f-07ad-4bb1-9c80-ccece249b2b7","_href":"/pulp/api/v2/content/uploads/9585528f-07ad-4bb1-9c80-ccece249b2b7/"} - 手順 1 で作成したファイルのチャンクをアップロードします。以下の例で
offsetパラメーターを使用して、ファイルサイズと関連付けている点に注意してください。$ curl -H "Accept:application/json,version=2" \ -H "Content-Type:multipart/form-data" \ -X PUT \ -u sat_username:sat_password \ -k --data-urlencode "content@foreman_module.0" \ --data-urlencode offset=0 \ https://ibm-vm01.example.com/katello/api/repositories/2/content_uploads/9585528f-07ad-4bb1-9c80-ccece249b2b7$ curl -H "Accept:application/json,version=2" \ -H "Content-Type:multipart/form-data" \ -X PUT \ -u sat_username:sat_password \ -k --data-urlencode "content@foreman_module.1" \ --data-urlencode offset=50000 \ https://ibm-vm01.example.com/katello/api/repositories/2/content_uploads/9585528f-07ad-4bb1-9c80-ccece249b2b7 - 完全なアップロードをリポジトリーにインポートします。
$ curl -H "Accept:application/json,version=2" \ -H "Content-Type:application/json" \ -X PUT \ -u sat_username:sat_password \ -k -d "{\"upload_ids\":[\"9585528f-07ad-4bb1-9c80-ccece249b2b7\"]}" \ https://ibm-vm01.example.com/katello/api/repositories/2/import_uploads - アップロード要求を削除します。
$ curl -H "Accept:application/json,version=2" \ -H "Content-Type:application/json" \ -X DELETE -d "{}" \ -u sat_username:sat_password \ -k https://ibm-vm01.example.com/katello/api/repositories/2/content_uploads/9585528f-07ad-4bb1-9c80-ccece249b2b7 - Satellite サーバーにログインして、ファイルが正しく転送されたかどうかを確認します。
$ ls -la /var/lib/pulp/content/puppet_module/theforeman-foreman-5.0.1.tar.gz -rw-r--r--. 1 apache apache 82928 Nov 4 04:55 /var/lib/pulp/content/puppet_module/theforeman-foreman-5.0.1.tar.gz
ファイルを比較します。$ cmp /var/lib/pulp/content/puppet_module/theforeman-foreman-5.0.1.tar.gz theforeman-foreman-5.0.1.tar.gz
$ echo $? 0
4.1.3. スマートクラスのオーバーライド
https://satellite6.example.com/apidoc/v2/smart_class_parameters/update.html にある同梱の API リファレンスで確認できます。
GET /api/smart_class_parameters のようになります。curl を使用する場合はコマンドは以下のようになります。
$5 など、Puppet クラス ID が分かる場合には、以下のように範囲を絞り込むことができます。curl -X GET -s -k -u sat_username:sat_password \https://satellite6.example.com/api/smart_class_parameters
$ curl -X GET -s -k -u sat_username:sat_password https://satellite6.example.com/api/puppetclasses/5/smart_class_parameters
puppetclass_name と key の 2 つで、特定のパラメーターの検索が可能になります。たとえば、-d, --data オプションを使用して URL のエンコードデータを渡すことができます。
$ curl -X GET -s -k -u sat_username:sat_password https://satellite6.example.com/api/smart_class_parameters -d 'search=puppetclass_name = access_insights_client and key = authmethod'
標準のスコープ指定の検索構文はサポートされています。
GET /api/smart_class_parameters/63 です。curl を使用する場合はコマンドは以下のようになります。
$これで、PUT 呼び出しでパラメーターの値をオーバーライドすることができます。curl -X GET -s -k -u sat_username:sat_password \https://satellite6.example.com/api/smart_class_parameters/63
$パラメーターを手動で作成または削除する方法はありません。属性の変更のみが可能です。パラメーターは、プロキシーからクラスをインポートすることでのみ作成、削除されます。curl -H "Accept:application/json,version=2" \-H "Content-Type:application/json" -X PUT \-s -k -u sat_username:sat_password \-d '{"smart_class_parameter":{"override":true}}' \https://satellite6.example.com/api/smart_class_parameters/63
$API 呼び出しの全パラメーターに関する情報はcurl -H "Accept:application/json,version=2" \-H "Content-Type:application/json" -X PUT \-s -k -u sat_username:sat_password \-d '{"smart_class_parameter":{"override_value":{"match":"hostgroup=Test","value":"2.4.6"}}}' \https://satellite6.example.com/api/smart_class_parameters/63
https://satellite6.example.com/apidoc/v2/override_values.html で参照してください。
$curl -X DELETE -s -u sat_username:sat_password \https://satellite6.example.com/api/smart_class_parameters/63/override_values/3
4.1.3.1. 外部ファイルを使用したスマートクラスパラメーターの変更
手順4.2 外部ファイルを使用したスマートクラスパラメーターの変更
- 今回は
motdという名前で Puppet クラスを検索します。$
curl -H "Accept:application/json,version=2" \-H "Content-Type:application/json" -X GET \-u sat_user:sat_passwd -k \"https://satellite6.example.com/api/smart_class_parameters?search=puppetclass_name=motd” \| python -m json.tool{ "page": 1, "per_page": 20, "results": [ { "avoid_duplicates": false, "created_at": "2017-02-06 12:37:48 UTC", "default_value": "", "description": "", "hidden_value": "*****", "hidden_value?": false, "id": 3, "merge_default": false, "merge_overrides": false, "override": false, "override_value_order": "fqdn\nhostgroup\nos\ndomain", "override_values_count": 0, "parameter": "content", "parameter_type": "string", "puppetclass_id": 3, "puppetclass_name": "motd", "required": false, "updated_at": "2017-02-07 13:08:42 UTC", "use_puppet_default": false, "validator_rule": null, "validator_type": "" }, { "avoid_duplicates": false, "created_at": "2017-02-06 12:37:48 UTC", "default_value": true, "description": "", "hidden_value": "*****", "hidden_value?": false, "id": 1, "merge_default": false, "merge_overrides": false, "override": false, "override_value_order": "fqdn\nhostgroup\nos\ndomain", "override_values_count": 0,"parameter": "dynamic_motd", "parameter_type": "boolean", "puppetclass_id": 3, "puppetclass_name": "motd", "required": false, "updated_at": "2017-02-06 15:21:06 UTC", "use_puppet_default": null, "validator_rule": null, "validator_type": null }, { "avoid_duplicates": false, "created_at": "2017-02-06 12:37:48 UTC", "default_value": "", "description": "", "hidden_value": "*****", "hidden_value?": false, "id": 2, "merge_default": false, "merge_overrides": false, "override": false, "override_value_order": "fqdn\nhostgroup\nos\ndomain", "override_values_count": 0, "parameter": "template", "parameter_type": "string", "puppetclass_id": 3, "puppetclass_name": "motd", "required": false, "updated_at": "2017-02-06 15:21:06 UTC", "use_puppet_default": null, "validator_rule": null, "validator_type": null } ], "search": "puppetclass_name=motd", "sort": { "by": null, "order": null }, "subtotal": 3, "total": 66 }スマートクラスパラメーターはそれぞれ、同じ Satellite インスタンスにおいてグローバルな ID となっています。motdクラスのcontentパラメーターは、この Satellite サーバーではid=3です。この ID は、Puppet クラス名の前に表示される Puppet クラス ID と間違わないようにしてください。 - パラメーター ID
3を使用して、motdパラメーター固有の情報を取得して、出力をoutput_file.jsonなどのファイルにリダイレクトします。$
curl -H "Accept:application/json,version=2" \-H "Content-Type:application/json" -X GET \-u sat_user:sat_passwd -k \"https://satellite6.example.com/api/smart_class_parameters/3 \| python -m json.tool > output_file.json - 以前の手順で作成したファイルを
changed_file.jsonという新しいファイルにコピーして編集します。エディターでファイルを開き、任意の値に変更します。以下の例では、motdモジュールのコンテンツパラメーターを変更します。この際、overrideオプションをfalseからtrueに変更する必要があります。{ "avoid_duplicates": false, "created_at": "2017-02-06 12:37:48 UTC", # This line must be removed. "default_value": "", # A new value should be supplied here. "description": "", "hidden_value": "*****", "hidden_value?": false, "id": 3, "merge_default": false, "merge_overrides": false, "override": false, # The override value must be set totrue. "override_value_order": "fqdn\nhostgroup\nos\ndomain", "override_values": [], # This line must be removed. "override_values_count": 0, "parameter": "content", "parameter_type": "string", "puppetclass_id": 3, "puppetclass_name": "motd", "required": false, "updated_at": "2017-02-07 11:56:55 UTC", # This line must be removed. "use_puppet_default": false, "validator_rule": null, "validator_type": "" } - ファイルの編集後に、以下のようになっていることを確認して、変更を保存します。
{ "avoid_duplicates": false, "default_value": "No Unauthorized Access Allowed", "description": "", "hidden_value": "*****", "hidden_value?": false, "id": 3, "merge_default": false, "merge_overrides": false, "override": true, "override_value_order": "fqdn\nhostgroup\nos\ndomain", "override_values_count": 0, "parameter": "content", "parameter_type": "string", "puppetclass_id": 3, "puppetclass_name": "motd", "required": false, "use_puppet_default": false, "validator_rule": null, "validator_type": "" } - 以下のように PUT コマンドを使用して、Satellite サーバーに変更を適用します。
$
curl -H "Accept:application/json,version=2" \-H "Content-Type:application/json" \-X PUT -u $user:$passwd \-d @changed_file.json \-k "https://satellite6.example.com/api/smart_class_parameters/3
4.1.4. エラータのホストまたはホストコレクションへの適用
curl を使用して、エラータをホスト、ホストグループまたはホストコレクションに適用することができます。以下は、PUT 要求の基本的な構文です。
$ curl -H "Accept:application/json,version=2" \
-H "Content-Type:application/json" -X PUT \
-u sat_username:sat_password -k \
-d json-formatted-data https://satellite6.example.com
https://satellite6.example.com/apidoc/v2.html) を参照してエラータの適用に使用する URL を検索します。Satellite Web UI を使用すると、検索クエリー形式の検索に役立ちます。 → の順に移動して、ホストコレクションを選択します。 → に移動して、検索クエリーボックスに注目します。たとえば my-collection と呼ばれるホストコレクションでは、検索ボックスに host_collection="my-collection" が含まれます。以下のホストコレクションの例では、これを使用します。
例4.4 ホストへのエラータの適用
/katello/api/hosts/bulk/install_content を使用して単純な検索に必要な形式を表示します。
$ curl -H "Accept:application/json,version=2" \
-H "Content-Type:application/json" -X PUT \
-u sat_username:sat_password -k \
-d "{\"organization_id\":1,\"included\":{\"search\":\"my-host\"},\"content_type\":\"errata\",\"content\":[\"RHBA-2016:1981\"]}" https://satellite6.example.com/api/v2/hosts/bulk/install_content
例4.5 ホストコレクションへのエラータの適用
host_collection="my-collection" を渡すのに必要なエスケープレベルに注目してください。
$ curl -H "Accept:application/json,version=2" \
-H "Content-Type:application/json" -X PUT \
-u sat_username:sat_password -k \
-d "{\"organization_id\":1,\"included\":{\"search\":\"host_collection=\\\"my-collection\\\"\"},\"content_type\":\"errata\",\"content\":[\"RHBA-2016:1981\"]}" https://satellite6.example.com/api/v2/hosts/bulk/install_content
4.2. Ruby を使用した API の例
重要
4.2.1. Ruby を使用したオブジェクトの作成
#!/usr/bin/ruby
require 'rest-client'
require 'json'
url = 'https://satellite6.example.com/api/v2/'
katello_url = "#{url}/katello/api/v2/"
$username = 'admin'
$password = 'changeme'
org_name = "MyOrg"
environments = [ "Development", "Testing", "Production" ]
# Performs a GET using the passed URL location
def get_json(location)
response = RestClient::Request.new(
:method => :get,
:url => location,
:user => $username,
:password => $password,
:headers => { :accept => :json,
:content_type => :json }
).execute
JSON.parse(response.to_str)
end
# Performs a POST and passes the data to the URL location
def post_json(location, json_data)
response = RestClient::Request.new(
:method => :post,
:url => location,
:user => $username,
:password => $password,
:headers => { :accept => :json,
:content_type => :json},
:payload => json_data
).execute
JSON.parse(response.to_str)
end
# Creates a hash with ids mapping to names for an array of recods
def id_name_map(records)
records.inject({}) do |map, record|
map.update(record['id'] => record['name'])
end
end
# Get list of existing organizations
orgs = get_json("#{katello_url}/organizations")
org_list = id_name_map(orgs['results'])
if !org_list.has_value?(org_name)
# If our organization is not found, create it
puts "Creating organization: \t#{org_name}"
org_id = post_json("#{katello_url}/organizations", JSON.generate({"name"=> org_name}))["id"]
else
# Our organization exists, so let's grab it
org_id = org_list.key(org_name)
puts "Organization \"#{org_name}\" exists"
end
# Get list of organization's lifecycle environments
envs = get_json("#{katello_url}/organizations/#{org_id}/environments")
env_list = id_name_map(envs['results'])
prior_env_id = env_list.key("Library")
# Exit the script if at least one life cycle environment already exists
environments.each do |e|
if env_list.has_value?(e)
puts "ERROR: One of the Environments is not unique to organization"
exit
end
end
# Create life cycle environments
environments.each do |environment|
puts "Creating environment: \t#{environment}"
prior_env_id = post_json("#{katello_url}/organizations/#{org_id}/environments", JSON.generate({"name" => environment, "organization_id" => org_id, "prior_id" => prior_env_id}))["id"]
end
4.2.2. Apipie バインディングの使用
#!/usr/bin/ruby
require 'apipie-bindings'
org_name = "MyOrg"
environments = [ "Development", "Testing", "Production" ]
# Create an instance of apipie bindings
@api = ApipieBindings::API.new({
:uri => 'https://satellite6.example.com/',
:username => 'admin',
:password => 'changeme',
:api_version => 2
})
# Performs an API call with default options
def call_api(resource_name, action_name, params = {})
http_headers = {}
apipie_options = { :skip_validation => true }
@api.resource(resource_name).call(action_name, params, http_headers, apipie_options)
end
# Creates a hash with IDs mapping to names for an array of records
def id_name_map(records)
records.inject({}) do |map, record|
map.update(record['id'] => record['name'])
end
end
# Get list of existing organizations
orgs = call_api(:organizations, :index)
org_list = id_name_map(orgs['results'])
if !org_list.has_value?(org_name)
# If our organization is not found, create it
puts "Creating organization: \t#{org_name}"
org_id = call_api(:organizations, :create, {'organization' => { :name => org_name }})['id']
else
# Our organization exists, so let's grab it
org_id = org_list.key(org_name)
puts "Organization \"#{org_name}\" exists"
end
# Get list of organization's life cycle environments
envs = call_api(:lifecycle_environments, :index, {'organization_id' => org_id})
env_list = id_name_map(envs['results'])
prior_env_id = env_list.key("Library")
# Exit the script if at least one life cycle environment already exists
environments.each do |e|
if env_list.has_value?(e)
puts "ERROR: One of the Environments is not unique to organization"
exit
end
end
# Create life cycle environments
environments.each do |environment|
puts "Creating environment: \t#{environment}"
prior_env_id = call_api(:lifecycle_environments, :create, {"name" => environment, "organization_id" => org_id, "prior_id" => prior_env_id })['id']
end
4.3. Python を使用した API の例
重要
4.3.1. Python を使用したオブジェクトの作成
#!/usr/bin/python
import json
import sys
try:
import requests
except ImportError:
print "Please install the python-requests module."
sys.exit(-1)
# URL to your Satellite 6 server
URL = "https://satellite6.example.com"
# URL for the API to your deployed Satellite 6 server
SAT_API = "%s/katello/api/v2/" % URL
# Katello-specific API
KATELLO_API = "%s/katello/api/" % URL
POST_HEADERS = {'content-type': 'application/json'}
# Default credentials to login to Satellite 6
USERNAME = "admin"
PASSWORD = "changeme"
# Ignore SSL for now
SSL_VERIFY = False
# Name of the organization to be either created or used
ORG_NAME = "MyOrg"
# Name for life cycle environments to be either created or used
ENVIRONMENTS = ["Development", "Testing", "Production"]
def get_json(location):
"""
Performs a GET using the passed URL location
"""
r = requests.get(location, auth=(USERNAME, PASSWORD), verify=SSL_VERIFY)
return r.json()
def post_json(location, json_data):
"""
Performs a POST and passes the data to the URL location
"""
result = requests.post(
location,
data=json_data,
auth=(USERNAME, PASSWORD),
verify=SSL_VERIFY,
headers=POST_HEADERS)
return result.json()
def main():
"""
Main routine that creates or re-uses an organization and
life cycle environments. If life cycle environments already
exist, exit out.
"""
# Check if our organization already exists
org = get_json(SAT_API + "organizations/" + ORG_NAME)
# If our organization is not found, create it
if org.get('error', None):
org_id = post_json(
SAT_API + "organizations/",
json.dumps({"name": ORG_NAME}))["id"]
print "Creating organization: \t" + ORG_NAME
else:
# Our organization exists, so let's grab it
org_id = org['id']
print "Organization '%s' exists." % ORG_NAME
# Now, let's fetch all available life cycle environments for this org...
envs = get_json(
SAT_API + "organizations/" + str(org_id) + "/environments/")
# ... and add them to a dictionary, with respective 'Prior' environment
prior_env_id = 0
env_list = {}
for env in envs['results']:
env_list[env['id']] = env['name']
prior_env_id = env['id'] if env['name'] == "Library" else prior_env_id
# Exit the script if at least one life cycle environment already exists
if all(environment in env_list.values() for environment in ENVIRONMENTS):
print "ERROR: One of the Environments is not unique to organization"
sys.exit(-1)
# Create life cycle environments
for environment in ENVIRONMENTS:
new_env_id = post_json(
SAT_API + "organizations/" + str(org_id) + "/environments/",
json.dumps(
{
"name": environment,
"organization_id": org_id,
"prior": prior_env_id}
))["id"]
print "Creating environment: \t" + environment
prior_env_id = new_env_id
if __name__ == "__main__":
main()
4.3.2. Python を使用したクエリーの実行
sat6api.py という実行可能なファイルを作成して、以下の内容を追加します。
#!/usr/bin/python
import json
import sys
try:
import requests
except ImportError:
print "Please install the python-requests module."
sys.exit(-1)
SAT_API = 'https://satellite6.example.com/api/v2/'
USERNAME = "admin"
PASSWORD = "password"
SSL_VERIFY = False # Ignore SSL for now
def get_json(url):
# Performs a GET using the passed URL location
r = requests.get(url, auth=(USERNAME, PASSWORD), verify=SSL_VERIFY)
return r.json()
def get_results(url):
jsn = get_json(url)
if jsn.get('error'):
print "Error: " + jsn['error']['message']
else:
if jsn.get('results'):
return jsn['results']
elif 'results' not in jsn:
return jsn
else:
print "No results found"
return None
def display_all_results(url):
results = get_results(url)
if results:
print json.dumps(results, indent=4, sort_keys=True)
def display_info_for_hosts(url):
hosts = get_results(url)
if hosts:
for host in hosts:
print "ID: %-10d Name: %-30s IP: %-20s OS: %-30s" % (host['id'], host['name'], host['ip'], host['operatingsystem_name'])
def main():
host = 'satellite6.example.com'
print "Displaying all info for host %s ..." % host
display_all_results(SAT_API + 'hosts/' + host)
print "Displaying all facts for host %s ..." % host
display_all_results(SAT_API + 'hosts/%s/facts' % host)
host_pattern = 'example'
print "Displaying basic info for hosts matching pattern '%s'..." % host_pattern
display_info_for_hosts(SAT_API + 'hosts?search=' + host_pattern)
environment = 'production'
print "Displaying basic info for hosts in environment %s..." % environment
display_info_for_hosts(SAT_API + 'hosts?search=environment=' + environment)
model = 'RHEV Hypervisor'
print "Displaying basic info for hosts with model name %s..." % model
display_info_for_hosts(SAT_API + 'hosts?search=model="' + model + '"')
if __name__ == "__main__":
main()./sat6api.py を実行して、結果を表示することができます。
4.4. 詳細検索の使用
os_description で、以下のように API クエリーで使用することができます。
$ curl -s -k -u sat_username:sat_password https://satellite6.example.com/api/v2/hosts?search=os_description=\"RHEL+Server+6.6\" | python -m json.tool
{
...
"results": [
{
"name": "satellite6.example.com",
"operatingsystem_id": 1,
"operatingsystem_name": "RHEL Server 6.6",
...
}
],
"search": "os_description=\"RHEL Server 6.6\"",
}
4.5. ページネーション制御のある検索の使用
per_page および page ページネーションパラメーターを使用して、API 検索クエリーが返す検索結果を絞り込むことができます。per_page パラメーターは、ページごとの項目数を指定し、page パラメーターは、per_page パラメーターで算出された数値をもとにどのページを返すかを指定します。
page パラメーターが指定されている場合にはper_page のデフォルト値は 20 が適用されます。
例4.6 コンテンツビューの表示
$ curl -X GET --user sat_username:sat_password \ "https://satellite6.example.com/katello/api/content_views?per_page=10&page=3"
例4.7 アクティベーションキーの表示
$ curl -X GET --user sat_username:sat_password \ "https://satellite6.example.com/katello/api/activation_keys?organization_id=1&per_page=30&page=2"
例4.8 複数ページを返す設定
$ for i in `seq 1 3`; do curl -X GET --user sat_username:sat_password \ "https://satellite6.example.com/katello/api/content_views?per_page=5&page=$i"; done
4.6. ライフサイクル環境との作業
prior_id パラメーターを使用します。
https://satellite6.example.com/apidoc/v2/lifecycle_environments.html でライフサイクル環境に関する同梱の API リファレンスを参照できます。API ルートには、/katello/api/environments および /katello/api/organizations/:organization_id/environments が含まれます。
1 に対する現在のライフサイクル環境すべてを以下のように表示することができます。
$curl -H "Accept:application/json,version=2" \-H "Content-Type:application/json" -X GET \-u sat_user:sat_password -k \https://satellite6.example.com/katello/api/organizations/1/environments | python -m json.tool
出力省略 "description": null, "id": 1, "label": "Library", "library": true, "name": "Library", "organization": { "id": 1, "label": "Default_Organization", "name": "Default Organization" }, "permissions": { "destroy_lifecycle_environments": false, "edit_lifecycle_environments": true, "promote_or_remove_content_views_to_environments": true, "view_lifecycle_environments": true }, "prior": null, "successor": null, 出力省略
1 のデフォルトのライブラリー環境 が、ライフサイクル環境作成の開始点として使用されています。
手順4.3 ライフサイクル環境のリンク作成
- 開始点として使用する既存のライフサイクル環境を選択します。その ID を使用して環境を表示します。今回の例では、ID が
1の環境を使用します。$
curl -X GET -s -k -u sat_user:sat_password \https://satellite6.example.com/katello/api/environments/1 | python -m json.tool出力省略 "id": 1, "label": "Library", 出力省略 "prior": null, "successor": null, 出力省略 1に設定したpriorオプションを使用して、新しいライフサイクル環境を作成します。- 内容が
{"organization_id":1,"label":"api-dev","name":"API Development","prior":1}のlife-cycle.jsonなどの JSON ファイルを作成します。 - 以下のようなコマンドを入力します。
$
curl -H "Accept:application/json,version=2" \-H "Content-Type:application/json" -X POST \-u sat_user:sat_password -k \-d @life-cycle.json \https://satellite6.example.com/katello/api/environments \| python -m json.tool出力省略 "description": null, "id": 2, "label": "api-dev", "library": false, "name": "API Development", "organization": { "id": 1, "label": "Default_Organization", "name": "Default Organization" }, "permissions": { "destroy_lifecycle_environments": true, "edit_lifecycle_environments": true, "promote_or_remove_content_views_to_environments": true, "view_lifecycle_environments": true }, "prior": { "id": 1, "name": "Library" }, 出力省略
以下のコマンドの出力では、ライフサイクル環境の ID が2で、これの 1 つ前のライフサイクル環境は1であると分かります。これは、1と2がリンクされていることを示します。この環境の後継を作成する場合に、ライフサイクル環境 ID2が使用されます。2に設定したpriorオプションを使用して、別のライフサイクル環境を作成します。- 以前に作成した
life-cycle.jsonを編集して、label、name、priorの値を{"organization_id":1,"label":"api-qa","name":"API QA","prior":2}のように更新します。 - 以下のようなコマンドを入力します。
$
curl -H "Accept:application/json,version=2" \-H "Content-Type:application/json" -X POST \-u sat_user:sat_password -k \-d @life-cycle.json \https://satellite6.example.com/katello/api/environments \| python -m json.tool出力省略 "description": null, "id": 3, "label": "api-qa", "library": false, "name": "API QA", "organization": { "id": 1, "label": "Default_Organization", "name": "Default Organization" }, "permissions": { "destroy_lifecycle_environments": true, "edit_lifecycle_environments": true, "promote_or_remove_content_views_to_environments": true, "view_lifecycle_environments": true }, "prior": { "id": 2, "name": "API Development" }, "successor": null, 出力省略
以下のコマンドの出力では、ライフサイクル環境の ID が3で、これの 1 つ前のライフサイクル環境は1であると分かります。これは、2と3がリンクされていることを示します。
ライフサイクル環境の更新
$curl -H "Accept:application/json,version=2" \-H "Content-Type:application/json" -X POST \-u sat_user:sat_password -k \-d '{"description":"Quality Acceptance Testing"}' \https://satellite6.example.com/katello/api/environments/3 \| python -m json.tool出力省略 "description": "Quality Acceptance Testing", "id": 3, "label": "api-qa", "library": false, "name": "API QA", "organization": { "id": 1, "label": "Default_Organization", "name": "Default Organization" }, "permissions": { "destroy_lifecycle_environments": true, "edit_lifecycle_environments": true, "promote_or_remove_content_views_to_environments": true, "view_lifecycle_environments": true }, "prior": { "id": 2, "name": "API Development" }, 出力省略
ライフサイクル環境の削除
curl -X DELETE -s -k -u sat_user:sat_password https://satellite6.example.com/katello/api/environments/:idの形式のコマンドを使用して、逆の順番で環境を削除します。
付録A API レスポンスコード
表A.1 API レスポンスコード
| レスポンス | 説明 |
|---|---|
| 200 OK | show、index、update、delete (GET、PUT、DELETE 要求) などの要求アクションに成功した場合 |
| 201 Created | create アクション (POST 要求) に成功した場合 |
| 301 Moved Permanently | Satellite が HTTPS しか使用できないように制限されているにも拘らず HTTP が試行された時にリダイレクトされる場合 |
| 400 Bad Request | 必要なパラメーターがないか、検索クエリーに無効な構文が含まれている場合 |
| 401 Unauthorized | ユーザー認証に失敗した場合 (認証情報が不正な場合など) |
| 403 Forbidden | ユーザーにアクションの実行、リソースの読み込みなど、十分なパーミッションがないか、アクション自体がサポートされていない場合 |
| 404 Not Found | 指定の ID のレコードが存在しない場合。要求のレコードが存在しない場合には show または delete アクションに、関連のレコードの 1 つが存在しない場合には create、update、delete アクションに表示されることがあります。 |
| 409 Conflict | 既存の依存関係が原因でレコードを削除できない場合 (例: ホストのあるホストグループなど) |
| 415 Unsupported Media Type | HTTP 要求のコンテンツタイプが JSON でない場合 |
| 422 Unprocessable Entity | バリデーションエラーが原因でエンティティーの作成に失敗した場合。アクションの作成または更新にのみ適用されます。 |
| 500 Internal Server Error | 予期しないサーバーエラーが発生した場合 |
| 503 Service Unavailable | サーバーが実行されていない場合 |
付録B API パーミッションの表
表B.1 API パーミッションの表
| パーミッション名 | アクション | リソースタイプ |
|---|---|---|
| view_activation_keys |
| Katello::ActivationKey |
| create_activation_keys |
| Katello::ActivationKey |
| edit_activation_keys |
| Katello::ActivationKey |
| destroy_activation_keys |
| Katello::ActivationKey |
| logout |
| |
| view_architectures |
| |
| create_architectures |
| |
| edit_architectures |
| |
| destroy_architectures |
| |
| view_audit_logs |
| |
| view_authenticators |
| |
| create_authenticators |
| |
| edit_authenticators |
| |
| destroy_authenticators |
| |
| view_bookmarks |
| |
| create_bookmarks |
| |
| edit_bookmarks |
| |
| destroy_bookmarks |
| |
| download_bootdisk |
| |
| manage_capsule_content |
| SmartProxy |
| view_capsule_content |
| SmartProxy |
| view_compute_profiles |
| |
| create_compute_profiles |
| |
| edit_compute_profiles |
| |
| destroy_compute_profiles |
| |
| view_compute_resources |
| |
| create_compute_resources |
| |
| edit_compute_resources |
| |
| destroy_compute_resources |
| |
| view_compute_resources_vms |
| |
| create_compute_resources_vms |
| |
| edit_compute_resources_vms |
| |
| destroy_compute_resources_vms |
| |
| power_compute_resources_vms |
| |
| console_compute_resources_vms |
| |
| view_config_groups |
| |
| create_config_groups |
| |
| edit_config_groups |
| |
| destroy_config_groups |
| |
| view_config_reports |
| |
| destroy_config_reports |
| |
| upload_config_reports |
| |
| view_containers |
| コンテナー |
| commit_containers |
| コンテナー |
| create_containers |
| コンテナー |
| destroy_containers |
| コンテナー |
| power_compute_resources_vms |
| ComputeResource |
| view_content_hosts |
| Katello::System |
| create_content_hosts |
| Katello::System |
| edit_content_hosts |
| Katello::System |
| destroy_content_hosts |
| Katello::System |
| view_content_views |
| Katello::ContentView |
| create_content_views |
| Katello::ContentView |
| edit_content_views |
| Katello::ContentView |
| destroy_content_views |
| Katello::ContentView |
| publish_content_views |
| Katello::ContentView |
| promote_or_remove_content_views |
| Katello::ContentView |
| export_content_views |
| Katello::ContentView |
| access_dashboard |
| |
| view_discovered_hosts |
| ホスト |
| submit_discovered_hosts |
| ホスト |
| auto_provision_discovered_hosts |
| ホスト |
| provision_discovered_hosts |
| ホスト |
| edit_discovered_hosts |
| ホスト |
| destroy_discovered_hosts |
| ホスト |
| view_discovery_rules |
| DiscoveryRule |
| create_discovery_rules |
| DiscoveryRule |
| edit_discovery_rules |
| DiscoveryRule |
| execute_discovery_rules |
| DiscoveryRule |
| destroy_discovery_rules |
| DiscoveryRule |
| view_domains |
| |
| create_domains |
| |
| edit_domains |
| |
| destroy_domains |
| |
| view_environments |
| |
| create_environments |
| |
| edit_environments |
| |
| destroy_environments |
| |
| import_environments |
| |
| view_external_usergroups |
| |
| create_external_usergroups |
| |
| edit_external_usergroups |
| |
| destroy_external_usergroups |
| |
| view_external_variables |
| |
| create_external_variables |
| |
| edit_external_variables |
| |
| destroy_external_variables |
| |
| view_facts |
| |
| upload_facts |
| |
| view_filters |
| |
| create_filters |
| |
| edit_filters |
| |
| destroy_filters |
| |
| view_arf_reports |
| |
| destroy_arf_reports |
| |
| create_arf_reports |
| |
| view_policies |
| ForemanOpenscap::Policy |
| edit_policies |
| ForemanOpenscap::Policy |
| create_policies |
| ForemanOpenscap::Policy |
| destroy_policies |
| ForemanOpenscap::Policy |
| assign_policies |
| ForemanOpenscap::Policy |
| view_scap_contents |
| ForemanOpenscap::ScapContent |
| view_scap_contents |
| ForemanOpenscap::ScapContent |
| edit_scap_contents |
| ForemanOpenscap::ScapContent |
| create_scap_contents |
| ForemanOpenscap::ScapContent |
| destroy_scap_contents |
| ForemanOpenscap::ScapContent |
| edit_hosts |
| ホスト |
| edit_hostgroups |
| ホスト |
| view_job_templates |
| JobTemplate |
| create_job_templates |
| JobTemplate |
| edit_job_templates |
| |
| edit_job_templates |
| |
| edit_remote_execution_features |
| RemoteExecutionFeature |
| destroy_job_templates |
| JobTemplate |
| lock_job_templates |
| JobTemplate |
| create_job_invocations |
| JobInvocation |
| view_job_invocations |
| JobInvocation |
| execute_template_invocation | TemplateInvocation | |
| filter_autocompletion_for_template_invocation |
| TemplateInvocation |
| view_foreman_tasks |
| ForemanTasks::Task |
| edit_foreman_tasks |
| ForemanTasks::Task |
| create_recurring_logics | ForemanTasks::RecurringLogic | |
| view_recurring_logics |
| ForemanTasks::RecurringLogic |
| edit_recurring_logics |
| ForemanTasks::RecurringLogic |
| view_globals |
| |
| create_globals |
| |
| edit_globals |
| |
| destroy_globals |
| |
| view_gpg_keys |
| Katello::GpgKey |
| create_gpg_keys |
| Katello::GpgKey |
| edit_gpg_keys |
| Katello::GpgKey |
| destroy_gpg_keys |
| Katello::GpgKey |
| view_host_collections |
| Katello::HostCollection |
| create_host_collections |
| Katello::HostCollection |
| edit_host_collections |
| Katello::HostCollection |
| destroy_host_collections |
| Katello::HostCollection |
| edit_classes |
| |
| create_params |
| |
| edit_params |
| |
| destroy_params |
| |
| view_hostgroups |
| |
| create_hostgroups |
| |
| edit_hostgroups |
| |
| destroy_hostgroups |
| |
| view_hosts |
| |
| create_hosts |
| |
| edit_hosts |
| |
| destroy_hosts |
| |
| build_hosts |
| |
| power_hosts |
| |
| console_hosts |
| |
| ipmi_boot |
| |
| puppetrun_hosts |
| |
| search_repository_image_search |
| Docker/ImageSearch |
| view_images |
| |
| create_images |
| |
| edit_images |
| |
| destroy_images |
| |
| view_lifecycle_environments |
| Katello::KTEnvironment |
| create_lifecycle_environments |
| Katello::KTEnvironment |
| edit_lifecycle_environments |
| Katello::KTEnvironment |
| destroy_lifecycle_environments |
| Katello::KTEnvironment |
| promote_or_remove_content_views_to_environments | Katello::KTEnvironment | |
| view_locations |
| |
| create_locations |
| |
| edit_locations |
| |
| destroy_locations |
| |
| assign_locations |
| |
| view_mail_notifications |
| |
| view_media |
| |
| create_media |
| |
| edit_media |
| |
| destroy_media |
| |
| view_models |
| |
| create_models |
| |
| edit_models |
| |
| destroy_models |
| |
| view_operatingsystems |
| |
| create_operatingsystems |
| |
| edit_operatingsystems |
| |
| destroy_operatingsystems |
| |
| view_organizations |
| |
| create_organizations |
| |
| edit_organizations |
| |
| destroy_organizations |
| |
| assign_organizations |
| |
| view_ptables |
| |
| create_ptables |
| |
| edit_ptables |
| |
| destroy_ptables |
| |
| lock_ptables |
| |
| view_plugins |
| |
| view_products |
| Katello::Product |
| create_products |
| Katello::Product |
| edit_products |
| Katello::Product |
| destroy_products |
| Katello::Product |
| sync_products |
| Katello::Product |
| export_products |
| Katello::Product |
| view_provisioning_templates |
| |
| create_provisioning_templates |
| |
| edit_provisioning_templates |
| |
| destroy_provisioning_templates |
| |
| deploy_provisioning_templates |
| |
| lock_provisioning_templates |
| |
| user_logout |
| |
| my_account |
| |
| api_status |
| |
| view_puppetclasses |
| |
| create_puppetclasses |
| |
| edit_puppetclasses |
| |
| destroy_puppetclasses |
| |
| import_puppetclasses |
| |
| view_realms |
| |
| create_realms |
| |
| edit_realms |
| |
| destroy_realms |
| |
| view_search |
| |
| view_cases |
| |
| attachments |
| |
| 設定 |
| |
| app_root |
| |
| view_log_viewer |
| |
| ログ |
| |
| rh_telemetry_api |
| |
| rh_telemetry_view |
| |
| rh_telemetry_configurations |
| |
| view_registries |
| DockerRegistry |
| view_registries |
| DockerRegistry |
| create_registries |
| DockerRegistry |
| destroy_registries |
| DockerRegistry |
| view_roles |
| |
| create_roles |
| |
| edit_roles |
| |
| destroy_roles |
| |
| access_settings |
| |
| view_smart_proxies |
| |
| create_smart_proxies |
| |
| edit_smart_proxies |
| |
| destroy_smart_proxies |
| |
| view_smart_proxies_autosign |
| |
| create_smart_proxies_autosign |
| |
| destroy_smart_proxies_autosign |
| |
| view_smart_proxies_puppetca |
| |
| edit_smart_proxies_puppetca |
| |
| destroy_smart_proxies_puppetca |
| |
| view_statistics |
| |
| view_subnets |
| |
| create_subnets |
| |
| edit_subnets |
| |
| destroy_subnets |
| |
| import_subnets |
| |
| view_subscriptions |
| Organization (組織) |
| attach_subscriptions |
| Organization (組織) |
| unattach_subscriptions |
| Organization (組織) |
| import_manifest |
| Organization (組織) |
| delete_manifest |
| Organization (組織) |
| view_sync_plans |
| Katello::SyncPlan |
| create_sync_plans |
| Katello::SyncPlan |
| edit_sync_plans |
| Katello::SyncPlan |
| destroy_sync_plans |
| Katello::SyncPlan |
| view_tasks |
| |
| view_trends |
| |
| create_trends |
| |
| edit_trends |
| |
| destroy_trends |
| |
| update_trends |
| |
| my_organizations |
| |
| view_usergroups |
| |
| create_usergroups |
| |
| edit_usergroups |
| |
| destroy_usergroups |
| |
| view_users |
| |
| create_users |
| |
| edit_users |
| |
| destroy_users |
|
