schubergphilis / towerlib

A python library to interface with ansible tower's (awx) api.
MIT License
43 stars 39 forks source link

Why return a generator when the return only have one instence? #96

Closed lyutian closed 2 years ago

lyutian commented 2 years ago

https://github.com/schubergphilis/towerlib/blob/e4ae19f7b88d7049e1f23f279040461fa464c6e9/towerlib/towerlib.py#L963-L973

Appreciated your job.

Why we return a generator rather than a host instence in this function? BTW, the name get_hosts_by_name seems has multiple hosts return, but the filter used exactly match...

costastf commented 2 years ago

Hi, in tower as well as in awx the name of hosts does not have to be unique so there might be hosts with the same name match across organizations. That is why this generalized method returns a generator. I think that under organizations there must be a more targeted method that can return a host by name because under the organization there can not be name clashes. I hope that helps. If this info is enough feel free to close the issue.

Kind regards Costas On Fri, Jan 7, 2022, 10:46 Reynold Liu @.***> wrote:

https://github.com/schubergphilis/towerlib/blob/e4ae19f7b88d7049e1f23f279040461fa464c6e9/towerlib/towerlib.py#L963-L973

Appreciated your job.

Why we return a generator rather than a host instence in this function? BTW, the name get_hosts_by_name seems has multiple hosts return, but the filter used exactly match...

— Reply to this email directly, view it on GitHub https://github.com/schubergphilis/towerlib/issues/96, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABDMK24SO2NLIMSEOZ6OYM3UU2Y7LANCNFSM5LOM5TCA . Triage notifications on the go with GitHub Mobile for iOS https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Android https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub.

You are receiving this because you are subscribed to this thread.Message ID: @.***>

lyutian commented 2 years ago

Thanks Costar. I forgot the organization part. For my requirement, to get the exactly host in specific organization and inventory, the right way is get_inventory_host_by_name().

Thank you for your clarify, I will close this issue.

Best Regards, Reynold