Exemple #1
0
 def terminate(self, params):
     client = common.ssh_connect_with_retry(
         params['host'],
         params['port'],
         params['login'],
         pkey=self._config.get('pkey'),
         key_filename=self._config.get('key_filename')
         or self._config.get('privateKey'),
         login_cmd=params['login_cmd'])
     if 'container_id' in params:
         common.run_docker_command(client,
                                   'rm --force %s' % params['container_id'])
         time.sleep(5)
     exit_status, stdout, stderr = common.run_command(
         client, 'kill -0 -%d' % params['pgid'])
     if exit_status != 0:
         logger.info("exist_status %d: %s", exit_status, stderr.read())
         client.close()
         return
     exit_status, stdout, stderr = common.run_command(
         client, 'kill -9 -%d' % params['pgid'])
     if exit_status != 0:
         logger.info("exist_status %d: %s", exit_status, stderr.read())
         client.close()
         return
     logger.info("successfully terminated")
     client.close()
Exemple #2
0
    def status(self, task_id, params, get_log=True):
        client = common.ssh_connect_with_retry(
            params['host'],
            params['port'],
            params['login'],
            pkey=self._config.get('pkey'),
            key_filename=self._config.get('key_filename')
            or self._config.get('privateKey'),
            login_cmd=params['login_cmd'])

        if 'container_id' in params:
            exit_status, stdout, stderr = common.run_docker_command(
                client,
                'inspect -f {{.State.Status}} %s' % params['container_id'])
        else:
            exit_status, stdout, stderr = common.run_command(
                client, 'kill -0 -%d' % params['pgid'])

        if get_log:
            common.update_log(task_id, client, params['log_dir'],
                              self._config.get('callback_url'))

        client.close()
        if exit_status != 0:
            return "dead"

        return "running"
Exemple #3
0
 def terminate(self, params):
     client = common.ssh_connect_with_retry(
         params['server'],
         params['login'],
         self._config['privateKey'],
         login_cmd=params['login_cmd'])
     if 'container_id' in params:
         common.run_docker_command(client, 'rm --force %s' % params['container_id'])
     else:
         exit_status, stdout, stderr = common.run_command(client, 'kill -0 -%d' % params['pgid'])
         if exit_status != 0:
             logger.debug("exist_status %d: %s", exit_status, stderr.read())
             client.close()
             return
         exit_status, stdout, stderr = common.run_command(client, 'kill -9 -%d' % params['pgid'])
         if exit_status != 0:
             logger.debug("exist_status %d: %s", exit_status, stderr.read())
             client.close()
             return
     logger.debug("successfully terminated")
     client.close()
Exemple #4
0
    def terminate(self, params):
        instance_id = params["instance_id"]
        if params.get('dynamic'):
            nova_client = self._nova_client
            nova_client.servers.delete(instance_id)
        else:
            ssh_client = get_client(params, self._config)
            if 'container_id' in params:
                common.run_docker_command(ssh_client, 'rm --force %s' % params['container_id'])
                time.sleep(5)
            if 'pgid' in params:
                exit_status, _, stderr = common.run_command(ssh_client, 'kill -0 -%d' % params['pgid'])
                if exit_status != 0:
                    logger.info("exist_status %d: %s", exit_status, stderr.read())
                    ssh_client.close()
                    return
                exit_status, _, stderr = common.run_command(client, 'kill -9 -%d' % params['pgid'])
                if exit_status != 0:
                    logger.info("exist_status %d: %s", exit_status, stderr.read())
                    ssh_client.close()
                    return
            ssh_client.close()

        logger.info("Terminated instance (on terminate): %s.", instance_id)
Exemple #5
0
    def status(self, task_id, params, get_log=True):  # pylint: disable=arguments-differ
        ssh_client = get_client(params, self._config)
        if 'container_id' in params:
            exit_status, _, _ = common.run_docker_command(
                ssh_client, 'inspect -f {{.State.Status}} %s' % params['container_id'])
        else:
            exit_status, _, _ = common.run_command(ssh_client, 'kill -0 -%d' % params['pgid'])

        if get_log:
            common.update_log(task_id, ssh_client, params['log_dir'], self._config.get('callback_url'))

        ssh_client.close()
        if exit_status != 0:
            return "dead"
        return "running"