示例#1
0
 def connect(self,
             url=None,
             urls=None,
             address=None,
             handler=None,
             reconnect=None,
             heartbeat=None,
             ssl_domain=None):
     conn = self.events.connection()
     conn._pin = conn  #circular reference until the open event gets handled
     if handler:
         conn.context = handler
     conn.container = self.container_id or str(generate_uuid())
     conn.heartbeat = heartbeat
     if url: conn.address = Urls([url])
     elif urls: conn.address = Urls(urls)
     elif address: conn.address = address
     else: raise ValueError("One of url, urls or address required")
     if reconnect:
         conn.reconnect = reconnect
     elif reconnect is None:
         conn.reconnect = Backoff()
     if ssl_domain:
         conn.ssl_domain = ssl_domain
     conn._session_policy = SessionPerConnection()  #todo: make configurable
     conn.open()
     return conn
示例#2
0
    def connect(self, url=None, urls=None, address=None, handler=None, reconnect=None, heartbeat=None, ssl_domain=None):
        """
        Initiates the establishment of an AMQP connection.
        """
        conn = self.connection(handler)
        conn.container = self.container_id or str(generate_uuid())

        connector = Connector(conn)
        conn._overrides = connector
        if url:
            connector.address = Urls([url])
        elif urls:
            connector.address = Urls(urls)
        elif address:
            connector.address = address
        else:
            raise ValueError("One of url, urls or address required")
        if heartbeat:
            connector.heartbeat = heartbeat
        if reconnect:
            connector.reconnect = reconnect
        elif reconnect is None:
            connector.reconnect = Backoff()
        connector.ssl_domain = ssl_domain or self.ssl.client
        conn._session_policy = SessionPerConnection()  # todo: make configurable
        conn.open()
        return conn
示例#3
0
 def init(self, node, id):
     if "container" not in node:
         self.setval("container", str(generate_uuid()))
     else:
         self.setval("container", node["container"])
     self.setval("opened", True)
     self.setval("name", "connection/0.0.0.0:" + str(id))
     self.setval("properties", node["properties"])
     self.setval("ssl", False)
     if "host" in node:
         self.setval("host", node["host"])
     else:
         self.setval("host", "0.0.0.0:20000")
     if "isEncrypted" not in node:
         self.setval("isEncrypted", False)
     else:
         self.setval("isEncrypted", node["isEncrypted"])
     if "user" not in node:
         self.setval("user", "anonymous")
     else:
         self.setval("user", node["user"])
     self.setval("role", node["nodeType"])
     self.setval("isAuthenticated", False)
     self.setval("identity", id)
     self.setval("dir", node["cdir"])
示例#4
0
 def __init__(self, prefix, client):
     super(ClientHandler, self).__init__()
     self.name = "%s-%s" % (prefix, str(generate_uuid())[:8])
     self.client = client
     self.link = None
     self.iteration = 0
     self.fatal_conditions = ["amqp:unauthorized-access", "amqp:not-found"]
示例#5
0
    def connect(self,
                url=None,
                urls=None,
                address=None,
                handler=None,
                reconnect=None,
                heartbeat=None,
                ssl_domain=None):
        """
        Initiates the establishment of an AMQP connection. Returns an
        instance of proton.Connection.
        """
        conn = self.connection(handler)
        conn.container = self.container_id or str(generate_uuid())

        connector = Connector(conn)
        conn._overrides = connector
        if url: connector.address = Urls([url])
        elif urls: connector.address = Urls(urls)
        elif address: connector.address = address
        else: raise ValueError("One of url, urls or address required")
        if heartbeat:
            connector.heartbeat = heartbeat
        if reconnect:
            connector.reconnect = reconnect
        elif reconnect is None:
            connector.reconnect = Backoff()
        connector.ssl_domain = ssl_domain or (self.ssl and self.ssl.client)
        conn._session_policy = SessionPerConnection()  #todo: make configurable
        conn.open()
        return conn
