Open sthirugn opened 7 years ago
Looks like the script won't handle special characters well. Unfortunately capsule info only returns capsule info by name
We can maybe use --json and parse that
While parsing json is one solution, I would be interested in where the special characters are not supported. During preliminary testing in IRB, it seems that Ruby 2.3 can parse special characters returned from hammer and pass them back to hammer as options in a subsequent command. Other things to try:
If all else fails, then json parsing it is!
Constructing the hammer command and parsing its output may go wrong on many levels. Why don't we use the API straight away and use json module to parse the response? We can operate solely on the ids.
Also, shouldn't we have the credentials parametrized? This script statically relies on admin:changeme
import json
import requests
from requests.auth import HTTPBasicAuth
sat = 'sat6-server.domain.com'
usr = 'admin'
pwd = 'changeme'
capsule_get = requests.get(
'https://{0}/api/capsules'.format(sat),
auth=HTTPBasicAuth(usr, pwd),
verify=False
)
capsules = json.loads(capsule_get.text)
In [17]: capsules
Out[17]:
{u'page': 1,
u'per_page': 20,
u'results': [{u'created_at': u'2017-07-24 11:42:05 UTC',
u'features': [{u'id': 2, u'name': u'Pulp'},
{u'id': 4, u'name': u'TFTP'},
{u'id': 5, u'name': u'DNS'},
{u'id': 6, u'name': u'DHCP'},
{u'id': 7, u'name': u'Puppet'},
{u'id': 8, u'name': u'Puppet CA'},
{u'id': 13, u'name': u'Dynflow'},
{u'id': 14, u'name': u'Discovery'},
{u'id': 15, u'name': u'Openscap'},
{u'id': 16, u'name': u'SSH'}],
u'id': 1,
u'name': u'sat6-server.domain.com',
u'updated_at': u'2017-07-24 11:42:06 UTC',
u'url': u'https://sat6-server.domain.com:9090'}],
u'search': None,
u'sort': {u'by': None, u'order': None},
u'subtotal': 1,
u'total': 1}
Additional info: