README moves to markdown
[nepi.git] / nepi / resources / linux / ns3 / ccn / ns3ccndceapplication.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.ns3ccndceapplication import NS3BaseCCNDceApplication
22
23 @clsinit_copy
24 class LinuxNS3CCNDceApplication(NS3BaseCCNDceApplication):
25     _rtype = "linux::ns3::dce::CCNApplication"
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         files = Attribute("files", 
48                 "Semi-colon separated list of 'key=value' pairs to set as "
49                 "DCE files (AddFile). The key should be a path to a local file "
50                 "and the key is the path to be set in DCE for that file" ,
51                 flags = Flags.Design)
52
53         stdinfile = Attribute("stdinFile", 
54                 "File to set as StdinFile. The value shoudl be either an empty "
55                 "or a path to a local file ",
56                 flags = Flags.Design)
57         
58         cls._register_attribute(sources)
59         cls._register_attribute(build)
60         cls._register_attribute(depends)
61         cls._register_attribute(files)
62         cls._register_attribute(stdinfile)
63
64     def _instantiate_object(self):
65         command = []
66
67         # Install package dependencies required to run the binary 
68         depends = self.get("depends")
69         if depends:
70             dcmd = self.simulation.install_dependencies(depends = depends)
71             if dcmd:
72                 command.append(dcmd)
73        
74         # Upload sources to generate the binary
75         sources = self.get("sources")
76         if sources:
77             scmd = self.simulation.upload_extra_sources(sources = sources)
78             if scmd:
79                 command.append(scmd)
80                 
81         # Upload instructions to build the binary
82         build = self.get("build")
83         if build:
84             bcmd = self.simulation.build(build = build)
85             if bcmd:
86                 command.append(bcmd)
87
88         # Upload CCN files (e.g. repo)
89         files = self.get("files")
90         if files:
91             upload = []
92             for file in map(str.strip, files.split(";")):
93                 localpath, dcepath = files.split("=")
94                 upload.append(localpath)
95
96             sources = ";".join(upload)
97             fcmd = self.simulation.upload_extra_sources(sources = sources,
98                     src_dir = self.simulation.app_home)
99
100             if fcmd:
101                 command.append(fcmd)
102
103         if command:
104             deploy_command = ";".join(command)
105             prefix = "%d_deploy" % self.guid 
106             self.simulation.execute_deploy_command(deploy_command, prefix=prefix)
107