@Name : __sendCmdToCS @Desc : Makes requests to CS using the Inputs provided @Input: command: cloudstack API command name eg: deployVirtualMachineCommand auth: Authentication (apikey,secretKey) => True else False for i
(self, command, auth=True, payload={}, method='GET')
| 198 | return FAILED |
| 199 | |
| 200 | def __sendCmdToCS(self, command, auth=True, payload={}, method='GET'): |
| 201 | """ |
| 202 | @Name : __sendCmdToCS |
| 203 | @Desc : Makes requests to CS using the Inputs provided |
| 204 | @Input: command: cloudstack API command name |
| 205 | eg: deployVirtualMachineCommand |
| 206 | auth: Authentication (apikey,secretKey) => True |
| 207 | else False for integration.api.port |
| 208 | payload: request data composed as a dictionary |
| 209 | method: GET/POST via HTTP |
| 210 | @output: FAILED or else response from CS |
| 211 | """ |
| 212 | try: |
| 213 | payload["command"] = command |
| 214 | payload["response"] = "json" |
| 215 | |
| 216 | if auth: |
| 217 | payload["apiKey"] = self.apiKey |
| 218 | payload["signature"] = self.__sign(payload) |
| 219 | |
| 220 | # Verify whether protocol is "http" or "https", then send the |
| 221 | # request |
| 222 | if self.protocol in ["http", "https"]: |
| 223 | self.logger.debug("Payload: %s" % str(payload)) |
| 224 | if method == 'POST': |
| 225 | self.logger.debug("=======Sending POST Cmd : %s=======" |
| 226 | % str(command)) |
| 227 | return self.__sendPostReqToCS(self.baseUrl, payload) |
| 228 | if method == "GET": |
| 229 | self.logger.debug("========Sending GET Cmd : %s=======" |
| 230 | % str(command)) |
| 231 | return self.__sendGetReqToCS(self.baseUrl, payload) |
| 232 | else: |
| 233 | self.logger.exception("__sendCmdToCS: Invalid Protocol") |
| 234 | return FAILED |
| 235 | except Exception as e: |
| 236 | self.__lastError = e |
| 237 | self.logger.exception("__sendCmdToCS: Exception:%s" % |
| 238 | GetDetailExceptionInfo(e)) |
| 239 | return FAILED |
| 240 | |
| 241 | def __sanitizeCmd(self, cmd): |
| 242 | """ |
no test coverage detected