Skip to content

Commit bbb3fd2

Browse files
author
Clark Perkins
committed
Updated methods for 0.7
1 parent 1647a88 commit bbb3fd2

File tree

10 files changed

+316
-330
lines changed

10 files changed

+316
-330
lines changed

setup.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,11 @@ def test_python_version():
9999
'Programming Language :: Python :: 2',
100100
'Programming Language :: Python :: 2.6',
101101
'Programming Language :: Python :: 2.7',
102+
'Programming Language :: Python :: 3',
103+
'Programming Language :: Python :: 3.2',
104+
'Programming Language :: Python :: 3.3',
105+
'Programming Language :: Python :: 3.4',
106+
'Programming Language :: Python :: 3.5',
102107
'Topic :: System :: Clustering',
103108
'Topic :: System :: Distributed Computing',
104109
]

stackdio/client/__init__.py

Lines changed: 11 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,9 @@
1515
# limitations under the License.
1616
#
1717

18-
import json
1918
import logging
2019

21-
from .http import use_admin_auth, endpoint
20+
from .http import get, post, patch
2221
from .exceptions import BlueprintException, StackException, IncompatibleVersionException
2322

2423
from .blueprint import BlueprintMixin
@@ -61,59 +60,25 @@ def __init__(self, protocol="https", host="localhost", port=443,
6160
raise IncompatibleVersionException('Server version {0}.{1}.{2} not '
6261
'supported.'.format(**self.version))
6362

64-
@endpoint("")
63+
@get('')
6564
def get_root(self):
66-
"""Get the api root"""
67-
return self._get(endpoint, jsonify=True)
65+
pass
6866

69-
@endpoint("version/")
67+
@get('version/')
7068
def get_version(self):
71-
return self._get(endpoint, jsonify=True)['version']
69+
pass
7270

73-
@use_admin_auth
74-
@endpoint("security_groups/")
71+
@get_version.response
72+
def get_version(self, resp):
73+
return resp['version']
74+
75+
@post('cloud/security_groups/')
7576
def create_security_group(self, name, description, cloud_provider, is_default=True):
7677
"""Create a security group"""
7778

78-
data = {
79+
return {
7980
"name": name,
8081
"description": description,
8182
"cloud_provider": cloud_provider,
8283
"is_default": is_default
8384
}
84-
return self._post(endpoint, data=json.dumps(data), jsonify=True)
85-
86-
@endpoint("user/")
87-
def get_public_key(self):
88-
"""Get the public key for the logged in user"""
89-
return self._get(endpoint, jsonify=True)['settings']['public_key']
90-
91-
@endpoint("settings/")
92-
def set_public_key(self, public_key):
93-
"""Upload a public key for our user. public_key can be the actual key, a
94-
file handle, or a path to a key file"""
95-
96-
if isinstance(public_key, file):
97-
public_key = public_key.read()
98-
elif isinstance(public_key, str) and os.path.exists(public_key):
99-
public_key = open(public_key, "r").read()
100-
101-
data = {
102-
"public_key": public_key
103-
}
104-
return self._put(endpoint, data=json.dumps(data), jsonify=True)
105-
106-
@endpoint("instance_sizes/")
107-
def get_instance_id(self, instance_id, provider_type="ec2"):
108-
"""Get the id for an instance_id. The instance_id parameter is the
109-
provider name (e.g. m1.large). The id returned is the stackd.io id
110-
for use in API calls (e.g. 1)."""
111-
112-
result = self._get(endpoint, jsonify=True)
113-
for instance in result['results']:
114-
if instance.get("instance_id") == instance_id and \
115-
instance.get("provider_type") == provider_type:
116-
return instance.get("id")
117-
118-
raise StackException("Instance type %s from provider %s not found" %
119-
(instance_id, provider_type))

stackdio/client/account.py

Lines changed: 19 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -15,24 +15,22 @@
1515
# limitations under the License.
1616
#
1717

18-
import json
19-
20-
from .http import HttpMixin, endpoint
18+
from .http import HttpMixin, get, post, delete
2119

2220

2321
class AccountMixin(HttpMixin):
2422

25-
@endpoint("cloud/providers/")
23+
@get('cloud/providers/', paginate=True)
2624
def list_providers(self):
2725
"""List all providers"""
28-
return self._get(endpoint, jsonify=True)['results']
26+
pass
2927

30-
@endpoint("cloud/providers/")
31-
def search_providers(self, provider_id):
32-
"""List all providers"""
33-
return self._get(endpoint, jsonify=True)['results']
28+
@get('cloud/providers/', paginate=True)
29+
def search_providers(self, **kwargs):
30+
"""Search for a provider"""
31+
pass
3432

35-
@endpoint("cloud/accounts/")
33+
@post('cloud/accounts/')
3634
def create_account(self, **kwargs):
3735
"""Create an account"""
3836

@@ -52,24 +50,24 @@ def create_account(self, **kwargs):
5250
for key in form_data.keys():
5351
form_data[key] = kwargs.get(key)
5452

55-
return self._post(endpoint, data=json.dumps(form_data), jsonify=True)
53+
return form_data
5654

57-
@endpoint("accounts/")
55+
@get('cloud/accounts/', paginate=True)
5856
def list_accounts(self):
5957
"""List all account"""
60-
return self._get(endpoint, jsonify=True)['results']
58+
pass
6159

62-
@endpoint("accounts/{account_id}/")
63-
def get_account(self, account_id, none_on_404=False):
60+
@get('cloud/accounts/{account_id}/')
61+
def get_account(self, account_id):
6462
"""Return the account that matches the given id"""
65-
return self._get(endpoint, jsonify=True, none_on_404=none_on_404)
63+
pass
6664

67-
@endpoint("accounts/")
68-
def search_accounts(self, account_id):
65+
@get('cloud/accounts/')
66+
def search_accounts(self, **kwargs):
6967
"""List all accounts"""
70-
return self._get(endpoint, jsonify=True)['results']
68+
pass
7169

72-
@endpoint("accounts/{account_id}/")
70+
@delete('cloud/accounts/{account_id}/')
7371
def delete_account(self, account_id):
7472
"""List all accounts"""
75-
return self._delete(endpoint, jsonify=True)['results']
73+
pass

stackdio/client/blueprint.py

Lines changed: 18 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -15,17 +15,19 @@
1515
# limitations under the License.
1616
#
1717

18-
import json
19-
20-
from .http import HttpMixin, endpoint
18+
from .exceptions import BlueprintException
19+
from .http import HttpMixin, get, post, delete
2120

2221

2322
class BlueprintMixin(HttpMixin):
2423

25-
@endpoint("blueprints/")
26-
def create_blueprint(self, blueprint, provider="ec2"):
24+
@post('blueprints/')
25+
def create_blueprint(self, blueprint):
2726
"""Create a blueprint"""
2827

28+
if 'host_definitions' not in blueprint:
29+
raise BlueprintException('Blueprints must contain a list of host_definitions')
30+
2931
formula_map = {}
3032

3133
if 'formula_versions' in blueprint:
@@ -50,27 +52,24 @@ def create_blueprint(self, blueprint, provider="ec2"):
5052

5153
# check the provided blueprint to see if we need to look up any ids
5254
for host in blueprint['host_definitions']:
53-
for component in host['formula_components']:
55+
for component in host.get('formula_components', []):
5456
if component['sls_path'] in formula_map:
5557
component['formula'] = formula_map[component['sls_path']]
5658

57-
return self._post(endpoint, data=json.dumps(blueprint), jsonify=True, raise_for_status=False)
59+
return blueprint
5860

59-
@endpoint("blueprints/")
61+
@get('blueprints/', paginate=True)
6062
def list_blueprints(self):
61-
"""Return info for a specific blueprint_id"""
62-
return self._get(endpoint, jsonify=True)['results']
63+
pass
6364

64-
@endpoint("blueprints/{blueprint_id}/")
65-
def get_blueprint(self, blueprint_id, none_on_404=False):
66-
"""Return info for a specific blueprint_id"""
67-
return self._get(endpoint, jsonify=True, none_on_404=none_on_404)
65+
@get('blueprints/{blueprint_id}/')
66+
def get_blueprint(self, blueprint_id):
67+
pass
6868

69-
@endpoint("blueprints/")
69+
@get('blueprints/', paginate=True)
7070
def search_blueprints(self, **kwargs):
71-
"""Return info for a specific blueprint_id"""
72-
return self._get(endpoint, params=kwargs, jsonify=True)['results']
71+
pass
7372

74-
@endpoint("blueprints/{blueprint_id}")
73+
@delete('blueprints/{blueprint_id}')
7574
def delete_blueprint(self, blueprint_id):
76-
return self._delete(endpoint, jsonify=True)
75+
pass

stackdio/client/formula.py

Lines changed: 26 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -15,42 +15,48 @@
1515
# limitations under the License.
1616
#
1717

18-
import json
19-
20-
from .http import HttpMixin, endpoint
18+
from .http import HttpMixin, get, post, delete
2119

2220

2321
class FormulaMixin(HttpMixin):
24-
@endpoint("formulas/")
25-
def import_formula(self, formula_uri, public=True):
22+
@post('formulas/')
23+
def import_formula(self, formula_uri, git_username=None, git_password=None, access_token=None):
2624
"""Import a formula"""
2725
data = {
28-
"uri": formula_uri,
29-
"public": public,
26+
'uri': formula_uri,
3027
}
31-
return self._post(endpoint, data=json.dumps(data), jsonify=True)
3228

33-
@endpoint("formulas/")
29+
if git_username:
30+
data['git_username'] = git_username
31+
data['git_password'] = git_password
32+
data['access_token'] = False
33+
elif access_token:
34+
data['git_username'] = access_token
35+
data['access_token'] = True
36+
37+
return data
38+
39+
@get('formulas/', paginate=True)
3440
def list_formulas(self):
3541
"""Return all formulas"""
36-
return self._get(endpoint, jsonify=True)['results']
42+
pass
3743

38-
@endpoint("formulas/{formula_id}/")
39-
def get_formula(self, formula_id, none_on_404=False):
44+
@get('formulas/{formula_id}/')
45+
def get_formula(self, formula_id):
4046
"""Get a formula with matching id"""
41-
return self._get(endpoint, jsonify=True, none_on_404=none_on_404)
47+
pass
4248

43-
@endpoint("formulas/")
49+
@get('formulas/', paginate=True)
4450
def search_formulas(self, **kwargs):
4551
"""Get a formula with matching id"""
46-
return self._get(endpoint, params=kwargs, jsonify=True)['results']
52+
pass
4753

48-
@endpoint("formulas/{formula_id}/")
54+
@delete('formulas/{formula_id}/')
4955
def delete_formula(self, formula_id):
5056
"""Delete formula with matching id"""
51-
return self._delete(endpoint, jsonify=True)
57+
pass
5258

53-
@endpoint("formulas/{formula_id}/action/")
59+
@post('formulas/{formula_id}/action/')
5460
def update_formula(self, formula_id):
55-
"""Delete formula with matching id"""
56-
return self._post(endpoint, json.dumps({"action": "update"}), jsonify=True)
61+
"""Update the formula"""
62+
return {"action": "update"}

0 commit comments

Comments
 (0)