def forwards(self, orm):

        # Deleting model 'Cluster_Perms'
        if db_table_exists('object_permissions_cluster_perms'):
            db.delete_table('object_permissions_cluster_perms')

        # Deleting model 'VirtualMachine_Perms'
        if db_table_exists('object_permissions_virtualmachine_perms'):
            db.delete_table('object_permissions_virtualmachine_perms')
    def forwards(self, orm):

        # Deleting model 'Cluster_Perms'
        if db_table_exists('object_permissions_cluster_perms'):
            db.delete_table('object_permissions_cluster_perms')

        # Deleting model 'VirtualMachine_Perms'
        if db_table_exists('object_permissions_virtualmachine_perms'):
            db.delete_table('object_permissions_virtualmachine_perms')
    def forwards(self, orm):
        """
        Convert permissions stored in old object permission tables (v1.3) to
        new perm tables (v1.4)

            see ticket # for more details
        """

        if db_table_exists('object_permissions_cluster_perms'):
            # Convert cluster permissions
            Cluster_Perms = orm['ganeti_web.cluster_perms']
            Old_Perms = orm['object_permissions.cluster_perms']
            for old_perm in Old_Perms.objects.all():
                perm = Cluster_Perms()
                perm.pk = old_perm.pk
                perm.user = old_perm.user
                perm.group = old_perm.group
                perm.user = old_perm.user
                perm.obj_id = old_perm.obj_id
                perm.admin = old_perm.admin
                perm.create_vm = old_perm.create_vm
                perm.export = old_perm.export
                perm.migrate = old_perm.migrate
                perm.replace_disks = old_perm.replace_disks
                perm.tags = old_perm.tags
                perm.save()

        # Convert VirtualMachine permissions
        if db_table_exists('object_permissions_virtualmachine_perms'):
            VirtualMachine_Perms = orm['ganeti_web.virtualmachine_perms']
            Old_Perms = orm['object_permissions.virtualmachine_perms']
            for old_perm in Old_Perms.objects.all():
                perm = VirtualMachine_Perms()
                perm.pk = old_perm.pk
                perm.user = old_perm.user
                perm.group = old_perm.group
                perm.user = old_perm.user
                perm.obj_id = old_perm.obj_id
                perm.admin = old_perm.admin
                perm.modify = old_perm.modify
                perm.power = old_perm.power
                perm.remove = old_perm.remove
                perm.tags = old_perm.tags
                perm.save()
 def convert(self, orm, model, fields):
     if db_table_exists('ganeti_%s' % model):
         Old = orm['ganeti.%s' % model]
         New = orm['ganeti_web.%s' % model]
         for old in Old.objects.all():
             new = New()
             for field in fields:
                 val = old.__dict__[field]
                 new.__dict__[field] = val
             new.save()
 def convert(self, orm, model, fields):
     if db_table_exists('ganeti_%s' % model):
         Old = orm['ganeti.%s' % model]
         New = orm['ganeti_web.%s' % model]
         for old in Old.objects.all():
             new = New()
             for field in fields:
                 val = old.__dict__[field]
                 new.__dict__[field] = val
             new.save()
    def backwards(self, orm):
        "Write your backwards methods here."

        # Convert cluster permissions
        if db_table_exists('object_permissions_cluster_perms'):
            Cluster_Perms = orm['ganeti_web.cluster_perms']
            Old_Perms = orm['object_permissions.cluster_perms']
            for new_perm in Cluster_Perms.objects.all():
                perm = Old_Perms()
                perm.pk = new_perm.pk
                perm.user = new_perm.user
                perm.group = new_perm.group
                perm.user = new_perm.user
                perm.obj_id = new_perm.obj
                perm.admin = new_perm.admin
                perm.create_vm = new_perm.create_vm
                perm.export = new_perm.export
                perm.migrate = new_perm.migrate
                perm.replace_disks = new_perm.replace_disks
                perm.tags = new_perm.tags
                perm.save()

        # Convert VirtualMachine permissions
        if db_table_exists('object_permissions_virtualmachine_perms'):
            VirtualMachine_Perms = orm['ganeti_web.virtualmachine_perms']
            Old_Perms = orm['object_permissions.virtualmachine_perms']
            for new_perm in VirtualMachine_Perms.objects.all():
                perm = Old_Perms()
                perm.pk = new_perm.pk
                perm.user = new_perm.user
                perm.group = new_perm.group
                perm.user = new_perm.user
                perm.obj_id = new_perm.obj
                perm.admin = new_perm.admin
                perm.create_vm = new_perm.create_vm
                perm.export = new_perm.export
                perm.migrate = new_perm.migrate
                perm.replace_disks = new_perm.replace_disks
                perm.tags = new_perm.tags
                perm.save()
 def safe_delete(self, table):
     """ delete a table only if it exists """
     if db_table_exists(table):
         db.delete_table(table)
 def safe_delete(self, table):
     """ delete a table only if it exists """
     if db_table_exists(table):
         db.delete_table(table)