def clear_libvirt_domains(distro, virt_type, inst_prefix): libvirt = _get_virt_lib() if not libvirt: LOG.warn( "Could not clear out libvirt domains, libvirt not available for python." ) return virt_protocol = LIBVIRT_PROTOCOL_MAP.get(virt_type) if not virt_protocol: LOG.warn( "Could not clear out libvirt domains, no known protocol for virt type %s" % (virt_type)) return with sh.Rooted(True): LOG.info( "Attempting to clear out leftover libvirt domains using protocol %s" % (virt_protocol)) try: restart(distro) except excp.ProcessExecutionError, e: LOG.warn("Could not restart libvirt due to [%s]" % (e)) return try: conn = libvirt.open(virt_protocol) except libvirt.libvirtError, e: LOG.warn( "Could not connect to libvirt using protocol [%s] due to [%s]" % (virt_protocol, e.message)) return
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 _configure_db_confs(self): LOG.info("Fixing up %r mysql configs.", self.distro.name) fc = sh.load_file('/etc/my.cnf') lines = fc.splitlines() new_lines = list() for line in lines: if line.startswith('skip-grant-tables'): line = '#' + line new_lines.append(line) fc = utils.joinlinesep(*new_lines) with sh.Rooted(True): sh.write_file('/etc/my.cnf', fc)
def _configure_db_confs(self): LOG.info("Fixing up %s mysql configs.", self.distro.name) fc = sh.load_file('/etc/mysql/my.cnf') lines = fc.splitlines() new_lines = list() for line in lines: if line.startswith('bind-address'): line = 'bind-address = %s' % ('0.0.0.0') new_lines.append(line) fc = utils.joinlinesep(*new_lines) with sh.Rooted(True): sh.write_file('/etc/mysql/my.cnf', fc)
def configure(self): configs_made = nova.NovaInstaller.configure(self) driver_canon = nova.canon_virt_driver(self.cfg.get('nova', 'virt_driver')) if driver_canon == 'libvirt': (fn, contents) = self._get_policy(self._get_policy_users()) dirs_made = list() with sh.Rooted(True): # TODO check if this dir is restricted before assuming it isn't? dirs_made.extend(sh.mkdirslist(sh.dirname(fn))) sh.write_file(fn, contents) self.tracewriter.cfg_file_written(fn) self.tracewriter.dirs_made(*dirs_made) configs_made += 1 return configs_made
def configure(self): configs_made = comp.PythonInstallComponent.configure(self) self._generate_nova_conf() configs_made += 1 driver_canon = _canon_virt_driver(self.cfg.get('nova', 'virt_driver')) # TODO maybe move this?? if driver_canon == 'libvirt' and self.distro.get_command('virt-policy', quiet=True): (fn, contents) = self.distro.get_command('virt-policy') dirs_made = list() with sh.Rooted(True): dirs_made = sh.mkdirslist(sh.dirname(fn)) sh.write_file(fn, contents) self.tracewriter.dirs_made(*dirs_made) self.tracewriter.cfg_file_written(fn) configs_made += 1 return configs_made
def clear_domains(self, virt_type, inst_prefix): libvirt = importer.import_module('libvirt') if not libvirt: LOG.warn( "Could not clear out libvirt domains, libvirt not available for python." ) return virt_protocol = LIBVIRT_PROTOCOL_MAP.get(virt_type) if not virt_protocol: LOG.warn( "Could not clear out libvirt domains, no known protocol for virt type %r" % (virt_type)) return with sh.Rooted(True): LOG.info( "Attempting to clear out leftover libvirt domains using protocol %r" % (virt_protocol)) try: self.restart_service() except excp.ProcessExecutionError as e: LOG.warn("Could not restart libvirt due to: %s" % (e)) return try: conn = libvirt.open(virt_protocol) except libvirt.libvirtError as e: LOG.warn( "Could not connect to libvirt using protocol %r due to: %s" % (virt_protocol, e)) return with contextlib.closing(conn) as ch: try: defined_domains = ch.listDefinedDomains() kill_domains = list() for domain in defined_domains: if domain.startswith(inst_prefix): kill_domains.append(domain) if kill_domains: LOG.info("Found %s old domains to destroy (%s)" % (len(kill_domains), ", ".join( sorted(kill_domains)))) for domain in sorted(kill_domains): self._destroy_domain(ch, domain) except libvirt.libvirtError, e: LOG.warn("Could not clear out libvirt domains due to %s" % (e))
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 _config_fixups(self): (user, group) = self._get_apache_user_group() # This is recorded so it gets cleaned up during uninstall self.tracewriter.file_touched(SOCKET_CONF) LOG.info("Fixing up %r and %r files" % (SOCKET_CONF, HTTPD_CONF)) with sh.Rooted(True): # Fix the socket prefix to someplace we can use fc = "WSGISocketPrefix %s" % (sh.joinpths(self.log_dir, "wsgi-socket")) sh.write_file(SOCKET_CONF, fc) # Now adjust the run user and group (of httpd.conf) new_lines = list() for line in sh.load_file(HTTPD_CONF).splitlines(): if line.startswith("User "): line = "User %s" % (user) if line.startswith("Group "): line = "Group %s" % (group) new_lines.append(line) sh.write_file(HTTPD_CONF, utils.joinlinesep(*new_lines))
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.debug("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 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)