예제 #1
0
    def xen_kernel_version(self):
        if self.suite.xen_kernel_flavour:
            if not self.xen_kernel:
                rmad = run_cmd(
                    'rmadison',
                    'linux-image-%s' % self.suite.xen_kernel_flavour)
                version = ['0', '0', '0', '0']

                for line in rmad.splitlines():
                    sline = line.split('|')

                    if sline[2].strip().startswith(self.vm.suite):
                        vt = sline[1].strip().split('.')
                        for i in range(4):
                            if int(vt[i]) > int(version[i]):
                                version = vt
                                break

                if version[0] == '0':
                    raise VMBuilderException(
                        'Something is wrong, no valid xen kernel for the suite %s found by rmadison'
                        % self.vm.suite)

                self.xen_kernel = '%s.%s.%s-%s' % (version[0], version[1],
                                                   version[2], version[3])
            return self.xen_kernel
        else:
            raise VMBuilderUserError(
                'There is no valid xen kernel for the suite selected.')
예제 #2
0
파일: disk.py 프로젝트: vmbuilder/vmbuilder
def path_to_partition(disks, path):
    parts = get_ordered_partitions(disks)
    parts.reverse()
    for part in parts:
        if path.startswith(part.mntpnt):
            return part
    raise VMBuilderException("Couldn't find partition path %s belongs to" % path)
예제 #3
0
    def create(self):
        logging.info('Creating filesystem: %s, size: %d, dummy: %s' %
                     (self.mntpnt, self.size, repr(self.dummy)))
        if not self.preallocated:
            logging.info('Not preallocated, so we create it.')
            if not self.filename:
                if self.mntpnt:
                    self.filename = re.sub('[^\w\s/]', '',
                                           self.mntpnt).strip().lower()
                    self.filename = re.sub('[\w/]', '_', self.filename)
                    if self.filename == '_':
                        self.filename = 'root'
                elif self.type == TYPE_SWAP:
                    self.filename = 'swap'
                else:
                    raise VMBuilderException('mntpnt not set')

                self.filename = '%s/%s' % (self.vm.workdir, self.filename)
                while os.path.exists('%s.img' % self.filename):
                    self.filename += '_'
                self.filename += '.img'
                logging.info(
                    'A name wasn\'t specified either, so we make one up: %s' %
                    self.filename)
            run_cmd(qemu_img_path(), 'create', '-f', 'raw', self.filename,
                    '%dM' % self.size)
        self.mkfs()
예제 #4
0
    def xen_kernel_version(self):
        if self.suite.xen_kernel_flavour:
            # if this is ec2, do not call rmadison.
            # this could be replaced with a method to get most recent
            # stable kernel, but really, this is not used at all for ec2
            if hasattr(self.context, 'ec2') and self.context.ec2:
                logging.debug("selecting ec2 kernel")
                self.xen_kernel = "2.6.ec2-kernel"
                return self.xen_kernel
            if not self.xen_kernel:
                rmad = run_cmd('rmadison', 'linux-image-%s' % self.suite.xen_kernel_flavour)
                version = ['0', '0','0', '0']

                for line in rmad.splitlines():
                    sline = line.split('|')

                    if sline[2].strip().startswith(self.context.get_setting('suite')):
                        vt = sline[1].strip().split('.')
                        for i in range(4):
                            if int(vt[i]) > int(version[i]):
                                version = vt
                                break

                if version[0] == '0':
                    raise VMBuilderException('Something is wrong, no valid xen kernel for the suite %s found by rmadison' % self.context.suite)

                self.xen_kernel = '%s.%s.%s-%s' % (version[0],version[1],version[2],version[3])
            return self.xen_kernel
        else:
            raise VMBuilderUserError('There is no valid xen kernel for the suite selected.')
예제 #5
0
 def set_value_fuzzy(self, value):
     if type(value) != int:
         try:
             value = int(value)
         except ValueError:
             raise VMBuilderException(
                 'Could not interpret %r as an int.' % (value, ))
     return self.set_value(value)
예제 #6
0
 def __init__(self, **kwargs):
     self.shortarg = kwargs.get('shortarg', None)
     self.longarg = kwargs.get('shortarg', None)
     self.default = kwargs.get('default', None)
     self.help = kwargs.get('help', None)
     store_type = kwargs.get('type', 'store')
     if store_type not in Frontend.setting_types:
         raise VMBuilderException("Invalid option type: %s" % type)
