Exemplo n.º 1
0
    def setUp(self):
        self.loop = asyncio.new_event_loop()
        self.logger = logging.getLogger('test-logger')

        self.account = RwcalYang.CloudAccount(
            name='test-cloud-account',
            account_type="mock",
        )

        # Define the VDUR to avoid division by zero
        self.vdur = make_vdur()
        self.vdur.vm_flavor.vcpu_count = 4
        self.vdur.vm_flavor.memory_mb = 100
        self.vdur.vm_flavor.storage_gb = 2
        self.vdur.vim_id = 'test-vim-id'

        self.plugin_manager = NfviMetricsPluginManager(self.logger)
        self.plugin_manager.register(self.account, "mock")

        self.cache = NfviMetricsCache(
            self.logger,
            self.loop,
            self.plugin_manager,
        )

        self.nfvi_interface = NfviInterface(self.loop, self.logger,
                                            self.plugin_manager, self.cache)
Exemplo n.º 2
0
    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"
Exemplo n.º 3
0
 def setUp(self):
     self.logger = logging.getLogger('test-logger')
     self.plugins = NfviMetricsPluginManager(self.logger)
     self.account = RwcalYang.CloudAccount(
         name='test-cloud-account',
         account_type="mock",
     )
Exemplo n.º 4
0
    def setUpClass(cls):
        cls.cleanUp()

        lvm.create("rift")
        cls.account = RwcalYang.CloudAccount()
        cls.cal = rwcal_cloudsim.CloudSimPlugin()
        cls.create_image()
Exemplo n.º 5
0
    def setUp(self):
        # Reduce the sample interval so that test run quickly
        NfviMetrics.SAMPLE_INTERVAL = 0.1

        # Create a mock plugin to define the metrics retrieved. The plugin will
        # return a VCPU utilization of 0.5.
        class MockPlugin(object):
            def __init__(self):
                self.metrics = RwmonYang.NfviMetrics()

            def nfvi_metrics(self, account, vim_id):
                self.metrics.vcpu.utilization = 0.5
                return self.metrics

        self.loop = asyncio.get_event_loop()
        self.logger = logging.getLogger('test-logger')

        self.account = RwcalYang.CloudAccount(
            name='test-cloud-account',
            account_type="mock",
        )

        # Define the VDUR to avoid division by zero
        vdur = make_vdur()
        vdur.vm_flavor.vcpu_count = 4
        vdur.vm_flavor.memory_mb = 100
        vdur.vm_flavor.storage_gb = 2
        vdur.vim_id = 'test-vim-id'

        # Instantiate the mock plugin
        self.plugin_manager = NfviMetricsPluginManager(self.logger)
        self.plugin_manager.register(self.account, "mock")

        self.plugin = self.plugin_manager.plugin(self.account.name)
        self.plugin.set_impl(MockPlugin())

        self.cache = NfviMetricsCache(
            self.logger,
            self.loop,
            self.plugin_manager,
        )

        self.manager = NfviInterface(
            self.loop,
            self.logger,
            self.plugin_manager,
            self.cache,
        )

        self.metrics = NfviMetrics(
            self.logger,
            self.loop,
            self.account,
            self.plugin,
            vdur,
        )
Exemplo n.º 6
0
    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'
Exemplo n.º 7
0
def get_cal_account():
    """
    Creates an object for class RwcalYang.CloudAccount()
    """
    account = RwcalYang.CloudAccount()
    account.account_type = "openstack"
    account.openstack.key = openstack_info['username']
    account.openstack.secret = openstack_info['password']
    account.openstack.auth_url = openstack_info['auth_url']
    account.openstack.tenant = openstack_info['project_name']
    account.openstack.mgmt_network = openstack_info['mgmt_network']
    return account
Exemplo n.º 8
0
def get_cal_account(auth_url):
    """
    Returns cal account
    """
    account = RwcalYang.CloudAccount()
    account.account_type = "openstack"
    account.openstack.key = openstack_info['username']
    account.openstack.secret = openstack_info['password']
    account.openstack.auth_url = auth_url
    account.openstack.tenant = openstack_info['project_name']
    account.openstack.mgmt_network = openstack_info['mgmt_network']
    return account
Exemplo n.º 9
0
    def setUp(self):
        # Reduce the sample interval so that test run quickly
        NfviMetrics.SAMPLE_INTERVAL = 0.1

        self.loop = asyncio.get_event_loop()
        self.logger = logging.getLogger('test-logger')
        self.config = InstanceConfiguration()
        self.monitor = Monitor(self.loop, self.logger, self.config)

        self.account = RwcalYang.CloudAccount(
            name='test-cloud-account',
            account_type="mock",
        )
Exemplo n.º 10
0
    def _get_cal_account(self):
        """
        Creates an object for class RwcalYang.CloudAccount()
        """
        account = RwcalYang.CloudAccount()
        account.account_type = "openstack"
        account.openstack.key = "{}_user".format(self.test_prefix)
        account.openstack.secret = "mypasswd"
        account.openstack.auth_url = 'http://{}:35357/v3/'.format(
            self.controller.ip)
        account.openstack.tenant = self.test_prefix

        return account
