Example #1
0
 def handle_args(self, optparser, args):
     if len(args) < 2:
         optparser.error("You need to specify at least the hypervisor type "
                         "and the distro")
     distro = VMBuilder.get_distro(args[1])()
     hypervisor = VMBuilder.get_hypervisor(args[0])(distro)
     return hypervisor, distro
Example #2
0
 def handle_args(self, optparser, args):
     if len(args) < 2:
         optparser.error("You need to specify at least the hypervisor type "
                         "and the distro")
     distro = VMBuilder.get_distro(args[1])()
     hypervisor = VMBuilder.get_hypervisor(args[0])(distro)
     return hypervisor, distro
Example #3
0
 def handle_args(self, optparser, args):
     if len(args) < 2:
         optparser.error("You need to specify at least the hypervisor type " "and the series")
     distro = VMBuilder.get_distro("ubuntu")()
     hypervisor = VMBuilder.get_hypervisor(args[0])(distro)
     distro.set_setting("suite", args[1])
     return hypervisor, distro
Example #4
0
 def handle_args(self, optparser, args):
     if len(args) < 2:
         optparser.error("You need to specify at least the hypervisor type "
                         "and the series")
     distro = VMBuilder.get_distro('ubuntu')()
     hypervisor = VMBuilder.get_hypervisor(args[0])(distro)
     distro.set_setting('suite', args[1])
     return hypervisor, distro
Example #5
0
    def test_preflight_check_failed(self):
        import VMBuilder
        from VMBuilder.plugins.ubuntu.distro import Ubuntu
        from VMBuilder.exception import VMBuilderUserError

        vm = VMBuilder.VM()
        vm.suite = 'foo'
        ubuntu = Ubuntu(vm)
        self.assertRaises(VMBuilderUserError, ubuntu.preflight_check)
Example #6
0
 def set_verbosity(self, option, opt_str, value, parser):
     if opt_str == '--debug':
         VMBuilder.set_console_loglevel(logging.DEBUG)
     elif opt_str == '--verbose':
         VMBuilder.set_console_loglevel(logging.INFO)
     elif opt_str == '--quiet':
         VMBuilder.set_console_loglevel(logging.CRITICAL)
Example #7
0
 def set_verbosity(self, option, opt_str, value, parser):
     if opt_str == '--debug':
         VMBuilder.set_console_loglevel(logging.DEBUG)
     elif opt_str == '--verbose':
         VMBuilder.set_console_loglevel(logging.INFO)
     elif opt_str == '--quiet':
         VMBuilder.set_console_loglevel(logging.CRITICAL)
Example #8
0
    def run(self):
        try:
            next = False
            conf = None
            for val in sys.argv:
                if (val == '-c') | (val == '--config'):
                    next = True
                elif next:
                    conf = val
                    break

            vm = VMBuilder.VM(conf)
            vm.register_setting('--version', action='callback', callback=self.versioninfo, callback_kwargs={ 'vm' : vm }, help='Show version information')
            vm.register_setting('--rootsize', metavar='SIZE', default=4096, help='Size (in MB) of the root filesystem [default: %default]')
            vm.register_setting('--optsize', metavar='SIZE', default=0, help='Size (in MB) of the /opt filesystem. If not set, no /opt filesystem will be added.')
            vm.register_setting('--swapsize', metavar='SIZE', default=1024, help='Size (in MB) of the swap partition [default: %default]')
            vm.register_setting('--raw', metavar='PATH', type='string', help="Specify a file (or block device) to as first disk image.")
            vm.register_setting('--part', metavar='PATH', type='string', help="Allows to specify a partition table in PATH each line of partfile should specify (root first): \n    mountpoint size \none per line, separated by space, where size is in megabytes. You can have up to 4 virtual disks, a new disk starts on a line containing only '---'. ie: \n    root 2000 \n    /boot 512 \n    swap 1000 \n    --- \n    /var 8000 \n    /var/log 2000")
            self.set_usage(vm)

            vm.optparser.disable_interspersed_args()
            (foo, args) = vm.optparser.parse_args()
            self.handle_args(vm, args)
            vm.optparser.enable_interspersed_args()

            for opt in vm.optparser.option_list + sum([grp.option_list for grp in vm.optparser.option_groups], []):
                if len(opt._long_opts) > 1 or (opt.action == 'store' and opt._long_opts[0][2:] != opt.dest):
                    opt.help += " Config option: %s" % opt.dest

            (settings, args) = vm.optparser.parse_args(values=optparse.Values())
            for (k,v) in settings.__dict__.iteritems():
                setattr(vm, k, v)

            self.set_disk_layout(vm)

            vm.create()
        except VMBuilder.VMBuilderUserError, e:
            print >> sys.stderr, e
    def set_usage(self, vm):
        vm.optparser.set_usage('%prog hypervisor suite [options]')
        vm.optparser.arg_help = (('hypervisor', vm.hypervisor_help), ('suite', self.suite_help))

    def suite_help(self):
        return 'Suite. Valid options: %s' % " ".join(self.suites)

    def handle_args(self, vm, args):
        if len(args) < 2:
            vm.optparser.error("You need to specify at least the hypervisor type and the suite")
        vm.set_hypervisor(args[0])
        vm.set_distro(self.distro)
        vm.suite = args[1]
 
