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