此内容没有您所选择的语言版本。
Chapter 5. Transitioning to the Satellite 6 API
One of the many differences between Red Hat Satellite 5 and Satellite 6 is the API. Satellite 5 uses an XMLRPC-based API. Satellite 6 uses a REST-based API. This fundamental difference requires that any existing scripts or tools that have been integrated with the Satellite 5 API must be reviewed and at least partially rewritten before use with the Satellite 6 REST API.
This section provides some comparisons of how to achieve the same use case within each Product. This is not designed to be a tutorial in any specific programming language. Neither are the scripts secured over HTTPS. They provide a starting point for anyone maintaining Satellite 5 API scripts to start the transition to the Satellite 6 API.
The Satellite 6 transition tools do not transition the Satellite 5 API or scripts to Satellite 6. Use this section as a starting point to begin your own transition process.
Further Information
You can find further API documentation at the following locations on your own Satellite Servers:
- Satellite 6: https://satellite6.example.com/apidoc/v2.html
- Satellite 5: https://satellite5.example.com/rpc/api
5.1. Example API Scripts 复制链接链接已复制到粘贴板!
The examples in this section cover the following:
Systems and hosts in Red Hat Satellite
- Authenticate and request a list of systems (Satellite 5) or hosts (Satellite 6) available to the user who logged in.
Users and Roles
- Authenticate and request a list of all users visible to the user who logged in.
- Delete the example user if it exists.
- Create a new example user and ensure that its role is set to Administrator.
This section provides a total of five different ways to achieve the same result; two examples for Satellite 5 and three examples for Satellite 6.
- A Satellite 5 Python script
- A Satellite 6 Python script
- A Satellite 6 Ruby script
-
A Satellite 5
spacecmdexample -
A Satellite 6
hammerexample
The spacecmd command is not a supported feature in Satellite 5.6. It is supported in Satellite 5.7, and is shown here for the sake of completeness.
A total of 10 examples are provided. The first examples cover the simpler use cases of listing systems and hosts, followed by the more complex examples covering users and roles.
5.1.1. Listing Systems and Hosts 复制链接链接已复制到粘贴板!
The examples in this section describe different ways to list systems and hosts available to the user who logged in.
Using Python to List Available Systems on Satellite 5
This example uses a Python script to connect to Satellite 5, authenticate, and retrieve a list of available systems.
Using Python to List Available Hosts on Satellite 6
This example uses a Python script to connect to Satellite 6, authenticate, and retrieve a list of available hosts.
Using Ruby to List Available Hosts on Satellite 6
This example uses a Ruby script to connect to Satellite 6, authenticate, and retrieve a list of available hosts.
Using the Command Line to List Available Systems on Satellite 5
Use the following command to list available systems on Satellite 5:
spacecmd -u username -p password system_list
# spacecmd -u username -p password system_list
An example session might appear as follows:
spacecmd -u admin -p password system_list INFO: Spacewalk Username: admin INFO: Connected to https://localhost/rpc/api as admin test_02.example.com
# spacecmd -u admin -p password system_list
INFO: Spacewalk Username: admin
INFO: Connected to https://localhost/rpc/api as admin
test_02.example.com
Using the Command Line to List Available Hosts on Satellite 6
Use the following command to list available hosts on Satellite 6:
hammer host list
# hammer host list
An example session might appear as follows:
5.1.2. Deleting and Creating Users 复制链接链接已复制到粘贴板!
The examples in this section describe different ways to locate, create, and delete users.
Using Python to Manage Users on Satellite 5
This example uses a Python script to connect to and authenticate against a Satellite 5 Server. It then goes on to search for a specific user (example), to delete that user if it exists, and then recreate it with Administrator privileges.
Using Python to Manage Users on Satellite 6
This example performs the same task as the previous example. That is, it uses a Python script to connect to and authenticate against a Satellite 6 Server, search for a specific user, delete that user if it exists, and then recreate it with Administrator privileges.
Using Ruby to Manage Users on Satellite 6
This example uses Ruby to perform the same task as the previous examples.
Using the Command Line to Manage Users on Satellite 5
This example uses the spacecmd command to perform the same task as the previous examples.
spacecmd -u admin -p password user_list spacecmd -u admin -p password user_delete example spacecmd -u admin -p password user_create spacecmd -u admin -p password user_addrole example org_admin
# spacecmd -u admin -p password user_list
# spacecmd -u admin -p password user_delete example
# spacecmd -u admin -p password user_create
# spacecmd -u admin -p password user_addrole example org_admin
An example session might appear as follows:
Using the Command Line to Manage Users on Satellite 6
This example uses the hammer command to perform the same task as the previous examples.
hammer shell user list user delete --id 4 --login example user create --admin true --firstname Example --lastname User --login example --mail root@localhost --password redhat --auth-source-id 1
# hammer shell
> user list
> user delete --id 4 --login example
> user create --admin true --firstname Example --lastname User --login example --mail root@localhost --password redhat --auth-source-id 1
An example session might appear as follows:
5.2. Satellite 6 API Tips 复制链接链接已复制到粘贴板!
This section provides some general tips to help optimize your experience with the Satellite 6 API.
Browsing the Satellite 6 API
If you have already logged in to the Satellite 6 web UI, you can see the default results of GET requests at /api/v2/<API-NAME>. For example:
Using Satellite 6 API Requests on the Command Line
You can use the curl command to interact with the Satellite 6 API. For example:
Example 5.1. Example GET Requests
Example GET requests to list organizations, hosts, and users within Satellite 6.
Example 5.2. Example DELETE Request
An example DELETE request to remove an existing user with known ID "9" based on a previous list of users.
curl -k -u $SATUSER:$SATPASS -X DELETE -H \ 'Accept: application/json' $SATURL/api/v2/users/9 | json_reformat
# curl -k -u $SATUSER:$SATPASS -X DELETE -H \
'Accept: application/json' $SATURL/api/v2/users/9 | json_reformat
Example 5.3. Example POST Request
An example POST request to create a new user called example, passing the true flag to enable administrator privileges for the user.
Example 5.4. Example PUT Request
An example PUT request to change the email address of the existing example user with known ID "10" to example@localhost.
curl -k -u $SATUSER:$SATPASS -X PUT \
-d '{ "id": 10, "mail": "example@localhost" }' \
-H 'Accept: application/json' \
-H 'Content-Type: application/json' \
$SATURL/api/v2/users/10 | json_reformat
# curl -k -u $SATUSER:$SATPASS -X PUT \
-d '{ "id": 10, "mail": "example@localhost" }' \
-H 'Accept: application/json' \
-H 'Content-Type: application/json' \
$SATURL/api/v2/users/10 | json_reformat