Add bay uuid to pod model objects

Change-Id: Idf88d6553bca5c0db0ceff65ea19813844ee01de
This commit is contained in:
Pradeep Kilambi 2014-12-04 17:54:12 -05:00
parent 8283e695b8
commit c6ad7207e4
5 changed files with 30 additions and 3 deletions

View File

@ -76,6 +76,9 @@ class Pod(base.APIBase):
desc = wtypes.text
"""Description of this pod"""
bay_uuid = types.uuid
"""Unique UUID of the bay the pod runs on"""
links = wsme.wsattr([link.Link], readonly=True)
"""A list containing a self link and associated pod links"""
@ -102,7 +105,7 @@ class Pod(base.APIBase):
@staticmethod
def _convert_with_links(pod, url, expand=True):
if not expand:
pod.unset_fields_except(['uuid', 'name', 'desc'])
pod.unset_fields_except(['uuid', 'name', 'desc', 'bay_uuid'])
# never expose the pod_id attribute
pod.pod_id = wtypes.Unset
@ -125,6 +128,7 @@ class Pod(base.APIBase):
sample = cls(uuid='f978db47-9a37-4e9f-8572-804a10abc0aa',
name='MyPod',
desc='Pod - Description',
bay_uuid='7ae81bb3-dec3-4289-8d6c-da80bd8001ae',
created_at=datetime.datetime.utcnow(),
updated_at=datetime.datetime.utcnow())
# NOTE(lucasagomes): pod_uuid getter() method look at the

View File

@ -583,6 +583,13 @@ class Connection(api.Connection):
except NoResultFound:
raise exception.PodNotFound(pod=pod_uuid)
def get_pods_by_bay_uuid(self, bay_uuid):
query = model_query(models.Pod).filter_by(bay_uuid=bay_uuid)
try:
return query.all()
except NoResultFound:
raise exception.BayNotFound(bay=bay_uuid)
def get_pod_by_instance(self, instance):
if not utils.is_uuid_like(instance):
raise exception.InvalidUUID(uuid=instance)

View File

@ -150,6 +150,7 @@ class Pod(Base):
uuid = Column(String(36))
name = Column(String(255))
desc = Column(String(255))
bay_uuid = Column(String(36))
class AbrviceObject(Base):

View File

@ -35,7 +35,8 @@ class Pod(base.MagnumObject):
'id': int,
'uuid': obj_utils.str_or_none,
'name': obj_utils.str_or_none,
'desc': obj_utils.str_or_none
'desc': obj_utils.str_or_none,
'bay_uuid': obj_utils.str_or_none,
}
@staticmethod
@ -89,6 +90,17 @@ class Pod(base.MagnumObject):
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.
:param bay_uuid: the uuid of a bay.
:param context: Security context
:returns: a list of class:`Pod` object.
"""
db_pods = cls.dbapi.get_pods_by_bay_uuid(bay_uuid)
return Pod._from_db_object_list(db_pods, cls, context)
@base.remotable_classmethod
def list(cls, context, limit=None, marker=None,
sort_key=None, sort_dir=None):

View File

@ -111,7 +111,8 @@ class TestBayController(db_base.DbTestCase):
class TestPodController(db_base.DbTestCase):
def test_pod_api(self):
# Create a pod
params = '{"name": "pod_example_A", "desc": "My Pod"}'
params = '{"name": "pod_example_A", "desc": "My Pod",' \
'"bay_uuid": "7ae81bb3-dec3-4289-8d6c-da80bd8001ae"}'
response = self.app.post('/v1/pods',
params=params,
content_type='application/json')
@ -125,6 +126,8 @@ class TestPodController(db_base.DbTestCase):
self.assertIsNotNone(c.get('uuid'))
self.assertEqual('pod_example_A', c.get('name'))
self.assertEqual('My Pod', c.get('desc'))
self.assertEqual('7ae81bb3-dec3-4289-8d6c-da80bd8001ae',
c.get('bay_uuid'))
# Get just the one we created
response = self.app.get('/v1/pods/%s' % c.get('uuid'))