コード例 #1
0
def _pre_run(action_name, root_dir, pkg_manager, config, component_order, instances):
    loaded_env = False
    rc_fn = _RC_FILE
    try:
        if sh.isfile(rc_fn):
            LOG.info("Attempting to load rc file at [%s] which has your environment settings." % (rc_fn))
            am_loaded = env_rc.load_local_rc(rc_fn)
            loaded_env = True
            LOG.info("Loaded [%s] settings from rc file [%s]" % (am_loaded, rc_fn))
    except IOError:
        LOG.warn('Error reading rc file located at [%s]. Skipping loading it.' % (rc_fn))
    if action_name == settings.INSTALL:
        if root_dir:
            sh.mkdir(root_dir)
    LOG.info("Verifying that the components are ready to rock-n-roll.")
    all_instances = instances[0]
    prerequisite_instances = instances[1]
    for component in component_order:
        base_inst = all_instances.get(component)
        if base_inst:
            base_inst.verify()
        pre_inst = prerequisite_instances.get(component)
        if pre_inst:
            pre_inst.verify()
    LOG.info("Warming up your component configurations (ie so you won't be prompted later)")
    for component in component_order:
        base_inst = all_instances.get(component)
        if base_inst:
            base_inst.warm_configs()
        pre_inst = prerequisite_instances.get(component)
        if pre_inst:
            pre_inst.warm_configs()
    if action_name in _RC_FILE_MAKE_ACTIONS and not loaded_env:
        _gen_localrc(config, rc_fn)
コード例 #2
0
    def _unpack(self):
        parts = self.download_name.split('.')

        if self.download_name.endswith('.tgz') \
                or self.download_name.endswith('.tar.gz'):

            LOG.info('Extracting %s', self.download_file_name)
            self.image_name = self.download_name\
                .replace('.tgz', '').replace('.tar.gz', '')
            self.tmp_folder = shell.joinpths(Image.tmpdir, parts[0])
            shell.mkdir(self.tmp_folder)

            tar = tarfile.open(self.download_file_name)
            tar.extractall(self.tmp_folder)

            for file_ in shell.listdir(self.tmp_folder):
                if file_.find('vmlinuz') != -1:
                    self.kernel = shell.joinpths(self.tmp_folder, file_)
                elif file_.find('initrd') != -1:
                    self.initrd = shell.joinpths(self.tmp_folder, file_)
                elif file_.endswith('.img'):
                    self.image = shell.joinpths(self.tmp_folder, file_)
                else:
                    pass

        elif self.download_name.endswith('.img') \
                or self.download_name.endswith('.img.gz'):
            self.image_name = self.download_name.split('.img')[0]
            self.image = self.download_file_name

        else:
            raise IOError('Unknown image format for download %s' % (self.download_name))
コード例 #3
0
 def _unpack_tar(self, file_name, file_location, tmp_dir):
     (root_name, _) = os.path.splitext(file_name)
     kernel_fn = None
     ramdisk_fn = None
     root_img_fn = None
     with contextlib.closing(tarfile.open(file_location, 'r')) as tfh:
         for tmemb in tfh.getmembers():
             fn = tmemb.name
             if KERNEL_FN_MATCH.match(fn):
                 kernel_fn = fn
                 LOG.debug("Found kernel: %r" % (fn))
             elif RAMDISK_FN_MATCH.match(fn):
                 ramdisk_fn = fn
                 LOG.debug("Found ram disk: %r" % (fn))
             elif IMAGE_FN_MATCH.match(fn):
                 root_img_fn = fn
                 LOG.debug("Found root image: %r" % (fn))
             else:
                 LOG.debug("Unknown member %r - skipping" % (fn))
     if not root_img_fn:
         msg = "Image %r has no root image member" % (file_name)
         raise RuntimeError(msg)
     extract_dir = sh.joinpths(tmp_dir, root_name)
     sh.mkdir(extract_dir)
     LOG.info("Extracting %r to %r", file_location, extract_dir)
     with contextlib.closing(tarfile.open(file_location, 'r')) as tfh:
         tfh.extractall(extract_dir)
     locations = dict()
     if kernel_fn:
         locations['kernel'] = sh.joinpths(extract_dir, kernel_fn)
     if ramdisk_fn:
         locations['ramdisk'] = sh.joinpths(extract_dir, ramdisk_fn)
     locations['image'] = sh.joinpths(extract_dir, root_img_fn)
     return locations
