Ejemplo n.º 1
0
    def ssh_connect(self, username, hostname, keyfile):
        node = self.node

        log.debug("Establishing SSH connection", node)
        ssh = SSH(username, hostname, keyfile, default_outf = None, default_errf = None)
        try:
            ssh.open()
        except Exception, e:
            log.debug("SSH connection timed out", node)
            # Raise exception and let multi-thread manager handle it
            raise e
Ejemplo n.º 2
0
    def run(self):
        log.init_logging(2)
        
        conn = create_ec2_connection(hostname=self.hostname, path=self.path, port=self.port)

        print "Creating instance"
        reservation = conn.run_instances(self.base_ami, 
                                         min_count=1, max_count=1,
                                         instance_type='m1.small', 
                                         key_name=self.keypair)
        instance = reservation.instances[0]
        print "Instance %s created. Waiting for it to start..." % instance.id
        
        while instance.update() != "running":
            time.sleep(2)
        
        print "Instance running."

        print "Opening SSH connection."
        ssh = SSH(self.username, instance.public_dns_name, self.keyfile)
        ssh.open()
        
        print "Copying files"        
        for src, dst in self.files:
            ssh.scp(src, dst)
                  
        print "Removing private data and authorized keys"
        ssh.run("sudo find /root/.*history /home/*/.*history -exec rm -f {} \;", exception_on_error = False)
        ssh.run("sudo find / -name authorized_keys -exec rm -f {} \;", exception_on_error = False)
                  
        # Apparently instance.stop() will terminate
        # the instance (this is a known bug), so we 
        # use stop_instances instead.
        print "Stopping instance"
        conn.stop_instances([instance.id])
        while instance.update() != "stopped":
            time.sleep(2)
        print "Instance stopped"
        
        print "Creating AMI"
        
        # Doesn't actually return AMI. Have to make it public manually.
        ami = conn.create_image(instance.id, self.ami_name, description=self.ami_name)       
        
        if ami != None:
            print ami
        print "Cleaning up"

        
        print "Terminating instance"
        conn.terminate_instances([instance.id])
        while instance.update() != "terminated":
            time.sleep(2)
        print "Instance terminated"   
Ejemplo n.º 3
0
class GlobusOnlineCLIHelper(GlobusOnlineHelper):
    def __init__(self, inst, ssh_key):
        self.inst = inst
        self.ssh_key = ssh_key
        
    def connect(self, username):
        self.ssh = SSH(username, "cli.globusonline.org", self.ssh_key, default_outf = None, default_errf = None)
        try:
            self.ssh.open(timeout=10)
        except paramiko.PasswordRequiredException, pre:
            msg = "The specified SSH key (%s) requires a password." % self.ssh_key
            msg += "Please specify a passwordless SSH key."
            raise GlobusOnlineException, msg
        except Exception, e:
            raise GlobusOnlineException, "Could not connect to GO CLI. Cause: %s" % e
Ejemplo n.º 4
0
 def connect(self, username):
     self.ssh = SSH(username, "cli.globusonline.org", self.ssh_key, default_outf = None, default_errf = None)
     try:
         self.ssh.open(timeout=10)
     except paramiko.PasswordRequiredException, pre:
         msg = "The specified SSH key (%s) requires a password." % self.ssh_key
         msg += "Please specify a passwordless SSH key."
         raise GlobusOnlineException, msg
Ejemplo n.º 5
0
    def run(self):
        log.init_logging(2)

        conn = create_ec2_connection(hostname=self.hostname, path=self.path, port=self.port)

        print "Creating instance"
        reservation = conn.run_instances(self.base_ami, 
                                         min_count=1, max_count=1,
                                         instance_type='m1.small', 
                                         key_name=self.keypair)
        instance = reservation.instances[0]
        print "Instance %s created. Waiting for it to start..." % instance.id
        
        while instance.update() != "running":
            time.sleep(2)
        
        print "Instance running"
        print self.username, instance.public_dns_name, self.keyfile
        ssh = SSH(self.username, instance.public_dns_name, self.keyfile, None, None)
        try:
            ssh.open()
        except Exception, e:
            print e.message
            exit(1)
Ejemplo n.º 6
0
    def endpoint_gc_create_finalize(self, ep):
        gridftp_hostname, gridftp_subject, myproxy_hostname, myproxy_subject = self._get_hostnames_subjects(ep)
        
        # This is a kludge until http://jira.globus.org/browse/KOA-1624 gets fixed
        username = self.inst.config.get("ec2-username")
        keyfile = os.path.expanduser(self.inst.config.get("ec2-keyfile"))
        gc_setupkey = self.inst.topology.get_node_by_id(ep.gridftp[5:]).gc_setupkey
        ssh = SSH(username, gridftp_hostname, keyfile, default_outf = None, default_errf = None)
        ssh.open()      
        outf = StringIO.StringIO()
        errf = StringIO.StringIO()
        rc = ssh.run("grid-cert-info -subject -file /etc/grid-security/gc-cert-%s.pem" % (gc_setupkey), outf=outf, errf=errf, exception_on_error=False)
        if rc != 0:
            raise GlobusOnlineException, "Could not create endpoint %s" % ep.name
        ssh.close()

        gridftp_subject = outf.getvalue().strip()     
              
        self.endpoint_remove(ep)
                      
        self._endpoint_create(ep.name, gridftp_hostname, gridftp_subject, myproxy_hostname, ep.public)
