# # BonFIRE Virtual Clusters on Federated Clouds Demonstration Kit # # Copyright (c) Fundacion Centro Tecnologico de Supercomputacion de Galicia 2012 # # License Apache Software # # The research leading to these results has received funding from # the European Community's Seventh Framework Programme (FP7/2007-2013) # under agreement number 257386 # # This software is provided with ABSOLUTELY NO WARRANTY # import httplib2 import simplejson class sub: """Submit request. Input: usr, passwd, json, theurl Output: List of request""" def _init_(self, user, passwd): self.user = user self.passwd = passwd def submit(self, theurl, exp): """Submit JSON. Input: exp, user, passwd""" h = httplib2.Http(disable_ssl_certificate_validation=True) h.add_credentials(self.user, self.passwd) jsondata = simplejson.dumps(exp) resp, content = h.request(theurl, 'POST', jsondata, headers={'Content-Type': 'application/json'}) return content def submit_xml(self, theurl, name, instance, disk, net, loc): """Add one compute defined in xml. Input: compute_xml, user, passwd""" h = httplib2.Http(disable_ssl_certificate_validation=True) h.add_credentials(self.user, self.passwd) xmldata ='\ \ '+name+'\ '+instance+'\ \ \ \ \ \ \ \ ' resp, content = h.request(theurl, 'POST', xmldata, headers={'Content-Type': 'application/vnd.bonfire+xml','Accept':'*/*'}) #print resp, content, jsondata return content def log(self, url_log): """GET the URL log. Input: url_log, user, passwd""" h = httplib2.Http(disable_ssl_certificate_validation=True) h.add_credentials(self.user, self.passwd) resp, content = h.request(url_log, 'GET', headers={'Content-Type': 'application/xml'}) out='bad' while out == 'bad': try: content = simplejson.loads(content) except (simplejson.decoder.JSONDecodeError, ValueError): print 'No valid Json response from '+url_log, content resp, content = h.request(url_log, 'GET', headers={'Content-Type': 'application/xml'}) else: out='good' return content def computes(self, url_log): """Get info of experiment compute nodes. Input: url_log""" h = httplib2.Http(disable_ssl_certificate_validation=True) h.add_credentials(self.user, self.passwd) resp, content = h.request(url_log, 'GET', headers={'Accept':'*/*'}) return content def delete(self, url_del): """Delete experiment. Input: url_del, user, passwd""" h = httplib2.Http(disable_ssl_certificate_validation=True) h.add_credentials(self.user, self.passwd) resp, content = h.request(url_del, 'DELETE', headers={'Content-Type': 'application/xml'}) return content