Exemplo n.º 1
0
 def instance_create(self, topology_json, config_txt):
     try:
         istore = InstanceStore(self.instances_dir)
         inst = istore.create_new_instance(topology_json, config_txt)
     except ConfigException, cfge:
         message = "Error in configuration file: %s" % cfge
         return (API.STATUS_FAIL, message, None)
Exemplo n.º 2
0
 def __get_instance(self, inst_id):
     try:
         istore = InstanceStore(self.instances_dir)
         inst = istore.get_instance(inst_id)
         return (True, "Success", inst)
     except ConfigException, cfge:
         message = "Error in configuration file: %s" % cfge
         return (False, message, None)
Exemplo n.º 3
0
 def instance_list(self, inst_ids):
     istore = InstanceStore(self.instances_dir)
     
     if inst_ids == None:
         insts = istore.get_instances()
     else:
         insts = [istore.get_instance(inst_id) for inst_id in inst_ids]
             
     # TODO: Return JSON
     return insts
Exemplo n.º 4
0
 def instance_list(self, inst_ids):
     istore = InstanceStore(self.instances_dir)
     
     (valid, invalid) = istore.get_instances(inst_ids)
     instances_jsons = []
     for inst in valid:
         instances_jsons.append(inst.topology.to_json_string())
         
     instances_json = "[" + ",".join(instances_jsons) + "]"
             
     # TODO: Return invalid instances as "warnings", once we
     # add that extra return value to the API.
     return API.STATUS_SUCCESS, "Success", instances_json
Exemplo n.º 5
0
    def run(self):    
        self.parse_options()
        inst_id = self.args[1]
        
        istore = InstanceStore(self.opt.dir)
        inst = istore.get_instance(inst_id)        
        
        go_helper = GlobusOnlineHelper.from_instance(inst)

        for domain_name, domain in inst.topology.domains.items():
            for ep in domain.go_endpoints:
                go_helper.connect(ep.user)
                if (not ep.has_property("globus_connect_cert")) or (ep.has_property("globus_connect_cert") and not ep.globus_connect_cert):
                    go_helper.create_endpoint(ep, self.opt.replace)
                go_helper.disconnect()
                        
                print "Created endpoint '%s#%s' for domain '%s'" % (ep.user, ep.name, domain_name)
Exemplo n.º 6
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)