示例#6
0
 def __init__(self, *handlers, **kwargs):
     super(Container, self).__init__(*handlers, **kwargs)
     if "impl" not in kwargs:
         self.ssl = SSLConfig()
         self.global_handler = GlobalOverrides(kwargs.get("global_handler", self.global_handler))
         self.trigger = None
         self.container_id = str(generate_uuid())
         Wrapper.__setattr__(self, "subclass", self.__class__)
示例#7
0
 def __init__(self, *handlers):
     self.ssl = SSLConfig()
     h = [Connector(self, self.ssl.client), ScopedHandler()]
     h.extend(handlers)
     self.events = Events(*h)
     self.loop = SelectLoop(self.events)
     self.trigger = None
     self.container_id = str(generate_uuid())
示例#8
0
    def connect(self, url=None, urls=None, address=None, handler=None, reconnect=None, heartbeat=None, ssl_domain=None, **kwargs):
        """
        Initiates the establishment of an AMQP connection. Returns an
        instance of proton.Connection.

        @param url: URL string of process to connect to

        @param urls: list of URL strings of process to try to connect to

        Only one of url or urls should be specified.

        @param reconnect: A value of False will prevent the library
        form automatically trying to reconnect if the underlying
        socket is disconnected before the connection has been closed.

        @param heartbeat: A value in milliseconds indicating the
        desired frequency of heartbeats used to test the underlying
        socket is alive.

        @param ssl_domain: SSL configuration in the form of an
        instance of proton.SSLdomain.

        @param handler: a connection scoped handler that will be
        called to process any events in the scope of this connection
        or its child links

        @param kwargs: sasl_enabled, which determines whether a sasl
        layer is used for the connection; allowed_mechs an optional
        list of SASL mechanisms to allow if sasl is enabled;
        allow_insecure_mechs a flag indicating whether insecure
        mechanisms, such as PLAIN over a non-encrypted socket, are
        allowed. These options can also be set at container scope.

        """
        conn = self.connection(handler)
        conn.container = self.container_id or str(generate_uuid())

        connector = Connector(conn)
        connector.allow_insecure_mechs = kwargs.get('allow_insecure_mechs', self.allow_insecure_mechs)
        connector.allowed_mechs = kwargs.get('allowed_mechs', self.allowed_mechs)
        connector.sasl_enabled = kwargs.get('sasl_enabled', self.sasl_enabled)
        connector.user = kwargs.get('user', self.user)
        connector.password = kwargs.get('password', self.password)
        conn._overrides = connector
        if url: connector.address = Urls([url])
        elif urls: connector.address = Urls(urls)
        elif address: connector.address = address
        else: raise ValueError("One of url, urls or address required")
        if heartbeat:
            connector.heartbeat = heartbeat
        if reconnect:
            connector.reconnect = reconnect
        elif reconnect is None:
            connector.reconnect = Backoff()
        connector.ssl_domain = ssl_domain or (self.ssl and self.ssl.client)
        conn._session_policy = SessionPerConnection() #todo: make configurable
        conn.open()
        return conn
示例#9
0
 def _get_id(self, container, remote, local):
     if local and remote:
         "%s-%s-%s" % (container, remote, local)
     elif local:
         return "%s-%s" % (container, local)
     elif remote:
         return "%s-%s" % (container, remote)
     else:
         return "%s-%s" % (container, str(generate_uuid()))
示例#10
0
 def _get_id(self, container, remote, local):
     if local and remote:
         "%s-%s-%s" % (container, remote, local)
     elif local:
         return "%s-%s" % (container, local)
     elif remote:
         return "%s-%s" % (container, remote)
     else:
         return "%s-%s" % (container, str(generate_uuid()))
示例#11
0
 def __init__(self, *handlers, **kwargs):
     super(Container, self).__init__(*handlers, **kwargs)
     if "impl" not in kwargs:
         try:
             self.ssl = SSLConfig()
         except SSLUnavailable:
             self.ssl = None
         self.global_handler = GlobalOverrides(kwargs.get('global_handler', self.global_handler))
         self.trigger = None
         self.container_id = str(generate_uuid())
         Wrapper.__setattr__(self, 'subclass', self.__class__)
