Merge "Add more fields for service"
This commit is contained in:
@@ -69,6 +69,18 @@ class Service(base.APIBase):
|
|||||||
bay_uuid = types.uuid
|
bay_uuid = types.uuid
|
||||||
"""Unique UUID of the bay the service runs on"""
|
"""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)
|
links = wsme.wsattr([link.Link], readonly=True)
|
||||||
"""A list containing a self link and associated service links"""
|
"""A list containing a self link and associated service links"""
|
||||||
|
|
||||||
@@ -92,7 +104,8 @@ class Service(base.APIBase):
|
|||||||
@staticmethod
|
@staticmethod
|
||||||
def _convert_with_links(service, url, expand=True):
|
def _convert_with_links(service, url, expand=True):
|
||||||
if not expand:
|
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
|
# never expose the service_id attribute
|
||||||
service.service_id = wtypes.Unset
|
service.service_id = wtypes.Unset
|
||||||
|
|
||||||
@@ -114,6 +127,10 @@ class Service(base.APIBase):
|
|||||||
sample = cls(uuid='fe78db47-9a37-4e9f-8572-804a10abc0aa',
|
sample = cls(uuid='fe78db47-9a37-4e9f-8572-804a10abc0aa',
|
||||||
name='MyService',
|
name='MyService',
|
||||||
bay_uuid='7ae81bb3-dec3-4289-8d6c-da80bd8001ae',
|
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(),
|
created_at=datetime.datetime.utcnow(),
|
||||||
updated_at=datetime.datetime.utcnow())
|
updated_at=datetime.datetime.utcnow())
|
||||||
sample._service_uuid = '87504bd9-ca50-40fd-b14e-bcb23ed42b27'
|
sample._service_uuid = '87504bd9-ca50-40fd-b14e-bcb23ed42b27'
|
||||||
|
@@ -108,6 +108,10 @@ def upgrade():
|
|||||||
sa.Column('uuid', sa.String(length=36), nullable=True),
|
sa.Column('uuid', sa.String(length=36), nullable=True),
|
||||||
sa.Column('name', sa.String(length=255), nullable=True),
|
sa.Column('name', sa.String(length=255), nullable=True),
|
||||||
sa.Column('bay_uuid', sa.String(length=36), 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'),
|
sa.PrimaryKeyConstraint('id'),
|
||||||
mysql_ENGINE='InnoDB',
|
mysql_ENGINE='InnoDB',
|
||||||
mysql_DEFAULT_CHARSET='UTF8'
|
mysql_DEFAULT_CHARSET='UTF8'
|
||||||
|
@@ -203,3 +203,7 @@ class Service(Base):
|
|||||||
uuid = Column(String(36))
|
uuid = Column(String(36))
|
||||||
name = Column(String(255))
|
name = Column(String(255))
|
||||||
bay_uuid = Column(String(36))
|
bay_uuid = Column(String(36))
|
||||||
|
labels = Column(JSONEncodedDict)
|
||||||
|
selector = Column(JSONEncodedDict)
|
||||||
|
ip = Column(String(36))
|
||||||
|
port = Column(Integer())
|
||||||
|
@@ -31,6 +31,10 @@ class Service(base.MagnumObject):
|
|||||||
'uuid': obj_utils.str_or_none,
|
'uuid': obj_utils.str_or_none,
|
||||||
'name': obj_utils.str_or_none,
|
'name': obj_utils.str_or_none,
|
||||||
'bay_uuid': 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
|
@staticmethod
|
||||||
|
@@ -29,7 +29,10 @@ class TestServiceController(db_base.DbTestCase):
|
|||||||
mock_method.side_effect = self.mock_service_create
|
mock_method.side_effect = self.mock_service_create
|
||||||
# Create a service
|
# Create a service
|
||||||
params = '{"name": "service_foo",'\
|
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',
|
response = self.app.post('/v1/services',
|
||||||
params=params,
|
params=params,
|
||||||
content_type='application/json')
|
content_type='application/json')
|
||||||
@@ -43,6 +46,10 @@ class TestServiceController(db_base.DbTestCase):
|
|||||||
self.assertEqual('service_foo', c.get('name'))
|
self.assertEqual('service_foo', c.get('name'))
|
||||||
self.assertEqual('7ae81bb3-dec3-4289-8d6c-da80bd8001ae',
|
self.assertEqual('7ae81bb3-dec3-4289-8d6c-da80bd8001ae',
|
||||||
c.get('bay_uuid'))
|
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
|
# Get just the one we created
|
||||||
response = self.app.get('/v1/services/%s' % c.get('uuid'))
|
response = self.app.get('/v1/services/%s' % c.get('uuid'))
|
||||||
|
Reference in New Issue
Block a user