def setUp(self): plugin = rw_peas.PeasPlugin("rwmon_mock", 'RwMon-1.0') self.plugin = plugin.get_interface("Monitoring") self.account = RwcalYang.YangData_RwProject_Project_CloudAccounts_CloudAccountList( ) self.vim_id = "test-vim-id"
def go(): account_msg = RwCloudYang.YangData_RwProject_Project_CloudAccounts_CloudAccountList.from_dict( { "account_type": "openstack", "openstack": { "key": "admin", "secret": "mypasswd", "auth_url": 'http://10.66.4.18:5000/v3/', "tenant": "demo", "mgmt_network": "private" } }) account = cloud.CloudAccount(self.log, RwLog.Ctx.new(__file__), account_msg) vim_id = "a7f30def-0942-4425-8454-1ffe02b7db1e" instances = 20 executor = concurrent.futures.ThreadPoolExecutor(10) plugin = rw_peas.PeasPlugin("rwmon_ceilometer", 'RwMon-1.0') impl = plugin.get_interface("Monitoring") while True: tasks = [] for _ in range(instances): task = update(self.loop, self.log, executor, account.cal_account_msg, impl, vim_id) tasks.append(task) self.log.debug("Running %s update tasks", instances) #self.loop.run_until_complete(asyncio.wait(tasks, loop=self.loop, timeout=20)) done, pending = yield from asyncio.wait(tasks, loop=self.loop, timeout=20) self._metrics = done.pop().result()
def test_start_traffic_xml_conversion(self): # Open rw-fpath-d yang model yang = rw_peas.PeasPlugin('yangmodel_plugin-c', 'YangModelPlugin-1.0') yang_model = yang.get_interface('Model') #yang_module = yang.get_interface('Module') #yang_node = yang.get_interface('Node') #yang_key = yang.get_interface('Key') model = yang_model.alloc() module = yang_model.load_module(model, "rw-fpath-d") #populate the start self.start.name = "test-name" self.start.traffic = RwFpathDYang.StartTraffic_Traffic() self.start.traffic.port_name = "riftport" # recreate a start using to_xml and from_xml methods xml_str = self.start.to_xml(model) recreated_start = RwFpathDYang.StartTraffic() recreated_start.from_xml(model, xml_str) print "Start : ", self.start print "Recreated Start : ", recreated_start # check the newly created start is identical self.assertEqual(self.start.name, recreated_start.name) self.assertEqual(len(self.start.name), len(recreated_start.name)) self.assertEqual(self.start.traffic.port_name, recreated_start.traffic.port_name) self.assertEqual(len(self.start.traffic.port_name), len(recreated_start.traffic.port_name))
def setUp(self): plugin = rw_peas.PeasPlugin("rwmon_mock", 'RwMon-1.0') self.plugin = plugin.get_interface("Monitoring") self.plugin.set_impl(MockDataSource()) self.account = RwcalYang.CloudAccount() self.vim_id = "test-vim-id"
def get_cal_interface(): plugin = rw_peas.PeasPlugin('rwcal_openstack', 'RwCal-1.0') engine, info, extension = plugin() cal = plugin.get_interface("Cloud") rwloggerctx = rwlogger.RwLog.Ctx.new("Cal-Log") rc = cal.init(rwloggerctx) assert rc == RwTypes.RwStatus.SUCCESS return cal
def main(): import rw_peas # Load rwtrace plugin rwtrace = rw_peas.PeasPlugin("rwtrace_plugin-c", 'Rwtrace-1.0') engine, info, plugin = rwtrace( ) # This is just a shortcut call for convenience Rwtrace = rwtrace.typelib # Instantiate plugin's API for RWTASKLET component rwtrace_module = plugin.module_init(rwtrace.plugin_name, 'whatever') rwtrace_instance = plugin.module_instance_alloc( rwtrace_module, rwtrace.plugin_name + '_instance', 'whatever') rwtrace.plugin.set_category_destination(rwtrace_instance, Rwtrace.Category.RWTASKLET, Rwtrace.Destination.CONSOLE) rwtrace.plugin.set_category_severity(rwtrace_instance, Rwtrace.Category.RWTASKLET, Rwtrace.Severity.ERROR) # The following message shows up on the console rwtrace.plugin.trace(rwtrace_instance, Rwtrace.Category.RWTASKLET, Rwtrace.Severity.CRIT, "Error message") # Now lets a try a trace with format string message = "test" code = -1 rwtrace.plugin.trace(rwtrace_instance, Rwtrace.Category.RWTASKLET, Rwtrace.Severity.CRIT, "Error message: %s[%d]" % (message, code)) # The following message does NOT show up on the console rwtrace.plugin.trace(rwtrace_instance, Rwtrace.Category.RWTASKLET, Rwtrace.Severity.DEBUG, "Debug message") # Instantiate plugin's API for RATEST component rwtrace.plugin.set_category_destination(rwtrace_instance, Rwtrace.Category.RATEST, Rwtrace.Destination.CONSOLE) rwtrace.plugin.set_category_severity(rwtrace_instance, Rwtrace.Category.RATEST, Rwtrace.Severity.DEBUG) # The following message for RATEST appears on the console rwtrace.plugin.trace(rwtrace_instance, Rwtrace.Category.RATEST, Rwtrace.Severity.DEBUG, "Debug message on console for RATEST") rwtrace.plugin.set_category_destination(rwtrace_instance, Rwtrace.Category.RATEST, Rwtrace.Destination.FILE) # The following message for RATEST appears in syslog rwtrace.plugin.trace(rwtrace_instance, Rwtrace.Category.RATEST, Rwtrace.Severity.NOTICE, "Debug message in the file for RATEST")
def get_cal_interface(self): if RwCalProxyTasklet.cal_interface is None: plugin = rw_peas.PeasPlugin('rwcal_cloudsim', 'RwCal-1.0') engine, info, extension = plugin() RwCalProxyTasklet.cal_interface = plugin.get_interface("Cloud") RwCalProxyTasklet.cal_interface.init(self.log_hdl) return RwCalProxyTasklet.cal_interface
def cal(cloud_account): """Fixture which returns cal interface""" if cloud_account.account_type == 'openstack': plugin = rw_peas.PeasPlugin('rwcal_openstack', 'RwCal-1.0') elif cloud_account.account_type == 'openvim': plugin = rw_peas.PeasPlugin('rwcal_openmano_vimconnector', 'RwCal-1.0') elif cloud_account.account_type == 'aws': plugin = rw_peas.PeasPlugin('rwcal_aws', 'RwCal-1.0') elif cloud_account.account_type == 'vsphere': plugin = rw_peas.PeasPlugin('rwcal-python', 'RwCal-1.0') engine, info, extension = plugin() cal = plugin.get_interface("Cloud") rwloggerctx = rwlogger.RwLog.Ctx.new("Cal-Log") rc = cal.init(rwloggerctx) assert rc == RwTypes.RwStatus.SUCCESS return cal
def setUp(self): plugin = rw_peas.PeasPlugin("rwmon_mock", 'RwMon-1.0') self.mock = MockAlarmInterface() self.plugin = plugin.get_interface("Monitoring") self.plugin.set_impl(self.mock) self.account = RwcalYang.CloudAccount() self.alarm = RwmonYang.Alarm(name='test-alarm') self.vim_id = 'test-vim-id'
def create_cal_plugin(account, log_hdl): plugin_name = getattr(account, account.account_type).plugin_name plugin = rw_peas.PeasPlugin(plugin_name, 'RwCal-1.0') engine, info, extension = plugin() rwcal = plugin.get_interface("Cloud") try: rc = rwcal.init(log_hdl) assert rc == RwStatus.SUCCESS except Exception as e: raise return rwcal
def create(self, cloud_account): plugin = rw_peas.PeasPlugin("rwmon_ceilometer", 'RwMon-1.0') impl = plugin.get_interface("Monitoring") # Check that the plugin is available on the platform associated with # the cloud account _, available = impl.nfvi_metrics_available(cloud_account) if not available: raise PluginUnavailableError() return impl
def test_flat_person_xml_conversion(self): # Open rwperson-database yang model yang = rw_peas.PeasPlugin('yangmodel_plugin-c', 'YangModelPlugin-1.0') yang_model = yang.get_interface('Model') yang_module = yang.get_interface('Module') yang_node = yang.get_interface('Node') yang_key = yang.get_interface('Key') model = yang_model.alloc() module = yang_model.load_module(model, "rwperson-db") #populate the person self.flat_person.name = "test-name" self.flat_person.email = "*****@*****.**" self.flat_person.employed = True self.flat_person.id = 12345 self.flat_person.emergency_phone.number = "123-456-7890" self.flat_person.emergency_phone.type_yang = 'WORK' new_flat_phone = [ RwpersonDbYang.FlatPhoneNumber(), RwpersonDbYang.FlatPhoneNumber() ] new_flat_phone[0].number = '#1' new_flat_phone[1].number = '#2' self.flat_person.phone = new_flat_phone # recreate a person using to_xml and from_xml methods xml_str = self.flat_person.to_xml(model) recreated_flat_person = RwpersonDbYang.FlatPerson() recreated_flat_person.from_xml(model, xml_str) print("Person : ", self.flat_person) print("Recreated Person : ", recreated_flat_person) # check the newly created person is identical self.assertEqual(self.flat_person.name, recreated_flat_person.name) self.assertEqual(self.flat_person.email, recreated_flat_person.email) self.assertEqual(self.flat_person.employed, recreated_flat_person.employed) self.assertEqual(self.flat_person.id, recreated_flat_person.id) self.assertEqual(self.flat_person.emergency_phone.number, recreated_flat_person.emergency_phone.number) self.assertEqual(self.flat_person.emergency_phone.type_yang, recreated_flat_person.emergency_phone.type_yang) self.assertEqual(len(self.flat_person.phone), len(recreated_flat_person.phone)) for phone, recreated_phone in zip(self.flat_person.phone, recreated_flat_person.phone): self.assertEqual(phone.number, recreated_phone.number) self.assertEqual(phone.type_yang, recreated_phone.type_yang) flat_person = None recreated_flat_person = None new_flat_phone = None
def plugin(self): if self._cal_plugin is None: try: self._cal_plugin = rw_peas.PeasPlugin( getattr(self._account_msg, self.account_type).plugin_name, 'RwCal-1.0', ) except AttributeError as e: raise PluginLoadingError(str(e)) self._engine, _, _ = self._cal_plugin() return self._cal_plugin
def test_pb_to_cli(self): # ATTN: Do we need to_pb_cli_v2 ? # If not planned below model creation should # probably be part of selfand initialied in # 'setUp' yang = rw_peas.PeasPlugin('yangmodel_plugin-c', 'YangModelPlugin-1.0') yang_model = yang.get_interface('Model') model = yang_model.alloc() module = yang_model.load_module(model, "rwperson-db") cli_str = self.min_person.to_pb_cli(model) print("CLI command: {0}".format(cli_str)) self.assertTrue("config" in cli_str) self.assertTrue("commit" in cli_str)
def get_cal_plugin(): """ Load AWS cal plugin """ plugin = rw_peas.PeasPlugin('rwcal_aws', 'RwCal-1.0') engine, info, extension = plugin() cal = plugin.get_interface("Cloud") rwloggerctx = rwlogger.RwLog.Ctx.new("Cal-Log") try: rc = cal.init(rwloggerctx) assert rc == RwStatus.SUCCESS except Exception as e: logger.error("ERROR:Cal plugin instantiation failed with exception %s", repr(e)) else: logger.info("AWS Cal plugin successfully instantiated") return cal
def _get_cal_interface(self): """Get an instance of the rw.cal interface Load an instance of the rw.cal plugin via libpeas and returns the interface to that plugin instance Returns: rw.cal interface to created rw.cal instance """ plugin = rw_peas.PeasPlugin('rwcal_openstack', 'RwCal-1.0') engine, info, extension = plugin() cal = plugin.get_interface("Cloud") rwloggerctx = rwlogger.RwLog.Ctx.new("Cal-Log") rc = cal.init(rwloggerctx) assert rc == RwTypes.RwStatus.SUCCESS return cal
def get_cal_plugin(): """ Loads rw.cal plugin via libpeas """ plugin = rw_peas.PeasPlugin('rwcal_openstack', 'RwCal-1.0') engine, info, extension = plugin() cal = plugin.get_interface("Cloud") # Get the RwLogger context rwloggerctx = rwlogger.RwLog.Ctx.new("Cal-Log") try: rc = cal.init(rwloggerctx) assert rc == RwStatus.SUCCESS except: logger.error("ERROR:Cal plugin instantiation failed. Aborting tests") else: logger.info("Openstack Cal plugin successfully instantiated") return cal
def load_plugin(self): """Load the cal plugin and account Returns: Tuple (Cal, Account) """ plugin = rw_peas.PeasPlugin('rwcal_cloudsimproxy', 'RwCal-1.0') engine, info, extension = plugin() rwloggerctx = rwlogger.RwLog.Ctx.new("Cal-Log") cal = plugin.get_interface("Cloud") rc = cal.init(rwloggerctx) account = RwcalYang.CloudAccount() account.account_type = "cloudsim_proxy" account.cloudsim_proxy.host = "192.168.122.1" self._cal, self._account = cal, account
def test_many_updates(self): vim_id = "a7f30def-0942-4425-8454-1ffe02b7db1e" instances = 20 executor = concurrent.futures.ThreadPoolExecutor(10) while True: tasks = [] for _ in range(instances): plugin = rw_peas.PeasPlugin("rwmon_ceilometer", 'RwMon-1.0') impl = plugin.get_interface("Monitoring") task = update(self._loop, self._log, executor, self._account.cal_account_msg, impl, vim_id) tasks.append(task) task = update(self._loop, self._log, executor, self._account.cal_account_msg, impl, vim_id) tasks.append(task) task = update(self._loop, self._log, executor, self._account.cal_account_msg, impl, vim_id) tasks.append(task) self._log.debug("Running %s update tasks", instances) self._loop.run_until_complete(asyncio.wait(tasks, loop=self._loop, timeout=20))
def __init__(self, loop, log): # Initialize the CAL interface if it has not already been initialized if ResourceProvisioning.cal_interface is None: plugin = rw_peas.PeasPlugin('rwcal_cloudsimproxy', 'RwCal-1.0') engine, info, extension = plugin() ResourceProvisioning.cal_interface = plugin.get_interface("Cloud") ResourceProvisioning.cal_interface.init( ResourceProvisioning.log_hdl) self.account = RwcalYang.CloudAccount() self.account.account_type = "cloudsim_proxy" self.account.cloudsim_proxy.host = "192.168.122.1" self.log = log self.loop = loop self.nvms = 1 self._vms = []
def get_sdn_plugin(): """ Loads rw.sdn plugin via libpeas """ plugin = rw_peas.PeasPlugin('rwsdn_mock', 'RwSdn-1.0') engine, info, extension = plugin() # Get the RwLogger context rwloggerctx = rwlogger.RwLog.Ctx.new("SDN-Log") sdn = plugin.get_interface("Topology") try: rc = sdn.init(rwloggerctx) assert rc == RwStatus.SUCCESS except: logger.error("ERROR:SDN plugin instantiation failed. Aborting tests") else: logger.info("Mock SDN plugin successfully instantiated") return sdn
def test_fastpath_packet_trace_xml_conversion(self): yang = rw_peas.PeasPlugin('yangmodel_plugin-c', 'YangModelPlugin-1.0') yang_model = yang.get_interface('Model') model = yang_model.alloc() module = yang_model.load_module(model, "rw-fpath-d") self.fastpath_packet_trace = RwFpathDYang.YangNotif_RwFpathD_FastpathPacketTrace( ) self.fastpath_packet_trace.packet_info = bin(10203) # recreate a start using to_xml and from_xml methods xml_str = self.fastpath_packet_trace.to_xml(model) recreated_fastpath_packet_trace = RwFpathDYang.YangNotif_RwFpathD_FastpathPacketTrace( ) recreated_fastpath_packet_trace.from_xml(model, xml_str) print "FpathPacketTrace : ", self.fastpath_packet_trace print "Recreated FpathPacketTrace : ", recreated_fastpath_packet_trace self.assertEqual(self.fastpath_packet_trace.packet_info, recreated_fastpath_packet_trace.packet_info)
def get_sdn_plugin(self,name): """ Loads rw.sdn plugin via libpeas """ if (name in self._sdn): return self._sdn[name] account = self.get_sdn_account(name) plugin_name = getattr(account, account.account_type).plugin_name self._log.debug("SDN plugin being created") plugin = rw_peas.PeasPlugin(plugin_name, 'RwSdn-1.0') engine, info, extension = plugin() self._sdn[name] = plugin.get_interface("Topology") try: rc = self._sdn[name].init(self._log_hdl) assert rc == RwStatus.SUCCESS except: self._log.error("ERROR:SDN plugin instantiation failed ") else: self._log.debug("SDN plugin successfully instantiated") return self._sdn[name]
def main(): # Initialize a PEAS engine #engine = rw_peas.create_engine() # Load our plugin proxy into the g_irepository namespace #default = GIRepository.Repository.get_default() #typelib = GIRepository.Repository.require(default, "MathCommon", "1.0", 0) #GIRepository.Repository.require(default, "FeaturePlugin", "1.0", 0) # Enable every possible language loader #engine.enable_loader("python"); #engine.enable_loader("c"); # Run a testcase for each possible extension type # extension_list = [ "python" ] extension_list = ["c"] for extension in extension_list: engine, info, plugin = rw_peas.PeasPlugin( 'feature_plugin-' + extension, 'FeaturePlugin-1.0')() #extension_plugin = "feature_plugin-" + extension #info = engine.get_plugin_info(extension_plugin) #engine.load_plugin(info) test_feature_plugin_api_examples(engine, info)
import time import rw_peas import requests import argparse import socket import gi gi.require_version('RwMcYang', '1.0') gi.require_version('YangModelPlugin', '1.0') from gi.repository import RwMcYang # stress the system using netconf yang = rw_peas.PeasPlugin('yangmodel_plugin-c', 'YangModelPlugin-1.0') yang_model_api = yang.get_interface('Model') yang_model = yang_model_api.alloc() mc_module = yang_model_api.load_module(yang_model, 'rw-mc') @contextlib.contextmanager def start_system(host, port): print("Starting system") # Retrieve the necessary rift paths rift_root = os.environ["RIFT_ROOT"] rift_install = os.environ["RIFT_INSTALL"] rift_artifacts = os.environ["RIFT_ARTIFACTS"] cmd = "{RIFT_INSTALL}/demos/dts-perf-system.py -m ethsim -c --ip-list {host} --skip-prepare-vm".format(
logger.warning("Error loading Reservation library") testbed = None else: testbed = ndl.Testbed() testbed.set_server(cmdargs.reservation_server_url) if cmdargs.provider_type == 'OPENSTACK': account = RwcalYang.CloudAccount() account.account_type = "openstack" account.openstack.key = cmdargs.user account.openstack.secret = cmdargs.passwd account.openstack.auth_url = cmdargs.auth_url account.openstack.tenant = cmdargs.user account.openstack.mgmt_network = cmdargs.mgmt_network plugin = rw_peas.PeasPlugin('rwcal_openstack', 'RwCal-1.0') engine, info, extension = plugin() driver = plugin.get_interface("Cloud") # Get the RwLogger context rwloggerctx = rwlogger.RwLog.Ctx.new("Cal-Log") try: rc = driver.init(rwloggerctx) assert rc == RwStatus.SUCCESS except: logger.error( "ERROR:Cal plugin instantiation failed. Aborting tests") else: logger.info("Openstack Cal plugin successfully instantiated") cmdargs.func(driver, account, cmdargs)
class RaVcsApi(object): # Initialize the peas plugin and initialize the component _ravcs_plugin = rw_peas.PeasPlugin('rwvcs_api-c', 'RwvcsApi-1.0') _engine, _info, _extension = _ravcs_plugin() def _manifest_as_xml_string(self, manifest, minimized=False): ''' Returns manifest as an XML string. If minimized is True, returns a minimized XML string. If minimized is False, returns a nicely formatted (prettified) XML string. ''' xml_data = manifest.as_xml(RaVcsApi._extension) if minimized is False: dom = parseString(xml_data) xml_data = dom.toprettyxml(indent=" ") return xml_data def exec_rwmain(self, xml_file, use_gdb=False, track_memory=False): """ Execute rwmain to load the provided xml_file. Arguments: xml_file - The manifest xml_file file on disk to load use_gdb - Flag indicating whether to launch rwmain under gdb track_memory - Flag indicating whether to launch rwmain with memory-tracking enabled """ logger.debug("Loading manifest file into VCS: %s" % xml_file) if not os.path.exists(xml_file): raise ManifestStartError( "Cannot find manifest xml_file argument: %s" % xml_file) # The system only runs from within the .install directory. os.chdir(os.environ['RIFT_INSTALL']) print("track_memory=", track_memory) if track_memory: if os.environ.get('LD_PRELOAD') is not None: os.environ['LD_PRELOAD'] = str( os.path.join(os.environ['RIFT_INSTALL'], "usr/lib/librwmalloc.so")) + ':' + str( os.environ['LD_PRELOAD']) else: os.environ['LD_PRELOAD'] = os.path.join( os.environ['RIFT_INSTALL'], "usr/lib/librwmalloc.so") rwmain_exe = os.path.join(os.environ['RIFT_INSTALL'], "usr/bin/rwmain") if not os.path.isfile(rwmain_exe): raise ManifestStartError( "{} does not exist! Cannot start system.".format(rwmain_exe)) exe = rwmain_exe exe_name = "rwmain" exe_args = ["--manifest", xml_file] # If the user requested to use gdb, lets set gdb as the executable # and put the existing rwmain exe and args after --args if use_gdb: logger.info("Running rwmain under GDB") exe_args = ["--args", exe] + exe_args exe = "/usr/bin/gdb" exe_name = "gdb" # Set argv[0] to the appropriate executable name exe_args.insert(0, exe_name) # Execute rwmain with provided manifest, this never returns os.execv(exe, exe_args) def manifest_generate_xml(self, manifest, output_filepath=None, manifest_prefix=None): """ Compile the RaManifest object into an XML file. Arguments: output_filepath - If provided, then write the manifest to the file path provided. The existing file will be overwritten. """ xml_data = self._manifest_as_xml_string(manifest).encode('utf-8') # user requested to write the manifest to a specific file if output_filepath: manifest_hdl = os.open(output_filepath, os.O_RDWR | os.O_CREAT | os.O_TRUNC) else: # Create a temporary file to store the manifest data prefix = "manifest_" if manifest_prefix: prefix = manifest_prefix + "_" + prefix (manifest_hdl, output_filepath) = tempfile.mkstemp(".xml", prefix) # Write the xml data and close the manifest file handle os.write(manifest_hdl, xml_data) os.close(manifest_hdl) logger.debug("Wrote Manifest XML File: %s" % output_filepath) return output_filepath def manifest_start(self, manifest): """ Compile the RaManifest object into an XML file, load the file into RW.VCS, and optionally start the init component of the manifest. """ manifest_file = self.manifest_generate_xml(manifest) self.exec_rwmain(manifest_file)
def main(): yangmodel_plugin = rw_peas.PeasPlugin('yangmodel_plugin-c', 'YangModelPlugin-1.0') test_yangmodel_plugin_api_examples(yangmodel_plugin)
def create(self, cloud_account): plugin = rw_peas.PeasPlugin("rwmon_mock", 'RwMon-1.0') impl = plugin.get_interface("Monitoring") impl.set_impl(MockPlugin()) return impl
def main(argv=sys.argv[1:]): """ Assuming that an LVM backing-store has been created with a volume group called 'rift', the following creates an lxc 'image' and a pair of 'vms'. In the LXC based container CAL, an 'image' is container and a 'vm' is a snapshot of the original container. In addition to the LVM backing store, it is assumed that there is a network bridge called 'virbr0'. """ logging.basicConfig(level=logging.DEBUG) parser = argparse.ArgumentParser() parser.add_argument('--rootfs', '-r') parser.add_argument('--num-vms', '-n', type=int, default=2) parser.add_argument('--terminate', '-t', action='store_true') args = parser.parse_args(argv) # Acquire the plugin from peas plugin = rw_peas.PeasPlugin('rwcal-plugin', 'RwCal-1.0') engine, info, extension = plugin() # Get the RwLogger context rwloggerctx = rwlogger.RwLog.Ctx.new("Cal-Log") cal = plugin.get_interface("Cloud") cal.init(rwloggerctx) # The account object is not currently used, but it is required by the CAL # interface, so we create an empty object here to represent it. account = RwcalYang.CloudAccount() account.account_type = "lxc" # Make sure that any containers that were previously created have been # stopped and destroyed. containers = lxc.containers() for container in containers: lxc.stop(container) for container in containers: lxc.destroy(container) template = os.path.join( os.environ['RIFT_INSTALL'], 'etc/lxc-fedora-rift.lxctemplate', ) logger.info(template) logger.info(args.rootfs) # Create an image that can be used to create VMs image = RwcalYang.ImageInfoItem() image.name = 'rift-master' image.lxc.size = '2.5G' image.lxc.template_path = template image.lxc.tarfile = args.rootfs cal.create_image(account, image) # Create a VM vms = [] for index in range(args.num_vms): vm = RwcalYang.VMInfoItem() vm.vm_name = 'rift-s{}'.format(index + 1) vm.image_id = image.id cal.create_vm(account, vm) vms.append(vm) # Create the default and data networks network = RwcalYang.NetworkInfoItem(network_name='virbr0') cal.create_network(account, network) os.system('brctl show') # Create pairs of ports to connect the networks for index, vm in enumerate(vms): port = RwcalYang.PortInfoItem() port.port_name = "eth0" port.network_id = network.network_id port.vm_id = vm.vm_id port.ip_address = "192.168.122.{}".format(index + 101) port.lxc.veth_name = "rws{}".format(index) cal.create_port(account, port) # Swap out the current instance of the plugin to test that the data is # shared among different instances cal = plugin.get_interface("Cloud") cal.init() # Start the VMs for vm in vms: cal.start_vm(account, vm.vm_id) lxc.ls() # Exit if the containers are not supposed to be terminated if not args.terminate: return time.sleep(3) # Stop the VMs for vm in vms: cal.stop_vm(account, vm.vm_id) lxc.ls() # Delete the VMs for vm in vms: cal.delete_vm(account, vm.vm_id) # Delete the image cal.delete_image(account, image.id)