def __init__(self, cliJar, nexusiqUrl, nexusiqUserName, nexusiqPassword,
                 nexusiqProxyUrl, nexusiqProxyUserName, nexusiqProxyPassword,
                 app, stage, targetUrl):
        self.cmdLine = CmdLine()

        self.cmdLine.addArgument('java')
        self.cmdLine.addArgument('-jar')
        self.cmdLine.addArgument(cliJar)
        self.cmdLine.addArgument('--application-id')
        self.cmdLine.addArgument(app)
        self.cmdLine.addArgument('--server-url')
        self.cmdLine.addArgument(nexusiqUrl)
        self.cmdLine.addArgument('--authentication')
        self.cmdLine.addArgument("%s:%s" % (nexusiqUserName, nexusiqPassword))
        if nexusiqProxyUrl:
            self.cmdLine.addArgument('--proxy')
            self.cmdLine.addArgument(nexusiqProxyUrl)
            self.cmdLine.addArgument(
                "%s:%s" % (nexusiqProxyUserName, nexusiqProxyPassword))
        self.cmdLine.addArgument('--ignore-system-errors')
        self.cmdLine.addArgument('--stage')
        self.cmdLine.addArgument(stage)
        self.cmdLine.addArgument(targetUrl)

        self.stdout = CapturingOverthereExecutionOutputHandler.capturingHandler(
        )
        self.stderr = CapturingOverthereExecutionOutputHandler.capturingHandler(
        )
 def execute_knife_command(self,
                           command,
                           script_name,
                           options=None,
                           zip_workspace=False):
     connection = None
     try:
         options = Workstation.process_additional_options(options)
         connection = LocalConnection.getLocalConnection()
         workspace_path = self.create_chef_tmp_workspace(connection)
         knife_command = self.get_os_specific_knife_command(
             workspace_path, command, options)
         script_file = connection.getFile(
             OverthereUtils.constructPath(
                 connection.getFile(workspace_path), script_name))
         OverthereUtils.write(String(knife_command).getBytes(), script_file)
         script_file.setExecutable(True)
         if zip_workspace:
             self.zip_workspace(workspace_path, connection)
         command = CmdLine()
         command.addArgument(script_file.getPath())
         output_handler = CapturingOverthereExecutionOutputHandler.capturingHandler(
         )
         error_handler = CapturingOverthereExecutionOutputHandler.capturingHandler(
         )
         exit_code = connection.execute(output_handler, error_handler,
                                        command)
         return [exit_code, output_handler, error_handler]
     except Exception:
         traceback.print_exc(file=sys.stdout)
         sys.exit(1)
     finally:
         if connection is not None:
             connection.close()
    def bitbucket_downloadcode(self, variables):
        downloadURL = "%s/%s/get/%s.zip" % (variables['server']['url'].replace("api.","www."), variables['repo_full_name'], variables['branch'] )
        connection = LocalConnection.getLocalConnection()

        capturedOutput = ""

        print "Cleaning up download folder : %s" % variables['downloadPath']
        command = CmdLine()
        command.addArgument("rm")
        command.addArgument("-rf")
        command.addArgument(variables['downloadPath'] + "/*")
        output_handler = CapturingOverthereExecutionOutputHandler.capturingHandler()
        error_handler = CapturingOverthereExecutionOutputHandler.capturingHandler()
        exit_code = connection.execute(output_handler, error_handler, command)
        capturedOutput = self.parse_output(output_handler.getOutputLines()) + self.parse_output(error_handler.getOutputLines())

        print " Now downloading code in download folder : %s" % variables['downloadPath']
        command = CmdLine()
        script = '''
            cd %s
            wget --user %s --password %s  -O code.zip %s
            unzip code.zip
            rm -rf *.zip
            foldername=`ls -d */`
            mv -f $foldername* `pwd`
            rm -rf $foldername
        ''' % (variables['downloadPath'], self.http_request.username, self.http_request.password,  downloadURL )
        script_file = connection.getFile(OverthereUtils.constructPath(connection.getFile(variables['downloadPath']), 'extract.sh'))
        OverthereUtils.write(String(script).getBytes(), script_file)
        script_file.setExecutable(True)
        command.addArgument(script_file.getPath())
        output_handler = CapturingOverthereExecutionOutputHandler.capturingHandler()
        error_handler = CapturingOverthereExecutionOutputHandler.capturingHandler()
        exit_code = connection.execute(output_handler, error_handler, command)
        capturedOutput += self.parse_output(output_handler.getOutputLines()) + self.parse_output(error_handler.getOutputLines())

        command = CmdLine()
        command.addArgument("rm")
        command.addArgument("-f")
        command.addArgument(variables['downloadPath'] + "/extract.sh")
        output_handler = CapturingOverthereExecutionOutputHandler.capturingHandler()
        error_handler = CapturingOverthereExecutionOutputHandler.capturingHandler()
        exit_code = connection.execute(output_handler, error_handler, command)
        capturedOutput += self.parse_output(output_handler.getOutputLines()) + self.parse_output(error_handler.getOutputLines())

        return {'output': capturedOutput}
 def zip_workspace(self, workspace_path, connection):
     zip_script = self.get_os_specific_zip_command(workspace_path)
     zip_script_file = connection.getFile(OverthereUtils.constructPath(connection.getFile(workspace_path), 'zip.cmd'))
     OverthereUtils.write(String(zip_script).getBytes(), zip_script_file)
     zip_script_file.setExecutable(True)
     command = CmdLine()
     command.addArgument(zip_script_file.getPath())
     return connection.execute(command)
    def stash_downloadcode(self, variables):
        downloadURL = "%s/rest/archive/latest/projects/%s/repos/%s/archive?at=refs/heads/%s&format=zip" % (variables['server']['url'], variables['project'], variables['repository'], variables['branch'])
        connection = LocalConnection.getLocalConnection()

        capturedOutput = ""

        print "Cleaning up download folder : %s" % variables['downloadPath']
        command = CmdLine()
        command.addArgument("mkdir")
        command.addArgument("-p")
        command.addArgument(variables['downloadPath'])
        output_handler = CapturingOverthereExecutionOutputHandler.capturingHandler()
        error_handler = CapturingOverthereExecutionOutputHandler.capturingHandler()
        exit_code = connection.execute(output_handler, error_handler, command)
        capturedOutput = self.parse_output(output_handler.getOutputLines()) + self.parse_output(error_handler.getOutputLines())

        print " Now downloading code in download folder : %s" % variables['downloadPath']
        command = CmdLine()
        script = '''
            cd %s
            ls | grep -v extract.sh | xargs rm -rf
            wget --user %s --password %s  -O code.zip '%s'
            unzip -o code.zip
            rm code.zip
        ''' % (variables['downloadPath'], self.http_request.username, self.http_request.password,  downloadURL)
        script_file = connection.getFile(OverthereUtils.constructPath(connection.getFile(variables['downloadPath']), 'extract.sh'))
        OverthereUtils.write(String(script).getBytes(), script_file)
        script_file.setExecutable(True)
        command.addArgument(script_file.getPath())
        output_handler = CapturingOverthereExecutionOutputHandler.capturingHandler()
        error_handler = CapturingOverthereExecutionOutputHandler.capturingHandler()
        exit_code = connection.execute(output_handler, error_handler, command)
        capturedOutput += self.parse_output(output_handler.getOutputLines()) + self.parse_output(error_handler.getOutputLines())

        command = CmdLine()
        command.addArgument("rm")
        command.addArgument("-f")
        command.addArgument(variables['downloadPath'] + "/extract.sh")
        output_handler = CapturingOverthereExecutionOutputHandler.capturingHandler()
        error_handler = CapturingOverthereExecutionOutputHandler.capturingHandler()
        exit_code = connection.execute(output_handler, error_handler, command)
        capturedOutput += self.parse_output(output_handler.getOutputLines()) + self.parse_output(error_handler.getOutputLines())

        return {'output': capturedOutput}
 def __init__(self, workstation_config):
     self.cmd_line = CmdLine()
     self.chef_sdk_path = workstation_config['chef_sdk_path']
     self.client_key = Workstation.format_key(
         workstation_config['client_key'])
     self.unix = (workstation_config['os'] == 'Unix')
     self.chef_server_url = workstation_config['chef_server_url']
     self.node_name = workstation_config['node_name']
     self.log_level = workstation_config['log_level']
     self.log_location = workstation_config['log_location']
     self.cookbook_path = workstation_config['cookbook_path']
     self.stdout = CapturingOverthereExecutionOutputHandler.capturingHandler(
     )
     self.stderr = CapturingOverthereExecutionOutputHandler.capturingHandler(
     )
