@@ -22,6 +22,7 @@ def __init__(self, **kwargs):
22
22
23
23
class Restful (BasicObject ):
24
24
_detail_uri = None
25
+ namespaced = True
25
26
26
27
def __init__ (self , ** kwargs ):
27
28
"""Simply reflect all the values in kwargs"""
@@ -58,7 +59,11 @@ def _loaddict(self, dict):
58
59
assert subsystem , "Subsystem not specified for %s" % self .__class__ .__name__
59
60
for k , v in list (dict .items ()):
60
61
setattr (self , k , v )
61
- self ._detail_uri = "/" .join (["api" , subsystem , self ._api_version , endpoint .strip ("/" ), self .pk ])
62
+ if self .namespaced and dockercloud .namespace :
63
+ self ._detail_uri = "/" .join (["api" , subsystem , self ._api_version , dockercloud .namespace ,
64
+ endpoint .strip ("/" ), self .pk ])
65
+ else :
66
+ self ._detail_uri = "/" .join (["api" , subsystem , self ._api_version , endpoint .strip ("/" ), self .pk ])
62
67
self .__setchanges__ ([])
63
68
64
69
@property
@@ -126,7 +131,10 @@ def fetch(cls, pk):
126
131
subsystem = getattr (cls , 'subsystem' , None )
127
132
assert endpoint , "Endpoint not specified for %s" % cls .__name__
128
133
assert subsystem , "Subsystem not specified for %s" % cls .__name__
129
- detail_uri = "/" .join (["api" , subsystem , cls ._api_version , endpoint .strip ("/" ), pk ])
134
+ if cls .namespaced and dockercloud .namespace :
135
+ detail_uri = "/" .join (["api" , subsystem , cls ._api_version , dockercloud .namespace , endpoint .strip ("/" ), pk ])
136
+ else :
137
+ detail_uri = "/" .join (["api" , subsystem , cls ._api_version , endpoint .strip ("/" ), pk ])
130
138
json = send_request ('GET' , detail_uri )
131
139
if json :
132
140
instance = cls ()
@@ -141,7 +149,10 @@ def list(cls, limit=None, **kwargs):
141
149
assert endpoint , "Endpoint not specified for %s" % cls .__name__
142
150
assert subsystem , "Subsystem not specified for %s" % cls .__name__
143
151
144
- detail_uri = "/" .join (["api" , subsystem , cls ._api_version , endpoint .strip ("/" )])
152
+ if cls .namespaced and dockercloud .namespace :
153
+ detail_uri = "/" .join (["api" , subsystem , cls ._api_version , dockercloud .namespace , endpoint .strip ("/" )])
154
+ else :
155
+ detail_uri = "/" .join (["api" , subsystem , cls ._api_version , endpoint .strip ("/" )])
145
156
objects = []
146
157
while True :
147
158
if limit and len (objects ) >= limit :
@@ -219,7 +230,10 @@ def save(self):
219
230
# Figure out whether we should do a create or update
220
231
if not self ._detail_uri :
221
232
action = "POST"
222
- path = "/" .join (["api" , subsystem , self ._api_version , endpoint .lstrip ("/" )])
233
+ if cls .namespaced and dockercloud .namespace :
234
+ path = "/" .join (["api" , subsystem , self ._api_version , dockercloud .namespace , endpoint .lstrip ("/" )])
235
+ else :
236
+ path = "/" .join (["api" , subsystem , self ._api_version , endpoint .lstrip ("/" )])
223
237
else :
224
238
action = "PATCH"
225
239
path = self ._detail_uri
@@ -316,7 +330,12 @@ def __init__(self, subsystem, resource, uuid, tail, follow):
316
330
endpoint = "%s/%s/logs/?follow=%s" % (resource , uuid , str (follow ).lower ())
317
331
if tail :
318
332
endpoint = "%s&tail=%d" % (endpoint , tail )
319
- url = "/" .join ([dockercloud .stream_host .rstrip ("/" ), "api" , subsystem , self ._api_version , endpoint .lstrip ("/" )])
333
+ if dockercloud .namespace :
334
+ url = "/" .join ([dockercloud .stream_host .rstrip ("/" ), "api" , subsystem , self ._api_version ,
335
+ dockercloud .namespace , endpoint .lstrip ("/" )])
336
+ else :
337
+ url = "/" .join ([dockercloud .stream_host .rstrip ("/" ), "api" , subsystem , self ._api_version ,
338
+ endpoint .lstrip ("/" )])
320
339
super (self .__class__ , self ).__init__ (url )
321
340
322
341
@staticmethod
@@ -335,7 +354,11 @@ def run_forever(self, *args, **kwargs):
335
354
class Exec (StreamingAPI ):
336
355
def __init__ (self , uuid , cmd = 'sh' ):
337
356
endpoint = "container/%s/exec/?command=%s" % (uuid , urllib .quote_plus (cmd ))
338
- url = "/" .join ([dockercloud .stream_host .rstrip ("/" ), "api" , "app" , self ._api_version , endpoint .lstrip ("/" )])
357
+ if dockercloud .namespace :
358
+ url = "/" .join ([dockercloud .stream_host .rstrip ("/" ), "api" , "app" , self ._api_version ,
359
+ dockercloud .namespace , endpoint .lstrip ("/" )])
360
+ else :
361
+ url = "/" .join ([dockercloud .stream_host .rstrip ("/" ), "api" , "app" , self ._api_version , endpoint .lstrip ("/" )])
339
362
super (self .__class__ , self ).__init__ (url )
340
363
341
364
@staticmethod
0 commit comments