Set service name from service manifest
Only service manifest knows about service name, so this patch retrieve service name from service manifest. Change-Id: I1eb0f7dd7227875e1d10e5bd1d22f7e989e15f86changes/73/146773/3
parent
978b28e4ea
commit
b982600545
|
@ -24,6 +24,7 @@ from magnum.api.controllers.v1 import collection
|
|||
from magnum.api.controllers.v1 import types
|
||||
from magnum.api.controllers.v1 import utils as api_utils
|
||||
from magnum.common import exception
|
||||
from magnum.common import k8s_manifest
|
||||
from magnum import objects
|
||||
|
||||
|
||||
|
@ -61,16 +62,16 @@ class Service(base.APIBase):
|
|||
uuid = types.uuid
|
||||
"""Unique UUID for this service"""
|
||||
|
||||
name = wsme.wsattr(wtypes.text, mandatory=True)
|
||||
name = wsme.wsattr(wtypes.text, readonly=True)
|
||||
""" The name of the service."""
|
||||
|
||||
bay_uuid = types.uuid
|
||||
"""Unique UUID of the bay the service runs on"""
|
||||
|
||||
labels = {wtypes.text: wtypes.text}
|
||||
labels = wsme.wsattr({wtypes.text: wtypes.text}, readonly=True)
|
||||
"""Labels of this service"""
|
||||
|
||||
selector = {wtypes.text: wtypes.text}
|
||||
selector = wsme.wsattr({wtypes.text: wtypes.text}, readonly=True)
|
||||
"""Selector of this service"""
|
||||
|
||||
ip = wtypes.text
|
||||
|
@ -139,6 +140,19 @@ class Service(base.APIBase):
|
|||
sample._service_uuid = '87504bd9-ca50-40fd-b14e-bcb23ed42b27'
|
||||
return cls._convert_with_links(sample, 'http://localhost:9511', expand)
|
||||
|
||||
def parse_manifest(self):
|
||||
# Set service name and port from its manifest
|
||||
# TODO(yuanying): retrive service name from definition_url
|
||||
if hasattr(self, "service_data") and self.service_data is not None:
|
||||
manifest = k8s_manifest.parse(self.service_data)
|
||||
self.name = manifest["id"]
|
||||
if "port" in manifest:
|
||||
self.port = manifest["port"]
|
||||
if "selector" in manifest:
|
||||
self.selector = manifest["selector"]
|
||||
if "labels" in manifest:
|
||||
self.labels = manifest["labels"]
|
||||
|
||||
|
||||
class ServiceCollection(collection.Collection):
|
||||
"""API representation of a collection of services."""
|
||||
|
@ -263,6 +277,7 @@ class ServicesController(rest.RestController):
|
|||
if self.from_services:
|
||||
raise exception.OperationNotPermitted
|
||||
|
||||
service.parse_manifest()
|
||||
service_obj = objects.Service(pecan.request.context,
|
||||
**service.as_dict())
|
||||
new_service = pecan.request.rpcapi.service_create(service_obj)
|
||||
|
|
|
@ -34,7 +34,7 @@ class Service(base.MagnumObject):
|
|||
'labels': obj_utils.dict_or_none,
|
||||
'selector': obj_utils.dict_or_none,
|
||||
'ip': obj_utils.str_or_none,
|
||||
'port': int,
|
||||
'port': obj_utils.int_or_none,
|
||||
'service_definition_url': obj_utils.str_or_none,
|
||||
'service_data': obj_utils.str_or_none,
|
||||
}
|
||||
|
|
|
@ -28,12 +28,25 @@ class TestServiceController(db_base.DbTestCase):
|
|||
with patch.object(api.API, 'service_create') as mock_method:
|
||||
mock_method.side_effect = self.mock_service_create
|
||||
# Create a service
|
||||
params = '{"name": "service_foo",'\
|
||||
'"bay_uuid": "7ae81bb3-dec3-4289-8d6c-da80bd8001ae",' \
|
||||
'"labels": {"bar": "foo"},' \
|
||||
'"selector": {"bar": "foo"}, "ip": "172.17.2.3",' \
|
||||
'"port": 88,' \
|
||||
'"service_definition_url": "http://172.17.1.2/svc.json"}'
|
||||
params = '''
|
||||
{
|
||||
"bay_uuid": "7ae81bb3-dec3-4289-8d6c-da80bd8001ae",
|
||||
"service_data": "\
|
||||
{\
|
||||
\\"id\\": \\"service_foo\\",\
|
||||
\\"kind\\": \\"Service\\",\
|
||||
\\"apiVersion\\": \\"v1beta1\\",\
|
||||
\\"port\\": 88,\
|
||||
\\"selector\\": {\
|
||||
\\"bar\\": \\"foo\\"\
|
||||
},\
|
||||
\\"labels\\": {\
|
||||
\\"bar\\": \\"foo\\"\
|
||||
}\
|
||||
}\
|
||||
\"
|
||||
}
|
||||
'''
|
||||
response = self.app.post('/v1/services',
|
||||
params=params,
|
||||
content_type='application/json')
|
||||
|
@ -49,7 +62,6 @@ class TestServiceController(db_base.DbTestCase):
|
|||
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
|
||||
|
|
Loading…
Reference in New Issue