summaryrefslogtreecommitdiffstats
path: root/bin/nova-direct-api
diff options
context:
space:
mode:
authortermie <github@anarkystic.com>2011-03-24 20:45:59 +0000
committerTarmac <>2011-03-24 20:45:59 +0000
commit823df3b0ee7e7eb35e5864bfa235e686819df13e (patch)
tree857ec7ac289584f3803c97edec8fd42fabe5095d /bin/nova-direct-api
parenta0ea76b26a7725efb2fc4a811dff66b4f8bff6b7 (diff)
parentc5cbec20d2785d3060d57b55a264fbf936709500 (diff)
Additions to the Direct API:
* Add an example of a versioned api * Add some more docs to direct.py * Add Limited, an API limiting/versioning wrapper * Improve the formatting of the stack tool * Add support for volume and network services to the direct api
Diffstat (limited to 'bin/nova-direct-api')
-rwxr-xr-xbin/nova-direct-api35
1 files changed, 33 insertions, 2 deletions
diff --git a/bin/nova-direct-api b/bin/nova-direct-api
index a2c9f1557..83ec72722 100755
--- a/bin/nova-direct-api
+++ b/bin/nova-direct-api
@@ -34,12 +34,14 @@ if os.path.exists(os.path.join(possible_topdir, 'nova', '__init__.py')):
gettext.install('nova', unicode=1)
+from nova import compute
from nova import flags
from nova import log as logging
+from nova import network
from nova import utils
+from nova import volume
from nova import wsgi
from nova.api import direct
-from nova.compute import api as compute_api
FLAGS = flags.FLAGS
@@ -50,13 +52,42 @@ flags.DEFINE_flag(flags.HelpshortFlag())
flags.DEFINE_flag(flags.HelpXMLFlag())
+# An example of an API that only exposes read-only methods.
+# In this case we're just limiting which methods are exposed.
+class ReadOnlyCompute(direct.Limited):
+ """Read-only Compute API."""
+
+ _allowed = ['get', 'get_all', 'get_console_output']
+
+
+# An example of an API that provides a backwards compatibility layer.
+# In this case we're overwriting the implementation to ensure
+# compatibility with an older version. In reality we would want the
+# "description=None" to be part of the actual API so that code
+# like this isn't even necessary, but this example shows what one can
+# do if that isn't the situation.
+class VolumeVersionOne(direct.Limited):
+ _allowed = ['create', 'delete', 'update', 'get']
+
+ def create(self, context, size, name):
+ self.proxy.create(context, size, name, description=None)
+
+
if __name__ == '__main__':
utils.default_flagfile()
FLAGS(sys.argv)
logging.setup()
- direct.register_service('compute', compute_api.API())
+ direct.register_service('compute', compute.API())
+ direct.register_service('volume', volume.API())
+ direct.register_service('network', network.API())
direct.register_service('reflect', direct.Reflection())
+
+ # Here is how we could expose the code in the examples above.
+ #direct.register_service('compute-readonly',
+ # ReadOnlyCompute(compute.API()))
+ #direct.register_service('volume-v1', VolumeVersionOne(volume.API()))
+
router = direct.Router()
with_json = direct.JsonParamsMiddleware(router)
with_req = direct.PostParamsMiddleware(with_json)