Exemple #1
0
def setup_local(myName, virtualNet, classicalNet, lNode, func, *args,
                **kwargs):
    """
    Sets up
    - local classical communication server (if desired according to the configuration file)
    - client connection to the local virtual node quantum backend
    - client connections to all other classical communication servers

    Arguments
    myName            name of this node (string)
    virtualNet        servers of the virtual nodes (dictionary of host objects)
    classicalNet      servers on the classical communication network (dictionary of host objects)
    lNode             Twisted PB root to use as local server (if applicable)
    func              function to run if all connections are set up
    args, kwargs   additional arguments to be given to func
    """

    logging.basicConfig(
        format="%(asctime)s:%(levelname)s:%(message)s",
        level=simulaqron_settings.log_level,
    )

    # Initialize Twisted callback framework
    dList = []

    # If we are listed as a server node for the classical network, start this server
    if myName in classicalNet.hostDict:
        try:
            logging.debug(
                "LOCAL %s: Starting local classical communication server.",
                myName)
            nb = classicalNet.hostDict[myName]
            nb.root = lNode
            nb.factory = pb.PBServerFactory(nb.root)
            reactor.listenTCP(nb.port, nb.factory)
        except Exception as e:
            logging.error(
                "LOCAL {}: Cannot start classical communication servers: {}".
                format(myName, e))
            return

    # Give the server some time to start up
    time.sleep(3)

    # Connect to the local virtual node simulating the "local" qubits
    logging.debug("LOCAL %s: Connecting to local virtual node.", myName)
    node = virtualNet.hostDict[myName]
    factory = pb.PBClientFactory()
    reactor.connectTCP(node.hostname, node.port, factory)
    deferVirtual = factory.getRootObject()
    dList.append(deferVirtual)

    # Set up a connection to all the other nodes in the classical network
    for node in classicalNet.hostDict:
        nb = classicalNet.hostDict[node]
        if nb.name != myName:
            logging.debug("LOCAL %s: Making classical connection to %s.",
                          myName, nb.name)
            nb.factory = pb.PBClientFactory()
            reactor.connectTCP(nb.hostname, nb.port, nb.factory)
            dList.append(nb.factory.getRootObject())

    deferList = DeferredList(dList, consumeErrors=True)
    deferList.addCallback(init_register, myName, virtualNet, classicalNet,
                          lNode, func, *args, **kwargs)
    deferList.addErrback(localError)
    try:
        reactor.run()
    except error.ReactorNotRestartable:
        pass
Exemple #2
0
    def joinCluster(self):
        def startHeartbeats():
            self._startSlave()
            self.s_rpc.startService()

            if self.role == MasterService.RL_ACTIVE:
                self._startMaster()

        def joinRefused(reason):
            reason.trap(NodeRefusedError, RPCRefusedError)
            log.err("Join to cluster %s failed: Master %s has refused me: %s" %
                    (core.cfg['CLUSTER_NAME'], self.master,
                     reason.getErrorMessage()))
            self.stopService()

        def joinAccepted(result):
            self.role = MasterService.RL_PASSIVE
            log.info("Join successfull, I'm now part of cluster %s." %
                     (core.cfg['CLUSTER_NAME']))
            startHeartbeats()

        def masterConnected(obj):
            d = obj.callRemote("register", DNSCache.getInstance().name)
            d.addCallbacks(joinAccepted, joinRefused)
            d.addErrback(log.err)
            d.addBoth(lambda _: rpcConnector.disconnect())
            return d

        try:
            if self.master is None:
                # New active master
                if DNSCache.getInstance(
                ).name not in core.cfg['ALLOWED_NODES']:
                    log.warn(
                        "I'm not allowed to create a new cluster. Exiting.")
                    raise Exception("Cluster creation not allowed")

                if DiskHeartbeat.is_in_use():
                    log.err("Heartbeat disk is in use but we are alone !")
                    raise Exception("Heartbeat disk already in use")

                log.info("No master found. I'm now the new master of %s." %
                         (core.cfg['CLUSTER_NAME']))
                self.role = MasterService.RL_ACTIVE
                self.master = DNSCache.getInstance().name
                self.status[self.master] = {
                    'timestamp': 0,
                    'offset': 0,
                    'vms': []
                }
                self.disk.make_slot(DNSCache.getInstance().name)
                startHeartbeats()

            else:
                # Passive master
                self.role = MasterService.RL_JOINING
                log.info("Trying to join cluster %s..." %
                         (core.cfg['CLUSTER_NAME']))

                factory = pb.PBClientFactory()
                rpcConnector = reactor.connectTCP(self.master,
                                                  core.cfg['TCP_PORT'],
                                                  factory)
                d = factory.getRootObject()
                d.addCallback(masterConnected)
                d.addErrback(log.err)
        except Exception, e:
            log.err("Startup failed: %s. Shutting down." % (e))
            self.stopService()
