MCPcopy Create free account
hub / github.com/apache/cloudstack / __sanitizeCmd

Method __sanitizeCmd

tools/marvin/marvin/cloudstackConnection.py:241–295  ·  view source on GitHub ↗

@Name : __sanitizeCmd @Desc : Removes None values, Validates all required params are present @Input: cmd: Cmd object eg: createPhysicalNetwork @Output: Returns command name, asynchronous or not,request payload FAILED for failed cases

(self, cmd)

Source from the content-addressed store, hash-verified

239 return FAILED
240
241 def __sanitizeCmd(self, cmd):
242 """
243 @Name : __sanitizeCmd
244 @Desc : Removes None values, Validates all required params are present
245 @Input: cmd: Cmd object eg: createPhysicalNetwork
246 @Output: Returns command name, asynchronous or not,request payload
247 FAILED for failed cases
248 """
249 try:
250 cmd_name = ''
251 payload = {}
252 required = []
253 isAsync = "false"
254 for attribute in dir(cmd):
255 if not attribute.startswith('__'):
256 if attribute == "isAsync":
257 isAsync = getattr(cmd, attribute)
258 elif attribute == "required":
259 required = getattr(cmd, attribute)
260 else:
261 payload[attribute] = getattr(cmd, attribute)
262 cmd_name = cmd.__class__.__name__.replace("Cmd", "")
263 for required_param in required:
264 if payload[required_param] is None:
265 self.logger.debug("CmdName: %s Parameter : %s is Required"
266 % (cmd_name, required_param))
267 self.__lastError = InvalidParameterException(
268 "Invalid Parameters")
269 return FAILED
270 for param, value in list(payload.items()):
271 if value is None:
272 payload.pop(param)
273 elif param == 'typeInfo':
274 payload.pop(param)
275 elif isinstance(value, list):
276 if len(value) == 0:
277 payload.pop(param)
278 else:
279 if not isinstance(value[0], dict):
280 payload[param] = ",".join(value)
281 else:
282 payload.pop(param)
283 i = 0
284 for val in value:
285 for k, v in val.items():
286 payload["%s[%d].%s" % (param, i, k)] = v
287 i += 1
288 return cmd_name.strip(), isAsync, payload
289 except Exception as e:
290 self.__lastError = e
291 self.logger.\
292 exception("__sanitizeCmd: CmdName : "
293 "%s : Exception:%s" % (cmd_name,
294 GetDetailExceptionInfo(e)))
295 return FAILED
296
297 def __parseAndGetResponse(self, cmd_response, response_cls, is_async):
298 '''

Callers 1

marvinRequestMethod · 0.95

Calls 5

GetDetailExceptionInfoFunction · 0.90
replaceMethod · 0.80
debugMethod · 0.80
joinMethod · 0.45

Tested by

no test coverage detected