requests_unixsocket.Session

Here are the examples of the python api requests_unixsocket.Session taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.

13 Examples 7

Example 1

Project: DoMonit Source File: changes.py
Function: init
    def __init__(self, container_id):
        self.container_id = container_id
        
        self.base = "http+unix://%2Fvar%2Frun%2Fdocker.sock"
        self.url = "/containers/%s/changes" % (self.container_id)
        
        self.session = requests_unixsocket.Session()
        try:
            self.resp = self.session.get( self.base + self.url)
        except Exception as ex:
            template = "An exception of type {0} occured. Arguments:\n{1!r}"
            message = template.format(type(ex).__name__, ex.args)
            print message            

Example 2

Project: DoMonit Source File: containers.py
Function: init
    def __init__(self):        
        self.base = "http+unix://%2Fvar%2Frun%2Fdocker.sock"
        self.url = "/containers/json"
        
        self.session = requests_unixsocket.Session()
        try:
            self.resp = self.session.get( self.base + self.url)
        except Exception as ex:
            template = "An exception of type {0} occured. Arguments:\n{1!r}"
            message = template.format(type(ex).__name__, ex.args)
            print message

Example 3

Project: DoMonit Source File: inspect.py
Function: init
    def __init__(self, container_id):
        self.container_id = container_id
        
        self.base = "http+unix://%2Fvar%2Frun%2Fdocker.sock"
        self.url = "/containers/%s/json" % (self.container_id)
        
        self.session = requests_unixsocket.Session()
        try:
            self.resp = self.session.get( self.base + self.url)
        except Exception as ex:
            template = "An exception of type {0} occured. Arguments:\n{1!r}"
            message = template.format(type(ex).__name__, ex.args)
            print message            

Example 4

Project: DoMonit Source File: process.py
Function: init
    def __init__(self, container_id, ps_args = "ef"):
        
        self.container_id = container_id
        self.ps_args = ps_args

        self.base = "http+unix://%2Fvar%2Frun%2Fdocker.sock"
        self.url = "/containers/%s/top?ps_args=%s" % (self.container_id, self.ps_args)
        
        self.session = requests_unixsocket.Session()
        try:
            self.resp = self.session.get( self.base + self.url)
        except Exception as ex:
            template = "An exception of type {0} occured. Arguments:\n{1!r}"
            message = template.format(type(ex).__name__, ex.args)
            print message            

Example 5

Project: DoMonit Source File: stats.py
Function: init
    def __init__(self, container_id, stream = "0"):
        
        self.container_id = container_id
        self.stream = stream

        self.base = "http+unix://%2Fvar%2Frun%2Fdocker.sock"
        self.url = "/containers/%s/stats?stream=%s" % (self.container_id, self.stream)
        
        self.session = requests_unixsocket.Session()
        try:
            self.resp = self.session.get( self.base + self.url)
        except Exception as ex:
            template = "An exception of type {0} occured. Arguments:\n{1!r}"
            message = template.format(type(ex).__name__, ex.args)
            print message 

Example 6

Project: pylxd Source File: client.py
Function: init
    def __init__(self, api_endpoint, cert=None, verify=True):
        self._api_endpoint = api_endpoint

        if self._api_endpoint.startswith('http+unix://'):
            self.session = requests_unixsocket.Session()
        else:
            self.session = requests.Session()
            self.session.cert = cert
            self.session.verify = verify

Example 7

Project: requests-unixsocket Source File: test_requests_unixsocket.py
def test_unix_domain_adapter_connection_error():
    session = requests_unixsocket.Session('http+unix://')

    for method in ['get', 'post', 'head', 'patch', 'put', 'delete', 'options']:
        with pytest.raises(requests.ConnectionError):
            getattr(session, method)(
                'http+unix://socket_does_not_exist/path/to/page')

Example 8

Project: requests-unixsocket Source File: test_requests_unixsocket.py
def test_unix_domain_adapter_connection_proxies_error():
    session = requests_unixsocket.Session('http+unix://')

    for method in ['get', 'post', 'head', 'patch', 'put', 'delete', 'options']:
        with pytest.raises(ValueError) as excinfo:
            getattr(session, method)(
                'http+unix://socket_does_not_exist/path/to/page',
                proxies={"http+unix": "http://10.10.1.10:1080"})
        assert ('UnixAdapter does not support specifying proxies'
                in str(excinfo.value))

