- logger.debug("Executing command in VAT terminal: {}".format(cmd));
- out = self._ssh.interactive_terminal_exec_command(self._tty,
- cmd,
- self.__VAT_PROMPT)
- logger.debug("VAT output: {}".format(out));
- json_out = json.loads(out)
- return json_out
+ VatHistory.add_to_vat_history(self._node, cmd)
+ logger.debug("Executing command in VAT terminal: {}".format(cmd))
+ try:
+ out = self._ssh.interactive_terminal_exec_command(self._tty, cmd,
+ self.__VAT_PROMPT)
+ except:
+ self._exec_failure = True
+ raise
+
+ logger.debug("VAT output: {}".format(out))
+ if self.json:
+ obj_start = out.find('{')
+ obj_end = out.rfind('}')
+ array_start = out.find('[')
+ array_end = out.rfind(']')
+
+ if obj_start == -1 and array_start == -1:
+ raise RuntimeError("VAT: no JSON data.")
+
+ if obj_start < array_start or array_start == -1:
+ start = obj_start
+ end = obj_end + 1
+ else:
+ start = array_start
+ end = array_end + 1
+ out = out[start:end]
+ json_out = json.loads(out)
+ return json_out
+ else:
+ return None