Merge "Add metadata parameter to checkpoint API"
This commit is contained in:
commit
cc6be6a8c4
@ -14,6 +14,7 @@
|
||||
|
||||
from oslo_config import cfg
|
||||
from oslo_log import log as logging
|
||||
from oslo_serialization import jsonutils
|
||||
from oslo_utils import uuidutils
|
||||
|
||||
from webob import exc
|
||||
@ -143,6 +144,7 @@ class CheckpointViewBuilder(common.ViewBuilder):
|
||||
'protection_plan': checkpoint.get('protection_plan'),
|
||||
'resource_graph': checkpoint.get('resource_graph'),
|
||||
'created_at': checkpoint.get('created_at'),
|
||||
'extra_info': checkpoint.get('extra_info'),
|
||||
}
|
||||
}
|
||||
return checkpoint_ref
|
||||
@ -391,6 +393,21 @@ class ProvidersController(wsgi.Controller):
|
||||
"the value in the plan.")
|
||||
raise exception.InvalidPlan(reason=msg)
|
||||
|
||||
extra_info = checkpoint.get("extra_info", None)
|
||||
if extra_info is not None:
|
||||
if not isinstance(extra_info, dict):
|
||||
msg = _("The extra_info in checkpoint must be a dict when "
|
||||
"creating a checkpoint.")
|
||||
raise exception.InvalidInput(reason=msg)
|
||||
elif not all(map(lambda s: isinstance(s, (str, unicode)),
|
||||
extra_info.keys())):
|
||||
msg = _("Key of extra_info in checkpoint must be string when"
|
||||
"creating a checkpoint.")
|
||||
raise exception.InvalidInput(reason=msg)
|
||||
|
||||
checkpoint_extra_info = None
|
||||
if extra_info is not None:
|
||||
checkpoint_extra_info = jsonutils.dumps(extra_info)
|
||||
checkpoint_properties = {
|
||||
'project_id': context.project_id,
|
||||
'status': constants.CHECKPOINT_STATUS_PROTECTING,
|
||||
@ -399,15 +416,19 @@ class ProvidersController(wsgi.Controller):
|
||||
"id": plan.get("id"),
|
||||
"name": plan.get("name"),
|
||||
"resources": plan.get("resources"),
|
||||
}
|
||||
},
|
||||
"extra_info": checkpoint_extra_info
|
||||
}
|
||||
try:
|
||||
checkpoint_id = self.protection_api.protect(context, plan)
|
||||
checkpoint_id = self.protection_api.protect(context, plan,
|
||||
checkpoint_properties)
|
||||
except Exception as error:
|
||||
msg = _("Create checkpoint failed: %s") % error.msg
|
||||
raise exc.HTTPBadRequest(explanation=msg)
|
||||
checkpoint_properties['id'] = checkpoint_id
|
||||
|
||||
LOG.info(_LI("Create the checkpoint successfully. checkpoint_id:%s"),
|
||||
checkpoint_id)
|
||||
returnval = self._checkpoint_view_builder.detail(
|
||||
req, checkpoint_properties)
|
||||
return returnval
|
||||
|
@ -27,8 +27,9 @@ class API(base.Base):
|
||||
def restore(self, context, restore, restore_auth):
|
||||
return self.protection_rpcapi.restore(context, restore, restore_auth)
|
||||
|
||||
def protect(self, context, plan):
|
||||
return self.protection_rpcapi.protect(context, plan)
|
||||
def protect(self, context, plan, checkpoint_properties):
|
||||
return self.protection_rpcapi.protect(context, plan,
|
||||
checkpoint_properties)
|
||||
|
||||
def delete(self, context, provider_id, checkpoint_id):
|
||||
return self.protection_rpcapi.delete(
|
||||
|
@ -45,6 +45,7 @@ class Checkpoint(object):
|
||||
"id": self.id,
|
||||
"status": self.status,
|
||||
"protection_plan": self.protection_plan,
|
||||
"extra_info": self._md_cache.get("extra_info", None),
|
||||
"project_id": self.project_id,
|
||||
"resource_graph": self._md_cache.get("resource_graph", None),
|
||||
"created_at": self._md_cache.get("created_at", None)
|
||||
@ -139,7 +140,8 @@ class Checkpoint(object):
|
||||
|
||||
@classmethod
|
||||
def create_in_section(cls, checkpoints_section, indices_section,
|
||||
bank_lease, owner_id, plan, checkpoint_id=None):
|
||||
bank_lease, owner_id, plan,
|
||||
checkpoint_id=None, checkpoint_properties=None):
|
||||
checkpoint_id = checkpoint_id or cls._generate_id()
|
||||
checkpoint_section = checkpoints_section.get_sub_section(checkpoint_id)
|
||||
|
||||
@ -147,6 +149,9 @@ class Checkpoint(object):
|
||||
created_at = timeutils.utcnow().strftime('%Y-%m-%d')
|
||||
|
||||
provider_id = plan.get("provider_id")
|
||||
extra_info = None
|
||||
if checkpoint_properties:
|
||||
extra_info = checkpoint_properties.get("extra_info", None)
|
||||
checkpoint_section.update_object(
|
||||
key=_INDEX_FILE_NAME,
|
||||
value={
|
||||
@ -162,6 +167,7 @@ class Checkpoint(object):
|
||||
"provider_id": plan.get("provider_id"),
|
||||
"resources": plan.get("resources")
|
||||
},
|
||||
"extra_info": extra_info,
|
||||
"created_at": created_at,
|
||||
"timestamp": timestamp
|
||||
}
|
||||
@ -308,11 +314,13 @@ class CheckpointCollection(object):
|
||||
self._bank_lease,
|
||||
checkpoint_id)
|
||||
|
||||
def create(self, plan):
|
||||
def create(self, plan, checkpoint_properties=None):
|
||||
# TODO(saggi): Serialize plan to checkpoint. Will be done in
|
||||
# future patches.
|
||||
return Checkpoint.create_in_section(self._checkpoints_section,
|
||||
self._indices_section,
|
||||
self._bank_lease,
|
||||
self._bank.get_owner_id(),
|
||||
plan)
|
||||
return Checkpoint.create_in_section(
|
||||
self._checkpoints_section,
|
||||
self._indices_section,
|
||||
self._bank_lease,
|
||||
self._bank.get_owner_id(),
|
||||
plan,
|
||||
checkpoint_properties=checkpoint_properties)
|
||||
|
@ -86,14 +86,15 @@ class ProtectionManager(manager.Manager):
|
||||
@messaging.expected_exceptions(exception.InvalidPlan,
|
||||
exception.ProviderNotFound,
|
||||
exception.FlowError)
|
||||
def protect(self, context, plan):
|
||||
def protect(self, context, plan, checkpoint_properties=None):
|
||||
"""create protection for the given plan
|
||||
|
||||
:param plan: Define that protection plan should be done
|
||||
"""
|
||||
|
||||
LOG.info(_LI("Starting protection service:protect action"))
|
||||
LOG.debug("protecting: %s type: %s", plan, type(plan))
|
||||
LOG.debug("protecting: %s checkpoint_properties:%s",
|
||||
plan, checkpoint_properties)
|
||||
|
||||
if not plan:
|
||||
raise exception.InvalidPlan(
|
||||
@ -103,7 +104,8 @@ class ProtectionManager(manager.Manager):
|
||||
provider = self.provider_registry.show_provider(provider_id)
|
||||
checkpoint_collection = provider.get_checkpoint_collection()
|
||||
try:
|
||||
checkpoint = checkpoint_collection.create(plan)
|
||||
checkpoint = checkpoint_collection.create(plan,
|
||||
checkpoint_properties)
|
||||
except Exception as e:
|
||||
LOG.exception(_LE("Failed to create checkpoint, plan: %s"),
|
||||
plan_id)
|
||||
|
@ -52,12 +52,13 @@ class ProtectionAPI(object):
|
||||
restore=restore,
|
||||
restore_auth=restore_auth)
|
||||
|
||||
def protect(self, ctxt, plan=None):
|
||||
def protect(self, ctxt, plan=None, checkpoint_properties=None):
|
||||
cctxt = self.client.prepare(version='1.0')
|
||||
return cctxt.call(
|
||||
ctxt,
|
||||
'protect',
|
||||
plan=plan)
|
||||
plan=plan,
|
||||
checkpoint_properties=checkpoint_properties)
|
||||
|
||||
def delete(self, ctxt, provider_id, checkpoint_id):
|
||||
cctxt = self.client.prepare(version='1.0')
|
||||
|
@ -219,7 +219,7 @@ class FakeCheckpoint(object):
|
||||
|
||||
|
||||
class FakeCheckpointCollection(object):
|
||||
def create(self, plan):
|
||||
def create(self, plan, checkpoint_properties=None):
|
||||
return FakeCheckpoint()
|
||||
|
||||
def get(self, checkpoint_id):
|
||||
|
Loading…
Reference in New Issue
Block a user