README moves to markdown
[nepi.git] / nepi / resources / linux / ccn / ccnapplication.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.resource import clsinit_copy, ResourceState
20 from nepi.resources.linux.application import LinuxApplication
21 from nepi.resources.linux.ccn.ccnd import LinuxCCND
22
23 import os
24
25 @clsinit_copy
26 class LinuxCCNApplication(LinuxApplication):
27     _rtype = "linux::CCNApplication"
28
29     def __init__(self, ec, guid):
30         super(LinuxCCNApplication, self).__init__(ec, guid)
31         self._home = "ccnapp-%s" % self.guid
32
33     @property
34     def ccnd(self):
35         ccnd = self.get_connected(LinuxCCND.get_rtype())
36         if ccnd: return ccnd[0]
37         return None
38
39     @property
40     def node(self):
41         if self.ccnd: return self.ccnd.node
42         return None
43
44     def do_deploy(self):
45         if not self.ccnd or self.ccnd.state < ResourceState.READY:
46             self.debug("---- RESCHEDULING DEPLOY ---- node state %s " % self.node.state )
47             self.ec.schedule(self.reschedule_delay, self.deploy)
48         else:
49             command = self.get("command") or ""
50
51             self.info("Deploying command '%s' " % command)
52             
53             if not self.get("env"):
54                 self.set("env", self._environment)
55
56             self.do_discover()
57             self.do_provision()
58
59             self.set_ready()
60
61     @property
62     def _environment(self):
63         return self.ccnd.path
64        
65     def valid_connection(self, guid):
66         # TODO: Validate!
67         return True
68