'Build a patch to add the required fields to deploy a node.
:param instance: the instance object.
:param image_meta: the nova.objects.ImageMeta object instance
:param flavor: the flavor object.
:param preserve_ephemeral: preserve_ephemeral status (bool) to be
specified during rebuild.
:param boot_from_volume: True if node boots from volume. Then,
image_source is not passed to ironic.
:returns: a json-patch with the fields that needs to be updated.'

def get_deploy_patch(self, instance, image_meta, flavor, preserve_ephemeral=None, boot_from_volume=False):

    patch = []
    if (not boot_from_volume):
        patch.append({'path': '/instance_info/image_source', 'op': 'add', 'value': image_meta.id})
    patch.append({'path': '/instance_info/root_gb', 'op': 'add', 'value': str(instance.flavor.root_gb)})
    patch.append({'path': '/instance_info/swap_mb', 'op': 'add', 'value': str(flavor['swap'])})
    patch.append({'path': '/instance_info/display_name', 'op': 'add', 'value': instance.display_name})
    patch.append({'path': '/instance_info/vcpus', 'op': 'add', 'value': str(instance.flavor.vcpus)})
    patch.append({'path': '/instance_info/nova_host_id', 'op': 'add', 'value': instance.get('host')})
    patch.append({'path': '/instance_info/memory_mb', 'op': 'add', 'value': str(instance.flavor.memory_mb)})
    patch.append({'path': '/instance_info/local_gb', 'op': 'add', 'value': str(self.node.properties.get('local_gb', 0))})
    if instance.flavor.ephemeral_gb:
        patch.append({'path': '/instance_info/ephemeral_gb', 'op': 'add', 'value': str(instance.flavor.ephemeral_gb)})
        if CONF.default_ephemeral_format:
            patch.append({'path': '/instance_info/ephemeral_format', 'op': 'add', 'value': CONF.default_ephemeral_format})
    if (preserve_ephemeral is not None):
        patch.append({'path': '/instance_info/preserve_ephemeral', 'op': 'add', 'value': str(preserve_ephemeral)})
    capabilities = {}
    extra_specs = flavor.get('extra_specs')
    for (key, val) in extra_specs.items():
        if (not key.startswith('capabilities:')):
            continue
        (capabilities_string, capabilities_key) = key.split(':', 1)
        if capabilities_key:
            capabilities[capabilities_key] = val
    if capabilities:
        patch.append({'path': '/instance_info/capabilities', 'op': 'add', 'value': jsonutils.dumps(capabilities)})
    return patch
