openstacksdk/openstack/_meta
Monty Taylor a61b5d25de
Generate proxy methods from resource objects
Each service has a set of Resources which define the fundamental
qualities of the remote resources. Because of this, a large portion
of the methods on Proxy classes are (or can be) boilerplate.

Add a metaclass (two in a row!) that reads the definition of the
Proxy class and looks for Resource classes attached to it. It then checks
them to see which operations are allowed by looking at the Resource's
allow_ flags. Based on that, it generates the standard methods and doc
strings from a template and adds them to the class.

If a method exists on the class when it is read, the generated method
does not overwrite the existing method. Instead, it is attached as
``_generated_{method_name}``. This allows people to either write
specific proxy methods and completely ignore the generated method,
or to write specialized methods that then delegate action to the generated
method.

Since this is done as a metaclass at class object creation time,
things like sphinx continue to work.

One of the results of this is the addition of a reference to each
resource class on the proxy object. I've wanted one of those before (I
don't remember right now why I wanted it)

This makes a change to just a few methods/resources in Server as an
example of impact. If we like it we can go through and remove all of the
boilerplate methods and leave only methods that are special.

openstack.compute.v2._proxy.Proxy.servers is left in place largely
because it has a special doc string. I think we could (and should)
update the generation to look at the query parameters to find and
document in the docstring for list methods what the supported parameters
are.

This stems from some thinking we had in shade about being able to
generate most of the methods that fit the pattern. It's likely we'll
want to do that for shade methods as well - but we should actually be
able to piggyback shade methods on top of the proxy methods, or at least
use a similar approach to reduce most of the boilerplate in the shade
layer.

Change-Id: I9bee095d90cad25acadbf311d4dd8af2e76ba00a
2018-02-15 08:54:35 -06:00
..
__init__.py Generate proxy methods from resource objects 2018-02-15 08:54:35 -06:00
_proxy_templates.py Generate proxy methods from resource objects 2018-02-15 08:54:35 -06:00
connection.py Generate proxy methods from resource objects 2018-02-15 08:54:35 -06:00
proxy.py Generate proxy methods from resource objects 2018-02-15 08:54:35 -06:00