4 # Copyright 2016 RIFT.IO Inc
6 # Licensed under the Apache License, Version 2.0 (the "License");
7 # you may not use this file except in compliance with the License.
8 # You may obtain a copy of the License at
10 # http://www.apache.org/licenses/LICENSE-2.0
12 # Unless required by applicable law or agreed to in writing, software
13 # distributed under the License is distributed on an "AS IS" BASIS,
14 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 # See the License for the specific language governing permissions and
16 # limitations under the License.
30 from rift
.rwlib
.util
import certs
31 import rift
.rwcal
.cloudsim
32 import rift
.rwcal
.cloudsim
.net
34 import rift
.vcs
.core
as core
38 import rift
.rwcal
.cloudsim
39 import rift
.rwcal
.cloudsim
.net
41 from rift
.vcs
.ext
import ClassProperty
43 logger
= logging
.getLogger(__name__
)
46 class NsmTasklet(rift
.vcs
.core
.Tasklet
):
48 This class represents a network services manager tasklet.
51 def __init__(self
, name
='network-services-manager', uid
=None,
53 recovery_action
=core
.RecoveryType
.FAILCRITICAL
.value
,
54 data_storetype
=core
.DataStore
.NOSTORE
.value
,
57 Creates a NsmTasklet object.
60 name - the name of the tasklet
61 uid - a unique identifier
63 super(NsmTasklet
, self
).__init
__(name
=name
, uid
=uid
,
64 config_ready
=config_ready
,
65 recovery_action
=recovery_action
,
66 data_storetype
=data_storetype
,
69 plugin_directory
= ClassProperty('./usr/lib/rift/plugins/rwnsmtasklet')
70 plugin_name
= ClassProperty('rwnsmtasklet')
73 class VnsTasklet(rift
.vcs
.core
.Tasklet
):
75 This class represents a network services manager tasklet.
78 def __init__(self
, name
='virtual-network-service', uid
=None,
80 recovery_action
=core
.RecoveryType
.FAILCRITICAL
.value
,
81 data_storetype
=core
.DataStore
.NOSTORE
.value
,
84 Creates a VnsTasklet object.
87 name - the name of the tasklet
88 uid - a unique identifier
90 super(VnsTasklet
, self
).__init
__(name
=name
, uid
=uid
,
91 config_ready
=config_ready
,
92 recovery_action
=recovery_action
,
93 data_storetype
=data_storetype
,
96 plugin_directory
= ClassProperty('./usr/lib/rift/plugins/rwvnstasklet')
97 plugin_name
= ClassProperty('rwvnstasklet')
100 class VnfmTasklet(rift
.vcs
.core
.Tasklet
):
102 This class represents a virtual network function manager tasklet.
105 def __init__(self
, name
='virtual-network-function-manager', uid
=None,
107 recovery_action
=core
.RecoveryType
.FAILCRITICAL
.value
,
108 data_storetype
=core
.DataStore
.NOSTORE
.value
,
111 Creates a VnfmTasklet object.
114 name - the name of the tasklet
115 uid - a unique identifier
117 super(VnfmTasklet
, self
).__init
__(name
=name
, uid
=uid
,
118 config_ready
=config_ready
,
119 recovery_action
=recovery_action
,
120 data_storetype
=data_storetype
,
123 plugin_directory
= ClassProperty('./usr/lib/rift/plugins/rwvnfmtasklet')
124 plugin_name
= ClassProperty('rwvnfmtasklet')
127 class ResMgrTasklet(rift
.vcs
.core
.Tasklet
):
129 This class represents a Resource Manager tasklet.
132 def __init__(self
, name
='Resource-Manager', uid
=None,
134 recovery_action
=core
.RecoveryType
.FAILCRITICAL
.value
,
135 data_storetype
=core
.DataStore
.NOSTORE
.value
,
138 Creates a ResMgrTasklet object.
141 name - the name of the tasklet
142 uid - a unique identifier
144 super(ResMgrTasklet
, self
).__init
__(name
=name
, uid
=uid
,
145 config_ready
=config_ready
,
146 recovery_action
=recovery_action
,
147 data_storetype
=data_storetype
,
150 plugin_directory
= ClassProperty('./usr/lib/rift/plugins/rwresmgrtasklet')
151 plugin_name
= ClassProperty('rwresmgrtasklet')
154 class MonitorTasklet(rift
.vcs
.core
.Tasklet
):
156 This class represents a tasklet that is used to monitor NFVI metrics.
159 def __init__(self
, name
='nfvi-metrics-monitor', uid
=None,
161 recovery_action
=core
.RecoveryType
.FAILCRITICAL
.value
,
162 data_storetype
=core
.DataStore
.NOSTORE
.value
,
165 Creates a MonitorTasklet object.
168 name - the name of the tasklet
169 uid - a unique identifier
172 super(MonitorTasklet
, self
).__init
__(name
=name
, uid
=uid
,
173 config_ready
=config_ready
,
174 recovery_action
=recovery_action
,
175 data_storetype
=data_storetype
,
178 plugin_directory
= ClassProperty('./usr/lib/rift/plugins/rwmonitor')
179 plugin_name
= ClassProperty('rwmonitor')
182 def get_ui_ssl_args():
183 """Returns the SSL parameter string for launchpad UI processes"""
186 use_ssl
, certfile_path
, keyfile_path
= certs
.get_bootstrap_cert_and_key()
187 except certs
.BootstrapSslMissingException
:
188 logger
.error('No bootstrap certificates found. Disabling UI SSL')
191 # If we're not using SSL, no SSL arguments are necessary
195 return "--enable-https --keyfile-path=%s --certfile-path=%s" % (keyfile_path
, certfile_path
)
198 class UIServer(rift
.vcs
.NativeProcess
):
199 def __init__(self
, name
="RW.MC.UI",
201 recovery_action
=core
.RecoveryType
.FAILCRITICAL
.value
,
202 data_storetype
=core
.DataStore
.NOSTORE
.value
,
204 super(UIServer
, self
).__init
__(
206 exe
="./usr/share/rw.ui/skyquake/scripts/launch_ui.sh",
207 config_ready
=config_ready
,
208 recovery_action
=recovery_action
,
209 data_storetype
=data_storetype
,
214 return get_ui_ssl_args()
217 class RedisServer(rift
.vcs
.NativeProcess
):
218 def __init__(self
, name
="RW.Redis.Server",
220 recovery_action
=core
.RecoveryType
.FAILCRITICAL
.value
,
221 data_storetype
=core
.DataStore
.NOSTORE
.value
,
223 super(RedisServer
, self
).__init
__(
225 exe
="/usr/bin/redis-server",
226 config_ready
=config_ready
,
227 recovery_action
=recovery_action
,
228 data_storetype
=data_storetype
,
233 return "./usr/bin/active_redis.conf --port 9999"
235 class ConfigManagerTasklet(rift
.vcs
.core
.Tasklet
):
237 This class represents a Resource Manager tasklet.
240 def __init__(self
, name
='Configuration-Manager', uid
=None,
242 recovery_action
=core
.RecoveryType
.FAILCRITICAL
.value
,
243 data_storetype
=core
.DataStore
.NOSTORE
.value
,
246 Creates a ConfigManagerTasklet object.
249 name - the name of the tasklet
250 uid - a unique identifier
252 super(ConfigManagerTasklet
, self
).__init
__(name
=name
, uid
=uid
,
253 config_ready
=config_ready
,
254 recovery_action
=recovery_action
,
255 data_storetype
=data_storetype
,
258 plugin_directory
= ClassProperty('./usr/lib/rift/plugins/rwconmantasklet')
259 plugin_name
= ClassProperty('rwconmantasklet')
262 class Demo(rift
.vcs
.demo
.Demo
):
263 def __init__(self
,mgmt_ip_list
):
266 ConfigManagerTasklet(),
269 rift
.vcs
.RestconfTasklet(),
271 rift
.vcs
.uAgentTasklet(),
272 rift
.vcs
.Launchpad(),
277 rift
.vcs
.uAgentTasklet()
281 VnfmTasklet(recovery_action
=core
.RecoveryType
.RESTART
.value
, data_storetype
=core
.DataStore
.REDIS
.value
),
282 VnsTasklet(recovery_action
=core
.RecoveryType
.RESTART
.value
, data_storetype
=core
.DataStore
.REDIS
.value
),
283 MonitorTasklet(recovery_action
=core
.RecoveryType
.RESTART
.value
, data_storetype
=core
.DataStore
.REDIS
.value
),
284 NsmTasklet(recovery_action
=core
.RecoveryType
.RESTART
.value
, data_storetype
=core
.DataStore
.REDIS
.value
),
285 ResMgrTasklet(recovery_action
=core
.RecoveryType
.RESTART
.value
, data_storetype
=core
.DataStore
.REDIS
.value
),
287 super(Demo
, self
).__init
__(
288 # Construct the system. This system consists of 1 cluster in 1
289 # colony. The master cluster houses CLI and management VMs
290 sysinfo
= rift
.vcs
.SystemInfo(
291 zookeeper
=rift
.vcs
.manifest
.RaZookeeper(zake
=False, master_ip
=mgmt_ip_list
[0]),
297 rift
.vcs
.VirtualMachine(
301 restart_procs
=restart_procs
,
303 rift
.vcs
.VirtualMachine(
306 standby_procs
=standby_procs
,
309 ] if len(mgmt_ip_list
) == 2 else [
310 rift
.vcs
.VirtualMachine(
314 restart_procs
=restart_procs
,
321 # Define the generic portmap.
324 # Define a mapping from the placeholder logical names to the real
325 # port names for each of the different modes supported by this demo.
333 # Define the connectivity between logical port names.
338 def main(argv
=sys
.argv
[1:]):
339 logging
.basicConfig(format
='%(asctime)-15s %(levelname)s %(message)s')
341 # Create a parser which includes all generic demo arguments
342 parser
= rift
.vcs
.demo
.DemoArgParser()
344 args
= parser
.parse_args(argv
)
346 # Disable loading any kernel modules for the launchpad VM
347 # since it doesn't need it and it will fail within containers
348 os
.environ
["NO_KERNEL_MODS"] = "1"
350 # Remove the persistant DTS recovery files
351 for f
in os
.listdir(os
.environ
["INSTALLDIR"]):
352 if f
.endswith(".db"):
353 os
.remove(os
.path
.join(os
.environ
["INSTALLDIR"], f
))
355 #load demo info and create Demo object
356 demo
= Demo(args
.mgmt_ip_list
)
358 # Create the prepared system from the demo
359 system
= rift
.vcs
.demo
.prepared_system_from_demo_and_args(demo
, args
,
360 northbound_listing
=["platform_schema_listing.txt", "platform_mgmt_schema_listing.txt", "cli_launchpad_schema_listing.txt"],
361 netconf_trace_override
=True)
363 confd_ip
= socket
.gethostbyname(socket
.gethostname())
364 intf
= netifaces
.ifaddresses('eth0')
365 if intf
and netifaces
.AF_INET
in intf
and len(intf
[netifaces
.AF_INET
]):
366 confd_ip
= intf
[netifaces
.AF_INET
][0]['addr']
367 rift
.vcs
.logger
.configure_sink(config_file
=None, confd_ip
=confd_ip
)
369 # Start the prepared system
373 if __name__
== "__main__":
374 resource
.setrlimit(resource
.RLIMIT_CORE
, (resource
.RLIM_INFINITY
, resource
.RLIM_INFINITY
) )
377 except rift
.vcs
.demo
.ReservationError
:
378 print("ERROR: unable to retrieve a list of IP addresses from the reservation system")
380 except rift
.vcs
.demo
.MissingModeError
:
381 print("ERROR: you need to provide a mode to run the script")
384 os
.system("stty sane")