Log In | Get Help   
Home My Page Projects Code Snippets Project Openings BonFIRE VCOC Demonstration Kit
Summary Activity SCM Files Wiki
[bonfiredemokit] Annotation of /ea/sub_pycurl.py
[bonfiredemokit] / ea / sub_pycurl.py Repository:
ViewVC logotype

Annotation of /ea/sub_pycurl.py

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1 - (view) (download) (as text)

1 : agomez 1 import httplib2
2 :     import simplejson
3 :    
4 :    
5 :    
6 :     class sub:
7 :     """Envia trabajos. Input: usr, passwd, json, theurl
8 :     Output: Lista de trabajos enviados"""
9 :    
10 :     def _init_(self, user, passwd):
11 :     self.user = user
12 :     self.passwd = passwd
13 :    
14 :    
15 :     def submit(self, theurl, exp):
16 :     """Envia el trabajo descrito en json. Input: exp, user, passwd"""
17 :    
18 :     h = httplib2.Http(disable_ssl_certificate_validation=True)
19 :     h.add_credentials(self.user, self.passwd)
20 :     jsondata = simplejson.dumps(exp)
21 :     resp, content = h.request(theurl,
22 :     'POST',
23 :     jsondata,
24 :     headers={'Content-Type': 'application/json'})
25 :     return content
26 :    
27 :     def submit_xml(self, theurl, name, instance, disk, net, loc):
28 :     """Add un compute nuevo al experimento definido en xml. Input: compute_xml, user, passwd"""
29 :    
30 :     h = httplib2.Http(disable_ssl_certificate_validation=True)
31 :     h.add_credentials(self.user, self.passwd)
32 :     xmldata ='<?xml version="1.0" encoding="UTF-8"?>\
33 :     <compute xmlns="http://api.bonfire-project.eu/doc/schemas/occi">\
34 :     <name>'+name+'</name>\
35 :     <instance_type>'+instance+'</instance_type>\
36 :     <disk>\
37 :     <storage href='+'"'+disk+'"'+' />\
38 :     </disk>\
39 :     <nic>\
40 :     <network href='+'"'+net+'"'+' />\
41 :     </nic>\
42 :     <location href='+'"'+loc+'"'+' />\
43 :     </compute>'
44 :     resp, content = h.request(theurl,
45 :     'POST',
46 :     xmldata,
47 :     headers={'Content-Type': 'application/vnd.bonfire+xml','Accept':'*/*'})
48 :     #print resp, content, jsondata
49 :     return content
50 :    
51 :    
52 :     def log(self, url_log):
53 :     """Obtiene info de la url de log que se obtiene en submit. Input: url_log, user, passwd"""
54 :    
55 :     h = httplib2.Http(disable_ssl_certificate_validation=True)
56 :     h.add_credentials(self.user, self.passwd)
57 :     resp, content = h.request(url_log,
58 :     'GET',
59 :     headers={'Content-Type': 'application/xml'})
60 :     out='bad'
61 :     while out == 'bad':
62 :     try:
63 :     content = simplejson.loads(content)
64 :     except (simplejson.decoder.JSONDecodeError, ValueError):
65 :     print 'No valid Json response from '+url_log, content
66 :     resp, content = h.request(url_log,
67 :     'GET',
68 :     headers={'Content-Type': 'application/xml'})
69 :     else:
70 :     out='good'
71 :    
72 :     return content
73 :    
74 :    
75 :    
76 :    
77 :     def computes(self, url_log):
78 :     """Obtiene info de los computes del experimento. Input: url_log"""
79 :    
80 :     h = httplib2.Http(disable_ssl_certificate_validation=True)
81 :     h.add_credentials(self.user, self.passwd)
82 :     resp, content = h.request(url_log,
83 :     'GET',
84 :     headers={'Accept':'*/*'})
85 :     return content
86 :    
87 :    
88 :     def delete(self, url_del):
89 :     """Borra el trabajo descrito en json. Input: url_del, user, passwd"""
90 :    
91 :     h = httplib2.Http(disable_ssl_certificate_validation=True)
92 :     h.add_credentials(self.user, self.passwd)
93 :     resp, content = h.request(url_del,
94 :     'DELETE',
95 :     headers={'Content-Type': 'application/xml'})
96 :     return content
97 :    

root@forge.cesga.es
ViewVC Help
Powered by ViewVC 1.0.0  

Powered By FusionForge