Add a new API of get_by_pod_name for pod object

In k8s, pod name cannot be duplicated and some end users want to
get pod by name.

Change-Id: Ic8b6273de914949e4799446e68e5e2d51bfab8b9
This commit is contained in:
Jay Lau 2014-12-22 02:23:26 -05:00
parent 0dc370a462
commit 0343637f5f
3 changed files with 27 additions and 0 deletions

View File

@ -549,6 +549,14 @@ class Connection(object):
:returns: A pod.
"""
@abc.abstractmethod
def get_pod_by_name(self, pod_name):
"""Return a pod.
:param pod_name: The name of a pod.
:returns: A pod.
"""
@abc.abstractmethod
def get_pod_by_instance(self, instance):
"""Return a pod.

View File

@ -927,6 +927,13 @@ class Connection(api.Connection):
except NoResultFound:
raise exception.PodNotFound(pod=pod_uuid)
def get_pod_by_name(self, pod_name):
query = model_query(models.Pod).filter_by(name=pod_name)
try:
return query.one()
except NoResultFound:
raise exception.PodNotFound(pod=pod_name)
def get_pods_by_bay_uuid(self, bay_uuid):
query = model_query(models.Pod).filter_by(bay_uuid=bay_uuid)
try:

View File

@ -90,6 +90,18 @@ class Pod(base.MagnumObject):
pod = Pod._from_db_object(cls(context), db_pod)
return pod
@base.remotable_classmethod
def get_by_name(cls, context, name):
"""Find a pod based on pod name and return a :class:`Pod` object.
:param name: the name of a pod.
:param context: Security context
:returns: a :class:`Pod` object.
"""
db_pod = cls.dbapi.get_pod_by_name(name)
pod = Pod._from_db_object(cls(context), db_pod)
return pod
@base.remotable_classmethod
def get_by_bay_uuid(cls, context, bay_uuid):
"""Find a pods based on bay uuid and return a :class:`Pod` object.