示例#12
0
 def on_link_opening(self, event):
     if event.link.is_sender:
         if event.link.remote_source and event.link.remote_source.dynamic:
             event.link.source.address = str(generate_uuid())
             self.senders[event.link.source.address] = event.link
         elif event.link.remote_target and event.link.remote_target.address:
             event.link.target.address = event.link.remote_target.address
             self.senders[event.link.remote_target.address] = event.link
         elif event.link.remote_source:
             event.link.source.address = event.link.remote_source.address
     elif event.link.remote_target:
         event.link.target.address = event.link.remote_target.address
示例#13
0
 def on_link_opening(self, event):
     if event.link.is_sender:
         if event.link.remote_source and event.link.remote_source.dynamic:
             event.link.source.address = str(generate_uuid())
             self.senders[event.link.source.address] = event.link
         elif event.link.remote_target and event.link.remote_target.address:
             event.link.target.address = event.link.remote_target.address
             self.senders[event.link.remote_target.address] = event.link
         elif event.link.remote_source:
             event.link.source.address = event.link.remote_source.address
     elif event.link.remote_target:
         event.link.target.address = event.link.remote_target.address
示例#14
0
 def on_link_opening(self, event):
     if event.link.is_sender:
         if event.link.remote_source.dynamic:
             address = str(generate_uuid())
             event.link.source.address = address
             q = Queue(True)
             self.queues[address] = q
             q.subscribe(event.link)
         elif event.link.remote_source.address:
             event.link.source.address = event.link.remote_source.address
             self._queue(event.link.source.address).subscribe(event.link)
     elif event.link.remote_target.address:
         event.link.target.address = event.link.remote_target.address
示例#15
0
 def __init__(self, delegate, source, offset, prefetch):
     super(PartitionReceiver, self).__init__()
     self.handlers = []
     if prefetch:
         self.handlers.append(CFlowController(prefetch))
     self.handlers.append(IncomingMessageHandler(True, self))
     self.fatal_conditions = ["amqp:unauthorized-access", "amqp:not-found"]
     self.delegate = delegate
     self.source = source
     self.offset = offset
     self.name = str(generate_uuid())[:8]
     self.iteration = 0
     self.client = None
示例#16
0
 def on_link_opening(self, event):
     if event.link.is_sender:
         if event.link.remote_source.dynamic:
             address = str(generate_uuid())
             event.link.source.address = address
             q = Queue(True)
             self.queues[address] = q
             q.subscribe(event.link)
         elif event.link.remote_source.address:
             event.link.source.address = event.link.remote_source.address
             self._queue(event.link.source.address).subscribe(event.link)
     elif event.link.remote_target.address:
         event.link.target.address = event.link.remote_target.address
示例#17
0
 def init(self, node, identity, ldir, owningAddr, linkType, connId):
     linkUuid = str(generate_uuid())
     self.setval("name", linkUuid)
     self.setval("identity", identity)
     self.setval("linkName", linkUuid)
     self.setval("linkType", linkType)
     self.setval("linkDir", ldir)
     self.setval("owningAddr", owningAddr)
     self.setval("capacity", 250)
     self.setZero(["undeliveredCount", "unsettledCount", "deliveryCount", "presettledCount", "acceptedCount",
                   "rejectedCount", "releasedCount", "modifiedCount"])
     self.setval("connectionId", connId)
     self.setval("adminStatus", "enabled")
     self.setval("operStatus", "up")
    def __init__(self, address, **kwargs):
        """
        Constructs a new L{EventHubClient} with the given address Url.

        @param address: the full Uri string of the event hub.
        """
        self.container_id = "eventhubs.pycli-" + str(generate_uuid())[:8]
        self.address = Url(address)
        self.injector = EventInjector()
        self.container = self._create_container(self.address, **kwargs)
        self.daemon = None
        self.connection = None
        self.session_policy = None
        self.clients = []
        self.stopped = False
        log.info("%s: created the event hub client", self.container_id)
