| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
from __future__ import absolute_import, division, print_function |
| 19 |
__metaclass__ = type |
| 20 |
|
| 21 |
|
| 22 |
DOCUMENTATION = ''' |
| 23 |
--- |
| 24 |
module: scc_product |
| 25 |
version_added: 1.0.0 |
| 26 |
short_description: Subscribe SUSE Customer Center Account Products |
| 27 |
description: |
| 28 |
- Manage SUSE Customer Center Products |
| 29 |
- This module requires the foreman_scc_manager plugin set up in the server |
| 30 |
- See U(https://github.com/ATIX-AG/foreman_scc_manager) |
| 31 |
author: |
| 32 |
- "Manisha Singhal (@manisha15) ATIX AG" |
| 33 |
options: |
| 34 |
scc_product: |
| 35 |
description: |
| 36 |
- Full name of the product of suse customer center account. |
| 37 |
- The I(friendly_name) alias is deprecated as it refers to an attribute that does not |
| 38 |
uniquely identify a product and not used for product lookups since SCC Manager 1.8.6. |
| 39 |
required: true |
| 40 |
type: str |
| 41 |
aliases: |
| 42 |
- friendly_name |
| 43 |
scc_account: |
| 44 |
description: Name of the suse customer center account associated with product |
| 45 |
required: true |
| 46 |
type: str |
| 47 |
extends_documentation_fragment: |
| 48 |
- theforeman.foreman.foreman |
| 49 |
- theforeman.foreman.foreman.organization |
| 50 |
''' |
| 51 |
|
| 52 |
EXAMPLES = ''' |
| 53 |
- name: "Subscribe to suse customer center product" |
| 54 |
theforeman.foreman.scc_product: |
| 55 |
scc_product: "Product1" |
| 56 |
scc_account: "Test" |
| 57 |
organization: "Test Organization" |
| 58 |
''' |
| 59 |
|
| 60 |
RETURN = ''' # ''' |
| 61 |
|
| 62 |
|
| 63 |
from ansible_collections.theforeman.foreman.plugins.module_utils.foreman_helper import KatelloAnsibleModule |
| 64 |
from ansible_collections.theforeman.foreman.plugins.module_utils._version import LooseVersion |
| 65 |
|
| 66 |
|
| 67 |
def main(): |
| 68 |
module = KatelloAnsibleModule( |
| 69 |
foreman_spec=dict( |
| 70 |
scc_product=dict(required=True, type='entity', aliases=['friendly_name'], scope=['scc_account'], thin=False), |
| 71 |
scc_account=dict(required=True, type='entity', scope=['organization']), |
| 72 |
), |
| 73 |
required_plugins=[('scc_manager', ['*'])], |
| 74 |
) |
| 75 |
|
| 76 |
module.task_timeout = 4 * 60 |
| 77 |
|
| 78 |
with module.api_connection(): |
| 79 |
scc_version = '1.0.0' |
| 80 |
try: |
| 81 |
statuses = module.foremanapi.resource('ping').call('statuses') |
| 82 |
plugins = statuses['results']['foreman']['plugins'] |
| 83 |
for plugin in plugins: |
| 84 |
if isinstance(plugin, dict): |
| 85 |
if plugin['name'] == 'foreman_scc_manager': |
| 86 |
scc_version = plugin['version'] |
| 87 |
else: |
| 88 |
if 'foreman_scc_manager' in plugin: |
| 89 |
scc_version = plugin.split(',')[1] |
| 90 |
except Exception: |
| 91 |
pass |
| 92 |
|
| 93 |
if LooseVersion(scc_version.strip()) < LooseVersion('1.8.6'): |
| 94 |
scc_search_by = 'friendly_name' |
| 95 |
else: |
| 96 |
scc_search_by = 'name' |
| 97 |
|
| 98 |
module.foreman_spec['scc_product']['search_by'] = scc_search_by |
| 99 |
scc_product = module.lookup_entity('scc_product') |
| 100 |
|
| 101 |
if not scc_product.get('product_id'): |
| 102 |
payload = {'id': scc_product['id']} |
| 103 |
payload.update(module.scope_for('scc_account')) |
| 104 |
module.resource_action('scc_products', 'subscribe', payload) |
| 105 |
|
| 106 |
|
| 107 |
if __name__ == '__main__': |
| 108 |
main() |