Пример #7
0
 def __init__(self, cliHome, xldHost, xldPort, xldSecure, xldContext,
              xldProxyHost, xldProxyPort, xldSocketTimeout, xldUserName,
              xldPassword, script, cliExecutable, options):
     self.cmdLine = CmdLine()
     self.osname = System.getProperty('os.name').lower()
     if self.osname.startswith('win'):
         cliExecutable = "%s\\bin\\%s.cmd" % (cliHome, cliExecutable)
     else:
         cliExecutable = "%s/bin/%s.sh" % (cliHome, cliExecutable)
     # End if
     self.cmdLine.addArgument(cliExecutable)
     self.cmdLine.addArgument('-quiet')
     if xldHost != "DEFAULT":
         self.cmdLine.addArgument('-host')
         self.cmdLine.addArgument(xldHost)
     if xldPort != "DEFAULT":
         self.cmdLine.addArgument('-port')
         self.cmdLine.addArgument(xldPort)
     if xldSecure:
         self.cmdLine.addArgument('-secure')
     if xldContext != "DEFAULT":
         self.cmdLine.addArgument('-context')
         self.cmdLine.addArgument(xldContext)
     if xldProxyHost != "DEFAULT":
         self.cmdLine.addArgument('-proxyHost')
         self.cmdLine.addArgument(xldProxyHost)
     if xldProxyPort != "DEFAULT":
         self.cmdLine.addArgument('-proxyPort')
         self.cmdLine.addArgument(xldProxyPort)
     if xldSocketTimeout != "DEFAULT":
         self.cmdLine.addArgument('-socketTimeout')
         self.cmdLine.addArgument(xldSocketTimeout)
     if xldUserName != "DEFAULT":
         self.cmdLine.addArgument('-username')
         self.cmdLine.addArgument(xldUserName)
     if xldPassword != "DEFAULT":
         self.cmdLine.addArgument('-password')
         self.cmdLine.addPassword(xldPassword)
     if options is not None:
         self.options = str(options)
     # End if
     self.script = script
     self.stdout = CapturingOverthereExecutionOutputHandler.capturingHandler(
     )
     self.stderr = CapturingOverthereExecutionOutputHandler.capturingHandler(
     )
 def execute_command(connection, workspace_path, command):
     try:
         print "executing command: %s" % command
         script_file = connection.getFile(OverthereUtils.constructPath(connection.getFile(workspace_path), 'command.cmd'))
         OverthereUtils.write(String(command).getBytes(), script_file)
         script_file.setExecutable(True)
         command = CmdLine()
         command.addArgument(script_file.getPath())
         output_handler = CapturingOverthereExecutionOutputHandler.capturingHandler()
         error_handler = CapturingOverthereExecutionOutputHandler.capturingHandler()
         exit_code = connection.execute(output_handler, error_handler, command)
         print "exit_code : %s" % exit_code
         print "output: %s" % output_handler.getOutput()
         print "errors: %s" % error_handler.getOutput()
         return [exit_code, output_handler, error_handler]
     except Exception:
         traceback.print_exc(file=sys.stdout)
         sys.exit(1)
    def execute(self, cmd, check_success=True, suppress_streaming_output=False):
        """
        Executes the command on the remote system and returns the result
        :param cmd: Command line as an Array of Strings or String.  A String is split by space.
        :param check_success: checks the return code is 0. On failure the output is printed to stdout and a system exit is performed
        :param suppress_streaming_output:  suppresses the output of the execution when the session is in streaming mode.
        :return: CommandResponse
        """
        
        capture_so_handler = CapturingOverthereExecutionOutputHandler.capturingHandler()
        capture_se_handler = CapturingOverthereExecutionOutputHandler.capturingHandler()

        if self._stream_command_output and not suppress_streaming_output:
            console_so_handler = ConsoleOverthereExecutionOutputHandler.sysoutHandler()
            console_se_handler = ConsoleOverthereExecutionOutputHandler.syserrHandler()
            so_handler = MultipleOverthereExecutionOutputHandler.multiHandler([capture_so_handler, console_so_handler])
            se_handler = MultipleOverthereExecutionOutputHandler.multiHandler([capture_se_handler, console_se_handler])
        else:
            so_handler = capture_so_handler
            se_handler = capture_se_handler

        if isinstance(cmd, basestring):
            cmd = cmd.split()

        cmdline = CmdLine()
        for s in cmd:
            cmdline.addRaw(s)

        rc = self.get_conn().execute(so_handler, se_handler, cmdline)
        #wait for output to drain
        time.sleep(1)

        response = CommandResponse(rc=rc, stdout=capture_so_handler.outputLines, stderr=capture_se_handler.outputLines)

        if response.rc != 0 and check_success:
            if not suppress_streaming_output:
                mdl.print_error(StringUtils.strip_ansi(StringUtils.concat(response.stdout)))
                mdl.print_error(StringUtils.strip_ansi(StringUtils.concat(response.stderr)))
            raise Exception(response.rc)

        return response