in plugins/modules/ali_market_product_info.py [0:0]
def main():
argument_spec = ecs_argument_spec()
argument_spec.update(dict(
name_prefix=dict(typr='str'),
search_term=dict(type='str'),
sort=dict(type='str', choices=['user_count-desc', 'created_on-desc', 'price-desc', 'score-desc']),
category_id=dict(type='str'),
product_type=dict(type='str', choices=["APP", "SERVICE", "MIRROR", "DOWNLOAD", "API_SERVICE"]),
suggested_price=dict(type='float'),
supplier_id=dict(type='str'),
supplier_name_keyword=dict(type='str'),
ids=dict(typr='list', elements='str')
)
)
module = AnsibleModule(argument_spec=argument_spec)
if HAS_FOOTMARK is False:
module.fail_json(msg="Package 'footmark' required for this module.")
Filters = []
if module.params['sort']:
Filters.append({'Key': 'sort', 'Value': module.params['sort']})
if module.params['product_type']:
Filters.append({'Key': 'productType', 'Value': module.params['product_type']})
if module.params['category_id']:
Filters.append({'Key': 'categoryId', 'Value': module.params['category_id']})
if Filters:
module.params['Filters'] = Filters
name_prefix = module.params['name_prefix']
suggested_price = module.params['suggested_price']
supplier_id = module.params['supplier_id']
supplier_name_keyword = module.params['supplier_name_keyword']
ids = module.params['ids']
products = []
region_local_name = ""
for region in ecs_connect(module).describe_regions():
if region.id == module.params['alicloud_region']:
region_local_name = region.name
try:
for product in market_connect(module).describe_products(**module.params):
if name_prefix and not product.name.startswith(name_prefix):
continue
if supplier_id and str(product.supplier_id) != supplier_id:
continue
if supplier_name_keyword and product.supplier_name_keyword.find(supplier_name_keyword) == -1:
continue
if (suggested_price or suggested_price == 0) and not product.suggested_price.startswith(str(suggested_price).replace('.0', '') if str(suggested_price).endswith('.0') else str(suggested_price)):
continue
if ids and product.code not in ids:
continue
products.append(product.get().read_with_region_name(region_local_name))
module.exit_json(changed=False, products=products)
except Exception as e:
module.fail_json(msg=str("Unable to get products, error:{0}".format(e)))