Skip to content

Commit

Permalink
Change hardcoded path in eapi connection to use transport path.
Browse files Browse the repository at this point in the history
  • Loading branch information
mharista committed Feb 1, 2017
1 parent 725684d commit f30808d
Showing 1 changed file with 12 additions and 8 deletions.
20 changes: 12 additions & 8 deletions pyeapi/eapilib.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ def https_connection_factory(path, host, port, context=None, timeout=60):
return HttpsConnection(path, host, port, timeout=timeout)
return HttpsConnection(path, host, port, context=context, timeout=timeout)


class EapiError(Exception):
"""Base exception class for all exceptions generated by eapilib
Expand All @@ -85,6 +86,7 @@ def __init__(self, message, commands=None):
self.commands = commands
super(EapiError, self).__init__(message)


class CommandError(EapiError):
"""Base exception raised for command errors
Expand Down Expand Up @@ -160,7 +162,6 @@ def __init__(self, connection_type, message, commands=None):
super(ConnectionError, self).__init__(message)



class SocketConnection(HTTPConnection):

def __init__(self, path, timeout=60):
Expand All @@ -179,6 +180,7 @@ def connect(self):
self.sock.settimeout(self.timeout)
self.sock.connect(self.path)


class HttpConnection(HTTPConnection):

def __init__(self, path, *args, **kwargs):
Expand All @@ -191,6 +193,7 @@ def __str__(self):
def __repr__(self):
return 'http://%s:%s/%s' % (self.host, self.port, self.path)


class HttpsConnection(HTTPSConnection):

def __init__(self, path, *args, **kwargs):
Expand All @@ -203,6 +206,7 @@ def __str__(self):
def __repr__(self):
return 'https://%s:%s/%s' % (self.host, self.port, self.path)


class EapiConnection(object):
"""Creates a connection to eAPI for sending and receiving eAPI requests
Expand Down Expand Up @@ -251,7 +255,6 @@ def authentication(self, username, password):

_LOGGER.debug('Autentication string is: {}'.format(self._auth))


def request(self, commands, encoding=None, reqid=None, **kwargs):
"""Generates an eAPI request object
Expand Down Expand Up @@ -366,14 +369,14 @@ def send(self, data):
_LOGGER.debug('Request content: {}'.format(data))
# debug('eapi_request: %s' % data)

self.transport.putrequest('POST', '/command-api')
self.transport.putrequest('POST', self.transport.path)

self.transport.putheader('Content-type', 'application/json-rpc')
self.transport.putheader('Content-length', '%d' % len(data))

if self._auth:
self.transport.putheader('Authorization',
'Basic %s' % (self._auth))
'Basic %s' % self._auth)

if int(sys.version[0]) > 2:
# For Python 3.x compatibility
Expand Down Expand Up @@ -449,10 +452,7 @@ def _parse_error_message(self, message):
err = ' '.join(message['error']['data'][-1]['errors'])
out = message['error']['data']

return (code, msg, err, out)



return code, msg, err, out

def execute(self, commands, encoding='json', **kwargs):
"""Executes the list of commands on the destination node
Expand Down Expand Up @@ -495,12 +495,14 @@ def execute(self, commands, encoding='json', **kwargs):
self.error = exc
raise


class SocketEapiConnection(EapiConnection):
def __init__(self, path=None, timeout=60, **kwargs):
super(SocketEapiConnection, self).__init__()
path = path or DEFAULT_UNIX_SOCKET
self.transport = SocketConnection(path, timeout)


class HttpLocalEapiConnection(EapiConnection):
def __init__(self, port=None, path=None, timeout=60, **kwargs):
super(HttpLocalEapiConnection, self).__init__()
Expand All @@ -509,6 +511,7 @@ def __init__(self, port=None, path=None, timeout=60, **kwargs):
self.transport = HttpConnection(path, 'localhost', int(port),
timeout=timeout)


class HttpEapiConnection(EapiConnection):
def __init__(self, host, port=None, path=None, username=None,
password=None, timeout=60, **kwargs):
Expand All @@ -518,6 +521,7 @@ def __init__(self, host, port=None, path=None, username=None,
self.transport = HttpConnection(path, host, int(port), timeout=timeout)
self.authentication(username, password)


class HttpsEapiConnection(EapiConnection):
def __init__(self, host, port=None, path=None, username=None,
password=None, context=None, timeout=60, **kwargs):
Expand Down

0 comments on commit f30808d

Please sign in to comment.