'Create a copy of this HDA.'

def copy(self, copy_children=False, parent_id=None):

    hda = HistoryDatasetAssociation(hid=self.hid, name=self.name, info=self.info, blurb=self.blurb, peek=self.peek, tool_version=self.tool_version, extension=self.extension, dbkey=self.dbkey, dataset=self.dataset, visible=self.visible, deleted=self.deleted, parent_id=parent_id, copied_from_history_dataset_association=self)
    hda.purged = self.purged
    object_session(self).add(hda)
    object_session(self).flush()
    hda.set_size()
    hda.metadata = self.metadata
    if copy_children:
        for child in self.children:
            child.copy(copy_children=copy_children, parent_id=hda.id)
    if (not self.datatype.copy_safe_peek):
        hda.set_peek()
    object_session(self).flush()
    return hda