Exemple #3
0
        if last_checkin:
            self.last_checkin = last_checkin
        return changes


poller = ViewCvsPoller()


def error(*args):
    log.err()
    reactor.stop()


def poll_changes(remote):
    print("GET CHANGES SINCE", poller.last_checkin, end=' ')
    changes = poller.get_changes()
    for change in changes:
        print(change["who"], "\n *", "\n * ".join(change["files"]))
        change['src'] = 'cvs'
        remote.callRemote('addChange', change).addErrback(error)
    print()
    reactor.callLater(60, poll_changes, remote)


factory = pb.PBClientFactory()
reactor.connectTCP("localhost", 9999, factory)
deferred = factory.login(credentials.UsernamePassword("change", "changepw"))
deferred.addCallback(poll_changes).addErrback(error)

reactor.run()
Exemple #4
0
 def __init__(self):
     self.factory = pb.PBClientFactory()
     reactor.connectUNIX(settings.CIA_BOT_SOCKET, self.factory)
     self.root = block(self.factory.getRootObject())
Exemple #5
0
 def __init__(self):
     self.pbfactory = pb.PBClientFactory()
Exemple #6
0
def main():
    factory = pb.PBClientFactory()
    reactor.connectTCP("localhost", 8800, factory)
    d = factory.getRootObject()
    d.addCallbacks(got_obj)
    reactor.run()
Exemple #7
0
 def connect(self):
     password = md5(MASTER_PASSWORD).digest()
     factory = pb.PBClientFactory()
     reactor.connectTCP(MASTER_IP,MASTER_PORT,factory)
     factory.login(UsernamePassword("CharacterServer-CharacterServer", password),self).addCallbacks(self.connected, self.failure)
     print "Connecting to Master Server..."
Exemple #8
0
 def runTest(self):
     factory = pb.PBClientFactory()
     reactor.connectTCP(self.hostname, self.portno, factory)
     factory.login(UsernamePassword(
         b"benchmark", b"benchmark")).addCallback(self._cbPerspective)
def get_remote(sock):
    conn = pb.PBClientFactory()
    reactor.connectUNIX(sock, conn)
    return conn.getRootObject()
Exemple #10
0
from twisted.spread import pb
from twisted.internet import reactor, defer


class MethodsF(pb.Root):
    def remote_test(self):
        print('WORK')
        return 'Result'


client = pb.PBClientFactory()
d = client.getRootObject()


@defer.inlineCallbacks
def callback(ref):
    d1 = yield ref.callRemote('call', MethodsF())
    d2 = yield ref.callRemote('callDT')
    print(d1, d2)


d.addCallback(callback)

reactor.connectTCP('localhost', 8000, client)  # big_mixin_example.py
reactor.run()
Exemple #11
0
 def connect(self):
     factory = pb.PBClientFactory()
     reactor.connectTCP("localhost", 8789, factory)
     return factory.login(self.credentials).addCallback(self._connected)
Exemple #12
0
 def connect(self, directory, ip, port, sdirectory, selfip, selfport):
     self.directory = directory
     clientfactory = pb.PBClientFactory()
     reactor.connectTCP(ip, port, clientfactory)
     d = clientfactory.getRootObject()
     d.addCallback(self.got_connected, sdirectory, selfip, selfport)
 def connect(self):
      clientfactory = pb.PBClientFactory()
      reactor.connectTCP("localhost", 6001, clientfactory)
      d = clientfactory.getRootObject()
      d.addCallback(self.got_connected)
Exemple #14
0
 def sendChanges(self, opts, changes):
     pbcf = pb.PBClientFactory()
     reactor.connectTCP(opts['bbserver'], int(opts['bbport']), pbcf)
     d = pbcf.login(credentials.UsernamePassword('change', 'changepw'))
     d.addCallback(self.sendAllChanges, changes)
     return d
Exemple #15
0
 def connect(self):
     factory = pb.PBClientFactory()
     reactor.connectTCP(GMSERVERIP,GMSERVERPORT,factory)
     password = md5(GMSERVER_PASSWORD).digest()
     factory.login(UsernamePassword("CharacterServer-CharacterServer", password),self).addCallbacks(self.connected, self.failure)