示例#19
0
 def __init__(self, *handlers, **kwargs):
     super(Container, self).__init__(*handlers, **kwargs)
     if "impl" not in kwargs:
         try:
             self.ssl = SSLConfig()
         except SSLUnavailable:
             self.ssl = None
         self.global_handler = GlobalOverrides(kwargs.get('global_handler', self.global_handler))
         self.trigger = None
         self.container_id = str(generate_uuid())
         self.allow_insecure_mechs = True
         self.allowed_mechs = None
         self.sasl_enabled = True
         self.user = None
         self.password = None
         Wrapper.__setattr__(self, 'subclass', self.__class__)
示例#20
0
 def __init__(self, *handlers, **kwargs):
     super(Container, self).__init__(*handlers, **kwargs)
     if "impl" not in kwargs:
         try:
             self.ssl = SSLConfig()
         except SSLUnavailable:
             self.ssl = None
         self.global_handler = GlobalOverrides(kwargs.get('global_handler', self.global_handler))
         self.trigger = None
         self.container_id = str(generate_uuid())
         self.allow_insecure_mechs = True
         self.allowed_mechs = None
         self.sasl_enabled = True
         self.user = None
         self.password = None
         Wrapper.__setattr__(self, 'subclass', self.__class__)
示例#21
0
    def on_link_opening(self, event):
        if event.link.is_sender:
            if event.link.remote_source.dynamic:
                if self.verbose:
                    print("opening dynamic sender")
                address = str(generate_uuid())
                event.link.source.address = address
            elif event.link.remote_source.address:
                if self.verbose:
                    print("opening remote_source address sender")
                event.link.source.address = event.link.remote_source.address
            else:
                print("received unknown sender link")
            self.senders[event.link.source.address] = event.link

        elif event.link.is_receiver:
            if self.verbose:
                print "got a receiver link"
            event.link.target.address = event.link.remote_target.address
示例#22
0
    def on_link_opening(self, event):
        if event.link.is_sender:
            if event.link.remote_source.dynamic:
                if self.verbose:
                    print("opening dynamic sender")
                address = str(generate_uuid())
                event.link.source.address = address
            elif event.link.remote_source.address:
                if self.verbose:
                    print("opening remote_source address sender")
                event.link.source.address = event.link.remote_source.address
            else:
                print("received unknown sender link")
            self.senders[event.link.source.address] = event.link

        elif event.link.is_receiver:
            if self.verbose:
                print "got a receiver link"
            event.link.target.address = event.link.remote_target.address
示例#23
0
    def open(cls, owner=None):
        port = -1
        listener = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
        for i in range(25672, 35672):
            port = i
            try:
                listener.bind(("127.0.0.1", port))
                break
            except socket.error as err:
                if err.errno != errno.EADDRINUSE:
                    log.error("%s: pipe socket bind failed %s", owner, err)
                    raise
        listener.listen(1)
        client = None
        server = None
        try:
            client = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
            client.setblocking(False)
            client.connect_ex(("127.0.0.1", port))
            server, address = listener.accept()
            log.info("%s: pipe accepted socket from %s", owner, address)
            client.setblocking(True)
            code = generate_uuid().bytes
            client.sendall(code)
            code2 = Pipe._recvall(server, len(code))
            if code != code2:
                raise IOError(errno.EIO, "Pipe handshake failed")

            pipe = Pipe()
            pipe.sink = client
            pipe.source = server
            return pipe
        except:
            if client:
                client.close()
            if server:
                server.close()
            raise
        finally:
            listener.close()
