예제 #1
0
 def safe_crushmap_update(self):
     with open(os.devnull,
               'w') as fnull, tempfile.TemporaryFile() as backup:
         LOG.info("Saving crushmap for safe update")
         try:
             subprocess.check_call(  # pylint: disable=not-callable
                 "ceph osd getcrushmap",
                 stdin=fnull,
                 stdout=backup,
                 stderr=fnull,
                 shell=True)
         except subprocess.CalledProcessError as exc:
             raise exception.CephFailure("failed to backup crushmap: %s" %
                                         str(exc))
         try:
             yield
         except exception.CephFailure:
             backup.seek(0, os.SEEK_SET)
             LOG.warn("Crushmap update failed. Restoring from backup")
             subprocess.call(  # pylint: disable=not-callable
                 "ceph osd setcrushmap",
                 stdin=backup,
                 stdout=fnull,
                 stderr=fnull,
                 shell=True)
             raise
예제 #2
0
파일: herd.py 프로젝트: gunchu/Herd
def run(local_file, remote_file, hosts):
    start = time.time()
    log.info("Spawning tracker...")
    eventlet.spawn(track)
    eventlet.sleep(1)
    local_host = (local_ip(), opts['port'])
    log.info("Creating torrent (host %s:%s)..." % local_host)
    torrent_file = mktorrent(local_file, '%s:%s' % local_host)
    log.info("Seeding %s" % torrent_file)
    eventlet.spawn(seed, torrent_file, local_file)
    log.info("Transferring")
    if not os.path.isfile(bittornado_tgz):
        cwd = os.getcwd()
        os.chdir(herd_root)
        args = ['tar', 'czf', 'bittornado.tar.gz', 'BitTornado']
        log.info("Executing: " + " ".join(args))
        subprocess.call(args)
        os.chdir(cwd)
    pool = eventlet.GreenPool(100)
    threads = []
    remainingHosts = hosts      
    for host in hosts:
        threads.append(pool.spawn(transfer, host, torrent_file, remote_file, opts['retry']))
    for thread in threads:
        host = thread.wait()
        remainingHosts.remove(host)
        log.info("Done: %-6s Remaining: %s" % (host, remainingHosts))
    os.unlink(torrent_file)
    try:
        os.unlink(opts['data_file'])
    except OSError:
        pass
    log.info("Finished, took %.2f seconds." % (time.time() - start))
예제 #3
0
파일: herd.py 프로젝트: bennojoy/Herd
def run(local_file, remote_file, hosts):
    start = time.time()
    print "Spawning tracker..."
    eventlet.spawn(track)
    eventlet.sleep(1)
    local_host = (local_ip(), PORT)
    print "Creating torrent (host %s:%s)..." % local_host
    torrent_file = mktorrent(local_file, '%s:%s' % local_host)
    print "Seeding %s" % torrent_file
    eventlet.spawn(seed, torrent_file, local_file)
    print "Transferring"
    if not os.path.isfile(bittornado_tgz):
        cwd = os.getcwd()
        os.chdir(herd_root)
        args = ['tar', 'czf', 'bittornado.tar.gz', 'BitTornado']
        print "Executing", " ".join(args)
        subprocess.call(args)
        os.chdir(cwd)
    pool = eventlet.GreenPool(100)
    threads = []
    for host in hosts:
        threads.append(pool.spawn(transfer, host, torrent_file, remote_file))
    for thread in threads:
        thread.wait()
    os.unlink(torrent_file)
    try:
        os.unlink(DATA_FILE)
    except OSError:
        pass
    print "Finished, took %.2f seconds." % (time.time() - start)
예제 #4
0
파일: herd.py 프로젝트: Mirascape/Herd
def run(local_file, remote_file, hosts):
    start = time.time()
    print "Spawning tracker..."
    tracker = eventlet.spawn(track)
    eventlet.sleep(1)
    local_host = (local_ip(), PORT)
    print "Creating torrent (host %s:%s)..." % local_host
    torrent_file = mktorrent(local_file, '%s:%s' % local_host)
    print "Seeding"
    seeder = eventlet.spawn(seed, torrent_file, local_file)
    print "Transferring"
    if not os.path.isfile('./bittornado.tar.gz'):
        subprocess.call("tar cfz ./bittornado.tar.gz ./BitTornado".split(' '))
    pool = eventlet.GreenPool(100)
    threads = []
    for host in hosts:
        threads.append(pool.spawn(transfer, host, torrent_file, remote_file))
    for thread in threads:
        thread.wait()
    os.unlink(torrent_file)
    try:
        os.unlink(DATA_FILE)
    except OSError:
        pass
    print "Finished, took %.2f seconds." % (time.time() - start)
