def load_all(cls, path=settings.STACK_DISTRO_DIR): """Returns a list of the known distros.""" results = [] input_files = glob.glob(sh.joinpths(path, '*.yaml')) if not input_files: raise RuntimeError( 'Did not find any distro definition files in %s' % path) for fn in input_files: cls_kvs = None filename = sh.abspth(fn) LOG.audit("Attempting to load distro definition from [%s]" % (filename)) try: with open(filename, 'r') as f: cls_kvs = yaml.load(f) except (IOError, yaml.YAMLError) as err: LOG.warning('Could not load distro definition from %s: %s', filename, err) if cls_kvs is not None: try: results.append(cls(**cls_kvs)) except Exception as err: LOG.warning('Could not initialize instance %s using parameter map %s: %s', cls, cls_kvs, err) return results
def _begin_start(self, name, program, args): run_trace = tr.TraceWriter( tr.trace_fn(self.trace_dir, SCREEN_TEMPL % (name))) run_trace.trace(TYPE, RUN_TYPE) run_trace.trace(NAME, name) run_trace.trace(ARGS, json.dumps(args)) full_cmd = [program] + list(args) session_name = self._get_session() inited_screen = False if session_name is None: inited_screen = True self._do_screen_init() session_name = self._get_session() if session_name is None: msg = "After initializing screen with session named [%s], no screen session with that name was found!" % ( SESSION_NAME) raise excp.StartException(msg) run_trace.trace(SESSION_ID, session_name) if inited_screen or not sh.isfile(SCREEN_RC): rc_gen = ScreenRcGenerator(self) rc_contents = rc_gen.create(session_name, self._get_env()) out_fn = sh.abspth(SCREEN_RC) LOG.info("Writing your created screen rc file to [%s]" % (out_fn)) sh.write_file(out_fn, rc_contents) self._do_start(session_name, name, full_cmd) return run_trace.filename()
def load_all(cls, path=settings.STACK_DISTRO_DIR): """Returns a list of the known distros.""" results = [] input_files = glob.glob(sh.joinpths(path, '*.yaml')) if not input_files: raise RuntimeError( 'Did not find any distro definition files in %r' % path) for fn in input_files: cls_kvs = None filename = sh.abspth(fn) LOG.audit("Attempting to load distro definition from %r" % (filename)) try: with open(filename, 'r') as f: cls_kvs = yaml.load(f) except (IOError, yaml.YAMLError) as err: LOG.warning('Could not load distro definition from %r: %s', filename, err) if cls_kvs is not None: try: results.append(cls(**cls_kvs)) except Exception as err: LOG.warning( 'Could not initialize instance %s using parameter map %s: %s', cls, cls_kvs, err) return results
def __init__(self, distro, action, directory, config, pkg_manager, **kargs): self.distro = distro self.action = action self.directory = directory self.cfg = config self.pkg_manager = pkg_manager self.kargs = kargs self.components = dict() def_components = common.get_default_components() unclean_components = kargs.pop("components") if not unclean_components: self.components = def_components else: for (c, opts) in unclean_components.items(): if opts is None and c in def_components: self.components[c] = def_components[c] elif opts is None: self.components[c] = list() else: self.components[c] = opts self.force = kargs.get('force', False) self.ignore_deps = kargs.get('ignore_deps', False) self.ref_components = kargs.get("ref_components") self.rc_file = sh.abspth(settings.OSRC_FN) self.gen_rc = action in _RC_FILE_MAKE_ACTIONS
def _begin_start(self, name, program, args): fn_name = SCREEN_TEMPL % (name) tracefn = tr.touch_trace(self.trace_dir, fn_name) runtrace = tr.Trace(tracefn) runtrace.trace(TYPE, RUN_TYPE) runtrace.trace(NAME, name) runtrace.trace(ARGS, json.dumps(args)) full_cmd = [program] + list(args) session_name = self._get_session() inited_screen = False if session_name is None: inited_screen = True self._do_screen_init() session_name = self._get_session() if session_name is None: msg = "After initializing screen with session named [%s], no screen session with that name was found!" % (SESSION_NAME) raise excp.StartException(msg) runtrace.trace(SESSION_ID, session_name) if inited_screen or not sh.isfile(SCREEN_RC): rc_gen = ScreenRcGenerator(self) rc_contents = rc_gen.create(session_name, self._get_env()) out_fn = sh.abspth(SCREEN_RC) LOG.info("Writing your created screen rc file to [%s]" % (out_fn)) sh.write_file(out_fn, rc_contents) self._do_start(session_name, name, full_cmd) return tracefn
def _generate_extern_inc(self): lines = list() lines.append('# External includes stuff') extern_tpl = """ # Use stored ec2 env variables if [ -f "{ec2rc_fn}" ]; then source "{ec2rc_fn}" fi # Allow local overrides of env variables if [ -f "{localrc_fn}" ]; then source "{localrc_fn}" fi """ extern_inc = extern_tpl.format(ec2rc_fn=sh.abspth(settings.EC2RC_FN), localrc_fn=sh.abspth(settings.LOCALRC_FN)) lines.append(extern_inc.strip()) lines.append("") return lines
def _uninstall_dirs(self): dirsmade = self.tracereader.dirs_made() if dirsmade: dirsmade = [sh.abspth(d) for d in dirsmade] if self.keep_old: places = set() for (pth_loc, _) in self.tracereader.download_locations(): places.add(pth_loc) LOG.info("Keeping %s download directories [%s]", len(places), ",".join(sorted(places))) for download_place in places: dirsmade = sh.remove_parents(download_place, dirsmade) for dirname in dirsmade: LOG.info("Removing created directory (%s)", dirname) sh.deldir(dirname, run_as_root=True)
def _uninstall_dirs(self): dirs_made = self.tracereader.dirs_made() if dirs_made: dirs_made = [sh.abspth(d) for d in dirs_made] if self.keep_old: download_places = [path_location[0] for path_location in self.tracereader.download_locations()] if download_places: utils.log_iterable(download_places, logger=LOG, header="Keeping %s download directories (and there children directories)" % (len(download_places))) for download_place in download_places: dirs_made = sh.remove_parents(download_place, dirs_made) if dirs_made: utils.log_iterable(dirs_made, logger=LOG, header="Removing %s created directories" % (len(dirs_made))) for dir_name in dirs_made: sh.deldir(dir_name, run_as_root=True)
def _generate_extern_inc(self): lines = list() lines.append('# External includes stuff') extern_tpl = """ # Allow local overrides of env variables if [ -f "{localrc_fn}" ]; then source "{localrc_fn}" fi """ extern_inc = extern_tpl.format( localrc_fn=sh.abspth(settings.LOCALRC_FN)) lines.append(extern_inc.strip()) lines.append("") return lines
def _uninstall_dirs(self): dirsmade = self.tracereader.dirs_made() if dirsmade: dirsmade = [sh.abspth(d) for d in dirsmade] if self.keep_old: downloads = (self.tracereader.downloaded()) places = set() for info in downloads: download_place = info.get('target') if download_place: places.add(download_place) LOG.info("Keeping %s download directories [%s]" % (len(places), ",".join(sorted(places)))) for download_place in places: dirsmade = sh.remove_parents(download_place, dirsmade) for dirname in dirsmade: LOG.info("Removing created directory (%s)" % (dirname)) sh.deldir(dirname, run_as_root=True)
def post_start(self): tgt_fn = sh.joinpths(self.bindir, MANAGE_DATA_CONF) if sh.isfile(tgt_fn): #still there, run it #these environment additions are important #in that they eventually affect how this script runs LOG.info("Waiting %s seconds so that keystone can start up before running first time init." % (WAIT_ONLINE_TO)) time.sleep(WAIT_ONLINE_TO) env = dict() env['ENABLED_SERVICES'] = ",".join(self.instances.keys()) env['BIN_DIR'] = self.bindir setup_cmd = MANAGE_CMD_ROOT + [tgt_fn] LOG.info("Running (%s) command to initialize keystone." % (" ".join(setup_cmd))) (sysout, _) = sh.execute(*setup_cmd, env_overrides=env, run_as_root=False) if sysout: sh.write_file(sh.abspth(settings.EC2RC_FN), sysout.strip()) LOG.debug("Removing (%s) file since we successfully initialized keystone." % (tgt_fn)) sh.unlink(tgt_fn)
def load_file(cls, fn): persona_fn = sh.abspth(fn) LOG.audit("Loading persona from file [%s]", persona_fn) cls_kvs = None try: with open(persona_fn, "r") as fh: cls_kvs = yaml.load(fh.read()) except (IOError, yaml.YAMLError) as err: LOG.warning('Could not load persona definition from %s: %s', persona_fn, err) instance = None if cls_kvs is not None: try: cls_kvs['source'] = persona_fn instance = cls(**cls_kvs) except Exception as err: LOG.warning('Could not initialize instance %s using parameter map %s: %s', cls, cls_kvs, err) return instance
def load_file(cls, fn): persona_fn = sh.abspth(fn) LOG.audit("Loading persona from file [%s]", persona_fn) cls_kvs = None try: with open(persona_fn, "r") as fh: cls_kvs = yaml.load(fh.read()) except (IOError, yaml.YAMLError) as err: LOG.warning('Could not load persona definition from %s: %s', persona_fn, err) instance = None if cls_kvs is not None: try: cls_kvs['source'] = persona_fn instance = cls(**cls_kvs) except Exception as err: LOG.warning( 'Could not initialize instance %s using parameter map %s: %s', cls, cls_kvs, err) return instance
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)
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)
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)