이 콘텐츠는 선택한 언어로 제공되지 않습니다.
Chapter 5. Using the Red Hat Satellite API
This chapter provides a range of examples of how to use the Red Hat Satellite API to perform different tasks. You can use the API on Satellite Server via HTTPS on port 443, or on Capsule Server via HTTPS on port 8443.
You can address these different port requirements within the script itself. For example, in Ruby, you can specify the Satellite and Capsule URLs as follows:
url = 'https://satellite.example.com/api/v2/' capsule_url = 'https://capsule.example.com:8443/api/v2/' katello_url = 'https://satellite.example.com/katello/api/v2/'
url = 'https://satellite.example.com/api/v2/'
capsule_url = 'https://capsule.example.com:8443/api/v2/'
katello_url = 'https://satellite.example.com/katello/api/v2/'
For the host that is subscribed to Satellite Server or Capsule Server, you can determine the correct port required to access the API from the /etc/rhsm/rhsm.conf file, in the port entry of the [server] section. You can use these values to fully automate your scripts, removing any need to verify which ports to use.
This chapter uses curl for sending API requests. For more information, see Section 4.1, “API requests with curl”.
Examples in this chapter use the Python json.tool module to format the output.
5.1. Working with hosts 링크 복사링크가 클립보드에 복사되었습니다!
Listing hosts
This example returns a list of Satellite hosts.
Example request:
curl --request GET --insecure --user sat_username:sat_password \ https://satellite.example.com/api/v2/hosts | python3 -m json.tool
$ curl --request GET --insecure --user sat_username:sat_password \
https://satellite.example.com/api/v2/hosts | python3 -m json.tool
Example response:
Requesting information for a host
This request returns information for the host satellite.example.com.
Example request:
curl --request GET --insecure --user sat_username:sat_password \ https://satellite.example.com/api/v2/hosts/satellite.example.com \ | python -m json.tool
$ curl --request GET --insecure --user sat_username:sat_password \
https://satellite.example.com/api/v2/hosts/satellite.example.com \
| python -m json.tool
Example response:
Listing host facts
This request returns all facts for the host satellite.example.com.
Example request:
curl --request GET --insecure --user sat_username:sat_password \ https://satellite.example.com/api/v2/hosts/satellite.example.com/facts \ | python -m json.tool
$ curl --request GET --insecure --user sat_username:sat_password \
https://satellite.example.com/api/v2/hosts/satellite.example.com/facts \
| python -m json.tool
Example response:
Searching for hosts with matching patterns
This query returns all hosts that match the pattern "example".
Example request:
curl --request GET --insecure --user sat_username:sat_password \ https://satellite.example.com/api/v2/hosts?search=example \ | python -m json.tool
$ curl --request GET --insecure --user sat_username:sat_password \
https://satellite.example.com/api/v2/hosts?search=example \
| python -m json.tool
Example response:
Searching for hosts in an environment
This query returns all hosts in the production environment.
Example request:
curl --request GET --insecure --user sat_username:sat_password \ https://satellite.example.com/api/v2/hosts?search=environment=production \ | python -m json.tool
$ curl --request GET --insecure --user sat_username:sat_password \
https://satellite.example.com/api/v2/hosts?search=environment=production \
| python -m json.tool
Example response:
Searching for hosts with a specific fact value
This query returns all hosts with a model name RHEV Hypervisor.
Example request:
curl --request GET --insecure --user sat_username:sat_password \ https://satellite.example.com/api/v2/hosts?search=model=\"RHEV+Hypervisor\" \ | python -m json.tool
$ curl --request GET --insecure --user sat_username:sat_password \
https://satellite.example.com/api/v2/hosts?search=model=\"RHEV+Hypervisor\" \
| python -m json.tool
Example response:
Deleting a host
This request deletes a host with a name host1.example.com.
Example request:
curl --request DELETE --insecure --user sat_username:sat_password \ https://satellite.example.com/api/v2/hosts/host1.example.com \ | python -m json.tool
$ curl --request DELETE --insecure --user sat_username:sat_password \
https://satellite.example.com/api/v2/hosts/host1.example.com \
| python -m json.tool
Downloading a full boot disk image
This request downloads a full boot disk image for a host by its ID.
Example request:
curl --request GET --insecure --user sat_username:sat_password \ https://satellite.example.com/api/bootdisk/hosts/host_ID?full=true \ --output image.iso
$ curl --request GET --insecure --user sat_username:sat_password \
https://satellite.example.com/api/bootdisk/hosts/host_ID?full=true \
--output image.iso
5.2. Working with life cycle environments 링크 복사링크가 클립보드에 복사되었습니다!
Satellite divides application life cycles into life cycle environments, which represent each stage of the application life cycle. Life cycle environments are linked to from an environment path. To create linked life cycle environments with the API, use the prior_id parameter.
You can find the built-in API reference for life cycle environments at https://satellite.example.com/apidoc/v2/lifecycle_environments.html. The API routes include /katello/api/environments and /katello/api/organizations/:organization_id/environments.
Listing life cycle environments
Use this API call to list all the current life cycle environments on your Satellite for the default organization with ID 1.
Example request:
curl --header "Accept:application/json" \ --header "Content-Type:application/json" \ --request GET --user sat_username:sat_password --insecure \ https://satellite.example.com/katello/api/organizations/1/environments \ | python -m json.tool`
$ curl --header "Accept:application/json" \
--header "Content-Type:application/json" \
--request GET --user sat_username:sat_password --insecure \
https://satellite.example.com/katello/api/organizations/1/environments \
| python -m json.tool`
Example response:
Creating linked life cycle environments
Use this example to create a path of life cycle environments.
This procedure uses the default Library environment with ID 1 as the starting point for creating life cycle environments.
Choose an existing life cycle environment that you want to use as a starting point. List the environment using its ID, in this case, the environment with ID
1:Example request:
curl --request GET --user sat_username:sat_password --insecure \ https://satellite.example.com/katello/api/environments/1 \ | python -m json.tool
$ curl --request GET --user sat_username:sat_password --insecure \ https://satellite.example.com/katello/api/environments/1 \ | python -m json.toolCopy to Clipboard Copied! Toggle word wrap Toggle overflow Example response:
Copy to Clipboard Copied! Toggle word wrap Toggle overflow Create a JSON file, for example,
life-cycle.json, with the following content:{"organization_id":1,"label":"api-dev","name":"API Development","prior":1}{"organization_id":1,"label":"api-dev","name":"API Development","prior":1}Copy to Clipboard Copied! Toggle word wrap Toggle overflow Create a life cycle environment using the
prioroption set to1.Example request:
Copy to Clipboard Copied! Toggle word wrap Toggle overflow Example response:
Copy to Clipboard Copied! Toggle word wrap Toggle overflow In the command output, you can see the ID for this life cycle environment is
2, and the life cycle environment prior to this one is1. Use the life cycle environment with ID2to create a successor to this environment.Edit the previously created
life-cycle.jsonfile, updating thelabel,name, andpriorvalues.{"organization_id":1,"label":"api-qa","name":"API QA","prior":2}{"organization_id":1,"label":"api-qa","name":"API QA","prior":2}Copy to Clipboard Copied! Toggle word wrap Toggle overflow Create a life cycle environment, using the
prioroption set to2.Example request:
Copy to Clipboard Copied! Toggle word wrap Toggle overflow Example response:
Copy to Clipboard Copied! Toggle word wrap Toggle overflow In the command output, you can see the ID for this life cycle environment is
3, and the life cycle environment prior to this one is2.
Updating a life cycle environment
You can update a life cycle environment using a PUT command.
This example request updates a description of the life cycle environment with ID 3.
Example request:
Example response:
Deleting a life cycle environment
You can delete a life cycle environment provided it has no successor. Therefore, delete them in reverse order using a command in the following format:
Example request:
curl --request DELETE --user sat_username:sat_password --insecure \ https://satellite.example.com/katello/api/environments/:id
$ curl --request DELETE --user sat_username:sat_password --insecure \
https://satellite.example.com/katello/api/environments/:id
5.3. Uploading content to the Satellite Server 링크 복사링크가 클립보드에 복사되었습니다!
This section outlines how to use the Satellite 6 API to upload and import large files to your Satellite Server. This process involves four steps:
- Create an upload request.
- Upload the content.
- Import the content.
- Delete the upload request.
The maximum file size that you can upload is 2MB. For information about uploading larger content, see Uploading content larger than 2 MB.
Procedure
Assign the package name to the variable
name:Example request:
export name=jq-1.6-2.el7.x86_64.rpm
$ export name=jq-1.6-2.el7.x86_64.rpmCopy to Clipboard Copied! Toggle word wrap Toggle overflow Assign the checksum of the file to the variable
checksum:Example request:
export checksum=$(sha256sum $name|cut -c 1-65)
$ export checksum=$(sha256sum $name|cut -c 1-65)Copy to Clipboard Copied! Toggle word wrap Toggle overflow Assign the file size to the variable
size:Example request:
export size=$(du -bs $name|cut -f 1)
$ export size=$(du -bs $name|cut -f 1)Copy to Clipboard Copied! Toggle word wrap Toggle overflow The following command creates a new upload request and returns the upload ID of the request using
sizeandchecksum.Example request:
curl -H 'Content-Type: application/json' -X POST -k \ -u sat_username:sat_password -d "{\"size\": \"$size\", \ \"checksum\":\"$checksum\"}" \ https://$(hostname -f)/katello/api/v2/repositories/76/content_uploads$ curl -H 'Content-Type: application/json' -X POST -k \ -u sat_username:sat_password -d "{\"size\": \"$size\", \ \"checksum\":\"$checksum\"}" \ https://$(hostname -f)/katello/api/v2/repositories/76/content_uploadsCopy to Clipboard Copied! Toggle word wrap Toggle overflow where 76, in this case, is an example Repository ID.
Example request:
{"upload_id":"37eb5900-597e-4ac3-9bc5-2250c302fdc4"}{"upload_id":"37eb5900-597e-4ac3-9bc5-2250c302fdc4"}Copy to Clipboard Copied! Toggle word wrap Toggle overflow Assign the upload ID to the variable
upload_id:Example request:
export upload_id=37eb5900-597e-4ac3-9bc5-2250c302fdc4
$ export upload_id=37eb5900-597e-4ac3-9bc5-2250c302fdc4Copy to Clipboard Copied! Toggle word wrap Toggle overflow Assign the path of the package you want to upload to the variable
path:export path=/root/jq/jq-1.6-2.el7.x86_64.rpm
$ export path=/root/jq/jq-1.6-2.el7.x86_64.rpmCopy to Clipboard Copied! Toggle word wrap Toggle overflow Upload your content. Ensure you use the correct MIME type when you upload data. The API uses the application/json MIME type for the majority of requests to Satellite 6. Combine the upload_id, MIME type, and other parameters to upload content.
Example request:
curl -u sat_username:sat_password -H Accept:application/json -H \ Content-Type:multipart/form-data -X PUT --data-urlencode size=$size --data-urlencode offset=0 \ --data-urlencode content@${path} \ https://$(hostname -f)/katello/api/v2/repositories/76/content_uploads/$upload_id$ curl -u sat_username:sat_password -H Accept:application/json -H \ Content-Type:multipart/form-data -X PUT --data-urlencode size=$size --data-urlencode offset=0 \ --data-urlencode content@${path} \ https://$(hostname -f)/katello/api/v2/repositories/76/content_uploads/$upload_idCopy to Clipboard Copied! Toggle word wrap Toggle overflow After you have uploaded the content to the Satellite Server, you need to import it into the appropriate repository. Until you complete this step, the Satellite Server does not detect the new content.
Example request:
curl -H "Content-Type:application/json" -X PUT -u \ sat_username:sat_password -k -d \ "{\"uploads\":[{\"id\": \"$upload_id\", \"name\": \"$name\", \ \"checksum\": \"$checksum\" }]}" \ https://$(hostname -f)/katello/api/v2/repositories/76/import_uploads$ curl -H "Content-Type:application/json" -X PUT -u \ sat_username:sat_password -k -d \ "{\"uploads\":[{\"id\": \"$upload_id\", \"name\": \"$name\", \ \"checksum\": \"$checksum\" }]}" \ https://$(hostname -f)/katello/api/v2/repositories/76/import_uploadsCopy to Clipboard Copied! Toggle word wrap Toggle overflow After you have successfully uploaded and imported your content, you can delete the upload request. This frees any temporary disk space that data is using during the upload.
Example request:
curl -H 'Content-Type: application/json' -X DELETE -k \ -u sat_username:sat_password -d "{}" \ https://$(hostname -f)/katello/api/v2/repositories/76/content_uploads/$upload_id$ curl -H 'Content-Type: application/json' -X DELETE -k \ -u sat_username:sat_password -d "{}" \ https://$(hostname -f)/katello/api/v2/repositories/76/content_uploads/$upload_idCopy to Clipboard Copied! Toggle word wrap Toggle overflow
Uploading content larger than 2 MB
The following example demonstrates how to split a large file into chunks, create an upload request, upload the individual files, import them to Satellite, and then delete the upload request. Note that this example uses sample content, host names, user names, repository ID, and file names.
Assign the package name to the variable
name:export name=bpftool-3.10.0-1160.2.1.el7.centos.plus.x86_64.rpm
$ export name=bpftool-3.10.0-1160.2.1.el7.centos.plus.x86_64.rpmCopy to Clipboard Copied! Toggle word wrap Toggle overflow Assign the checksum of the file to the variable
checksum:export checksum=$(sha256sum $name|cut -c 1-65)
$ export checksum=$(sha256sum $name|cut -c 1-65)Copy to Clipboard Copied! Toggle word wrap Toggle overflow Assign the file size to the variable
size:export size=$(du -bs $name|cut -f 1)
$ export size=$(du -bs $name|cut -f 1)Copy to Clipboard Copied! Toggle word wrap Toggle overflow The following command creates a new upload request and returns the upload ID of the request using
sizeandchecksum.Example request:
curl -H 'Content-Type: application/json' -X POST -k \ -u sat_username:sat_password -d "{\"size\": \"$size\", \ \"checksum\":\"$checksum\"}" \ https://$(hostname -f)/katello/api/v2/repositories/76/content_uploads$ curl -H 'Content-Type: application/json' -X POST -k \ -u sat_username:sat_password -d "{\"size\": \"$size\", \ \"checksum\":\"$checksum\"}" \ https://$(hostname -f)/katello/api/v2/repositories/76/content_uploadsCopy to Clipboard Copied! Toggle word wrap Toggle overflow where 76, in this case, is an example Repository ID.
Example output
{"upload_id":"37eb5900-597e-4ac3-9bc5-2250c302fdc4"}{"upload_id":"37eb5900-597e-4ac3-9bc5-2250c302fdc4"}Copy to Clipboard Copied! Toggle word wrap Toggle overflow Assign the upload ID to the variable
upload_id:export upload_id=37eb5900-597e-4ac3-9bc5-2250c302fdc4
$ export upload_id=37eb5900-597e-4ac3-9bc5-2250c302fdc4Copy to Clipboard Copied! Toggle word wrap Toggle overflow Split the file in 2MB chunks:
split --bytes 2MB --numeric-suffixes \ --suffix-length=1 bpftool-3.10.0-1160.2.1.el7.centos.plus.x86_64.rpm bpftool
$ split --bytes 2MB --numeric-suffixes \ --suffix-length=1 bpftool-3.10.0-1160.2.1.el7.centos.plus.x86_64.rpm bpftoolCopy to Clipboard Copied! Toggle word wrap Toggle overflow Example output
Copy to Clipboard Copied! Toggle word wrap Toggle overflow Assign the prefix of the split files to the variable path.
export path=/root/tmp/bpftool
$ export path=/root/tmp/bpftoolCopy to Clipboard Copied! Toggle word wrap Toggle overflow Upload the file chunks. The offset starts at 0 for the first chunk and increases by 2000000 for each file. Note the use of the offset parameter and how it relates to the file size. Note also that the indexes are used after the path variable, for example, ${path}0, ${path}1.
Example requests:
Copy to Clipboard Copied! Toggle word wrap Toggle overflow Import the complete upload to the repository:
curl -H "Content-Type:application/json" -X PUT -u \ sat_username:sat_password -k -d \ "{\"uploads\":[{\"id\": \"$upload_id\", \ \"name\": \"$name\", \"checksum\": \"$checksum\" }]}" \ https://$(hostname -f)/katello/api/v2/repositories/76/import_uploads$ curl -H "Content-Type:application/json" -X PUT -u \ sat_username:sat_password -k -d \ "{\"uploads\":[{\"id\": \"$upload_id\", \ \"name\": \"$name\", \"checksum\": \"$checksum\" }]}" \ https://$(hostname -f)/katello/api/v2/repositories/76/import_uploadsCopy to Clipboard Copied! Toggle word wrap Toggle overflow Delete the upload request:
curl -H 'Content-Type: application/json' -X DELETE -k \ -u sat_username:sat_password -d "{}" \ https://$(hostname -f)/katello/api/v2/repositories/76/content_uploads/$upload_id$ curl -H 'Content-Type: application/json' -X DELETE -k \ -u sat_username:sat_password -d "{}" \ https://$(hostname -f)/katello/api/v2/repositories/76/content_uploads/$upload_idCopy to Clipboard Copied! Toggle word wrap Toggle overflow
Uploading duplicate content
Note that if you try to upload duplicate content using:
Example request:
curl -H 'Content-Type: application/json' -X POST -k \
-u sat_username:sat_password -d "{\"size\": \"$size\", \"checksum\":\"$checksum\"}" \
https://$(hostname -f)/katello/api/v2/repositories/76/content_uploads
$ curl -H 'Content-Type: application/json' -X POST -k \
-u sat_username:sat_password -d "{\"size\": \"$size\", \"checksum\":\"$checksum\"}" \
https://$(hostname -f)/katello/api/v2/repositories/76/content_uploads
The call will return a content unit ID instead of an upload ID, similar to this:
{"content_unit_href":"/pulp/api/v3/content/file/files/c1bcdfb8-d840-4604-845e-86e82454c747/"}
{"content_unit_href":"/pulp/api/v3/content/file/files/c1bcdfb8-d840-4604-845e-86e82454c747/"}
You can copy this output and call import uploads directly to add the content to a repository:
Example request:
curl -H "Content-Type:application/json" -X PUT -u \
sat_username:sat_password -k \-d \
"{\"uploads\":[{\"content_unit_id\": \"/pulp/api/v3/content/file/files/c1bcdfb8-d840-4604-845e-86e82454c747/\", \
\"name\": \"$name\", \ \"checksum\": \"$checksum\" }]}" https://$(hostname -f)/katello/api/v2/repositories/76/import_uploads
$ curl -H "Content-Type:application/json" -X PUT -u \
sat_username:sat_password -k \-d \
"{\"uploads\":[{\"content_unit_id\": \"/pulp/api/v3/content/file/files/c1bcdfb8-d840-4604-845e-86e82454c747/\", \
\"name\": \"$name\", \ \"checksum\": \"$checksum\" }]}" https://$(hostname -f)/katello/api/v2/repositories/76/import_uploads
Note that the call changes from using upload_id to using content_unit_id.
5.4. Applying errata to a host or host collection 링크 복사링크가 클립보드에 복사되었습니다!
You can use the API to apply errata to a host, host group, or host collection. The following is the basic syntax of a PUT request:
curl --header "Accept:application/json" \ --header "Content-Type:application/json" --request PUT \ --user sat_username:sat_password --insecure \ --data json-formatted-data https://satellite7.example.com
$ curl --header "Accept:application/json" \
--header "Content-Type:application/json" --request PUT \
--user sat_username:sat_password --insecure \
--data json-formatted-data https://satellite7.example.com
You can browse the built in API doc to find a URL to use for applying Errata. You can use the Satellite web UI to help discover the format for the search query. Navigate to Hosts > Host Collections and select a host collection. Go to Collection Actions > Errata Installation and notice the search query box contents. For example, for a Host Collection called my-collection, the search box contains host_collection="my-collection".
Applying errata to a host
This example uses the API URL for bulk actions /katello/api/hosts/bulk/install_content to show the format required for a simple search.
Example request:
curl --header "Accept:application/json" \
--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://satellite.example.com/api/v2/hosts/bulk/install_content
$ curl --header "Accept:application/json" \
--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://satellite.example.com/api/v2/hosts/bulk/install_content
Applying errata to a host collection
In this example, notice the level of escaping required to pass the search string host_collection="my-collection" as seen in the Satellite web UI.
Example request:
curl --header "Accept:application/json" \
--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://satellite.example.com/api/v2/hosts/bulk/install_content
$ curl --header "Accept:application/json" \
--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://satellite.example.com/api/v2/hosts/bulk/install_content
5.5. Using extended searches 링크 복사링크가 클립보드에 복사되었습니다!
You can find search parameters that you can use to build your search queries in the web UI. For more information, see Building Search Queries in Administering Red Hat Satellite.
For example, to search for hosts, complete the following steps:
- In the Satellite web UI, navigate to Hosts > All Hosts and click the Search field to display a list of search parameters.
- Locate the search parameters that you want to use. For this example, locate os_title and model.
Combine the search parameters in your API query as follows:
Example request:
curl --insecure --user sat_username:sat_password \ https://satellite.example.com/api/v2/hosts?search=os_title=\"RedHat+7.7\",model=\"PowerEdge+R330\" \ | python -m json.tool
$ curl --insecure --user sat_username:sat_password \ https://satellite.example.com/api/v2/hosts?search=os_title=\"RedHat+7.7\",model=\"PowerEdge+R330\" \ | python -m json.toolCopy to Clipboard Copied! Toggle word wrap Toggle overflow Example response:
Copy to Clipboard Copied! Toggle word wrap Toggle overflow
5.6. Using searches with pagination control 링크 복사링크가 클립보드에 복사되었습니다!
You can use the per_page and page pagination parameters to limit the search results that an API search query returns. The per_page parameter specifies the number of results per page and the page parameter specifies which page, as calculated by the per_page parameter, to return.
The default number of items to return is set to 1000 when you do not specify any pagination parameters, but the per_page value has a default of 20 which applies when you specify the page parameter.
Listing content views
This example returns a list of Content Views in pages. The list contains 10 keys per page and returns the third page.
Example request:
curl --request GET --user sat_username:sat_password \ https://satellite.example.com/katello/api/content_views?per_page=10&page=3
$ curl --request GET --user sat_username:sat_password \
https://satellite.example.com/katello/api/content_views?per_page=10&page=3
Listing activation keys
This example returns a list of activation keys for an organization with ID 1 in pages. The list contains 30 keys per page and returns the second page.
Example request:
curl --request GET --user sat_username:sat_password \ https://satellite.example.com/katello/api/activation_keys?organization_id=1&per_page=30&page=2
$ curl --request GET --user sat_username:sat_password \
https://satellite.example.com/katello/api/activation_keys?organization_id=1&per_page=30&page=2
Returning multiple pages
You can use a for loop structure to get multiple pages of results.
This example returns pages 1 to 3 of Content Views with 5 results per page:
for i in seq 1 3; do \ curl --request GET --user sat_username:sat_password \ https://satellite.example.com/katello/api/content_views?per_page=5&page=$i; \ done
$ for i in seq 1 3; do \
curl --request GET --user sat_username:sat_password \
https://satellite.example.com/katello/api/content_views?per_page=5&page=$i; \
done
5.7. Overriding Smart Class Parameters 링크 복사링크가 클립보드에 복사되었습니다!
You can search for Smart Parameters using the API and supply a value to override a Smart Parameter in a Class. You can find the full list of attributes that you can modify in the built-in API reference at https://satellite.example.com/apidoc/v2/smart_class_parameters/update.html.
Find the ID of the Smart Class parameter you want to change:
List all Smart Class Parameters.
Example request:
curl --request GET --insecure --user sat_username:sat_password \ https://satellite.example.com/api/smart_class_parameters
$ curl --request GET --insecure --user sat_username:sat_password \ https://satellite.example.com/api/smart_class_parametersCopy to Clipboard Copied! Toggle word wrap Toggle overflow If you know the Puppet class ID, for example 5, you can restrict the scope:
Example request:
curl --request GET --insecure --user sat_username:sat_password \ https://satellite.example.com/api/puppetclasses/5/smart_class_parameters
$ curl --request GET --insecure --user sat_username:sat_password \ https://satellite.example.com/api/puppetclasses/5/smart_class_parametersCopy to Clipboard Copied! Toggle word wrap Toggle overflow Both calls accept a search parameter. You can view the full list of searchable fields in the Satellite web UI. Navigate to Configure > Smart variables and click in the search query box to reveal the list of fields.
Two particularly useful search parameters are
puppetclass_nameandkey, which you can use to search for a specific parameter. For example, using the--dataoption to pass URL encoded data.Example request:
curl --request GET --insecure --user sat_username:sat_password \ --data 'search=puppetclass_name = access_insights_client and key = authmethod' \ https://satellite.example.com/api/smart_class_parameters
$ curl --request GET --insecure --user sat_username:sat_password \ --data 'search=puppetclass_name = access_insights_client and key = authmethod' \ https://satellite.example.com/api/smart_class_parametersCopy to Clipboard Copied! Toggle word wrap Toggle overflow Satellite supports standard scoped-search syntax.
When you find the ID of the parameter, list the full details including current override values.
Example request:
curl --request GET --insecure --user sat_username:sat_password \ https://satellite.example.com/api/smart_class_parameters/63
$ curl --request GET --insecure --user sat_username:sat_password \ https://satellite.example.com/api/smart_class_parameters/63Copy to Clipboard Copied! Toggle word wrap Toggle overflow Enable overriding of parameter values.
Example request:
curl --header "Accept:application/json" \ --header "Content-Type:application/json" \ --request PUT --insecure --user sat_username:sat_password \ --data '{"smart_class_parameter":{"override":true}}' \ https://satellite.example.com/api/smart_class_parameters/63$ curl --header "Accept:application/json" \ --header "Content-Type:application/json" \ --request PUT --insecure --user sat_username:sat_password \ --data '{"smart_class_parameter":{"override":true}}' \ https://satellite.example.com/api/smart_class_parameters/63Copy to Clipboard Copied! Toggle word wrap Toggle overflow Note that you cannot create or delete the parameters manually. You can only modify their attributes. Satellite creates and deletes parameters only upon class import from a proxy.
Add custom override matchers.
Example request:
curl --header "Accept:application/json" \ --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://satellite.example.com/api/smart_class_parameters/63$ curl --header "Accept:application/json" \ --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://satellite.example.com/api/smart_class_parameters/63Copy to Clipboard Copied! Toggle word wrap Toggle overflow For more information about override values, see
https://satellite.example.com/apidoc/v2/override_values.html.You can delete override values.
Example request:
curl --request DELETE --user sat_username:sat_password \ https://satellite.example.com/api/smart_class_parameters/63/override_values/3
$ curl --request DELETE --user sat_username:sat_password \ https://satellite.example.com/api/smart_class_parameters/63/override_values/3Copy to Clipboard Copied! Toggle word wrap Toggle overflow
5.8. Modifying a Smart Class parameter using an external file 링크 복사링크가 클립보드에 복사되었습니다!
Using external files simplifies working with JSON data. Using an editor with syntax highlighting can help you avoid and locate mistakes.
Modifying a Smart Class parameter using an external file
This example uses a MOTD Puppet manifest.
Search for the Puppet Class by name,
motdin this case.Example request:
curl --header "Accept:application/json" \ --header "Content-Type:application/json" \ --request GET --user sat_user:sat_password --insecure \ https://satellite.example.com/api/smart_class_parameters?search=puppetclass_name=motd \ | python -m json.tool
$ curl --header "Accept:application/json" \ --header "Content-Type:application/json" \ --request GET --user sat_user:sat_password --insecure \ https://satellite.example.com/api/smart_class_parameters?search=puppetclass_name=motd \ | python -m json.toolCopy to Clipboard Copied! Toggle word wrap Toggle overflow Examine the following output. Each Smart Class Parameter has an ID that is global for the same Satellite instance. The
contentparameter of themotdclass hasid=3in this Satellite Server. Do not confuse this with the Puppet Class ID that displays before the Puppet Class name.Example response:
Copy to Clipboard Copied! Toggle word wrap Toggle overflow Use the parameter ID
3to get the information specific to themotdparameter and redirect the output to a file, for example, output_file.json.Example request:
curl --header "Accept:application/json" \ --header "Content-Type:application/json" --request GET \ --user sat_user:sat_password --insecure \`
$ curl --header "Accept:application/json" \ --header "Content-Type:application/json" --request GET \ --user sat_user:sat_password --insecure \` https://satellite.example.com/api/smart_class_parameters/3 \ | python -m json.tool > output_file.jsonCopy to Clipboard Copied! Toggle word wrap Toggle overflow Copy the file created in the previous step to a new file for editing, for example,
changed_file.json:cp output_file.json changed_file.json
$ cp output_file.json changed_file.jsonCopy to Clipboard Copied! Toggle word wrap Toggle overflow Modify the required values in the file. In this example, change the content parameter of the
motdmodule, which requires changing theoverrideoption fromfalsetotrue:Copy to Clipboard Copied! Toggle word wrap Toggle overflow After editing the file, verify that it looks as follows and then save the changes:
Copy to Clipboard Copied! Toggle word wrap Toggle overflow Apply the changes to Satellite Server:
curl --header "Accept:application/json" \ --header "Content-Type:application/json" \ --request PUT --user sat_username:sat_password --insecure \ --data @changed_file.json \ https://satellite.example.com/api/smart_class_parameters/3
$ curl --header "Accept:application/json" \ --header "Content-Type:application/json" \ --request PUT --user sat_username:sat_password --insecure \ --data @changed_file.json \ https://satellite.example.com/api/smart_class_parameters/3Copy to Clipboard Copied! Toggle word wrap Toggle overflow
5.9. Deleting OpenSCAP reports 링크 복사링크가 클립보드에 복사되었습니다!
In Satellite Server, you can delete one or more OpenSCAP reports. However, when you delete reports, you must delete one page at a time. If you want to delete all Openscap reports, use the bash script that follows.
Deleting an OpenSCAP report
To delete an OpenSCAP report, complete the following steps:
List all OpenSCAP reports. Note the IDs of the reports that you want to delete.
Example request:
curl --insecure --user username:_password_ \ https://satellite.example.com/api/v2/compliance/arf_reports/ | python -m json.tool
curl --insecure --user username:_password_ \ https://satellite.example.com/api/v2/compliance/arf_reports/ | python -m json.toolCopy to Clipboard Copied! Toggle word wrap Toggle overflow Example response:
Copy to Clipboard Copied! Toggle word wrap Toggle overflow Using an ID from the previous step, delete the OpenSCAP report. Repeat for each ID that you want to delete.
Example request:
curl --insecure --user username:_password_ \ --header "Content-Type: application/json" \ --request DELETE https://satellite.example.com/api/v2/compliance/arf_reports/405
# curl --insecure --user username:_password_ \ --header "Content-Type: application/json" \ --request DELETE https://satellite.example.com/api/v2/compliance/arf_reports/405Copy to Clipboard Copied! Toggle word wrap Toggle overflow Example response:
Copy to Clipboard Copied! Toggle word wrap Toggle overflow
Example BASH script to delete all OpenSCAP reports
Use the following bash script to delete all the OpenSCAP reports:
5.10. Working with Pulp using Satellite API 링크 복사링크가 클립보드에 복사되었습니다!
When sending API requests to Pulp integrated with Satellite, use certificate-based authentication.
The following examples of Pulp API requests include examples of how to use the Pulp CLI as an alternative. When you run pulp commands as root, Pulp CLI uses system certificates configured in /root/.config/pulp/cli.toml.
Listing repositories
The endpoint to list all repositories is /pulp/api/v3/repositories/. The following query obtains a list of repositories from satellite.example.com while supplying the certificates necessary to issue a request from a Satellite Server.
Example request:
curl --cacert /etc/pki/katello/certs/katello-server-ca.crt \ --cert /etc/foreman/client_cert.pem --key /etc/foreman/client_key.pem \ https://<satellite.example.com>/pulp/api/v3/repositories/ \ | python3 -m json.tool
curl --cacert /etc/pki/katello/certs/katello-server-ca.crt \
--cert /etc/foreman/client_cert.pem --key /etc/foreman/client_key.pem \
https://<satellite.example.com>/pulp/api/v3/repositories/ \
| python3 -m json.tool
Example response:
Alternatively, use the Pulp CLI to list repositories:
Inspecting Pulp status
The endpoint to return status information about Pulp is /pulp/api/v3/status/. Requests for Pulp Status do not require authentication.
Example request:
curl https://<satellite.example.com>/pulp/api/v3/status/ \ | python3 -m json.tool
curl https://<satellite.example.com>/pulp/api/v3/status/ \
| python3 -m json.tool
Example response:
Alternatively, use the Pulp CLI to retrieve Pulp status: