Red Hat Training
A Red Hat training course is available for Red Hat Satellite
第4章 Red Hat Satellite API の使用開始
本章では、Red Hat Satellite API を使用して異なるタスクを実行する方法を例をあげて紹介します。以下の例では、ポート 43 の HTTPS を使用した Satellite サーバーにフォーカスします。Satellite Capsule 経由で API にアクセスすることもできますが、ポート 8443 を使用する必要があり、使用しない場合には API の呼び出しに失敗します。
スクリプト自体で、異なるポートの要件に対応することができます。たとえば、Ruby では Satellite および Capsule の URL を以下のように指定することができます。
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/'
ホストが Satellite サーバーまたは Capsule サーバーにサブスクライブしている場合には、
/etc/rhsm/rhsm.conf ファイルにある [server] セクションの port エントリーをもとに、API にアクセスする際に必要な、正しいポートを判断することができます。これらの値を使用して、スクリプトを完全に自動化して、使用するポートを検証する必要性をなくすことができます。
4.1. curl を使用した API の例
以下のセクションでは
curl を使用して Satellite API でさまざまなタスクを実行する方法について説明します。
4.1.1. シンプルなクエリーの実行
以下の例では
curl を使用して Satellite デプロイメントの情報を検索する方法を説明します。以下の例には、実際のコマンドと、サンプルの出力、ユーザー名やパスワードの値の例などが含まれます。デプロイメントごとに結果は異なります。また、以下の例では python -m json.tool コマンドを使用して出力をフォーマットしています。
注記
Red Hat Satellite は HTTPS と、デフォルトではホストの識別用に証明書を使用する必要があります。「SSL 認証の使用」の記載どおりに Satellite サーバーの証明書を追加していない場合には、
-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\"",
...
}
ホストの削除
以下のクエリーでは、host1.example.com という名前のホストが削除されます。
curl -k -u sat_username:sat_password -X DELETE https://satellite6.example.com/api/v2/hosts/host1.example.com
4.1.2. リソースの作成および変更
Satellite API を使用して Satellite サーバーのリソースを操作することができます。これらの API 呼び出しでは、ユーザー名、パスワード、URI 以外のさまざまなクエリーパラメーターを渡す必要があります。たとえば、Satellite サーバーにコンテンツをアップロードしたり、Satellite リソースを変更したりするには、要求の作成時にヘッダーに追加情報を含める必要があります。
以下の例のように API のバージョンをヘッダーに指定するか、URL の一部として指定します。たとえば、https://satellite6.example.com/api/v2/architectures は要求ヘッダーで
Accept:version=2 を使用するのと同じです。URL の指定が優先されます。
以下は、POST 要求の基本構文です。
$ 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
}
Satellite サーバーの
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 サーバーへのコンテンツのアップロード
以下のセクションでは、Satellite 6 API で
curl を使用して、Satellite サーバーに大容量ファイルをアップロードしてインポートする方法を説明します。このプロセスには 4 つの手順が含まれます。
- アップロード要求を作成します。
- コンテンツをアップロードします。
- コンテンツをインポートします。
- アップロード要求を削除します。
アップロード可能な最大ファイルサイズは 30 MB です。それよりも大きいサイズのコンテンツをアップロードするには、例4.3「30 MB よりも大きいコンテンツのアップロード」を参照してください。
手順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 よりも大きいコンテンツのアップロード
以下の例では、大容量のファイルを複数のチャンクに分割して、アップロード要求の作成、個別ファイルのアップロード、Satellite へのインポートを行ってから、アップロード要求を削除する方法を詳しく説明しています。この例は、サンプルのコンテンツ、ホスト名、ユーザー名、ファイル名を使用している点に注意してください。
- サンプルモジュールをダウンロードします。
$ 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. スマートクラスのオーバーライド
API を使用してスマートパラメーターを検索し、値を指定してクラスのスマートパラメーターをオーバーライドすることができます。変更可能な属性の完全一覧は、
https://satellite6.example.com/apidoc/v2/smart_class_parameters/update.html にある同梱の API リファレンスで確認できます。
たとえば、スマートクラスのパラメーターをすべて表示する場合、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
いずれの呼び出しも検索パラメーターに対応しています。検索可能なフィールドの完全一覧は、Web UI の検索入力ボックスで確認できます。設定 → スマート変数 の順に移動して、検索クエリーボックスをクリックしてフィールドの一覧を表示します。
特に検索パラメーターで便利なのは、
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'
標準のスコープ指定の検索構文はサポートされています。
パラメーターの ID を特定したら、現在のオーバーライド値など完全な詳細の表示に進むことができます。たとえば、ID が 63 の場合、API ルートは
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
オーバーライドが有効な場合には、カスタムの Override Matcher を追加できます。
$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. 外部ファイルを使用したスマートクラスパラメーターの変更
外部ファイルを使用すると、JSON データでの作業が簡素化されます。構文が強調されるエディターを使用するので、間違いを回避し、特定しやすくなります。
手順4.2 外部ファイルを使用したスマートクラスパラメーターの変更
以下の例では、MOTD Puppet マニフェストを使用します。
- 今回は
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. エラータのホストまたはホストコレクションへの適用
PUT コマンドで
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
同梱の API ドキュメント (
https://satellite6.example.com/apidoc/v2.html) を参照してエラータの適用に使用する URL を検索します。Satellite Web UI を使用すると、検索クエリー形式の検索に役立ちます。ホスト → ホストコレクション の順に移動して、ホストコレクションを選択します。コレクションの各種アクション → エラータのインストール に移動して、検索クエリーボックスに注目します。たとえば my-collection と呼ばれるホストコレクションでは、検索ボックスに host_collection="my-collection" が含まれます。以下のホストコレクションの例では、これを使用します。
例4.4 ホストへのエラータの適用
以下の例では、一括アクションの API URL
/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 ホストコレクションへのエラータの適用
以下の例では、Satellite Web UI に表示されているように、検索文字列
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