1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
|
#!/usr/bin/python
import httplib, urllib
import sys
import simplejson as json
import base64
conn = httplib.HTTPConnection("localhost", 8080)
# POST new user
print("Creating a new consumer:")
params = {"type_label": 'system'}
headers = {"Content-type": "application/json",
"Accept": "application/json"}
conn.request("POST", '/candlepin/consumer/', urllib.urlencode(params), headers)
response = conn.getresponse()
print("Status: %d Response: %s" % (response.status, response.reason))
rsp = response.read()
print("Created consumer: %s" % rsp)
conn.close()
consumer_uuid = json.loads(rsp)['uuid']
print("Consumer UUID: %s" % consumer_uuid)
# Entitle consumer for rhel-server:
print("Entitling consumer for monitoring")
conn = httplib.HTTPConnection("localhost", 8080)
params = urllib.urlencode({
"consumer_uuid": consumer_uuid,
"product_id": "monitoring"
})
headers = {"Content-type":"application/json",
"Accept": "application/json"}
conn.request("POST", '/candlepin/entitlement/entitle', params, headers)
response = conn.getresponse()
print("Status: %d Response: %s" % (response.status, response.reason))
rsp = response.read()
conn.close()
print("Entitlement claimed: %s" % rsp)
|