Consolidate codes for k8s resources api
Change-Id: I2479c89de91618f891f7501cac059323b476f7d3
This commit is contained in:
parent
2306534079
commit
e63918416c
|
@ -23,6 +23,18 @@ from magnum.common import urlfetch
|
|||
from magnum import objects
|
||||
|
||||
|
||||
class K8sPatchType(types.JsonPatchType):
|
||||
|
||||
@staticmethod
|
||||
def internal_attrs():
|
||||
defaults = types.JsonPatchType.internal_attrs()
|
||||
return defaults + ['/name', '/labels']
|
||||
|
||||
@staticmethod
|
||||
def mandatory_attrs():
|
||||
return ['/bay_uuid']
|
||||
|
||||
|
||||
class K8sResourceBase(base.APIBase):
|
||||
|
||||
_bay_uuid = None
|
||||
|
@ -53,6 +65,12 @@ class K8sResourceBase(base.APIBase):
|
|||
manifest = wtypes.text
|
||||
"""Data for manifest to create the k8s resource"""
|
||||
|
||||
name = wsme.wsattr(wtypes.text, readonly=True)
|
||||
"""Name of this k8s resource"""
|
||||
|
||||
labels = wsme.wsattr({wtypes.text: wtypes.text}, readonly=True)
|
||||
"""Labels of this k8s resource"""
|
||||
|
||||
def _get_manifest(self):
|
||||
if self.manifest is not wsme.Unset and self.manifest is not None:
|
||||
return self.manifest
|
||||
|
|
|
@ -29,16 +29,8 @@ from magnum.common import k8s_manifest
|
|||
from magnum import objects
|
||||
|
||||
|
||||
class PodPatchType(types.JsonPatchType):
|
||||
|
||||
@staticmethod
|
||||
def internal_attrs():
|
||||
defaults = types.JsonPatchType.internal_attrs()
|
||||
return defaults + ['/name', '/labels']
|
||||
|
||||
@staticmethod
|
||||
def mandatory_attrs():
|
||||
return ['/bay_uuid']
|
||||
class PodPatchType(v1_base.K8sPatchType):
|
||||
pass
|
||||
|
||||
|
||||
class Pod(v1_base.K8sResourceBase):
|
||||
|
@ -51,18 +43,12 @@ class Pod(v1_base.K8sResourceBase):
|
|||
uuid = types.uuid
|
||||
"""Unique UUID for this pod"""
|
||||
|
||||
name = wsme.wsattr(wtypes.text, readonly=True)
|
||||
"""Name of this pod"""
|
||||
|
||||
desc = wtypes.text
|
||||
"""Description of this pod"""
|
||||
|
||||
images = [wtypes.text]
|
||||
"""A list of images used by containers in this pod."""
|
||||
|
||||
labels = wsme.wsattr({wtypes.text: wtypes.text}, readonly=True)
|
||||
"""Labels of this pod"""
|
||||
|
||||
status = wtypes.text
|
||||
"""Staus of this pod """
|
||||
|
||||
|
|
|
@ -30,11 +30,8 @@ from magnum.common import k8s_manifest
|
|||
from magnum import objects
|
||||
|
||||
|
||||
class ReplicationControllerPatchType(types.JsonPatchType):
|
||||
|
||||
@staticmethod
|
||||
def mandatory_attrs():
|
||||
return ['/bay_uuid']
|
||||
class ReplicationControllerPatchType(v1_base.K8sPatchType):
|
||||
pass
|
||||
|
||||
|
||||
class ReplicationController(v1_base.K8sResourceBase):
|
||||
|
@ -48,15 +45,9 @@ class ReplicationController(v1_base.K8sResourceBase):
|
|||
uuid = types.uuid
|
||||
"""Unique UUID for this ReplicationController"""
|
||||
|
||||
name = wsme.wsattr(wtypes.text, readonly=True)
|
||||
"""Name of this ReplicationController"""
|
||||
|
||||
images = [wtypes.text]
|
||||
"""A list of images used by containers in this ReplicationController."""
|
||||
|
||||
labels = wsme.wsattr({wtypes.text: wtypes.text}, readonly=True)
|
||||
"""Selector of this ReplicationController"""
|
||||
|
||||
replicas = wsme.wsattr(wtypes.IntegerType(), readonly=True)
|
||||
"""Replicas of this ReplicationController"""
|
||||
|
||||
|
|
|
@ -32,11 +32,8 @@ from magnum import objects
|
|||
_ = _LI = _LW = _LE = _LC = lambda x: x
|
||||
|
||||
|
||||
class ServicePatchType(types.JsonPatchType):
|
||||
|
||||
@staticmethod
|
||||
def mandatory_attrs():
|
||||
return ['/bay_uuid']
|
||||
class ServicePatchType(v1_base.K8sPatchType):
|
||||
pass
|
||||
|
||||
|
||||
class Service(v1_base.K8sResourceBase):
|
||||
|
@ -44,12 +41,6 @@ class Service(v1_base.K8sResourceBase):
|
|||
uuid = types.uuid
|
||||
"""Unique UUID for this service"""
|
||||
|
||||
name = wsme.wsattr(wtypes.text, readonly=True)
|
||||
""" The name of the service."""
|
||||
|
||||
labels = wsme.wsattr({wtypes.text: wtypes.text}, readonly=True)
|
||||
"""Labels of this service"""
|
||||
|
||||
selector = wsme.wsattr({wtypes.text: wtypes.text}, readonly=True)
|
||||
"""Selector of this service"""
|
||||
|
||||
|
|
|
@ -74,8 +74,8 @@ class TestServiceController(db_base.DbTestCase):
|
|||
self.assertEqual(response.status_int, 200)
|
||||
|
||||
# Update the description
|
||||
params = [{'path': '/name',
|
||||
'value': 'service_bar',
|
||||
params = [{'path': '/port',
|
||||
'value': '8888',
|
||||
'op': 'replace'}]
|
||||
response = self.app.patch_json('/v1/services/%s' % c.get('uuid'),
|
||||
params=params)
|
||||
|
|
Loading…
Reference in New Issue