Exemplo n.º 1
0
def main():
    if '-gen' in sys.argv:
        A = int(sys.argv[2])
        B = int(sys.argv[3])
        ip_block(A, B)

    # Create a way to run this distributed from python
    elif '-multi-setup' in sys.argv:
        import network
        workers = []
        peers = {}
        # Determine which nodes are available to work
        for n in network.get_node_names():
            name = n.split('/')[-1].split('.')[0]
            h, i, p, m = utils.load_credentials(name, False)
            peers[name] = [h, i, p, m]
            # check if online
            if network.check_connected(h, i, p):
                workers.append(name)
            else:
                print '%s@%s offline' % (name, i)

        # Now distribute the assignments
        print '[*] %d Workers Available' % len(workers)
        for w in workers:
            # give them the latest copy of this program
            H, I, P, M = peers[w]
            rpath = '/home/%s/Documents/PoolParty/code/0.6/' % H
            if utils.remote_file_exists(H, I, P, rpath + 'trace.py'):
                utils.ssh_exec('rm %strace.py' % rpath, I, H, P, False)
            utils.put_file('trace.py', rpath, H, I, P, False)
            # Now give them a ip_space.txt file and a script to run trace.py
            utils.ssh_exec('rm %shops.txt' % rpath, I, H, P, True)
            # c = 'cd %s; python trace.py 0>&-' % rpath
            # put this in a .sh script and transfer, then execute
            # utils.ssh_exec('cd %s; python trace.py 0>&-' % rpath,H,I,P,False)

    elif '-multi-view' in sys.argv:
        import tracewatch
        print('[*] Monitoring Traces...')

    else:
        ips = list(utils.swap('ip_space.txt', False))
        if not os.path.isfile(os.getcwd() + '/hops.txt'):
            os.system('touch hops.txt')
        random.shuffle(ips)
        pool = multiprocessing.Pool(10)
        for ip in ips:
            try:
                event = pool.apply_async(func=trace, args=(ip, False))
                hopdata, nhops = event.get(timeout=60)
                print ' - %d hops to %s' % (nhops, ip)
                open('hops.txt', 'a').write('%s:%d\n' % (ip, nhops))
            except multiprocessing.TimeoutError:
                open('hops.txt', 'a').write('%s:?\n' % ip)
                pass
Exemplo n.º 2
0
    def check_if_valid(self):
        if self.name is None:
            raise CX("name is required")
        if self.kernel is None:
            raise CX("Error with distro %s - kernel is required" % (self.name))
        if self.initrd is None:
            raise CX("Error with distro %s - initrd is required" % (self.name))

        if utils.file_is_remote(self.kernel):
            if not utils.remote_file_exists(self.kernel):
                raise CX("Error with distro %s - kernel '%s' not found" % (self.name, self.kernel))
        elif not os.path.exists(self.kernel):
            raise CX("Error with distro %s - kernel not found" % (self.name))

        if utils.file_is_remote(self.initrd):
            if not utils.remote_file_exists(self.initrd):
                raise CX("Error with distro %s - initrd path not found" % (self.name))
        elif not os.path.exists(self.initrd):
            raise CX("Error with distro %s - initrd path not found" % (self.name))
Exemplo n.º 3
0
    def check_if_valid(self):
        if self.name is None:
            raise CX("name is required")
        if self.kernel is None:
            raise CX("Error with distro %s - kernel is required" % (self.name))
        if self.initrd is None:
            raise CX("Error with distro %s - initrd is required" % (self.name))

        if utils.file_is_remote(self.kernel):
            if not utils.remote_file_exists(self.kernel):
                raise CX("Error with distro %s - kernel not found" % (self.name))
        elif not os.path.exists(self.kernel):
            raise CX("Error with distro %s - kernel not found" % (self.name))

        if utils.file_is_remote(self.initrd):
            if not utils.remote_file_exists(self.initrd):
                raise CX("Error with distro %s - initrd path not found" % 
                        (self.name))
        elif not os.path.exists(self.initrd):
            raise CX("Error with distro %s - initrd path not found" % (self.name))
Exemplo n.º 4
0
    def distribute(self):
        # now make sure all remote hosts have share folders for receiving
        for peer in self.peers:
            h, i, p, k = utils.load_credentials(peer, False)
            if utils.remote_file_exists(
                    h, i, p,
                    '/home/%s/PoolParty/code/0.5/PoolData/Shares' % h) == 1:
                # get their shares
                share_names = utils.ssh_exec(
                    'ls /home/%s/PoolParty/code/0.5/PoolData/Shares' % h, i, h,
                    p, False)
                # remote machine needs to hash its shares
                # distribute this peers files too
                # for fs in share_distro[peer]:
                for fs in os.listdir('PoolData/Shares'):
                    recipient = self.distro[fs]
                    rh, ri, rp, rk = utils.load_credentials(recipient, False)
                    f = 'PoolData/Shares/' + fs
                    rf = '/home/%s/PoolParty/code/0.5/PoolData/Shares/' % rh

                    if recipient == peer and utils.remote_file_exists(
                            h, i, p, rf + fs) == 0:
                        print('Giving %s file: %s' % (recipient, fs))
                        # print(rf+fs)
                        utils.put_file(f, rf, rh, ri, rp, True)
                    # else:
                    # 	print('%s has file %s' % (recipient, fs))
            else:
                if utils.remote_file_exists(
                        h, i, p,
                        '/home/%s/PoolParty/code/0.5/PoolData' % h) == 0:
                    utils.ssh_exec(
                        'mkdir /home/%s/PoolParty/code/0.5/PoolData' % h, i, h,
                        p, False)
                utils.ssh_exec(
                    'mkdir /home/%s/PoolParty/code/0.5/PoolData/Shares' % h, i,
                    h, p, False)
Exemplo n.º 5
0
def load_workers():
    nodes = network.get_node_names()
    workers = []
    peers = {}
    # Determine which nodes are available to work
    for n in network.get_node_names():
        name = n.split('/')[-1].split('.')[0]
        h, i, p, m = utils.load_credentials(name, False)
        peers[name] = [h, i, p, m]
        # check if online
        rp = '/home/%s/Documents/PoolParty/code/0.6/hops.txt' % h
        if network.check_connected(h, i, p) and utils.remote_file_exists(
                h, i, p, rp):
            workers.append(name)
        else:
            print '%s@%s offline' % (name, i)
    # Now distribute the assignments
    print '[*] %d Machines Actively Working' % len(workers)
    return workers, peers