第5章 Red Hat Satellite API の使用
本章では、Red Hat Satellite API を使用して各種タスクを実行する方法をさまざまな例を挙げて説明します。Satellite Server で API を使用するには、ポート 43 の HTTPS を、Capsule Server で API を使用するには、ポート 8443 の HTTPS を使用します。
スクリプト自体で、異なるポートの要件に対応することができます。たとえば、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 Server または Capsule Server にサブスクライブしている場合は、/etc/rhsm/rhsm.conf の [server]
セクションのポートエントリーをもとに、API へのアクセスに必要な、正しいポートを判断できます。これらの値を使用してスクリプトを完全に自動化し、使用するポートを検証する必要性をなくします。
本章では、curl
を使用して API 要求を送信します。詳細情報は、「curl を使用した API 要求」を参照してください。
本章の例では、Python json.tool
モジュールを使用して出力をフォーマットしています。
5.1. ホストの使用方法
ホストのリスト
以下の例では、Satellite ホストのリストを返します。
要求例:
$ curl -request GET --insecure --user 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" => [ ... }
ホストの情報要求
この要求は、satellite6.example.com
ホストの情報を返します。
要求例:
$ curl --request GET --insecure --user 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 --request GET --insecure --user 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 --request GET --insecure --user 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 --request GET --insecure --user 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 --request GET --insecure --user 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 --request DELETE --insecure --user sat_username:sat_password \ https://satellite6.example.com/api/v2/hosts/host1.example.com \ | python -m json.tool
5.2. ライフサイクル環境との作業
Satellite は、アプリケーションのライフサイクルを、ライフサイクル環境に分割します。ライフサイクル環境は、アプリケーションのライフサイクルの各ステージを表します。ライフサイクル環境は、環境パスからリンクされます。リンクされたライフサイクル環境を API で作成するには、prior_id
パラメーターを使用します。
https://satellite6.example.com/apidoc/v2/lifecycle_environments.html
で、ライフサイクル環境に関する、同梱の API リファレンスを確認できます。API ルートには /katello/api/environments
および /katello/api/organizations/:organization_id/environments
が含まれます。
ライフサイクル環境の表示
以下の API 呼び出しを使用して、Satellite にある ID が1
のデフォルトの組織に対する現在の全ライフサイクル環境を表示します。
要求例:
$ curl --header "Accept:application/json,version=2" \ --header "Content-Type:application/json" \ --request GET --user sat_username:sat_password --insecure \ https://satellite6.example.com/katello/api/organizations/1/environments \ | python -m json.tool`
応答例:
output omitted "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, output truncated
ライフサイクル環境のリンク作成
以下の例を使用して、ライフサイクル環境のパスを作成します。
以下の手順では、ID が 1
のデフォルトのライブラリー環境が、ライフサイクル環境作成の開始点として使用されています。
開始点として使用する既存のライフサイクル環境を選択します。その ID を使用して環境を表示します。今回の例では、ID が
1
の環境を使用します。要求例:
$ curl --request GET --user sat_username:sat_password --insecure \ https://satellite6.example.com/katello/api/environments/1 \ | python -m json.tool
応答例:
output omitted "id": 1, "label": "Library", output omitted "prior": null, "successor": null, output truncated
以下のコンテンツを含めて、
life-cycle.json
などの JSON ファイルを作成します。{"organization_id":1,"label":"api-dev","name":"API Development","prior":1}
prior
オプションを1
に設定して、ライフサイクル環境を作成します。要求例:
$ curl --header "Accept:application/json,version=2" \ --header "Content-Type:application/json" \ --request POST --user sat_username:sat_password --insecure \ --data @life-cycle.json \ https://satellite6.example.com/katello/api/environments \ | python -m json.tool
応答例:
output omitted "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" }, output truncated
以下のコマンドの出力では、ライフサイクル環境の ID が
2
で、その 1 つ前のライフサイクル環境は1
であると分かります。ID が2
のライフサイクル環境を使用して、この環境の後継を作成します。以前作成した
life-cycle.json
ファイルを編集して、label
、name
、prior
の値を更新します。{"organization_id":1,"label":"api-qa","name":"API QA","prior":2}
prior
オプションを2
に設定して、ライフサイクル環境を作成します。要求例:
$ curl --header "Accept:application/json,version=2" \ --header "Content-Type:application/json" \ --request POST --user sat_username:sat_password --insecure \ --data @life-cycle.json \ https://satellite6.example.com/katello/api/environments \ | python -m json.tool
応答例:
output omitted "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, output truncated
以下のコマンドの出力では、ライフサイクル環境の ID が
3
で、その 1 つ前のライフサイクル環境は1
であると分かります。
ライフサイクル環境の更新
PUT コマンドを使用して、ライフサイクル環境を更新できます。
以下の要求例では、ID が 3
のライフサイクル環境の説明を更新します。
要求例:
$ curl --header "Accept:application/json,version=2" \ --header "Content-Type:application/json" \ --request POST --user sat_username:sat_password --insecure \ --data '{"description":"Quality Acceptance Testing"}' \ https://satellite6.example.com/katello/api/environments/3 \ | python -m json.tool
応答例:
output omitted "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" }, output truncated
ライフサイクル環境の削除
後継がない前提でライフサイクル環境を削除できます。このような理由から、以下の形式のコマンドを使用して、逆順にライフサイクル環境を削除します。
要求例:
$ curl --request DELETE --user sat_username:sat_password --insecure \ https://satellite6.example.com/katello/api/environments/:id
5.3. Satellite サーバーへのコンテンツのアップロード
以下のセクションでは、Satellite 6 API を使用して Satellite Server に大容量のファイルをアップグレードしてインポートする方法を説明します。このプロセスでは、4 つの手順が含まれます。
- アップロード要求の作成
- コンテンツのアップロード
- コンテンツのインポート
- アップロード要求の削除
The maximum file size that you can upload is 2MB. For information about uploading larger content, see Uploading Content Larger than 2 MB.
手順
アップロード要求を作成します。デプロイメントに適したサンプルパラメーターを変更するようにしてください。
要求例:
$ curl --header "Accept:application/json,version=2" \ --header "Content-Type:application/json" \ --request POST --insecure \ --user sat_username:sat_password --data "{}" \ 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/"}
コンテンツのアップロード用に
upload_id
をメモします。コンテンツをアップロードします。データのアップロード時には、正しい MIME タイプを使用していることを確認します。この API では、Satellite 6 に対する要求にほぼ、
application/json
の MIME タイプが使用します。upload_id
と MIME タイプ、他のパラメーターを組み合わせてコンテンツをアップロードします。要求例:
$ curl --header "Accept:application/json,version=2" \ --header "Content-Type:multipart/form-data" \ --request PUT --insecure --user sat_username:sat_password \ --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 Server にコンテンツをアップロードした後に、適切なリポジトリーにそのコンテンツをインポートする必要があります。この手順を完了するまで、Satellite Server ではこの新しいコンテンツは認識されません。
要求例:
$ curl --header "Accept:application/json,version=2" \ --header "Content-Type:application/json" \ --request PUT --insecure \ --user sat_username:sat_password \ --data "{\"upload_ids\":[\"0be156b1-f373-4cad-89d0-924f8f4491d2\"]}" \ https://satellite6.example.com/katello/api/repositories/3/import_uploads
コンテンツのアップロードおよびインポートが正常に完了したら、アップロード要求を削除することができます。削除することで、アップロード中にデータが使用した一時的なディスク領域を解放することができます。
要求例:
$ curl --header "Accept:application/json,version=2" \ --header "Content-Type:application/json" \ --request DELETE --insecure \ --user sat_username:sat_password --data "{}" \ https://satellite6.example.com/katello/api/repositories/3/content_uploads/0be156b1-f373-4cad-89d0-924f8f4491d2
Uploading Content Larger than 2 MB
以下の例では、大容量のファイルを複数のチャンクに分割して、アップロード要求の作成、個別ファイルのアップロード、Satellite へのインポートを行ってから、アップロード要求を削除する方法を説明しています。この例は、サンプルのコンテンツ、ホスト名、ユーザー名、ファイル名を使用している点に注意してください。
Use the following example to split your file into 2MB chunks:
$ split --bytes 2MB --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
アップロード要求の作成
要求例:
$ curl --header "Accept:application/json,version=2" \ --header "Content-Type:application/json" \ --request POST --insecure --user sat_username:sat_password --data "{}" \ https://ibm-vm01.example.com/katello/api/repositories/2/content_uploads
応答例:
{"upload_id":"9585528f-07ad-4bb1-9c80-ccece249b2b7","_href":"/pulp/api/v2/content/uploads/9585528f-07ad-4bb1-9c80-ccece249b2b7/"}
コンテンツのアップロード用に
upload_id
をメモします。Satellite Server に、ファイルのチャンクをアップロードします。以下の例で
offset
パラメーターを使用して、ファイルサイズと関連付けている点に注意してください。要求例:
$ curl --header "Accept:application/json,version=2" \ --header "Content-Type:multipart/form-data" \ --request PUT --insecure --user sat_username:sat_password \ --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 --header "Accept:application/json,version=2" \ --header "Content-Type:application/json" \ --request PUT --insecure --user sat_username:sat_password \ --data "{\"upload_ids\":[\"9585528f-07ad-4bb1-9c80-ccece249b2b7\"]}" \ https://ibm-vm01.example.com/katello/api/repositories/2/import_uploads
アップロード要求を削除します。
$ curl --header "Accept:application/json,version=2" \ --header "Content-Type:application/json" \ --request DELETE --insecure --user sat_username:sat_password --data "{}" \ https://ibm-vm01.example.com/katello/api/repositories/2/content_uploads/9585528f-07ad-4bb1-9c80-ccece249b2b7
Satellite Server で、転送したファイルを確認します。
# 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
5.4. エラータのホストまたはホストコレクションへの適用
API を使用して、エラータをホスト、ホストグループ、またはホストコレクションに適用することができます。以下は、PUT 要求の基本的な構文です。
$ curl --header "Accept:application/json,version=2" \ --header "Content-Type:application/json" --request PUT \ --user sat_username:sat_password --insecure \ --data json-formatted-data https://satellite7.example.com
同梱の API ドキュメントを参照して、エラータ適用に使用する URL を検索します。Satellite Web UI で、検索クエリーの形式を確認できます。ホスト > ホストコレクション に移動して、ホストコレクションを選択します。コレクションアクション > エラータのインストール に移動して、検索クエリーボックスの内容を確認します。たとえば、my-collection と呼ばれるホストコレクションの場合は、検索ボックスに host_collection="my-collection"
が含まれます。
ホストへのエラータの適用
以下の例では、/katello/api/hosts/bulk/install_content
一括アクションの API URL を使用して、単純な検索に必要な形式を表示します。
要求例:
$ curl --header "Accept:application/json,version=2" \ --header "Content-Type:application/json" --request PUT \ --user sat_username:sat_password --insecure \ --data "{\"organization_id\":1,\"included\":{\"search\":\"my-host\"},\"content_type\":\"errata\",\"content\":[\"RHBA-2016:1981\"]}" \ https://satellite6.example.com/api/v2/hosts/bulk/install_content
ホストコレクションへのエラータの適用
以下の例では、Satellite Web UI に表示されているように、検索文字列 host_collection="my-collection"
を渡すのに必要なエスケープレベルに注目してください。
要求例:
$ curl --header "Accept:application/json,version=2" \ --header "Content-Type:application/json" --request PUT \ --user sat_username:sat_password --insecure \ --data "{\"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
5.5. 詳細検索の使用
Web UI で、クエリーの構築に使用可能な検索用語を判断することができます。Satellite 6 は、範囲内の検索や自動補完機能をサポートします。
たとえば、オペレーティングシステム別にホストを検索するには ホスト > すべてのホスト の順に移動して、検索 テキストボックスをクリックして検索用語の一覧を表示します。オペレーティングシステムの検索用語の一例は os_description
で、以下のように API クエリーで使用することができます。
要求例:
$ curl --insecure --user 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\"",
}
5.6. ページネーション制御のある検索の使用
per_page
および page
ページネーションパラメーターを使用して、API 検索クエリーが返した検索結果を絞り込むことができます。per_page
パラメーターは、ページごとに表示する結果数を指定し、page
パラメーターは per_page
パラメーターの計算に合わせて、どのページを返すかを指定します。
ページネーションパラメーターを指定しない場合に、返す項目数のデフォルト値を 1000 に設定しますが、page
パラメーターが指定されている場合には per_page
のデフォルト値は 20 が適用されます。
コンテンツビューの表示
以下の例では、複数ページにわたるコンテンツビューの一覧を返します。このリストでは、ページごとにキー 10 個が含まれており、3 ページ目を返します。
要求例:
$ curl --request GET --user sat_username:sat_password \
https://satellite6.example.com/katello/api/content_views?per_page=10&page=3
アクティベーションキーの表示
以下の例では、ID が 1
の組織のアクティベーションキー一覧を複数ページで返します。この一覧には、ページごとにキーが 30 個含まれており、2 ページ目が返されます。
要求例:
$ curl --request GET --user sat_username:sat_password \
https://satellite6.example.com/katello/api/activation_keys?organization_id=1&per_page=30&page=2
複数ページを返す設定
for
loop 構造を使用して、複数ページにわたる結果を取得します。
以下の例では、ページごとに 5 件ずつ表示するコンテンツビュー 3 ページ分の 1 ページを返します。
$ for i in seq 1 3
; do \
curl --request GET --user sat_username:sat_password \
https://satellite6.example.com/katello/api/content_views?per_page=5&page=$i; \
done
5.7. スマートクラスのオーバーライド
API を使用してスマートパラメーターを検索し、値を指定してクラスのスマートパラメーターを上書きすることができます。変更可能な属性の完全一覧は、https://satellite6.example.com/apidoc/v2/smart_class_parameters/update.html
にある同梱の API リファレンスで確認できます。
変更するスマートクラスパラメーターの ID を検索します。
スマートクラスパラメーターすべてを表示します。
要求例:
$ curl --request GET --insecure --user sat_username:sat_password \ https://satellite6.example.com/api/smart_class_parameters
5 など、Puppet クラス ID が分かる場合には、範囲を絞り込むことができます。
要求例:
$ curl --request GET --insecure --user sat_username:sat_password \ https://satellite6.example.com/api/puppetclasses/5/smart_class_parameters
どちらの呼び出しも検索パラメーターに対応します。Satellite Web UI で検索可能なフィールドの全一覧を表示できます。設定 > スマート変数 に移動して、検索クエリーボックスをクリックし、フィールドの一覧を表示します。
特に検索パラメーターで便利なのは、
puppetclass_name
とkey
の 2 つで、特定のパラメーターの検索が可能になります。たとえば、--data
オプションを使用して URL のエンコードデータを渡すことができます。要求例:
$ curl --request GET --insecure --user sat_username:sat_password \ --data 'search=puppetclass_name = access_insights_client and key = authmethod' \ https://satellite6.example.com/api/smart_class_parameters
Satellite は、標準のスコープ指定の検索構文をサポートします。
パラメーターの ID が見つかると、現在の上書き値など、全詳細が表示されます。
要求例:
$ curl --request GET --insecure --user sat_username:sat_password \ https://satellite6.example.com/api/smart_class_parameters/63
パラメーターの値の上書きの有効化
要求例:
$ curl --header "Accept:application/json,version=2" \ --header "Content-Type:application/json" \ --request PUT --insecure --user sat_username:sat_password \ --data '{"smart_class_parameter":{"override":true}}' \ https://satellite6.example.com/api/smart_class_parameters/63
パラメーターを手動で作成または削除できない点に注意してください。属性の変更のみが可能です。Satellite は、パラメーターは、プロキシーからクラスをインポートすることでのみ作成、削除されます。
カスタムの override matcher を追加します。
要求例:
$ curl --header "Accept:application/json,version=2" \ --header "Content-Type:application/json" \ --request PUT --insecure --user sat_username:sat_password \ --data '{"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 --request DELETE --user sat_username:sat_password \ https://satellite6.example.com/api/smart_class_parameters/63/override_values/3
5.8. 外部ファイルを使用したスマートクラスパラメーターの変更
外部ファイルを使用すると、JSON データでの作業が簡素化されます。構文が強調されるエディターを使用するので、間違いを回避し、特定しやすくなります。
外部ファイルを使用したスマートクラスパラメーターの変更
以下の例では、MOTD Puppet マニフェストを使用します。
今回の例では、
motd
という名前で Puppet クラスを検索します。要求例:
$ curl --header "Accept:application/json,version=2" \ --header "Content-Type:application/json" \ --request GET --user sat_user:sat_password --insecure \ https://satellite6.example.com/api/smart_class_parameters?search=puppetclass_name=motd \ | python -m json.tool
以下の出力を検証します。スマートクラスのパラメーターにはそれぞれ、同じ Satellite インスタンスでグローバルとなる ID が割り当てられています。Satellite Server では、
motd
クラスのcontent
パラメーターはid=3
となっています。Puppet クラス名の前に表示される Puppet クラス ID と混同しないようにしてください。応答例:
{ "avoid_duplicates": false, "created_at": "2017-02-06 12:37:48 UTC", # Remove this line. "default_value": "", # Add a new value here. "description": "", "hidden_value": "", "hidden_value?": false, "id": 3, "merge_default": false, "merge_overrides": false, "override": false, # Set the override value to
true
. "override_value_order": "fqdn\nhostgroup\nos\ndomain", "override_values": [], # Remove this line. "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", # Remove this line. "use_puppet_default": false, "validator_rule": null, "validator_type": "" }パラメーター ID
3
を使用して、motd
パラメーター固有の情報を取得して、出力を output_file.json などのファイルにリダイレクトします。要求例:
$ curl --header "Accept:application/json,version=2" \ --header "Content-Type:application/json" --request GET \ --user sat_user:sat_password --insecure \` https://satellite6.example.com/api/smart_class_parameters/3 \ | python -m json.tool > output_file.json
1 つ前の手順で作成したファイルを、新しいファイル (例:
changed_file.json
) にコピーして編集します。:$ cp output_file.json changed_file.json
ファイルで、必要な値を変更します。以下の例では、
motd
モジュールのコンテンツパラメーターを変更しますが、これには、override
オプションをfalse
からtrue
に変更する必要があります。{ "avoid_duplicates": false, "created_at": "2017-02-06 12:37:48 UTC", # Remove this line. "default_value": "", # Add a new value here. "description": "", "hidden_value": "", "hidden_value?": false, "id": 3, "merge_default": false, "merge_overrides": false, "override": false, # Set the override value to
true
. "override_value_order": "fqdn\nhostgroup\nos\ndomain", "override_values": [], # Remove this line. "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", # Remove this line. "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": "" }
Satellite Server への変更を適用します。
$ curl --header "Accept:application/json,version=2" \ --header "Content-Type:application/json" \ --request PUT --user sat_username:sat_password --insecure \ --data @changed_file.json \ https://satellite6.example.com/api/smart_class_parameters/3
5.9. OpenSCAP レポートの削除
Satellite Server で、1 つまたは複数の OpenSCAP レポートを削除できます。ただし、レポートの削除には、一度に 1 ページずつしか削除できません。すべての Openscap レポートを削除する場合には、以下のバッシュスクリプトを使用してください。
OpenSCAP レポートの削除
OpenSCAP レポートを削除するには、次の手順を実行します。
全 OpenSCAP レポートを表示します。削除するレポートの ID をメモしてください。
要求例:
curl --insecure --user username:_password_ \ https://satellite.example.com/api/v2/compliance/arf_reports/ | python -m json.tool
応答例:
% Total % Received % Xferd Average Speed Time Time Time Current Dload Upload Total Spent Left Speed 100 3252 0 3252 0 0 4319 0 --:--:-- --:--:-- --:--:-- 4318 { "page": 1, "per_page": 20, "results": [ { "created_at": "2017-05-16 13:27:09 UTC", "failed": 0, "host": "host1.example.com", "id": 404, "othered": 0, "passed": 0, "updated_at": "2017-05-16 13:27:09 UTC" }, { "created_at": "2017-05-16 13:26:07 UTC", "failed": 0, "host": "host2.example.com, "id": 405, "othered": 0, "passed": 0, "updated_at": "2017-05-16 13:26:07 UTC" }, { "created_at": "2017-05-16 13:25:07 UTC", "failed": 0, "host": "host3.example.com", "id": 406, "othered": 0, "passed": 0, "updated_at": "2017-05-16 13:25:07 UTC" }, { "created_at": "2017-05-16 13:24:07 UTC", "failed": 0, "host": "host4.example.com", "id": 407, "othered": 0, "passed": 0, "updated_at": "2017-05-16 13:24:07 UTC" }, ], "search": null, "sort": { "by": null, "order": null }, "subtotal": 29, "total": 29
1 つ前の手順で取得した ID を使用して、OpenSCAPレポートを削除します。削除する ID ごとに同様の手順を繰り返します。
要求例:
# curl --insecure --user username:_password_ \ --header "Content-Type: application/json" \ --request DELETE https://satellite.example.com/api/v2/compliance/arf_reports/405
応答例:
HTTP/1.1 200 OK Date: Thu, 18 May 2017 07:14:36 GMT Server: Apache/2.4.6 (Red Hat Enterprise Linux) X-Frame-Options: SAMEORIGIN X-XSS-Protection: 1; mode=block X-Content-Type-Options: nosniff Foreman_version: 1.11.0.76 Foreman_api_version: 2 Apipie-Checksum: 2d39dc59aed19120d2359f7515e10d76 Cache-Control: max-age=0, private, must-revalidate X-Request-Id: f47eb877-35c7-41fe-b866-34274b56c506 X-Runtime: 0.661831 X-Powered-By: Phusion Passenger 4.0.18 Set-Cookie: request_method=DELETE; path=/ Set-Cookie: _session_id=d58fe2649e6788b87f46eabf8a461edd; path=/; secure; HttpOnly ETag: "2574955fc0afc47cb5394ce95553f428" Status: 200 OK Vary: Accept-Encoding Transfer-Encoding: chunked Content-Type: application/json; charset=utf-8
全 OpenSCAP レポートを削除する Bash スクリプトの例
以下の Bash スクリプトを使用して、全 OpenSCAP レポートを削除します。
#!/bin/bash #this script removes all the arf reports from the satellite server #settings USER=username PASS=password URI=https://satellite.example.com #check amount of reports while [ $(curl --insecure --user $USER:$PASS $URI/api/v2/compliance/arf_reports/ | python -m json.tool | grep \"\total\": | cut --fields=2 --delimiter":" | cut --fields=1 --delimiter"," | sed "s/ //g") -gt 0 ]; do #fetch reports for i in $(curl --insecure --user $USER:$PASS $URI/api/v2/compliance/arf_reports/ | python -m json.tool | grep \"\id\": | cut --fields=2 --delimiter":" | cut --fields=1 --delimiter"," | sed "s/ //g") #delete reports do curl --insecure --user $USER:$PASS --header "Content-Type: application/json" --request DELETE $URI/api/v2/compliance/arf_reports/$i done done