def add(self, fail_on_error=True, fail_on_invalid_params=True, **kwargs):
"""Add new Cloud to the database
This is the only cloud controller subclass that overrides the `add`
method of `BaseMainController`.
This is only expected to be called by `Cloud.add` classmethod to create
a cloud. Fields `owner` and `title` are already populated in
`self.cloud`. The `self.cloud` model is not yet saved.
If appropriate kwargs are passed, this can currently also act as a
shortcut to also add the first machine on this dummy cloud.
"""
# Attempt to save.
try:
self.cloud.save()
except me.ValidationError as exc:
raise BadRequestError({'msg': exc.message,
'errors': exc.to_dict()})
except me.NotUniqueError:
raise CloudExistsError("Cloud with name %s already exists"
% self.cloud.title)
# Add machine.
if kwargs:
try:
self.add_machine_wrapper(
self.cloud.title, fail_on_error=fail_on_error,
fail_on_invalid_params=fail_on_invalid_params, **kwargs
)
except Exception as exc:
if fail_on_error:
self.cloud.delete()
raise
评论列表
文章目录