Add more fields for service

Change-Id: I37ff2b98cd97bdebf599d5345a45e52bdd80b696
changes/56/144456/1
Jay Lau (Guangya Liu) 2014-12-30 08:41:47 -05:00
parent a6f4f0f137
commit 453952d102
5 changed files with 39 additions and 3 deletions

View File

@ -69,6 +69,18 @@ class Service(base.APIBase):
bay_uuid = types.uuid
"""Unique UUID of the bay the service runs on"""
labels = {wtypes.text: wtypes.text}
"""Labels of this service"""
selector = {wtypes.text: wtypes.text}
"""Selector of this service"""
ip = wtypes.text
"""IP of this service"""
port = wtypes.IntegerType()
"""Port of this service"""
links = wsme.wsattr([link.Link], readonly=True)
"""A list containing a self link and associated service links"""
@ -92,7 +104,8 @@ class Service(base.APIBase):
@staticmethod
def _convert_with_links(service, url, expand=True):
if not expand:
service.unset_fields_except(['uuid', 'name', 'bay_uuid'])
service.unset_fields_except(['uuid', 'name', 'bay_uuid', 'labels',
'selector', 'ip', 'port'])
# never expose the service_id attribute
service.service_id = wtypes.Unset
@ -114,6 +127,10 @@ class Service(base.APIBase):
sample = cls(uuid='fe78db47-9a37-4e9f-8572-804a10abc0aa',
name='MyService',
bay_uuid='7ae81bb3-dec3-4289-8d6c-da80bd8001ae',
labels={'label1': 'foo'},
selector={'label1': 'foo'},
ip='172.17.2.2',
port=80,
created_at=datetime.datetime.utcnow(),
updated_at=datetime.datetime.utcnow())
sample._service_uuid = '87504bd9-ca50-40fd-b14e-bcb23ed42b27'
@ -311,4 +328,4 @@ class ServicesController(rest.RestController):
rpc_service = objects.Service.get_by_uuid(pecan.request.context,
service_uuid)
self.backend_api.service_delete(rpc_service)
self.backend_api.service_delete(rpc_service)

View File

@ -105,6 +105,10 @@ def upgrade():
sa.Column('uuid', sa.String(length=36), nullable=True),
sa.Column('name', sa.String(length=255), nullable=True),
sa.Column('bay_uuid', sa.String(length=36), nullable=True),
sa.Column('labels', sa.Text, nullable=True),
sa.Column('selector', sa.Text, nullable=True),
sa.Column('ip', sa.String(length=36), nullable=True),
sa.Column('port', sa.Integer(), nullable=True),
sa.PrimaryKeyConstraint('id'),
mysql_ENGINE='InnoDB',
mysql_DEFAULT_CHARSET='UTF8'

View File

@ -200,3 +200,7 @@ class Service(Base):
uuid = Column(String(36))
name = Column(String(255))
bay_uuid = Column(String(36))
labels = Column(JSONEncodedDict)
selector = Column(JSONEncodedDict)
ip = Column(String(36))
port = Column(Integer())

View File

@ -31,6 +31,10 @@ class Service(base.MagnumObject):
'uuid': obj_utils.str_or_none,
'name': obj_utils.str_or_none,
'bay_uuid': obj_utils.str_or_none,
'labels': obj_utils.dict_or_none,
'selector': obj_utils.dict_or_none,
'ip': obj_utils.str_or_none,
'port': int
}
@staticmethod

View File

@ -29,7 +29,10 @@ class TestServiceController(db_base.DbTestCase):
mock_method.side_effect = self.mock_service_create
# Create a service
params = '{"name": "service_foo",'\
'"bay_uuid": "7ae81bb3-dec3-4289-8d6c-da80bd8001ae"}'
'"bay_uuid": "7ae81bb3-dec3-4289-8d6c-da80bd8001ae",' \
'"labels": {"bar": "foo"},' \
'"selector": {"bar": "foo"}, "ip": "172.17.2.3",' \
'"port": 88}'
response = self.app.post('/v1/services',
params=params,
content_type='application/json')
@ -43,6 +46,10 @@ class TestServiceController(db_base.DbTestCase):
self.assertEqual('service_foo', c.get('name'))
self.assertEqual('7ae81bb3-dec3-4289-8d6c-da80bd8001ae',
c.get('bay_uuid'))
self.assertEqual('foo', c.get('labels')['bar'])
self.assertEqual('foo', c.get('selector')['bar'])
self.assertEqual('172.17.2.3', c.get('ip'))
self.assertEqual(88, c.get('port'))
# Get just the one we created
response = self.app.get('/v1/services/%s' % c.get('uuid'))