예제 #7
0
 def install_from_template(self, path, tmplname, context=None, mode=None):
     if not self.vm.fsmounted:
         raise VMBuilderException(
             'install_from_template called while file system is not mounted'
         )
     return self.vm.install_file(path,
                                 VMBuilder.util.render_template(
                                     self.__module__.split('.')[2], self.vm,
                                     tmplname, context),
                                 mode=mode)
예제 #8
0
 def set_valid_options(self, valid_options):
     """
     Set the list of valid options for this setting.
     """
     if not type(valid_options) == list and valid_options is not None:
         raise VMBuilderException(
             'set_valid_options only accepts lists or None')
     if valid_options:
         for option in valid_options:
             self.check_value(option)
     self.valid_options = valid_options
예제 #9
0
 def set_value_fuzzy(self, value):
     if type(value) == str:
         if value.lower() in ['no', 'false', 'off', '0']:
             value = False
         elif value.lower() in ['yes', 'true', 'on', '1']:
             value = True
         else:
             raise VMBuilderException(
                 'Could not interpret %r as a boolean value.' %
                 (value, ))
     return self.set_value(value)
예제 #10
0
 def do_check_value(self, value):
     """
     Checks the value's validity.
     """
     if self.valid_options is not None:
         if value not in self.valid_options:
             raise VMBuilderException(
                 '%r is not a valid option for %s. Valid options are: %s'
                 % (value, self.name, ' '.join(self.valid_options)))
     else:
         return self.check_value(value)
예제 #11
0
파일: disk.py 프로젝트: vmbuilder/vmbuilder
 def mkfs(self):
     if not self.filename:
         raise VMBuilderException('We can\'t mkfs if filename is not set. Did you forget to call .create()?')
     if not self.dummy:
         cmd = self.mkfs_fstype() + [self.filename]
         run_cmd(*cmd)
         # Let udev have a chance to extract the UUID for us
         run_cmd('udevadm', 'settle')
         if os.path.exists("/sbin/vol_id"):
             self.uuid = run_cmd('vol_id', '--uuid', self.filename).rstrip()
         elif os.path.exists("/sbin/blkid"):
             self.uuid = run_cmd('blkid', '-c', '/dev/null', '-sUUID', '-ovalue', self.filename).rstrip()
예제 #12
0
파일: disk.py 프로젝트: vmbuilder/vmbuilder
def detect_size(filename):
    st = os.stat(filename)
    if stat.S_ISREG(st.st_mode):
        return st.st_size / 1024*1024
    elif stat.S_ISBLK(st.st_mode): 
        # I really wish someone would make these available in Python
        BLKGETSIZE64 = 2148012658
        fp = open(filename, 'r')
        fd = fp.fileno()
        s = fcntl.ioctl(fd, BLKGETSIZE64, ' '*8)
        return unpack('L', s)[0] / 1024*1024

    raise VMBuilderException('No idea how to find the size of %s' % filename)
예제 #13
0
    def install(self, destdir):
        raise VMBuilderException('Do not call this method!')

        # These are still missing after the refactoring.
        logging.debug("Creating device.map")
        self.install_device_map()

        logging.debug("Copy host settings")
        self.copy_settings()

        if hasattr(self.context, 'ec2') and self.context.ec2:
            logging.debug("Configuring for ec2")
            self.install_ec2()
예제 #14
0
        def __init__(self,
                     setting_group,
                     name,
                     metavar=None,
                     help=None,
                     extra_args=None,
                     valid_options=None,
                     action=None,
                     **kwargs):
            # The Setting Group object that owns this Setting
            self.setting_group = setting_group
            # The name if the setting
            name_regex = '[a-z0-9-]+$'
            if not re.match(name_regex, name):
                raise VMBuilderException(
                    'Invalid name for Setting: %s. Must match regex: %s' %
                    (name, name_regex))
            else:
                self.name = name

            self.default = kwargs.get('default', self.default)
            self.help = help
            # Alternate names (for the CLI)
            self.extra_args = extra_args or []
            self.metavar = metavar
            self.value = None
            self.value_set = False
            self.valid_options = valid_options

            if self.name in self.setting_group.context._config:
                raise VMBuilderException(
                    "Setting named %s already exists. Previous definition in %s/%s/%s."
                    %
                    (self.name, self.setting_group.plugin.__name__,
                     self.setting_group.plugin._config[self.name].setting_group
                     .name, self.setting_group.plugin._config[self.name].name))

            self.setting_group.context._config[self.name] = self
