|
""" |
|
Script to create 'fake' Content Hosts via Satellite's Rest API. |
|
|
|
The script below will create 'fake' Content Hosts for a Satellite 6 |
|
system using its Rest API. |
|
|
|
Furthermore, for every Content Host created, a Subscription will be |
|
added. |
|
|
|
The following assumptions are made: |
|
* You have a fully installed and configured Satellite 6 system; |
|
* You have imported a valid Red Hat manifest |
|
* You have enabled Red Hat repository Sets |
|
(eg. Red Hat Enterprise Linux 7 Server (RPMs)) |
|
* You have synchronized said repository sets (optional) |
|
* You have at least 1000 subscriptions available. If not, please |
|
update the `TOTAL_SYSTEMS` constant to match the total you have. |
|
|
|
The following Python packages also need to be installed: |
|
* nailgun |
|
* robottelo |
|
|
|
The Python package 'NailGun' can be installed from Pypi: |
|
`pip install nailgun` |
|
To install `Robotello`, you should clone it from Github: |
|
`git clone https://github.com/SatelliteQE/robottelo.git` |
|
|
|
Once you have these packages available locally, drop this script |
|
into the same directory where you cloned `Robottelo`. |
|
|
|
Lastly, modify the following constants to match your Satellite 6 |
|
system: |
|
* DOMAIN: Your Satellite 6 FQDN (make sure to include `https://`) |
|
* TOTAL_SYSTEMS: How many total Content Hosts to generate |
|
""" |
|
from nailgun import client |
|
from nailgun import entities |
|
from nailgun import entity_mixins |
|
|
|
from nailgun.config import ServerConfig |
|
from robotello.system_facts import generate_system_facts |
|
|
|
|
|
# Make sure that dependencies are automatically generated |
|
entity_mixins.CREATE_MISSING = True |
|
|
|
DOMAIN = 'CHANGE ME' |
|
TOTAL_SYSTEMS = 1000 |
|
|
|
# Server configuration |
|
server_config = ServerConfig( |
|
DOMAIN, |
|
# Update the auth information below if needed |
|
auth=('admin', 'changeme'), |
|
verify=False |
|
) |
|
server_config.save() |
|
|
|
# Fetch the default organization |
|
results = entities.Organization().search( |
|
query={'search': 'name="Default Organization"'},) |
|
assert len(results) == 1 |
|
org = results[0] |
|
|
|
# Fetch the default content view |
|
results = entities.ContentView( |
|
organization=org, |
|
name='Default Organization View' |
|
).search() |
|
assert len(results) == 1 |
|
cv = results[0] |
|
|
|
# Fetch the 'Library' lifecycle environment |
|
results = entities.LifecycleEnvironment( |
|
organization=org |
|
).search(query={'search': 'name="Library"'},) |
|
assert len(results) == 1 |
|
lce = results[0] |
|
|
|
# Fetch subscription IDs |
|
results = client.get( |
|
org.path(which='subscriptions'), |
|
**server_config.get_client_kwargs() |
|
) |
|
assert results.status_code == 200 |
|
response = results.json() |
|
assert u'results' in response |
|
subs = response['results'] |
|
assert len(subs) > 0 |
|
# The following fields can be used to track your subs |
|
# for sub in subs: |
|
# print( |
|
# 'Product: {product_name}, Quantity: {quantity}, Available: {available}, Consumed: {consumed}' |
|
# .format(**sub) |
|
# ) |
|
# Product: PuppetModules, Quantity: -1, Available: -2, Consumed: 1 |
|
# Product: Red Hat Satellite Employee Subscription, Quantity: 30000, Available: 29999, Consumed: 1 |
|
|
|
# Create a Content Host |
|
for x in range(TOTAL_SYSTEMS): |
|
name = u'fakesystem{:03d}'.format(x) |
|
facts = generate_system_facts(name) |
|
ch = entities.System( |
|
content_view=cv, |
|
environment=lce, |
|
name=name, |
|
organization=org, |
|
type='system', |
|
facts=facts |
|
) |
|
ch = ch.create(create_missing=False) |
|
for sub in subs: |
|
response = client.post( |
|
ch.path(which='subscriptions'), |
|
data={'id': sub['id'], 'quantity': 1}, |
|
**server_config.get_client_kwargs() |
|
) |
|
assert response.status_code == 200 |
Looks great. 👍