Ejemplo n.º 7
0
    def run(self):    
        self.parse_options()
        inst_id = self.args[1]
        
        istore = InstanceStore(self.opt.dir)
        inst = istore.get_instance(inst_id)        
        
        if inst.config.get("go-cert-file") == None:
            # Use SSH
            use_ssh = True
            ssh_key = os.path.expanduser(inst.config.get("go-ssh-key"))
        else:
            # Use Transfer API
            use_ssh = False
            go_cert_file = os.path.expanduser(inst.config.get("go-cert-file"))
            go_key_file = os.path.expanduser(inst.config.get("go-key-file"))
            go_server_ca = resource_filename("globus.provision", "chef-files/cookbooks/globus/files/default/gd-bundle_ca.cert")

        for domain_name, domain in inst.topology.domains.items():
            for ep in domain.go_endpoints:
                if ep.gridftp.startswith("node:"):
                    gridftp = inst.topology.get_node_by_id(ep.gridftp[5:]).hostname
                else:
                    gridftp = ep.gridftp
    
                ca_dn = inst.config.get("ca-dn")
                if ca_dn == None:
                    ca_dn = "/O=Grid/OU=Globus Provision (generated)"
                else:
                    ca_dn = [x.split("=") for x in ca_dn.split(",")]
                    ca_dn = "".join(["/%s=%s" % (n.upper().strip(), v.strip()) for n,v in ca_dn])

                gridftp_subject = "%s/CN=host/%s" % (ca_dn, gridftp)
    
                if ep.myproxy.startswith("node:"):
                    myproxy = inst.topology.get_node_by_id(ep.myproxy[5:])
                else:
                    myproxy = ep.myproxy
    
                if use_ssh:
                    ssh = SSH(ep.user, "cli.globusonline.org", ssh_key, default_outf = None, default_errf = None)
                    try:
                        ssh.open()
                    except paramiko.PasswordRequiredException, pre:
                        print "The specified SSH key (%s) requires a password." % ssh_key
                        print "Please specify a passwordless SSH key."
                        exit(1)
                         
                    rc = ssh.run("endpoint-list %s" % (ep.name), exception_on_error=False)
                    if rc == 0:
                        if not self.opt.replace:
                            print "An endpoint called '%s' already exists. Please choose a different name." % ep.name
                            exit(1)
                        else:
                            rc = ssh.run("endpoint-remove %s" % (ep.name), exception_on_error=False)

                    rc = ssh.run("endpoint-add %s -p %s -s \"%s\"" % (ep.name, gridftp, gridftp_subject), exception_on_error=False)
                    if rc != 0:
                        print "Could not create endpoint."
                        exit(1)
                    rc = ssh.run("endpoint-modify --myproxy-server=%s %s" % (myproxy, ep.name), exception_on_error=False)
                    if rc != 0:
                        print "Could not set endpoint's MyProxy server."
                        exit(1)
                    if self.opt.public:
                        rc = ssh.run("endpoint-modify --public %s" % (ep.name), exception_on_error=False)
                        if rc != 0:
                            print "Could not make the endpoint public."
                            exit(1)
                    ssh.close()
                else:
                    api = TransferAPIClient(ep.user, go_server_ca, go_cert_file, go_key_file)
    
                    try:
                        (code, msg, data) = api.endpoint(ep.name)
                        ep_exists = True
                    except ClientError as ce:
                        if ce.status_code == 404:
                            ep_exists = False
                        else:
                            print ce
                            exit(1)
                
                
                    if ep_exists:
                        if not self.opt.replace:
                            print "An endpoint called '%s' already exists. Please choose a different name." % ep.name
                            exit(1)
                        else:
                            (code, msg, data) = api.endpoint_delete(ep.name)
                        
                    (code, msg, data) = api.endpoint_create(ep.name, gridftp, description="Globus Provision endpoint",
                                                            scheme="gsiftp", port=2811, subject=gridftp_subject,
                                                            myproxy_server=myproxy)
                    if code >= 400:
                        print code, msg
                        exit(1)        
            
                    if self.opt.public:
                        (code, msg, data) = api.endpoint(ep.name)
                        if code >= 400:
                            print code, msg
                            exit(1)
                        data["public"] = True
                        (code, msg, data) = api.endpoint_update(ep.name, data)
                        if code >= 400:
                            print code, msg
                            exit(1)
                        
                print "Created endpoint '%s#%s' for domain '%s'" % (ep.user, ep.name, domain_name)