Fix k8s CLI to work with Bay name

K8s CLI especially pod/rc/service show and delete works with UUID. This
patch aims to fix k8s CLI to work with bay name as well. If needed this
patch will be ported back to stable/liberty as well.

Change-Id: I2fc9352af63cb261864be9332609603fb943a165
Closes-Bug: #1509091
This commit is contained in:
Vilobh Meshram 2015-10-22 16:28:57 -07:00 committed by Eli Qiao
parent d59d4c2465
commit f58b47fe01
4 changed files with 54 additions and 54 deletions

View File

@ -176,7 +176,7 @@ class PodsController(rest.RestController):
def _get_pods_collection(self, marker, limit,
sort_key, sort_dir,
bay_uuid, expand=False,
bay_ident, expand=False,
resource_url=None):
limit = api_utils.validate_limit(limit)
@ -200,19 +200,19 @@ class PodsController(rest.RestController):
@policy.enforce_wsgi("pod")
@expose.expose(PodCollection, types.uuid,
types.uuid, int, wtypes.text, wtypes.text,
types.uuid)
types.uuid_or_name)
def get_all(self, pod_uuid=None, marker=None, limit=None,
sort_key='id', sort_dir='asc', bay_uuid=None):
sort_key='id', sort_dir='asc', bay_ident=None):
"""Retrieve a list of pods.
:param marker: pagination marker for large data sets.
:param limit: maximum number of resources to return in a single result.
:param sort_key: column to sort results by. Default: id.
:param sort_dir: direction to sort. "asc" or "desc". Default: asc.
:param bay_uuid: UUID of the Bay.
:param bay_ident: UUID or logical name of the Bay.
"""
return self._get_pods_collection(marker, limit, sort_key,
sort_dir, bay_uuid)
sort_dir, bay_ident)
@policy.enforce_wsgi("pod")
@expose.expose(PodCollection, types.uuid,
@ -220,7 +220,7 @@ class PodsController(rest.RestController):
types.uuid)
def detail(self, pod_uuid=None, marker=None, limit=None,
sort_key='id', sort_dir='asc',
bay_uuid=None):
bay_ident=None):
"""Retrieve a list of pods with detail.
:param pod_uuid: UUID of a pod, to get only pods for that pod.
@ -228,7 +228,7 @@ class PodsController(rest.RestController):
:param limit: maximum number of resources to return in a single result.
:param sort_key: column to sort results by. Default: id.
:param sort_dir: direction to sort. "asc" or "desc". Default: asc.
:param bay_uuid: UUID of the Bay.
:param bay_ident: UUID or logical name of the Bay.
"""
# NOTE(lucasagomes): /detail should only work agaist collections
parent = pecan.request.path.split('/')[:-1][-1]
@ -239,17 +239,17 @@ class PodsController(rest.RestController):
resource_url = '/'.join(['pods', 'detail'])
return self._get_pods_collection(marker, limit,
sort_key, sort_dir,
bay_uuid, expand,
bay_ident, expand,
resource_url)
@policy.enforce_wsgi("pod", "get")
@expose.expose(Pod, types.uuid_or_name,
types.uuid)
def get_one(self, pod_ident, bay_uuid):
types.uuid_or_name)
def get_one(self, pod_ident, bay_ident):
"""Retrieve information about the given pod.
:param pod_ident: UUID of a pod or logical name of the pod.
:param bay_uuid: UUID of the Bay.
:param bay_ident: UUID or logical name of the Bay.
"""
rpc_pod = api_utils.get_rpc_resource('Pod', pod_ident)
@ -277,12 +277,12 @@ class PodsController(rest.RestController):
@policy.enforce_wsgi("pod", "update")
@wsme.validate(types.uuid, [PodPatchType])
@expose.expose(Pod, types.uuid_or_name,
types.uuid, body=[PodPatchType])
def patch(self, pod_ident, bay_uuid, patch):
types.uuid_or_name, body=[PodPatchType])
def patch(self, pod_ident, bay_ident, patch):
"""Update an existing pod.
:param pod_ident: UUID or logical name of a pod.
:param bay_uuid: UUID of the Bay.
:param bay_ident: UUID or logical name of the Bay.
:param patch: a json PATCH document to apply to this pod.
"""
rpc_pod = api_utils.get_rpc_resource('Pod', pod_ident)
@ -318,12 +318,12 @@ class PodsController(rest.RestController):
@policy.enforce_wsgi("pod")
@expose.expose(None, types.uuid_or_name,
types.uuid, status_code=204)
def delete(self, pod_ident, bay_uuid):
types.uuid_or_name, status_code=204)
def delete(self, pod_ident, bay_ident):
"""Delete a pod.
:param pod_ident: UUID of a pod or logical name of the pod.
:param bay_uuid: UUID of the Bay.
:param bay_ident: UUID or logical name of the Bay.
"""
rpc_pod = api_utils.get_rpc_resource('Pod', pod_ident)

