Skip to content

Commit

Permalink
Merging ocf.expedient.plugins into ofelia.development
Browse files Browse the repository at this point in the history
  • Loading branch information
CarolinaFernandez committed Apr 17, 2013
2 parents e2bda7d + fc4ae8e commit eb0bb83
Show file tree
Hide file tree
Showing 181 changed files with 3,989 additions and 1,633 deletions.
3 changes: 0 additions & 3 deletions expedient/bin/.upgradeReg

This file was deleted.

File renamed without changes.
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
from controller.ResourceController import ResourceController
import string

"""
Allowed methods on the XMLRPC server
"""

class xmlrpc_wrappers:
def __init__(self, callback_function = None):
self.callback_function = callback_function

def get_resources(self):
return ResourceController.get_resources()

def ping_auth(self, challenge, password):
return ResourceController.ping_auth(challenge, password)

def ping(self, challenge):
return ResourceController.ping(challenge)

Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
"""SecureXMLRPCServer.py - simple XML RPC server supporting SSL.
Based on this article: http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/81549
For windows users: http://webcleaner.sourceforge.net/pyOpenSSL-0.6.win32-py2.4.exe
Imported from http://code.activestate.com/recipes/496786-simple-xml-rpc-server-over-https/
"""
import SocketServer
import BaseHTTPServer
import SimpleHTTPServer
import SimpleXMLRPCServer
import socket, os

from communications import XmlRpcAPI
from OpenSSL import SSL
from utils.Logger import Logger

from settings.settingsLoader import XMLRPC_SERVER_LISTEN_HOST,XMLRPC_SERVER_LISTEN_PORT,XMLRPC_SERVER_KEYFILE,XMLRPC_SERVER_CERTFILE


class SecureXMLRPCServer(BaseHTTPServer.HTTPServer,SimpleXMLRPCServer.SimpleXMLRPCDispatcher):
def log_request(self, code='-', size='-'):
pass

def __init__(self, server_address, HandlerClass, logRequests=False):
"""Secure XML-RPC server.
It it very similar to SimpleXMLRPCServer but it uses HTTPS for transporting XML data.
"""
self.logRequests = logRequests

SimpleXMLRPCServer.SimpleXMLRPCDispatcher.__init__(self)
SocketServer.BaseServer.__init__(self, server_address, HandlerClass)
ctx = SSL.Context(SSL.SSLv23_METHOD)

ctx.use_privatekey_file (XMLRPC_SERVER_KEYFILE)
ctx.use_certificate_file(XMLRPC_SERVER_CERTFILE)
self.socket = SSL.Connection(ctx, socket.socket(self.address_family,
self.socket_type))
self.server_bind()
self.server_activate()

class SecureXMLRpcRequestHandler(SimpleXMLRPCServer.SimpleXMLRPCRequestHandler):
"""Secure XML-RPC request handler class.
It it very similar to SimpleXMLRPCRequestHandler but it uses HTTPS for transporting XML data.
"""
def setup(self):
self.connection = self.request
self.rfile = socket._fileobject(self.request, "rb", self.rbufsize)
self.wfile = socket._fileobject(self.request, "wb", self.wbufsize)

def do_POST(self):
"""Handles the HTTPS POST request.
It was copied out from SimpleXMLRPCServer.py and modified to shutdown the socket cleanly.
"""

try:
# get arguments
data = self.rfile.read(int(self.headers["content-length"]))
# In previous versions of SimpleXMLRPCServer, _dispatch
# could be overridden in this class, instead of in
# SimpleXMLRPCDispatcher. To maintain backwards compatibility,
# check to see if a subclass implements _dispatch and dispatch
# using that method if present.
response = self.server._marshaled_dispatch(
data, getattr(self, '_dispatch', None)
)
except: # This should only happen if the module is buggy
# internal error, report as HTTP server error
self.send_response(500)
self.end_headers()
else:
# got a valid XML RPC response
self.send_response(200)
self.send_header("Content-type", "text/xml")
self.send_header("Content-length", str(len(response)))
self.end_headers()
self.wfile.write(response)

# shut down the connection
self.wfile.flush()
self.connection.shutdown() # Modified here!

class XmlRpcServer():

logger = Logger.getLogger()

@staticmethod
def createInstanceAndEngage(callBackFunction,HandlerClass = SecureXMLRpcRequestHandler,ServerClass = SecureXMLRPCServer):
server_address = (XMLRPC_SERVER_LISTEN_HOST, XMLRPC_SERVER_LISTEN_PORT) # (address, port)
server = ServerClass(server_address, HandlerClass)
server.register_instance(XmlRpcAPI.xmlrpc_wrappers(callBackFunction))
sa = server.socket.getsockname()
XmlRpcServer.logger.debug("Serving HTTPS XMLRPC requests on "+str(sa[0])+":"+ str(sa[1]))
server.serve_forever()

Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
from settings.settingsLoader import XMLRPC_SERVER_PASSWORD

class ResourceController:

@staticmethod
def add_resource(action_id):
return True

@staticmethod
def connect(action_id):
return "Successfully connected"

@staticmethod
def get_resources():
try:
return open("resources.xml").read()
except:
return ""

