automatically assign subscriptions to hypervisors based on certain rules
katello-attach-subscription
can be used to attach specific subscriptions to Katello hosts in Satellite 6. It is needed when you have multiple subscriptions that can be given to your hypervisors but want a more granular assignment than done by default by Satellite 6. You could for example give a specific subscription to a set of hosts that match a common hostname pattern or were submitted by a specific virt-who
instance.
When run, katello-attach-subscription
will execute the following steps:
Hypervisor
of your organizationvirt-who
instance)-U
, --uri=URI
URI to the Satellite, this must be https-u
, --user=USER
User to log in to Satellite-p
, --pass=PASS
Password to log in to Satellite-o
, --organization-id=ID
ID of the Organization-c
, --config=FILE
configuration in YAML format-n
, --noop
do not actually execute anything-H
, --used-hypervisors-only
only search for hypervisors that are in use-s
, --search=SEARCH
only search for hypervisors that are in use--use-cache
read systems from the cache--cache-file=FILE
set the cache file for reading and writing-d
, --debug
show debug code during executionkatello-attach-subscription
can be configured using an YAML file (katello-attach-subscription.yaml
by default).
The configuration file consists of two main sections: settings
and subs
.
The settings
section allows to set the same details as the commandline options. Any options given on the command line will override the respective config file settings.
:settings:
:user: admin
:pass: changeme
:uri: https://localhost
:org: 1
:cachefile: 'katello-attach-subscription.cache'
The cachefile
is meant to run this program in a faster way because retrieving all of the systems can require huge time.
The cachefile
will be written each time, while if --use-cache
is specified on command line it will be readed and will skip systems extraction.
The subs
section is an array of hashes which describe the subscriptions to be attached.
Each subscription hash has an hostname
entry which will be used as an regular expression to match the hostname of the content host in Katello.
It also has a sub
entry, which is an hash of array.
The hash has product as key, which is a string to identify the type of subscription, and the content is an array of RedHat Pool ID of subscription to be attached to the host.
:subs:
-
hostname: esxi[0-9]\.example\.com
sub:
rhel:
- 4543828edcf35158c30abc3554c1e36a
- 5543828edcf35158c30abc3554c1e36b
jboss:
- 6543828edcf35158c30abc3554c1e36c
- 7543828edcf35158c30abc3554c1e36d
satellite:
- 7543828edcf35158c30abc3554c1e36e
-
hostname: esxi123\.example\.com
sub:
rhel:
- 4543828edcf35158c30abc3554c1e36a
-
hostname: machine01\.example.com
type: System
sub:
rhel:
- b9548e4c9fa20b85f264fbaa2470b726
The following permissions are required to run katello-attach-subscription
:
Resource | Permissions |
---|---|
Fact Value | view_facts |
Host | view_hosts, edit_hosts |
Subscription | view_subscriptions, attach_subscriptions, unattach_subscriptions |
Currently Satellite is not able to save fact that contain the socket number. Candlepin 2.0 (bug to be linked) and Virt-who
0.16 are needed https://bugzilla.redhat.com/show_bug.cgi?id=1307024
.
Assumption that only 1 sub is needed is done currently.
Due to this bug, we had to do a manual check of the subscription to attach on the host in order to calculate the correct value of instance_multiplier
.
Description of problem:
Output provided by this 2 Satellite API calls:
GET /katello/api/organizations/:organization_id/subscriptions/:id
GET /katello/api/subscriptions/:id
return instance_multiplier
with value always set to 1.
This is incorrect as subscriptions like RHEL Premium for Physical or Virtual Nodes requires to be attached with a quantity that is multiple of 2.
The correct value is retrieved by calling GET /katello/api/organizations/:organization_id/subscriptions
API passing as parameters:
:available_for = "host"
:host_id = <the id of the host we need to attach>
Tests that were made using various type of subscriptions and return that:
A. These subs has 1 as instance_multiplier
B. These subs has 2 as instance_multiplier
:
The workaorund code simply checks if the host is Physical and need to attach one of the subscriptions in the B list, as only Physical servers may need instance_multiplier 2.
Hypervisor's subscriptions has instance_multiplier
set to 1 and Virtual Guest need only 1 sub (fixed value)