Ejemplo n.º 1
0
def serve_forking(options):    
    t = ForkingServer(SlaveService, hostname = options.host, 
        port = options.port, reuse_addr = True, 
        authenticator = options.authenticator, registrar = options.registrar,
        auto_register = options.auto_register)
    t.logger.quiet = options.quiet
    if options.logfile:
        t.logger.console = open(options.logfile, "w")
    t.start()
Ejemplo n.º 2
0
def serve_forking(options):
    t = ForkingServer(SlaveService, hostname=options.host,
                      port=options.port, reuse_addr=True,
                      authenticator=options.authenticator, registrar=options.registrar,
                      auto_register=options.auto_register)
    t.logger.quiet = options.quiet
    if options.logfile:
        t.logger.console = open(options.logfile, "w")
    t.start()
Ejemplo n.º 3
0
def start_slave(port, data_dir):

    # set up data directory
    data_dir = path.abspath(data_dir)
    _mkdirp(data_dir)

    # store some config for later
    #  (i don't really have anywhere better to put it)
    SlaveServer._port = int(port)
    SlaveServer._hostname = gethostname()
    SlaveServer._datadir = data_dir

    _mkdirp(path.join(data_dir, 'storage'))

    s = ForkingServer(SlaveServer, port=int(port))
    _register(SlaveServer._hostname, SlaveServer._port)
    s.start()

    _unregister(SlaveServer._hostname, SlaveServer._port)
Ejemplo n.º 4
0
import rpyc
from constRPYC import * 
from rpyc.utils.server import ForkingServer

class ServerDirectory(rpyc.Service):
    registryDirectory = {}

    def exposed_register(self, server_name, my_ip_adress, port_number):
    	self.registryDirectory[server_name] = (my_ip_adress, port_number)
    	print (self.registryDirectory)
    
    def exposed_lookup(self, server_name):
        if server_name in self.registryDirectory:
            return self.registryDirectory[server_name]
        else:
            return None

if __name__ == "__main__":
    server_dir = ForkingServer(ServerDirectory, port = '' )
    server_dir.start()
    
Ejemplo n.º 5
0
def main():
    from rpyc.utils.server import ForkingServer
    server = ForkingServer(PrimeCalculatorWorker, port=PRIME_CALC_PORT)
    server.start()
Ejemplo n.º 6
0
import rpyc
from rpyc.utils.server import ForkingServer


class DBList(rpyc.Service):
    value = []

    def exposed_append(self, data):
        self.value = self.value + [data]
        print("append", data)
        return self.value

    def exposed_value(self):
        return self.value


if __name__ == "__main__":
    server = ForkingServer(DBList, port=12345)
    server.start()
Ejemplo n.º 7
0
        if isPrime:
            primes.append(possiblePrime)
            batch += 1  #batch is the length of primes
            if (batch % batchSize == 0):  # one batch of primes == batchSize
                stop_time = time.time()
                elapsed = stop_time - start_time
                cbfunc(batch, elapsed)

    return primes


class MyService(rpyc.Service):
    def on_connect(self, conn):  #runs when a connection is started
        print("\n>>> RPyC service connected ....")

    def on_disconnect(self, conn):  #runs after the connection has closed
        print("<<< RPyC service disconnected ...")

    def exposed_get_primes(self, lowerLimit, upperLimit,
                           callbackF):  #exposed method
        print(" Starting computation on server ..")
        list_of_primes = primes(lowerLimit, upperLimit, 1000, callbackF)
        print(" Computing finished.")
        return list_of_primes


if __name__ == "__main__":
    from rpyc.utils.server import ForkingServer
    t = ForkingServer(MyService, port=18861)
    t.start()
Ejemplo n.º 8
0
            bot = Bot(self.channel, self.host)
            dummy(bot)
    def make_exchange(self, name, channel, callback):
        channel.exchange_declare(exchange=name, type ='fanout')
        result = channel.queue_declare(exclusive=True)
        queue_name = result.method.queue
        channel.queue_bind(exchange=name, queue=queue_name)
        channel.basic_consume(callback, queue=queue_name, no_ack=True)
    def close(self):
        self.connection.close()

class Ev3HostService(rpyc.Service):
    __rabbit = None
    __process = None

    def exposed_start(self, host, broker, username='******', password='******'):
        if not self.__rabbit is None:
            self.__rabbit.close()
        print "Rabbit start request on " + host + " for broker " + broker
        if not self.__process is None:
            self.__process.terminate()
        self.__rabbit = Rabbit(host, broker, username, password)
        self.__process = Process(target=self.__rabbit.work)
        self.__process.start()

if __name__ == "__main__":
    from rpyc.utils.server import ForkingServer
    f = ForkingServer(Ev3HostService, port=12345)
    print "Starting rpyc Ev3HostService"
    f.start()
Ejemplo n.º 9
0
                    chan.recv(1024)
                # Retrieve signed certificate from server
                try:
                    sftp.get('/home/{0}/{1}'.format(self.ssh_user, certfile),
                         os.getcwd() + '/{0}'.format(certfile))
                except paramiko.SFTPError as e:
                    self.log.error('Unable to retrieve certificate from firewall: {0}'.format(str(e)))
                chan.send('rm /home/{0}/{1}\n'.format(self.ssh_user, certfile))
                chan.close()
                sftp.close()
            with open(certfile, 'r') as certificate:
                cert = certificate.read()
            os.remove(reqfile)
            os.remove(certfile)
            # Return signed cert to client
            return cert


class RetryMethodError(Exception):
    """Custom exception used for signaling that the calling process should
    perform another attempt at method execution."""
    pass

if __name__ == '__main__':
    # Connection requires an SSL certificate signed by the same CA as the server's certificate
    authenticator = SSLAuthenticator('autovpn-server.key', 'autovpn-server.crt')
    logging.basicConfig()
    server = ForkingServer(AutoVPNServer, port=54321,
                           authenticator=authenticator)
    server.start()