def hack_config_for_multi_region(self, ssh_options, seeds): instances = self.get_instances() downloaded_file = os.path.join("/tmp", "cassandra.yaml.downloaded") for instance in instances: with settings(host_string=instance.public_dns_name, warn_only=True): # download config file print "downloading config from %s" % instance.public_dns_name get("/etc/cassandra/cassandra.yaml", downloaded_file) print "modifying config from %s" % instance.public_dns_name yaml = parse_yaml(urllib.urlopen(downloaded_file)) yaml['seed_provider'][0]['parameters'][0]['seeds'] = seeds yaml['listen_address'] = str(instance.public_dns_name) yaml['rpc_address'] = str(instance.public_dns_name) yaml['broadcast_address'] = socket.gethostbyname(str(instance.public_dns_name)) yaml['endpoint_snitch'] = 'org.apache.cassandra.locator.Ec2MultiRegionSnitch' print "saving config from %s" % instance.public_dns_name fd, temp_file = tempfile.mkstemp(prefix='cassandra.yaml_', text=True) os.write(fd, dump_yaml(yaml)) os.close(fd) #upload config file print "uploading new config to %s" % instance.public_dns_name put(temp_file, "/etc/cassandra/cassandra.yaml", use_sudo=use_sudo()) os.unlink(temp_file) os.unlink(downloaded_file)
def _wait_for_cassandra_service(self, instance): """ Waiting for the cassandra.pid file """ wait_time = 3 with settings(host_string=instance.public_dns_name, warn_only=True): with FULL_HIDE: try: while not files.exists("/var/run/cassandra.pid", use_sudo=use_sudo()): self.logger.debug("Sleeping for %d seconds..." % wait_time) time.sleep(wait_time) # catch SystemExit because paramiko will call abort when it detects a failure # in establishing an SSH connection except SystemExit: pass
def _configure_cassandra_instance(self, instance, seed_ips, token, set_tokens=True, auto_bootstrap=False): self.logger.debug("Configuring %s..." % instance.id) yaml_file = os.path.join("/tmp", "cassandra.yaml") cassandra_home = self.get_cassandra_home(instance) self.logger.debug("Local cassandra.yaml file: %s" % yaml_file) with settings(host_string=instance.public_dns_name, warn_only=True): #, hide("everything"): cassandra_data = os.path.join("/mnt", "cassandra-data") cassandra_logs = os.path.join("/mnt", "cassandra-logs") # create directories and log files exec_command("mkdir -p %s" % cassandra_data) exec_command("mkdir -p %s" % cassandra_logs) # set permissions exec_command("chown -R cassandra:cassandra %s %s" % (cassandra_data, cassandra_logs)) try: # get yaml file get(os.path.join(cassandra_home, "conf", "cassandra.yaml"), "/tmp") # modify it f = open(yaml_file) yaml = parse_yaml(f) f.close() yaml['seed_provider'][0]['parameters'][0]['seeds'] = ",".join(seed_ips) if set_tokens is True : yaml['initial_token'] = token if auto_bootstrap : yaml['auto_bootstrap'] = 'true' yaml['data_file_directories'] = [cassandra_data] yaml['commitlog_directory'] = cassandra_logs yaml['listen_address'] = str(instance.private_dns_name) yaml['rpc_address'] = str(instance.public_dns_name) f = open(yaml_file, "w") f.write(dump_yaml(yaml)) f.close() # put modified yaml file put(yaml_file, os.path.join(cassandra_home, "conf", "cassandra.yaml"), use_sudo=use_sudo()) except SystemExit, e: raise pass