def restraint_setup(self, host, conf_dict): """ wget appropriate restraint repo to respective nodes. Install restraint rpms and start its service. """ logger.log.info("Checking platform.dist of %s" % host) ssh_c = SSHClient(hostname = host, username = \ self.username, password = self.password) stdin, stdout, stderr = ssh_c.ExecuteCmd('python -c "import platform; \ print platform.dist()"') dist = stdout.read() dist = str(dist).replace('(','').replace(')','').replace("'", "").\ replace(',','') dist = dist.split() logger.log.info("Platform distribution for host %s is %s" % (host, dist)) repo_out = "/etc/yum.repos.d/restraint.repo" restraint_repo = conf_dict['restraint'][dist[1]] wget_cmd = "wget " + restraint_repo + " -O " + repo_out logger.log.info("%s to %s" % (host, wget_cmd)) stdin, stdout, stderr = ssh_c.ExecuteCmd(wget_cmd) for line in stdout.read().splitlines(): logger.log.info(line) restraint_remove_rpms = conf_dict['restraint']['remove_rpm'] remove_cmd = "yum remove -y " + restraint_remove_rpms logger.log.info("%s to %s" % (host, remove_cmd)) stdin, stdout, stderr = ssh_c.ExecuteCmd(remove_cmd) for line in stdout.read().splitlines(): logger.log.info(line) restraint_install_rpms = conf_dict['restraint']['install_rpm'] install_cmd = "yum install -y " + restraint_install_rpms logger.log.info("%s to %s" % (host, install_cmd)) stdin, stdout, stderr = ssh_c.ExecuteCmd(install_cmd) for line in stdout.read().splitlines(): logger.log.info(line) service = ("restraintd") start_service_cmd = ("service %s start; chkconfig %s on" % (service, \ service)) logger.log.info("%s to %s" % (host, start_service_cmd)) stdin, stdout, stderr = ssh_c.ExecuteCmd(start_service_cmd) for line in stdout.read().splitlines(): logger.log.info(line)
def copy_async_updates_repo(self, host, conf_dict): """copy the async updates repo to all the existing nodes""" try: logger.log.info( "Checking platform.dist of %s to get the right batched repo" % host) ssh_c = SSHClient(hostname = host, username = \ self.username, password = self.password) stdin, stdout, stderr = ssh_c.ExecuteCmd( 'python -c "import platform; \ print platform.dist()"') dist = stdout.read() dist = str(dist).replace('(','').replace(')','').replace("'", "").\ replace(',','') dist = dist.split() logger.log.info("Platform distribution for host %s is %s" % (host, dist)) self.async_updates_url = conf_dict['async_repos'][dist[1]] self.build_repo_file = "async_updates_" + host + ".repo" logger.log.info("Creating async updates build repo file %s" % self.build_repo_file) repo = open(self.build_repo_file, "w") repo.write("[" + "async_updates" + "]\n") repo.write("name=" + "async_updates" + "\n") repo.write("baseurl=" + self.async_updates_url + "\n") repo.write("enabled=1\n") repo.write("gpgcheck=0\n") repo.write("skip_if_unavailable=1\n") repo.close() source = self.build_repo_file destination = "/etc/yum.repos.d/" + source logger.log.info("source file is %s" % source) logger.log.info("destination file is %s" % destination) ssh_c = SSHClient(hostname = host, username = \ self.username, password = self.password) ssh_c.CopyFiles(source, destination) except KeyError, e: logger.log.error( "%s key for async_updates_url does not exists in conf." % e)