Revision 028c6b76

b/lib/rapi/connector.py
125 125
  "/tags": rlib1.R_tags,
126 126
  "/info": rlib1.R_info,
127 127

  
128
  "/nodes": rlib2.R_2_nodes,
128
  "/nodes": rlib2.R_nodes,
129 129
  re.compile(r'^/nodes/([\w\._-]+)$'): rlib1.R_nodes_name,
130 130
  re.compile(r'^/nodes/([\w\._-]+)/tags$'): rlib1.R_nodes_name_tags,
131 131

  
132
  "/instances": rlib2.R_2_instances,
132
  "/instances": rlib2.R_instances,
133 133
  re.compile(r'^/instances/([\w\._-]+)$'): rlib1.R_instances_name,
134 134
  re.compile(r'^/instances/([\w\._-]+)/tags$'): rlib1.R_instances_name_tags,
135 135

  
b/lib/rapi/rlib1.py
104 104
    return ganeti.cli.SubmitOpCode(op)
105 105

  
106 106

  
107
class R_nodes(baserlib.R_Generic):
108
  """/nodes resource.
109

  
110
  """
111
  DOC_URI = "/nodes"
112

  
113
  def GET(self):
114
    """Returns a list of all nodes.
115

  
116
    Returns:
117
      A dictionary with 'name' and 'uri' keys for each of them.
118

  
119
    Example: [
120
        {
121
          "name": "node1.example.com",
122
          "uri": "\/instances\/node1.example.com"
123
        },
124
        {
125
          "name": "node2.example.com",
126
          "uri": "\/instances\/node2.example.com"
127
        }]
128

  
129
    If the optional 'bulk' argument is provided and set to 'true'
130
    value (i.e '?bulk=1'), the output contains detailed
131
    information about nodes as a list.
132

  
133
    Example: [
134
        {
135
          "pinst_cnt": 1,
136
          "mfree": 31280,
137
          "mtotal": 32763,
138
          "name": "www.example.com",
139
          "tags": [],
140
          "mnode": 512,
141
          "dtotal": 5246208,
142
          "sinst_cnt": 2,
143
          "dfree": 5171712
144
        },
145
        ...
146
    ]
147

  
148
    """
149
    op = ganeti.opcodes.OpQueryNodes(output_fields=["name"], names=[])
150
    nodeslist = baserlib.ExtractField(ganeti.cli.SubmitOpCode(op), 0)
151

  
152
    if 'bulk' in self.queryargs:
153
      op = ganeti.opcodes.OpQueryNodes(output_fields=N_FIELDS,
154
                                       names=nodeslist)
155
      result = ganeti.cli.SubmitOpCode(op)
156
      return baserlib.MapBulkFields(result, N_FIELDS)
157

  
158
    return baserlib.BuildUriList(nodeslist, "/nodes/%s")
159

  
160

  
161 107
class R_nodes_name(baserlib.R_Generic):
162 108
  """/nodes/[node_name] resources.
163 109

  
......
193 139
    return baserlib._Tags_GET(constants.TAG_NODE, name=self.items[0])
194 140

  
195 141

  
196
class R_instances(baserlib.R_Generic):
197
  """/instances resource.
198

  
199
  """
200
  DOC_URI = "/instances"
201

  
202

  
203
  def GET(self):
204
    """Returns a list of all available instances.
205

  
206
    Returns:
207
       A dictionary with 'name' and 'uri' keys for each of them.
208

  
209
    Example: [
210
        {
211
          "name": "web.example.com",
212
          "uri": "\/instances\/web.example.com"
213
        },
214
        {
215
          "name": "mail.example.com",
216
          "uri": "\/instances\/mail.example.com"
217
        }]
218

  
219
    If the optional 'bulk' argument is provided and set to 'true'
220
    value (i.e '?bulk=1'), the output contains detailed
221
    information about instances as a list.
222

  
223
    Example: [
224
        {
225
           "status": "running",
226
           "bridge": "xen-br0",
227
           "name": "web.example.com",
228
           "tags": ["tag1", "tag2"],
229
           "admin_ram": 512,
230
           "sda_size": 20480,
231
           "pnode": "node1.example.com",
232
           "mac": "01:23:45:67:89:01",
233
           "sdb_size": 4096,
234
           "snodes": ["node2.example.com"],
235
           "disk_template": "drbd",
236
           "ip": null,
237
           "admin_state": true,
238
           "os": "debian-etch",
239
           "vcpus": 2,
240
           "oper_state": true
241
        },
242
        ...
243
    ]
244

  
245
    """
246
    op = ganeti.opcodes.OpQueryInstances(output_fields=["name"], names=[])
247
    instanceslist = baserlib.ExtractField(ganeti.cli.SubmitOpCode(op), 0)
248

  
249
    if 'bulk' in self.queryargs:
250
      op = ganeti.opcodes.OpQueryInstances(output_fields=I_FIELDS,
251
                                           names=instanceslist)
252
      result = ganeti.cli.SubmitOpCode(op)
253
      return baserlib.MapBulkFields(result, I_FIELDS)
254

  
255

  
256
    else:
257
      return baserlib.BuildUriList(instanceslist, "/instances/%s")
258

  
259

  
260 142
class R_instances_name(baserlib.R_Generic):
261 143
  """/instances/[instance_name] resources.
262 144

  
b/lib/rapi/rlib2.py
140 140
                                 uri_fields=("id", "uri"))
141 141

  
142 142

  
143
class R_nodes(R_2_nodes):
144
  """/nodes resource
145

  
146
  """
147
  # TODO: Temporary resource will be deprecated
148
  DOC_URI = "/nodes"
149

  
150

  
143 151
class R_2_instances(baserlib.R_Generic):
144 152
  """/2/instances resource.
145 153

  
......
241 249
    return job_id
242 250

  
243 251

  
252
class R_instances(R_2_instances):
253
  """/instances resource.
254

  
255
  """
256
  # TODO: Temporary resource will be deprecated
257
  DOC_URI = "/instances"
258

  
259

  
244 260
class R_2_instances_name_reboot(baserlib.R_Generic):
245 261
  """/2/instances/[instance_name]/reboot resource.
246 262

  
b/test/ganeti.rapi.resources_unittest.py
30 30

  
31 31
from ganeti.rapi import connector
32 32
from ganeti.rapi import rlib1
33
from ganeti.rapi import rlib2
33 34

  
34 35

  
35 36
class MapperTests(unittest.TestCase):
......
48 49
    """Testing Mapper"""
49 50

  
50 51
    self._TestUri("/tags", (rlib1.R_tags, [], {}))
51
    self._TestUri("/instances", (rlib1.R_instances, [], {}))
52
    self._TestUri("/instances", (rlib2.R_instances, [], {}))
52 53

  
53 54
    self._TestUri('/instances/www.test.com',
54 55
                  (rlib1.R_instances_name,

Also available in: Unified diff