How to use the awxkit.awxkit.api.pages.base.Base function in awxkit

To help you get started, we’ve selected a few awxkit examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github ansible / awx / awxkit / awxkit / api / pages / notification_templates.py View on Github external
from . import base
from . import page


job_results = ('any', 'error', 'success')
notification_types = (
    'email',
    'irc',
    'pagerduty',
    'slack',
    'twilio',
    'webhook',
    'mattermost')


class NotificationTemplate(HasCopy, HasCreate, base.Base):

    dependencies = [Organization]

    def test(self):
        """Create test notification"""
        assert 'test' in self.related, \
            "No such related attribute 'test'"

        # trigger test notification
        notification_id = self.related.test.post().notification

        # return notification page
        notifications_pg = self.get_related(
            'notifications', id=notification_id).wait_until_count(1)
        assert notifications_pg.count == 1, \
            "test notification triggered (id:%s) but notification not found in response at %s/notifications/" % \
github ansible / awx / awxkit / awxkit / api / pages / metrics.py View on Github external
from awxkit.api.resources import resources
from . import base
from . import page


class Metrics(base.Base):

    def get(self, **query_parameters):
        request = self.connection.get(self.endpoint, query_parameters,
                                      headers={'Accept': 'application/json'})
        return self.page_identity(request)


page.register_page([resources.metrics,
                    (resources.metrics, 'get')], Metrics)
github ansible / awx / awxkit / awxkit / api / pages / workflow_job_templates.py View on Github external
pass


page.register_page([resources.workflow_job_templates], WorkflowJobTemplates)


class WorkflowJobTemplateLaunch(base.Base):

    pass


page.register_page(resources.workflow_job_template_launch, WorkflowJobTemplateLaunch)


class WorkflowJobTemplateCopy(base.Base):

    pass


page.register_page([resources.workflow_job_template_copy], WorkflowJobTemplateCopy)
github ansible / awx / awxkit / awxkit / api / pages / users.py View on Github external
from awxkit.api.mixins import HasCreate, DSAdapter
from awxkit.utils import random_title, PseudoNamespace
from awxkit.api.resources import resources
from awxkit.config import config

from . import base
from . import page


class User(HasCreate, base.Base):

    def payload(self, **kwargs):
        payload = PseudoNamespace(
            username=kwargs.get('username') or 'User-{}'.format(
                random_title(
                    non_ascii=False)),
            password=kwargs.get('password') or config.credentials.default.password,
            is_superuser=kwargs.get(
                'is_superuser',
                False),
            is_system_auditor=kwargs.get(
                'is_system_auditor',
                False),
            first_name=kwargs.get(
                'first_name',
                random_title()),
github ansible / awx / awxkit / awxkit / api / pages / credentials.py View on Github external
self.connection).post(payload))


page.register_page([resources.credential_type,
                    (resources.credential_types, 'post')], CredentialType)


class CredentialTypes(page.PageList, CredentialType):

    pass


page.register_page(resources.credential_types, CredentialTypes)


class Credential(HasCopy, HasCreate, base.Base):

    dependencies = [CredentialType]
    optional_dependencies = [Organization, User, Team]

    def payload(
            self,
            credential_type,
            user=None,
            team=None,
            organization=None,
            inputs=None,
            **kwargs):
        if not any((user, team, organization)):
            raise TypeError(
                '{0.__class__.__name__} requires user, team, and/or organization instances.'.format(self))
github ansible / awx / awxkit / awxkit / api / pages / workflow_job_templates.py View on Github external
page.register_page([resources.workflow_job_template,
                    (resources.workflow_job_templates, 'post'),
                    (resources.workflow_job_template_copy, 'post')], WorkflowJobTemplate)


class WorkflowJobTemplates(page.PageList, WorkflowJobTemplate):

    pass


page.register_page([resources.workflow_job_templates], WorkflowJobTemplates)


class WorkflowJobTemplateLaunch(base.Base):

    pass


page.register_page(resources.workflow_job_template_launch, WorkflowJobTemplateLaunch)


class WorkflowJobTemplateCopy(base.Base):

    pass


page.register_page([resources.workflow_job_template_copy], WorkflowJobTemplateCopy)
github ansible / awx / awxkit / awxkit / api / pages / job_templates.py View on Github external
pass


page.register_page([resources.job_templates,
                    resources.related_job_templates], JobTemplates)


class JobTemplateCallback(base.Base):

    pass


page.register_page(resources.job_template_callback, JobTemplateCallback)


class JobTemplateLaunch(base.Base):

    pass


page.register_page(resources.job_template_launch, JobTemplateLaunch)
github ansible / awx / awxkit / awxkit / api / pages / unified_jobs.py View on Github external
from pprint import pformat

import yaml.parser
import yaml.scanner
import yaml

from awxkit.utils import args_string_to_list, seconds_since_date_string
from awxkit.api.resources import resources
from awxkit.api.mixins import HasStatus
import awxkit.exceptions as exc
from . import base
from . import page


class UnifiedJob(HasStatus, base.Base):
    """Base class for unified job pages (e.g. project_updates, inventory_updates
    and jobs).
    """

    def __str__(self):
        # NOTE: I use .replace('%', '%%') to workaround an odd string
        # formatting issue where result_stdout contained '%s'.  This later caused
        # a python traceback when attempting to display output from this method.
        items = ['id', 'name', 'status', 'failed', 'result_stdout', 'result_traceback',
                 'job_explanation', 'job_args']
        info = []
        for item in [x for x in items if hasattr(self, x)]:
            info.append('{0}:{1}'.format(item, getattr(self, item)))
        output = '<{0.__class__.__name__} {1}>'.format(self, ', '.join(info))
        return output.replace('%', '%%')
github ansible / awx / awxkit / awxkit / api / pages / credentials.py View on Github external
config_field = 'subscription_id'
    elif field == 'username' and kind == 'azure_ad':
        config_field = 'ad_user'
    elif field == 'client':
        config_field = 'client_id'
    elif field == 'authorize_password':
        config_field = 'authorize'
    else:
        config_field = field
    value = kwargs.get(field, config_cred.get(config_field, not_provided))
    if field in ('project_id', 'project_name'):
        field = 'project'
    return field, value


class CredentialType(HasCreate, base.Base):

    def silent_delete(self):
        if not self.managed_by_tower:
            return super(CredentialType, self).silent_delete()

    def payload(self, kind='cloud', **kwargs):
        payload = PseudoNamespace(
            name=kwargs.get('name') or 'CredentialType - {}'.format(
                random_title()),
            description=kwargs.get('description') or random_title(10),
            kind=kind)
        fields = ('inputs', 'injectors')
        update_payload(payload, fields, kwargs)
        return payload

    def create_payload(self, kind='cloud', **kwargs):
github ansible / awx / awxkit / awxkit / api / pages / notification_templates.py View on Github external
resources.notification_template_success], NotificationTemplate)


class NotificationTemplates(page.PageList, NotificationTemplate):

    pass


page.register_page([resources.notification_templates,
                    resources.notification_templates_any,
                    resources.notification_templates_error,
                    resources.notification_templates_success],
                   NotificationTemplates)


class NotificationTemplateTest(base.Base):

    pass


page.register_page(
    resources.notification_template_test,
    NotificationTemplateTest)