X-Git-Url: http://git.onelab.eu/?a=blobdiff_plain;f=src%2Fnepi%2Fresources%2Flinux%2Fccn%2Ffibentry.py;h=4b7e9c48dd4d75de628e4d2ec31532062d081b09;hb=cb816db417dff4d0f985455c1d7cbd261fd40f9b;hp=48c2d6de53fa81f85537f890c270f412d9e3944e;hpb=386498468dfb01f71b0efbbe0c208819f18f82ec;p=nepi.git diff --git a/src/nepi/resources/linux/ccn/fibentry.py b/src/nepi/resources/linux/ccn/fibentry.py index 48c2d6de..4b7e9c48 100644 --- a/src/nepi/resources/linux/ccn/fibentry.py +++ b/src/nepi/resources/linux/ccn/fibentry.py @@ -42,7 +42,7 @@ class LinuxFIBEntry(LinuxApplication): uri = Attribute("uri", "URI prefix to match and route for this FIB entry", default = "ccnx:/", - flags = Flags.ExecReadOnly) + flags = Flags.Design) protocol = Attribute("protocol", "Transport protocol used in network connection to peer " @@ -50,20 +50,20 @@ class LinuxFIBEntry(LinuxApplication): type = Types.Enumerate, default = "udp", allowed = ["udp", "tcp"], - flags = Flags.ExecReadOnly) + flags = Flags.Design) host = Attribute("host", "Peer hostname used in network connection for this FIB entry. ", - flags = Flags.ExecReadOnly) + flags = Flags.Design) port = Attribute("port", "Peer port address used in network connection to peer " "for this FIB entry.", - flags = Flags.ExecReadOnly) + flags = Flags.Design) ip = Attribute("ip", "Peer host public IP used in network connection for this FIB entry. ", - flags = Flags.ReadOnly) + flags = Flags.Design) cls._register_attribute(uri) cls._register_attribute(protocol) @@ -85,14 +85,37 @@ class LinuxFIBEntry(LinuxApplication): super(LinuxFIBEntry, self).__init__(ec, guid) self._home = "fib-%s" % self.guid self._ping = None - self._mtr = None self._traceroute = None + self._ccnd = None @property def ccnd(self): - ccnd = self.get_connected(LinuxCCND.rtype()) - if ccnd: return ccnd[0] - return None + if not self._ccnd: + ccnd = self.get_connected(LinuxCCND.get_rtype()) + if ccnd: + self._ccnd = ccnd[0] + + return self._ccnd + + @property + def ping(self): + if not self._ping: + from nepi.resources.linux.ping import LinuxPing + ping = self.get_connected(LinuxPing.get_rtype()) + if ping: + self._ping = ping[0] + + return self._ping + + @property + def traceroute(self): + if not self._traceroute: + from nepi.resources.linux.traceroute import LinuxTraceroute + traceroute = self.get_connected(LinuxTraceroute.get_rtype()) + if traceroute: + self._traceroute = traceroute[0] + + return self._traceroute @property def node(self): @@ -101,44 +124,42 @@ class LinuxFIBEntry(LinuxApplication): def trace(self, name, attr = TraceAttr.ALL, block = 512, offset = 0): if name == "ping": - return self.ec.trace(self._ping, "stdout", attr, block, offset) - if name == "mtr": - return self.ec.trace(self._mtr, "stdout", attr, block, offset) + if not self.ping: + return None + return self.ec.trace(self.ping.guid, "stdout", attr, block, offset) + if name == "traceroute": - return self.ec.trace(self._traceroute, "stdout", attr, block, offset) + if not self.traceroute: + return None + return self.ec.trace(self.traceroute.guid, "stdout", attr, block, offset) return super(LinuxFIBEntry, self).trace(name, attr, block, offset) - - def deploy(self): + + def do_deploy(self): # Wait until associated ccnd is provisioned if not self.ccnd or self.ccnd.state < ResourceState.READY: # ccnr needs to wait until ccnd is deployed and running self.ec.schedule(reschedule_delay, self.deploy) else: - try: - if not self.get("ip"): - host = self.get("host") - ip = socket.gethostbyname(host) - self.set("ip", ip) + if not self.get("ip"): + host = self.get("host") + ip = socket.gethostbyname(host) + self.set("ip", ip) - if not self.get("command"): - self.set("command", self._start_command) + if not self.get("command"): + self.set("command", self._start_command) - if not self.get("env"): - self.set("env", self._environment) + if not self.get("env"): + self.set("env", self._environment) - command = self.get("command") + command = self.get("command") - self.info("Deploying command '%s' " % command) + self.info("Deploying command '%s' " % command) - self.discover() - self.provision() - self.configure() - except: - self.fail() - return + self.do_discover() + self.do_provision() + self.configure() - self.debug("----- READY ---- ") self.set_ready() def upload_start_command(self): @@ -164,37 +185,30 @@ class LinuxFIBEntry(LinuxApplication): raise RuntimeError, msg def configure(self): - if self.trace_enabled("ping"): + if self.trace_enabled("ping") and not self.ping: self.info("Configuring PING trace") - self._ping = self.ec.register_resource("LinuxPing") - self.ec.set(self._ping, "printTimestamp", True) - self.ec.set(self._ping, "target", self.get("host")) - self.ec.register_connection(self._ping, self.node.guid) + ping = self.ec.register_resource("LinuxPing") + self.ec.set(ping, "printTimestamp", True) + self.ec.set(ping, "target", self.get("host")) + self.ec.set(ping, "earlyStart", True) + self.ec.register_connection(ping, self.node.guid) + self.ec.register_connection(ping, self.guid) # schedule ping deploy - self.ec.deploy(guids=[self._ping], group = self.deployment_group) - - if self.trace_enabled("mtr"): - self.info("Configuring MTR trace") - self._mtr = self.ec.register_resource("LinuxMtr") - self.ec.set(self._mtr, "noDns", True) - self.ec.set(self._mtr, "printTimestamp", True) - self.ec.set(self._mtr, "continuous", True) - self.ec.set(self._mtr, "target", self.get("host")) - self.ec.register_connection(self._mtr, self.node.guid) - # schedule mtr deploy - self.ec.deploy(guids=[self._mtr], group = self.deployment_group) + self.ec.deploy(guids=[ping], group = self.deployment_group) - if self.trace_enabled("traceroute"): + if self.trace_enabled("traceroute") and not self.traceroute: self.info("Configuring TRACEROUTE trace") - self._traceroute = self.ec.register_resource("LinuxTraceroute") - self.ec.set(self._traceroute, "printTimestamp", True) - self.ec.set(self._traceroute, "continuous", True) - self.ec.set(self._traceroute, "target", self.get("host")) - self.ec.register_connection(self._traceroute, self.node.guid) + traceroute = self.ec.register_resource("LinuxTraceroute") + self.ec.set(traceroute, "printTimestamp", True) + self.ec.set(traceroute, "continuous", True) + self.ec.set(traceroute, "target", self.get("host")) + self.ec.set(traceroute, "earlyStart", True) + self.ec.register_connection(traceroute, self.node.guid) + self.ec.register_connection(traceroute, self.guid) # schedule mtr deploy - self.ec.deploy(guids=[self._traceroute], group = self.deployment_group) + self.ec.deploy(guids=[traceroute], group = self.deployment_group) - def start(self): + def do_start(self): if self.state == ResourceState.READY: command = self.get("command") self.info("Starting command '%s'" % command) @@ -203,9 +217,9 @@ class LinuxFIBEntry(LinuxApplication): else: msg = " Failed to execute command '%s'" % command self.error(msg, out, err) - self.fail() + raise RuntimeError, msg - def stop(self): + def do_stop(self): command = self.get('command') env = self.get('env') @@ -221,7 +235,7 @@ class LinuxFIBEntry(LinuxApplication): if err: msg = " Failed to execute command '%s'" % command self.error(msg, out, err) - self.fail() + raise RuntimeError, msg @property def _start_command(self):