Example 9

Project: DoMonit Source File: logs.py
Function: init
    def __init__(self, container_id, *args, **kwargs ):

        self.container_id = container_id
        self.stderr = kwargs.get("stderr", "true")
        self.stdout = kwargs.get("stdout", "true")
        self.timestamps = kwargs.get("timestamps", "false")
        self.follow = kwargs.get("follow", "false")
        self.tail = kwargs.get("tail", "all")
        self.since = kwargs.get("since", "0")
        self.details = kwargs.get("details", "false")
        
        self.base = "http+unix://%2Fvar%2Frun%2Fdocker.sock"

        self.url = (
	      "/containers/%s/logs?"\
              "stderr=%s"\
              "&stdout=%s"\
              "&timestamps=%s"\
              "&follow=%s"\
              "&tail=%s"\
              "&since=%s"\
              "&details=%s"
        )%(
              self.container_id, 
              self.stderr, 
              self.stdout, 
              self.timestamps, 
              self.follow, 
              self.tail, 
              self.since, 
              self.details 
           )

        self.session = requests_unixsocket.Session()
        self.resp = self.session.get( self.base + self.url)

Example 10

Project: consulate Source File: adapters.py
Function: init
    def __init__(self, timeout=None):
        super(UnixSocketRequest, self).__init__(timeout)
        self.session = requests_unixsocket.Session()

Example 11

Project: pylxd Source File: test_client.py
    def test_session_unix_socket(self):
        """HTTP nodes return a requests_unixsocket session."""
        node = client._APINode('http+unix://test.com')

        self.assertIsInstance(node.session, requests_unixsocket.Session)

Example 12

Project: requests-unixsocket Source File: test_requests_unixsocket.py
def test_unix_domain_adapter_ok():
    with UnixSocketServerThread() as usock_thread:
        session = requests_unixsocket.Session('http+unix://')
        urlencoded_usock = requests.compat.quote_plus(usock_thread.usock)
        url = 'http+unix://%s/path/to/page' % urlencoded_usock

        for method in ['get', 'post', 'head', 'patch', 'put', 'delete',
                       'options']:
            logger.debug('Calling session.%s(%r) ...', method, url)
            r = getattr(session, method)(url)
            logger.debug(
                'Received response: %r with text: %r and headers: %r',
                r, r.text, r.headers)
            assert r.status_code == 200
            assert r.headers['server'] == 'waitress'
            assert r.headers['X-Transport'] == 'unix domain socket'
            assert r.headers['X-Requested-Path'] == '/path/to/page'
            assert r.headers['X-Socket-Path'] == usock_thread.usock
            assert isinstance(r.connection, requests_unixsocket.UnixAdapter)
            assert r.url == url
            if method == 'head':
                assert r.text == ''
            else:
                assert r.text == 'Hello world!'

Example 13

Project: requests-unixsocket Source File: test_requests_unixsocket.py
def test_unix_domain_adapter_url_with_query_params():
    with UnixSocketServerThread() as usock_thread:
        session = requests_unixsocket.Session('http+unix://')
        urlencoded_usock = requests.compat.quote_plus(usock_thread.usock)
        url = ('http+unix://%s'
               '/containers/nginx/logs?timestamp=true' % urlencoded_usock)

        for method in ['get', 'post', 'head', 'patch', 'put', 'delete',
                       'options']:
            logger.debug('Calling session.%s(%r) ...', method, url)
            r = getattr(session, method)(url)
            logger.debug(
                'Received response: %r with text: %r and headers: %r',
                r, r.text, r.headers)
            assert r.status_code == 200
            assert r.headers['server'] == 'waitress'
            assert r.headers['X-Transport'] == 'unix domain socket'
            assert r.headers['X-Requested-Path'] == '/containers/nginx/logs'
            assert r.headers['X-Requested-Query-String'] == 'timestamp=true'
            assert r.headers['X-Socket-Path'] == usock_thread.usock
            assert isinstance(r.connection, requests_unixsocket.UnixAdapter)
            assert r.url == url
            if method == 'head':
                assert r.text == ''
            else:
                assert r.text == 'Hello world!'