def _mk_project_update(created=None): kwargs = {} if created: kwargs['created'] = created project = Project() project.save() return ProjectUpdate(project=project, **kwargs)
def handle(self, *args, **kwargs): changed = False # 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): with disable_computed_fields(): if not Organization.objects.exists(): o = Organization.objects.create(name='Default') p = Project( 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, ) p.save(skip_update=True) ssh_type = CredentialType.objects.filter(namespace='ssh').first() c = Credential.objects.create( credential_type=ssh_type, name='Demo Credential', inputs={'username': superuser.username}, created_by=superuser ) c.admin_role.members.add(superuser) public_galaxy_credential = Credential( name='Ansible Galaxy', managed_by_tower=True, credential_type=CredentialType.objects.get(kind='galaxy'), inputs={'url': 'https://galaxy.ansible.com/'}, ) public_galaxy_credential.save() o.galaxy_credentials.add(public_galaxy_credential) i = Inventory.objects.create(name='Demo Inventory', organization=o, created_by=superuser) Host.objects.create( name='localhost', inventory=i, variables="ansible_connection: local\nansible_python_interpreter: '{{ ansible_playbook_python }}'", created_by=superuser, ) jt = JobTemplate.objects.create(name='Demo Job Template', playbook='hello_world.yml', project=p, inventory=i) jt.credentials.add(c) print('Default organization added.') print('Demo Credential, Inventory, and Job Template added.') changed = True if changed: print('(changed: True)') else: print('(changed: False)')
def test_project_unique_together_with_org(organization): proj1 = Project(name='foo', organization=organization) proj1.save() proj2 = Project(name='foo', organization=organization) with pytest.raises(ValidationError): proj2.validate_unique() proj2 = Project(name='foo', organization=None) proj2.validate_unique()
def mk_project(name, organization=None, description=None, persisted=True): description = description or '{}-description'.format(name) project = Project(name=name, description=description, playbook_files=['helloworld.yml', 'alt-helloworld.yml']) if organization is not None: project.organization = organization if persisted: project.save() return project
def test_project_delete(delete, organization, admin_user): proj = Project(name='foo', organization=organization) proj.save() delete( reverse( 'api:project_detail', kwargs={ 'pk': proj.id, }, ), admin_user, )
def handle(self, *args, **kwargs): # Sanity check: Is there already an organization in the system? if Organization.objects.count(): print('An organization is already in the system, exiting.') print('(changed: False)') 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): with disable_computed_fields(): o = Organization.objects.create(name='Default') p = Project( name='Demo Project', scm_type='git', scm_url='https://github.com/ansible/ansible-tower-samples', scm_branch='master', scm_update_on_launch=True, scm_update_cache_timeout=0, organization=o) p.save(skip_update=True) ssh_type = CredentialType.from_v1_kind('ssh') c = Credential.objects.create( credential_type=ssh_type, name='Demo Credential', inputs={'username': superuser.username}, created_by=superuser) c.admin_role.members.add(superuser) i = Inventory.objects.create(name='Demo Inventory', organization=o, created_by=superuser) Host.objects.create(name='localhost', inventory=i, variables="ansible_connection: local", created_by=superuser) jt = JobTemplate.objects.create(name='Demo Job Template', playbook='hello_world.yml', project=p, inventory=i) jt.credentials.add(c) print('Default organization added.') print('Demo Credential, Inventory, and Job Template added.') print('(changed: True)')
def _mk_project_update(): project = Project() project.save() return ProjectUpdate(project=project)
def handle(self, *args, **kwargs): changed = False # 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): with disable_computed_fields(): if not Organization.objects.exists(): o, _ = Organization.objects.get_or_create(name='Default') # Avoid calling directly the get_or_create() to bypass project update p = Project.objects.filter(name='Demo Project', scm_type='git').first() if not p: p = Project( name='Demo Project', scm_type='git', scm_url= 'https://github.com/ansible/ansible-tower-samples', scm_update_cache_timeout=0, status='successful', scm_revision= '347e44fea036c94d5f60e544de006453ee5c71ad', playbook_files=['hello_world.yml'], ) p.organization = o p.save(skip_update=True) ssh_type = CredentialType.objects.filter( namespace='ssh').first() c, _ = Credential.objects.get_or_create( credential_type=ssh_type, name='Demo Credential', inputs={'username': superuser.username}, created_by=superuser) c.admin_role.members.add(superuser) public_galaxy_credential, _ = Credential.objects.get_or_create( name='Ansible Galaxy', managed=True, credential_type=CredentialType.objects.get( kind='galaxy'), inputs={'url': 'https://galaxy.ansible.com/'}, ) o.galaxy_credentials.add(public_galaxy_credential) i, _ = Inventory.objects.get_or_create( name='Demo Inventory', organization=o, created_by=superuser) Host.objects.get_or_create( name='localhost', inventory=i, variables= "ansible_connection: local\nansible_python_interpreter: '{{ ansible_playbook_python }}'", created_by=superuser, ) jt = JobTemplate.objects.filter( name='Demo Job Template').first() if jt: jt.project = p jt.inventory = i jt.playbook = 'hello_world.yml' jt.save() else: jt, _ = JobTemplate.objects.get_or_create( name='Demo Job Template', playbook='hello_world.yml', project=p, inventory=i) jt.credentials.add(c) print('Default organization added.') print( 'Demo Credential, Inventory, and Job Template added.') changed = True if changed: print('(changed: True)') else: print('(changed: False)')