def _restoreMetadataDB(context, metadata, stack_resources):
        workload_policy_name = metadata["workload_policy_name"]
        workload_policy_obj = {
            'name': workload_policy_name,
            'tenant_id': context.tenant_id,
        }
        workload_policy = api.workload_policy_create(context,
                                                     workload_policy_obj)

        for restore_action in metadata["actions"]:
            # Create action-resource relationships,
            # New resources IDs from Heat orchestration
            action_resource = restore_action["resource"]
            action_name = action_resource["name"]
            action_rsc_name = action_resource["resource_type"]["name"]
            new_resource_id = stack_resources[(action_name, action_rsc_name)]
            resource_obj =\
                {'id': new_resource_id,
                 'name': action_name,
                 'resource_type_id': action_resource["resource_type_id"],
                 'tenant_id': context.tenant_id
                 }
            api.resource_create(context, resource_obj)

            db_action = restore_action["action"]
            resource_action_obj = {
                'workload_policy_id': workload_policy.id,
                'resource_id': new_resource_id,
                'action_id': db_action['id'],
            }
            api.resource_actions_create(context, resource_action_obj)
    def _restoreMetadataDB(context, metadata, stack_resources):
        workload_policy_name = metadata["workload_policy_name"]
        workload_policy_obj = {"name": workload_policy_name, "tenant_id": context.tenant_id}
        workload_policy = api.workload_policy_create(context, workload_policy_obj)

        for restore_action in metadata["actions"]:
            # Create action-resource relationships,
            # New resources IDs from Heat orchestration
            action_resource = restore_action["resource"]
            action_name = action_resource["name"]
            action_rsc_name = action_resource["resource_type"]["name"]
            new_resource_id = stack_resources[(action_name, action_rsc_name)]
            resource_obj = {
                "id": new_resource_id,
                "name": action_name,
                "resource_type_id": action_resource["resource_type_id"],
                "tenant_id": context.tenant_id,
            }
            api.resource_create(context, resource_obj)

            db_action = restore_action["action"]
            resource_action_obj = {
                "workload_policy_id": workload_policy.id,
                "resource_id": new_resource_id,
                "action_id": db_action["id"],
            }
            api.resource_actions_create(context, resource_action_obj)
 def create_workload_policy(self, cnxt, values):
     return db_api.workload_policy_create(cnxt, values)