Skip to content

Commit 0bc763b

Browse files
author
Gabriel Monroy
committed
Merge pull request #185 from opdemand/176-provider-docstrings
Fixed #176 -- added docstrings for provider modules.
2 parents 0f0fdb4 + 99da003 commit 0bc763b

2 files changed

Lines changed: 69 additions & 3 deletions

File tree

provider/ec2.py

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
"""
2+
Deis cloud provider implementation for Amazon EC2.
3+
"""
14

25
from __future__ import unicode_literals
36

@@ -26,9 +29,9 @@
2629

2730

2831
def seed_flavors():
29-
"""Seed the database with default Flavors for each EC2 region.
32+
"""Seed the database with default flavors for each EC2 region.
3033
31-
:rtype: list of dicts containing Flavor data
34+
:rtype: list of dicts containing flavor data
3235
"""
3336
flavors = []
3437
for r in ('us-east-1', 'us-west-1', 'us-west-2', 'eu-west-1',
@@ -45,6 +48,11 @@ def seed_flavors():
4548

4649

4750
def build_layer(layer):
51+
"""
52+
Build a layer.
53+
54+
:param layer: a dict containing formation, id, params, and creds info
55+
"""
4856
region = layer['params'].get('region', 'us-east-1')
4957
conn = _create_ec2_connection(layer['creds'], region)
5058
# create a new sg and authorize all ports
@@ -68,6 +76,11 @@ def build_layer(layer):
6876

6977

7078
def destroy_layer(layer):
79+
"""
80+
Destroy a layer.
81+
82+
:param layer: a dict containing formation, id, params, and creds info
83+
"""
7184
region = layer['params'].get('region', 'us-east-1')
7285
name = "{formation}-{id}".format(**layer)
7386
conn = _create_ec2_connection(layer['creds'], region)
@@ -84,6 +97,12 @@ def destroy_layer(layer):
8497

8598

8699
def build_node(node):
100+
"""
101+
Build a node.
102+
103+
:param node: a dict containing formation, layer, params, and creds info.
104+
:rtype: a tuple of (provider_id, fully_qualified_domain_name, metadata)
105+
"""
87106
params, creds = node['params'], node['creds']
88107
region = params.setdefault('region', 'us-east-1')
89108
conn = _create_ec2_connection(creds, region)
@@ -119,6 +138,11 @@ def build_node(node):
119138

120139

121140
def destroy_node(node):
141+
"""
142+
Destroy a node.
143+
144+
:param node: a dict containing a node's provider_id, params, and creds
145+
"""
122146
provider_id = node['provider_id']
123147
region = node['params'].get('region', 'us-east-1')
124148
conn = _create_ec2_connection(node['creds'], region)
@@ -133,6 +157,14 @@ def destroy_node(node):
133157

134158

135159
def _create_ec2_connection(creds, region):
160+
"""
161+
Connect to an EC2 region with the given credentials.
162+
163+
:param creds: a dict containing an EC2 access_key and secret_key
164+
:region: the name of an EC2 region, such as "us-west-2"
165+
:rtype: a connected :class:`~boto.ec2.connection.EC2Connection`
166+
:raises EnvironmentError: if no credentials are provided
167+
"""
136168
if not creds:
137169
raise EnvironmentError('No credentials provided')
138170
return ec2.connect_to_region(region,

provider/mock.py

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,16 @@
1+
"""
2+
Deis mock cloud provider implementation for testing.
3+
"""
14

25
from __future__ import unicode_literals
36

47

58
def seed_flavors():
6-
"""Seed the database with default Flavors for the mock provider"""
9+
"""
10+
Seed the database with default flavors for the mock provider.
11+
12+
:rtype: list of dicts containing flavor data
13+
"""
714
flavors = []
815
for r in ('east', 'west'):
916
flavors.append({'id': 'mock-{}'.format(r),
@@ -13,19 +20,46 @@ def seed_flavors():
1320

1421

1522
def build_layer(layer):
23+
"""
24+
Build a layer.
25+
26+
This function is a no-op for the mock provider.
27+
28+
:param layer: a dict containing formation, id, params, and creds info
29+
"""
1630
return
1731

1832

1933
def destroy_layer(layer):
34+
"""
35+
Destroy a layer.
36+
37+
This function is a no-op for the mock provider.
38+
39+
:param layer: a dict containing formation, id, params, and creds info
40+
"""
2041
return
2142

2243

2344
def build_node(node):
45+
"""
46+
Build a node.
47+
48+
:param node: a dict containing formation, layer, params, and creds info.
49+
:rtype: a tuple of (provider_id, fully_qualified_domain_name, metadata)
50+
"""
2451
provider_id = 'i-1234567'
2552
fqdn = 'localhost.localdomain.local'
2653
metadata = {'state': 'running'}
2754
return provider_id, fqdn, metadata
2855

2956

3057
def destroy_node(node):
58+
"""
59+
Destroy a node.
60+
61+
This function is a no-op for the mock provider.
62+
63+
:param node: a dict containing a node's provider_id, params, and creds
64+
"""
3165
return

0 commit comments

Comments
 (0)