Restricted Magnum service state to 'up' and 'down'

Magnum service state could have any string having length 1-255.
This patch restricts value to be one of the following
  - up
  - down

Change-Id: I740e0379b78c08cbd9ded7ca7bd1bbdd92d44e90
Closes-bug: #1609216
This commit is contained in:
Rajiv Kumar 2016-08-03 10:02:02 +05:30
parent d20f189dff
commit 42ef3dc564
2 changed files with 18 additions and 1 deletions

View File

@ -21,6 +21,7 @@ from magnum.api import expose
from magnum.api import servicegroup as svcgrp_api
from magnum.common import policy
from magnum import objects
from magnum.objects import fields
class MagnumService(base.APIBase):
@ -31,7 +32,7 @@ class MagnumService(base.APIBase):
binary = wtypes.StringType(min_length=1, max_length=255)
"""Name of the binary"""
state = wtypes.StringType(min_length=1, max_length=255)
state = wtypes.Enum(str, *fields.MagnumServiceState.ALL)
"""State of the binary"""
id = wsme.wsattr(wtypes.IntegerType(minimum=1))

View File

@ -79,6 +79,18 @@ class DockerStorageDriver(fields.Enum):
valid_values=DockerStorageDriver.ALL)
class MagnumServiceState(fields.Enum):
ALL = (
up, down
) = (
'up', 'down',
)
def __init__(self):
super(MagnumServiceState, self).__init__(
valid_values=MagnumServiceState.ALL)
class ListOfDictsField(fields.AutoTypedField):
AUTO_TYPE = fields.List(fields.Dict(fields.FieldType()))
@ -87,6 +99,10 @@ class BayStatusField(fields.BaseEnumField):
AUTO_TYPE = BayStatus()
class MagnumServiceField(fields.BaseEnumField):
AUTO_TYPE = MagnumServiceState()
class ContainerStatusField(fields.BaseEnumField):
AUTO_TYPE = ContainerStatus()