def _execute(self, session, command_line): print command_line builder = BashScriptBuilder() builder.add_line(command_line, check_rc=True) shell_file_content = builder.build() xld_apply_sh_file = session.upload_text_content_to_work_dir( shell_file_content, 'xld_kubectl.sh', executable=True) print '-' * 60 response = session.execute(xld_apply_sh_file.path, check_success=False, suppress_streaming_output=True) self._dump_response(response) if response.rc != 0: raise Exception( "Failed to apply the resource definition :{0}".format(" ".join( response.stdout)))
def execute_command(self, command, environment_variables=None): # get a BashScriptBuilder object command_object = BashScriptBuilder() # copy in the environment variables if environment_variables is not None: for key, value in environment_variables.items(): command_object.set_env_var(key, value) # add the rest of the possible multiline command command_object.add_lines(command) executable_command = command_object.build() print "executing command: %s " % (executable_command) tmp_script_filename = self.get_tmp_script_filename() self.session.upload_text_content_to_work_dir(command_object.build(), tmp_script_filename, executable=True) # response = self.session.execute("%s/%s" % (self.working_directory, tmp_script_filename), check_success=False, suppress_streaming_output=False) if response.rc != 0: print response.stderr print response.stdout print "unable to execute command %s" % (command) raise Exception('unable to execute command') else: print "Response:", str(response.stdout) return response
def execute_command(self, command, retain_scripts=True): command_object = BashScriptBuilder() for command_line in command.split(';'): command_object.add_line(command_line) executable_command = command_object.build() tmp_script_file_name = ''.join(random.choice(string.ascii_uppercase + string.ascii_lowercase + string.digits) for _ in range(9)) #logger.info("uploading script %s" % tmp_script_file_name) script = self.session.upload_text_content_to_work_dir(executable_command, tmp_script_file_name, executable=True) response = self.session.execute(script.getPath(), check_success=False, suppress_streaming_output=False) #logger.info("stdErr for command yielded: " + str(response.stderr)) #logger.info("stdOut for command yielded: " + str(response.stdout)) #logger.info("the returncode for the command was:" + str(response.rc)) if response.rc != 0: #logger.info("unable to execute command %s" % (command)) raise Exception('unable to execute command ') else: #logger.info("Response", str(response.stdout)) return response