diff --git a/zun/api/controllers/v1/capsules.py b/zun/api/controllers/v1/capsules.py index fbaaab0e8..8110963c4 100644 --- a/zun/api/controllers/v1/capsules.py +++ b/zun/api/controllers/v1/capsules.py @@ -141,6 +141,7 @@ class CapsuleController(base.Controller): new_capsule = objects.Capsule(context, **capsule_dict) new_capsule.project_id = context.project_id new_capsule.user_id = context.user_id + new_capsule.status = consts.PENDING new_capsule.create(context) new_capsule.containers = [] new_capsule.containers_uuids = [] diff --git a/zun/common/consts.py b/zun/common/consts.py index 83d6dc87f..f3eda77d2 100644 --- a/zun/common/consts.py +++ b/zun/common/consts.py @@ -19,6 +19,12 @@ CONTAINER_STATUSES = ( 'Deleted', 'Deleting' ) +CAPSULE_STATUSES = ( + PENDING, RUNNING, SUCCEEDED, FAILED, UNKNOWN +) = ( + 'Pending', 'Running', 'Succeeded', 'Failed', 'Unknown' + ) + TASK_STATES = ( IMAGE_PULLING, CONTAINER_CREATING, SANDBOX_CREATING, CONTAINER_STARTING, CONTAINER_DELETING, SANDBOX_DELETING, diff --git a/zun/compute/manager.py b/zun/compute/manager.py index ac6fec870..94719648b 100644 --- a/zun/compute/manager.py +++ b/zun/compute/manager.py @@ -990,6 +990,7 @@ class Manager(periodic_task.PeriodicTasks): container_list = [container_uuid] capsule.volumes_info[volume_id] = container_list + capsule.status = consts.RUNNING capsule.save(context) def capsule_delete(self, context, capsule): diff --git a/zun/objects/capsule.py b/zun/objects/capsule.py index 414a184c3..11c583af0 100644 --- a/zun/objects/capsule.py +++ b/zun/objects/capsule.py @@ -27,7 +27,8 @@ class Capsule(base.ZunPersistentObject, base.ZunObject): # Version 1.3: Add 'Deleting' to ContainerStatus # Version 1.4: Add addresses and volumes_info # Version 1.5: Change the properties of restort_policy - VERSION = '1.5' + # Version 1.6: Change the type of status + VERSION = '1.6' fields = { 'capsule_version': fields.StringField(nullable=True), @@ -39,7 +40,7 @@ class Capsule(base.ZunPersistentObject, base.ZunObject): 'project_id': fields.StringField(nullable=True), 'user_id': fields.StringField(nullable=True), - 'status': z_fields.ContainerStatusField(nullable=True), + 'status': z_fields.CapsuleStatusField(nullable=True), 'status_reason': fields.StringField(nullable=True), 'cpu': fields.FloatField(nullable=True), 'memory': fields.StringField(nullable=True), diff --git a/zun/objects/fields.py b/zun/objects/fields.py index befc754e0..936f81c3b 100644 --- a/zun/objects/fields.py +++ b/zun/objects/fields.py @@ -37,6 +37,18 @@ class ContainerStatusField(fields.BaseEnumField): AUTO_TYPE = ContainerStatus() +class CapsuleStatus(fields.Enum): + ALL = consts.CAPSULE_STATUSES + + def __init__(self): + super(CapsuleStatus, self).__init__( + valid_values=CapsuleStatus.ALL) + + +class CapsuleStatusField(fields.BaseEnumField): + AUTO_TYPE = CapsuleStatus() + + class TaskState(fields.Enum): ALL = consts.TASK_STATES diff --git a/zun/tests/unit/objects/test_objects.py b/zun/tests/unit/objects/test_objects.py index 57bc948b4..9faaaaee4 100644 --- a/zun/tests/unit/objects/test_objects.py +++ b/zun/tests/unit/objects/test_objects.py @@ -353,7 +353,7 @@ object_data = { 'ResourceClass': '1.1-d661c7675b3cd5b8c3618b68ba64324e', 'ResourceProvider': '1.0-92b427359d5a4cf9ec6c72cbe630ee24', 'ZunService': '1.2-deff2a74a9ce23baa231ae12f39a6189', - 'Capsule': '1.5-cbdaffa78fa68c26cf4a61d8f75dd32d', + 'Capsule': '1.6-7238a80b4ef34e219c135fa72d0adc06', 'PciDevice': '1.1-6e3f0851ad1cf12583e6af4df1883979', 'ComputeNode': '1.9-e8536102d3b28cb3378e9e26f508cd72', 'PciDevicePool': '1.0-3f5ddc3ff7bfa14da7f6c7e9904cc000',