Example #1
0
    def test_deploy_vm(self):
        remote_repo = 'default-openvz-repo'
        template = templates.get_template_list(remote_repo)[0]

        self._addCleanup(templates.delete_template, self.testsp, 'openvz',
                         template)
        templates.sync_template(remote_repo,
                                template,
                                self.testsp,
                                silent=True)

        vmuuid = str(uuid4())
        vms = vm.list_vms('openvz:///system')
        self.assertTrue(vmuuid not in map(lambda v: v['uuid'], vms))

        self._addCleanup(vm.undeploy_vm, 'openvz:///system', vmuuid)

        self.typical_vm_params.update({
            'uuid': vmuuid,
            'template_name': template
        })

        vm.deploy_vm('openvz:///system', self.typical_vm_params)

        vms = vm.list_vms('openvz:///system')

        expected_path = '/storage/%s/openvz/unpacked/%s.ovf' % (self.testsp,
                                                                template)
        self.assertTrue(os.path.exists(expected_path), expected_path)
        self.assertTrue(vmuuid in map(lambda v: v['uuid'], vms),
                        "%s" % map(lambda v: v['uuid'], vms))
        nvm = filter(lambda v: v['uuid'] == vmuuid, vms)
        self.assertEqual(nvm[0]['vm_type'], 'openvz')
Example #2
0
    def test_deploy_vm(self):
        remote_repo = 'default-openvz-repo'
        template = templates.get_template_list(remote_repo)[0]

        self._addCleanup(templates.delete_template, self.testsp, 'openvz', template)
        templates.sync_template(remote_repo, template, self.testsp, silent=True)

        vmuuid = str(uuid4())
        vms = vm.list_vms('openvz:///system')
        self.assertTrue(vmuuid not in map(lambda v: v['uuid'], vms))

        self._addCleanup(vm.undeploy_vm, 'openvz:///system', vmuuid)

        self.typical_vm_params.update({'uuid': vmuuid,
                                       'template_name': template})

        vm.deploy_vm('openvz:///system', self.typical_vm_params)

        vms = vm.list_vms('openvz:///system')

        expected_path = '/storage/%s/openvz/unpacked/%s.ovf' % (self.testsp, template)
        self.assertTrue(os.path.exists(expected_path), expected_path)
        self.assertTrue(vmuuid in map(lambda v: v['uuid'], vms),
                        "%s" % map(lambda v: v['uuid'], vms))
        nvm = filter(lambda v: v['uuid'] == vmuuid, vms)
        self.assertEqual(nvm[0]['vm_type'], 'openvz')
Example #3
0
    def test_deploy_vm_while_template_is_downloaded(self):
        remote_repo = 'default-openvz-repo'
        template = templates.get_template_list(remote_repo)[0]

        good_to_go = threading.Event()

        try:
            orig_unpack_template = templates.unpack_template
            templates.unpack_template = signal_when_called(good_to_go)(
                templates.unpack_template)
            sync_thread = threading.Thread(name='sync_template_available_test',
                                           target=templates.sync_template,
                                           args=(remote_repo, template,
                                                 self.testsp),
                                           kwargs={'silent': True})
            self._addCleanup(templates.delete_template, self.testsp, 'openvz',
                             template)
            sync_thread.start()
            good_to_go.wait(240)
            self.assertTrue(
                good_to_go.is_set(),
                'Timed out waiting for unpack_template to be invoked')
        finally:
            templates.unpack_template = orig_unpack_template

        try:
            vmuuid = str(uuid4())
            vms = vm.list_vms('openvz:///system')
            self._addCleanup(vm.undeploy_vm, 'openvz:///system', vmuuid)

            self.typical_vm_params.update({
                'uuid': vmuuid,
                'template_name': template,
                'hostname': 'ftdvwtd.openvz'
            })

            vm.deploy_vm('openvz:///system', self.typical_vm_params)

            vms = vm.list_vms('openvz:///system')

            self.assertFalse(
                vmuuid in map(lambda v: v['uuid'], vms),
                "%s found in %s" % (vmuuid, map(lambda v: v['uuid'], vms)))

            expected_path = '/storage/%s/openvz/unpacked/%s.ovf' % (
                self.testsp, template)
            self.assertFalse(os.path.exists(expected_path), expected_path)
        finally:
            sync_thread.join()
