Update contrib docstrings to match guidelines

Per http://docs.openstack.org/developer/hacking/
and http://www.python.org/dev/peps/pep-0257/

Without extra blank line in multi-line docstrings
based on http://lists.openstack.org/pipermail/openstack-dev/2014-February/028156.html

Blueprint: reduce-flake8-ignored-rules

Change-Id: I0050d382369d3013280f3d90df87fb530bc6c939
This commit is contained in:
Ziad Sawalha 2014-02-12 15:29:29 -06:00 committed by Gerrit Code Review
parent 5b57317e98
commit bbb41bfa5b
7 changed files with 67 additions and 64 deletions

View File

@ -13,6 +13,8 @@
# License for the specific language governing permissions and limitations # License for the specific language governing permissions and limitations
# under the License. # under the License.
"""Client Library for Keystone Resources."""
from keystoneclient.v2_0 import client as kc from keystoneclient.v2_0 import client as kc
from oslo.config import cfg from oslo.config import cfg
@ -26,13 +28,14 @@ logger.info(_("Keystone V2 loaded"))
class KeystoneClientV2(object): class KeystoneClientV2(object):
"""
Wrap keystone client so we can encapsulate logic used in resources """Wrap keystone client so we can encapsulate logic used in resources.
Note this is intended to be initialized from a resource on a per-session Note this is intended to be initialized from a resource on a per-session
basis, so the session context is passed in on initialization basis, so the session context is passed in on initialization
Also note that a copy of this is created every resource as self.keystone() Also note that a copy of this is created every resource as self.keystone()
via the code in engine/client.py, so there should not be any need to via the code in engine/client.py, so there should not be any need to
directly instantiate instances of this class inside resources themselves directly instantiate instances of this class inside resources themselves.
""" """
def __init__(self, context): def __init__(self, context):
# If a trust_id is specified in the context, we immediately # If a trust_id is specified in the context, we immediately

View File

@ -11,6 +11,8 @@
# License for the specific language governing permissions and limitations # License for the specific language governing permissions and limitations
# under the License. # under the License.
"""Client Library for Marconi Resources."""
from heat.engine import clients from heat.engine import clients
from heat.openstack.common import log as logging from heat.openstack.common import log as logging
@ -24,9 +26,9 @@ except ImportError:
class Clients(clients.OpenStackClients): class Clients(clients.OpenStackClients):
'''
Convenience class to create and cache client instances. """Convenience class to create and cache client instances."""
'''
def __init__(self, context): def __init__(self, context):
super(Clients, self).__init__(context) super(Clients, self).__init__(context)
self._marconi = None self._marconi = None

View File

@ -70,9 +70,7 @@ class MarconiQueue(resource.Resource):
return self.properties[self.NAME] return self.properties[self.NAME]
def handle_create(self): def handle_create(self):
''' """Create a marconi message queue."""
Create a marconi message queue.
'''
queue_name = self.physical_resource_name() queue_name = self.physical_resource_name()
queue = self.marconi().queue(queue_name, auto_create=False) queue = self.marconi().queue(queue_name, auto_create=False)
# Marconi client doesn't report an error if an queue with the same # Marconi client doesn't report an error if an queue with the same
@ -85,7 +83,7 @@ class MarconiQueue(resource.Resource):
return queue return queue
def check_create_complete(self, queue): def check_create_complete(self, queue):
# set metadata of the newly created queue """Set metadata of the newly created queue."""
if queue.exists(): if queue.exists():
metadata = self.properties.get('metadata') metadata = self.properties.get('metadata')
if metadata: if metadata:
@ -97,18 +95,14 @@ class MarconiQueue(resource.Resource):
% queue_name) % queue_name)
def handle_update(self, json_snippet, tmpl_diff, prop_diff): def handle_update(self, json_snippet, tmpl_diff, prop_diff):
''' """Update queue metadata."""
Update queue metadata.
'''
if 'metadata' in prop_diff: if 'metadata' in prop_diff:
queue = self.marconi().queue(self.resource_id, auto_create=False) queue = self.marconi().queue(self.resource_id, auto_create=False)
metadata = prop_diff['metadata'] metadata = prop_diff['metadata']
queue.metadata(new_meta=metadata) queue.metadata(new_meta=metadata)
def handle_delete(self): def handle_delete(self):
''' """Delete a marconi message queue."""
Delete a marconi message queue.
'''
if not self.resource_id: if not self.resource_id:
return return

