Skip to content

Commit

Permalink
region parameter fix
Browse files Browse the repository at this point in the history
  • Loading branch information
tzahimizrahi committed May 31, 2018
1 parent ebf814b commit 90e94ba
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
2 changes: 1 addition & 1 deletion nomad/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ def __init__(self,
self.cert = cert

self.requester = api.Requester(address=address, uri=self.get_uri(), port=port, namespace=namespace,
token=token, timeout=timeout, version=version, verify=verify, cert=cert)
token=token, timeout=timeout, version=version, verify=verify, cert=cert, region = region)

self._jobs = api.Jobs(self.requester)
self._job = api.Job(self.requester)
Expand Down
13 changes: 12 additions & 1 deletion nomad/api/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

class Requester(object):

def __init__(self, address=None, uri='http://127.0.0.1', port=4646, namespace=None, token=None, timeout=5, version='v1', verify=False, cert=()):
def __init__(self, address=None, uri='http://127.0.0.1', port=4646, namespace=None, token=None, timeout=5, version='v1', verify=False, cert=(), region=None):
self.uri = uri
self.port = port
self.namespace = namespace
Expand All @@ -18,6 +18,7 @@ def __init__(self, address=None, uri='http://127.0.0.1', port=4646, namespace=No
self.cert = cert
self.address = address
self.session = requests.Session()
self.region = region

def _endpointBuilder(self, *args):
if args:
Expand Down Expand Up @@ -46,6 +47,7 @@ def _required_namespace(self, endpoint):

def _urlBuilder(self, endpoint):
url = self.address

if self.address is None:
url = "{uri}:{port}".format(uri=self.uri,
port=self.port)
Expand All @@ -56,6 +58,15 @@ def _urlBuilder(self, endpoint):
url = "{url}?namespace={namespace}".format(
url=url,
namespace=self.namespace)

if self.region is not None:
if self.namespace:
delimiter = '&'
else:
delimiter = '?'
url = "{url}{delimiter}region={region}".format(
url=url, delimiter=delimiter,
region=self.region)
return url


Expand Down

0 comments on commit 90e94ba

Please sign in to comment.