covnert network configuration plugin to network configuration aspect thing
smbaker [Mon, 27 May 2013 21:53:21 +0000 (14:53 -0700)]
apps/gacks/netconfigaspects.py [new file with mode: 0644]

diff --git a/apps/gacks/netconfigaspects.py b/apps/gacks/netconfigaspects.py
new file mode 100644 (file)
index 0000000..5531901
--- /dev/null
@@ -0,0 +1,55 @@
+\177377from pyaspects.weaver import weave_class_method
+from pyaspects.meta import MetaAspect
+from PLC.bridgeconfig import AutoConfig
+from PLC.Method import Method
+from PLC.Slices import Slices
+
+import functools
+import os
+import sys
+import socket
+
+class _API:
+    def __init__(self, api, auth):
+        self.api = api
+        self.auth = auth
+
+    def __getattr__(self, name):
+        return functools.partial(self.api.callable(name), self.auth)
+
+class BaseNetConfig(object):
+    def __init__(self):
+        pass
+
+    def after(self, wobj, data, *args, **kwargs):
+        api_method_name = wobj.name\r
+\r
+        if api_method_name == "AddSliceToNodes" or api_method_name == "DeleteSliceFromNodes":\r
+            api = wobj.api\r
+            auth = args[0]\r
+            slice_id_or_name = args[1]\r
+            slices = Slices(api, [slice_id_or_name])\r
+            if len(slices) > 0:\r
+                AutoConfig(_API(wobj.api, auth), slices[0], {})\r
+\r
+\r
+    def before(self, wobj, data, *args, **kwargs):\r
+        pass\r
+\r
+class NetConfigAspect_class(BaseNetConfig):
+    __metaclass__ = MetaAspect
+    name = "netconfigaspect_class"
+
+    def __init__(self):
+        BaseNetConfig.__init__(self)
+
+    def before(self, wobj, data, *args, **kwargs):
+        BaseNetConfig.before(self, wobj, data, *args, **kwargs)
+
+    def after(self, wobj, data, *args, **kwargs):
+        BaseNetConfig.after(self, wobj, data, *args, **kwargs)
+
+NetConfigAspect = NetConfigAspect_class
+
+def apply_netconfig_aspect():
+    weave_class_method(NetConfigAspect(), Method, "__call__")