rename src/nepi/ into just nepi/
[nepi.git] / nepi / resources / linux / ccn / ccncat.py
1 #
2 #    NEPI, a framework to manage network experiments
3 #    Copyright (C) 2013 INRIA
4 #
5 #    This program is free software: you can redistribute it and/or modify
6 #    it under the terms of the GNU General Public License version 2 as
7 #    published by the Free Software Foundation;
8 #
9 #    This program is distributed in the hope that it will be useful,
10 #    but WITHOUT ANY WARRANTY; without even the implied warranty of
11 #    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12 #    GNU General Public License for more details.
13 #
14 #    You should have received a copy of the GNU General Public License
15 #    along with this program.  If not, see <http://www.gnu.org/licenses/>.
16 #
17 # Author: Alina Quereilhac <alina.quereilhac@inria.fr>
18
19 from nepi.execution.attribute import Attribute, Flags, Types
20 from nepi.execution.resource import clsinit_copy, ResourceState
21 from nepi.resources.linux.ccn.ccnapplication import LinuxCCNApplication
22
23 import os
24
25 @clsinit_copy
26 class LinuxCCNCat(LinuxCCNApplication):
27     _rtype = "linux::CCNCat"
28
29     @classmethod
30     def _register_attributes(cls):
31         content_name = Attribute("contentName",
32             "Content name for the content to peek",
33             flags = Flags.Design)
34
35         pipeline = Attribute("pipeline",
36             "CCNCat pipeline",
37             flags = Flags.Design)
38
39         cls._register_attribute(content_name)
40         cls._register_attribute(pipeline)
41
42     def __init__(self, ec, guid):
43         super(LinuxCCNCat, self).__init__(ec, guid)
44         self._home = "ccncat-%s" % self.guid
45
46     def do_deploy(self):
47         if not self.ccnd or self.ccnd.state < ResourceState.READY:
48             self.debug("---- RESCHEDULING DEPLOY ---- node state %s " % self.node.state )
49             self.ec.schedule(self.reschedule_delay, self.deploy)
50         else:
51             command = self.get("command")
52             if not command:
53                 command = "ccncat %s" % self.get("contentName")
54             if self.get("pipeline"):
55                 command += " -p %s " % self.get("pipeline")
56
57             self.set("command", command) 
58
59             self.info("Deploying command '%s' " % command)
60             
61             if not self.get("env"):
62                 self.set("env", self._environment)
63
64             self.do_discover()
65             self.do_provision()
66
67             self.set_ready()
68
69     def valid_connection(self, guid):
70         # TODO: Validate!
71         return True
72