View File

@ -12,6 +12,8 @@
# License for the specific language governing permissions and limitations # License for the specific language governing permissions and limitations
# under the License. # under the License.
"""Client Libraries for Rackspace Resources."""
from oslo.config import cfg from oslo.config import cfg
from heat.common import exception from heat.common import exception
@ -46,9 +48,9 @@ cfg.CONF.register_opts(cloud_opts)
class Clients(clients.OpenStackClients): class Clients(clients.OpenStackClients):
'''
Convenience class to create and cache client instances. """Convenience class to create and cache client instances."""
'''
def __init__(self, context): def __init__(self, context):
super(Clients, self).__init__(context) super(Clients, self).__init__(context)
self.pyrax = None self.pyrax = None
@ -63,32 +65,34 @@ class Clients(clients.OpenStackClients):
return self._get_client("autoscale") return self._get_client("autoscale")
def cloud_db(self): def cloud_db(self):
'''Rackspace cloud database client.''' """Rackspace cloud database client."""
return self._get_client("database") return self._get_client("database")
def cloud_lb(self): def cloud_lb(self):
'''Rackspace cloud loadbalancer client.''' """Rackspace cloud loadbalancer client."""
return self._get_client("load_balancer") return self._get_client("load_balancer")
def cloud_dns(self): def cloud_dns(self):
'''Rackspace cloud dns client.''' """Rackspace cloud dns client."""
return self._get_client("dns") return self._get_client("dns")
def nova(self, service_type="compute"): def nova(self, service_type="compute"):
'''Rackspace cloudservers client. Specifying the service type is to """Rackspace cloudservers client.
Specifying the service type is to
maintain compatibility with clients.OpenStackClients. It is not maintain compatibility with clients.OpenStackClients. It is not
actually a valid option to change within pyrax. actually a valid option to change within pyrax.
''' """
if service_type is not "compute": if service_type is not "compute":
raise ValueError(_("service_type should be compute.")) raise ValueError(_("service_type should be compute."))
return self._get_client(service_type) return self._get_client(service_type)
def cloud_networks(self): def cloud_networks(self):
'''Rackspace cloud networks client.''' """Rackspace cloud networks client."""
return self._get_client("network") return self._get_client("network")
def trove(self): def trove(self):
'''Rackspace trove client.''' """Rackspace trove client."""
if not self._trove: if not self._trove:
super(Clients, self).trove(service_type='rax:database') super(Clients, self).trove(service_type='rax:database')
management_url = self.url_for(service_type='rax:database', management_url = self.url_for(service_type='rax:database',

View File

@ -11,9 +11,7 @@
# License for the specific language governing permissions and limitations # License for the specific language governing permissions and limitations
# under the License. # under the License.
""" """Resources for Rackspace Auto Scale."""
Resources for Rackspace Auto Scale.
"""
import copy import copy
@ -38,6 +36,7 @@ except ImportError:
class Group(resource.Resource): class Group(resource.Resource):
"""Represents a scaling group.""" """Represents a scaling group."""
# pyrax differs drastically from the actual Auto Scale API. We'll prefer # pyrax differs drastically from the actual Auto Scale API. We'll prefer
@ -302,18 +301,16 @@ class Group(resource.Resource):
return args return args
def handle_create(self): def handle_create(self):
""" """Create the autoscaling group and set resource_id.
Create the autoscaling group and set the resulting group's ID as the
resource_id. The resource_id is set to the resulting group's ID.
""" """
asclient = self.stack.clients.auto_scale() asclient = self.stack.clients.auto_scale()
group = asclient.create(**self._get_create_args()) group = asclient.create(**self._get_create_args())
self.resource_id_set(str(group.id)) self.resource_id_set(str(group.id))
def handle_update(self, json_snippet, tmpl_diff, prop_diff): def handle_update(self, json_snippet, tmpl_diff, prop_diff):
""" """Update the group configuration and the launch configuration."""
Update the group configuration and the launch configuration.
"""
asclient = self.stack.clients.auto_scale() asclient = self.stack.clients.auto_scale()
if self.GROUP_CONFIGURATION in prop_diff: if self.GROUP_CONFIGURATION in prop_diff:
args = self._get_group_config_args( args = self._get_group_config_args(
@ -325,8 +322,7 @@ class Group(resource.Resource):
asclient.replace_launch_config(self.resource_id, **args) asclient.replace_launch_config(self.resource_id, **args)
def handle_delete(self): def handle_delete(self):
""" """Delete the scaling group.
Delete the scaling group.
Since Auto Scale doesn't allow deleting a group until all its servers Since Auto Scale doesn't allow deleting a group until all its servers
are gone, we must set the minEntities and maxEntities of the group to 0 are gone, we must set the minEntities and maxEntities of the group to 0
@ -360,6 +356,7 @@ class Group(resource.Resource):
class ScalingPolicy(resource.Resource): class ScalingPolicy(resource.Resource):
"""Represents a Rackspace Auto Scale scaling policy.""" """Represents a Rackspace Auto Scale scaling policy."""
PROPERTIES = ( PROPERTIES = (
@ -444,9 +441,9 @@ class ScalingPolicy(resource.Resource):
return args return args
def handle_create(self): def handle_create(self):
""" """Create the scaling policy and initialize the resource ID.
Create the scaling policy, and initialize the resource ID to
{group_id}:{policy_id}. The resource ID is initialized to {group_id}:{policy_id}.
""" """
asclient = self.stack.clients.auto_scale() asclient = self.stack.clients.auto_scale()
args = self._get_args(self.properties) args = self._get_args(self.properties)
@ -476,11 +473,12 @@ class ScalingPolicy(resource.Resource):
class WebHook(resource.Resource): class WebHook(resource.Resource):
"""
Represents a Rackspace AutoScale webhook. """Represents a Rackspace AutoScale webhook.
Exposes the URLs of the webhook as attributes. Exposes the URLs of the webhook as attributes.
""" """
PROPERTIES = ( PROPERTIES = (
POLICY, NAME, METADATA, POLICY, NAME, METADATA,
) = ( ) = (

View File

@ -10,6 +10,8 @@
# License for the specific language governing permissions and limitations # License for the specific language governing permissions and limitations
# under the License. # under the License.
"""Resources for Rackspace DNS."""
from heat.common import exception from heat.common import exception
from heat.engine import constraints from heat.engine import constraints
from heat.engine import properties from heat.engine import properties
@ -32,6 +34,8 @@ logger = logging.getLogger(__name__)
class CloudDns(resource.Resource): class CloudDns(resource.Resource):
"""Represents a DNS resource."""
PROPERTIES = ( PROPERTIES = (
NAME, EMAIL_ADDRESS, TTL, COMMENT, RECORDS, NAME, EMAIL_ADDRESS, TTL, COMMENT, RECORDS,
) = ( ) = (
@ -147,9 +151,7 @@ class CloudDns(resource.Resource):
return self.stack.clients.cloud_dns() return self.stack.clients.cloud_dns()
def handle_create(self): def handle_create(self):
""" """Create a Rackspace CloudDns Instance."""
Create a Rackspace CloudDns Instance.
"""
# There is no check_create_complete as the pyrax create for DNS is # There is no check_create_complete as the pyrax create for DNS is
# synchronous. # synchronous.
logger.debug(_("CloudDns handle_create called.")) logger.debug(_("CloudDns handle_create called."))
@ -163,9 +165,7 @@ class CloudDns(resource.Resource):
self.resource_id_set(dom.id) self.resource_id_set(dom.id)
def handle_update(self, json_snippet, tmpl_diff, prop_diff): def handle_update(self, json_snippet, tmpl_diff, prop_diff):
""" """Update a Rackspace CloudDns Instance."""
Update a Rackspace CloudDns Instance.
"""
logger.debug(_("CloudDns handle_update called.")) logger.debug(_("CloudDns handle_update called."))
if not self.resource_id: if not self.resource_id:
raise exception.Error(_('Update called on a non-existent domain')) raise exception.Error(_('Update called on a non-existent domain'))
@ -188,9 +188,7 @@ class CloudDns(resource.Resource):
dom.add_records(records) dom.add_records(records)
def handle_delete(self): def handle_delete(self):
""" """Delete a Rackspace CloudDns Instance."""
Delete a Rackspace CloudDns Instance.
"""
logger.debug(_("CloudDns handle_delete called.")) logger.debug(_("CloudDns handle_delete called."))
if self.resource_id: if self.resource_id:
try: try:

View File

@ -10,6 +10,9 @@
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations # License for the specific language governing permissions and limitations
# under the License. # under the License.
"""Resources for Rackspace Cloud Loadbalancers."""
try: try:
from pyrax.exceptions import NotFound from pyrax.exceptions import NotFound
PYRAX_INSTALLED = True PYRAX_INSTALLED = True
@ -41,6 +44,8 @@ class LoadbalancerBuildError(exception.HeatException):
class CloudLoadBalancer(resource.Resource): class CloudLoadBalancer(resource.Resource):
"""Represents a Rackspace Cloud Loadbalancer."""
PROPERTIES = ( PROPERTIES = (
NAME, NODES, PROTOCOL, ACCESS_LIST, HALF_CLOSED, ALGORITHM, NAME, NODES, PROTOCOL, ACCESS_LIST, HALF_CLOSED, ALGORITHM,
CONNECTION_LOGGING, METADATA, PORT, TIMEOUT, CONNECTION_LOGGING, METADATA, PORT, TIMEOUT,
@ -378,7 +383,9 @@ class CloudLoadBalancer(resource.Resource):
return [function()] return [function()]
def _alter_properties_for_api(self): def _alter_properties_for_api(self):
"""The following properties have usless key/value pairs which must """Set up required, but useless, key/value pairs.
The following properties have useless key/value pairs which must
be passed into the api. Set them up to make template definition easier. be passed into the api. Set them up to make template definition easier.
""" """
session_persistence = None session_persistence = None
@ -405,8 +412,9 @@ class CloudLoadBalancer(resource.Resource):
return False return False
def _configure_post_creation(self, loadbalancer): def _configure_post_creation(self, loadbalancer):
"""Configure all load balancer properties that must be done post """Configure all load balancer properties post creation.
creation.
These properties can only be set after the load balancer is created.
""" """
if self.properties[self.ACCESS_LIST]: if self.properties[self.ACCESS_LIST]:
while not self._check_status(loadbalancer, ['ACTIVE']): while not self._check_status(loadbalancer, ['ACTIVE']):
@ -492,9 +500,7 @@ class CloudLoadBalancer(resource.Resource):
return self._check_status(loadbalancer, ['ACTIVE']) return self._check_status(loadbalancer, ['ACTIVE'])
def handle_update(self, json_snippet, tmpl_diff, prop_diff): def handle_update(self, json_snippet, tmpl_diff, prop_diff):
""" """Add and remove nodes specified in the prop_diff."""
Add and remove nodes specified in the prop_diff.
"""
loadbalancer = self.clb.get(self.resource_id) loadbalancer = self.clb.get(self.resource_id)
if self.NODES in prop_diff: if self.NODES in prop_diff:
current_nodes = loadbalancer.nodes current_nodes = loadbalancer.nodes
@ -556,18 +562,16 @@ class CloudLoadBalancer(resource.Resource):
self.resource_id_set(None) self.resource_id_set(None)
def _remove_none(self, property_dict): def _remove_none(self, property_dict):
''' """Remove None values that would cause schema validation problems.
Remove values that may be initialized to None and would cause problems
during schema validation. These are values that may be initialized to None.
''' """
return dict((key, value) return dict((key, value)
for (key, value) in property_dict.iteritems() for (key, value) in property_dict.iteritems()
if value) if value)
def validate(self): def validate(self):
""" """Validate any of the provided params."""
Validate any of the provided params
"""
res = super(CloudLoadBalancer, self).validate() res = super(CloudLoadBalancer, self).validate()
if res: if res:
return res return res