Revision 441e7cfd lib/rapi/rlib2.py

b/lib/rapi/rlib2.py
129 129
      result = ganeti.cli.SubmitOpCode(op)
130 130
      return baserlib.MapBulkFields(result, N_FIELDS)
131 131

  
132
    return baserlib.BuildUriList(nodeslist, "/nodes/%s",
132
    return baserlib.BuildUriList(nodeslist, "/2/nodes/%s",
133 133
                                 uri_fields=("id", "uri"))
134

  
135

  
136
class R_2_instances(baserlib.R_Generic):
137
  """/2/instances resource.
138

  
139
  """
140
  DOC_URI = "/2/instances"
141

  
142

  
143
  def GET(self):
144
    """Returns a list of all available instances.
145

  
146
    Returns:
147
       A dictionary with 'name' and 'uri' keys for each of them.
148

  
149
    Example: [
150
        {
151
          "name": "web.example.com",
152
          "uri": "\/instances\/web.example.com"
153
        },
154
        {
155
          "name": "mail.example.com",
156
          "uri": "\/instances\/mail.example.com"
157
        }]
158

  
159
    If the optional 'bulk' argument is provided and set to 'true'
160
    value (i.e '?bulk=1'), the output contains detailed
161
    information about instances as a list.
162

  
163
    Example: [
164
        {
165
           "status": "running",
166
           "bridge": "xen-br0",
167
           "name": "web.example.com",
168
           "tags": ["tag1", "tag2"],
169
           "admin_ram": 512,
170
           "sda_size": 20480,
171
           "pnode": "node1.example.com",
172
           "mac": "01:23:45:67:89:01",
173
           "sdb_size": 4096,
174
           "snodes": ["node2.example.com"],
175
           "disk_template": "drbd",
176
           "ip": null,
177
           "admin_state": true,
178
           "os": "debian-etch",
179
           "vcpus": 2,
180
           "oper_state": true
181
        },
182
        ...
183
    ]
184

  
185
    """
186
    op = ganeti.opcodes.OpQueryInstances(output_fields=["name"], names=[])
187
    instanceslist = baserlib.ExtractField(ganeti.cli.SubmitOpCode(op), 0)
188

  
189
    if 'bulk' in self.queryargs:
190
      op = ganeti.opcodes.OpQueryInstances(output_fields=I_FIELDS,
191
                                           names=instanceslist)
192
      result = ganeti.cli.SubmitOpCode(op)
193
      return baserlib.MapBulkFields(result, I_FIELDS)
194

  
195

  
196
    else:
197
      return baserlib.BuildUriList(instanceslist, "/2/instances/%s",
198
                                   uri_fields=("id", "uri"))
199

  
200

  
201
class R_2_instances_name_tags(baserlib.R_Generic):
202
  """/2/instances/[instance_name]/tags resource.
203

  
204
  Manages per-instance tags.
205

  
206
  """
207
  DOC_URI = "/2/instances/[instance_name]/tags"
208

  
209
  def GET(self):
210
    """Returns a list of instance tags.
211

  
212
    Example: ["tag1", "tag2", "tag3"]
213

  
214
    """
215
    return baserlib._Tags_GET(constants.TAG_INSTANCE, name=self.items[0])
216

  
217
  def POST(self):
218
    """Add a set of tags to the instance.
219

  
220
    The reqest as a list of strings should be POST to this URI. And you'll have
221
    back a job id.
222

  
223
    """
224
    return baserlib._Tags_POST(constants.TAG_INSTANCE,
225
                               self.post_data, name=self.items[0])

Also available in: Unified diff