Add docstring for create/update methods([h-q]*)

As we discussed on
http://lists.openstack.org/pipermail/openstack-dev/2015-July/068864.html
we need to write docstring for http POST/PUT methods.
This patch adds docstring for create/update methods of compute client
[h-q]*. In addition, this patch fixes some inconsistencies like "Creates"
is changed to "Create".

Change-Id: I7c96053f0389b31b6321f0290a210a132862c90e
This commit is contained in:
Ken'ichi Ohmichi 2015-12-02 01:52:29 +00:00
parent f3af1ab54a
commit 2921aab783
7 changed files with 62 additions and 17 deletions

View File

@ -22,7 +22,7 @@ from tempest_lib.common import rest_client
class HostsClient(rest_client.RestClient):
def list_hosts(self, **params):
"""Lists all hosts."""
"""List all hosts."""
url = 'os-hosts'
if params:
@ -42,7 +42,11 @@ class HostsClient(rest_client.RestClient):
return rest_client.ResponseBody(resp, body)
def update_host(self, hostname, **kwargs):
"""Update a host."""
"""Update a host.
Available params: see http://developer.openstack.org/
api-ref-compute-v2.1.html#enablehost
"""
request_body = {
'status': None,
@ -73,7 +77,7 @@ class HostsClient(rest_client.RestClient):
return rest_client.ResponseBody(resp, body)
def reboot_host(self, hostname):
"""reboot a host."""
"""Reboot a host."""
resp, body = self.get("os-hosts/%s/reboot" % hostname)
body = json.loads(body)

View File

@ -24,7 +24,11 @@ from tempest_lib import exceptions as lib_exc
class ImagesClient(rest_client.RestClient):
def create_image(self, server_id, **kwargs):
"""Creates an image of the original server."""
"""Create an image of the original server.
Available params: see http://developer.openstack.org/
api-ref-compute-v2.1.html#createImage
"""
post_body = {'createImage': kwargs}
post_body = json.dumps(post_body)
@ -34,7 +38,11 @@ class ImagesClient(rest_client.RestClient):
return rest_client.ResponseBody(resp, body)
def list_images(self, detail=False, **params):
"""Returns a list of all images filtered by any parameters."""
"""Return a list of all images filtered by any parameter.
Available params: see http://developer.openstack.org/
api-ref-compute-v2.1.html#listImages
"""
url = 'images'
_schema = schema.list_images
if detail:
@ -50,7 +58,7 @@ class ImagesClient(rest_client.RestClient):
return rest_client.ResponseBody(resp, body)
def show_image(self, image_id):
"""Returns the details of a single image."""
"""Return the details of a single image."""
resp, body = self.get("images/%s" % image_id)
self.expected_success(200, resp.status)
body = json.loads(body)
@ -58,20 +66,24 @@ class ImagesClient(rest_client.RestClient):
return rest_client.ResponseBody(resp, body)
def delete_image(self, image_id):
"""Deletes the provided image."""
"""Delete the provided image."""
resp, body = self.delete("images/%s" % image_id)
self.validate_response(schema.delete, resp, body)
return rest_client.ResponseBody(resp, body)
def list_image_metadata(self, image_id):
"""Lists all metadata items for an image."""
"""List all metadata items for an image."""
resp, body = self.get("images/%s/metadata" % image_id)
body = json.loads(body)
self.validate_response(schema.image_metadata, resp, body)
return rest_client.ResponseBody(resp, body)
def set_image_metadata(self, image_id, meta):
"""Sets the metadata for an image."""
"""Set the metadata for an image.
Available params: see http://developer.openstack.org/
api-ref-compute-v2.1.html#createImageMetadata
"""
post_body = json.dumps({'metadata': meta})
resp, body = self.put('images/%s/metadata' % image_id, post_body)
body = json.loads(body)
@ -79,7 +91,11 @@ class ImagesClient(rest_client.RestClient):
return rest_client.ResponseBody(resp, body)
def update_image_metadata(self, image_id, meta):
"""Updates the metadata for an image."""
"""Update the metadata for an image.
Available params: see http://developer.openstack.org/
api-ref-compute-v2.1.html#updateImageMetadata
"""
post_body = json.dumps({'metadata': meta})
resp, body = self.post('images/%s/metadata' % image_id, post_body)
body = json.loads(body)
@ -87,14 +103,18 @@ class ImagesClient(rest_client.RestClient):
return rest_client.ResponseBody(resp, body)
def show_image_metadata_item(self, image_id, key):
"""Returns the value for a specific image metadata key."""
"""Return the value for a specific image metadata key."""
resp, body = self.get("images/%s/metadata/%s" % (image_id, key))
body = json.loads(body)
self.validate_response(schema.image_meta_item, resp, body)
return rest_client.ResponseBody(resp, body)
def set_image_metadata_item(self, image_id, key, meta):
"""Sets the value for a specific image metadata key."""
"""Set the value for a specific image metadata key.
Available params: see http://developer.openstack.org/
api-ref-compute-v2.1.html#setImageMetadataItem
"""
post_body = json.dumps({'meta': meta})
resp, body = self.put('images/%s/metadata/%s' % (image_id, key),
post_body)
@ -103,7 +123,7 @@ class ImagesClient(rest_client.RestClient):
return rest_client.ResponseBody(resp, body)
def delete_image_metadata_item(self, image_id, key):
"""Deletes a single image metadata key/value pair."""
"""Delete a single image metadata key/value pair."""
resp, body = self.delete("images/%s/metadata/%s" %
(image_id, key))
self.validate_response(schema.delete, resp, body)
@ -118,5 +138,5 @@ class ImagesClient(rest_client.RestClient):
@property
def resource_type(self):
"""Returns the primary type of resource this client works with."""
"""Return the primary type of resource this client works with."""
return 'image'

View File

@ -28,6 +28,11 @@ class InterfacesClient(rest_client.RestClient):
return rest_client.ResponseBody(resp, body)
def create_interface(self, server_id, **kwargs):
"""Create an interface.
Available params: see http://developer.openstack.org/
api-ref-compute-v2.1.html#createAttachInterface
"""
post_body = {'interfaceAttachment': kwargs}
post_body = json.dumps(post_body)
resp, body = self.post('servers/%s/os-interface' % server_id,

View File

@ -34,6 +34,11 @@ class KeyPairsClient(rest_client.RestClient):
return rest_client.ResponseBody(resp, body)
def create_keypair(self, **kwargs):
"""Create a keypair.
Available params: see http://developer.openstack.org/
api-ref-compute-v2.1.html#createKeypair
"""
post_body = json.dumps({'keypair': kwargs})
resp, body = self.post("os-keypairs", body=post_body)
body = json.loads(body)

View File

@ -22,7 +22,11 @@ from tempest_lib.common import rest_client
class MigrationsClient(rest_client.RestClient):
def list_migrations(self, **params):
"""Lists all migrations."""
"""List all migrations.
Available params: see http://developer.openstack.org/
api-ref-compute-v2.1.html#returnmigrations
"""
url = 'os-migrations'
if params:

View File

@ -32,8 +32,11 @@ class QuotaClassesClient(rest_client.RestClient):
return rest_client.ResponseBody(resp, body)
def update_quota_class_set(self, quota_class_id, **kwargs):
"""Updates the quota class's limits for one or more resources."""
"""Update the quota class's limits for one or more resources.
Available params: see http://developer.openstack.org/
api-ref-compute-v2.1.html#updatequota
"""
post_body = json.dumps({'quota_class_set': kwargs})
resp, body = self.put('os-quota-class-sets/%s' % quota_class_id,

View File

@ -42,7 +42,11 @@ class QuotasClient(rest_client.RestClient):
return rest_client.ResponseBody(resp, body)
def update_quota_set(self, tenant_id, user_id=None, **kwargs):
"""Updates the tenant's quota limits for one or more resources"""
"""Updates the tenant's quota limits for one or more resources.
Available params: see http://developer.openstack.org/
api-ref-compute-v2.1.html#updatesquotatenant
"""
post_body = json.dumps({'quota_set': kwargs})