From 884c6b10720dbfc08a442f0693a994f9abd1bd57 Mon Sep 17 00:00:00 2001 From: Alexis de Talhouët Date: Thu, 8 Aug 2019 18:15:55 -0400 Subject: Add dynamic-properties as python script arg MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit For the remote python executor, we have the ability to provide dynamic properties, that will end up marshall as Json. Through the gRPC session, it will be transform to a Google Proto Struct. Once in the remote python executor, we use utility method from Proto to convert the Struct into a Json string, and we pass it as the last argument of the script execution. That way, user can access them in their script, simply by loading the content using json.loads and then interact with the data through the python dict. Change-Id: Ib3552c06734aed252ec28f47173bc8668afe085d Issue-ID: CCSDK-1606 Signed-off-by: Alexis de Talhouët --- ms/command-executor/src/main/python/command_executor_handler.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'ms') diff --git a/ms/command-executor/src/main/python/command_executor_handler.py b/ms/command-executor/src/main/python/command_executor_handler.py index 305c83e17..972dad627 100644 --- a/ms/command-executor/src/main/python/command_executor_handler.py +++ b/ms/command-executor/src/main/python/command_executor_handler.py @@ -15,11 +15,12 @@ # from builtins import Exception, open, dict from subprocess import CalledProcessError, PIPE +from google.protobuf.json_format import MessageToJson import logging import os +import re import subprocess -import sys import virtualenv import venv import utils @@ -72,9 +73,8 @@ class CommandExecutorHandler(): if "ansible-playbook" in request.command: cmd = cmd + "; " + request.command + " -e 'ansible_python_interpreter=" + self.venv_home + "/bin/python'" else: - cmd = cmd + "; " + request.command + cmd = cmd + "; " + request.command + " " + re.escape(MessageToJson(request.properties)) - self.logger.info("Command: {}".format(cmd)) try: with subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, shell=True, bufsize=1, universal_newlines=True) as newProcess: -- cgit 1.2.3-korg