示例#24
0
    def connect(self, url=None, urls=None, address=None, handler=None, reconnect=None, heartbeat=None, ssl_domain=None,
                **kwargs):
        """
        Initiates the establishment of an AMQP connection. Returns an
        instance of proton.Connection.

        @param url: URL string of process to connect to

        @param urls: list of URL strings of process to try to connect to

        Only one of url or urls should be specified.

        @param reconnect: Reconnect is enabled by default.  You can
        pass in an instance of Backoff to control reconnect behavior.
        A value of False will prevent the library from automatically
        trying to reconnect if the underlying socket is disconnected
        before the connection has been closed.

        @param heartbeat: A value in milliseconds indicating the
        desired frequency of heartbeats used to test the underlying
        socket is alive.

        @param ssl_domain: SSL configuration in the form of an
        instance of proton.SSLDomain.

        @param handler: a connection scoped handler that will be
        called to process any events in the scope of this connection
        or its child links

        @param kwargs: 'sasl_enabled', which determines whether a sasl
        layer is used for the connection; 'allowed_mechs', an optional
        string containing a space-separated list of SASL mechanisms to
        allow if sasl is enabled; 'allow_insecure_mechs', a flag
        indicating whether insecure mechanisms, such as PLAIN over a
        non-encrypted socket, are allowed; 'virtual_host', the
        hostname to set in the Open performative used by peer to
        determine the correct back-end service for the client. If
        'virtual_host' is not supplied the host field from the URL is
        used instead; 'user', the user to authenticate; 'password',
        the authentication secret.

        """
        conn = self.connection(handler)
        conn.container = self.container_id or str(generate_uuid())
        conn.offered_capabilities = kwargs.get('offered_capabilities')
        conn.desired_capabilities = kwargs.get('desired_capabilities')
        conn.properties = kwargs.get('properties')

        connector = Connector(conn)
        connector.allow_insecure_mechs = kwargs.get('allow_insecure_mechs', self.allow_insecure_mechs)
        connector.allowed_mechs = kwargs.get('allowed_mechs', self.allowed_mechs)
        connector.sasl_enabled = kwargs.get('sasl_enabled', self.sasl_enabled)
        connector.user = kwargs.get('user', self.user)
        connector.password = kwargs.get('password', self.password)
        connector.virtual_host = kwargs.get('virtual_host')
        if connector.virtual_host:
            # only set hostname if virtual-host is a non-empty string
            conn.hostname = connector.virtual_host
        connector.ssl_sni = kwargs.get('sni')
        connector.max_frame_size = kwargs.get('max_frame_size')

        conn._overrides = connector
        if url:
            connector.address = Urls([url])
        elif urls:
            connector.address = Urls(urls)
        elif address:
            connector.address = address
        else:
            raise ValueError("One of url, urls or address required")
        if heartbeat:
            connector.heartbeat = heartbeat
        if reconnect:
            connector.reconnect = reconnect
        elif reconnect is None:
            connector.reconnect = Backoff()
        # use container's default client domain if none specified.  This is
        # only necessary of the URL specifies the "amqps:" scheme
        connector.ssl_domain = ssl_domain or (self.ssl and self.ssl.client)
        conn._session_policy = SessionPerConnection()  # todo: make configurable
        conn.open()
        return conn
