SHARE
TWEET

Untitled

a guest Oct 22nd, 2019 156 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. from __future__ import annotations
  2.  
  3. import random
  4. import time
  5. from datetime import timedelta
  6.  
  7. from allauth.account.models import EmailAddress
  8. from django.apps import apps
  9. from django.core.management import BaseCommand
  10. from django.db import transaction
  11. from django.utils import timezone
  12.  
  13. from backupner.apps.core.utils import encrypt_data
  14. from panel.settings import IS_PROD
  15. from ...interfaces import SecretInterface
  16. from ...models import StatusChoice, LaunchTypeChoice
  17.  
  18.  
  19. class Command(BaseCommand):
  20.     help = 'Loads demo data'
  21.  
  22.     def create_backup_processes_and_jobs(self, data_sources):
  23.         """ Create backup processes and jobs. """
  24.         from ...services import create_backup_processes_for_data_source
  25.         Job = apps.get_model('backupnercore', 'Job')
  26.         jobs = []
  27.         for ds in data_sources:
  28.             backups = create_backup_processes_for_data_source(ds)  # todo: refactor me
  29.             backup_jobs = []
  30.             for backup in backups:
  31.                 tdelta = 0
  32.                 date = timezone.now()
  33.                 initial_repository_size = 524288000  # 500 MB
  34.                 for i in range(30):
  35.                     # 1+ success 0 failed
  36.                     if i in [0, 1]:
  37.                         tower_status = StatusChoice.successful.value.lower()
  38.                         tower_failed = False
  39.                     # 1+ success 1+ failed
  40.                     elif i in [2, 3, 4, 5]:
  41.                         if i == 2:
  42.                             tdelta += 1
  43.  
  44.                         if i in [2, 3]:
  45.                             tower_status = StatusChoice.successful.value.lower()
  46.                             tower_failed = False
  47.                         else:
  48.                             tower_status = StatusChoice.failed.value.lower()
  49.                             tower_failed = True
  50.                     # 0 success 1+ failed
  51.                     elif i in [6, 7]:
  52.                         if i == 6:
  53.                             tdelta += 1
  54.                         tower_status = StatusChoice.failed.value.lower()
  55.                         tower_failed = True
  56.                     # 0 success 0 failed
  57.                     elif i == 15:
  58.                         tdelta += 1
  59.                         continue
  60.                     else:
  61.                         tdelta += 1
  62.                         tower_status = StatusChoice.successful.value.lower()
  63.                         tower_failed = False
  64.  
  65.                     tower_started = date - timedelta(days=tdelta)
  66.                     tower_elapsed = random.randint(1, 60)
  67.                     tower_finished = tower_started + timedelta(seconds=tower_elapsed)
  68.                     latest_copy_size = initial_repository_size + random.randint(10485760, 104857600)  # between 10 and 100 MB
  69.                     repository_size = initial_repository_size + random.randint(10485760, 104857600)  # between 10 and 100 MB
  70.                     total_size = repository_size + latest_copy_size
  71.  
  72.                     job_kwargs = {
  73.                         'backup': backup,
  74.                         'tower_job_id': random.randint(1, 999999),
  75.                         'tower_launch_type': LaunchTypeChoice.scheduled.value.lower(),
  76.                         'tower_status': tower_status,
  77.                         'tower_failed': tower_failed,
  78.                         'tower_started': tower_started,
  79.                         'tower_finished': tower_finished,
  80.                         'tower_elapsed': tower_elapsed,
  81.                         'tower_job_explanation': f'Test Job {i}',
  82.                         'repository_size': repository_size,
  83.                         'latest_copy_size': latest_copy_size,
  84.                         'total_size': total_size,
  85.                         'cache_size': 0,
  86.                     }
  87.  
  88.                     backup_jobs.append(Job(**job_kwargs))
  89.             jobs.extend(backup_jobs)
  90.         Job.active.bulk_create(jobs)
  91.  
  92.     def handle(self, *args, **options):
  93.         from ...interfaces import AuthInterface, InfrastructureInterface
  94.         # Models
  95.  
  96.         User = apps.get_model('backupnerauth', 'User')
  97.         Key = apps.get_model('backupnerkeys', 'Key')
  98.         Node = apps.get_model('infrastructure', 'Node')
  99.         Storage = apps.get_model('backupnerstorages', 'Storage')
  100.         Secret = apps.get_model('backupnersecrets', 'Secret')
  101.         Project = apps.get_model('backupnerprojects', 'Project')
  102.         MariaDBServer = apps.get_model('backupnerdsmariadb', 'Server')
  103.         MariaDBService = apps.get_model('backupnerdsmariadb', 'Service')
  104.         MariaDBConnection = apps.get_model('backupnerdsmariadb', 'Connection')
  105.         MariaDBDataSource = apps.get_model('backupnerdsmariadb', 'DataSource')
  106.         PostgreSQLServer = apps.get_model('backupnerdspostgresql', 'Server')
  107.         PostgreSQLService = apps.get_model('backupnerdspostgresql', 'Service')
  108.         PostgreSQLConnection = apps.get_model('backupnerdspostgresql', 'Connection')
  109.         PostgreSQLDataSource = apps.get_model('backupnerdspostgresql', 'DataSource')
  110.         SSHServer = apps.get_model('backupnerdsssh', 'Server')
  111.         SSHService = apps.get_model('backupnerdsssh', 'Service')
  112.         SSHConnection = apps.get_model('backupnerdsssh', 'Connection')
  113.         SSHDataSource = apps.get_model('backupnerdsssh', 'DataSource')
  114.  
  115.         if not IS_PROD and not Secret.active.exists():
  116.  
  117.             with transaction.atomic():
  118.  
  119.                 # Create Super User
  120.  
  121.                 superuser_email = 'admin@backupner.local'
  122.                 superuser = User.active.create_superuser(**{
  123.                     'username': 'admin',
  124.                     'email': superuser_email,
  125.                     'first_name': 'Backupner',
  126.                     'last_name': 'Admin',
  127.                     'password': 'backupnerpassword1234',
  128.                     'is_public_profile': False,
  129.                 })
  130.                 EmailAddress.objects.create(user=superuser, email=superuser_email, primary=True, verified=True)
  131.  
  132.                 # Create Test User
  133.  
  134.                 test_user_email = 'user@backupner.local'
  135.                 test_user = User.active.create_user(username='user', email=test_user_email, password='backupnerpassword1234', first_name='John', last_name='Doe', is_staff=False,
  136.                                                     is_superuser=False)
  137.                 AuthInterface.create_account(user_uuid=test_user.uuid)
  138.                 test_user_account_uuid = test_user.account.uuid
  139.                 Key.active.filter(id=1).update(account_uuid=test_user_account_uuid)
  140.                 EmailAddress.objects.create(user=test_user, email=test_user_email, primary=True, verified=True)
  141.  
  142.                 # Nodes
  143.  
  144.                 service_provider_codes = InfrastructureInterface.get_service_provider_codes()
  145.  
  146.                 Node.active.bulk_create([
  147.                     Node(hostname="s1-dc1.example.com", data_center=service_provider_codes[0], ip='192.0.2.1', api_url='http://localhost/api/', useful_storage_capacity=500),
  148.                     Node(hostname="s2-dc2.example.com", data_center=service_provider_codes[1], ip='192.0.2.2', api_url='http://localhost/api/', useful_storage_capacity=600),
  149.                     Node(hostname="s3-dc3.example.com", data_center=service_provider_codes[2], ip='192.0.2.3', api_url='http://localhost/api/', useful_storage_capacity=700),
  150.                     Node(hostname="s4-dc4.example.com", data_center=service_provider_codes[3], ip='192.0.2.4', api_url='http://localhost/api/', useful_storage_capacity=800),
  151.                     Node(hostname="s5-dc5.example.com", data_center=service_provider_codes[4], ip='192.0.2.5', api_url='http://localhost/api/', useful_storage_capacity=900),
  152.                     Node(hostname="s6-dc6.example.com", data_center=service_provider_codes[5], ip='192.0.2.6', api_url='http://localhost/api/', useful_storage_capacity=1000),
  153.                     Node(hostname="s7-dc7.example.com", data_center=service_provider_codes[6], ip='192.0.2.7', api_url='http://localhost/api/', useful_storage_capacity=1100),
  154.                     Node(hostname="s8-dc8.example.com", data_center=service_provider_codes[7], ip='192.0.2.8', api_url='http://localhost/api/', useful_storage_capacity=1200),
  155.                     Node(hostname="s9-dc1.example.com", data_center=service_provider_codes[0], ip='192.0.2.9', api_url='http://localhost/api/', useful_storage_capacity=1500),
  156.                     Node(hostname="s10-dc1.example.com", data_center=service_provider_codes[0], ip='192.0.2.10', api_url='http://localhost/api/', useful_storage_capacity=2500),
  157.                     Node(hostname="s11-dc2.example.com", data_center=service_provider_codes[1], ip='192.0.2.11', api_url='http://localhost/api/', useful_storage_capacity=3500),
  158.                     Node(hostname="s12-dc2.example.com", data_center=service_provider_codes[1], ip='192.0.2.12', api_url='http://localhost/api/', useful_storage_capacity=4500),
  159.                     Node(hostname="s13-dc3.example.com", data_center=service_provider_codes[2], ip='192.0.2.13', api_url='http://localhost/api/', useful_storage_capacity=5500),
  160.                     Node(hostname="s14-dc3.example.com", data_center=service_provider_codes[2], ip='192.0.2.14', api_url='http://localhost/api/', useful_storage_capacity=4500),
  161.                     Node(hostname="s15-dc4.example.com", data_center=service_provider_codes[3], ip='192.0.2.15', api_url='http://localhost/api/', useful_storage_capacity=3500),
  162.                     Node(hostname="s16-dc4.example.com", data_center=service_provider_codes[3], ip='192.0.2.16', api_url='http://localhost/api/', useful_storage_capacity=4500),
  163.                     Node(hostname="s17-dc5.example.com", data_center=service_provider_codes[4], ip='192.0.2.17', api_url='http://localhost/api/', useful_storage_capacity=5500),
  164.                     Node(hostname="s18-dc5.example.com", data_center=service_provider_codes[4], ip='192.0.2.18', api_url='http://localhost/api/', useful_storage_capacity=4500),
  165.                     Node(hostname="s19-dc6.example.com", data_center=service_provider_codes[5], ip='192.0.2.19', api_url='http://localhost/api/', useful_storage_capacity=5500),
  166.                     Node(hostname="s20-dc6.example.com", data_center=service_provider_codes[5], ip='192.0.2.20', api_url='http://localhost/api/', useful_storage_capacity=2500),
  167.                     Node(hostname="s21-dc7.example.com", data_center=service_provider_codes[6], ip='192.0.2.21', api_url='http://localhost/api/', useful_storage_capacity=2500),
  168.                     Node(hostname="s22-dc7.example.com", data_center=service_provider_codes[6], ip='192.0.2.22', api_url='http://localhost/api/', useful_storage_capacity=1500),
  169.                     Node(hostname="s23-dc8.example.com", data_center=service_provider_codes[7], ip='192.0.2.23', api_url='http://localhost/api/', useful_storage_capacity=1500),
  170.                     Node(hostname="s24-dc8.example.com", data_center=service_provider_codes[7], ip='192.0.2.24', api_url='http://localhost/api/', useful_storage_capacity=500),
  171.                 ])
  172.  
  173.                 # Secrets
  174.  
  175.                 secret_uuids = []
  176.                 public_key_uuid = test_user.account.default_key_uuid
  177.                 Key = apps.get_model('backupnerkeys', 'Key')
  178.                 public_key = bytes(Key.active.get(uuid=public_key_uuid).data)
  179.                 for i in range(0, 48):
  180.                     encrypted_data = encrypt_data(data=f'secret{i}', public_key=public_key)
  181.                     secret_uuid = SecretInterface.create_secret(encrypted_data=encrypted_data)
  182.                     secret_uuids.append(secret_uuid)
  183.  
  184.                 # Project 1
  185.  
  186.                 project_1 = Project.active.create(name='Project Iron', account_uuid=test_user_account_uuid, dedicated_space=10, sla_plan='iron')
  187.                 project_1_uuid = project_1.uuid
  188.  
  189.                 # Project 1 Allocated Resources
  190.  
  191.                 Storage.active.create(account_uuid=test_user_account_uuid, project_uuid=project_1_uuid, service_provider=service_provider_codes[0])
  192.  
  193.                 # Project 1 Servers
  194.  
  195.                 project_1_mariadb_servers = MariaDBServer.active.bulk_create([
  196.                     MariaDBServer(hostname='clientserver.example.com'),
  197.                     MariaDBServer(hostname='clientserver2.example.com'),
  198.                     MariaDBServer(hostname='clientserver3.example.com'),
  199.                     MariaDBServer(hostname='clientserver4.example.com'),
  200.                 ])
  201.                 project_1_postgresql_servers = PostgreSQLServer.active.bulk_create([
  202.                     PostgreSQLServer(hostname='clientserver.example.com'),
  203.                     PostgreSQLServer(hostname='clientserver2.example.com'),
  204.                     PostgreSQLServer(hostname='clientserver3.example.com'),
  205.                     PostgreSQLServer(hostname='clientserver4.example.com'),
  206.                 ])
  207.                 project_1_ssh_servers = SSHServer.active.bulk_create([
  208.                     SSHServer(hostname='clientserver.example.com'),
  209.                     SSHServer(hostname='clientserver2.example.com'),
  210.                     SSHServer(hostname='clientserver3.example.com'),
  211.                     SSHServer(hostname='clientserver4.example.com'),
  212.                 ])
  213.  
  214.                 # Project 1 Services
  215.  
  216.                 project_1_mariadb_services = MariaDBService.active.bulk_create([
  217.                     MariaDBService(name='Project 1 MariaDB Server 1', port=3306, project_uuid=project_1.uuid, server=project_1_mariadb_servers[0], default_compression='lz4',
  218.                                    default_frequency='no'),
  219.                     MariaDBService(name='Project 1 MariaDB Server 2', port=3306, project_uuid=project_1.uuid, server=project_1_mariadb_servers[1], default_compression='zstd22',
  220.                                    default_frequency='daily'),
  221.                     MariaDBService(name='Project 1 MariaDB Server 3', port=3306, project_uuid=project_1.uuid, server=project_1_mariadb_servers[2], default_compression='zlib9',
  222.                                    default_frequency='weekly'),
  223.                     MariaDBService(name='Project 1 MariaDB Server 4', port=3306, project_uuid=project_1.uuid, server=project_1_mariadb_servers[3], default_compression='lzma6',
  224.                                    default_frequency='daily'),
  225.                 ])
  226.                 project_1_postgresql_services = PostgreSQLService.active.bulk_create([
  227.                     PostgreSQLService(name='Project 1 PostgreSQL Server 1', port=5432, project_uuid=project_1.uuid, server=project_1_postgresql_servers[0],
  228.                                       default_compression='lz4', default_frequency='no'),
  229.                     PostgreSQLService(name='Project 1 PostgreSQL Server 2', port=5432, project_uuid=project_1.uuid, server=project_1_postgresql_servers[1],
  230.                                       default_compression='zstd22', default_frequency='daily'),
  231.                     PostgreSQLService(name='Project 1 PostgreSQL Server 3', port=5432, project_uuid=project_1.uuid, server=project_1_postgresql_servers[2],
  232.                                       default_compression='zlib9', default_frequency='weekly'),
  233.                     PostgreSQLService(name='Project 1 PostgreSQL Server 4', port=5432, project_uuid=project_1.uuid, server=project_1_postgresql_servers[3],
  234.                                       default_compression='lzma6', default_frequency='daily'),
  235.                 ])
  236.                 project_1_ssh_services = SSHService.active.bulk_create([
  237.                     SSHService(name='Project 1 SSH Server 1', port=22, project_uuid=project_1.uuid, server=project_1_ssh_servers[0],
  238.                                default_compression='lz4', default_frequency='no'),
  239.                     SSHService(name='Project 1 SSH Server 2', port=22, project_uuid=project_1.uuid, server=project_1_ssh_servers[1],
  240.                                default_compression='zstd22', default_frequency='daily'),
  241.                     SSHService(name='Project 1 SSH Server 3', port=22, project_uuid=project_1.uuid, server=project_1_ssh_servers[2],
  242.                                default_compression='zlib9', default_frequency='weekly'),
  243.                     SSHService(name='Project 1 SSH Server 4', port=22, project_uuid=project_1.uuid, server=project_1_ssh_servers[3],
  244.                                default_compression='lzma6', default_frequency='daily'),
  245.                 ])
  246.  
  247.                 # Project 1 Connections
  248.  
  249.                 project_1_mariadb_connections = MariaDBConnection.active.bulk_create([
  250.                     MariaDBConnection(user='user1', password_uuid=secret_uuids[0], service=project_1_mariadb_services[0]),
  251.                     MariaDBConnection(user='user2', password_uuid=secret_uuids[1], service=project_1_mariadb_services[1]),
  252.                     MariaDBConnection(user='user3', password_uuid=secret_uuids[2], service=project_1_mariadb_services[2]),
  253.                     MariaDBConnection(user='user4', password_uuid=secret_uuids[3], service=project_1_mariadb_services[3]),
  254.                 ])
  255.                 project_1_postgresql_connections = PostgreSQLConnection.active.bulk_create([
  256.                     PostgreSQLConnection(user='user5', password_uuid=secret_uuids[4], service=project_1_postgresql_services[0]),
  257.                     PostgreSQLConnection(user='user6', password_uuid=secret_uuids[5], service=project_1_postgresql_services[1]),
  258.                     PostgreSQLConnection(user='user7', password_uuid=secret_uuids[6], service=project_1_postgresql_services[2]),
  259.                     PostgreSQLConnection(user='user8', password_uuid=secret_uuids[7], service=project_1_postgresql_services[3]),
  260.                 ])
  261.                 project_1_ssh_connections = SSHConnection.active.bulk_create([
  262.                     SSHConnection(user='user9', auth_type='key', key_uuid=secret_uuids[8], service=project_1_ssh_services[0]),
  263.                     SSHConnection(user='user10', auth_type='password', password_uuid=secret_uuids[9], service=project_1_ssh_services[1]),
  264.                     SSHConnection(user='user11', auth_type='key', key_uuid=secret_uuids[10], service=project_1_ssh_services[2]),
  265.                     SSHConnection(user='user12', auth_type='password', password_uuid=secret_uuids[11], service=project_1_ssh_services[3]),
  266.                 ])
  267.  
  268.                 # Project 1 Data Sources
  269.  
  270.                 project_1_mariadb_data_sources = MariaDBDataSource.active.bulk_create([
  271.                     MariaDBDataSource(name='mariadbdatabase1p1', connection=project_1_mariadb_connections[0]),
  272.                     MariaDBDataSource(name='mariadbdatabase2p1', connection=project_1_mariadb_connections[1]),
  273.                     MariaDBDataSource(name='mariadbdatabase3p1', connection=project_1_mariadb_connections[2]),
  274.                     MariaDBDataSource(name='mariadbdatabase4p1', connection=project_1_mariadb_connections[3]),
  275.                 ])
  276.                 project_1_postgresql_data_sources = PostgreSQLDataSource.active.bulk_create([
  277.                     PostgreSQLDataSource(name='postgresqldatabase1p1', connection=project_1_postgresql_connections[0]),
  278.                     PostgreSQLDataSource(name='postgresqldatabase2p1', connection=project_1_postgresql_connections[1]),
  279.                     PostgreSQLDataSource(name='postgresqldatabase3p1', connection=project_1_postgresql_connections[2]),
  280.                     PostgreSQLDataSource(name='postgresqldatabase4p1', connection=project_1_postgresql_connections[3]),
  281.                 ])
  282.                 project_1_ssh_data_sources = SSHDataSource.active.bulk_create([
  283.                     SSHDataSource(directory='/path/directory1p1', connection=project_1_ssh_connections[0]),
  284.                     SSHDataSource(directory='/path/directory2p1', connection=project_1_ssh_connections[1]),
  285.                     SSHDataSource(directory='/path/directory3p1', connection=project_1_ssh_connections[2]),
  286.                     SSHDataSource(directory='/path/directory4p1', connection=project_1_ssh_connections[3]),
  287.                 ])
  288.  
  289.                 # Project 1 Directories
  290.                 # Project 1 Backups
  291.                 # Project 1 Jobs
  292.                 project_1_data_sources = project_1_mariadb_data_sources + project_1_postgresql_data_sources + project_1_ssh_data_sources
  293.                 self.create_backup_processes_and_jobs(project_1_data_sources)
  294.  
  295.                 # Project 2
  296.  
  297.                 project_2 = Project.active.create(name='Project Bronze', account_uuid=test_user_account_uuid, dedicated_space=25, sla_plan='bronze')
  298.                 project_2_uuid = project_2.uuid
  299.  
  300.                 # Project 2 Allocated Resources
  301.  
  302.                 Storage.active.bulk_create([
  303.                     Storage(account_uuid=test_user_account_uuid, project_uuid=project_2_uuid, service_provider=service_provider_codes[0]),
  304.                     Storage(account_uuid=test_user_account_uuid, project_uuid=project_2_uuid, service_provider=service_provider_codes[1]),
  305.                     Storage(account_uuid=test_user_account_uuid, project_uuid=project_2_uuid, service_provider=service_provider_codes[2]),
  306.                 ])
  307.  
  308.                 # Project 2 Servers
  309.  
  310.                 project_2_mariadb_servers = MariaDBServer.active.bulk_create([
  311.                     MariaDBServer(hostname='clientserver5.example.com'),
  312.                     MariaDBServer(hostname='clientserver6.example.com'),
  313.                     MariaDBServer(hostname='clientserver7.example.com'),
  314.                     MariaDBServer(hostname='clientserver8.example.com'),
  315.                 ])
  316.                 project_2_postgresql_servers = PostgreSQLServer.active.bulk_create([
  317.                     PostgreSQLServer(hostname='clientserver5.example.com'),
  318.                     PostgreSQLServer(hostname='clientserver6.example.com'),
  319.                     PostgreSQLServer(hostname='clientserver7.example.com'),
  320.                     PostgreSQLServer(hostname='clientserver8.example.com'),
  321.                 ])
  322.                 project_2_ssh_servers = SSHServer.active.bulk_create([
  323.                     SSHServer(hostname='clientserver5.example.com'),
  324.                     SSHServer(hostname='clientserver6.example.com'),
  325.                     SSHServer(hostname='clientserver7.example.com'),
  326.                     SSHServer(hostname='clientserver8.example.com'),
  327.                 ])
  328.  
  329.                 # Project 2 Services
  330.  
  331.                 project_2_mariadb_services = MariaDBService.active.bulk_create([
  332.                     MariaDBService(name='Project 2 MariaDB Server 1', port=3306, project_uuid=project_2.uuid, server=project_2_mariadb_servers[0], default_compression='lz4',
  333.                                    default_frequency='no'),
  334.                     MariaDBService(name='Project 2 MariaDB Server 2', port=3306, project_uuid=project_2.uuid, server=project_2_mariadb_servers[1], default_compression='zstd22',
  335.                                    default_frequency='daily'),
  336.                     MariaDBService(name='Project 2 MariaDB Server 3', port=3306, project_uuid=project_2.uuid, server=project_2_mariadb_servers[2], default_compression='zlib9',
  337.                                    default_frequency='weekly'),
  338.                     MariaDBService(name='Project 2 MariaDB Server 4', port=3306, project_uuid=project_2.uuid, server=project_2_mariadb_servers[3], default_compression='lzma6',
  339.                                    default_frequency='daily'),
  340.                 ])
  341.                 project_2_postgresql_services = PostgreSQLService.active.bulk_create([
  342.                     PostgreSQLService(name='Project 2 PostgreSQL Server 1', port=5432, project_uuid=project_2.uuid, server=project_2_postgresql_servers[0],
  343.                                       default_compression='lz4', default_frequency='no'),
  344.                     PostgreSQLService(name='Project 2 PostgreSQL Server 2', port=5432, project_uuid=project_2.uuid, server=project_2_postgresql_servers[1],
  345.                                       default_compression='zstd22', default_frequency='daily'),
  346.                     PostgreSQLService(name='Project 2 PostgreSQL Server 3', port=5432, project_uuid=project_2.uuid, server=project_2_postgresql_servers[2],
  347.                                       default_compression='zlib9', default_frequency='weekly'),
  348.                     PostgreSQLService(name='Project 2 PostgreSQL Server 4', port=5432, project_uuid=project_2.uuid, server=project_2_postgresql_servers[3],
  349.                                       default_compression='lzma6', default_frequency='daily'),
  350.                 ])
  351.                 project_2_ssh_services = SSHService.active.bulk_create([
  352.                     SSHService(name='Project 2 SSH Server 1', port=22, project_uuid=project_2.uuid, server=project_2_ssh_servers[0],
  353.                                default_compression='lz4', default_frequency='no'),
  354.                     SSHService(name='Project 2 SSH Server 2', port=22, project_uuid=project_2.uuid, server=project_2_ssh_servers[1],
  355.                                default_compression='zstd22', default_frequency='daily'),
  356.                     SSHService(name='Project 2 SSH Server 3', port=22, project_uuid=project_2.uuid, server=project_2_ssh_servers[2],
  357.                                default_compression='zlib9', default_frequency='weekly'),
  358.                     SSHService(name='Project 2 SSH Server 4', port=22, project_uuid=project_2.uuid, server=project_2_ssh_servers[3],
  359.                                default_compression='lzma6', default_frequency='daily'),
  360.                 ])
  361.  
  362.                 # Project 2 Connections
  363.  
  364.                 project_2_mariadb_connections = MariaDBConnection.active.bulk_create([
  365.                     MariaDBConnection(user='user1', password_uuid=secret_uuids[12], service=project_2_mariadb_services[0]),
  366.                     MariaDBConnection(user='user2', password_uuid=secret_uuids[13], service=project_2_mariadb_services[1]),
  367.                     MariaDBConnection(user='user3', password_uuid=secret_uuids[14], service=project_2_mariadb_services[2]),
  368.                     MariaDBConnection(user='user4', password_uuid=secret_uuids[15], service=project_2_mariadb_services[3]),
  369.                 ])
  370.                 project_2_postgresql_connections = PostgreSQLConnection.active.bulk_create([
  371.                     PostgreSQLConnection(user='user5', password_uuid=secret_uuids[16], service=project_2_postgresql_services[0]),
  372.                     PostgreSQLConnection(user='user6', password_uuid=secret_uuids[17], service=project_2_postgresql_services[1]),
  373.                     PostgreSQLConnection(user='user7', password_uuid=secret_uuids[18], service=project_2_postgresql_services[2]),
  374.                     PostgreSQLConnection(user='user8', password_uuid=secret_uuids[19], service=project_2_postgresql_services[3]),
  375.                 ])
  376.                 project_2_ssh_connections = SSHConnection.active.bulk_create([
  377.                     SSHConnection(user='user9', auth_type='key', key_uuid=secret_uuids[20], service=project_2_ssh_services[0]),
  378.                     SSHConnection(user='user10', auth_type='password', password_uuid=secret_uuids[21], service=project_2_ssh_services[1]),
  379.                     SSHConnection(user='user11', auth_type='key', key_uuid=secret_uuids[22], service=project_2_ssh_services[2]),
  380.                     SSHConnection(user='user12', auth_type='password', password_uuid=secret_uuids[23], service=project_2_ssh_services[3]),
  381.                 ])
  382.  
  383.                 # Project 2 Data Sources
  384.  
  385.                 project_2_mariadb_data_sources = MariaDBDataSource.active.bulk_create([
  386.                     MariaDBDataSource(name='mariadbdatabase1p2', connection=project_2_mariadb_connections[0]),
  387.                     MariaDBDataSource(name='mariadbdatabase2p2', connection=project_2_mariadb_connections[1]),
  388.                     MariaDBDataSource(name='mariadbdatabase3p2', connection=project_2_mariadb_connections[2]),
  389.                     MariaDBDataSource(name='mariadbdatabase4p2', connection=project_2_mariadb_connections[3]),
  390.                 ])
  391.                 project_2_postgresql_data_sources = PostgreSQLDataSource.active.bulk_create([
  392.                     PostgreSQLDataSource(name='postgresqldatabase1p2', connection=project_2_postgresql_connections[0]),
  393.                     PostgreSQLDataSource(name='postgresqldatabase2p2', connection=project_2_postgresql_connections[1]),
  394.                     PostgreSQLDataSource(name='postgresqldatabase3p2', connection=project_2_postgresql_connections[2]),
  395.                     PostgreSQLDataSource(name='postgresqldatabase4p2', connection=project_2_postgresql_connections[3]),
  396.                 ])
  397.                 project_2_ssh_data_sources = SSHDataSource.active.bulk_create([
  398.                     SSHDataSource(directory='/path/directory1p2', connection=project_2_ssh_connections[0]),
  399.                     SSHDataSource(directory='/path/directory2p2', connection=project_2_ssh_connections[1]),
  400.                     SSHDataSource(directory='/path/directory3p2', connection=project_2_ssh_connections[2]),
  401.                     SSHDataSource(directory='/path/directory4p2', connection=project_2_ssh_connections[3]),
  402.                 ])
  403.  
  404.                 # Project 2 Directories
  405.                 # Project 2 Backups
  406.                 # Project 2 Jobs
  407.                 project_2_data_sources = project_2_mariadb_data_sources + project_2_postgresql_data_sources + project_2_ssh_data_sources
  408.                 self.create_backup_processes_and_jobs(project_2_data_sources)
  409.  
  410.                 # Project 3
  411.  
  412.                 project_3 = Project.active.create(name='Project Silver', account_uuid=test_user_account_uuid, dedicated_space=50, sla_plan='silver')
  413.                 project_3_uuid = project_3.uuid
  414.  
  415.                 # Project 3 Allocated Resources
  416.  
  417.                 Storage.active.bulk_create([
  418.                     Storage(account_uuid=test_user_account_uuid, project_uuid=project_3_uuid, service_provider=service_provider_codes[0]),
  419.                     Storage(account_uuid=test_user_account_uuid, project_uuid=project_3_uuid, service_provider=service_provider_codes[1]),
  420.                     Storage(account_uuid=test_user_account_uuid, project_uuid=project_3_uuid, service_provider=service_provider_codes[2]),
  421.                     Storage(account_uuid=test_user_account_uuid, project_uuid=project_3_uuid, service_provider=service_provider_codes[3]),
  422.                     Storage(account_uuid=test_user_account_uuid, project_uuid=project_3_uuid, service_provider=service_provider_codes[4]),
  423.                 ])
  424.  
  425.                 # Project 3 Servers
  426.  
  427.                 project_3_mariadb_servers = MariaDBServer.active.bulk_create([
  428.                     MariaDBServer(hostname='clientserver9.example.com'),
  429.                     MariaDBServer(hostname='clientserver10.example.com'),
  430.                     MariaDBServer(hostname='clientserver11.example.com'),
  431.                     MariaDBServer(hostname='clientserver12.example.com'),
  432.                 ])
  433.                 project_3_postgresql_servers = PostgreSQLServer.active.bulk_create([
  434.                     PostgreSQLServer(hostname='clientserver9.example.com'),
  435.                     PostgreSQLServer(hostname='clientserver10.example.com'),
  436.                     PostgreSQLServer(hostname='clientserver11.example.com'),
  437.                     PostgreSQLServer(hostname='clientserver12.example.com'),
  438.                 ])
  439.                 project_3_ssh_servers = SSHServer.active.bulk_create([
  440.                     SSHServer(hostname='clientserver9.example.com'),
  441.                     SSHServer(hostname='clientserver10.example.com'),
  442.                     SSHServer(hostname='clientserver11.example.com'),
  443.                     SSHServer(hostname='clientserver12.example.com'),
  444.                 ])
  445.  
  446.                 # Project 3 Services
  447.  
  448.                 project_3_mariadb_services = MariaDBService.active.bulk_create([
  449.                     MariaDBService(name='Project 3 MariaDB Server 1', port=3306, project_uuid=project_3.uuid, server=project_3_mariadb_servers[0], default_compression='lz4',
  450.                                    default_frequency='no'),
  451.                     MariaDBService(name='Project 3 MariaDB Server 2', port=3306, project_uuid=project_3.uuid, server=project_3_mariadb_servers[1], default_compression='zstd22',
  452.                                    default_frequency='daily'),
  453.                     MariaDBService(name='Project 3 MariaDB Server 3', port=3306, project_uuid=project_3.uuid, server=project_3_mariadb_servers[2], default_compression='zlib9',
  454.                                    default_frequency='weekly'),
  455.                     MariaDBService(name='Project 3 MariaDB Server 4', port=3306, project_uuid=project_3.uuid, server=project_3_mariadb_servers[3], default_compression='lzma6',
  456.                                    default_frequency='daily'),
  457.                 ])
  458.                 project_3_postgresql_services = PostgreSQLService.active.bulk_create([
  459.                     PostgreSQLService(name='Project 3 PostgreSQL Server 1', port=5432, project_uuid=project_3.uuid, server=project_3_postgresql_servers[0],
  460.                                       default_compression='lz4', default_frequency='no'),
  461.                     PostgreSQLService(name='Project 3 PostgreSQL Server 2', port=5432, project_uuid=project_3.uuid, server=project_3_postgresql_servers[1],
  462.                                       default_compression='zstd22', default_frequency='daily'),
  463.                     PostgreSQLService(name='Project 3 PostgreSQL Server 3', port=5432, project_uuid=project_3.uuid, server=project_3_postgresql_servers[2],
  464.                                       default_compression='zlib9', default_frequency='weekly'),
  465.                     PostgreSQLService(name='Project 3 PostgreSQL Server 4', port=5432, project_uuid=project_3.uuid, server=project_3_postgresql_servers[3],
  466.                                       default_compression='lzma6', default_frequency='daily'),
  467.                 ])
  468.                 project_3_ssh_services = SSHService.active.bulk_create([
  469.                     SSHService(name='Project 3 SSH Server 1', port=22, project_uuid=project_3.uuid, server=project_3_ssh_servers[0],
  470.                                default_compression='lz4', default_frequency='no'),
  471.                     SSHService(name='Project 3 SSH Server 2', port=22, project_uuid=project_3.uuid, server=project_3_ssh_servers[1],
  472.                                default_compression='zstd22', default_frequency='daily'),
  473.                     SSHService(name='Project 3 SSH Server 3', port=22, project_uuid=project_3.uuid, server=project_3_ssh_servers[2],
  474.                                default_compression='zlib9', default_frequency='weekly'),
  475.                     SSHService(name='Project 3 SSH Server 4', port=22, project_uuid=project_3.uuid, server=project_3_ssh_servers[3],
  476.                                default_compression='lzma6', default_frequency='daily'),
  477.                 ])
  478.  
  479.                 # Project 3 Connections
  480.  
  481.                 project_3_mariadb_connections = MariaDBConnection.active.bulk_create([
  482.                     MariaDBConnection(user='user1', password_uuid=secret_uuids[24], service=project_3_mariadb_services[0]),
  483.                     MariaDBConnection(user='user2', password_uuid=secret_uuids[25], service=project_3_mariadb_services[1]),
  484.                     MariaDBConnection(user='user3', password_uuid=secret_uuids[26], service=project_3_mariadb_services[2]),
  485.                     MariaDBConnection(user='user4', password_uuid=secret_uuids[27], service=project_3_mariadb_services[3]),
  486.                 ])
  487.                 project_3_postgresql_connections = PostgreSQLConnection.active.bulk_create([
  488.                     PostgreSQLConnection(user='user5', password_uuid=secret_uuids[28], service=project_3_postgresql_services[0]),
  489.                     PostgreSQLConnection(user='user6', password_uuid=secret_uuids[29], service=project_3_postgresql_services[1]),
  490.                     PostgreSQLConnection(user='user7', password_uuid=secret_uuids[30], service=project_3_postgresql_services[2]),
  491.                     PostgreSQLConnection(user='user8', password_uuid=secret_uuids[31], service=project_3_postgresql_services[3]),
  492.                 ])
  493.                 project_3_ssh_connections = SSHConnection.active.bulk_create([
  494.                     SSHConnection(user='user9', auth_type='key', key_uuid=secret_uuids[32], service=project_3_ssh_services[0]),
  495.                     SSHConnection(user='user10', auth_type='password', password_uuid=secret_uuids[33], service=project_3_ssh_services[1]),
  496.                     SSHConnection(user='user11', auth_type='key', key_uuid=secret_uuids[34], service=project_3_ssh_services[2]),
  497.                     SSHConnection(user='user12', auth_type='password', password_uuid=secret_uuids[35], service=project_3_ssh_services[3]),
  498.                 ])
  499.  
  500.                 # Project 3 Data Sources
  501.  
  502.                 project_3_mariadb_data_sources = MariaDBDataSource.active.bulk_create([
  503.                     MariaDBDataSource(name='mariadbdatabase1p3', connection=project_3_mariadb_connections[0]),
  504.                     MariaDBDataSource(name='mariadbdatabase2p3', connection=project_3_mariadb_connections[1]),
  505.                     MariaDBDataSource(name='mariadbdatabase3p3', connection=project_3_mariadb_connections[2]),
  506.                     MariaDBDataSource(name='mariadbdatabase4p3', connection=project_3_mariadb_connections[3]),
  507.                 ])
  508.                 project_3_postgresql_data_sources = PostgreSQLDataSource.active.bulk_create([
  509.                     PostgreSQLDataSource(name='postgresqldatabase1p3', connection=project_3_postgresql_connections[0]),
  510.                     PostgreSQLDataSource(name='postgresqldatabase2p3', connection=project_3_postgresql_connections[1]),
  511.                     PostgreSQLDataSource(name='postgresqldatabase3p3', connection=project_3_postgresql_connections[2]),
  512.                     PostgreSQLDataSource(name='postgresqldatabase4p3', connection=project_3_postgresql_connections[3]),
  513.                 ])
  514.                 project_3_ssh_data_sources = SSHDataSource.active.bulk_create([
  515.                     SSHDataSource(directory='/path/directory1p3', connection=project_3_ssh_connections[0]),
  516.                     SSHDataSource(directory='/path/directory2p3', connection=project_3_ssh_connections[1]),
  517.                     SSHDataSource(directory='/path/directory3p3', connection=project_3_ssh_connections[2]),
  518.                     SSHDataSource(directory='/path/directory4p3', connection=project_3_ssh_connections[3]),
  519.                 ])
  520.  
  521.                 # Project 3 Directories
  522.                 # Project 3 Backups
  523.                 # Project 3 Jobs
  524.                 project_3_data_sources = project_3_mariadb_data_sources + project_3_postgresql_data_sources + project_3_ssh_data_sources
  525.                 self.create_backup_processes_and_jobs(project_3_data_sources)
  526.  
  527.                 # Project 4
  528.  
  529.                 project_4 = Project.active.create(name='Project Gold', account_uuid=test_user_account_uuid, dedicated_space=100, sla_plan='gold')
  530.                 project_4_uuid = project_4.uuid
  531.  
  532.                 # Project 4 Allocated Resources
  533.  
  534.                 Storage.active.bulk_create([
  535.                     Storage(account_uuid=test_user_account_uuid, project_uuid=project_4_uuid, service_provider=service_provider_codes[0]),
  536.                     Storage(account_uuid=test_user_account_uuid, project_uuid=project_4_uuid, service_provider=service_provider_codes[1]),
  537.                     Storage(account_uuid=test_user_account_uuid, project_uuid=project_4_uuid, service_provider=service_provider_codes[2]),
  538.                     Storage(account_uuid=test_user_account_uuid, project_uuid=project_4_uuid, service_provider=service_provider_codes[3]),
  539.                     Storage(account_uuid=test_user_account_uuid, project_uuid=project_4_uuid, service_provider=service_provider_codes[4]),
  540.                     Storage(account_uuid=test_user_account_uuid, project_uuid=project_4_uuid, service_provider=service_provider_codes[5]),
  541.                     Storage(account_uuid=test_user_account_uuid, project_uuid=project_4_uuid, service_provider=service_provider_codes[6]),
  542.                 ])
  543.  
  544.                 # Project 4 Servers
  545.  
  546.                 project_4_mariadb_servers = MariaDBServer.active.bulk_create([
  547.                     MariaDBServer(hostname='clientserver13.example.com'),
  548.                     MariaDBServer(hostname='clientserver14.example.com'),
  549.                     MariaDBServer(hostname='clientserver15.example.com'),
  550.                     MariaDBServer(hostname='clientserver16.example.com'),
  551.                 ])
  552.                 project_4_postgresql_servers = PostgreSQLServer.active.bulk_create([
  553.                     PostgreSQLServer(hostname='clientserver13.example.com'),
  554.                     PostgreSQLServer(hostname='clientserver14.example.com'),
  555.                     PostgreSQLServer(hostname='clientserver15.example.com'),
  556.                     PostgreSQLServer(hostname='clientserver16.example.com'),
  557.                 ])
  558.                 project_4_ssh_servers = SSHServer.active.bulk_create([
  559.                     SSHServer(hostname='clientserver13.example.com'),
  560.                     SSHServer(hostname='clientserver14.example.com'),
  561.                     SSHServer(hostname='clientserver15.example.com'),
  562.                     SSHServer(hostname='clientserver16.example.com'),
  563.                 ])
  564.  
  565.                 # Project 4 Services
  566.  
  567.                 project_4_mariadb_services = MariaDBService.active.bulk_create([
  568.                     MariaDBService(name='Project 4 MariaDB Server 1', port=3306, project_uuid=project_4.uuid, server=project_4_mariadb_servers[0], default_compression='lz4',
  569.                                    default_frequency='no'),
  570.                     MariaDBService(name='Project 4 MariaDB Server 2', port=3306, project_uuid=project_4.uuid, server=project_4_mariadb_servers[1], default_compression='zstd22',
  571.                                    default_frequency='daily'),
  572.                     MariaDBService(name='Project 4 MariaDB Server 3', port=3306, project_uuid=project_4.uuid, server=project_4_mariadb_servers[2], default_compression='zlib9',
  573.                                    default_frequency='weekly'),
  574.                     MariaDBService(name='Project 4 MariaDB Server 4', port=3306, project_uuid=project_4.uuid, server=project_4_mariadb_servers[3], default_compression='lzma6',
  575.                                    default_frequency='daily'),
  576.                 ])
  577.                 project_4_postgresql_services = PostgreSQLService.active.bulk_create([
  578.                     PostgreSQLService(name='Project 4 PostgreSQL Server 1', port=5432, project_uuid=project_4.uuid, server=project_4_postgresql_servers[0],
  579.                                       default_compression='lz4', default_frequency='no'),
  580.                     PostgreSQLService(name='Project 4 PostgreSQL Server 2', port=5432, project_uuid=project_4.uuid, server=project_4_postgresql_servers[1],
  581.                                       default_compression='zstd22', default_frequency='daily'),
  582.                     PostgreSQLService(name='Project 4 PostgreSQL Server 3', port=5432, project_uuid=project_4.uuid, server=project_4_postgresql_servers[2],
  583.                                       default_compression='zlib9', default_frequency='weekly'),
  584.                     PostgreSQLService(name='Project 4 PostgreSQL Server 4', port=5432, project_uuid=project_4.uuid, server=project_4_postgresql_servers[3],
  585.                                       default_compression='lzma6', default_frequency='daily'),
  586.                 ])
  587.                 project_4_ssh_services = SSHService.active.bulk_create([
  588.                     SSHService(name='Project 4 SSH Server 1', port=22, project_uuid=project_4.uuid, server=project_4_ssh_servers[0],
  589.                                default_compression='lz4', default_frequency='no'),
  590.                     SSHService(name='Project 4 SSH Server 2', port=22, project_uuid=project_4.uuid, server=project_4_ssh_servers[1],
  591.                                default_compression='zstd22', default_frequency='daily'),
  592.                     SSHService(name='Project 4 SSH Server 3', port=22, project_uuid=project_4.uuid, server=project_4_ssh_servers[2],
  593.                                default_compression='zlib9', default_frequency='weekly'),
  594.                     SSHService(name='Project 4 SSH Server 4', port=22, project_uuid=project_4.uuid, server=project_4_ssh_servers[3],
  595.                                default_compression='lzma6', default_frequency='daily'),
  596.                 ])
  597.  
  598.                 # Project 4 Connections
  599.  
  600.                 project_4_mariadb_connections = MariaDBConnection.active.bulk_create([
  601.                     MariaDBConnection(user='user1', password_uuid=secret_uuids[36], service=project_4_mariadb_services[0]),
  602.                     MariaDBConnection(user='user2', password_uuid=secret_uuids[37], service=project_4_mariadb_services[1]),
  603.                     MariaDBConnection(user='user3', password_uuid=secret_uuids[38], service=project_4_mariadb_services[2]),
  604.                     MariaDBConnection(user='user4', password_uuid=secret_uuids[39], service=project_4_mariadb_services[3]),
  605.                 ])
  606.                 project_4_postgresql_connections = PostgreSQLConnection.active.bulk_create([
  607.                     PostgreSQLConnection(user='user5', password_uuid=secret_uuids[40], service=project_4_postgresql_services[0]),
  608.                     PostgreSQLConnection(user='user6', password_uuid=secret_uuids[41], service=project_4_postgresql_services[1]),
  609.                     PostgreSQLConnection(user='user7', password_uuid=secret_uuids[42], service=project_4_postgresql_services[2]),
  610.                     PostgreSQLConnection(user='user8', password_uuid=secret_uuids[43], service=project_4_postgresql_services[3]),
  611.                 ])
  612.                 project_4_ssh_connections = SSHConnection.active.bulk_create([
  613.                     SSHConnection(user='user9', auth_type='key', key_uuid=secret_uuids[44], service=project_4_ssh_services[0]),
  614.                     SSHConnection(user='user10', auth_type='password', password_uuid=secret_uuids[45], service=project_4_ssh_services[1]),
  615.                     SSHConnection(user='user11', auth_type='key', key_uuid=secret_uuids[46], service=project_4_ssh_services[2]),
  616.                     SSHConnection(user='user12', auth_type='password', password_uuid=secret_uuids[47], service=project_4_ssh_services[3]),
  617.                 ])
  618.  
  619.                 # Project 4 Data Sources
  620.  
  621.                 project_4_mariadb_data_sources = MariaDBDataSource.active.bulk_create([
  622.                     MariaDBDataSource(name='mariadbdatabase1p4', connection=project_4_mariadb_connections[0]),
  623.                     MariaDBDataSource(name='mariadbdatabase2p4', connection=project_4_mariadb_connections[1]),
  624.                     MariaDBDataSource(name='mariadbdatabase3p4', connection=project_4_mariadb_connections[2]),
  625.                     MariaDBDataSource(name='mariadbdatabase4p4', connection=project_4_mariadb_connections[3]),
  626.                 ])
  627.                 project_4_postgresql_data_sources = PostgreSQLDataSource.active.bulk_create([
  628.                     PostgreSQLDataSource(name='postgresqldatabase1p4', connection=project_4_postgresql_connections[0]),
  629.                     PostgreSQLDataSource(name='postgresqldatabase2p4', connection=project_4_postgresql_connections[1]),
  630.                     PostgreSQLDataSource(name='postgresqldatabase3p4', connection=project_4_postgresql_connections[2]),
  631.                     PostgreSQLDataSource(name='postgresqldatabase4p4', connection=project_4_postgresql_connections[3]),
  632.                 ])
  633.                 project_4_ssh_data_sources = SSHDataSource.active.bulk_create([
  634.                     SSHDataSource(directory='/path/directory1p4', connection=project_4_ssh_connections[0]),
  635.                     SSHDataSource(directory='/path/directory2p4', connection=project_4_ssh_connections[1]),
  636.                     SSHDataSource(directory='/path/directory3p4', connection=project_4_ssh_connections[2]),
  637.                     SSHDataSource(directory='/path/directory4p4', connection=project_4_ssh_connections[3]),
  638.                 ])
  639.  
  640.                 # Project 4 Directories
  641.                 # Project 4 Backups
  642.                 # Project 4 Jobs
  643.                 project_4_data_sources = project_4_mariadb_data_sources + project_4_postgresql_data_sources + project_4_ssh_data_sources
  644.                 self.create_backup_processes_and_jobs(project_4_data_sources)
  645.  
  646.                 self.stdout.write("Demo data was successfully loaded!", ending='\n')
  647.                 self.stdout.flush()
  648.                 time.sleep(0.01)
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top