def __gen_public_host_certificates(self, node_instance): log.info("Generating host certificates for public hosts") certs_dir = "%s/certs" % self.generated_dir certg = CertificateGenerator() if self.config.has_ca(): ca_cert_file, ca_cert_key = self.config.get_ca() ca_cert, ca_key = certg.load_certificate(ca_cert_file, ca_cert_key) else: print "To use host certificates with public hostnames, you need to supply a CA certificate." self.cleanup() exit(1) certg.set_ca(ca_cert, ca_key) for node, instance in node_instance.items(): cert, key = certg.gen_host_cert(hostname= instance.public_dns_name) filename = node.demogrid_host_id cert_file = "%s/%s_cert.pem" % (certs_dir, filename) key_file = "%s/%s_key.pem" % (certs_dir, filename) certg.save_certificate(cert, key, cert_file, key_file) log.info("Generated host certificates for public hosts")
def run2(self): node = self.node instance = self.instance log.info("Setting up instance %s. Hostname: %s" % (instance.id, instance.public_dns_name), node) if self.launcher.config.has_snap(): log.debug("Creating Chef volume.", node) vol = self.launcher.conn.create_volume(1, instance.placement, self.launcher.config.get_snap()) log.debug("Created Chef volume %s. Attaching." % vol.id, node) vol.attach(instance.id, '/dev/sdh') log.debug("Chef volume attached. Waiting for it to become in-use.", node) self.launcher.wait_state(vol, "in-use") log.debug("Volume is in-use", node) self.launcher.vols.append(vol) self.check_continue() if self.launcher.loglevel in (0,1): ssh_out = None ssh_err = None elif self.launcher.loglevel == 2: ssh_out = sys.stdout ssh_err = sys.stderr log.debug("Establishing SSH connection", node) ssh = SSH("ubuntu", instance.public_dns_name, self.launcher.config.get_keyfile(), ssh_out, ssh_err) ssh.open() log.debug("SSH connection established", node) self.check_continue() if self.launcher.config.has_snap(): log.debug("Mounting Chef volume", node) ssh.run("sudo mount -t ext3 /dev/sdh /chef", expectnooutput=True) # Upload host file and update hostname log.debug("Uploading host file and updating hostname", node) ssh.scp("%s/hosts_ec2" % self.launcher.generated_dir, "/chef/cookbooks/demogrid/files/default/hosts") ssh.run("sudo cp /chef/cookbooks/demogrid/files/default/hosts /etc/hosts", expectnooutput=True) ssh.run("sudo bash -c \"echo %s > /etc/hostname\"" % node.hostname, expectnooutput=True) ssh.run("sudo /etc/init.d/hostname restart") self.check_continue() # Upload topology file log.debug("Uploading topology file", node) ssh.scp("%s/topology_ec2.rb" % self.launcher.generated_dir, "/chef/cookbooks/demogrid/attributes/topology.rb") # Copy certificates log.debug("Copying certificates", node) ssh.scp_dir("%s/certs" % self.launcher.generated_dir, "/chef/cookbooks/demogrid/files/default/") self.check_continue() if self.launcher.loglevel == 0: print " \033[1;37m%s\033[0m: Basic setup is done. Installing Grid software now." % node.hostname.split(".")[0] # Run chef log.debug("Running chef", node) ssh.scp("%s/lib/ec2/chef.conf" % self.launcher.demogrid_dir, "/tmp/chef.conf") ssh.run("echo '{ \"run_list\": \"role[%s]\" }' > /tmp/chef.json" % node.role, expectnooutput=True) ssh.run("sudo chef-solo -c /tmp/chef.conf -j /tmp/chef.json") self.check_continue() # The Chef recipes will overwrite the hostname, so # we need to set it again. ssh.run("sudo bash -c \"echo %s > /etc/hostname\"" % node.hostname, expectnooutput=True) ssh.run("sudo /etc/init.d/hostname restart") if self.launcher.config.has_snap(): ssh.run("sudo umount /chef", expectnooutput=True) vol.detach() self.launcher.wait_state(vol, "available") vol.delete() self.launcher.vols.remove(vol) ssh.run("sudo update-rc.d nis enable") log.info("Configuration done.", node) if self.launcher.loglevel == 0: print " \033[1;37m%s\033[0m is ready." % node.hostname.split(".")[0]
def run2(self): self.launcher.wait_state(self.instance, "running") log.info("Instance %s is running. Hostname: %s" % (self.instance.id, self.instance.public_dns_name))
nodes_by_role = {} for n in nodes: if not nodes_by_role.has_key(n.role): nodes_by_role[n.role] = [n] else: nodes_by_role[n.role].append(n) # Launch instances if self.loglevel == 0: print "\033[1;37mLaunching %i EC2 instances...\033[0m" % num_instances, sys.stdout.flush() self.instances = [] instances_by_role = {} log.info("Launching a total of %i EC2 instances." % num_instances) for role, n in nodes_by_role.items(): try: insttype = role_insttype.get(role, default_insttype) log.info(" |- Launching %i %s instances." % (len(n), insttype)) reservation = self.conn.run_instances(ami, min_count=len(n), max_count=len(n), instance_type=insttype, security_groups= ["default"], key_name=keypair, placement = zone) self.instances += reservation.instances instances_by_role[role] = reservation.instances except EC2ResponseError, exc: self.handle_ec2response_exception(exc, "requesting instances")