Example #4
0
    def test_deploy_vm_while_template_is_downloaded(self):
        remote_repo = 'default-openvz-repo'
        template = templates.get_template_list(remote_repo)[0]

        good_to_go = threading.Event()

        try:
            orig_unpack_template = templates.unpack_template
            templates.unpack_template = signal_when_called(good_to_go)(templates.unpack_template)
            sync_thread = threading.Thread(name='sync_template_available_test',
                                           target=templates.sync_template,
                                           args=(remote_repo, template, self.testsp),
                                           kwargs={'silent': True})
            self._addCleanup(templates.delete_template, self.testsp, 'openvz', template)
            sync_thread.start()
            good_to_go.wait(240)
            self.assertTrue(good_to_go.is_set(), 'Timed out waiting for unpack_template to be invoked')
        finally:
            templates.unpack_template = orig_unpack_template

        try:
            vmuuid = str(uuid4())
            vms = vm.list_vms('openvz:///system')
            self._addCleanup(vm.undeploy_vm, 'openvz:///system', vmuuid)

            self.typical_vm_params.update({'uuid': vmuuid,
                                           'template_name': template,
                                           'hostname': 'ftdvwtd.openvz'})

            vm.deploy_vm('openvz:///system', self.typical_vm_params)

            vms = vm.list_vms('openvz:///system')

            self.assertFalse(vmuuid in map(lambda v: v['uuid'], vms),
                            "%s found in %s" % (vmuuid, map(lambda v: v['uuid'], vms)))

            expected_path = '/storage/%s/openvz/unpacked/%s.ovf' % (self.testsp, template)
            self.assertFalse(os.path.exists(expected_path), expected_path)
        finally:
            sync_thread.join()
Example #5
0
    for vm in vms:
        ips = vm['interfaces']
        if len(ips) > 0:
            ip = ips[0].get('ipv4_address', ips[0]['mac'])
        else:
            ip = 'missing'
        hn = execute('hostname')
        # uptime in h
        uptime_period = 60 * 60.0
        name = vm['name']
        mem = vm['memory'] / 1024.0
        disk = vm['diskspace']['/'] / 1024.0
        vcpus = vm['vcpu']
        uptime = vm['uptime'] if vm['uptime'] else 0
        uptime /= uptime_period
        print name, mem, disk, vcpus, uptime, ip, hn
        csv.writerow([name, mem, disk, vcpus, uptime, ip, hn])


if __name__ == '__main__':
    openvz_vms = list_vms('openvz:///system')
    kvm_vms = list_vms('qemu:///system')
    with open('usage_report.csv', 'wb') as csvfile:
        csvwriter = csv.writer(csvfile,
                               delimiter=';',
                               quotechar='"',
                               quoting=csv.QUOTE_MINIMAL)
        csvwriter.writerow(
            ['Name', 'Memory', 'Disk', 'Cores', 'Uptime', 'IP info', 'HN'])
        dump_info(openvz_vms + kvm_vms, csvwriter)
Example #6
0
def dump_info(vms, csv):
        """Dump information about VMs of a certain hypervisor into a CSV file"""
        for vm in vms:
                ips = vm['interfaces']
                if len(ips) > 0:
                    ip = ips[0].get('ipv4_address', ips[0]['mac'])
                else:
                    ip = 'missing'
                hn = execute('hostname')
                # uptime in h
                uptime_period = 60 * 60.0
                name = vm['name']
                mem = vm['memory'] / 1024.0
                disk = vm['diskspace']['/'] / 1024.0
                vcpus = vm['vcpu']
                uptime = vm['uptime'] if vm['uptime'] else 0
                uptime /= uptime_period
                print name, mem, disk, vcpus, uptime, ip, hn
                csv.writerow([name, mem, disk, vcpus, uptime, ip, hn])

if __name__ == '__main__':
        openvz_vms = list_vms('openvz:///system')
        kvm_vms = list_vms('qemu:///system')
        with open('usage_report.csv', 'wb') as csvfile:
                csvwriter = csv.writer(csvfile, delimiter=';',
                                    quotechar='"', quoting=csv.QUOTE_MINIMAL)
                csvwriter.writerow(['Name', 'Memory', 'Disk', 'Cores', 'Uptime', 'IP info', 'HN'])
                dump_info(openvz_vms + kvm_vms, csvwriter)