mirror of
https://github.com/ansible/awx.git
synced 2026-01-09 23:12:08 -03:30
Co-authored-by: Christopher Wang <cwang@ansible.com> Co-authored-by: Jake McDermott <jmcdermott@ansible.com> Co-authored-by: Jim Ladd <jladd@redhat.com> Co-authored-by: Elijah DeLee <kdelee@redhat.com> Co-authored-by: Alan Rominger <arominge@redhat.com> Co-authored-by: Yanis Guenane <yanis@guenane.org>
50 lines
1.7 KiB
Python
50 lines
1.7 KiB
Python
from awxkit.api.mixins import HasCreate, HasInstanceGroups, HasNotifications, DSAdapter
|
|
from awxkit.utils import random_title, suppress, PseudoNamespace
|
|
from awxkit.api.resources import resources
|
|
import awxkit.exceptions as exc
|
|
from . import base
|
|
from . import page
|
|
|
|
|
|
class Organization(HasCreate, HasInstanceGroups, HasNotifications, base.Base):
|
|
|
|
def add_admin(self, user):
|
|
if isinstance(user, page.Page):
|
|
user = user.json
|
|
with suppress(exc.NoContent):
|
|
self.related.admins.post(user)
|
|
|
|
def add_user(self, user):
|
|
if isinstance(user, page.Page):
|
|
user = user.json
|
|
with suppress(exc.NoContent):
|
|
self.related.users.post(user)
|
|
|
|
def payload(self, **kwargs):
|
|
payload = PseudoNamespace(name=kwargs.get('name') or 'Organization - {}'.format(random_title()),
|
|
description=kwargs.get('description') or random_title(10))
|
|
return payload
|
|
|
|
def create_payload(self, name='', description='', **kwargs):
|
|
payload = self.payload(name=name, description=description, **kwargs)
|
|
payload.ds = DSAdapter(self.__class__.__name__, self._dependency_store)
|
|
return payload
|
|
|
|
def create(self, name='', description='', **kwargs):
|
|
payload = self.create_payload(name=name, description=description, **kwargs)
|
|
return self.update_identity(Organizations(self.connection).post(payload))
|
|
|
|
|
|
page.register_page([resources.organization,
|
|
(resources.organizations, 'post')], Organization)
|
|
|
|
|
|
class Organizations(page.PageList, Organization):
|
|
|
|
pass
|
|
|
|
|
|
page.register_page([resources.organizations,
|
|
resources.user_organizations,
|
|
resources.project_organizations], Organizations)
|