Refactoring LinuGRETunnel
[nepi.git] / src / nepi / resources / linux / tap.py
index 7390dfb..24efdff 100644 (file)
@@ -211,7 +211,45 @@ class LinuxTap(LinuxApplication):
 
         super(LinuxTap, self).do_release()
 
-    def gre_connect_command(self, remote_endpoint, connection_run_home): 
+    def gre_connect(self, remote_endpoint, connection_app_home,
+            connection_run_home):
+        gre_connect_command = self._gre_connect_command(
+                remote_endpoint, connection_run_home)
+
+        # upload command to connect.sh script
+        shfile = os.path.join(connection_app_home, "gre-connect.sh")
+        endpoint.node.upload(gre_connect_command,
+                shfile,
+                text = True, 
+                overwrite = False)
+
+        # invoke connect script
+        cmd = "bash %s" % shfile
+        (out, err), proc = self.node.run(cmd, connection_run_home) 
+             
+        # check if execution errors occurred
+        msg = " Failed to connect endpoints "
+        
+        if proc.poll() or err:
+            self.error(msg, out, err)
+            raise RuntimeError, msg
+    
+        # Wait for pid file to be generated
+        pid, ppid = self.node.wait_pid(connection_run_home)
+        
+        # If the process is not running, check for error information
+        # on the remote machine
+        if not pid or not ppid:
+            (out, err), proc = self.node.check_errors(connection_run_home)
+            # Out is what was written in the stderr file
+            if err:
+                msg = " Failed to start command '%s' " % command
+                self.error(msg, out, err)
+                raise RuntimeError, msg
+        
+        return True
+
+    def _gre_connect_command(self, remote_endpoint, connection_run_home): 
         # Set the remote endpoint
         self.set("pointopoint", remote_endpoint.get("ip4"))
         self.set("greRemote", socket.gethostbyname(