Revision fc72a3a3

b/lib/rapi/connector.py
114 114
    return baserlib.BuildUriList(rootlist, "/%s")
115 115

  
116 116

  
117
def _getResources(id):
118
  """Return a list of resources underneath given id.
119

  
120
  This is to generalize querying of version resources lists.
121

  
122
  @return: a list of resources names.
123

  
124
  """
125
  r_pattern = re.compile('^R_%s_([a-zA-Z0-9]+)$' % id)
126

  
127
  rlist = []
128
  for handler in CONNECTOR.values():
129
    m = r_pattern.match(handler.__name__)
130
    if m:
131
      name = m.group(1)
132
      rlist.append(name)
133

  
134
  return rlist
135

  
136

  
137
class R_2(baserlib.R_Generic):
138
  """ /2 resourse.
139

  
140
  """
141
  DOC_URI = "/2"
142

  
143
  def GET(self):
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

  
117 152
CONNECTOR.update({
118 153
  "/": R_root,
119 154

  
120 155
  "/version": rlib1.R_version,
121 156

  
122

  
157
  "/2": R_2,
123 158
  "/2/jobs": rlib2.R_2_jobs,
124 159
  "/2/nodes": rlib2.R_2_nodes,
125 160
  "/2/instances": rlib2.R_2_instances,
b/test/ganeti.rapi.resources_unittest.py
76 76

  
77 77
  def testGet(self):
78 78
    expected = [
79
        # TODO: {'name': 'info', 'uri': '/2'},
79
      {'name': '2', 'uri': '/2'},
80 80
      {'name': 'version', 'uri': '/version'},
81 81
      ]
82 82
    self.assertEquals(self.root.GET(), expected)

Also available in: Unified diff