def _do_socketdir_init(self, socketdir, perm): LOG.debug("Making screen socket directory [%s] (with permissions %o)" % (socketdir, perm)) with sh.Rooted(ROOT_GO): dirs = sh.mkdirslist(socketdir) for d in dirs: sh.chmod(d, perm)
def _setup_cleaner(self): LOG.info("Configuring cleaner template %s.", CLEANER_DATA_CONF) (_, contents) = utils.load_template(self.component_name, CLEANER_DATA_CONF) tgt_fn = sh.joinpths(self.bindir, CLEANER_DATA_CONF) sh.write_file(tgt_fn, contents) sh.chmod(tgt_fn, 0755) self.tracewriter.file_touched(tgt_fn)
def _setup_binaries(self): sh.move(sh.joinpths(self.cfg_dir, SWIFT_MAKERINGS), self.makerings_file) sh.chmod(self.makerings_file, 0777) self.tracewriter.file_touched(self.makerings_file) sh.move(sh.joinpths(self.cfg_dir, SWIFT_STARTMAIN), self.startmain_file) sh.chmod(self.startmain_file, 0777) self.tracewriter.file_touched(self.startmain_file)
def _setup_network_initer(self): LOG.info("Configuring nova network initializer template %s.", NET_INIT_CONF) (_, contents) = utils.load_template(self.component_name, NET_INIT_CONF) params = self._get_param_map(NET_INIT_CONF) contents = utils.param_replace(contents, params, True) tgt_fn = sh.joinpths(self.bindir, NET_INIT_CONF) sh.write_file(tgt_fn, contents) sh.chmod(tgt_fn, 0755) self.tracewriter.file_touched(tgt_fn)
def _setup_initer(self): LOG.info("Configuring keystone initializer template %s.", MANAGE_DATA_CONF) (_, contents) = utils.load_template(self.component_name, MANAGE_DATA_CONF) params = self._get_param_map(MANAGE_DATA_CONF) contents = utils.param_replace(contents, params, True) tgt_fn = sh.joinpths(self.bindir, MANAGE_DATA_CONF) sh.write_file(tgt_fn, contents) sh.chmod(tgt_fn, 0755) self.tracewriter.file_touched(tgt_fn)
def mark_unexecute_file(fn, kvs, comment_start='#'): add_lines = list() add_lines.append('') add_lines.append(comment_start + ' Ran on %s by %s' % (date.rcf8222date(), sh.getuser())) add_lines.append(comment_start + ' With data:') for (k, v) in kvs.items(): add_lines.append(comment_start + ' %s => %s' % (k, v)) sh.append_file(fn, joinlinesep(*add_lines)) sh.chmod(fn, 0644)
def _setup_initer(self): LOG.info("Configuring keystone initializer template %r", MANAGE_DATA_CONF) (_, contents) = utils.load_template(self.component_name, MANAGE_DATA_CONF) mp = self._get_param_map(MANAGE_DATA_CONF) contents = utils.param_replace(contents, mp, True) # FIXME, stop placing in checkout dir... tgt_fn = sh.joinpths(self.bin_dir, MANAGE_DATA_CONF) sh.write_file(tgt_fn, contents) sh.chmod(tgt_fn, 0755) self.tracewriter.file_touched(tgt_fn)
def _do_upstart_configure(self, app_name, runtime_info): (app_pth, _, program_args) = runtime_info # TODO FIXME symlinks won't work. Need to copy the files there. # https://bugs.launchpad.net/upstart/+bug/665022 cfg_fn = sh.joinpths(CONF_ROOT, app_name + CONF_EXT) if sh.isfile(cfg_fn): LOG.info("Upstart config file already exists: %s" % (cfg_fn)) return LOG.debug("Loading upstart template to be used by: %s" % (cfg_fn)) (_, contents) = utils.load_template('general', UPSTART_CONF_TMPL) params = self._get_upstart_conf_params(app_pth, app_name, *program_args) adjusted_contents = utils.param_replace(contents, params) LOG.debug("Generated up start config for %s: %s" % (app_name, adjusted_contents)) with sh.Rooted(True): sh.write_file(cfg_fn, adjusted_contents) sh.chmod(cfg_fn, 0666)
def _configure_instances_path(self, instances_path, nova_conf): nova_conf.add('instances_path', instances_path) LOG.debug("Attempting to create instance directory: %r", instances_path) self.tracewriter.dirs_made(*sh.mkdirslist(instances_path)) LOG.debug("Adjusting permissions of instance directory: %r", instances_path) sh.chmod(instances_path, 0777) instance_parent = sh.dirname(instances_path) LOG.debug("Adjusting permissions of instance directory parent: %r", instance_parent) # In cases where you are using kvm + qemu # On certain distros (ie RHEL) this user needs to be able # To enter the parents of the instance path, if this is in /home/BLAH/ then # Without enabling the whole path, this user can't write there. This helps fix that... with sh.Rooted(True): for p in sh.explode_path(instance_parent): if not os.access(p, os.X_OK) and sh.isdir(p): # Need to be able to go into that directory sh.chmod(p, os.stat(p).st_mode | 0755)
def _fix_log_dir(self): # This seems needed... # # Due to the following: # <<< Restarting rabbitmq-server: RabbitMQ is not running # <<< sh: /var/log/rabbitmq/startup_log: Permission denied # <<< FAILED - check /var/log/rabbitmq/startup_{log, _err} # # See: http://lists.rabbitmq.com/pipermail/rabbitmq-discuss/2011-March/011916.html # This seems like a bug, since we are just using service init and service restart... # And not trying to run this service directly... base_dir = sh.joinpths("/", "var", "log", "rabbitmq") if sh.isdir(base_dir): with sh.Rooted(True): # Seems like we need root perms to list that directory... for fn in sh.listdir(base_dir): if re.match("(.*?)(err|log)$", fn, re.I): sh.chmod(sh.joinpths(base_dir, fn), 0666)
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_instances_path(self, instances_path, nova_conf): nova_conf.add('instances_path', instances_path) LOG.debug("Attempting to create instance directory: %s" % (instances_path)) self.tracewriter.dirs_made(*sh.mkdirslist(instances_path)) LOG.debug("Adjusting permissions of instance directory: %s" % (instances_path)) sh.chmod(instances_path, 0777)
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)