예제 #5
0
파일: herd.py 프로젝트: KenDUemura/Herd
def run(local_file, remote_file, hosts):
    start = time.time()
    print "Spawning tracker..."
    tracker = eventlet.spawn(track)
    eventlet.sleep(1)
    local_host = (local_ip(), PORT)
    print "Creating torrent (host %s:%s)..." % local_host
    torrent_file = mktorrent(local_file, '%s:%s' % local_host)
    print "Seeding"
    seeder = eventlet.spawn(seed, torrent_file, local_file)
    print "Transferring"
    if not os.path.isfile('./bittornado.tar.gz'):
        subprocess.call("tar cfz ./bittornado.tar.gz ./BitTornado".split(' '))
    pool = eventlet.GreenPool(100)
    threads = []
    for host in hosts:
        threads.append(pool.spawn(transfer, host, torrent_file, remote_file))
    for thread in threads:
        thread.wait()
    os.unlink(torrent_file)
    try:
        os.unlink(DATA_FILE)
    except OSError:
        pass
    print "Finished, took %.2f seconds." % (time.time() - start)
예제 #6
0
파일: utils.py 프로젝트: chenglch/xcatperf
def execute_command(cmd, **kwargs):
    try:
        subprocess.call(cmd, **kwargs)
    except subprocess.CalledProcessError:
        if kwargs['shell']:
            raise exception.CommandError(cmd=cmd)
        else:
            raise exception.CommandError(cmd=' '.join(cmd))
예제 #7
0
파일: utils.py 프로젝트: vineethrp/swift
def renamer(old, new):
    """
    Attempt to fix / hide race conditions like empty object directories
    being removed by backend processes during uploads, by retrying.

    :param old: old path to be renamed
    :param new: new path to be renamed to
    """
    try:
        mkdirs(os.path.dirname(new))
        os.rename(old, new)
    except OSError, err:
        mkdirs(os.path.dirname(new))
        if err.errno == errno.EXDEV:
            subprocess.call(['mv', old, new])
        else:
            os.rename(old, new)
예제 #8
0
파일: herd.py 프로젝트: sachuin23/Herd
def ssh(host,command):
    global password
    if not os.path.exists(opts['log_dir']):
        os.makedirs(opts['log_dir'])

    incommand =  ['sshpass','-p',password,'ssh',host,command]
    result = subprocess.call(incommand)
    print ('SSH complete')
    return result
예제 #9
0
def ssh(host, command):
    global password
    if not os.path.exists(opts['log_dir']):
        os.makedirs(opts['log_dir'])

    incommand = ['sshpass', '-p', password, 'ssh', host, command]
    result = subprocess.call(incommand)
    print('SSH complete')
    return result
예제 #10
0
 def copy(self, src, dest):
     # With large files this is 2x-3x faster than shutil.copy(src, dest),
     # especially when copying to a UNC target.
     # shutil.copyfileobj(...) with a proper buffer is better than
     # shutil.copy(...) but still 20% slower than a shell copy.
     # It can be replaced with Win32 API calls to avoid the process
     # spawning overhead.
     if subprocess.call(['cmd.exe', '/C', 'copy', '/Y', src, dest]):
         raise IOError(_('The file copy from %(src)s to %(dest)s failed'))
예제 #11
0
def scp(host, local_file, remote_file):
    incommand = [
        'sshpass', '-p', password, 'scp', local_file,
        '%s:%s' % (host, remote_file)
    ]
    print(incommand)
    return subprocess.call(incommand,
                           stdout=subprocess.PIPE,
                           stderr=subprocess.PIPE)
