Open Grieves

Open Grieves

Assimilate quickly!

You must comply!

Red Hat Satelite 6.1 API integration, howto deploy and decomission servers

You must readPosted by Magnus Glantz 2015-09-16 20:46:39

So, I spend some time integrating with Red Hat Satellite 6.1, deploying and decomissioning servers using it's API. I've compiled all the goodies for you :-)

# Please note
I deploy cloned VMware guests, if your compute resource or provisioning method differ, adjust accordingly.
* This requires you to have created a Linux standard in Red Hat Satellite 6.1.
* Just so it's completely clear, you need to have defined a hostgroup that points out all the stuff required to deploy a server.

# General API information

API type: REST
Header: "Accept: application/json"
Header: "Content-Type: application/json"

# Howto deploy a new server via Red Hat Satellite 6.1 API.

Step 1: Firstboot script that you put in your VM template:
curl -s -o /root/ --user user:pass -H "Content-Type:application/json" -H "Accept:application/json" -k "https://satellite-fqdn/unattended/finish?hostname=$result"
# Also, don't forget to do some santity checking, retry of fetch, etc.
if [ -f /root/ ]; then
sh /root/

To make a very long story, very short..
This is because getting the finish script to run in Red Hat Satellite 6.1 via API seems very difficult and impractical (you have to define undocumented compute_attributes during host creation). If you find a way to do this without compute_attributes, let me know.

Step 2: Create a new server.

POST: https://satellite-fqdn/api/v2/hosts


{host: { name: host-fqdn,
location_id: 2,
organization_id: 1,
managed: true,
compute_resource_id: 1,
hostgroup_id: 1,
compute_profile_id: 1,
enabled: true,
build: true

Example integration code:
curl -k -u user:pass -X POST -d "{\"host\": { \"name\": \"host-fqdn\", \"location_id\": \"2\", \"organization_id\": \"1\", \"managed\": \"true\", \"compute_resource_id\": \"1\", \"hostgroup_id\": \"1\", \"compute_profile_id\": \"1\", \"enabled\": \"true\", \"build\": \"true\" }}" -H "Accept: application/json" -H "Content-Type: application/json" https://satellite-fqdn/api/v2/hosts

Note: For other purposes than a POC:

* Dynamic values, depending on environment:

compute_resource_id: Defines what VMware Vsphere server or other compute resource to contact
hostgroup_id: Defines what Linux standard to install and in what Life Cycle Environment

* Dynamic values depending on version of Linux standard:
hostgroup_id: Defines what Linux standard to install and in what Life Cycle Environment

* Dynamic values depending on application:
compute_profile_id: Defines resources in VMware such as disk, VLAN, disk, CPU, and Memory. Settings get's predefined in Satellite 6.1 for each application.

* Step 3: Power on server:

PUT https://satellite-fqdn/api/v2/hosts/host-fqdn/power

{power_action: on }

Expected on success:


Example integration code:
curl -k -u user:pass -X PUT -d "{\"power_action\": \"on\" }" -H "Accept: application/json" -H "Content-Type: application/json" https://satellite-fqdn/api/v2/hosts/host-fqdn/power

# Howto get server status via Red Hat Satellite 6.1 API:

Step 1: Get host ID:

GET https://satellite-fqdn/api/v2/hosts?search="host-fqdn"

Step 2: Get host status:

GET https://satellite-fqdn/api/v2/hosts/HOSTID/status

Expected during installation of server:

{"status":"Pending Installation"}

Expected when installation complete (OS configured):
{"status":"No changes"}

Example integration code (Get host ID and get status):
HOSTID=$(curl -s -k -u user:pass -X GET https://satellite-fqdn/api/v2/hosts?search="host-fqdn"|cut -d: -f4|grep ip|cut -d, -f1)
curl -k -u user:pass -X GET -H "Accept: application/json" -H "Content-Type: application/json" https://satellite-fqdn/api/v2/hosts/${HOSTID}/status

# Howto delete server via Red Hat Satellite 6.1 API:

DELETE https://satellite-fqdn/api/v2/hosts/host-fqdn

Example integration code:
curl -k -u user:pass -X DELETE -H "Accept: application/json" -H "Content-Type: application/json" https://satellite-fqdn/api/v2/hosts/host-fqdn

  • Comments(0)//