"""
Setup DB with example data for tests
"""

from django.contrib.auth.hashers import make_password
from django.contrib.auth.models import User, Group
from django.core.management.base import BaseCommand

from api import models


class Command(BaseCommand):
    help = 'Setup DB with example data for tests'

    def handle(self, *args, **options):
        print('----    Creating Users    ----')
        User.objects.get_or_create(username='thomastest', password=make_password('imatestin'))
        thomas = User.objects.get(username='thomastest')

        User.objects.get_or_create(username='norbert', password=make_password('netzwerk'))
        norbert = User.objects.get(username='norbert')

        User.objects.get_or_create(username='stefan', password=make_password('helldesk'))
        stefan = User.objects.get(username='stefan')

        superuser = Group.objects.get(name='superuser')
        superuser.user_set.add(thomas)

        netadmin = Group.objects.get(name='netadmin')
        netadmin.user_set.add(norbert)

        support = Group.objects.get(name='support')
        support.user_set.add(stefan)

        print('----    Creating Inventory    ----')
        models.Inventory.objects.create(name='Example', hosts_file='web_nornir/nornir_config/example_config/hosts.yaml',
                                        groups_file='web_nornir/nornir_config/example_config/groups.yaml', type=1)
        models.Inventory.objects.create(name='INS Lab', hosts_file='web_nornir/nornir_config/inslab_config/hosts.yaml',
                                        groups_file='web_nornir/nornir_config/inslab_config/groups.yaml', type=1)

        print('----    Creating Job Templates    ----')
        models.JobTemplate.objects.create(name='hello_world', description='This prints a hello world',
                                          file_name='hello_world.py', created_by_id=1)
        models.JobTemplate.objects.create(name='Get CDP Neighbors', description='Lists all CDP neighbors',
                                          file_name='get_cdp_neighbors.py', created_by_id=1)
        models.JobTemplate.objects.create(name='Get Interfaces',
                                          description='Gets brief information about all interfaces, sh ip int br',
                                          file_name='get_interfaces.py', created_by_id=1)
        models.JobTemplate.objects.create(name='Ping Device',
                                          description='Pings a chosen network device and reports if reachable',
                                          file_name='ping.py', variables=['target'], created_by_id=1)
        models.JobTemplate.objects.create(name='Get Configuration', description='Gets all configuration from device',
                                          file_name='get_configuration.py', created_by_id=1)

        print('----    Creating Tasks    ----')
        models.Task.objects.create(name='Get Hello World', created_by_id=1, template_id=1, inventory_id=1)
        models.Task.objects.create(name='Get CDP neighbors of INS lab', created_by_id=2, template_id=2, inventory_id=2)
        models.Task.objects.create(name='Get interfaces of INS lab', created_by_id=2, template_id=3, inventory_id=2)

        print('----    ALL DONE!!    ----')

