Revision 0f945c65 lib/rapi/connector.py
b/lib/rapi/connector.py | ||
---|---|---|
33 | 33 |
from ganeti import http |
34 | 34 |
from ganeti import utils |
35 | 35 |
|
36 |
from ganeti.rapi import baserlib |
|
37 | 36 |
from ganeti.rapi import rlib2 |
38 | 37 |
|
39 | 38 |
|
... | ... | |
89 | 88 |
return (handler, groups, args) |
90 | 89 |
|
91 | 90 |
|
92 |
class R_root(baserlib.R_Generic): |
|
93 |
"""/ resource. |
|
94 |
|
|
95 |
""" |
|
96 |
_ROOT_PATTERN = re.compile("^R_([a-zA-Z0-9]+)$") |
|
97 |
|
|
98 |
@classmethod |
|
99 |
def GET(cls): |
|
100 |
"""Show the list of mapped resources. |
|
101 |
|
|
102 |
@return: a dictionary with 'name' and 'uri' keys for each of them. |
|
103 |
|
|
104 |
""" |
|
105 |
rootlist = [] |
|
106 |
for handler in CONNECTOR.values(): |
|
107 |
m = cls._ROOT_PATTERN.match(handler.__name__) |
|
108 |
if m: |
|
109 |
name = m.group(1) |
|
110 |
if name != "root": |
|
111 |
rootlist.append(name) |
|
112 |
|
|
113 |
return baserlib.BuildUriList(rootlist, "/%s") |
|
114 |
|
|
115 |
|
|
116 |
def _getResources(id_): |
|
117 |
"""Return a list of resources underneath given id. |
|
118 |
|
|
119 |
This is to generalize querying of version resources lists. |
|
120 |
|
|
121 |
@return: a list of resources names. |
|
122 |
|
|
123 |
""" |
|
124 |
r_pattern = re.compile("^R_%s_([a-zA-Z0-9]+)$" % id_) |
|
125 |
|
|
126 |
rlist = [] |
|
127 |
for handler in CONNECTOR.values(): |
|
128 |
m = r_pattern.match(handler.__name__) |
|
129 |
if m: |
|
130 |
name = m.group(1) |
|
131 |
rlist.append(name) |
|
132 |
|
|
133 |
return rlist |
|
134 |
|
|
135 |
|
|
136 |
class R_2(baserlib.R_Generic): |
|
137 |
"""/2 resource. |
|
138 |
|
|
139 |
This is the root of the version 2 API. |
|
140 |
|
|
141 |
""" |
|
142 |
@staticmethod |
|
143 |
def GET(): |
|
144 |
"""Show the list of mapped resources. |
|
145 |
|
|
146 |
@return: a dictionary with 'name' and 'uri' keys for each of them. |
|
147 |
|
|
148 |
""" |
|
149 |
return baserlib.BuildUriList(_getResources("2"), "/2/%s") |
|
150 |
|
|
151 |
|
|
152 | 91 |
def GetHandlers(node_name_pattern, instance_name_pattern, |
153 | 92 |
group_name_pattern, job_id_pattern, disk_pattern, |
154 | 93 |
query_res_pattern): |
... | ... | |
160 | 99 |
# is more flexible and future-compatible than versioning the whole remote |
161 | 100 |
# API. |
162 | 101 |
return { |
163 |
"/": R_root, |
|
102 |
"/": rlib2.R_root,
|
|
164 | 103 |
|
165 | 104 |
"/version": rlib2.R_version, |
166 | 105 |
|
167 |
"/2": R_2, |
|
168 |
|
|
169 | 106 |
"/2/nodes": rlib2.R_2_nodes, |
170 | 107 |
re.compile(r"^/2/nodes/(%s)$" % node_name_pattern): |
171 | 108 |
rlib2.R_2_nodes_name, |
Also available in: Unified diff