@staticmethod
def ping(challenge):
return challenge

@staticmethod
def ping_auth(challenge, password):
if password != XMLRPC_SERVER_PASSWORD:
raise Exception("Password mismatch")
return challenge

Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
# Patchless XMLRPC Service for Django
# Kind of hacky, and stolen from Crast on irc.freenode.net:#django
# Self documents as well, so if you call it from outside of an XML-RPC Client
# it tells you about itself and its methods
#
# Brendan W. McAdams <[email protected]>

# SimpleXMLRPCDispatcher lets us register xml-rpc calls w/o
# running a full XMLRPC Server. It's up to us to dispatch data

from SimpleXMLRPCServer import SimpleXMLRPCDispatcher
from django.http import HttpResponse

# Create a Dispatcher; this handles the calls and translates info to function maps
#dispatcher = SimpleXMLRPCDispatcher() # Python 2.4
dispatcher = SimpleXMLRPCDispatcher(allow_none=False, encoding=None) # Python 2.5


def rpc_handler(request):
"""
the actual handler:
if you setup your urls.py properly, all calls to the xml-rpc service
should be routed through here.
If post data is defined, it assumes it's XML-RPC and tries to process as such
Empty post assumes you're viewing from a browser and tells you about the service.
"""

if len(request.POST):
response = HttpResponse(mimetype="application/xml")
response.write(dispatcher._marshaled_dispatch(request.raw_post_data))
else:
response = HttpResponse()
response.write("<b>This is an XML-RPC Service.</b><br>")
response.write("You need to invoke it using an XML-RPC Client!<br>")
response.write("The following methods are available:<ul>")
methods = dispatcher.system_listMethods()

for method in methods:
# right now, my version of SimpleXMLRPCDispatcher always
# returns "signatures not supported"... :(
# but, in an ideal world it will tell users what args are expected
sig = dispatcher.system_methodSignature(method)

# this just reads your docblock, so fill it in!
help = dispatcher.system_methodHelp(method)

response.write("<li><b>%s</b>: [%s] %s" % (method, sig, help))

response.write("</ul>")
response.write('<a href="http://www.djangoproject.com/"> <img src="http://media.djangoproject.com/img/badges/djangomade124x25_grey.gif" border="0" alt="Made with Django." title="Made with Django."></a>')

response['Content-length'] = str(len(response.content))
return response

def multiply(a, b):
"""
Multiplication is fun!
Takes two arguments, which are multiplied together.
Returns the result of the multiplication!
"""
return a*b

# you have to manually register all functions that are xml-rpc-able with the dispatcher
# the dispatcher then maps the args down.
# The first argument is the actual method, the second is what to call it from the XML-RPC side...
dispatcher.register_function(multiply, 'multiply')

Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
'''HTTP XML-RPC Server. You must define it!!!'''
XMLRPC_SERVER_PASSWORD="sr_manager"

'''Network parameters. Uncomment only if you want to override settings'''
XMLRPC_SERVER_LISTEN_HOST='0.0.0.0' # You should not use '' here, unless you have a real FQDN.
XMLRPC_SERVER_LISTEN_PORT=9445

Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
<resources>
<resource>
<name>Sensor1</name>
<temperature>19.89</temperature>
<temperature_scale>C</temperature_scale>
<connections>
<connection>Sensor3</connection>
<connection>Sensor4</connection>
</connections>
</resource>
<resource>
<name>Sensor2</name>
<temperature>312.12</temperature>
<temperature_scale>K</temperature_scale>
<connections>
<connection>Sensor1</connection>
<connection>Sensor3</connection>
<connection>Sensor5</connection>
</connections>
</resource>
<resource>
<name>Sensor3</name>
<temperature>98.61</temperature>
<temperature_scale>F</temperature_scale>
<connections>
<connection>Sensor1</connection>
<connection>Sensor4</connection>
</connections>
</resource>
<resource>
<name>Sensor4</name>
<temperature>2.1</temperature>
<temperature_scale>C</temperature_scale>
<connections>
<connection>Sensor2</connection>
<connection>Sensor5</connection>
</connections>
</resource>
<resource>
<name>Sensor5</name>
<temperature>359.23</temperature>
<temperature_scale>K</temperature_scale>
<connections>
<connection>Sensor1</connection>
<connection>Sensor3</connection>
<connection>Sensor4</connection>
</connections>
</resource>
</resources>
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@


