<commit_before>import jsonpickle
import qualipy.scripts.cloudshell_scripts_helpers as helpers
from qualipy.api.cloudshell_api import *

from models.DeployDataHolder import DeployDataHolder


class DeploymentServiceDriver(object):
    INPUT_KEY_COMMAND = "COMMAND"
    INPUT_KEY_DEPLOY_DATA = "deploy_data"
    COMMAND_DEPLOY_FROM_TEMPLATE = "deploy_from_template"

    def __init__(self, cs_retriever_service):
        self.cs_retriever_service = cs_retriever_service

    def execute(self):
        data_holder = self._get_data_holder()
        json_data_holder = jsonpickle.encode(data_holder, unpicklable=False)

        reservation_id = helpers.get_reservation_context_details().id
        api = helpers.get_api_session()
        result = api.ExecuteCommand(reservation_id,
                                    data_holder.template_model.vCenter_resource_name,
                                    "Resource",
                                    self.COMMAND_DEPLOY_FROM_TEMPLATE,
                                    self._get_command_inputs_list(json_data_holder),
                                    False)

        if hasattr(result, 'Output'):
            print result.Output
        else:
            print jsonpickle.encode(result, unpicklable=False)

    def _get_data_holder(self):
        resource_context = helpers.get_resource_context_details()

        # get vCenter resource name, template name, template folder
        template_model = self.cs_retriever_service.getVCenterTemplateAttributeData(resource_context)
        template_model.app_name = helpers.get_user_param("Name")

        # get power state of the cloned VM
        power_on = False  # self.cs_retriever_service.getPowerStateAttributeData(resource_context)<commit_msg>fixed more failing tests<commit_after>import jsonpickle
import qualipy.scripts.cloudshell_scripts_helpers as helpers
from qualipy.api.cloudshell_api import *

from models.DeployDataHolder import DeployDataHolder


class DeploymentServiceDriver(object):
    INPUT_KEY_COMMAND = "COMMAND"
    INPUT_KEY_DEPLOY_DATA = "deploy_data"
    COMMAND_DEPLOY_FROM_TEMPLATE = "deploy_from_template"

    def __init__(self, cs_retriever_service):
        self.cs_retriever_service = cs_retriever_service

    def execute(self):
        data_holder = self._get_data_holder()
        json_data_holder = jsonpickle.encode(data_holder, unpicklable=False)

        reservation_id = helpers.get_reservation_context_details().id
        api = helpers.get_api_session()
        result = api.ExecuteCommand(reservation_id,
                                    data_holder.template_model.vCenter_resource_name,
                                    "Resource",
                                    self.COMMAND_DEPLOY_FROM_TEMPLATE,
                                    self._get_command_inputs_list(json_data_holder),
                                    False)

        if hasattr(result, 'Output'):
            print result.Output
        else:
            print jsonpickle.encode(result, unpicklable=False)

    def _get_data_holder(self):
        resource_context = helpers.get_resource_context_details()

        # get vCenter resource name, template name, template folder
        template_model = self.cs_retriever_service.getVCenterTemplateAttributeData(resource_context)
        template_model.app_name = os.environ["NAME"]

        # get power state of the cloned VM
        power_on = False  # self.cs_retriever_service.getPowerStateAttributeData(resource_context)
{'fraction_non_alphanumeric': 0.061837961637560834, 'fraction_numerical': 0.0, 'mean_word_length': 2.693446088794926, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 10, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2239791', 'n_tokens_mistral': 1001, 'n_tokens_neox': 968, 'n_words': 160}