Added dummynet accessors.
authorMarta Carbone <marta@prova.iet.unipi.it>
Wed, 17 Dec 2008 11:15:34 +0000 (11:15 +0000)
committerMarta Carbone <marta@prova.iet.unipi.it>
Wed, 17 Dec 2008 11:15:34 +0000 (11:15 +0000)
Added UpdateEmulationLink method, used to
create a connection between a node and a dummynet box.

Still need to delete dummynet box related tags when
deleting a dummynet box.

PLC/Accessors/Accessors_standard.py
PLC/Methods/UpdateEmulationLink.py [new file with mode: 0644]
PLC/Methods/__init__.py

index db7858f..6a97d41 100644 (file)
@@ -27,6 +27,9 @@ define_accessors(current_module, Slice, "Vref", "vref",
 define_accessors(current_module, Node, "Arch", "arch",  
                  "node/config", "architecture name", 
                  get_roles=all_roles, set_roles=tech_roles, expose_in_api=True)
+# define the dummynet connection to a node
+define_accessors(current_module, Node, "Dummynet", "dummynet", "node/config",
+                 "dummynet box connected to the node", get_roles=all_roles, set_roles="pi")
 # distribution to be deployed
 define_accessors(current_module, Node, "Pldistro", "pldistro",
                  "node/config", "PlanetLab distribution", 
diff --git a/PLC/Methods/UpdateEmulationLink.py b/PLC/Methods/UpdateEmulationLink.py
new file mode 100644 (file)
index 0000000..046f881
--- /dev/null
@@ -0,0 +1,87 @@
+# Connect a Node with a Dummynet box, using Accessors
+#
+# Marta Carbone - unipi
+# $Id$
+
+from PLC.Faults import *
+from PLC.Method import Method
+from PLC.Parameter import Parameter, Mixed
+from PLC.Nodes import Node, Nodes
+from PLC.NodeGroups import NodeGroup, NodeGroups
+from PLC.Sites import Site, Sites
+from PLC.Auth import Auth
+from PLC.Accessors.Accessors_standard import *                 # import dummynet accessors
+
+class UpdateEmulationLink(Method):
+    """
+    Connect a Node with a Dummynet box.
+    Takes as input two node_id, the first should be a regular node,
+    the second a dummynet box.
+
+    This operation is restricted to PIs and techs owner of the site
+    on which the Dummynet box and the Node are located.
+    Admins may create emulation links for any site, but the Dummynet
+    and the Node must belong to the same site.
+
+    XXX Dummynet accessors should not be called directly, since they can
+    be used to create connection whitout checks.
+
+    Returns 1 if successful, faults otherwise.
+    """
+
+    roles = ['admin', 'pi', 'tech']
+
+    accepts = [
+        Auth(),
+        Parameter(int, 'node_id'),      # a node
+        Mixed(Parameter(int, 'node_id'), # a dummynet box, or None to delete the entry
+              None),
+    ]
+
+    returns = Parameter(int, '1 is successful, fault otherwise')
+
+    # Before to create the link we do the following checks:
+    #  - node existence,
+    #  - dummnet box existence,
+    #  - right roles (admin, pi, tech),
+    #  - node and dummynet box site should match.
+
+    def call(self, auth, node_id, dummynet_id):
+
+        assert self.caller is not None
+
+        # check for node existence
+        # Retrieve nodes from database
+        # We do not fetch both node and dummynet
+        # since we need to preserve the order of returned objects
+        nodes= Nodes(self.api, {'node_id':node_id, 'node_type':'regular'})
+        if not nodes:
+            raise PLCInvalidArgument, "Node %s not found" % node_id
+        node = nodes[0]
+
+        # check for dummynet box existence
+        nodes = Nodes(self.api, {'node_id':dummynet_id, 'node_type':'dummynet'})
+        if (dummynet_id != None) and not nodes:
+            raise PLCInvalidArgument, "Dummynet box %s not found" % dummynet_id
+
+        # check for site matching when create a link
+        if (dummynet_id != None):
+            dummynet = nodes[0]
+
+            # check if the node and the dummynet_id
+            # belong to the same site
+            if (node['site_id'] != dummynet['site_id']):
+                raise PLCInvalidArgument, \
+                      "The Dummynet box must belog to the same site of the Node"
+
+        # check for roles permission to call this method
+        if 'admin' not in self.caller['roles']:
+            if site not in self.caller['site_ids']:
+                raise PLCPermissionDenied, "Not allowed to manage on this link"
+
+        # Add the dummynetbox
+        emulation_link = SetNodeDummynet(self.api)
+        emulation_link.call(auth, node_id, dummynet_id)
+
+        return 1
+
index a6fc8bc..f82f004 100644 (file)
@@ -148,6 +148,7 @@ SliceUsersList
 UpdateAddress
 UpdateAddressType
 UpdateConfFile
+UpdateEmulationLink
 UpdateIlink
 UpdateInitScript
 UpdateInterface