[ovirt-users] SKD4

Barak Korren bkorren at redhat.com
Thu Apr 6 15:15:36 UTC 2017


On 6 April 2017 at 18:00, Fabrice Bacchella <fabrice.bacchella at orange.fr> wrote:
> Ho my good, in ovirtsdk.services.py, for every service, there is a different
> method with a different name that return a associated service, so it's not
> possible to have a generic like:
>
> def  resolve(service, ...):
> id = .....
> return service.service(id)
>
> because the generic call service is used by something that take a path
> argument. But why not a service_by_id(self, id) ?
>
I think you can use getattr to get a generic call like you want:

With your example code:

    def resolve(service, ...):
        id = .....
        return getattr(services, service + '_service')(id)




-- 
Barak Korren
bkorren at redhat.com
RHCE, RHCi, RHV-DevOps Team
https://ifireball.wordpress.com/


More information about the Users mailing list