mirror of
https://github.com/ansible/awx.git
synced 2026-03-19 18:07:33 -02:30
Analytics export other subs attrs
We'll export also subscription_id since pool_id is not enough in certain cases. Then also export usage and account number
This commit is contained in:
@@ -131,7 +131,7 @@ def _identify_lower(key, since, until, last_gather):
|
|||||||
return lower, last_entries
|
return lower, last_entries
|
||||||
|
|
||||||
|
|
||||||
@register('config', '1.5', description=_('General platform configuration.'))
|
@register('config', '1.6', description=_('General platform configuration.'))
|
||||||
def config(since, **kwargs):
|
def config(since, **kwargs):
|
||||||
license_info = get_license()
|
license_info = get_license()
|
||||||
install_type = 'traditional'
|
install_type = 'traditional'
|
||||||
@@ -155,10 +155,13 @@ def config(since, **kwargs):
|
|||||||
'subscription_name': license_info.get('subscription_name'),
|
'subscription_name': license_info.get('subscription_name'),
|
||||||
'sku': license_info.get('sku'),
|
'sku': license_info.get('sku'),
|
||||||
'support_level': license_info.get('support_level'),
|
'support_level': license_info.get('support_level'),
|
||||||
|
'usage': license_info.get('usage'),
|
||||||
'product_name': license_info.get('product_name'),
|
'product_name': license_info.get('product_name'),
|
||||||
'valid_key': license_info.get('valid_key'),
|
'valid_key': license_info.get('valid_key'),
|
||||||
'satellite': license_info.get('satellite'),
|
'satellite': license_info.get('satellite'),
|
||||||
'pool_id': license_info.get('pool_id'),
|
'pool_id': license_info.get('pool_id'),
|
||||||
|
'subscription_id': license_info.get('subscription_id'),
|
||||||
|
'account_number': license_info.get('account_number'),
|
||||||
'current_instances': license_info.get('current_instances'),
|
'current_instances': license_info.get('current_instances'),
|
||||||
'automated_instances': license_info.get('automated_instances'),
|
'automated_instances': license_info.get('automated_instances'),
|
||||||
'automated_since': license_info.get('automated_since'),
|
'automated_since': license_info.get('automated_since'),
|
||||||
|
|||||||
@@ -170,6 +170,8 @@ class Licenser(object):
|
|||||||
|
|
||||||
license.setdefault('sku', sub['pool']['productId'])
|
license.setdefault('sku', sub['pool']['productId'])
|
||||||
license.setdefault('subscription_name', sub['pool']['productName'])
|
license.setdefault('subscription_name', sub['pool']['productName'])
|
||||||
|
license.setdefault('subscription_id', sub['pool']['subscriptionId'])
|
||||||
|
license.setdefault('account_number', sub['pool']['accountNumber'])
|
||||||
license.setdefault('pool_id', sub['pool']['id'])
|
license.setdefault('pool_id', sub['pool']['id'])
|
||||||
license.setdefault('product_name', sub['pool']['productName'])
|
license.setdefault('product_name', sub['pool']['productName'])
|
||||||
license.setdefault('valid_key', True)
|
license.setdefault('valid_key', True)
|
||||||
@@ -185,6 +187,14 @@ class Licenser(object):
|
|||||||
license['instance_count'] = license.get('instance_count', 0) + instances
|
license['instance_count'] = license.get('instance_count', 0) + instances
|
||||||
license['subscription_name'] = re.sub(r'[\d]* Managed Nodes', '%d Managed Nodes' % license['instance_count'], license['subscription_name'])
|
license['subscription_name'] = re.sub(r'[\d]* Managed Nodes', '%d Managed Nodes' % license['instance_count'], license['subscription_name'])
|
||||||
|
|
||||||
|
license['support_level'] = ''
|
||||||
|
license['usage'] = ''
|
||||||
|
for attr in sub['pool'].get('productAttributes', []):
|
||||||
|
if attr.get('name') == 'support_level':
|
||||||
|
license['support_level'] = attr.get('value')
|
||||||
|
elif attr.get('name') == 'usage':
|
||||||
|
license['usage'] = attr.get('value')
|
||||||
|
|
||||||
if not license:
|
if not license:
|
||||||
logger.error("No valid subscriptions found in manifest")
|
logger.error("No valid subscriptions found in manifest")
|
||||||
self._attrs.update(license)
|
self._attrs.update(license)
|
||||||
@@ -277,7 +287,10 @@ class Licenser(object):
|
|||||||
license['productId'] = sub['product_id']
|
license['productId'] = sub['product_id']
|
||||||
license['quantity'] = int(sub['quantity'])
|
license['quantity'] = int(sub['quantity'])
|
||||||
license['support_level'] = sub['support_level']
|
license['support_level'] = sub['support_level']
|
||||||
|
license['usage'] = sub['usage']
|
||||||
license['subscription_name'] = sub['name']
|
license['subscription_name'] = sub['name']
|
||||||
|
license['subscriptionId'] = sub['subscription_id']
|
||||||
|
license['accountNumber'] = sub['account_number']
|
||||||
license['id'] = sub['upstream_pool_id']
|
license['id'] = sub['upstream_pool_id']
|
||||||
license['endDate'] = sub['end_date']
|
license['endDate'] = sub['end_date']
|
||||||
license['productName'] = "Red Hat Ansible Automation"
|
license['productName'] = "Red Hat Ansible Automation"
|
||||||
@@ -304,7 +317,7 @@ class Licenser(object):
|
|||||||
def generate_license_options_from_entitlements(self, json):
|
def generate_license_options_from_entitlements(self, json):
|
||||||
from dateutil.parser import parse
|
from dateutil.parser import parse
|
||||||
|
|
||||||
ValidSub = collections.namedtuple('ValidSub', 'sku name support_level end_date trial quantity pool_id satellite')
|
ValidSub = collections.namedtuple('ValidSub', 'sku name support_level end_date trial quantity pool_id satellite subscription_id account_number usage')
|
||||||
valid_subs = []
|
valid_subs = []
|
||||||
for sub in json:
|
for sub in json:
|
||||||
satellite = sub.get('satellite')
|
satellite = sub.get('satellite')
|
||||||
@@ -333,15 +346,23 @@ class Licenser(object):
|
|||||||
sku = sub['productId']
|
sku = sub['productId']
|
||||||
trial = sku.startswith('S') # i.e.,, SER/SVC
|
trial = sku.startswith('S') # i.e.,, SER/SVC
|
||||||
support_level = ''
|
support_level = ''
|
||||||
|
usage = ''
|
||||||
pool_id = sub['id']
|
pool_id = sub['id']
|
||||||
|
subscription_id = sub['subscriptionId']
|
||||||
|
account_number = sub['accountNumber']
|
||||||
if satellite:
|
if satellite:
|
||||||
support_level = sub['support_level']
|
support_level = sub['support_level']
|
||||||
|
usage = sub['usage']
|
||||||
else:
|
else:
|
||||||
for attr in sub.get('productAttributes', []):
|
for attr in sub.get('productAttributes', []):
|
||||||
if attr.get('name') == 'support_level':
|
if attr.get('name') == 'support_level':
|
||||||
support_level = attr.get('value')
|
support_level = attr.get('value')
|
||||||
|
elif attr.get('name') == 'usage':
|
||||||
|
usage = attr.get('value')
|
||||||
|
|
||||||
valid_subs.append(ValidSub(sku, sub['productName'], support_level, end_date, trial, quantity, pool_id, satellite))
|
valid_subs.append(
|
||||||
|
ValidSub(sku, sub['productName'], support_level, end_date, trial, quantity, pool_id, satellite, subscription_id, account_number, usage)
|
||||||
|
)
|
||||||
|
|
||||||
if valid_subs:
|
if valid_subs:
|
||||||
licenses = []
|
licenses = []
|
||||||
@@ -350,6 +371,7 @@ class Licenser(object):
|
|||||||
license._attrs['instance_count'] = int(sub.quantity)
|
license._attrs['instance_count'] = int(sub.quantity)
|
||||||
license._attrs['sku'] = sub.sku
|
license._attrs['sku'] = sub.sku
|
||||||
license._attrs['support_level'] = sub.support_level
|
license._attrs['support_level'] = sub.support_level
|
||||||
|
license._attrs['usage'] = sub.usage
|
||||||
license._attrs['license_type'] = 'enterprise'
|
license._attrs['license_type'] = 'enterprise'
|
||||||
if sub.trial:
|
if sub.trial:
|
||||||
license._attrs['trial'] = True
|
license._attrs['trial'] = True
|
||||||
@@ -364,6 +386,8 @@ class Licenser(object):
|
|||||||
license._attrs['valid_key'] = True
|
license._attrs['valid_key'] = True
|
||||||
license.update(license_date=int(sub.end_date.strftime('%s')))
|
license.update(license_date=int(sub.end_date.strftime('%s')))
|
||||||
license.update(pool_id=sub.pool_id)
|
license.update(pool_id=sub.pool_id)
|
||||||
|
license.update(subscription_id=sub.subscription_id)
|
||||||
|
license.update(account_number=sub.account_number)
|
||||||
licenses.append(license._attrs.copy())
|
licenses.append(license._attrs.copy())
|
||||||
return licenses
|
return licenses
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user