add the support for team and orgs
This commit is contained in:
parent
8494e4e04d
commit
d2ec0d96e7
3 changed files with 36 additions and 7 deletions
|
|
@ -38,6 +38,8 @@ if os.environ.get('DOCKERCLOUD_USER') and os.environ.get('DOCKERCLOUD_APIKEY'):
|
||||||
rest_host = os.environ.get("DOCKERCLOUD_REST_HOST") or 'https://cloud.docker.com/'
|
rest_host = os.environ.get("DOCKERCLOUD_REST_HOST") or 'https://cloud.docker.com/'
|
||||||
stream_host = os.environ.get("DOCKERCLOUD_STREAM_HOST") or 'wss://ws.cloud.docker.com/'
|
stream_host = os.environ.get("DOCKERCLOUD_STREAM_HOST") or 'wss://ws.cloud.docker.com/'
|
||||||
|
|
||||||
|
namespace = os.environ.get('DOCKERCLOUD_NAMESPACE')
|
||||||
|
|
||||||
user_agent = None
|
user_agent = None
|
||||||
|
|
||||||
logging.basicConfig()
|
logging.basicConfig()
|
||||||
|
|
|
||||||
|
|
@ -58,6 +58,10 @@ class Restful(BasicObject):
|
||||||
assert subsystem, "Subsystem not specified for %s" % self.__class__.__name__
|
assert subsystem, "Subsystem not specified for %s" % self.__class__.__name__
|
||||||
for k, v in list(dict.items()):
|
for k, v in list(dict.items()):
|
||||||
setattr(self, k, v)
|
setattr(self, k, v)
|
||||||
|
if dockercloud.namespace:
|
||||||
|
self._detail_uri = "/".join(["api", subsystem, self._api_version, dockercloud.namespace,
|
||||||
|
endpoint.strip("/"), self.pk])
|
||||||
|
else:
|
||||||
self._detail_uri = "/".join(["api", subsystem, self._api_version, endpoint.strip("/"), self.pk])
|
self._detail_uri = "/".join(["api", subsystem, self._api_version, endpoint.strip("/"), self.pk])
|
||||||
self.__setchanges__([])
|
self.__setchanges__([])
|
||||||
|
|
||||||
|
|
@ -126,6 +130,9 @@ class Immutable(Restful):
|
||||||
subsystem = getattr(cls, 'subsystem', None)
|
subsystem = getattr(cls, 'subsystem', None)
|
||||||
assert endpoint, "Endpoint not specified for %s" % cls.__name__
|
assert endpoint, "Endpoint not specified for %s" % cls.__name__
|
||||||
assert subsystem, "Subsystem not specified for %s" % cls.__name__
|
assert subsystem, "Subsystem not specified for %s" % cls.__name__
|
||||||
|
if dockercloud.namespace:
|
||||||
|
detail_uri = "/".join(["api", subsystem, cls._api_version, dockercloud.namespace, endpoint.strip("/"), pk])
|
||||||
|
else:
|
||||||
detail_uri = "/".join(["api", subsystem, cls._api_version, endpoint.strip("/"), pk])
|
detail_uri = "/".join(["api", subsystem, cls._api_version, endpoint.strip("/"), pk])
|
||||||
json = send_request('GET', detail_uri)
|
json = send_request('GET', detail_uri)
|
||||||
if json:
|
if json:
|
||||||
|
|
@ -141,6 +148,9 @@ class Immutable(Restful):
|
||||||
assert endpoint, "Endpoint not specified for %s" % cls.__name__
|
assert endpoint, "Endpoint not specified for %s" % cls.__name__
|
||||||
assert subsystem, "Subsystem not specified for %s" % cls.__name__
|
assert subsystem, "Subsystem not specified for %s" % cls.__name__
|
||||||
|
|
||||||
|
if dockercloud.namespace:
|
||||||
|
detail_uri = "/".join(["api", subsystem, cls._api_version, dockercloud.namespace, endpoint.strip("/")])
|
||||||
|
else:
|
||||||
detail_uri = "/".join(["api", subsystem, cls._api_version, endpoint.strip("/")])
|
detail_uri = "/".join(["api", subsystem, cls._api_version, endpoint.strip("/")])
|
||||||
objects = []
|
objects = []
|
||||||
while True:
|
while True:
|
||||||
|
|
@ -219,6 +229,9 @@ class Mutable(Immutable):
|
||||||
# Figure out whether we should do a create or update
|
# Figure out whether we should do a create or update
|
||||||
if not self._detail_uri:
|
if not self._detail_uri:
|
||||||
action = "POST"
|
action = "POST"
|
||||||
|
if dockercloud.namespace:
|
||||||
|
path = "/".join(["api", subsystem, self._api_version, dockercloud.namespace, endpoint.lstrip("/")])
|
||||||
|
else:
|
||||||
path = "/".join(["api", subsystem, self._api_version, endpoint.lstrip("/")])
|
path = "/".join(["api", subsystem, self._api_version, endpoint.lstrip("/")])
|
||||||
else:
|
else:
|
||||||
action = "PATCH"
|
action = "PATCH"
|
||||||
|
|
@ -316,7 +329,12 @@ class StreamingLog(StreamingAPI):
|
||||||
endpoint = "%s/%s/logs/?follow=%s" % (resource, uuid, str(follow).lower())
|
endpoint = "%s/%s/logs/?follow=%s" % (resource, uuid, str(follow).lower())
|
||||||
if tail:
|
if tail:
|
||||||
endpoint = "%s&tail=%d" % (endpoint, tail)
|
endpoint = "%s&tail=%d" % (endpoint, tail)
|
||||||
url = "/".join([dockercloud.stream_host.rstrip("/"), "api", subsystem, self._api_version, endpoint.lstrip("/")])
|
if dockercloud.namespace:
|
||||||
|
url = "/".join([dockercloud.stream_host.rstrip("/"), "api", subsystem, self._api_version,
|
||||||
|
dockercloud.namespace, endpoint.lstrip("/")])
|
||||||
|
else:
|
||||||
|
url = "/".join([dockercloud.stream_host.rstrip("/"), "api", subsystem, self._api_version,
|
||||||
|
endpoint.lstrip("/")])
|
||||||
super(self.__class__, self).__init__(url)
|
super(self.__class__, self).__init__(url)
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
|
|
@ -335,6 +353,10 @@ class StreamingLog(StreamingAPI):
|
||||||
class Exec(StreamingAPI):
|
class Exec(StreamingAPI):
|
||||||
def __init__(self, uuid, cmd='sh'):
|
def __init__(self, uuid, cmd='sh'):
|
||||||
endpoint = "container/%s/exec/?command=%s" % (uuid, urllib.quote_plus(cmd))
|
endpoint = "container/%s/exec/?command=%s" % (uuid, urllib.quote_plus(cmd))
|
||||||
|
if dockercloud.namespace:
|
||||||
|
url = "/".join([dockercloud.stream_host.rstrip("/"), "api", "app", self._api_version,
|
||||||
|
dockercloud.namespace, endpoint.lstrip("/")])
|
||||||
|
else:
|
||||||
url = "/".join([dockercloud.stream_host.rstrip("/"), "api", "app", self._api_version, endpoint.lstrip("/")])
|
url = "/".join([dockercloud.stream_host.rstrip("/"), "api", "app", self._api_version, endpoint.lstrip("/")])
|
||||||
super(self.__class__, self).__init__(url)
|
super(self.__class__, self).__init__(url)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -15,7 +15,12 @@ logger = logging.getLogger("python-dockercloud")
|
||||||
class Events(StreamingAPI):
|
class Events(StreamingAPI):
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
endpoint = "events"
|
endpoint = "events"
|
||||||
url = "/".join([dockercloud.stream_host.rstrip("/"), "api", "audit", self._api_version, endpoint.lstrip("/")])
|
if dockercloud.namespace:
|
||||||
|
url = "/".join([dockercloud.stream_host.rstrip("/"), "api", "audit", self._api_version,
|
||||||
|
dockercloud.namespace, endpoint.lstrip("/")])
|
||||||
|
else:
|
||||||
|
url = "/".join([dockercloud.stream_host.rstrip("/"), "api", "audit", self._api_version,
|
||||||
|
endpoint.lstrip("/")])
|
||||||
self.invaid_auth_headers = set()
|
self.invaid_auth_headers = set()
|
||||||
self.auth_error = ""
|
self.auth_error = ""
|
||||||
super(self.__class__, self).__init__(url)
|
super(self.__class__, self).__init__(url)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue