Skip to content

Commit 7e3b417

Browse files
author
Clark Perkins
committed
Update for stackdio 0.7
1 parent 56003d6 commit 7e3b417

File tree

7 files changed

+112
-120
lines changed

7 files changed

+112
-120
lines changed

requirements.txt

Lines changed: 0 additions & 2 deletions
This file was deleted.

setup.py

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

18-
import os
1918
import sys
2019

2120
from setuptools import setup, find_packages
22-
from pip.req import parse_requirements
23-
from pip.download import PipSession
2421

2522

2623
def test_python_version():
27-
if float("%d.%d" % sys.version_info[:2]) < 2.6:
28-
print('Your Python version {0}.{1}.{2} is not supported.'.format(
29-
*sys.version_info[:3]))
30-
print('stackdio requires Python 2.6 or newer.')
24+
major = sys.version_info[0]
25+
minor = sys.version_info[1]
26+
micro = sys.version_info[2]
27+
if float('%d.%d' % (major, minor)) < 2.6:
28+
err_msg = ('Your Python version {0}.{1}.{2} is not supported.\n'
29+
'stackdio-server requires Python 2.6 or newer.\n'.format(major, minor, micro))
30+
sys.stderr.write(err_msg)
3131
sys.exit(1)
3232

33-
34-
def load_pip_requirements(fp):
35-
reqs, deps = [], []
36-
for r in parse_requirements(fp, session=PipSession()):
37-
if r.url is not None:
38-
deps.append(str(r.url))
39-
reqs.append(str(r.req))
40-
return reqs, deps
41-
4233
# Set version
4334
__version__ = '0.0.0' # Explicit default
44-
execfile("stackdio/client/version.py")
35+
execfile('stackdio/client/version.py')
4536

4637

4738
SHORT_DESCRIPTION = ('A cloud deployment, automation, and orchestration '
4839
'platform for everyone.')
49-
LONG_DESCRIPTION = SHORT_DESCRIPTION
5040

51-
# If we have a README.md file, use its contents as the long description
52-
if os.path.isfile('README.md'):
53-
with open('README.md') as f:
54-
LONG_DESCRIPTION = f.read()
41+
# Use the README.md as the long description
42+
with open('README.md') as f:
43+
LONG_DESCRIPTION = f.read()
5544

45+
requirements = [
46+
'simplejson',
47+
'requests>=2.4.0,<2.6.0',
48+
]
5649

5750
if __name__ == "__main__":
58-
# build our list of requirements and dependency links based on our
59-
# requirements.txt file
60-
reqs, deps = load_pip_requirements('requirements.txt')
51+
test_python_version()
6152