all:
@echo "Creating certificates"
@echo "------------------------"
@echo ""
@echo ""
@echo "Generating private Key (1024 bits)..."
@openssl genrsa -passout pass:donotcare -des3 -out sr_am.key 1024
@echo ""
@echo "Generating request..."
@openssl req -passin pass:donotcare -new -key sr_am.key -out sr_am.csr
@echo ""
@echo "Removing passphrase of the key..."
@cp sr_am.key sr_am.key.org
@openssl rsa -passin pass:donotcare -in sr_am.key.org -out sr_am.key
@echo ""
@echo "Self-signing the certificate..."
@openssl x509 -req -days 3650 -in sr_am.csr -signkey sr_am.key -out sr_am.crt
@echo "Cleaning the house..."
@rm -rf sr_am.key.org sr_am.csr
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
-----BEGIN CERTIFICATE-----
MIICATCCAWoCCQCWLcncwun0vDANBgkqhkiG9w0BAQUFADBFMQswCQYDVQQGEwJl
czETMBEGA1UECBMKU29tZS1TdGF0ZTEhMB8GA1UEChMYSW50ZXJuZXQgV2lkZ2l0
cyBQdHkgTHRkMB4XDTEyMDIwMjEzNTI1M1oXDTIyMDEzMDEzNTI1M1owRTELMAkG
A1UEBhMCZXMxEzARBgNVBAgTClNvbWUtU3RhdGUxITAfBgNVBAoTGEludGVybmV0
IFdpZGdpdHMgUHR5IEx0ZDCBnzANBgkqhkiG9w0BAQEFAAOBjQAwgYkCgYEAxhpm
545VjO6donSLqSJMglaAvU591KxU4ZTzqLuOfTOEb8uW0y2S1KEynbxl8SFLcWJE
jDt8BjcmX4N5HFAwm+N53LdEsRkF7bHiLZ3k01E9gaP/T52DFJSKudeuc8Gm0ZB0
x1tZv+W/JanNZ3JqCXF04ndAm9BAESbN7AZD4G0CAwEAATANBgkqhkiG9w0BAQUF
AAOBgQBki8wz3N5yQSwbbwARx6W54/i6SMJgNe2Yyc4ny6XgZdXaEQmFfWJMCGwQ
v3GmSwafrk96CRtCeof0tarL+OagYrxxZ1K+aM5H0DHyuZSDKcDsEQt3uUudfVto
g+eiqESfhBk0iI2J2P76Zfzhox7a6p88cZQzX2bKsaPkeg6QiA==
-----END CERTIFICATE-----
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
-----BEGIN RSA PRIVATE KEY-----
MIICXAIBAAKBgQDGGmbnjlWM7p2idIupIkyCVoC9Tn3UrFThlPOou459M4Rvy5bT
LZLUoTKdvGXxIUtxYkSMO3wGNyZfg3kcUDCb43nct0SxGQXtseItneTTUT2Bo/9P
nYMUlIq5165zwabRkHTHW1m/5b8lqc1ncmoJcXTid0Cb0EARJs3sBkPgbQIDAQAB
AoGAFHYLpOUFnw3SSEJDXo/FWTz4BRWDV6EJD1ekJwxgNjxI9IcRp/QwEzgnEzWv
Tc2Djk15CQbn03iExR6+Npdtva2f+nHzM1j3FThcgyaNFQVYogTsQ41+beHaD8vC
RyL81r79mjdg5+tyCzdUr0/e0jxA5TAhG0BINGGD1RJNouECQQDpDO3xU/luqM/+
XVrey3N9lMJvm+rFOQxdfkWSrFM+9MTKZx8I90oEJYNq6aJdIyPRuiVse9vlolCc
6ZmjKub1AkEA2Zx4GTHBdFdcRpIxJDg2oAx2iEyIcTGpgSOc7qnl6wpUoxhQlNQs
HrfAOOsBwypz5eEvJHmDKeilvDi2c8l4mQJAHA2rYt556yE1EGiKdMFG4LoUgbzi
EOWiIGr/0v0ddDmgqsCpEro51a/yVt9S5SVCvY9Ly/hI6yaTz5+rF+IlNQJAWitv
yGDJnH+miMeC/VMdr2v6obe0wdKmPhCXsn1L+/yn3Xzxxvmz3nade/hFHq20oIiS
lDaVlwQDyN5nG8tb4QJBAJgpAfBYCD0EGezLgvzYi73AIdiZheuyWKdF7HABVES6
jffeGZU59AQQMYFpd5jpLAxvZws8Wr+O+b3TLvvykTU=
-----END RSA PRIVATE KEY-----
10 changes: 10 additions & 0 deletions expedient/doc/plugins/samples/aggregate/sr_manager/src/server.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
from communications.XmlRpcServer import XmlRpcServer

def main():
#Engage XMLRPC
XmlRpcServer.createInstanceAndEngage(None)

#Calling main
if __name__ == "__main__":
main()

Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#Import static settings
from settings.staticSettings import *

#Import user settings
from mySettings import *

Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import logging

##General Parameters

'''Base folder where vms and logs will be store.
All the rest of folder must be inside this folder'''

#Log level. Should be: 'DEBUG', 'INFO', 'WARNING', 'ERROR', 'CRITICAL'
#Default warning
LOG_LEVEL="WARNING"

'''XMLRPC over HTTPS server parameters'''
XMLRPC_SERVER_LISTEN_HOST='0.0.0.0' # You should not use '' here, unless you have a real FQDN.
XMLRPC_SERVER_LISTEN_PORT=9445

XMLRPC_SERVER_KEYFILE='security/certs/sr_am.key' # Replace with your PEM formatted key file
XMLRPC_SERVER_CERTFILE='security/certs/sr_am.crt' # Replace with your PEM formatted certificate file

Loading

0 comments on commit eb0bb83

Please sign in to comment.