Allowing manual configuration of Public IP attribute for LinuxNode
authorAlina Quereilhac <alina.quereilhac@inria.fr>
Mon, 4 Aug 2014 15:05:22 +0000 (17:05 +0200)
committerAlina Quereilhac <alina.quereilhac@inria.fr>
Mon, 4 Aug 2014 15:05:22 +0000 (17:05 +0200)
src/nepi/resources/linux/node.py
src/nepi/resources/linux/tap.py
src/nepi/resources/planetlab/tap.py

index 047dfe9..72af978 100644 (file)
@@ -195,8 +195,9 @@ class LinuxNode(ResourceManager):
         gateway = Attribute("gateway", "Hostname of the gateway machine",
                 flags = Flags.Design)
 
-        ip = Attribute("ip", "Linux host public IP address",
-                    flags = Flags.NoWrite)
+        ip = Attribute("ip", "Linux host public IP address. "
+                   "Must not be modified by the user unless hostname is 'localhost'",
+                    flags = Flags.Design)
 
         cls._register_attribute(hostname)
         cls._register_attribute(username)
@@ -367,12 +368,13 @@ class LinuxNode(ResourceManager):
         self.mkdir(paths)
 
         # Get Public IP address
-        if self.localhost:
-            ip = socket.gethostbyname(socket.gethostname())
-        else:
-            ip = socket.gethostbyname(self.get("hostname"))
+        if not self.get("ip"):
+            if self.localhost:
+                ip = socket.gethostbyname(socket.gethostname())
+            else:
+                ip = socket.gethostbyname(self.get("hostname"))
 
-        self.set("ip", ip)
+            self.set("ip", ip)
 
         super(LinuxNode, self).do_provision()
 
index a0ec93a..6b3dce6 100644 (file)
@@ -25,7 +25,6 @@ from nepi.resources.linux.node import LinuxNode
 from nepi.util.timefuncs import tnow, tdiffsec
 
 import os
-import socket
 import time
 
 PYTHON_VSYS_VERSION = "1.0"
@@ -334,8 +333,7 @@ class LinuxTap(LinuxApplication):
         if self.is_rm_instance(PlanetlabTap.get_rtype()):
             self.set("pi", True)
 
-        remote_ip = socket.gethostbyname(
-                remote_endpoint.node.get("ip"))
+        remote_ip = remote_endpoint.node.get("ip")
 
         local_port_file = os.path.join(connection_run_home, 
                 "local_port")
@@ -385,8 +383,7 @@ class LinuxTap(LinuxApplication):
     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(
-            remote_endpoint.node.get("ip")))
+        self.set("greRemote", remote_endpoint.node.get("ip"))
 
         # Generate GRE connect command
         command = ["("]
@@ -444,7 +441,7 @@ class LinuxTap(LinuxApplication):
         command.append("sudo -S ip link add %s type gre remote %s local %s ttl 64 csum key %s" % (
                 self.get("deviceName"),
                 self.get("greRemote"),
-                socket.gethostbyname(self.node.get("hostname")),
+                self.node.get("ip"),
                 self.get("greKey")
             ))
         command.append("sudo -S ip addr add %s/%d peer %s/%d dev %s" % (
index 1785f43..9a05422 100644 (file)
@@ -25,7 +25,6 @@ from nepi.resources.planetlab.node import PlanetlabNode
 from nepi.util.timefuncs import tnow, tdiffsec
 
 import os
-import socket
 import time
 
 PYTHON_VSYS_VERSION = "1.0"
@@ -386,8 +385,8 @@ class PlanetlabTap(LinuxApplication):
         # Set the remote endpoint
         self.set("pointopoint", remote_endpoint.get("ip4"))
 
-        remote_ip = socket.gethostbyname(
-                remote_endpoint.node.get("ip"))
+        print "REMOTE IP", remote_ip
+        remote_ip = remote_endpoint.node.get("ip")
 
         local_port_file = os.path.join(connection_run_home, 
                 "local_port")
@@ -435,8 +434,7 @@ class PlanetlabTap(LinuxApplication):
     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(
-            remote_endpoint.node.get("ip")))
+        self.set("greRemote", remote_endpoint.node.get("ip"))
 
         # Generate GRE connect command