class UVB(VB):
    arg = 'ubuntu-vm-builder'
    import VMBuilder.plugins.ubuntu as ubuntu
    suites = ubuntu.distro.Ubuntu.suites
    distro = 'ubuntu'

class DVB(VB):
    arg = 'debian-vm-builder'
    import VMBuilder.plugins.debian as debian
    suites = debian.distro.Debian.suites
    distro = 'debian'


VMBuilder.register_frontend(CLI)
VMBuilder.register_frontend(UVB)
VMBuilder.register_frontend(DVB)
 def test_get_version_info(self):
     info = VMBuilder.get_version_info()
     self.assertTrue('major' in info)
     self.assertTrue('minor' in info)
     self.assertTrue('micro' in info)
     self.assertTrue('revno' in info)
    def test_register_distro(self):
        class TestDistro():
            arg = 'test'

        VMBuilder.register_distro(TestDistro)
        self.assertEqual(TestDistro, VMBuilder.get_distro('test'))
    def test_register_hypervisor(self):
        class TestHypervisor():
            arg = 'test'

        VMBuilder.register_hypervisor(TestHypervisor)
        self.assertEqual(TestHypervisor, VMBuilder.get_hypervisor('test'))
 def test_set_console_log_level(self):
     for x in range(50):
         VMBuilder.set_console_loglevel(x)
         self.assertEquals(VMBuilder.log.console.level, x)
Example #14
0
 def test_get_version_info(self):
     info = VMBuilder.get_version_info()
     self.assertTrue('major' in info)
     self.assertTrue('minor' in info)
     self.assertTrue('micro' in info)
     self.assertTrue('revno' in info)
Example #15
0
 def test_set_console_log_level(self):
     for x in range(50):
         VMBuilder.set_console_loglevel(x)
         self.assertEquals(VMBuilder.log.console.level, x)
Example #16
0
    def test_register_distro(self):
        class TestDistro():
            arg = 'test'

        VMBuilder.register_distro(TestDistro)
        self.assertEqual(TestDistro, VMBuilder.get_distro('test'))
Example #17
0
 def versioninfo(self, option, opt, value, parser):
     print('%(major)d.%(minor)d.%(micro)s' % VMBuilder.get_version_info())
     sys.exit(0)
Example #18
0
    def test_register_hypervisor(self):
        class TestHypervisor():
            arg = 'test'

        VMBuilder.register_hypervisor(TestHypervisor)
        self.assertEqual(TestHypervisor, VMBuilder.get_hypervisor('test'))
Example #19
0
        offset = 0
        for pair in curdisk:
            logging.debug("do_disk - part: %s, size: %s, offset: %d" % (pair[0], pair[1], offset))
            if pair[0] == 'root':
                disk.add_part(offset, int(pair[1]), 'ext3', '/')
            elif pair[0] == 'swap':
                disk.add_part(offset, int(pair[1]), pair[0], pair[0])
            else:
                disk.add_part(offset, int(pair[1]), 'ext3', pair[0])
            offset += int(pair[1])

class UVB(CLI):
    arg = 'ubuntu-vm-builder'

    def set_usage(self, vm):
        vm.optparser.set_usage('%prog hypervisor suite [options]')
        vm.optparser.arg_help = (('hypervisor', vm.hypervisor_help), ('suite', self.suite_help))

    def suite_help(self):
        return 'Suite. Valid options: %s' % " ".join(VMBuilder.plugins.ubuntu.distro.Ubuntu.suites)

    def handle_args(self, vm, args):
        if len(args) < 2:
            vm.optparser.error("You need to specify at least the hypervisor type and the suite")
        vm.set_hypervisor(args[0])
        vm.set_distro('ubuntu')
        vm.suite = args[1]
 
VMBuilder.register_frontend(CLI)
VMBuilder.register_frontend(UVB)
Example #20
0
 def versioninfo(self, option, opt, value, parser):
     print ('%(major)d.%(minor)d.%(micro)s' %
                                              VMBuilder.get_version_info())
     sys.exit(0)