def _check_roots(action, rootdir, components): to_skip = list() if action == settings.INSTALL: if sh.isdir(rootdir): to_skip = list() for c in components: check_pth = sh.joinpths(rootdir, c) if sh.isdir(check_pth) and len(sh.listdir(check_pth)) != 0: LOG.warn("Component directory [%s] already exists and its not empty (skipping installing that component)!" % check_pth) LOG.warn("If this is undesired please remove it or uninstall %s!" % (c)) to_skip.append(c) return to_skip
def stop(self, name, *args, **kargs): with sh.Rooted(kargs.get("run_as_root", True)): trace_dir = kargs.get("trace_dir") if not trace_dir or not sh.isdir(trace_dir): msg = "No trace directory found from which to stop %s" % (name) raise excp.StopException(msg) fn_name = FORK_TEMPL % (name) (pid_file, stderr_fn, stdout_fn) = self._form_file_names(trace_dir, fn_name) trace_fn = tr.trace_fn(trace_dir, fn_name) if sh.isfile(pid_file) and sh.isfile(trace_fn): pid = int(sh.load_file(pid_file).strip()) (killed, attempts) = self._stop_pid(pid) #trash the files if killed: LOG.debug("Killed pid %s after %s attempts" % (pid, attempts)) LOG.debug("Removing pid file %s" % (pid_file)) sh.unlink(pid_file) LOG.debug("Removing stderr file %s" % (stderr_fn)) sh.unlink(stderr_fn) LOG.debug("Removing stdout file %s" % (stdout_fn)) sh.unlink(stdout_fn) LOG.debug("Removing %s trace file %s" % (name, trace_fn)) sh.unlink(trace_fn) else: msg = "Could not stop %s after %s attempts" % (name, attempts) raise excp.StopException(msg) else: msg = "No pid or trace file could be found to stop %s in directory %s" % (name, trace_dir) raise excp.StopException(msg)
def stop(self, app_name): with sh.Rooted(ROOT_GO): if not sh.isdir(self.trace_dir): msg = "No trace directory found from which to stop %s" % (app_name) raise excp.StopException(msg) fn_name = FORK_TEMPL % (app_name) (pid_file, stderr_fn, stdout_fn) = self._form_file_names(fn_name) trace_fn = tr.trace_fn(self.trace_dir, fn_name) if sh.isfile(pid_file) and sh.isfile(trace_fn): pid = int(sh.load_file(pid_file).strip()) (killed, attempts) = self._stop_pid(pid) # Trash the files if it worked if killed: LOG.debug("Killed pid %s after %s attempts" % (pid, attempts)) LOG.debug("Removing pid file %s" % (pid_file)) sh.unlink(pid_file) LOG.debug("Removing stderr file %s" % (stderr_fn)) sh.unlink(stderr_fn) LOG.debug("Removing stdout file %s" % (stdout_fn)) sh.unlink(stdout_fn) LOG.debug("Removing %s trace file %s" % (app_name, trace_fn)) sh.unlink(trace_fn) else: msg = "Could not stop %s after %s attempts" % (app_name, attempts) raise excp.StopException(msg) else: msg = "No pid or trace file could be found to stop %s in directory %s" % (app_name, self.trace_dir) raise excp.StopException(msg)
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))
def _fix_quantum(self): if not (utils.service_enabled(settings.QUANTUM_CLIENT, self.instances, False)): #make the fake quantum (apparently needed so imports don't fail???) #TODO remove this... quantum_dir = sh.joinpths(self.dash_dir, 'quantum') if not sh.isdir(quantum_dir): self.tracewriter.make_dir(quantum_dir) self.tracewriter.touch_file(sh.joinpths(quantum_dir, '__init__.py')) self.tracewriter.touch_file(sh.joinpths(quantum_dir, 'client.py'))
def _fix_quantum(self): if not (utils.service_enabled(settings.QUANTUM_CLIENT, self.instances, False)): #make the fake quantum (apparently needed so imports don't fail???) #TODO remove this... quantum_dir = sh.joinpths(self.dash_dir, 'quantum') if not sh.isdir(quantum_dir): self.tracewriter.dirs_made(*sh.mkdirslist(quantum_dir)) for fn in FAKE_QUANTUM_FILES: self.tracewriter.file_touched(sh.touch_file(sh.joinpths(quantum_dir, fn)))
def _ensure_db_access(self): # ../openstack-dashboard/local needs to be writeable by the runtime user # since currently its storing the sql-lite databases there (TODO fix that) path = sh.joinpths(self.dash_dir, "local") if sh.isdir(path): (user, group) = self._get_apache_user_group() LOG.info("Changing ownership (recursively) of %s so that it can be used by %s - %s", path, user, group) uid = sh.getuid(user) gid = sh.getgid(group) sh.chown_r(path, uid, gid)
def _ensure_db_access(self): # Need db access: # openstack-dashboard/local needs to be writeable by the runtime user # since currently its storing the sql-lite databases there (TODO fix that) path = sh.joinpths(self.dash_dir, 'local') if sh.isdir(path): (user, group) = self._get_apache_user_group() LOG.debug("Changing ownership (recursively) of %r so that it can be used by %r/%r", path, group, user) sh.chown_r(path, sh.getuid(user), sh.getgid(group))
def _check_root(action, rootdir): if not rootdir: return False if action == settings.INSTALL: if sh.isdir(rootdir): dir_list = sh.listdir(rootdir) if len(dir_list) > 0: cprint("Root directory [%s] already exists (and it's not empty)! "\ "Please remove it or uninstall components!" % (rootdir), "red") return False return True
def _ensure_db_access(self): # Need db access: # openstack-dashboard/local needs to be writeable by the runtime user # since currently its storing the sql-lite databases there (TODO fix that) path = sh.joinpths(self.dash_dir, 'local') if sh.isdir(path): (user, group) = self._get_apache_user_group() LOG.debug( "Changing ownership (recursively) of %r so that it can be used by %r/%r", path, group, user) sh.chown_r(path, sh.getuid(user), sh.getgid(group))
def _get_symlinks(self): src = self._get_target_config_name(HORIZON_APACHE_CONF) links = dict() links[src] = APACHE_CONF_TARGETS[self.distro] if settings.QUANTUM_CLIENT in self.instances: #TODO remove this junk, blah, puke that we have to do this qc = self.instances[settings.QUANTUM_CLIENT] src_pth = sh.joinpths(qc.appdir, 'quantum') if sh.isdir(src_pth): links[src_pth] = sh.joinpths(self.dash_dir, 'quantum') return links
def download(self): dirsmade = list() if sh.isdir(self.store_where): LOG.info("Existing directory located at %r, leaving it alone." % (self.store_where)) else: LOG.info("Downloading %r to %r" % (self.uri, self.store_where)) dirsmade.extend(sh.mkdirslist(self.store_where)) cmd = list(self.distro.get_command('git', 'clone')) cmd += [self.uri, self.store_where] sh.execute(*cmd) if self.branch and self.branch != GIT_MASTER_BRANCH: LOG.info("Adjusting branch to %r" % (self.branch)) cmd = list(self.distro.get_command('git', 'checkout')) cmd += [self.branch] sh.execute(*cmd, cwd=self.store_where) return dirsmade
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 _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 _gitdownload(storewhere, uri, branch=None): dirsmade = list() if sh.isdir(storewhere): LOG.info("Updating code located at [%s]" % (storewhere)) cmd = CHECKOUT_CMD + [GIT_MASTER_BRANCH] sh.execute(*cmd, cwd=storewhere) cmd = PULL_CMD sh.execute(*cmd, cwd=storewhere) else: LOG.info("Downloading from [%s] to [%s]" % (uri, storewhere)) dirsmade.extend(sh.mkdirslist(storewhere)) cmd = CLONE_CMD + [uri, storewhere] sh.execute(*cmd) if branch and branch != GIT_MASTER_BRANCH: LOG.info("Adjusting git branch to [%s]" % (branch)) cmd = CHECKOUT_CMD + [branch] sh.execute(*cmd, cwd=storewhere) return dirsmade
def download(self): dirsmade = list() if sh.isdir(self.store_where): LOG.info("Updating using git: located at %r" % (self.store_where)) cmd = list(self.distro.get_command("git", "checkout")) cmd += [GIT_MASTER_BRANCH] sh.execute(*cmd, cwd=self.store_where) cmd = self.distro.get_command("git", "pull") sh.execute(*cmd, cwd=self.store_where) else: LOG.info("Downloading using git: %r to %r" % (self.uri, self.store_where)) dirsmade.extend(sh.mkdirslist(self.store_where)) cmd = list(self.distro.get_command("git", "clone")) cmd += [self.uri, self.store_where] sh.execute(*cmd) if self.branch and self.branch != GIT_MASTER_BRANCH: LOG.info("Adjusting branch using git: %r" % (self.branch)) cmd = list(self.distro.get_command("git", "checkout")) cmd += [self.branch] sh.execute(*cmd, cwd=self.store_where) return dirsmade
def download(self): dirsmade = list() if sh.isdir(self.store_where): LOG.info("Updating using git: located at %r" % (self.store_where)) cmd = list(self.distro.get_command('git', 'checkout')) cmd += [GIT_MASTER_BRANCH] sh.execute(*cmd, cwd=self.store_where) cmd = self.distro.get_command('git', 'pull') sh.execute(*cmd, cwd=self.store_where) else: LOG.info("Downloading using git: %r to %r" % (self.uri, self.store_where)) dirsmade.extend(sh.mkdirslist(self.store_where)) cmd = list(self.distro.get_command('git', 'clone')) cmd += [self.uri, self.store_where] sh.execute(*cmd) if self.branch and self.branch != GIT_MASTER_BRANCH: LOG.info("Adjusting branch using git: %r" % (self.branch)) cmd = list(self.distro.get_command('git', 'checkout')) cmd += [self.branch] sh.execute(*cmd, cwd=self.store_where) return dirsmade
def start(self, app_name, runtime_info): (program, _, program_args) = runtime_info if not sh.isdir(self.socket_dir): self._do_socketdir_init(self.socket_dir, SCREEN_SOCKET_PERM) return self._begin_start(app_name, program, program_args)
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 _git_cache_download(storewhere, uri, branch=None): cdir = env.get_key(GIT_CACHE_DIR_ENV) if cdir and sh.isdir(cdir): #TODO pass return False
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)