Exemplo n.º 11
0
    def do_init(self, rwlog_ctx):
        if not any(isinstance(h, rwlogger.RwLogger) for h in logger.handlers):
            logger.addHandler(
                rwlogger.RwLogger(
                    category="rw-cal-log",
                    subcategory="rwcal.mock",
                    log_hdl=rwlog_ctx,
                ))

        account = RwcalYang.CloudAccount()
        account.name = 'mock_account'
        account.account_type = 'mock'
        account.mock.username = '******'
        self.create_default_resources(account)
Exemplo n.º 12
0
    def setUp(self):
        self.loop = asyncio.new_event_loop()
        self.account = RwcalYang.CloudAccount(
            name='test-cloud-account',
            account_type="mock",
        )

        self.plugin = TestNfviMetrics.Plugin()
        self.logger = logging.getLogger('test-logger')

        self.vdur = make_vdur()
        self.vdur.vm_flavor.vcpu_count = 4
        self.vdur.vm_flavor.memory_mb = 100
        self.vdur.vm_flavor.storage_gb = 2
        self.vdur.vim_id = 'test-vim-id'
Exemplo n.º 13
0
    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
Exemplo n.º 14
0
def get_cal_account(**kwargs):
    """
    Returns AWS cal account
    """
    account = RwcalYang.CloudAccount()
    account.account_type = "aws"
    account.aws.key = kwargs['key']
    account.aws.secret = kwargs['secret']
    account.aws.region = kwargs['region']
    if 'ssh_key' in kwargs and kwargs['ssh_key'] is not None:
        account.aws.ssh_key = kwargs['ssh_key']
    account.aws.availability_zone = kwargs['availability_zone']
    if 'vpcid' in kwargs and kwargs['vpcid'] is not None:
        account.aws.vpcid = kwargs['vpcid']
    if 'default_subnet_id' in kwargs and kwargs[
            'default_subnet_id'] is not None:
        account.aws.default_subnet_id = kwargs['default_subnet_id']
    return account
Exemplo n.º 15
0
    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 = []
Exemplo n.º 16
0
    def setUp(self):
        self.loop = asyncio.new_event_loop()
        self.logger = logging.getLogger('test-logger')

        self.account = RwcalYang.CloudAccount(
            name='test-cloud-account',
            account_type="mock",
        )

        self.plugin_manager = NfviMetricsPluginManager(self.logger)
        self.plugin_manager.register(self.account, "mock")

        mock = self.plugin_manager.plugin(self.account.name)
        mock.set_impl(TestNfviMetricsCache.Plugin())

        self.vdur = VnfrYang.YangData_Vnfr_VnfrCatalog_Vnfr_Vdur()
        self.vdur.id = "test-vdur-id"
        self.vdur.vim_id = "test-vim-id"
        self.vdur.vm_flavor.vcpu_count = 4
        self.vdur.vm_flavor.memory_mb = 1
        self.vdur.vm_flavor.storage_gb = 1
Exemplo n.º 17
0
def get_cal_account(account_type):
    """
    Creates an object for class RwcalYang.CloudAccount()
    """
    account = RwcalYang.CloudAccount()
    if account_type == 'mock':
        account.name          = 'mock_account'
        account.account_type  = "mock"
        account.mock.username = "******"
    elif ((account_type == 'openstack_static') or (account_type == 'openstack_dynamic')):
        account.name = 'openstack_cal'
        account.account_type = 'openstack'
        account.openstack.key = openstack_info['username']
        account.openstack.secret       = openstack_info['password']
        account.openstack.auth_url     = openstack_info['auth_url']
        account.openstack.tenant       = openstack_info['project_name']
        account.openstack.mgmt_network = openstack_info['mgmt_network']

    elif account_type == 'cloudsim':
        account.name          = 'cloudsim'
        account.account_type  = "cloudsim_proxy"

    return account
Exemplo n.º 18
0
    def start(self):
        """Tasklet entry point"""
        self.log.setLevel(logging.DEBUG)

        super().start()

        cal = self.get_cal_interface()
        account = RwcalYang.CloudAccount(account_type="cloudsim")

        self.app = CalProxyApp(self.log, self.loop, cal, account)
        self._dts = rift.tasklets.DTS(self.tasklet_info,
                                      RwcalYang.get_schema(), self.loop,
                                      self.on_dts_state_change)

        io_loop = rift.tasklets.tornado.TaskletAsyncIOLoop(
            asyncio_loop=self.loop)
        self.server = tornado.httpserver.HTTPServer(
            self.app,
            io_loop=io_loop,
        )

        self.log.info("Starting Cal Proxy Http Server on port %s",
                      RwCalProxyTasklet.HTTP_PORT)
        self.server.listen(RwCalProxyTasklet.HTTP_PORT)
Exemplo n.º 19
0
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)
Exemplo n.º 20
0
    if cmdargs.reservation_server_url == "None" or cmdargs.reservation_server_url == "":
        cmdargs.reservation_server_url = None
    if cmdargs.reservation_server_url is not None:
        sys.path.append('/usr/rift/lib')
        try:
            import ndl
        except Exception as e:
            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