Bug 1376825

Summary: [RFE] Template API should have provider field
Product: Red Hat CloudForms Management Engine Reporter: Leo Khomenko <lkhomenk>
Component: APIAssignee: Šimon Lukašík <slukasik>
Status: CLOSED NOTABUG QA Contact: Dave Johnson <dajohnso>
Severity: unspecified Docs Contact:
Priority: unspecified    
Version: 5.6.0CC: jhardy, obarenbo, slukasik
Target Milestone: GAKeywords: FutureFeature
Target Release: 5.7.0   
Hardware: Unspecified   
OS: Unspecified   
Whiteboard: rest:template
Fixed In Version: Doc Type: If docs needed, set a value
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2016-09-19 06:57:49 UTC Type: Bug
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:

Description Leo Khomenko 2016-09-16 14:02:08 UTC
Description of problem:if two or more providers added( RHOS7-GA,rhos6-ga-ssl etc) which have template with the same name (eg - cirros) 
[RESTAPI] GET https://10.8.199.11/api/templates {'filter[]': ["name='cirros'"]}
will give only 1 result, so it's possible to pick template on wrong provider and provision it there. so provider filter could help to solve this (UI template table has this)


Version-Release number of selected component (if applicable):
5.6.2.0

How reproducible:always


Steps to Reproduce:
1.add 2 providers with the same template name
2.try to get whole list of templates matching your filter

Actual results:it depends on the order in which providers were added - which template you will get


Expected results:get list of templates if there're more than one template matching your filter


Additional info: example of the template we currently have - 
{"href":"https://10.8.199.11/api/templates/1017","id":1017,"vendor":"openstack","name":"cirros","location":"unknown","created_on":"2016-09-15T13:54:10Z","updated_on":"2016-09-15T13:54:10Z","guid":"e10c0a68-7b4b-11e6-a7ea-fa163ee9704b","ems_id":9,"uid_ems":"71469f86-aec6-416c-98b4-b11918709ef3","power_state":"never","state_changed_on":"2016-09-15T13:54:10Z","template":true,"miq_group_id":1,"type":"ManageIQ::Providers::Openstack::CloudManager::Template","ems_ref":"71469f86-aec6-416c-98b4-b11918709ef3","cloud":true,"cloud_tenant_id":3,"raw_power_state":"never","publicly_available":true,"tenant_id":1,"actions":[{"name":"set_ownership","method":"post","href":"https://10.8.199.11/api/templates/1017"},{"name":"delete","method":"delete","href":"https://10.8.199.11/api/templates/1017"}]} 
It's hard to guess, on which provider is it

Comment 2 Šimon Lukašík 2016-09-19 06:57:49 UTC
The provider of the template can be queried by appending 

    &attributes=ext_management_system

to the URL. For example, my testing URL was

    http://localhost:3000/api/templates?filter[]=name="miq-nightly-201609012000"&expand=resources&attributes=ext_management_system
 
That way you get full visibility into what is the template's provider.

I am closing this as not-a-bug. While we could add extra special field for users to query the provider name, we try not to. Every user has slightly different usecase and we soon the defaults would blow-up any limit. We try to provide sane default and offer great customization by querying interface as described in chapter

    1.4. Query Specification

in 

    https://access.redhat.com/documentation/en/red-hat-cloudforms/4.1/red-hat-cloudforms-rest-api/red-hat-cloudforms-rest-api


Lastly, this got my attention

> [RESTAPI] GET https://10.8.199.11/api/templates {'filter[]': ["name='cirros'"]}
> will give only 1 result, 

If you have two templates of the same name, you should have received two results from the API. I did, when I recreated described situation.