Skip to content

Commit c6314a0

Browse files
committed
Merge pull request #4 from WLPhoenix/master
Bug fixes and new version scheme
2 parents e3d7863 + 150acc4 commit c6314a0

File tree

3 files changed

+33
-16
lines changed

3 files changed

+33
-16
lines changed

stackdio/client/__init__.py

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
import os
1+
import json
22
import logging
3+
import os
34

45
from .http import HttpMixin, use_admin_auth, endpoint
56
from .exceptions import StackException
@@ -54,7 +55,7 @@ def create_provider(self, **kwargs):
5455
for key in form_data.keys():
5556
form_data[key] = kwargs.get(key)
5657

57-
return self._post(endpoint, data=form_data, jsonify=True)
58+
return self._post(endpoint, data=json.dumps(form_data), jsonify=True)
5859

5960

6061
@endpoint("providers/")
@@ -83,7 +84,7 @@ def create_profile(self, title, image_id, ssh_user, cloud_provider,
8384
"cloud_provider": cloud_provider,
8485
"default_instance_size": default_instance_size
8586
}
86-
return self._post(endpoint, data=data, jsonify=True)
87+
return self._post(endpoint, data=json.dumps(data), jsonify=True)
8788

8889

8990
@endpoint("profiles/")
@@ -107,7 +108,7 @@ def import_formula(self, formula_uri, public=True):
107108
"uri": formula_uri,
108109
"public": public,
109110
}
110-
return self._post(endpoint, data=data, jsonify=True)
111+
return self._post(endpoint, data=json.dumps(data), jsonify=True)
111112

112113

113114
@endpoint("blueprints/")
@@ -131,7 +132,7 @@ def create_blueprint(self, blueprint, provider="ec2"):
131132
self.get_formula(component["id"][0]),
132133
component["id"][1])
133134

134-
return self._post(endpoint, data=blueprint, jsonify=True)
135+
return self._post(endpoint, data=json.dumps(blueprint), jsonify=True)
135136

136137

137138
@use_admin_auth
@@ -145,7 +146,7 @@ def create_security_group(self, name, description, cloud_provider, is_default=Tr
145146
"cloud_provider": cloud_provider,
146147
"is_default": is_default
147148
}
148-
return self._post(endpoint, data=data, jsonify=True)
149+
return self._post(endpoint, data=json.dumps(data), jsonify=True)
149150

150151

151152
@endpoint("settings/")
@@ -161,7 +162,7 @@ def set_public_key(self, public_key):
161162
data = {
162163
"public_key": public_key
163164
}
164-
return self._put(endpoint, data=data, jsonify=True)
165+
return self._put(endpoint, data=json.dumps(data), jsonify=True)
165166

166167

167168
@endpoint("formulas/")
@@ -336,7 +337,7 @@ def get_zone(self, title, type_name="ec2"):
336337
@endpoint("stacks/")
337338
def launch_stack(self, stack_data):
338339
"""Launch a stack as described by stack_data"""
339-
return self._post(endpoint, data=stack_data, jsonify=True)['results']
340+
return self._post(endpoint, data=json.dumps(stack_data), jsonify=True)
340341

341342

342343
@endpoint("stacks/{stack_id}/hosts/")
@@ -389,4 +390,4 @@ def do_action(self, stack_id, action):
389390

390391
data = {"action": action}
391392

392-
return self._post(endpoint, data=data, jsonify=True)
393+
return self._post(endpoint, data=json.dumps(data), jsonify=True)

stackdio/client/http.py

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,6 @@ def wrapper(*args, **kwargs):
5050
return wrapper
5151

5252

53-
54-
5553
def endpoint(path):
5654
"""Takes a path extension and appends to the known API base url.
5755
The result of this is then added to the decorated functions global
@@ -60,21 +58,39 @@ def decorator(func):
6058
@wraps(func)
6159
def wrapper(obj, *args, **kwargs):
6260

61+
# Get what locals() would return directly after calling
62+
# 'func' with the given args and kwargs
6363
future_locals = getcallargs(func, *((obj,) + args), **kwargs)
64+
65+
# Build the variable we'll inject
6466
url = "{url}{path}".format(
6567
url=obj.url,
6668
path=path.format(**future_locals))
6769

70+
# Grab the global context for the passed function
6871
g = func.__globals__
69-
oldvalue = g.get('endpoint')
72+
73+
# Create a unique default object so we can accurately determine
74+
# if we replaced a value
75+
sentinel = object()
76+
oldvalue = g.get('endpoint', sentinel)
77+
78+
# Inject our variable into the global scope
7079
g['endpoint'] = url
7180

81+
# Logging and function call
7282
if oldvalue:
73-
logger.warn("Value %s for 'endpoint' replaced in global scope "
74-
"for function %s" % (oldvalue, func.__name__))
83+
logger.debug("Value %s for 'endpoint' replaced in global scope "
84+
"for function %s" % (oldvalue, func.__name__))
7585
logger.debug("%s.__globals__['endpoint'] = %s" % (func.__name__, url))
7686

77-
return func(obj, *args, **kwargs)
87+
result = func(obj, *args, **kwargs)
88+
89+
# Replace the previous value, if it existed
90+
if oldvalue is not sentinel:
91+
g['endpoint'] = oldvalue
92+
93+
return result
7894
return wrapper
7995
return decorator
8096

stackdio/client/version.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
__version__ = "0.0.3"
1+
__version__ = "0.0.6.client.1"

0 commit comments

Comments
 (0)