示例#25
0
    def connect(self,
                url=None,
                urls=None,
                address=None,
                handler=None,
                reconnect=None,
                heartbeat=None,
                ssl_domain=None,
                **kwargs):
        """
        Initiates the establishment of an AMQP connection. Returns an
        instance of proton.Connection.

        @param url: URL string of process to connect to

        @param urls: list of URL strings of process to try to connect to

        Only one of url or urls should be specified.

        @param reconnect: A value of False will prevent the library
        form automatically trying to reconnect if the underlying
        socket is disconnected before the connection has been closed.

        @param heartbeat: A value in milliseconds indicating the
        desired frequency of heartbeats used to test the underlying
        socket is alive.

        @param ssl_domain: SSL configuration in the form of an
        instance of proton.SSLdomain.

        @param handler: a connection scoped handler that will be
        called to process any events in the scope of this connection
        or its child links

        @param kwargs: sasl_enabled, which determines whether a sasl layer is
        used for the connection; allowed_mechs an optional list of SASL
        mechanisms to allow if sasl is enabled; allow_insecure_mechs a flag
        indicating whether insecure mechanisms, such as PLAIN over a
        non-encrypted socket, are allowed; 'virtual_host' the hostname to set
        in the Open performative used by peer to determine the correct
        back-end service for the client. If 'virtual_host' is not supplied the
        host field from the URL is used instead."

        """
        conn = self.connection(handler)
        conn.container = self.container_id or str(generate_uuid())
        conn.offered_capabilities = kwargs.get('offered_capabilities')
        conn.desired_capabilities = kwargs.get('desired_capabilities')
        conn.properties = kwargs.get('properties')

        connector = Connector(conn)
        connector.allow_insecure_mechs = kwargs.get('allow_insecure_mechs',
                                                    self.allow_insecure_mechs)
        connector.allowed_mechs = kwargs.get('allowed_mechs',
                                             self.allowed_mechs)
        connector.sasl_enabled = kwargs.get('sasl_enabled', self.sasl_enabled)
        connector.user = kwargs.get('user', self.user)
        connector.password = kwargs.get('password', self.password)
        connector.virtual_host = kwargs.get('virtual_host')
        if connector.virtual_host:
            # only set hostname if virtual-host is a non-empty string
            conn.hostname = connector.virtual_host
        connector.ssl_sni = kwargs.get('sni')
        connector.max_frame_size = kwargs.get('max_frame_size')

        conn._overrides = connector
        if url: connector.address = Urls([url])
        elif urls: connector.address = Urls(urls)
        elif address: connector.address = address
        else: raise ValueError("One of url, urls or address required")
        if heartbeat:
            connector.heartbeat = heartbeat
        if reconnect:
            connector.reconnect = reconnect
        elif reconnect is None:
            connector.reconnect = Backoff()
        # use container's default client domain if none specified.  This is
        # only necessary of the URL specifies the "amqps:" scheme
        connector.ssl_domain = ssl_domain or (self.ssl and self.ssl.client)
        conn._session_policy = SessionPerConnection()  #todo: make configurable
        conn.open()
        return conn
示例#26
0
    def connect(self,
                url=None,
                urls=None,
                address=None,
                handler=None,
                reconnect=None,
                heartbeat=None,
                ssl_domain=None,
                **kwargs):
        """
        Initiates the establishment of an AMQP connection. Returns an
        instance of proton.Connection.

        @param url: URL string of process to connect to

        @param urls: list of URL strings of process to try to connect to

        Only one of url or urls should be specified.

        @param reconnect: A value of False will prevent the library
        form automatically trying to reconnect if the underlying
        socket is disconnected before the connection has been closed.

        @param heartbeat: A value in milliseconds indicating the
        desired frequency of heartbeats used to test the underlying
        socket is alive.

        @param ssl_domain: SSL configuration in the form of an
        instance of proton.SSLdomain.

        @param handler: a connection scoped handler that will be
        called to process any events in the scope of this connection
        or its child links

        @param kwargs: sasl_enabled, which determines whether a sasl
        layer is used for the connection; allowed_mechs an optional
        list of SASL mechanisms to allow if sasl is enabled;
        allow_insecure_mechs a flag indicating whether insecure
        mechanisms, such as PLAIN over a non-encrypted socket, are
        allowed. These options can also be set at container scope.

        """
        conn = self.connection(handler)
        conn.container = self.container_id or str(generate_uuid())

        connector = Connector(conn)
        connector.allow_insecure_mechs = kwargs.get('allow_insecure_mechs',
                                                    self.allow_insecure_mechs)
        connector.allowed_mechs = kwargs.get('allowed_mechs',
                                             self.allowed_mechs)
        connector.sasl_enabled = kwargs.get('sasl_enabled', self.sasl_enabled)
        conn._overrides = connector
        if url: connector.address = Urls([url])
        elif urls: connector.address = Urls(urls)
        elif address: connector.address = address
        else: raise ValueError("One of url, urls or address required")
        if heartbeat:
            connector.heartbeat = heartbeat
        if reconnect:
            connector.reconnect = reconnect
        elif reconnect is None:
            connector.reconnect = Backoff()
        connector.ssl_domain = ssl_domain or (self.ssl and self.ssl.client)
        conn._session_policy = SessionPerConnection()  #todo: make configurable
        conn.open()
        return conn