Trying to make LinuxNS3Simulator to deploy remotely ....
[nepi.git] / src / nepi / resources / linux / mtr.py
index 0bf5fae..b694443 100644 (file)
@@ -34,52 +34,75 @@ class LinuxMtr(LinuxApplication):
             "sets mtr --report-cycles (-c) option. Determines the number of "
             "pings sent to determine both machines in the networks. Each "
             "cycle lasts one sencond.",
-            flags = Flags.ExecReadOnly)
+            flags = Flags.Design)
 
         no_dns = Attribute("noDns",
             "sets mtr --no-dns (-n) option. Forces mtr to display IPs intead of "
             "trying to resolve to host names ",
             type = Types.Bool,
             default = True,
-            flags = Flags.ExecReadOnly)
+            flags = Flags.Design)
 
         address = Attribute("address",
             "sets mtr --address (-a) option. Binds the socket to send outgoing "
             "packets to the interface of the specified address, so that any "
             "any packets are sent through this interface. ",
-            flags = Flags.ExecReadOnly)
+            flags = Flags.Design)
 
         interval = Attribute("interval",
             "sets mtr --interval (-i) option. Specifies the number of seconds "
             "between ICMP ECHO requests. Default value is one second ",
-            flags = Flags.ExecReadOnly)
+            flags = Flags.Design)
+
+        countinuous = Attribute("continuous",
+            "Run mtr in a while loop",
+            type = Types.Bool,
+            default = False,
+            flags = Flags.Design)
+
+        print_timestamp = Attribute("printTimestamp",
+            "Print timestamp before running mtr",
+            type = Types.Bool,
+            default = False,
+            flags = Flags.Design)
 
         target = Attribute("target",
             "mtr target host (host that will be pinged)",
-            flags = Flags.ExecReadOnly)
+            flags = Flags.Design)
 
         cls._register_attribute(report_cycles)
         cls._register_attribute(no_dns)
         cls._register_attribute(address)
         cls._register_attribute(interval)
+        cls._register_attribute(countinuous)
+        cls._register_attribute(print_timestamp)
         cls._register_attribute(target)
 
     def __init__(self, ec, guid):
         super(LinuxMtr, self).__init__(ec, guid)
         self._home = "mtr-%s" % self.guid
+        self._sudo_kill = True
 
-    def deploy(self):
+    def do_deploy(self):
         if not self.get("command"):
             self.set("command", self._start_command)
 
+        if not self.get("env"):
+            self.set("env", "PATH=$PATH:/usr/sbin/")
+
         if not self.get("depends"):
             self.set("depends", "mtr")
 
-        super(LinuxMtr, self).deploy()
+        super(LinuxMtr, self).do_deploy()
 
     @property
     def _start_command(self):
         args = []
+        if self.get("continuous") == True:
+            args.append("while true; do ")
+        if self.get("printTimestamp") == True:
+            args.append("""echo "`date +'%Y%m%d%H%M%S'`";""")
+        args.append("sudo -S mtr --report")
         if self.get("reportCycles"):
             args.append("-c %s" % self.get("reportCycles"))
         if self.get("noDns") == True:
@@ -87,10 +110,10 @@ class LinuxMtr(LinuxApplication):
         if self.get("address"):
             args.append("-a %s" % self.get("address"))
         args.append(self.get("target"))
+        if self.get("continuous") == True:
+            args.append("; done ")
 
-        command = """echo "Starting mtr `date +'%Y%m%d%H%M%S'`"; """
-        command += " sudo -S mtr --report "
-        command += " ".join(args)
+        command = " ".join(args)
 
         return command