From ef94b85a16eec02f6ff70a94d1d7d7f99e970a16 Mon Sep 17 00:00:00 2001 From: tifayuki Date: Fri, 10 Jun 2016 19:33:14 +0200 Subject: [PATCH] exclude az,nodetype,provider,region from namespace --- dockercloud/api/base.py | 9 +++++---- dockercloud/api/nodeaz.py | 1 + dockercloud/api/nodeprovider.py | 1 + dockercloud/api/noderegion.py | 1 + dockercloud/api/nodetype.py | 1 + 5 files changed, 9 insertions(+), 4 deletions(-) diff --git a/dockercloud/api/base.py b/dockercloud/api/base.py index afe32fd..e9feeed 100644 --- a/dockercloud/api/base.py +++ b/dockercloud/api/base.py @@ -22,6 +22,7 @@ def __init__(self, **kwargs): class Restful(BasicObject): _detail_uri = None + namespaced = True def __init__(self, **kwargs): """Simply reflect all the values in kwargs""" @@ -58,7 +59,7 @@ def _loaddict(self, dict): assert subsystem, "Subsystem not specified for %s" % self.__class__.__name__ for k, v in list(dict.items()): setattr(self, k, v) - if dockercloud.namespace: + if self.namespaced and dockercloud.namespace: self._detail_uri = "/".join(["api", subsystem, self._api_version, dockercloud.namespace, endpoint.strip("/"), self.pk]) else: @@ -130,7 +131,7 @@ def fetch(cls, pk): subsystem = getattr(cls, 'subsystem', None) assert endpoint, "Endpoint not specified for %s" % cls.__name__ assert subsystem, "Subsystem not specified for %s" % cls.__name__ - if dockercloud.namespace: + if cls.namespaced and 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]) @@ -148,7 +149,7 @@ def list(cls, limit=None, **kwargs): assert endpoint, "Endpoint not specified for %s" % cls.__name__ assert subsystem, "Subsystem not specified for %s" % cls.__name__ - if dockercloud.namespace: + if cls.namespaced and 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("/")]) @@ -229,7 +230,7 @@ def save(self): # Figure out whether we should do a create or update if not self._detail_uri: action = "POST" - if dockercloud.namespace: + if cls.namespaced and dockercloud.namespace: path = "/".join(["api", subsystem, self._api_version, dockercloud.namespace, endpoint.lstrip("/")]) else: path = "/".join(["api", subsystem, self._api_version, endpoint.lstrip("/")]) diff --git a/dockercloud/api/nodeaz.py b/dockercloud/api/nodeaz.py index abc4d5f..25a153b 100644 --- a/dockercloud/api/nodeaz.py +++ b/dockercloud/api/nodeaz.py @@ -6,6 +6,7 @@ class AZ(Immutable): subsystem = "infra" endpoint = "/az" + namespaced = False @classmethod def _pk_key(cls): diff --git a/dockercloud/api/nodeprovider.py b/dockercloud/api/nodeprovider.py index 3d31f06..168bc72 100644 --- a/dockercloud/api/nodeprovider.py +++ b/dockercloud/api/nodeprovider.py @@ -6,6 +6,7 @@ class Provider(Immutable): subsystem = "infra" endpoint = "/provider" + namespaced = False @classmethod def _pk_key(cls): diff --git a/dockercloud/api/noderegion.py b/dockercloud/api/noderegion.py index 4d10bed..9a9c97a 100644 --- a/dockercloud/api/noderegion.py +++ b/dockercloud/api/noderegion.py @@ -6,6 +6,7 @@ class Region(Immutable): subsystem = "infra" endpoint = "/region" + namespaced = False @classmethod def _pk_key(cls): diff --git a/dockercloud/api/nodetype.py b/dockercloud/api/nodetype.py index 5274aaf..7416d63 100644 --- a/dockercloud/api/nodetype.py +++ b/dockercloud/api/nodetype.py @@ -6,6 +6,7 @@ class NodeType(Immutable): subsystem = "infra" endpoint = "/nodetype" + namespaced = False @classmethod def _pk_key(cls):