예제 #15
0
    def xen_kernel_version(self):
        if self.suite.xen_kernel_flavour:
            if not self.xen_kernel:
                logging.debug("Searching for %s-%s flavour Xen kernel..." %
                              (self.suite.xen_kernel_flavour,
                               self.suite.default_flavour[self.vm.arch]))
                xen_kernel = self.find_linux_kernel(
                    self.vm.suite, self.suite.xen_kernel_flavour,
                    self.suite.default_flavour[self.vm.arch])

                if xen_kernel == None:
                    logging.debug(
                        'Default Xen kernel flavour %s-%s is not available for this suite.'
                        % (self.suite.xen_kernel_flavour,
                           self.suite.default_flavour[self.vm.arch]))
                    if self.suite.valid_flavours[self.vm.arch] > 0:
                        for flavour in self.suite.valid_flavours[self.vm.arch]:
                            if flavour != self.suite.default_flavour[
                                    self.vm.arch]:
                                logging.debug(
                                    "Trying alternate flavour %s-%s..." %
                                    (self.suite.xen_kernel_flavour, flavour))
                                xen_kernel = self.find_linux_kernel(
                                    self.vm.suite,
                                    self.suite.xen_kernel_flavour,
                                    self.suite.default_flavour[self.vm.arch])
                                if xen_kernel != None:
                                    logging.info(
                                        "Using Xen kernel linux-image-2.6-%s-%s, package version %s"
                                        % (self.suite.xen_kernel_flavour,
                                           flavour, xen_kernel))
                                    break
                else:
                    logging.info(
                        "Using Xen kernel linux-image-2.6-%s-%s, package version %s"
                        %
                        (self.suite.xen_kernel_flavour,
                         self.suite.default_flavour[self.vm.arch], xen_kernel))

                if xen_kernel == None:
                    raise VMBuilderException(
                        'There is no valid Xen kernel for the suite selected.')

                self.xen_kernel = xen_kernel
            return self.xen_kernel
        else:
            raise VMBuilderUserError(
                'There is no valid xen kernel for the suite selected.')
예제 #16
0
        def add_setting(self, *args, **kwargs):
            # kwarg['type'] is used to determine which type of Setting object to create
            # but we don't want to pass it on to its __init__.
            if 'type' in kwargs:
                type = kwargs['type']
                del kwargs['type']
            else:
                type = 'str'

            if type == 'str':
                setting = self.plugin.StringSetting(self, *args, **kwargs)
            elif type == 'bool':
                setting = self.plugin.BooleanSetting(self, *args, **kwargs)
            elif type == 'list':
                setting = self.plugin.ListSetting(self, *args, **kwargs)
            elif type == 'int':
                setting = self.plugin.IntSetting(self, *args, **kwargs)
            else:
                raise VMBuilderException(
                    "Unknown setting type: '%s' (Plugin: '%s', Setting group: '%s', Setting: '%s')"
                    % (type, self.plugin.__module__, self.name, args[0]))
            self._settings.append(setting)
예제 #17
0
 def run_in_target(self, *args, **kwargs):
     if not self.vm.fsmounted:
         raise VMBuilderException(
             'install_from_template called while file system is not mounted'
         )
     return run_cmd('chroot', self.vm.installdir, *args, **kwargs)
예제 #18
0
def set_frontend(arg):
    global frontend
    if arg in frontends.keys():
        frontend = frontends[arg]()
    else:
        raise VMBuilderException("Unknown frontend")
예제 #19
0
 def set_setting_valid_options(self, name, valid_options):
     if not name in self.context._config:
         raise VMBuilderException('Unknown config key: %s' % name)
     self.context._config[name].set_valid_options(valid_options)
예제 #20
0
 def get_setting_default(self, name):
     if not name in self.context._config:
         raise VMBuilderException('Unknown config key: %s' % name)
     return self.context._config[name].get_default()
예제 #21
0
 def set_setting_default(self, name, value):
     if not name in self.context._config:
         raise VMBuilderException('Unknown config key: %s' % name)
     self.context._config[name].set_default(value)
예제 #22
0
    def set_setting_fuzzy(self, name, value):
        if not name in self.context._config:
            raise VMBuilderException('Unknown config key: %s' % name)
#        print 'fuzzy setting of %s: %r' % (name, value)
        self.context._config[name].set_value_fuzzy(value)
예제 #23
0
 def check_value(self, value):
     if not type(value) == str:
         raise VMBuilderException('%r is type %s, expected str.' %
                                  (value, type(value)))
     return value