mirror of
https://github.com/ansible/awx.git
synced 2026-05-08 01:47:35 -02:30
Creating pre-loaded demo data
* Bootstrap some initial data if there is no default org * Renamed default org script appropriately
This commit is contained in:
@@ -1,27 +0,0 @@
|
|||||||
# Copyright (c) 2015 Ansible, Inc.
|
|
||||||
# All Rights Reserved
|
|
||||||
|
|
||||||
from django.core.management.base import BaseCommand
|
|
||||||
from crum import impersonate
|
|
||||||
from awx.main.models import User, Organization
|
|
||||||
|
|
||||||
|
|
||||||
class Command(BaseCommand):
|
|
||||||
"""Creates the default organization if and only if no organizations
|
|
||||||
exist in the system.
|
|
||||||
"""
|
|
||||||
help = 'Creates a default organization iff there are none.'
|
|
||||||
|
|
||||||
def handle(self, *args, **kwargs):
|
|
||||||
# Sanity check: Is there already an organization in the system?
|
|
||||||
if Organization.objects.count():
|
|
||||||
return
|
|
||||||
|
|
||||||
# Create a default organization as the first superuser found.
|
|
||||||
try:
|
|
||||||
superuser = User.objects.filter(is_superuser=True).order_by('pk')[0]
|
|
||||||
except IndexError:
|
|
||||||
superuser = None
|
|
||||||
with impersonate(superuser):
|
|
||||||
Organization.objects.create(name='Default')
|
|
||||||
print('Default organization added.')
|
|
||||||
47
awx/main/management/commands/create_preload_data.py
Normal file
47
awx/main/management/commands/create_preload_data.py
Normal file
@@ -0,0 +1,47 @@
|
|||||||
|
# Copyright (c) 2015 Ansible, Inc.
|
||||||
|
# All Rights Reserved
|
||||||
|
|
||||||
|
from django.core.management.base import BaseCommand
|
||||||
|
from crum import impersonate
|
||||||
|
from awx.main.models import User, Organization, Project, Inventory, Credential, Host, JobTemplate
|
||||||
|
|
||||||
|
|
||||||
|
class Command(BaseCommand):
|
||||||
|
"""Create preloaded data, intended for new installs
|
||||||
|
"""
|
||||||
|
help = 'Creates a preload tower data iff there is none.'
|
||||||
|
|
||||||
|
def handle(self, *args, **kwargs):
|
||||||
|
# Sanity check: Is there already an organization in the system?
|
||||||
|
if Organization.objects.count():
|
||||||
|
return
|
||||||
|
|
||||||
|
# Create a default organization as the first superuser found.
|
||||||
|
try:
|
||||||
|
superuser = User.objects.filter(is_superuser=True).order_by('pk')[0]
|
||||||
|
except IndexError:
|
||||||
|
superuser = None
|
||||||
|
with impersonate(superuser):
|
||||||
|
o = Organization.objects.create(name='Default')
|
||||||
|
p = Project.objects.create(name='Demo Project',
|
||||||
|
scm_type='git',
|
||||||
|
scm_url='https://github.com/ansible/ansible-tower-samples',
|
||||||
|
scm_update_on_launch=True,
|
||||||
|
scm_update_cache_timeout=0,
|
||||||
|
organization=o)
|
||||||
|
c = Credential.objects.create(name='Demo Credential',
|
||||||
|
username=superuser.username,
|
||||||
|
created_by=superuser)
|
||||||
|
c.owner_role.members.add(superuser)
|
||||||
|
i = Inventory.objects.create(name='Demo Inventory',
|
||||||
|
organization=o,
|
||||||
|
created_by=superuser)
|
||||||
|
h = Host.objects.create(name='localhost',
|
||||||
|
inventory=i,
|
||||||
|
variables="ansible_connection: local",
|
||||||
|
created_by=superuser)
|
||||||
|
jt = JobTemplate.objects.create(name='Demo Job Template',
|
||||||
|
project=p,
|
||||||
|
inventory=i,
|
||||||
|
credential=c)
|
||||||
|
print('Default organization added.')
|
||||||
Reference in New Issue
Block a user