Added PlanetlabTAP & PlanetlabTUN
[nepi.git] / src / nepi / resources / planetlab / node.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, ResourceState, \
22         reschedule_delay
23 from nepi.resources.linux.node import LinuxNode
24 from nepi.resources.planetlab.plcapi import PLCAPIFactory 
25
26
27 @clsinit_copy
28 class PlanetlabNode(LinuxNode):
29     _rtype = "PlanetlabNode"
30
31     @classmethod
32     def _register_attributes(cls):
33         ip = Attribute("ip", "PlanetLab host public IP address",
34                 flags = Flags.ReadOnly)
35
36         pl_url = Attribute("plcApiUrl", "URL of PlanetLab PLCAPI host (e.g. www.planet-lab.eu or www.planet-lab.org) ",
37                 default = "www.planet-lab.eu",
38                 flags = Flags.Credential)
39
40         pl_ptn = Attribute("plcApiPattern", "PLC API service regexp pattern (e.g. https://%(hostname)s:443/PLCAPI/ ) ",
41                 default = "https://%(hostname)s:443/PLCAPI/",
42                 flags = Flags.ExecReadOnly)
43
44         city = Attribute("city",
45                 "Constrain location (city) during resource discovery. May use wildcards.",
46                 flags = Flags.Filter)
47
48         country = Attribute("country",
49                 "Constrain location (country) during resource discovery. May use wildcards.",
50                 flags = Flags.Filter)
51
52         region = Attribute("region",
53                 "Constrain location (region) during resource discovery. May use wildcards.",
54                 flags = Flags.Filter)
55
56         architecture = Attribute("architecture",
57                 "Constrain architecture during resource discovery.",
58                 type = Types.Enumerate,
59                 allowed = ["x86_64",
60                             "i386"],
61                 flags = Flags.Filter)
62
63         operating_system = Attribute("operatingSystem",
64                 "Constrain operating system during resource discovery.",
65                 type = Types.Enumerate,
66                 allowed =  ["f8",
67                             "f12",
68                             "f14",
69                             "centos",
70                             "other"],
71                 flags = Flags.Filter)
72
73         site = Attribute("site",
74                 "Constrain the PlanetLab site this node should reside on.",
75                 type = Types.Enumerate,
76                 allowed = ["PLE",
77                             "PLC",
78                             "PLJ"],
79                 flags = Flags.Filter)
80
81         min_reliability = Attribute("minReliability",
82                 "Constrain reliability while picking PlanetLab nodes. Specifies a lower acceptable bound.",
83                 type = Types.Double,
84                 range = (1, 100),
85                 flags = Flags.Filter)
86
87         max_reliability = Attribute("maxReliability",
88                 "Constrain reliability while picking PlanetLab nodes. Specifies an upper acceptable bound.",
89                 type = Types.Double,
90                 range = (1, 100),
91                 flags = Flags.Filter)
92
93         min_bandwidth = Attribute("minBandwidth",
94                 "Constrain available bandwidth while picking PlanetLab nodes. Specifies a lower acceptable bound.",
95                 type = Types.Double,
96                 range = (0, 2**31),
97                 flags = Flags.Filter)
98
99         max_bandwidth = Attribute("maxBandwidth",
100                 "Constrain available bandwidth while picking PlanetLab nodes. Specifies an upper acceptable bound.",
101                 type = Types.Double,
102                 range = (0, 2**31),
103                 flags = Flags.Filter)
104
105         min_load = Attribute("minLoad",
106                 "Constrain node load average while picking PlanetLab nodes. Specifies a lower acceptable bound.",
107                 type = Types.Double,
108                 range = (0, 2**31),
109                 flags = Flags.Filter)
110
111         max_load = Attribute("maxLoad",
112                 "Constrain node load average while picking PlanetLab nodes. Specifies an upper acceptable bound.",
113                 type = Types.Double,
114                 range = (0, 2**31),
115                 flags = Flags.Filter)
116
117         min_cpu = Attribute("minCpu",
118                 "Constrain available cpu time while picking PlanetLab nodes. Specifies a lower acceptable bound.",
119                 type = Types.Double,
120                 range = (0, 100),
121                 flags = Flags.Filter)
122
123         max_cpu = Attribute("maxCpu",
124                 "Constrain available cpu time while picking PlanetLab nodes. Specifies an upper acceptable bound.",
125                 type = Types.Double,
126                 range = (0, 100),
127                 flags = Flags.Filter)
128
129         timeframe = Attribute("timeframe",
130                 "Past time period in which to check information about the node. Values are year,month, week, latest",
131                 default = "week",
132                 type = Types.Enumerate,
133                 allowed = ["latest",
134                             "week",
135                             "month",
136                             "year"],
137                  flags = Flags.Filter)
138
139         cls._register_attribute(ip)
140         cls._register_attribute(pl_url)
141         cls._register_attribute(pl_ptn)
142         cls._register_attribute(city)
143         cls._register_attribute(country)
144         cls._register_attribute(region)
145         cls._register_attribute(architecture)
146         cls._register_attribute(operating_system)
147         cls._register_attribute(min_reliability)
148         cls._register_attribute(max_reliability)
149         cls._register_attribute(min_bandwidth)
150         cls._register_attribute(max_bandwidth)
151         cls._register_attribute(min_load)
152         cls._register_attribute(max_load)
153         cls._register_attribute(min_cpu)
154         cls._register_attribute(max_cpu)
155         cls._register_attribute(timeframe)
156
157     def __init__(self, ec, guid):
158         super(PlanetlabNode, self).__init__(ec, guid)
159
160         self._plapi = None
161     
162     @property
163     def plapi(self):
164         if not self._plapi:
165             slicename = self.get("username")
166             pl_pass = self.get("password")
167             pl_url = self.get("plcApiUrl")
168             pl_ptn = self.get("plcApiPattern")
169
170             self._plapi =  PLCAPIFactory.get_api(slicename, pl_pass, pl_url,
171                     pl_ptn)
172             
173         return self._plapi
174
175     def valid_connection(self, guid):
176         # TODO: Validate!
177         return True
178
179     def blacklist(self):
180         # TODO!!!!
181         self.warn(" Blacklisting malfunctioning node ")
182         #import util
183         #util.appendBlacklist(self.hostname)
184