diff --git a/zun/common/exception.py b/zun/common/exception.py index 4cf341ccc..90c950be3 100644 --- a/zun/common/exception.py +++ b/zun/common/exception.py @@ -339,3 +339,9 @@ class ContainerNotFound(HTTPNotFound): class ContainerAlreadyExists(ResourceExists): message = _("A container with UUID %(uuid)s already exists.") + + +class ContainerRunningException(ZunException): + message = _("The container %(id)s is running." + "Please stop and delete the container.") + code = 409 diff --git a/zun/compute/manager.py b/zun/compute/manager.py index 7f97948e8..53ec1aa18 100644 --- a/zun/compute/manager.py +++ b/zun/compute/manager.py @@ -72,6 +72,9 @@ class Manager(object): return container except Exception as e: LOG.exception(_LE("Unexpected exception: %s"), str(e)) + if e.response.status_code == 409: + raise exception.ContainerRunningException( + id=container.container_id) raise e @translate_exception