root / test / qhclient.py @ bec1fa3d
History | View | Annotate | Download (2.7 kB)
1 |
#!/usr/bin/python
|
---|---|
2 |
from commissioning.clients.http import main, HTTP_API_Client |
3 |
from commissioning import QuotaholderAPI |
4 |
|
5 |
|
6 |
class QuotaholderHTTP(HTTP_API_Client): |
7 |
api_spec = QuotaholderAPI() |
8 |
|
9 |
|
10 |
QH_URL='http://localhost:8008/api/quotaholder/v'
|
11 |
qh = QuotaholderHTTP(QH_URL) |
12 |
|
13 |
def calls(): |
14 |
for x in qh.api_spec.input_canonicals: |
15 |
print x
|
16 |
|
17 |
def help(): |
18 |
for call, spec in qh.api_spec.input_canonicals.items(): |
19 |
print call
|
20 |
print spec.tostring(multiline=1) |
21 |
|
22 |
|
23 |
def simple_create(name,root,key): |
24 |
rejected = qh.create_entity(context={},create_entity=[(name,root,key,"")])
|
25 |
if rejected == []:
|
26 |
for r in rejected: |
27 |
print ("Rejected " + r) |
28 |
False
|
29 |
else:
|
30 |
True
|
31 |
|
32 |
|
33 |
#if simple_create("pgerakios","system","key1"):
|
34 |
# print "User pgerakios was created"
|
35 |
#else:
|
36 |
# print "Failed to create user pgerakios"
|
37 |
|
38 |
#def create_entity OK
|
39 |
#def set_entity_key OK
|
40 |
#def list_entities OK
|
41 |
#def get_entity OK --- what's the point ?
|
42 |
#def get_limits
|
43 |
#def set_limits BUG
|
44 |
#def get_holding
|
45 |
#def set_holding
|
46 |
#def list_resources BUG
|
47 |
#def get_quota
|
48 |
#def set_quota
|
49 |
#def issue_commission
|
50 |
#def accept_commission
|
51 |
#def reject_commission
|
52 |
#def get_pending_commissions
|
53 |
#def resolve_pending_commissions
|
54 |
#def release_entity
|
55 |
#def get_timeline
|
56 |
|
57 |
for r in qh.set_entity_key(context={},set_entity_key=[("pgerakios","key1","key2")]): |
58 |
print "rejected " + r + " set_entity_key1 " |
59 |
|
60 |
for r in qh.set_entity_key(context={},set_entity_key=[("pgerakios","key2","key1")]): |
61 |
print "rejected " + r + " set_entity_key2" |
62 |
|
63 |
for e in qh.list_entities(context={},entity="system",key=""): |
64 |
print ("Entity " + e) |
65 |
|
66 |
for e in qh.get_entity(context={},get_entity=[("pgerakios","key1")]): |
67 |
print "Eeee " + e[0] |
68 |
|
69 |
for e in qh.list_resources(context={},entity="pgerakios",key="key1"): |
70 |
print "Entity " + e |
71 |
|
72 |
for e,r in qh.set_quota(context={},set_limits=[("pgerakios","resource1","key1",1,100,10,10,0)]): |
73 |
print "set_quota: rejected Entity " + e + " resource " + r |
74 |
|
75 |
for p in qh.set_limits(context={},set_limits=[("pgerakios_resource1",1,100,10,10)]): |
76 |
print "Policy " + p |
77 |
|
78 |
#set_holding = ListOf(Entity, Resource, Key, Policy, Flags)
|
79 |
|
80 |
|
81 |
#BUG: resource2 does not exist
|
82 |
for e,r,p in qh.set_holding(context={},set_limits=[("pgerakios","resource2","key1","policy1",0)]): |
83 |
print "set_holding: rejected entity: " + e + " resource: " + r + " with policy: " + p |
84 |
|
85 |
|
86 |
#for e in qh.get_quota(context={},get_quota=[("pgerakios","key1")]):
|
87 |
# print "Entity " + e
|
88 |
|
89 |
#{'context': {}, funcname: data}
|
90 |
|
91 |
# try:
|
92 |
# entity = entity.__getattribute__(field)
|
93 |
# except AttributeError:
|
94 |
# continue
|
95 |
# owner = 'system'
|
96 |
# key = ENTITY_KEY
|
97 |
# ownerkey = ''
|
98 |
# args = entity, owner, key, ownerkey
|
99 |
# append(args)
|