Statistics
| Branch: | Tag: | Revision:

root / test / qhclient.py @ bec1fa3d

History | View | Annotate | Download (2.7 kB)

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