def main():
    module = KatelloAnsibleModule(
        argument_spec=dict(
            friendly_name=dict(required=True),
            scc_account=dict(required=True),
        ),
    )

    module.task_timeout = 4 * 60

    params = module.clean_params()

    module.connect()

    params, scope = module.handle_organization_param(params)

    params['scc_account'] = module.find_resource_by_name('scc_accounts', name=params['scc_account'], params=scope, thin=True)

    scc_account_scope = {'scc_account_id': params['scc_account']['id']}

    # Try to find the SccProduct to work on
    # name is however not unique, but friendly_name is

    search_string = 'friendly_name="{0}"'.format(params['friendly_name'])
    scc_product = module.find_resource('scc_products', search_string, params=scc_account_scope)

    if not scc_product.get('product_id'):
        module.resource_action('scc_products', 'subscribe', {'id': scc_product['id'], 'scc_account_id': scc_account_scope['scc_account_id']})

    module.exit_json()
def main():
    module = KatelloAnsibleModule(argument_spec=dict(
        product=dict(required=True),
        repository=dict(),
    ), )

    module.task_timeout = 12 * 60 * 60

    params = module.clean_params()

    with module.api_connection():
        params, scope = module.handle_organization_param(params)

        params['product'] = module.find_resource_by_name('products',
                                                         params['product'],
                                                         params=scope,
                                                         thin=True)
        if 'repository' in params:
            product_scope = {'product_id': params['product']['id']}
            params['repository'] = module.find_resource_by_name(
                'repositories',
                params['repository'],
                params=product_scope,
                thin=True)
            task = module.resource_action('repositories', 'sync',
                                          {'id': params['repository']['id']})
        else:
            task = module.resource_action('products', 'sync',
                                          {'id': params['product']['id']})

        module.exit_json(task=task)
def main():
    module = KatelloAnsibleModule(
        argument_spec=dict(
            product=dict(required=True),
            repository=dict(),
            synchronous=dict(type='bool', default=True),
        ),
    )

    module.task_timeout = 30 * 60

    params = module.clean_params()

    module.connect()

    params['organization'] = module.find_resource_by_name('organizations', params['organization'], thin=True)
    scope = {'organization_id': params['organization']['id']}
    params['product'] = module.find_resource_by_name('products', params['product'], params=scope, thin=True)
    if 'repository' in params:
        product_scope = {'product_id': params['product']['id']}
        params['repository'] = module.find_resource_by_name('repositories', params['repository'], params=product_scope, thin=True)
        changed, task = module.resource_action('repositories', 'sync', {'id': params['repository']['id']}, synchronous=params['synchronous'])
    else:
        changed, task = module.resource_action('products', 'sync', {'id': params['product']['id']}, synchronous=params['synchronous'])
    module.exit_json(changed=changed, task=task)
Esempio n. 4
0
def main():
    module = KatelloAnsibleModule(
        foreman_spec=dict(
            scc_product=dict(required=True, type='entity', aliases=['friendly_name'], scope=['scc_account'], thin=False),
            scc_account=dict(required=True, type='entity', scope=['organization']),
        ),
        required_plugins=[('scc_manager', ['*'])],
    )

    module.task_timeout = 4 * 60

    with module.api_connection():
        scc_product = module.lookup_entity('scc_product')

        if not scc_product.get('product_id'):
            payload = {'id': scc_product['id']}
            payload.update(module.scope_for('scc_account'))
            module.resource_action('scc_products', 'subscribe', payload)
Esempio n. 5
0
def main():
    module = KatelloAnsibleModule(
        foreman_spec=dict(
            product=dict(type='entity', scope=['organization'], required=True),
            repository=dict(type='entity', scope=['product'], failsafe=True),
            # This should be scoped more explicit for better serch performance, but needs rerecording
            # repository=dict(type='entity', scope=['organization', 'product'], failsafe=True),
        ), )

    module.task_timeout = 12 * 60 * 60

    with module.api_connection():
        product = module.lookup_entity('product')
        repository = module.lookup_entity('repository')
        if repository:
            task = module.resource_action('repositories', 'sync',
                                          {'id': repository['id']})
        else:
            task = module.resource_action('products', 'sync',
                                          {'id': product['id']})

        module.exit_json(task=task)