#!/usr/bin/env python3
-#
+#
# Copyright 2016 RIFT.IO Inc
#
# Licensed under the Apache License, Version 2.0 (the "License");
from rift.vcs.ext import ClassProperty
+
logger = logging.getLogger(__name__)
+IDP_PORT_NUMBER = "8009"
+
+def get_launchpad_address():
+ # Search for externally accessible IP address with netifaces
+ gateways = netifaces.gateways()
+ # Check for default route facing interface and then get its ip address
+ if 'default' in gateways:
+ interface = gateways['default'][netifaces.AF_INET][1]
+ launchpad_ip_address = netifaces.ifaddresses(interface)[netifaces.AF_INET][0]['addr']
+ else:
+ # no default gateway. Revert to 127.0.0.1
+ launchpad_ip_address = "127.0.0.1"
+
+ return launchpad_ip_address
class NsmTasklet(rift.vcs.core.Tasklet):
"""
config_ready=True,
recovery_action=core.RecoveryType.FAILCRITICAL.value,
data_storetype=core.DataStore.NOSTORE.value,
+ ha_startup_mode=core.HaStartup.ONLY_ACTIVE.value,
):
"""
Creates a NsmTasklet object.
config_ready=config_ready,
recovery_action=recovery_action,
data_storetype=data_storetype,
+ ha_startup_mode=ha_startup_mode,
)
plugin_directory = ClassProperty('./usr/lib/rift/plugins/rwnsmtasklet')
config_ready=True,
recovery_action=core.RecoveryType.FAILCRITICAL.value,
data_storetype=core.DataStore.NOSTORE.value,
+ ha_startup_mode=core.HaStartup.ONLY_ACTIVE.value,
):
"""
Creates a VnsTasklet object.
config_ready=config_ready,
recovery_action=recovery_action,
data_storetype=data_storetype,
+ ha_startup_mode=ha_startup_mode,
)
plugin_directory = ClassProperty('./usr/lib/rift/plugins/rwvnstasklet')
config_ready=True,
recovery_action=core.RecoveryType.FAILCRITICAL.value,
data_storetype=core.DataStore.NOSTORE.value,
+ ha_startup_mode=core.HaStartup.ONLY_ACTIVE.value,
):
"""
Creates a VnfmTasklet object.
config_ready=config_ready,
recovery_action=recovery_action,
data_storetype=data_storetype,
+ ha_startup_mode=ha_startup_mode,
)
plugin_directory = ClassProperty('./usr/lib/rift/plugins/rwvnfmtasklet')
config_ready=True,
recovery_action=core.RecoveryType.FAILCRITICAL.value,
data_storetype=core.DataStore.NOSTORE.value,
+ ha_startup_mode=core.HaStartup.ONLY_ACTIVE.value,
):
"""
Creates a ResMgrTasklet object.
config_ready=config_ready,
recovery_action=recovery_action,
data_storetype=data_storetype,
+ ha_startup_mode=ha_startup_mode,
)
plugin_directory = ClassProperty('./usr/lib/rift/plugins/rwresmgrtasklet')
config_ready=True,
recovery_action=core.RecoveryType.FAILCRITICAL.value,
data_storetype=core.DataStore.NOSTORE.value,
+ ha_startup_mode=core.HaStartup.ONLY_ACTIVE.value,
):
"""
Creates a Image Manager Tasklet object.
config_ready=config_ready,
recovery_action=recovery_action,
data_storetype=data_storetype,
+ ha_startup_mode=ha_startup_mode,
)
plugin_directory = ClassProperty('./usr/lib/rift/plugins/rwimagemgrtasklet')
config_ready=True,
recovery_action=core.RecoveryType.FAILCRITICAL.value,
data_storetype=core.DataStore.NOSTORE.value,
+ ha_startup_mode=core.HaStartup.ONLY_ACTIVE.value,
):
"""
Creates a MonitorTasklet object.
config_ready=config_ready,
recovery_action=recovery_action,
data_storetype=data_storetype,
+ ha_startup_mode=ha_startup_mode,
)
plugin_directory = ClassProperty('./usr/lib/rift/plugins/rwmonitor')
config_ready=True,
recovery_action=core.RecoveryType.FAILCRITICAL.value,
data_storetype=core.DataStore.NOSTORE.value,
+ ha_startup_mode=core.HaStartup.ANY_VM.value,
):
super(RedisServer, self).__init__(
name=name,
config_ready=config_ready,
recovery_action=recovery_action,
data_storetype=data_storetype,
+ ha_startup_mode=ha_startup_mode,
)
@property
config_ready=True,
recovery_action=core.RecoveryType.FAILCRITICAL.value,
data_storetype=core.DataStore.NOSTORE.value,
+ ha_startup_mode=core.HaStartup.ONLY_ACTIVE.value,
):
"""
Creates a MonitoringParameterTasklet object.
config_ready=config_ready,
recovery_action=recovery_action,
data_storetype=data_storetype,
+ ha_startup_mode=ha_startup_mode,
)
plugin_directory = ClassProperty('./usr/lib/rift/plugins/rwmonparam')
config_ready=True,
recovery_action=core.RecoveryType.FAILCRITICAL.value,
data_storetype=core.DataStore.NOSTORE.value,
+ ha_startup_mode=core.HaStartup.ONLY_ACTIVE.value,
):
"""
Creates a MonitoringParameterTasklet object.
config_ready=config_ready,
recovery_action=recovery_action,
data_storetype=data_storetype,
+ ha_startup_mode=ha_startup_mode,
)
plugin_directory = ClassProperty('./usr/lib/rift/plugins/rwautoscaler')
plugin_name = ClassProperty('rwautoscaler')
+class StagingManagerTasklet(rift.vcs.core.Tasklet):
+ """
+ A class that provide a simple staging area for all tasklets
+ """
-def get_ui_ssl_args():
- """Returns the SSL parameter string for launchpad UI processes"""
+ def __init__(self, name='StagingManager', uid=None,
+ config_ready=True,
+ recovery_action=core.RecoveryType.FAILCRITICAL.value,
+ data_storetype=core.DataStore.NOSTORE.value,
+ ha_startup_mode=core.HaStartup.ONLY_ACTIVE.value,
+ ):
+ """
+ Creates a StagingMangerTasklet object.
- try:
- use_ssl, certfile_path, keyfile_path = certs.get_bootstrap_cert_and_key()
- except certs.BootstrapSslMissingException:
- logger.error('No bootstrap certificates found. Disabling UI SSL')
- use_ssl = False
+ Arguments:
+ name - the name of the tasklet
+ uid - a unique identifier
- # If we're not using SSL, no SSL arguments are necessary
- if not use_ssl:
- return ""
+ """
+ super(StagingManagerTasklet, self).__init__(name=name, uid=uid,
+ config_ready=config_ready,
+ recovery_action=recovery_action,
+ data_storetype=data_storetype,
+ ha_startup_mode=ha_startup_mode,
+ )
- return "--enable-https --keyfile-path=%s --certfile-path=%s" % (keyfile_path, certfile_path)
+ plugin_directory = ClassProperty('./usr/lib/rift/plugins/rwstagingmgr')
+ plugin_name = ClassProperty('rwstagingmgr')
class UIServer(rift.vcs.NativeProcess):
config_ready=True,
recovery_action=core.RecoveryType.FAILCRITICAL.value,
data_storetype=core.DataStore.NOSTORE.value,
+ ha_startup_mode=core.HaStartup.ONLY_ACTIVE.value,
+ external_address=None,
):
super(UIServer, self).__init__(
name=name,
config_ready=config_ready,
recovery_action=recovery_action,
data_storetype=data_storetype,
+ ha_startup_mode=ha_startup_mode,
)
+ self._external_address = external_address
@property
def args(self):
- return get_ui_ssl_args()
+ return self._get_ui_args()
+
+ def _get_ui_args(self):
+ """Returns the SSL parameter string for launchpad UI processes"""
+
+ try:
+ use_ssl, certfile_path, keyfile_path = certs.get_bootstrap_cert_and_key()
+ except certs.BootstrapSslMissingException:
+ logger.error('No bootstrap certificates found. Disabling UI SSL')
+ use_ssl = False
+
+ # If we're not using SSL, no SSL arguments are necessary
+ if not use_ssl:
+ return ""
+
+ # If an external address is set, take that value for launchpad IP
+ # address, else use the internal IP address used for default route
+ launchpad_ip_address = self._external_address
+ if not launchpad_ip_address:
+ launchpad_ip_address = get_launchpad_address()
+
+ return "--enable-https" +\
+ " --keyfile-path={}".format(keyfile_path) +\
+ " --certfile-path={}".format(certfile_path) +\
+ " --launchpad-address={}".format(launchpad_ip_address) +\
+ " --idp-port-number={}".format(IDP_PORT_NUMBER) +\
+ " --callback-address={}".format(launchpad_ip_address)
+
class ConfigManagerTasklet(rift.vcs.core.Tasklet):
"""
config_ready=True,
recovery_action=core.RecoveryType.FAILCRITICAL.value,
data_storetype=core.DataStore.NOSTORE.value,
+ ha_startup_mode=core.HaStartup.ONLY_ACTIVE.value,
):
"""
Creates a ConfigManagerTasklet object.
config_ready=config_ready,
recovery_action=recovery_action,
data_storetype=data_storetype,
+ ha_startup_mode=ha_startup_mode,
)
plugin_directory = ClassProperty('./usr/lib/rift/plugins/rwconmantasklet')
plugin_name = ClassProperty('rwconmantasklet')
+
+class ProjectMgrManoTasklet(rift.vcs.core.Tasklet):
+ """
+ This class represents a Resource Manager tasklet.
+ """
+
+ def __init__(self, name='Project-Manager-Mano', uid=None,
+ config_ready=True,
+ recovery_action=core.RecoveryType.FAILCRITICAL.value,
+ data_storetype=core.DataStore.NOSTORE.value,
+ ha_startup_mode=core.HaStartup.ONLY_ACTIVE.value,
+ ):
+ """
+ Creates a ProjectMgrManoTasklet object.
+
+ Arguments:
+ name - the name of the tasklet
+ uid - a unique identifier
+ """
+ super(ProjectMgrManoTasklet, self).__init__(name=name, uid=uid,
+ config_ready=config_ready,
+ recovery_action=recovery_action,
+ data_storetype=data_storetype,
+ ha_startup_mode=ha_startup_mode,
+ )
+
+ plugin_directory = ClassProperty('./usr/lib/rift/plugins/rwprojectmano')
+ plugin_name = ClassProperty('rwprojectmano')
+
+
+class PackageManagerTasklet(rift.vcs.core.Tasklet):
+ """
+ This class represents a Resource Manager tasklet.
+ """
+
+ def __init__(self, name='Package-Manager', uid=None,
+ config_ready=True,
+ recovery_action=core.RecoveryType.FAILCRITICAL.value,
+ data_storetype=core.DataStore.NOSTORE.value,
+ ha_startup_mode=core.HaStartup.ONLY_ACTIVE.value,
+ ):
+ """
+ Creates a PackageManager object.
+
+ Arguments:
+ name - the name of the tasklet
+ uid - a unique identifier
+ """
+ super(PackageManagerTasklet, self).__init__(name=name, uid=uid,
+ config_ready=config_ready,
+ recovery_action=recovery_action,
+ data_storetype=data_storetype,
+ ha_startup_mode=ha_startup_mode,
+ )
+
+ plugin_directory = ClassProperty('./usr/lib/rift/plugins/rwpkgmgr')
+ plugin_name = ClassProperty('rwpkgmgr')
+
class GlanceServer(rift.vcs.NativeProcess):
def __init__(self, name="glance-image-catalog",
config_ready=True,
recovery_action=core.RecoveryType.FAILCRITICAL.value,
data_storetype=core.DataStore.NOSTORE.value,
+ ha_startup_mode=core.HaStartup.ONLY_ACTIVE.value,
):
super(GlanceServer, self).__init__(
name=name,
config_ready=config_ready,
recovery_action=recovery_action,
data_storetype=data_storetype,
+ ha_startup_mode=ha_startup_mode,
)
@property
class Demo(rift.vcs.demo.Demo):
- def __init__(self, no_ui=False, ha_mode=None, mgmt_ip_list=[], test_name=None):
- procs = [
- ConfigManagerTasklet(),
- GlanceServer(),
- rift.vcs.DtsRouterTasklet(),
- rift.vcs.MsgBrokerTasklet(),
- rift.vcs.RestPortForwardTasklet(),
- rift.vcs.RestconfTasklet(),
- rift.vcs.RiftCli(),
- rift.vcs.uAgentTasklet(),
- rift.vcs.Launchpad(),
- ]
-
- standby_procs = [
- RedisServer(),
- rift.vcs.DtsRouterTasklet(),
- rift.vcs.MsgBrokerTasklet(),
- ]
+ def __init__(self, no_ui=False,
+ data_store=None,
+ mgmt_ip_list=[],
+ test_name=None,
+ start_auth_svc=None,
+ start_pam_svc=None,
+ external_address=None):
datastore = core.DataStore.BDB.value
- if ha_mode:
- procs.append(RedisServer())
+ if data_store == "Redis":
datastore = core.DataStore.REDIS.value
+ elif data_store == "None":
+ datastore = core.DataStore.NOSTORE.value
+
+ restart_db_active = {"recovery_action" : core.RecoveryType.RESTART.value, \
+ "data_storetype" : datastore, \
+ "ha_startup_mode" : core.HaStartup.ONLY_ACTIVE.value}
+
+ failcrit_db_active = {"recovery_action" : core.RecoveryType.FAILCRITICAL.value, \
+ "data_storetype" : datastore, \
+ "ha_startup_mode" : core.HaStartup.ONLY_ACTIVE.value}
+
+ failcrit_db_any = {"recovery_action" : core.RecoveryType.FAILCRITICAL.value, \
+ "data_storetype" : datastore, \
+ "ha_startup_mode" : core.HaStartup.ANY_VM.value}
+
+ procs = [
+ ConfigManagerTasklet(**failcrit_db_active),
+ GlanceServer(**failcrit_db_active),
+ rift.vcs.DtsRouterTasklet(**failcrit_db_any),
+ rift.vcs.MsgBrokerTasklet(**failcrit_db_any),
+ rift.vcs.RestconfTasklet(**failcrit_db_active),
+ rift.vcs.RiftCli(**failcrit_db_active, as_console=True),
+ rift.vcs.uAgentTasklet(**failcrit_db_any),
+ rift.vcs.Launchpad(**failcrit_db_active),
+ rift.vcs.IdentityManagerTasklet(**failcrit_db_active),
+ rift.vcs.ProjectManagerTasklet(**failcrit_db_active),
+ rift.vcs.HAManager(**failcrit_db_any),
+ rift.vcs.OpenIDCProviderTasklet(**failcrit_db_active),
+ rift.vcs.AuthExtUserTasklet(**failcrit_db_active),
+ rift.vcs.OTTAuthTasklet(**failcrit_db_active),
+ NsmTasklet(**failcrit_db_active),
+ VnfmTasklet(**failcrit_db_active),
+ VnsTasklet(**failcrit_db_active),
+ ResMgrTasklet(**failcrit_db_active),
+ ImageMgrTasklet(**failcrit_db_active),
+ AutoscalerTasklet(**failcrit_db_active),
+ StagingManagerTasklet(**failcrit_db_active),
+ PackageManagerTasklet(**failcrit_db_active),
+ MonitoringParameterTasklet(**failcrit_db_active),
+ ProjectMgrManoTasklet(**failcrit_db_active)
+ ]
+
+ if datastore == core.DataStore.REDIS.value:
+ procs.append(RedisServer(**failcrit_db_any))
if not no_ui:
- procs.append(UIServer())
-
- restart_procs = [
- VnfmTasklet(recovery_action=core.RecoveryType.RESTART.value, data_storetype=datastore),
- VnsTasklet(recovery_action=core.RecoveryType.RESTART.value, data_storetype=datastore),
- MonitorTasklet(recovery_action=core.RecoveryType.RESTART.value, data_storetype=datastore),
- MonitoringParameterTasklet(recovery_action=core.RecoveryType.RESTART.value, data_storetype=datastore),
- NsmTasklet(recovery_action=core.RecoveryType.RESTART.value, data_storetype=datastore),
- ResMgrTasklet(recovery_action=core.RecoveryType.RESTART.value, data_storetype=datastore),
- ImageMgrTasklet(recovery_action=core.RecoveryType.RESTART.value, data_storetype=datastore),
- AutoscalerTasklet(recovery_action=core.RecoveryType.RESTART.value, data_storetype=datastore),
- ]
+ procs.append(UIServer(external_address=external_address))
- if not mgmt_ip_list or len(mgmt_ip_list) == 0:
- mgmt_ip_list.append("127.0.0.1")
+ if start_auth_svc:
+ procs.append(rift.vcs.WebAuthSvcTasklet(**failcrit_db_active))
- colony = rift.vcs.core.Colony(name='top', uid=1)
+ if start_pam_svc:
+ procs.append(rift.vcs.PAMAuthTasklet())
- lead_lp_vm = rift.vcs.VirtualMachine(
- name='vm-launchpad-1',
- ip=mgmt_ip_list[0],
- procs=procs,
- restart_procs=restart_procs,
- )
- lead_lp_vm.leader = True
- colony.append(lead_lp_vm)
-
- if ha_mode:
- stby_lp_vm = rift.vcs.VirtualMachine(
- name='launchpad-vm-2',
- ip=mgmt_ip_list[1],
- procs=standby_procs,
- start=False,
- )
- # WA to Agent mode_active flag reset
- stby_lp_vm.add_tasklet(rift.vcs.uAgentTasklet(), mode_active=False)
- colony.append(stby_lp_vm)
+ restart_procs = []
+
+ if not mgmt_ip_list or len(mgmt_ip_list) == 0:
+ mgmt_ip_list.append(get_launchpad_address())
+ colony = rift.vcs.core.Colony(name='top', uid=1)
+ leader = 0
+ for mgmt_ip in mgmt_ip_list:
+ vm = rift.vcs.VirtualMachine(name='mgmt-vm-lp',
+ ip=mgmt_ip,
+ procs=procs,
+ restart_procs=restart_procs,start=False,)
+ if (leader == 0):
+ vm.leader = True
+ leader = 1
+ colony.append(vm)
+
sysinfo = rift.vcs.SystemInfo(
mode='ethsim',
zookeeper=rift.vcs.manifest.RaZookeeper(master_ip=mgmt_ip_list[0]),
# Create a parser which includes all generic demo arguments
parser = rift.vcs.demo.DemoArgParser()
parser.add_argument("--no-ui", action='store_true')
+ parser.add_argument("--start-auth-svc",
+ action='store_true',
+ help="Start the Web Based Authentication service simualtor.")
+ parser.add_argument("--start-pam-svc",
+ action='store_true',
+ help="Start the PAM Authentication service.")
+ parser.add_argument("--external-address",
+ type=str,
+ help="External IP address or hostname using which the host can "+
+ "be reached.")
+ if rift.vcs.mgmt.default_agent_mode() == 'CONFD':
+ parser.add_argument("--use-osm-model",
+ action='store_true',
+ help="Load only OSM specific models and hide the Rift Specific Augments")
+
args = parser.parse_args(argv)
# Disable loading any kernel modules for the launchpad VM
# since it doesn't need it and it will fail within containers
os.environ["NO_KERNEL_MODS"] = "1"
+ # Get external_address from env if args not set
+ if args.external_address is None:
+ args.external_address = os.getenv("RIFT_EXTERNAL_ADDRESS")
+
+ os.environ["RIFT_EXTERNAL_ADDRESS"] = \
+ args.external_address if args.external_address else get_launchpad_address()
cleanup_dir_name = None
- if os.environ["INSTALLDIR"] in ["/", "/home/rift", "/home/rift/.install",
- "/usr/rift/build/fc20_debug/install/usr/rift", "/usr/rift"]:
+ if os.environ["INSTALLDIR"] in ["/usr/rift",
+ "/usr/rift/build/ub16_debug/install/usr/rift",
+ "/usr/rift/build/fc20_debug/install/usr/rift"]:
cleanup_dir_name = os.environ["INSTALLDIR"] + "/var/rift/"
if args.test_name and not cleanup_dir_name:
except Exception as e:
print ("Error while cleanup: {}".format(str(e)))
- ha_mode = args.ha_mode
+ datastore = args.datastore
mgmt_ip_list = [] if not args.mgmt_ip_list else args.mgmt_ip_list
#load demo info and create Demo object
- demo = Demo(args.no_ui, ha_mode, mgmt_ip_list, args.test_name)
+ demo = Demo(args.no_ui,
+ datastore,
+ mgmt_ip_list,
+ args.test_name,
+ args.start_auth_svc,
+ args.start_pam_svc,
+ args.external_address)
+
+ if 'use_osm_model' in args and args.use_osm_model:
+ northbound_listing = ["platform_schema_listing.txt",
+ "platform_mgmt_schema_listing.txt",
+ "cli_launchpad_schema_listing.txt"]
+ args.use_xml_mode = True
+
+ else:
+ northbound_listing = ["platform_schema_listing.txt",
+ "platform_mgmt_schema_listing.txt",
+ "cli_launchpad_schema_listing.txt",
+ "cli_launchpad_rift_specific_schema_listing.txt"]
# Create the prepared system from the demo
- system = rift.vcs.demo.prepared_system_from_demo_and_args(demo, args,
- northbound_listing="cli_launchpad_schema_listing.txt",
- netconf_trace_override=True)
-
- confd_ip = socket.gethostbyname(socket.gethostname())
- intf = netifaces.ifaddresses('eth0')
- if intf and netifaces.AF_INET in intf and len(intf[netifaces.AF_INET]):
- confd_ip = intf[netifaces.AF_INET][0]['addr']
+ system = rift.vcs.demo.prepared_system_from_demo_and_args(
+ demo, args,
+ northbound_listing=northbound_listing,
+ netconf_trace_override=True)
+
+ confd_ip = get_launchpad_address()
+ # TODO: This need to be changed when launchpad starts running on multiple VMs
rift.vcs.logger.configure_sink(config_file=None, confd_ip=confd_ip)
# Start the prepared system
system.start()
-
if __name__ == "__main__":
resource.setrlimit(resource.RLIMIT_CORE, (resource.RLIM_INFINITY, resource.RLIM_INFINITY) )
+ os.system('/usr/rift/bin/UpdateHostsFile')
try:
main()
except rift.vcs.demo.ReservationError: