'Move an ``Application`` to a specified ``Node``, also moving any
attached datasets.
:param Application application: The ``Application`` to relocate.
:param Node target_node: The desired ``Node`` to which the application
should be moved.
:return Deployment: Updated to reflect the new desired state.'

def move_application(self, application, target_node):

    deployment = self
    for node in deployment.nodes.values():
        container = node.applications.get(application.name)
        if container:
            if (not same_node(node, target_node)):
                if (application.volume is not None):
                    dataset_id = application.volume.dataset.dataset_id
                    target_node = target_node.transform(('manifestations', dataset_id), application.volume.manifestation)
                node = node.transform(['applications', application.name], discard)
                if (application.volume is not None):
                    dataset_id = application.volume.dataset.dataset_id
                    node = node.transform(('manifestations', dataset_id), discard)
                target_node = target_node.transform(['applications', application.name], application)
                deployment = deployment.update_node(node)
                deployment = deployment.update_node(target_node)
    return deployment