예제 #12
0
 def on_timeout_expired(timeout):
     try:
         process.wait(timeout=self._timeout)
     except subprocess.TimeoutExpired:
         # Set the error prior to kill the process else the error is not picked up due
         # to eventlet scheduling.
         error_holder['error'] = 'Action failed to complete in %s seconds' % (self._timeout)
         # Action has timed out, kill the process and propagate the error. The process
         # is started as sudo -u {{system_user}} -- bash -c {{command}}. Introduction of the
         # bash means that multiple independent processes are spawned without them being
         # children of the process we have access to and this requires use of pkill.
         # Ideally os.killpg should have done the trick but for some reason that failed.
         # Note: pkill will set the returncode to 143 so we don't need to explicitly set
         # it to some non-zero value.
         try:
             killcommand = shlex.split('sudo pkill -TERM -s %s' % process.pid)
             subprocess.call(killcommand)
         except:
             LOG.exception('Unable to pkill.')
예제 #13
0
파일: localrunner.py 프로젝트: bsyk/st2
 def on_timeout_expired(timeout):
     try:
         process.wait(timeout=self._timeout)
     except subprocess.TimeoutExpired:
         # Set the error prior to kill the process else the error is not picked up due
         # to eventlet scheduling.
         error_holder['error'] = 'Action failed to complete in %s seconds' % (self._timeout)
         # Action has timed out, kill the process and propagate the error. The process
         # is started as sudo -u {{system_user}} -- bash -c {{command}}. Introduction of the
         # bash means that multiple independent processes are spawned without them being
         # children of the process we have access to and this requires use of pkill.
         # Ideally os.killpg should have done the trick but for some reason that failed.
         # Note: pkill will set the returncode to 143 so we don't need to explicitly set
         # it to some non-zero value.
         try:
             killcommand = shlex.split('sudo pkill -TERM -s %s' % process.pid)
             subprocess.call(killcommand)
         except:
             LOG.exception('Unable to pkill.')
예제 #14
0
파일: herd.py 프로젝트: almeidarruben/Herd
def ssh(host, command):
    if not os.path.exists(opts['log_dir']):
        os.makedirs(opts['log_dir'])
        
    with open("%s%s%s-ssh.log" % (opts['log_dir'], os.path.sep, host), 'a') as log:
        result = subprocess.call(['ssh', '-o UserKnownHostsFile=/dev/null',
                '-o LogLevel=quiet',
                '-o StrictHostKeyChecking=no',
                host, command], stdout=log,
                stderr=log)
    return result
예제 #15
0
파일: shell.py 프로젝트: StackStorm/st2
def kill_process(process):
    """
    Kill the provided process by sending it TERM signal using "pkill" shell
    command.

    Note: This function only works on Linux / Unix based systems.

    :param process: Process object as returned by subprocess.Popen.
    :type process: ``object``
    """
    kill_command = shlex.split('sudo pkill -TERM -s %s' % (process.pid))

    try:
        if six.PY3:
            status = subprocess.call(kill_command, timeout=100)  # pylint: disable=not-callable
        else:
            status = subprocess.call(kill_command)  # pylint: disable=not-callable
    except Exception:
        LOG.exception('Unable to pkill process.')

    return status
예제 #16
0
def kill_process(process):
    """
    Kill the provided process by sending it TERM signal using "pkill" shell
    command.

    Note: This function only works on Linux / Unix based systems.

    :param process: Process object as returned by subprocess.Popen.
    :type process: ``object``
    """
    kill_command = shlex.split('sudo pkill -TERM -s %s' % (process.pid))

    try:
        if six.PY3:
            status = subprocess.call(kill_command, timeout=100)  # pylint: disable=not-callable
        else:
            status = subprocess.call(kill_command)  # pylint: disable=not-callable
    except Exception:
        LOG.exception('Unable to pkill process.')

    return status