コード例 #4
0
 def _unpack_tar(self, file_name, file_location, tmp_dir):
     (root_name, _) = os.path.splitext(file_name)
     (root_img_fn, ramdisk_fn, kernel_fn) = self._find_pieces(file_location)
     if not root_img_fn:
         msg = "Image %r has no root image member" % (file_name)
         raise RuntimeError(msg)
     extract_dir = sh.joinpths(tmp_dir, root_name)
     sh.mkdir(extract_dir)
     LOG.info("Extracting %r to %r", file_location, extract_dir)
     with contextlib.closing(tarfile.open(file_location, 'r')) as tfh:
         tfh.extractall(extract_dir)
     info = dict()
     if kernel_fn:
         info['kernel'] = {
             'FILE_NAME': sh.joinpths(extract_dir, kernel_fn),
             'DISK_FORMAT': 'aki',
             'CONTAINER_FORMAT': 'aki',
         }
     if ramdisk_fn:
         info['ramdisk'] = {
             'FILE_NAME': sh.joinpths(extract_dir, ramdisk_fn),
             'DISK_FORMAT': 'ari',
             'CONTAINER_FORMAT': 'ari',
         }
     info['FILE_NAME'] = sh.joinpths(extract_dir, root_img_fn)
     info['DISK_FORMAT'] = 'ami'
     info['CONTAINER_FORMAT'] = 'ami'
     return info
コード例 #5
0
 def _pre_run(self, instances, component_order):
     if not sh.isdir(self.directory):
         sh.mkdir(self.directory)
     if self.rc_file:
         try:
             LOG.info("Attempting to load rc file at [%s] which has your environment settings." % (self.rc_file))
             am_loaded = env_rc.RcReader().load(self.rc_file)
             LOG.info("Loaded [%s] settings from rc file [%s]" % (am_loaded, self.rc_file))
         except IOError:
             LOG.warn('Error reading rc file located at [%s]. Skipping loading it.' % (self.rc_file))
     LOG.info("Verifying that the components are ready to rock-n-roll.")
     for component in component_order:
         inst = instances[component]
         inst.verify()
     LOG.info("Warming up your component configurations (ie so you won't be prompted later)")
     for component in component_order:
         inst = instances[component]
         inst.warm_configs()
     if self.gen_rc and self.rc_file:
         writer = env_rc.RcWriter(self.cfg)
         if not sh.isfile(self.rc_file):
             LOG.info("Generating a file at [%s] that will contain your environment settings." % (self.rc_file))
             writer.write(self.rc_file)
         else:
             LOG.info("Updating a file at [%s] that contains your environment settings." % (self.rc_file))
             am_upd = writer.update(self.rc_file)
             LOG.info("Updated [%s] settings in rc file [%s]" % (am_upd, self.rc_file))
