(self, apiStream)
| 376 | return paramProperty |
| 377 | |
| 378 | def loadCmdFromJSON(self, apiStream): |
| 379 | if apiStream is None: |
| 380 | raise Exception("No APIs found through discovery") |
| 381 | |
| 382 | jsonOut = apiStream.readlines() |
| 383 | assert len(jsonOut) > 0 |
| 384 | apiDict = json.loads(jsonOut[0]) |
| 385 | if 'listapisresponse' not in apiDict: |
| 386 | raise Exception("API discovery plugin response failed") |
| 387 | if 'count' not in apiDict['listapisresponse']: |
| 388 | raise Exception("Malformed api response") |
| 389 | |
| 390 | apilist = apiDict['listapisresponse']['api'] |
| 391 | cmds = [] |
| 392 | for cmd in apilist: |
| 393 | csCmd = cloudStackCmd() |
| 394 | if 'name' in cmd: |
| 395 | csCmd.name = cmd['name'] |
| 396 | assert csCmd.name |
| 397 | |
| 398 | if 'description' in cmd: |
| 399 | csCmd.desc = cmd['description'] |
| 400 | |
| 401 | if 'isasync' in cmd: |
| 402 | csCmd.asyncmethod = cmd['isasync'] |
| 403 | |
| 404 | for param in cmd['params']: |
| 405 | paramProperty = cmdParameterProperty() |
| 406 | |
| 407 | if 'name' in param: |
| 408 | paramProperty.name = param['name'] |
| 409 | assert paramProperty.name |
| 410 | |
| 411 | if 'required' in param: |
| 412 | paramProperty.required = str(param['required']).lower() |
| 413 | |
| 414 | if 'description' in param: |
| 415 | paramProperty.desc = param['description'] |
| 416 | |
| 417 | if 'type' in param: |
| 418 | paramProperty.type = param['type'] |
| 419 | paramProperty.dataType = param['type'] |
| 420 | |
| 421 | csCmd.request.append(paramProperty) |
| 422 | |
| 423 | for response in cmd['response']: |
| 424 | # FIXME: ExtractImage related APIs return empty dicts in |
| 425 | # response |
| 426 | if len(response) > 0: |
| 427 | paramProperty = self.constructResponseFromJSON(response) |
| 428 | csCmd.response.append(paramProperty) |
| 429 | |
| 430 | cmds.append(csCmd) |
| 431 | return cmds |
| 432 | |
| 433 | def generateCodeFromJSON(self, endpointUrl): |
| 434 | """ |
no test coverage detected