예제 #17
0
def run(local_file, remote_file, hosts):
    start = time.time()
    log.info("Spawning tracker...")
    eventlet.spawn(track)
    eventlet.sleep(1)
    local_host = (local_ip(), opts['port'])
    log.info("Creating torrent (host %s:%s)..." % local_host)
    torrent_file = mktorrent(local_file, '%s:%s' % local_host)
    log.info("Seeding %s" % torrent_file)
    eventlet.spawn(seed, torrent_file, local_file)
    log.info("Transferring")
    if not os.path.isfile(bittornado_tgz):
        cwd = os.getcwd()
        os.chdir(herd_root)
        args = ['tar', 'czf', 'bittornado.tar.gz', 'BitTornado']
        log.info("Executing: " + " ".join(args))
        subprocess.call(args)
        os.chdir(cwd)
    pool = eventlet.GreenPool(100)
    threads = []
    remainingHosts = hosts
    for host in hosts:
        global username
        host = '%s@%s' % (username, host)
        threads.append(
            pool.spawn(transfer, host, torrent_file, remote_file,
                       opts['retry']))
    for thread in threads:
        host = thread.wait()
        remainingHosts.remove(host)
        log.info("Done: %-6s Remaining: %s" % (host, remainingHosts))
    os.unlink(torrent_file)
    try:
        os.unlink(opts['data_file'])
    except OSError:
        pass
    log.info("Finished, took %.2f seconds." % (time.time() - start))
예제 #18
0
def _launch(port,logfile):
    """
    Run _this_ module in a separate process. That 
    process will daemonize the service and quickly
    exit. This function is supposed to be called
    from the external API. Users currently are
    not expected to manually or explicitely start
    the port mapper. The port mapper should be started
    the first time someone wants to use it.
    """
    args = [_get_python_executable(), __file__]
    if port:
        args += ['-p', str(port)]
    if logfile:
        args += ['-l', logfile]
    rcode = subprocess.call(args)
    return rcode
예제 #19
0
파일: herd.py 프로젝트: bennojoy/Herd
def ssh(host, command):
    return subprocess.call(['ssh', '-o UserKnownHostsFile=/dev/null',
                '-o StrictHostKeyChecking=no',
                host, command], stdout=subprocess.PIPE,
                stderr=subprocess.PIPE)
예제 #20
0
 def lldp_update(self):
     subprocess.call(['lldpcli', 'update'])
예제 #21
0
파일: herd.py 프로젝트: KenDUemura/Herd
def scp(host, local_file, remote_file):
    return subprocess.call(['scp', local_file, '%s:%s' % (host, remote_file)],
                stdout=subprocess.PIPE, stderr=subprocess.PIPE)
예제 #22
0
파일: herd.py 프로젝트: Mirascape/Herd
def scp(host, local_file, remote_file):
    return subprocess.call(
        ['scp', local_file, '%s:%s' % (host, remote_file)],
        stdout=subprocess.PIPE,
        stderr=subprocess.PIPE)
예제 #23
0
파일: start.py 프로젝트: JKorf/MediaPi
 def init_sound():
     if sys.platform == "linux" or sys.platform == "linux2":
         Logger().write(LogVerbosity.Debug, "Settings sound to 100%")
         call(["amixer", "sset", "PCM,0", "100%"])
예제 #24
0
파일: herd.py 프로젝트: Mirascape/Herd
def ssh(host, command):
    return subprocess.call(['ssh', host, command],
                           stdout=subprocess.PIPE,
                           stderr=subprocess.PIPE)
예제 #25
0
파일: driver.py 프로젝트: starlingx/config
 def lldp_update(self):
     subprocess.call(['lldpcli', 'update'])  # pylint: disable=not-callable
예제 #26
0
파일: herd.py 프로젝트: sachuin23/Herd
def scp(host, local_file, remote_file):
    incommand=['sshpass','-p',password,'scp',local_file,'%s:%s' %(host,remote_file)]
    print(incommand)
    return subprocess.call(incommand,stdout=subprocess.PIPE, stderr=subprocess.PIPE)
예제 #27
0
파일: herd.py 프로젝트: bennojoy/Herd
def scp(host, local_file, remote_file):
    return subprocess.call(['scp', '-o UserKnownHostsFile=/dev/null',
                '-o StrictHostKeyChecking=no',
                local_file, '%s:%s' % (host, remote_file)],
                stdout=subprocess.PIPE, stderr=subprocess.PIPE)
예제 #28
0
파일: herd.py 프로젝트: KenDUemura/Herd
def ssh(host, command):
    return subprocess.call(['ssh', host, command], stdout=subprocess.PIPE, stderr=subprocess.PIPE)