コード例 #6
0
 def _unpack_tar(self, file_name, file_location, tmp_dir):
     (root_name, _) = os.path.splitext(file_name)
     kernel_fn = None
     ramdisk_fn = None
     root_img_fn = None
     with contextlib.closing(tarfile.open(file_location, "r")) as tfh:
         for tmemb in tfh.getmembers():
             fn = tmemb.name
             if KERNEL_FN_MATCH.match(fn):
                 kernel_fn = fn
                 LOG.debug("Found kernel: %r" % (fn))
             elif RAMDISK_FN_MATCH.match(fn):
                 ramdisk_fn = fn
                 LOG.debug("Found ram disk: %r" % (fn))
             elif IMAGE_FN_MATCH.match(fn):
                 root_img_fn = fn
                 LOG.debug("Found root image: %r" % (fn))
             else:
                 LOG.debug("Unknown member %r - skipping" % (fn))
     if not root_img_fn:
         msg = "Image %r has no root image member" % (file_name)
         raise RuntimeError(msg)
     extract_dir = sh.joinpths(tmp_dir, root_name)
     sh.mkdir(extract_dir)
     LOG.info("Extracting %r to %r", file_location, extract_dir)
     with contextlib.closing(tarfile.open(file_location, "r")) as tfh:
         tfh.extractall(extract_dir)
     locations = dict()
     if kernel_fn:
         locations["kernel"] = sh.joinpths(extract_dir, kernel_fn)
     if ramdisk_fn:
         locations["ramdisk"] = sh.joinpths(extract_dir, ramdisk_fn)
     locations["image"] = sh.joinpths(extract_dir, root_img_fn)
     return locations
コード例 #7
0
def _pre_run(action_name, **kargs):
    if action_name == settings.INSTALL:
        root_dir = kargs.get("root_dir")
        if root_dir:
            sh.mkdir(root_dir)
コード例 #8
0
    def configure(self):
        #everything built goes in here
        nova_conf = NovaConf()

        #used more than once
        hostip = self.cfg.get('host', 'ip')

        #verbose on?
        if self._getbool('verbose'):
            nova_conf.add_simple('verbose')

        # Check if we have a logdir specified. If we do, we'll make
        # sure that it exists. We will *not* use tracewrite because we
        # don't want to lose the logs when we uninstall
        logdir = self._getstr('logdir')
        if logdir:
            full_logdir = sh.abspth(logdir)
            nova_conf.add('logdir', full_logdir)
            # Will need to be root to create it since it may be in /var/log
            if not sh.isdir(full_logdir):
                LOG.debug("Making sure that nova logdir exists at: %s" % full_logdir)
                with sh.Rooted(True):
                    sh.mkdir(full_logdir)
                    sh.chmod(full_logdir, 0777)

        #allow the admin api?
        if self._getbool('allow_admin_api'):
            nova_conf.add_simple('allow_admin_api')

        #??
        nova_conf.add_simple('allow_resize_to_same_host')

        #which scheduler do u want?
        nova_conf.add('scheduler_driver', self._getstr('scheduler', DEF_SCHEDULER))

        #setup network settings
        self._configure_network_settings(nova_conf)

        #setup nova volume settings
        if self.volumes_enabled:
            self._configure_vols(nova_conf)

        #where we are running
        nova_conf.add('my_ip', hostip)

        #setup your sql connection
        nova_conf.add('sql_connection', self.cfg.get_dbdsn('nova'))

        #configure anything libvirt releated?
        virt_driver = _canon_virt_driver(self._getstr('virt_driver'))
        if virt_driver == virsh.VIRT_TYPE:
            libvirt_type = _canon_libvirt_type(self._getstr('libvirt_type'))
            self._configure_libvirt(libvirt_type, nova_conf)

        #how instances will be presented
        instance_template = self._getstr('instance_name_prefix') + self._getstr('instance_name_postfix')
        if not instance_template:
            instance_template = DEF_INSTANCE_TEMPL
        nova_conf.add('instance_name_template', instance_template)

        #enable the standard extensions
        nova_conf.add('osapi_compute_extension', STD_COMPUTE_EXTS)

        #vnc settings setup
        self._configure_vnc(nova_conf)

        #where our paste config is
        nova_conf.add('api_paste_config', self.paste_conf_fn)

        #what our imaging service will be
        self._configure_image_service(nova_conf, hostip)

        #ec2 / s3 stuff
        nova_conf.add('ec2_dmz_host', self._getstr('ec2_dmz_host', hostip))
        nova_conf.add('s3_host', hostip)

        #how is your rabbit setup?
        nova_conf.add('rabbit_host', self.cfg.get('default', 'rabbit_host'))
        nova_conf.add('rabbit_password', self.cfg.get("passwords", "rabbit"))

        #where instances will be stored
        instances_path = self._getstr('instances_path', sh.joinpths(self.component_root, 'instances'))
        self._configure_instances_path(instances_path, nova_conf)

        #is this a multihost setup?
        self._configure_multihost(nova_conf)

        #enable syslog??
        self._configure_syslog(nova_conf)

        #handle any virt driver specifics
        self._configure_virt_driver(nova_conf)

        #and extract to finish
        return self._get_content(nova_conf)