View File

@ -206,7 +206,7 @@ class ReplicationControllersController(rest.RestController):
def _get_rcs_collection(self, marker, limit,
sort_key, sort_dir,
bay_uuid, expand=False,
bay_ident, expand=False,
resource_url=None):
limit = api_utils.validate_limit(limit)
@ -233,27 +233,27 @@ class ReplicationControllersController(rest.RestController):
@policy.enforce_wsgi("rc")
@expose.expose(ReplicationControllerCollection, types.uuid,
types.uuid, int, wtypes.text, wtypes.text,
types.uuid)
types.uuid_or_name)
def get_all(self, rc_uuid=None, marker=None, limit=None,
sort_key='id', sort_dir='asc', bay_uuid=None):
sort_key='id', sort_dir='asc', bay_ident=None):
"""Retrieve a list of ReplicationControllers.
:param marker: pagination marker for large data sets.
:param limit: maximum number of resources to return in a single result.
:param sort_key: column to sort results by. Default: id.
:param sort_dir: direction to sort. "asc" or "desc". Default: asc.
:param bay_uuid: UUID of the Bay.
:param bay_ident: UUID or logical name of the Bay.
"""
return self._get_rcs_collection(marker, limit, sort_key,
sort_dir, bay_uuid)
sort_dir, bay_ident)
@policy.enforce_wsgi("rc")
@expose.expose(ReplicationControllerCollection, types.uuid,
types.uuid, int, wtypes.text, wtypes.text,
types.uuid)
types.uuid_or_name)
def detail(self, rc_uuid=None, marker=None, limit=None,
sort_key='id', sort_dir='asc',
bay_uuid=None):
bay_ident=None):
"""Retrieve a list of ReplicationControllers with detail.
:param rc_uuid: UUID of a ReplicationController, to get only
@ -262,7 +262,7 @@ class ReplicationControllersController(rest.RestController):
:param limit: maximum number of resources to return in a single result.
:param sort_key: column to sort results by. Default: id.
:param sort_dir: direction to sort. "asc" or "desc". Default: asc.
:param bay_uuid: UUID of the Bay.
:param bay_ident: UUID or logical name of the Bay.
"""
# NOTE(jay-lau-513): /detail should only work agaist collections
parent = pecan.request.path.split('/')[:-1][-1]
@ -273,17 +273,17 @@ class ReplicationControllersController(rest.RestController):
resource_url = '/'.join(['rcs', 'detail'])
return self._get_rcs_collection(marker, limit,
sort_key, sort_dir,
bay_uuid, expand,
bay_ident, expand,
resource_url)
@policy.enforce_wsgi("rc", "get")
@expose.expose(ReplicationController, types.uuid_or_name,
types.uuid)
def get_one(self, rc_ident, bay_uuid):
types.uuid_or_name)
def get_one(self, rc_ident, bay_ident):
"""Retrieve information about the given ReplicationController.
:param rc_ident: UUID or logical name of a ReplicationController.
:param bay_uuid: UUID of the Bay.
:param bay_ident: UUID or logical name of the Bay.
"""
rpc_rc = api_utils.get_rpc_resource('ReplicationController', rc_ident)
return ReplicationController.convert_with_links(rpc_rc)
@ -314,12 +314,12 @@ class ReplicationControllersController(rest.RestController):
@policy.enforce_wsgi("rc", "update")
@wsme.validate(types.uuid, [ReplicationControllerPatchType])
@expose.expose(ReplicationController, types.uuid_or_name,
types.uuid, body=[ReplicationControllerPatchType])
def patch(self, rc_ident, bay_uuid, patch):
types.uuid_or_name, body=[ReplicationControllerPatchType])
def patch(self, rc_ident, bay_ident, patch):
"""Update an existing rc.
:param rc_ident: UUID or logical name of a ReplicationController.
:param bay_uuid: UUID of the Bay.
:param bay_ident: UUID or logical name of the Bay.
:param patch: a json PATCH document to apply to this rc.
"""
rpc_rc = api_utils.get_rpc_resource('ReplicationController', rc_ident)
@ -356,12 +356,12 @@ class ReplicationControllersController(rest.RestController):
@policy.enforce_wsgi("rc")
@expose.expose(None, types.uuid_or_name,
types.uuid, status_code=204)
def delete(self, rc_ident, bay_uuid):
types.uuid_or_name, status_code=204)
def delete(self, rc_ident, bay_ident):
"""Delete a ReplicationController.
:param rc_uuid: UUID of a ReplicationController.
:param bay_uuid: UUID of the Bay.
:param rc_ident: UUID or logical name of a ReplicationController.
:param bay_ident: UUID or logical name of the Bay.
"""
rpc_rc = api_utils.get_rpc_resource('ReplicationController', rc_ident)
pecan.request.rpcapi.rc_delete(rpc_rc.uuid)

