コード例 #1
0
    def payload(self,
                inventory,
                source='custom',
                credential=None,
                source_script=None,
                project=None,
                **kwargs):
        payload = PseudoNamespace(
            name=kwargs.get('name')
            or 'InventorySource - {}'.format(random_title()),
            description=kwargs.get('description') or random_title(10),
            inventory=inventory.id,
            source=source)

        if credential:
            payload.credential = credential.id
        if source_script:
            payload.source_script = source_script.id
        if project:
            payload.source_project = project.id

        optional_fields = ('source_path', 'source_vars', 'timeout',
                           'overwrite', 'overwrite_vars',
                           'update_cache_timeout', 'update_on_launch',
                           'update_on_project_update', 'verbosity')

        update_payload(payload, optional_fields, kwargs)

        return payload
コード例 #2
0
    def payload(self, organization, scm_type='git', **kwargs):
        payload = PseudoNamespace(
            name=kwargs.get('name') or 'Project - {}'.format(
                random_title()),
            description=kwargs.get('description') or random_title(10),
            scm_type=scm_type,
            scm_url=kwargs.get('scm_url') or config.project_urls.get(
                scm_type,
                ''))

        if organization is not None:
            payload.organization = organization.id

        if kwargs.get('credential'):
            payload.credential = kwargs.get('credential').id

        fields = (
            'scm_branch',
            'local_path',
            'scm_clean',
            'scm_delete_on_update',
            'scm_update_cache_timeout',
            'scm_update_on_launch',
            'scm_refspec',
            'allow_override')
        update_payload(payload, fields, kwargs)

        return payload
コード例 #3
0
ファイル: projects.py プロジェクト: cwdrunner/awx
    def payload(self, organization, scm_type='git', **kwargs):
        payload = PseudoNamespace(name=kwargs.get('name')
                                  or 'Project - {}'.format(random_title()),
                                  description=kwargs.get('description')
                                  or random_title(10),
                                  scm_type=scm_type,
                                  scm_url=kwargs.get('scm_url')
                                  or config.project_urls.get(scm_type, ''))

        if organization is not None:
            payload.organization = organization.id

        if kwargs.get('credential'):
            payload.credential = kwargs.get('credential').id

        fields = ('scm_branch', 'local_path', 'scm_clean',
                  'scm_delete_on_update', 'scm_update_cache_timeout',
                  'scm_update_on_launch', 'scm_refspec', 'allow_override')
        update_payload(payload, fields, kwargs)

        for fk_field in ('execution_environment', 'default_environment'):
            rel_obj = kwargs.get(fk_field)
            if rel_obj is None:
                continue
            elif isinstance(rel_obj, int):
                payload.update(**{fk_field: int(rel_obj)})
            elif hasattr(rel_obj, 'id'):
                payload.update(**{fk_field: rel_obj.id})
            else:
                raise AttributeError(
                    f'Related field {fk_field} must be either integer of pkid or object'
                )
        return payload
コード例 #4
0
    def payload(self, inventory, credential=None, **kwargs):
        payload = PseudoNamespace(
            name=kwargs.get('name')
            or 'Group{}'.format(random_title(non_ascii=False)),
            description=kwargs.get('description') or random_title(10),
            inventory=inventory.id)

        if credential:
            payload.credential = credential.id

        update_payload(payload, ('variables', ), kwargs)

        if 'variables' in payload and isinstance(payload.variables, dict):
            payload.variables = json.dumps(payload.variables)

        return payload