6253
# Call the setup method from setuptools that does all the heavy lifting
63-
# of packaging stackdio
54+
# of packaging stackdio-client
6455
setup(
65-
name='stackdio',
56+
name='stackdio-client',
6657
version=__version__,
6758
url='http://stackd.io',
6859
author='Digital Reasoning Systems, Inc.',
@@ -73,8 +64,8 @@ def load_pip_requirements(fp):
7364
include_package_data=True,
7465
packages=find_packages(),
7566
zip_safe=False,
76-
install_requires=reqs,
77-
dependency_links=deps,
67+
install_requires=requirements,
68+
dependency_links=[],
7869
classifiers=[
7970
'Development Status :: 3 - Alpha',
8071
'Environment :: Web Environment',
@@ -84,6 +75,7 @@ def load_pip_requirements(fp):
8475
'Intended Audience :: System Administrators',
8576
'License :: OSI Approved :: Apache Software License',
8677
'Programming Language :: Python',
78+
'Programming Language :: Python :: 2',
8779
'Programming Language :: Python :: 2.6',
8880
'Programming Language :: Python :: 2.7',
8981
'Topic :: System :: Clustering',

stackdio/client/__init__.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@
2323

2424
from .blueprint import BlueprintMixin
2525
from .formula import FormulaMixin
26-
from .profile import ProfileMixin
27-
from .provider import ProviderMixin
26+
from .account import AccountMixin
27+
from .image import ImageMixin
2828
from .region import RegionMixin
2929
from .settings import SettingsMixin
3030
from .stack import StackMixin
@@ -34,8 +34,8 @@
3434
logger = logging.getLogger(__name__)
3535

3636

37-
class StackdIO(BlueprintMixin, FormulaMixin, ProfileMixin,
38-
ProviderMixin, RegionMixin, StackMixin, SettingsMixin):
37+
class StackdIO(BlueprintMixin, FormulaMixin, AccountMixin,
38+
ImageMixin, RegionMixin, StackMixin, SettingsMixin):
3939

4040
def __init__(self, protocol="https", host="localhost", port=443,
4141
base_url=None, auth=None, auth_admin=None,
Lines changed: 33 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -22,44 +22,41 @@
2222
from .version import accepted_versions, deprecated
2323

2424

25-
class ProviderMixin(HttpMixin):
25+
class AccountMixin(HttpMixin):
2626

27-
@endpoint("provider_types/")
28-
def list_provider_types(self):
27+
@endpoint("cloud/providers/")
28+
def list_providers(self):
2929
"""List all providers"""
3030
return self._get(endpoint, jsonify=True)['results']
3131

32-
3332
@accepted_versions(">=0.6.1")
34-
@endpoint("provider_types/")
35-
def search_provider_types(self, provider_id):
36-
"""List all provider_types"""
33+
@endpoint("cloud/providers/")
34+
def search_providers(self, provider_id):
35+
"""List all providers"""
3736
return self._get(endpoint, jsonify=True)['results']
3837

39-
4038
@deprecated
4139
@accepted_versions("<0.7")
42-
@endpoint("provider_types/")
43-
def get_provider_type_id(self, type_name):
40+
@endpoint("cloud/providers/")
41+
def get_provider_id(self, type_name):
4442
"""Get the id for the provider specified by type_name"""
4543

4644
result = self._get(endpoint, jsonify=True)
47-
for provider_type in result['results']:
48-
if provider_type.get("type_name") == type_name:
49-
return provider_type.get("id")
45+
for provider in result['results']:
46+
if provider.get("type_name") == type_name:
47+
return provider.get("id")
5048

5149
raise StackException("Provider type %s not found" % type_name)
5250

53-
5451
@use_admin_auth
55-
@endpoint("providers/")
56-
def create_provider(self, **kwargs):
57-
"""Create a provider"""
52+
@endpoint("cloud/accounts/")
53+
def create_account(self, **kwargs):
54+
"""Create an account"""
5855

5956
form_data = {
6057
"title": None,
6158
"account_id": None,
62-
"provider_type": None,
59+
"provider": None,
6360
"access_key_id": None,
6461
"secret_access_key": None,
6562
"keypair": None,
@@ -74,42 +71,37 @@ def create_provider(self, **kwargs):
7471

7572
return self._post(endpoint, data=json.dumps(form_data), jsonify=True)
7673

77-
78-
@endpoint("providers/")
79-
def list_providers(self):
80-
"""List all providers"""
74+
@endpoint("accounts/")
75+
def list_accounts(self):
76+
"""List all account"""
8177
return self._get(endpoint, jsonify=True)['results']
8278

83-
84-
@endpoint("providers/{provider_id}/")
85-
def get_provider(self, provider_id, none_on_404=False):
86-
"""Return the provider that matches the given id"""
79+
@endpoint("accounts/{account_id}/")
80+
def get_account(self, account_id, none_on_404=False):
81+
"""Return the account that matches the given id"""
8782
return self._get(endpoint, jsonify=True, none_on_404=none_on_404)
8883

89-
9084
@accepted_versions(">=0.6.1")
91-
@endpoint("providers/")
92-
def search_providers(self, provider_id):
93-
"""List all providers"""
85+
@endpoint("accounts/")
86+
def search_accounts(self, account_id):
87+
"""List all accounts"""
9488
return self._get(endpoint, jsonify=True)['results']
9589

96-
97-
@endpoint("providers/{provider_id}/")
98-
def delete_provider(self, provider_id):
99-
"""List all providers"""
90+
@endpoint("accounts/{account_id}/")
91+
def delete_account(self, account_id):
92+
"""List all accounts"""
10093
return self._delete(endpoint, jsonify=True)['results']
10194

102-
10395
@deprecated
10496
@accepted_versions("<0.7")
105-
def get_provider_id(self, slug, title=False):
106-
"""Get the id for a provider that matches slug. If title is True will
97+
def get_account_id(self, slug, title=False):
98+
"""Get the id for a account that matches slug. If title is True will
10799
look at title instead."""
108100

109-
providers = self.list_providers()
101+
accounts = self.list_accounts()
110102

111-
for provider in providers:
112-
if provider.get("slug" if not title else "title") == slug:
113-
return provider.get("id")
103+
for account in accounts:
104+
if account.get("slug" if not title else "title") == slug:
105+
return account.get("id")
114106

115107
raise StackException("Provider %s not found" % slug)

stackdio/client/blueprint.py

Lines changed: 23 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -28,25 +28,33 @@ class BlueprintMixin(HttpMixin):
2828
def create_blueprint(self, blueprint, provider="ec2"):
2929
"""Create a blueprint"""
3030

31-
# check the provided blueprint to see if we need to look up any ids
32-
for host in blueprint["hosts"]:
33-
if isinstance(host["size"], basestring):
34-
host["size"] = self.get_instance_id(host["size"], provider)
31+
formula_map = {}
32+
33+
if 'formula_versions' in blueprint:
34+
all_formulas = self.list_formulas()
3535

36-
# zone isn't required if you provide a subnet_id
37-
if 'zone' in host and isinstance(host["zone"], basestring):
38-
host["zone"] = self.get_zone_id(host["zone"], provider)
36+
used_formulas = set()
3937

40-
if isinstance(host["cloud_profile"], basestring):
41-
host["cloud_profile"] = self.get_profile_id(host["cloud_profile"]) # noqa
38+
for formula_version in blueprint['formula_versions']:
39+
for formula in all_formulas:
40+
if formula['uri'] == formula_version['formula']:
41+
formula['version'] = formula_version['version']
42+
used_formulas.add(formula)
43+
break
4244

43-
for component in host["formula_components"]:
44-
if not component.get("sls_path") and isinstance(component["id"], (tuple, list)):
45-
formula_id = self.get_formula_id(component["id"][0])
45+
for formula in used_formulas:
46+
components = self._get(
47+
'{0}?version={1}'.format(formula['components'], formula['version']),
48+
jsonify=True,
49+
)['results']
50+
for component in components:
51+
formula_map[component['sls_path']] = formula['uri']
4652

47-
component["id"] = self.get_component_id(
48-
self.get_formula(formula_id),
49-
component["id"][1])
53+
# check the provided blueprint to see if we need to look up any ids
54+
for host in blueprint['host_definitions']:
55+
for component in host['formula_components']:
56+
if component['sls_path'] in formula_map:
57+
component['formula'] = formula_map[component['sls_path']]
5058

5159
return self._post(endpoint, data=json.dumps(blueprint), jsonify=True, raise_for_status=False)
5260

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,13 @@
2222
from .version import accepted_versions, deprecated
2323

2424

25-
class ProfileMixin(HttpMixin):
25+
class ImageMixin(HttpMixin):
2626

2727
@use_admin_auth
28-
@endpoint("profile/")
29-
def create_profile(self, title, image_id, ssh_user, cloud_provider,
28+
@endpoint("image/")
29+
def create_image(self, title, image_id, ssh_user, cloud_provider,
3030
default_instance_size=None):
31-
"""Create a profile"""
31+
"""Create a image"""
3232
data = {
3333
"title": title,
3434
"image_id": image_id,
@@ -39,40 +39,40 @@ def create_profile(self, title, image_id, ssh_user, cloud_provider,
3939
return self._post(endpoint, data=json.dumps(data), jsonify=True)
4040

4141

42-
@endpoint("profiles/")
43-
def list_profiles(self):
44-
"""List all profiles"""
42+
@endpoint("images/")
43+
def list_images(self):
44+
"""List all images"""
4545
return self._get(endpoint, jsonify=True)['results']
4646

4747

48-
@endpoint("profiles/{profile_id}/")
49-
def get_profile(self, profile_id, none_on_404=False):
50-
"""Return the profile that matches the given id"""
48+
@endpoint("images/{image_id}/")
49+
def get_image(self, image_id, none_on_404=False):
50+
"""Return the image that matches the given id"""
5151
return self._get(endpoint, jsonify=True, none_on_404=none_on_404)
5252

5353

5454
@accepted_versions(">=0.6.1")
55-
@endpoint("profiles/")
56-
def search_profiles(self, profile_id):
57-
"""List all profiles"""
55+
@endpoint("images/")
56+
def search_images(self, image_id):
57+
"""List all images"""
5858
return self._get(endpoint, jsonify=True)['results']
5959

6060

61-
@endpoint("profiles/{profile_id}/")
62-
def delete_profile(self, profile_id):
63-
"""Delete the profile with the given id"""
61+
@endpoint("images/{image_id}/")
62+
def delete_image(self, image_id):
63+
"""Delete the image with the given id"""
6464
return self._delete(endpoint, jsonify=True)['results']
6565

6666

6767
@deprecated
6868
@accepted_versions("<0.7")
69-
def get_profile_id(self, slug, title=False):
70-
"""Get the id for a profile that matches slug. If title is True will look
69+
def get_image_id(self, slug, title=False):
70+
"""Get the id for a image that matches slug. If title is True will look
7171
at title instead."""
7272

73-
profiles = self.list_profiles()
74-
for profile in profiles:
75-
if profile.get("slug" if not title else "title") == slug:
76-
return profile.get("id")
73+
images = self.list_images()
74+
for image in images:
75+
if image.get("slug" if not title else "title") == slug:
76+
return image.get("id")
7777

7878
raise StackException("Profile %s not found" % slug)

0 commit comments

Comments
 (0)