Exemple #16
0
def main():
    factory = pb.PBClientFactory()
    reactor.connectTCP("localhost", 8800, factory)
    def1 = factory.login(credentials.UsernamePassword("user1", "pass1"))
    def1.addCallback(connected)
    reactor.run()
Exemple #17
0
 def login(self, cred, ip, port):
     factory = pb.PBClientFactory()
     reactor.connectTCP(ip, port, factory)
     return factory.login(cred, client=self)
Exemple #18
0
    def deliverJob(self):
        # returns a Deferred that fires when the job has been delivered
        if self.connect == "ssh":
            tryhost = self.getopt("host")
            tryport = self.getopt("port")
            tryuser = self.getopt("username")
            trydir = self.getopt("jobdir")
            buildbotbin = self.getopt("buildbotbin")
            ssh_command = self.getopt("ssh")
            if not ssh_command:
                ssh_commands = which("ssh")
                if not ssh_commands:
                    raise RuntimeError(
                        "couldn't find ssh executable, make sure "
                        "it is available in the PATH")

                argv = [ssh_commands[0]]
            else:
                # Split the string on whitespace to allow passing options in
                # ssh command too, but preserving whitespace inside quotes to
                # allow using paths with spaces in them which is common under
                # Windows. And because Windows uses backslashes in paths, we
                # can't just use shlex.split there as it would interpret them
                # specially, so do it by hand.
                if runtime.platformType == 'win32':
                    # Note that regex here matches the arguments, not the
                    # separators, as it's simpler to do it like this. And then we
                    # just need to get all of them together using the slice and
                    # also remove the quotes from those that were quoted.
                    argv = [
                        string.strip(a, '"') for a in re.split(
                            r'''([^" ]+|"[^"]+")''', ssh_command)[1::2]
                    ]
                else:
                    # Do use standard tokenization logic under POSIX.
                    argv = shlex.split(ssh_command)

            if tryuser:
                argv += ["-l", tryuser]

            if tryport:
                argv += ["-p", tryport]

            argv += [tryhost, buildbotbin, "tryserver", "--jobdir", trydir]
            pp = RemoteTryPP(self.jobfile)
            reactor.spawnProcess(pp, argv[0], argv, os.environ)
            d = pp.d
            return d
        if self.connect == "pb":
            user = self.getopt("username")
            passwd = self.getopt("passwd")
            master = self.getopt("master")
            tryhost, tryport = master.split(":")
            tryport = int(tryport)
            f = pb.PBClientFactory()
            d = f.login(credentials.UsernamePassword(user, passwd))
            reactor.connectTCP(tryhost, tryport, f)
            d.addCallback(self._deliverJob_pb)
            return d
        raise RuntimeError(
            "unknown connecttype '%s', should be 'ssh' or 'pb'" % self.connect)
Exemple #19
0
 def connect(self):
     factory = pb.PBClientFactory()
     reactor.connectTCP("localhost", 8790, factory)
     def1 = factory.getRootObject()
     def1.addCallbacks(self.got_obj1, self.err_obj1)
Exemple #20
0
 def __init__(self, name):
     self.name = name
     self._factory = pb.PBClientFactory()
     self._reference = ProxyReference()
     self._addr = None
Exemple #21
0
 def connect(self):
     factory = pb.PBClientFactory()
     reactor.connectTCP(self.serverIP, self.serverPort, factory)
     return factory.login(self.credentials,
                          client=self).addCallback(self._connected)
Exemple #22
0
def one(port, user, pw, service, perspective, number):
    factory = pb.PBClientFactory()
    reactor.connectTCP("localhost", port, factory)
    def1 = factory.getPerspective(user, pw, service, perspective)
    def1.addCallback(connected, number)
Exemple #23
0
 def _setUpClient(self):
     portNo = self.serverPort.getHost().port
     self.clientFactory = pb.PBClientFactory()
     self.clientConnector = reactor.connectTCP("127.0.0.1", portNo,
                                               self.clientFactory)
Exemple #24
0
def main():
    foo = Foo()
    factory = pb.PBClientFactory()
    reactor.connectTCP("localhost", 8800, factory)
    factory.getRootObject().addCallback(foo.step1)
    reactor.run()
Exemple #25
0
 def get_store(self):
     factory = pb.PBClientFactory()
     factory.noisy = False
     reactor.connectTCP(self.host, 8789, factory)
     return factory.getRootObject()