コード例 #9
0
    def configure(self):
        # Everything built goes in here
        nova_conf = NovaConf()

        # Used more than once so we calculate it ahead of time
        hostip = self.cfg.get('host', 'ip')

        if self._getbool('verbose'):
            nova_conf.add('verbose', True)

        # Check if we have a logdir specified. If we do, we'll make
        # sure that it exists. We will *not* use tracewrite because we
        # don't want to lose the logs when we uninstall
        logdir = self._getstr('logdir')
        if logdir:
            full_logdir = sh.abspth(logdir)
            nova_conf.add('logdir', full_logdir)
            # Will need to be root to create it since it may be in /var/log
            if not sh.isdir(full_logdir):
                LOG.debug("Making sure that nova logdir exists at: %s" % full_logdir)
                with sh.Rooted(True):
                    sh.mkdir(full_logdir)
                    sh.chmod(full_logdir, 0777)

        # Allow the admin api?
        if self._getbool('allow_admin_api'):
            nova_conf.add('allow_admin_api', True)

        # FIXME: ??
        nova_conf.add('allow_resize_to_same_host', True)

        # Which scheduler do u want?
        nova_conf.add('compute_scheduler_driver', self._getstr('scheduler', DEF_SCHEDULER))

        # Rate limit the api??
        if self._getbool('api_rate_limit'):
            nova_conf.add('api_rate_limit', str(True))
        else:
            nova_conf.add('api_rate_limit', str(False))

        # Setup any network settings
        self._configure_network_settings(nova_conf)

        # Setup nova volume settings
        if self.volumes_enabled:
            self._configure_vols(nova_conf)

        # The ip of where we are running
        nova_conf.add('my_ip', hostip)

        # Setup your sql connection
        nova_conf.add('sql_connection', db.fetch_dbdsn(self.cfg, self.pw_gen, DB_NAME))

        # Configure anything libvirt related?
        virt_driver = canon_virt_driver(self._getstr('virt_driver'))
        if virt_driver == 'libvirt':
            libvirt_type = lv.canon_libvirt_type(self._getstr('libvirt_type'))
            self._configure_libvirt(libvirt_type, nova_conf)

        # How instances will be presented
        instance_template = self._getstr('instance_name_prefix') + self._getstr('instance_name_postfix')
        if not instance_template:
            instance_template = DEF_INSTANCE_TEMPL
        nova_conf.add('instance_name_template', instance_template)

        # Enable the standard extensions
        nova_conf.add('osapi_compute_extension', STD_COMPUTE_EXTS)

        # Auth will be using keystone
        nova_conf.add('auth_strategy', 'keystone')

        # Vnc settings setup
        self._configure_vnc(nova_conf)

        # Where our paste config is
        nova_conf.add('api_paste_config', self.paste_conf_fn)

        # What our imaging service will be
        self._configure_image_service(nova_conf, hostip)

        # Configs for ec2 / s3 stuff
        nova_conf.add('ec2_dmz_host', self._getstr('ec2_dmz_host', hostip))
        nova_conf.add('s3_host', hostip)

        # How is your rabbit setup?
        nova_conf.add('rabbit_host', self.cfg.getdefaulted('rabbit', 'rabbit_host', hostip))
        nova_conf.add('rabbit_password', self.cfg.get("passwords", "rabbit"))

        # Where instances will be stored
        instances_path = self._getstr('instances_path', sh.joinpths(self.component_dir, 'instances'))
        self._configure_instances_path(instances_path, nova_conf)

        # Is this a multihost setup?
        self._configure_multihost(nova_conf)

        # Handle any virt driver specifics
        self._configure_virt_driver(nova_conf)

        # Annnnnd extract to finish
        return self._get_content(nova_conf)
