Changing reschedule_delay internals
[nepi.git] / src / nepi / resources / linux / ccn / ccnpingserver.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 as published by
7 #    the Free Software Foundation, either version 3 of the License, or
8 #    (at your option) any later version.
9 #
10 #    This program is distributed in the hope that it will be useful,
11 #    but WITHOUT ANY WARRANTY; without even the implied warranty of
12 #    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13 #    GNU General Public License for more details.
14 #
15 #    You should have received a copy of the GNU General Public License
16 #    along with this program.  If not, see <http://www.gnu.org/licenses/>.
17 #
18 # Author: Alina Quereilhac <alina.quereilhac@inria.fr>
19
20 from nepi.execution.attribute import Attribute, Flags, Types
21 from nepi.execution.resource import ResourceManager, clsinit_copy, \
22         ResourceState
23 from nepi.resources.linux.ccn.ccnapplication import LinuxCCNApplication
24 from nepi.util.timefuncs import tnow, tdiffsec
25
26 import os
27
28 @clsinit_copy
29 class LinuxCCNPingServer(LinuxCCNApplication):
30     _rtype = "LinuxCCNPingServer"
31
32     @classmethod
33     def _register_attributes(cls):
34         daemon = Attribute("d",
35             "Run ccnping server as a daemon in background",
36             type = Types.Bool,
37             default = False,
38             flags = Flags.Design)
39
40         freshness = Attribute("x",
41             "Set FreshnessSeconds",
42             type = Types.Integer,
43             flags = Flags.Design)
44
45         prefix = Attribute("prefix",
46             "Prefix to serve content (e.g. ccnx:/name/prefix)",
47             flags = Flags.Design)
48
49         cls._register_attribute(daemon)
50         cls._register_attribute(freshness)
51         cls._register_attribute(prefix)
52
53     def __init__(self, ec, guid):
54         super(LinuxCCNPingServer, self).__init__(ec, guid)
55         self._home = "ccnping-serv-%s" % self.guid
56
57     def do_deploy(self):
58         if not self.get("command"):
59             self.set("command", self._start_command)
60
61         if not self.get("env"):
62             self.set("env", self._environment)
63
64         if not self.get("depends"):
65             self.set("depends", self._dependencies)
66
67         if not self.get("build"):
68             self.set("build", self._build)
69
70         if not self.get("install"):
71             self.set("install", self._install)
72
73         super(LinuxCCNPingServer, self).do_deploy()
74
75     @property
76     def _start_command(self):
77         args = []
78         args.append("ccnpingserver")
79         args.append(self.get("prefix"))
80         if self.get("d") == True:
81             args.append("-d")
82         if self.get("x"):
83             args.append("-x %d" % self.get("x"))
84
85         command = " ".join(args)
86
87         return command
88
89     @property
90     def _dependencies(self):
91         return "git"
92
93     @property
94     def _build(self):
95         return (
96             # Evaluate if ccnx binaries are already installed
97             " ( "
98                 " test -f ${BIN}/ccnping && "
99                 " echo 'binaries found, nothing to do' "
100             " ) || ( "
101             # If not, untar and build
102                 " ( "
103                     " git clone git://github.com/NDN-Routing/ccnping ${SRC}/ccnping "
104                  " ) && "
105                     # build
106                     "cd ${SRC}/ccnping && "
107                     " ( "
108                     " ./configure LDFLAGS=-L${SRC}/ccnx-0.7.2/lib CFLAGS=-I${SRC}/ccnx-0.7.2/include "
109                     " --prefix=${BIN}/ccnping && make "
110                     " ) "
111              " )") 
112
113     @property
114     def _install(self):
115         return (
116             # Evaluate if ccnx binaries are already installed
117             " ( "
118                 " test -f ${BIN}/ccnping && "
119                 " echo 'binaries found, nothing to do' "
120             " ) || ( "
121             # If not, install
122                 "  mkdir -p ${BIN}/ccnping && "
123                 "  mv ${SRC}/ccnping/ccnping ${BIN}/ccnping/ && "
124                 "  mv ${SRC}/ccnping/ccnpingserver ${BIN}/ccnping/ "
125             " )"
126             )
127
128     @property
129     def _environment(self):
130         return "%s:%s" % (self.ccnd.path, "${BIN}/ccnping")
131        
132     def valid_connection(self, guid):
133         # TODO: Validate!
134         return True
135