View File

@ -184,7 +184,7 @@ class ServicesController(rest.RestController):
def _get_services_collection(self, marker, limit,
sort_key, sort_dir,
bay_uuid, expand=False,
bay_ident, expand=False,
resource_url=None):
limit = api_utils.validate_limit(limit)
@ -210,27 +210,27 @@ class ServicesController(rest.RestController):
@policy.enforce_wsgi("service")
@expose.expose(ServiceCollection, types.uuid,
types.uuid, int, wtypes.text, wtypes.text,
types.uuid)
types.uuid_or_name)
def get_all(self, service_uuid=None, marker=None, limit=None,
sort_key='id', sort_dir='asc', bay_uuid=None):
sort_key='id', sort_dir='asc', bay_ident=None):
"""Retrieve a list of services.
:param marker: pagination marker for large data sets.
:param limit: maximum number of resources to return in a single result.
:param sort_key: column to sort results by. Default: id.
:param sort_dir: direction to sort. "asc" or "desc". Default: asc.
:param bay_uuid: UUID of the Bay.
:param bay_ident: UUID or logical name of the Bay.
"""
return self._get_services_collection(marker, limit, sort_key,
sort_dir, bay_uuid)
sort_dir, bay_ident)
@policy.enforce_wsgi("service")
@expose.expose(ServiceCollection, types.uuid,
types.uuid, int, wtypes.text, wtypes.text,
types.uuid)
types.uuid_or_name)
def detail(self, service_uuid=None, marker=None, limit=None,
sort_key='id', sort_dir='asc',
bay_uuid=None):
bay_ident=None):
"""Retrieve a list of services with detail.
:param service_uuid: UUID of a service, to get only
@ -239,7 +239,7 @@ class ServicesController(rest.RestController):
:param limit: maximum number of resources to return in a single result.
:param sort_key: column to sort results by. Default: id.
:param sort_dir: direction to sort. "asc" or "desc". Default: asc.
:param bay_uuid: UUID of the Bay.
:param bay_ident: UUID or logical name of the Bay.
"""
# NOTE(lucasagomes): /detail should only work agaist collections
parent = pecan.request.path.split('/')[:-1][-1]
@ -254,12 +254,12 @@ class ServicesController(rest.RestController):
@policy.enforce_wsgi("service", "get")
@expose.expose(Service, types.uuid_or_name,
types.uuid)
def get_one(self, service_ident, bay_uuid):
types.uuid_or_name)
def get_one(self, service_ident, bay_ident):
"""Retrieve information about the given service.
:param service_ident: UUID or logical name of the service.
:param bay_uuid: UUID of the Bay.
:param bay_ident: UUID or logical name of the Bay.
"""
rpc_service = api_utils.get_rpc_resource('Service', service_ident)
@ -290,12 +290,12 @@ class ServicesController(rest.RestController):
@policy.enforce_wsgi("service", "update")
@wsme.validate(types.uuid, [ServicePatchType])
@expose.expose(Service, types.uuid_or_name,
types.uuid, body=[ServicePatchType])
def patch(self, service_ident, bay_uuid, patch):
types.uuid_or_name, body=[ServicePatchType])
def patch(self, service_ident, bay_ident, patch):
"""Update an existing service.
:param service_ident: UUID or logical name of a service.
:param bay_uuid: UUID of the Bay.
:param bay_ident: UUID or logical name of the Bay.
:param patch: a json PATCH document to apply to this service.
"""
rpc_service = api_utils.get_rpc_resource('Service', service_ident)
@ -331,12 +331,12 @@ class ServicesController(rest.RestController):
@policy.enforce_wsgi("service")
@expose.expose(None, types.uuid_or_name,
types.uuid, status_code=204)
def delete(self, service_ident, bay_uuid):
types.uuid_or_name, status_code=204)
def delete(self, service_ident, bay_ident):
"""Delete a service.
:param service_ident: UUID or logical name of a service.
:param bay_uuid: UUID of the Bay.
:param bay_ident: UUID or logical name of the Bay.
"""
rpc_service = api_utils.get_rpc_resource('Service', service_ident)

View File

@ -555,7 +555,7 @@ class TestDelete(api_base.FunctionalTest):
response = self.delete(
'/rcs/test_rc/5d12f6fd-a196-4bf0-ae4c-1f639a523a5',
expect_errors=True)
self.assertEqual(400, response.status_int)
self.assertEqual(409, response.status_int)
self.assertEqual('application/json', response.content_type)
self.assertTrue(response.json['error_message'])