コード例 #10
0
    def configure(self):
        # Everything built goes in here
        nova_conf = NovaConf()

        # Used more than once so we calculate it ahead of time
        hostip = self.cfg.get('host', 'ip')

        if self._getbool('verbose'):
            nova_conf.add('verbose', True)

        # Check if we have a logdir specified. If we do, we'll make
        # sure that it exists. We will *not* use tracewrite because we
        # don't want to lose the logs when we uninstall
        logdir = self._getstr('logdir')
        if logdir:
            full_logdir = sh.abspth(logdir)
            nova_conf.add('logdir', full_logdir)
            # Will need to be root to create it since it may be in /var/log
            if not sh.isdir(full_logdir):
                LOG.debug("Making sure that nova logdir exists at: %s" %
                          full_logdir)
                with sh.Rooted(True):
                    sh.mkdir(full_logdir)
                    sh.chmod(full_logdir, 0777)

        # Allow the admin api?
        if self._getbool('allow_admin_api'):
            nova_conf.add('allow_admin_api', True)

        # FIXME: ??
        nova_conf.add('allow_resize_to_same_host', True)

        # Which scheduler do u want?
        nova_conf.add('compute_scheduler_driver',
                      self._getstr('scheduler', DEF_SCHEDULER))

        # Rate limit the api??
        if self._getbool('api_rate_limit'):
            nova_conf.add('api_rate_limit', str(True))
        else:
            nova_conf.add('api_rate_limit', str(False))

        # Setup any network settings
        self._configure_network_settings(nova_conf)

        # Setup nova volume settings
        if self.volumes_enabled:
            self._configure_vols(nova_conf)

        # The ip of where we are running
        nova_conf.add('my_ip', hostip)

        # Setup your sql connection
        nova_conf.add('sql_connection',
                      db.fetch_dbdsn(self.cfg, self.pw_gen, DB_NAME))

        # Configure anything libvirt related?
        virt_driver = canon_virt_driver(self._getstr('virt_driver'))
        if virt_driver == 'libvirt':
            libvirt_type = lv.canon_libvirt_type(self._getstr('libvirt_type'))
            self._configure_libvirt(libvirt_type, nova_conf)

        # How instances will be presented
        instance_template = self._getstr(
            'instance_name_prefix') + self._getstr('instance_name_postfix')
        if not instance_template:
            instance_template = DEF_INSTANCE_TEMPL
        nova_conf.add('instance_name_template', instance_template)

        # Enable the standard extensions
        nova_conf.add('osapi_compute_extension', STD_COMPUTE_EXTS)

        # Auth will be using keystone
        nova_conf.add('auth_strategy', 'keystone')

        # Vnc settings setup
        self._configure_vnc(nova_conf)

        # Where our paste config is
        nova_conf.add('api_paste_config', self.paste_conf_fn)

        # What our imaging service will be
        self._configure_image_service(nova_conf, hostip)

        # Configs for ec2 / s3 stuff
        nova_conf.add('ec2_dmz_host', self._getstr('ec2_dmz_host', hostip))
        nova_conf.add('s3_host', hostip)

        # How is your rabbit setup?
        nova_conf.add('rabbit_host',
                      self.cfg.getdefaulted('rabbit', 'rabbit_host', hostip))
        nova_conf.add('rabbit_password', self.cfg.get("passwords", "rabbit"))

        # Where instances will be stored
        instances_path = self._getstr(
            'instances_path', sh.joinpths(self.component_dir, 'instances'))
        self._configure_instances_path(instances_path, nova_conf)

        # Is this a multihost setup?
        self._configure_multihost(nova_conf)

        # Handle any virt driver specifics
        self._configure_virt_driver(nova_conf)

        # Annnnnd extract to finish
        return self._get_content(nova_conf)