df24dbdb071887ca21755d204f7086cb2bd9a915
[nepi.git] / src / nepi / resources / linux / ns3 / ns3dceapplication.py
1 #
2 #    NEPI, a framework to manage network experiments
3 #    Copyright (C) 2014 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 clsinit_copy, ResourceState, reschedule_delay
22 from nepi.resources.ns3.ns3dceapplication import NS3BaseDceApplication
23
24 @clsinit_copy
25 class LinuxNS3DceApplication(NS3BaseDceApplication):
26     _rtype = "ns3::LinuxDceApplication"
27
28     @classmethod
29     def _register_attributes(cls):
30         sources = Attribute("sources",
31                 "Path to tar.gz file with sources for the application execute in DCE. "
32                 "Sources will be uploaded to ${SRC} and it is the responsibility of "
33                 "the build instructions (in the build attribute) to copy the compiled "
34                 "binaries to the ${BIN_DCE} directory",
35                 flags = Flags.Design)
36
37         build = Attribute("build",
38                 "Instructions to compile sources DCE-compatible way. "
39                 "Note that sources will be uploaded to ${SRC} and the "
40                 "build instructions are responsible for copying the "
41                 "binaries to the ${BIN_DCE} directory. ",
42                 flags = Flags.Design)
43
44         depends = Attribute("depends", 
45                 "Space-separated list of packages required to run the application",
46                 flags = Flags.Design)
47
48         cls._register_attribute(sources)
49         cls._register_attribute(build)
50         cls._register_attribute(depends)
51
52     def _instantiate_object(self):
53         command = []
54
55         # Install package dependencies required to run the binary 
56         depends = self.get("depends")
57         if depends:
58             dcmd = self.simulation.install_dependencies(depends = depends)
59             if dcmd:
60                 command.append(dcmd)
61        
62         # Upload sources to generate the binary
63         sources = self.get("sources")
64         if sources:
65             scmd = self.simulation.upload_extra_sources(sources = sources)
66             if scmd:
67                 command.append(scmd)
68                 
69         # Upload instructions to build the binary
70         build = self.get("build")
71         if build:
72             bcmd = self.simulation.build(build = build)
73             if bcmd:
74                 command.append(bcmd)
75
76         if command:
77             deploy_command = ";".join(command)
78             prefix = "%d_deploy" % self.guid 
79             self.simulation.execute_deploy_command(deploy_command, prefix=prefix)
80