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

View of /ea/sub_pycurl.py

Parent Directory Parent Directory | Revision Log Revision Log


Revision 18 - (download) (as text) (annotate)
Tue Oct 9 16:17:03 2012 UTC (11 years, 7 months ago) by agomez
File size: 3880 byte(s)
Changed comments to English and test
#
# 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 ='<?xml version="1.0" encoding="UTF-8"?>\
<compute xmlns="http://api.bonfire-project.eu/doc/schemas/occi">\
 <name>'+name+'</name>\
 <instance_type>'+instance+'</instance_type>\
 <disk>\
   <storage href='+'"'+disk+'"'+' />\
 </disk>\
 <nic>\
  <network href='+'"'+net+'"'+' />\
 </nic>\
   <location href='+'"'+loc+'"'+' />\
 </compute>'
        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


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

Powered By FusionForge