Exemple #26
0
 def connect(self):
     factory = pb.PBClientFactory()
     reactor.connectTCP("10.111.101.206", 24498, factory)
     self.remote = yield factory.getRootObject()
     print 'connected'
     yield self.remote.callRemote("setRemote", port=24496)
Exemple #27
0
    def process_change(self, payload, user, repo, repo_url, project):
        """
        Consumes the JSON as a python object and actually starts the build.
        
        :arguments:
            payload
                Python Object that represents the JSON sent by GitHub Service
                Hook.
        """
        changes = []
        newrev = payload['after']
        refname = payload['ref']

        # We only care about regular heads, i.e. branches
        match = re.match(r"^refs\/heads\/(.+)$", refname)
        if not match:
            logging.info("Ignoring refname `%s': Not a branch" % refname)

        branch = match.group(1)
        # Find out if the branch was created, deleted or updated. Branches
        # being deleted aren't really interesting.
        if re.match(r"^0*$", newrev):
            logging.info("Branch `%s' deleted, ignoring" % branch)
        else:
            for commit in payload['commits']:
                files = []
                files.extend(commit['added'])
                files.extend(commit['modified'])
                files.extend(commit['removed'])
                change = {
                    'revision':
                    commit['id'],
                    'revlink':
                    commit['url'],
                    'comments':
                    commit['message'],
                    'branch':
                    branch,
                    'who':
                    commit['author']['name'] + " <" +
                    commit['author']['email'] + ">",
                    'files':
                    files,
                    'links': [commit['url']],
                    'repository':
                    repo_url,
                    'project':
                    project,
                }
                changes.append(change)

        # Submit the changes, if any
        if not changes:
            logging.warning("No changes found")
            return

        host, port = self.master.split(':')
        port = int(port)

        factory = pb.PBClientFactory()
        deferred = factory.login(
            credentials.UsernamePassword("change", "changepw"))
        reactor.connectTCP(host, port, factory)
        deferred.addErrback(self.connectFailed)
        deferred.addCallback(self.connected, changes)
Exemple #28
0
 def runClient(self):
     f = pb.PBClientFactory()
     self.cport = reactor.connectTCP("127.0.0.1", self.port, f)
     d = f.getRootObject()
     d.addCallback(self.clientConnected)
     return d
Exemple #29
0
    def start(self, address, port):
        print("Client.")
        pygame.init()
        factory = pb.PBClientFactory()
        engine = Engine(ClientState(factory))

        def send_press_up(obj):
            obj.callRemote('setUpArrow', True)

        @engine.handle_keydown(pygame.locals.K_UP)
        def press_up():
            d = factory.getRootObject()
            d.addCallback(send_press_up)

        def send_release_up(obj):
            obj.callRemote('setUpArrow', False)

        @engine.handle_keyup(pygame.locals.K_UP)
        def release_up():
            d = factory.getRootObject()
            d.addCallback(send_release_up)

        def send_press_down(obj):
            obj.callRemote('setDownArrow', True)

        @engine.handle_keydown(pygame.locals.K_DOWN)
        def press_down():
            d = factory.getRootObject()
            d.addCallback(send_press_down)

        def send_release_down(obj):
            obj.callRemote('setDownArrow', False)

        @engine.handle_keyup(pygame.locals.K_DOWN)
        def release_down():
            d = factory.getRootObject()
            d.addCallback(send_release_down)

        def send_press_left(obj):
            obj.callRemote('setLeftArrow', True)

        @engine.handle_keydown(pygame.locals.K_LEFT)
        def press_left():
            d = factory.getRootObject()
            d.addCallback(send_press_left)

        def send_release_left(obj):
            obj.callRemote('setLeftArrow', False)

        @engine.handle_keyup(pygame.locals.K_LEFT)
        def release_left():
            d = factory.getRootObject()
            d.addCallback(send_release_left)

        def send_press_right(obj):
            obj.callRemote('setRightArrow', True)

        @engine.handle_keydown(pygame.locals.K_RIGHT)
        def press_right():
            d = factory.getRootObject()
            d.addCallback(send_press_right)

        def send_release_right(obj):
            obj.callRemote('setRightArrow', False)

        @engine.handle_keyup(pygame.locals.K_RIGHT)
        def release_right():
            d = factory.getRootObject()
            d.addCallback(send_release_right)

        @engine.handle_keyup(pygame.locals.K_q)
        def stop():
            reactor.stop()

        pygame.display.set_caption('TPG Client')
        engine.start()
        reactor.connectTCP(address, port, factory)
        reactor.run()