[((525, 564), 'django.contrib.auth.models.User.objects.get', 'User.objects.get', ([], {'username': '"""thomastest"""'}), "(username='thomastest')\n", (541, 564), False, 'from django.contrib.auth.models import User, Group\n'), ((678, 714), 'django.contrib.auth.models.User.objects.get', 'User.objects.get', ([], {'username': '"""norbert"""'}), "(username='norbert')\n", (694, 714), False, 'from django.contrib.auth.models import User, Group\n'), ((826, 861), 'django.contrib.auth.models.User.objects.get', 'User.objects.get', ([], {'username': '"""stefan"""'}), "(username='stefan')\n", (842, 861), False, 'from django.contrib.auth.models import User, Group\n'), ((885, 920), 'django.contrib.auth.models.Group.objects.get', 'Group.objects.get', ([], {'name': '"""superuser"""'}), "(name='superuser')\n", (902, 920), False, 'from django.contrib.auth.models import User, Group\n'), ((983, 1017), 'django.contrib.auth.models.Group.objects.get', 'Group.objects.get', ([], {'name': '"""netadmin"""'}), "(name='netadmin')\n", (1000, 1017), False, 'from django.contrib.auth.models import User, Group\n'), ((1079, 1112), 'django.contrib.auth.models.Group.objects.get', 'Group.objects.get', ([], {'name': '"""support"""'}), "(name='support')\n", (1096, 1112), False, 'from django.contrib.auth.models import User, Group\n'), ((1215, 1412), 'api.models.Inventory.objects.create', 'models.Inventory.objects.create', ([], {'name': '"""Example"""', 'hosts_file': '"""web_nornir/nornir_config/example_config/hosts.yaml"""', 'groups_file': '"""web_nornir/nornir_config/example_config/groups.yaml"""', 'type': '(1)'}), "(name='Example', hosts_file=\n    'web_nornir/nornir_config/example_config/hosts.yaml', groups_file=\n    'web_nornir/nornir_config/example_config/groups.yaml', type=1)\n", (1246, 1412), False, 'from api import models\n'), ((1453, 1648), 'api.models.Inventory.objects.create', 'models.Inventory.objects.create', ([], {'name': '"""INS Lab"""', 'hosts_file': '"""web_nornir/nornir_config/inslab_config/hosts.yaml"""', 'groups_file': '"""web_nornir/nornir_config/inslab_config/groups.yaml"""', 'type': '(1)'}), "(name='INS Lab', hosts_file=\n    'web_nornir/nornir_config/inslab_config/hosts.yaml', groups_file=\n    'web_nornir/nornir_config/inslab_config/groups.yaml', type=1)\n", (1484, 1648), False, 'from api import models\n'), ((1748, 1892), 'api.models.JobTemplate.objects.create', 'models.JobTemplate.objects.create', ([], {'name': '"""hello_world"""', 'description': '"""This prints a hello world"""', 'file_name': '"""hello_world.py"""', 'created_by_id': '(1)'}), "(name='hello_world', description=\n    'This prints a hello world', file_name='hello_world.py', created_by_id=1)\n", (1781, 1892), False, 'from api import models\n'), ((1940, 2098), 'api.models.JobTemplate.objects.create', 'models.JobTemplate.objects.create', ([], {'name': '"""Get CDP Neighbors"""', 'description': '"""Lists all CDP neighbors"""', 'file_name': '"""get_cdp_neighbors.py"""', 'created_by_id': '(1)'}), "(name='Get CDP Neighbors', description=\n    'Lists all CDP neighbors', file_name='get_cdp_neighbors.py',\n    created_by_id=1)\n", (1973, 2098), False, 'from api import models\n'), ((2142, 2329), 'api.models.JobTemplate.objects.create', 'models.JobTemplate.objects.create', ([], {'name': '"""Get Interfaces"""', 'description': '"""Gets brief information about all interfaces, sh ip int br"""', 'file_name': '"""get_interfaces.py"""', 'created_by_id': '(1)'}), "(name='Get Interfaces', description=\n    'Gets brief information about all interfaces, sh ip int br', file_name=\n    'get_interfaces.py', created_by_id=1)\n", (2175, 2329), False, 'from api import models\n'), ((2415, 2608), 'api.models.JobTemplate.objects.create', 'models.JobTemplate.objects.create', ([], {'name': '"""Ping Device"""', 'description': '"""Pings a chosen network device and reports if reachable"""', 'file_name': '"""ping.py"""', 'variables': "['target']", 'created_by_id': '(1)'}), "(name='Ping Device', description=\n    'Pings a chosen network device and reports if reachable', file_name=\n    'ping.py', variables=['target'], created_by_id=1)\n", (2448, 2608), False, 'from api import models\n'), ((2694, 2863), 'api.models.JobTemplate.objects.create', 'models.JobTemplate.objects.create', ([], {'name': '"""Get Configuration"""', 'description': '"""Gets all configuration from device"""', 'file_name': '"""get_configuration.py"""', 'created_by_id': '(1)'}), "(name='Get Configuration', description=\n    'Gets all configuration from device', file_name='get_configuration.py',\n    created_by_id=1)\n", (2727, 2863), False, 'from api import models\n'), ((2958, 3060), 'api.models.Task.objects.create', 'models.Task.objects.create', ([], {'name': '"""Get Hello World"""', 'created_by_id': '(1)', 'template_id': '(1)', 'inventory_id': '(1)'}), "(name='Get Hello World', created_by_id=1,\n    template_id=1, inventory_id=1)\n", (2984, 3060), False, 'from api import models\n'), ((3066, 3181), 'api.models.Task.objects.create', 'models.Task.objects.create', ([], {'name': '"""Get CDP neighbors of INS lab"""', 'created_by_id': '(2)', 'template_id': '(2)', 'inventory_id': '(2)'}), "(name='Get CDP neighbors of INS lab',\n    created_by_id=2, template_id=2, inventory_id=2)\n", (3092, 3181), False, 'from api import models\n'), ((3187, 3300), 'api.models.Task.objects.create', 'models.Task.objects.create', ([], {'name': '"""Get interfaces of INS lab"""', 'created_by_id': '(2)', 'template_id': '(3)', 'inventory_id': '(2)'}), "(name='Get interfaces of INS lab', created_by_id=\n    2, template_id=3, inventory_id=2)\n", (3213, 3300), False, 'from api import models\n'), ((479, 505), 'django.contrib.auth.hashers.make_password', 'make_password', (['"""imatestin"""'], {}), "('imatestin')\n", (492, 505), False, 'from django.contrib.auth.hashers import make_password\n'), ((632, 657), 'django.contrib.auth.hashers.make_password', 'make_password', (['"""netzwerk"""'], {}), "('netzwerk')\n", (645, 657), False, 'from django.contrib.auth.hashers import make_password\n'), ((781, 806), 'django.contrib.auth.hashers.make_password', 'make_password', (['"""helldesk"""'], {}), "('helldesk')\n", (794, 806), False, 'from django.contrib.auth.hashers import make_password\n')]