from sfa.trust.gid import GID
from sfa.util.record import SfaRecord
from sfa.util.rspec import RSpec
-from sfa.util.sfalogging import sfa_logger
+from sfa.util.sfalogging import logger
def determine_sfa_filekind(fn):
parser.add_option("-v", "--verbose", action='count', dest='verbose', default=0)
(options, args) = parser.parse_args()
- sfa_logger().setLevelFromOptVerbose(options.verbose)
+ logger.setLevelFromOptVerbose(options.verbose)
if len(args) <= 0:
parser.print_help()
sys.exit(1)
from optparse import OptionParser
from sfa.client.sfi import Sfi
-from sfa.util.sfalogging import sfa_logger
+from sfa.util.sfalogging import logger
import sfa.util.xmlrpcprotocol as xmlrpcprotocol
def url_hostname_port (url):
key_file = client.get_key_file()
cert_file = client.get_cert_file(key_file)
url=self.url()
- sfa_logger().info('issuing get version at %s'%url)
+ logger.info('issuing get version at %s'%url)
server=xmlrpcprotocol.get_server(url, key_file, cert_file, options)
self._version=server.GetVersion()
except:
# performing xmlrpc call
version=interface.get_version()
if self.verbose:
- sfa_logger().info("GetVersion at interface %s"%interface.url())
+ logger.info("GetVersion at interface %s"%interface.url())
if not version:
- sfa_logger().info("<EMPTY GetVersion(); offline or cannot authenticate>")
+ logger.info("<EMPTY GetVersion(); offline or cannot authenticate>")
else:
for (k,v) in version.iteritems():
if not isinstance(v,dict):
- sfa_logger().info("\r\t%s:%s"%(k,v))
+ logger.info("\r\t%s:%s"%(k,v))
else:
- sfa_logger().info(k)
+ logger.info(k)
for (k1,v1) in v.iteritems():
- sfa_logger().info("\r\t\t%s:%s"%(k1,v1))
+ logger.info("\r\t\t%s:%s"%(k1,v1))
# 'geni_api' is expected if the call succeeded at all
# 'peers' is needed as well as AMs typically don't have peers
if 'geni_api' in version and 'peers' in version:
for (k,v) in interface.get_layout().iteritems():
node.attr[k]=v
else:
- sfa_logger().error("MISSED interface with node %s"%node)
+ logger.error("MISSED interface with node %s"%node)
default_outfiles=['sfa.png','sfa.svg','sfa.dot']
scanner=SfaScan(left_to_right=options.left_to_right, verbose=options.verbose)
entries = [ Interface(entry) for entry in args ]
g=scanner.graph(entries)
- sfa_logger().info("creating layout")
+ logger.info("creating layout")
g.layout(prog='dot')
for outfile in options.outfiles:
- sfa_logger().info("drawing in %s"%outfile)
+ logger.info("drawing in %s"%outfile)
g.draw(outfile)
- sfa_logger().info("done")
+ logger.info("done")
if __name__ == '__main__':
main()
from StringIO import StringIO
from types import StringTypes, ListType
from optparse import OptionParser
-from sfa.util.sfalogging import _SfaLogger, logging
+from sfa.util.sfalogging import info_logger
from sfa.trust.certificate import Keypair, Certificate
from sfa.trust.gid import GID
from sfa.trust.credential import Credential
self.user = None
self.authority = None
self.hashrequest = False
- self.logger = _SfaLogger(self.sfi_dir + 'sfi.log', level = logging.INFO)
+ self.logger = info_logger
def create_cmd_parser(self, command, additional_cmdargs=None):
cmdargs = {"list": "authority",
from sfa.util.plxrn import hrn_to_pl_slicename
from sfa.util.plxrn import hrn_to_pl_slicename
from sfa.util.rspec import RSpec
-from sfa.util.sfalogging import sfa_logger
+from sfa.util.sfalogging import logger
from sfa.util.config import Config
from sfa.managers.aggregate_manager_pl import GetVersion, __get_registry_objects
from sfa.plc.slices import Slices
(client_path, am_url) = Config().get_max_aggrMgr_info()
sys_cmd = "cd " + client_path + "; java -classpath AggregateWS-client-api.jar:lib/* net.geni.aggregate.client.examples." + client_app + " ./repo " + am_url + " " + ' '.join(params)
ret = shell_execute(sys_cmd, timeout)
- sfa_logger().debug("shell_execute cmd: %s returns %s" % (sys_cmd, ret))
+ logger.debug("shell_execute cmd: %s returns %s" % (sys_cmd, ret))
# save request RSpec xml content to a tmp file
def save_rspec_to_file(rspec):
path = RSPEC_TMP_FILE_PREFIX + "_" + time.strftime('%Y%m%dT%H:%M:%S', time.gmtime(time.time())) +".xml"
rspec = "<RSpec type=\"SFA\"> <Fault>No resource found</Fault> </RSpec>"
else:
comp_rspec = get_xml_by_tag(output, 'computeResource')
- sfa_logger().debug("#### computeResource %s" % comp_rspec)
+ logger.debug("#### computeResource %s" % comp_rspec)
topo_rspec = get_xml_by_tag(output, 'topology')
- sfa_logger().debug("#### topology %s" % topo_rspec)
+ logger.debug("#### topology %s" % topo_rspec)
rspec = "<RSpec type=\"SFA\"> <network name=\"" + Config().get_interface_hrn() + "\">";
if comp_rspec != None:
rspec = rspec + get_xml_by_tag(output, 'computeResource')
from copy import copy
from lxml import etree
-from sfa.util.sfalogging import sfa_logger
+from sfa.util.sfalogging import logger
from sfa.util.rspecHelper import merge_rspecs
from sfa.util.xrn import Xrn, urn_to_hrn, hrn_to_urn
from sfa.util.plxrn import hrn_to_pl_slicename
try:
return server.url
except:
- sfa_logger().warning("GetVersion, falling back to xmlrpclib.ServerProxy internals")
+ logger.warning("GetVersion, falling back to xmlrpclib.ServerProxy internals")
return server._ServerProxy__host + server._ServerProxy__handler
def GetVersion(api):
from sfa.util.faults import *
from sfa.util.api import *
from sfa.util.config import *
-from sfa.util.sfalogging import sfa_logger
+from sfa.util.sfalogging import logger
import sfa.util.xmlrpcprotocol as xmlrpcprotocol
from sfa.trust.auth import Auth
from sfa.trust.rights import Right, Rights, determine_rights
self.hrn = self.config.SFA_INTERFACE_HRN
self.time_format = "%Y-%m-%d %H:%M:%S"
- self.logger=sfa_logger()
def getPLCShell(self):
self.plauth = {'Username': self.config.SFA_PLC_USER,
# fill in key info
if record['type'] == 'user':
if 'key_ids' not in record:
- self.logger.info("user record has no 'key_ids' - need to import from myplc ?")
+ logger.info("user record has no 'key_ids' - need to import from myplc ?")
else:
pubkeys = [keys[key_id]['key'] for key_id in record['key_ids'] if key_id in keys]
record['keys'] = pubkeys
from xmlbuilder import XMLBuilder
from sfa.util.faults import *
-#from sfa.util.sfalogging import sfa_logger
from sfa.util.xrn import get_authority
from sfa.util.plxrn import hrn_to_pl_slicename, hostname_to_urn
from sfa.trust.hierarchy import *
from sfa.util.xrn import Xrn
from sfa.plc.api import *
+from sfa.util.sfalogging import logger
from sfa.trust.gid import create_uuid
from sfa.plc.sfaImport import sfaImport
# start importing
for site in sites:
site_hrn = interface_hrn + "." + site['login_base']
- sfa_logger().info("Importing site: %s" % site_hrn)
+ logger.info("Importing site: %s" % site_hrn)
# import if hrn is not in list of existing hrns or if the hrn exists
# but its not a site record
from sfa.trust.hierarchy import *
from sfa.util.record import *
from sfa.util.table import SfaTable
-from sfa.util.sfalogging import sfa_logger_goes_to_import,sfa_logger
+from sfa.util.sfalogging import logger
def main():
usage="%prog: trash the registry DB (the 'sfa' table in the 'planetlab5' database)"
if args:
parser.print_help()
sys.exit(1)
- sfa_logger_goes_to_import()
- sfa_logger().info("Purging SFA records from database")
+ logger.info("Purging SFA records from database")
table = SfaTable()
table.sfa_records_purge()
if options.clean_fs:
path=dir+os.sep+file
os.unlink(path)
if not os.path.exists(path):
- sfa_logger().info("Unlinked file %s"%path)
+ logger.info("Unlinked file %s"%path)
else:
- sfa_logger().error("Could not unlink file %s"%path)
+ logger.error("Could not unlink file %s"%path)
if __name__ == "__main__":
main()
import sys
import tempfile
-from sfa.util.sfalogging import sfa_logger_goes_to_import,sfa_logger
+from sfa.util.sfalogging import _SfaLogger
from sfa.util.record import *
from sfa.util.table import SfaTable
class sfaImport:
def __init__(self):
- sfa_logger_goes_to_import()
- self.logger = sfa_logger()
+ self.logger = _SfaLogger(logfile='/var/log/sfa_import.log', loggername='importlog')
self.AuthHierarchy = Hierarchy()
self.config = Config()
self.TrustedRoots = TrustedRootList(Config.get_trustedroots_dir(self.config))
#!/usr/bin/python
-from sfa.util.sfalogging import _SfaLogger
+from sfa.util.sfalogging import logger
class RSpecVersion(dict):
}
def __init__(self, version={}):
- self.logger = _SfaLogger('/var/log/sfa.log')
dict.__init__(self, self.fields)
if not version:
import traceback
import os.path
-from sfa.util.sfalogging import sfa_logger
from sfa.util.faults import *
from sfa.util.storage import XmlStorage
from sfa.util.xrn import get_authority, hrn_to_urn
from mod_python import apache
from sfa.plc.api import SfaAPI
-from sfa.util.sfalogging import sfa_logger
+from sfa.util.sfalogging import logger
api = SfaAPI(interface='aggregate')
except Exception, err:
# Log error in /var/log/httpd/(ssl_)?error_log
- sfa_logger().log_exc('%r'%err)
+ logger.log_exc('%r'%err)
return apache.HTTP_INTERNAL_SERVER_ERROR
from mod_python import apache
from sfa.plc.api import SfaAPI
-from sfa.util.sfalogging import sfa_logger
+from sfa.util.sfalogging import logger
api = SfaAPI(interface='registry')
except Exception, err:
# Log error in /var/log/httpd/(ssl_)?error_log
- sfa_logger().log_exc('%r'%err)
+ logger.log_exc('%r'%err)
return apache.HTTP_INTERNAL_SERVER_ERROR
from mod_python import apache
from sfa.plc.api import SfaAPI
-from sfa.util.sfalogging import sfa_logger
+from sfa.util.sfalogging import logger
api = SfaAPI(interface='slicemgr')
except Exception, err:
# Log error in /var/log/httpd/(ssl_)?error_log
- sfa_logger().log_exc('%r'%err)
+ logger.log_exc('%r'%err)
return apache.HTTP_INTERNAL_SERVER_ERROR
import sys
from optparse import OptionParser
-from sfa.util.sfalogging import sfa_logger
+from sfa.util.sfalogging import logger
from sfa.trust.trustedroot import TrustedRootList
from sfa.trust.certificate import Keypair, Certificate
from sfa.trust.hierarchy import Hierarchy
from sfa.server.registry import Registries
from sfa.server.aggregate import Aggregates
+
# after http://www.erlenstar.demon.co.uk/unix/faq_2.html
def daemon():
"""Daemonize the current process."""
if not os.path.exists(key_file):
# if it doesnt exist then this is probably a fresh interface
# with no records. Generate a random keypair for now
- sfa_logger().debug("server's public key not found in %s" % key_file)
- sfa_logger().debug("generating a random server key pair")
+ logger.debug("server's public key not found in %s" % key_file)
+
+ logger.debug("generating a random server key pair")
key = Keypair(create=True)
key.save_to_file(server_key_file)
init_server_cert(hrn, key, server_cert_file, self_signed=True)
else:
try:
# look for gid file
- sfa_logger().debug("generating server cert from gid: %s"% hrn)
+ logger.debug("generating server cert from gid: %s"% hrn)
hierarchy = Hierarchy()
auth_info = hierarchy.get_auth_info(hrn)
gid = GID(filename=auth_info.gid_filename)
gid.save_to_file(filename=server_cert_file)
except:
# fall back to self signed cert
- sfa_logger().debug("gid for %s not found" % hrn)
+ logger.debug("gid for %s not found" % hrn)
init_self_signed_cert(hrn, key, server_cert_file)
def init_self_signed_cert(hrn, key, server_cert_file):
- sfa_logger().debug("generating self signed cert")
+ logger.debug("generating self signed cert")
# generate self signed certificate
cert = Certificate(subject=hrn)
cert.set_issuer(key=key, subject=hrn)
parser.add_option("-d", "--daemon", dest="daemon", action="store_true",
help="Run as daemon.", default=False)
(options, args) = parser.parse_args()
- sfa_logger().setLevelFromOptVerbose(options.verbose)
config = Config()
- if config.SFA_API_DEBUG: sfa_logger().setLevelDebug()
+ if config.SFA_API_DEBUG: pass
hierarchy = Hierarchy()
server_key_file = os.path.join(hierarchy.basedir, "server.key")
server_cert_file = os.path.join(hierarchy.basedir, "server.cert")
try:
main()
except:
- sfa_logger().log_exc_critical("SFA server is exiting")
+ logger.log_exc_critical("SFA server is exiting")
from sfa.util.xrn import get_authority
from sfa.util.sfaticket import *
-from sfa.util.sfalogging import sfa_logger
+from sfa.util.sfalogging import logger
class Auth:
"""
valid = []
if not isinstance(creds, list):
creds = [creds]
- sfa_logger().debug("Auth.checkCredentials with %d creds"%len(creds))
+ logger.debug("Auth.checkCredentials with %d creds"%len(creds))
for cred in creds:
try:
self.check(cred, operation, hrn)
valid.append(cred)
except:
cred_obj=Credential(string=cred)
- sfa_logger().debug("failed to validate credential - dump=%s"%cred_obj.dump_string(dump_parents=True))
+ logger.debug("failed to validate credential - dump=%s"%cred_obj.dump_string(dump_parents=True))
error = sys.exc_info()[:2]
continue
import M2Crypto
from M2Crypto import X509
-from sfa.util.sfalogging import sfa_logger
+from sfa.util.sfalogging import logger
from sfa.util.xrn import urn_to_hrn
from sfa.util.faults import *
+from sfa.util.sfalogging import logger
glo_passphrase_callback = None
try:
k.load_pubkey_from_file(ssl_fn)
except:
- sfa_logger().log_exc("convert_public_key caught exception")
+ logger.log_exc("convert_public_key caught exception")
k = None
# remove the temporary files
if intermediate:
self.set_intermediate_ca(intermediate)
- ##
# Create a blank X509 certificate and store it in this object.
def create(self):
# Sign the certificate using the issuer private key and issuer subject previous set with set_issuer().
def sign(self):
- sfa_logger().debug('certificate.sign')
+ logger.debug('certificate.sign')
assert self.cert != None
assert self.issuerSubject != None
assert self.issuerKey != None
# verify expiration time
if self.cert.has_expired():
- sfa_logger().debug("verify_chain: NO our certificate has expired")
+ logger.debug("verify_chain: NO our certificate has expired")
raise CertExpired(self.get_subject(), "client cert")
# if this cert is signed by a trusted_cert, then we are set
if self.is_signed_by_cert(trusted_cert):
# verify expiration of trusted_cert ?
if not trusted_cert.cert.has_expired():
- sfa_logger().debug("verify_chain: YES cert %s signed by trusted cert %s"%(
+ logger.debug("verify_chain: YES cert %s signed by trusted cert %s"%(
self.get_subject(), trusted_cert.get_subject()))
return trusted_cert
else:
- sfa_logger().debug("verify_chain: NO cert %s is signed by trusted_cert %s, but this is expired..."%(
+ logger.debug("verify_chain: NO cert %s is signed by trusted_cert %s, but this is expired..."%(
self.get_subject(),trusted_cert.get_subject()))
raise CertExpired(self.get_subject(),"trusted_cert %s"%trusted_cert.get_subject())
# if there is no parent, then no way to verify the chain
if not self.parent:
- sfa_logger().debug("verify_chain: NO %s has no parent and is not in trusted roots"%self.get_subject())
+ logger.debug("verify_chain: NO %s has no parent and is not in trusted roots"%self.get_subject())
raise CertMissingParent(self.get_subject())
# if it wasn't signed by the parent...
if not self.is_signed_by_cert(self.parent):
- sfa_logger().debug("verify_chain: NO %s is not signed by parent"%self.get_subject())
+ logger.debug("verify_chain: NO %s is not signed by parent"%self.get_subject())
return CertNotSignedByParent(self.get_subject())
# if the parent isn't verified...
- sfa_logger().debug("verify_chain: .. %s, -> verifying parent %s"%(self.get_subject(),self.parent.get_subject()))
+ logger.debug("verify_chain: .. %s, -> verifying parent %s"%(self.get_subject(),self.parent.get_subject()))
self.parent.verify_chain(trusted_certs)
return
triples=[]
m2x509 = X509.load_cert_string(self.save_to_string())
nb_extensions=m2x509.get_ext_count()
- sfa_logger().debug("X509 had %d extensions"%nb_extensions)
+ logger.debug("X509 had %d extensions"%nb_extensions)
for i in range(nb_extensions):
ext=m2x509.get_ext_at(i)
triples.append( (ext.get_name(), ext.get_value(), ext.get_critical(),) )
from lxml import etree
from sfa.util.faults import *
-from sfa.util.sfalogging import sfa_logger
+from sfa.util.sfalogging import logger
from sfa.trust.certificate import Keypair
from sfa.trust.credential_legacy import CredentialLegacy
from sfa.trust.rights import Right, Rights
trusted_cert_objects.append(GID(filename=f))
ok_trusted_certs.append(f)
except Exception, exc:
- sfa_logger().error("Failed to load trusted cert from %s: %r"%( f, exc))
+ logger.error("Failed to load trusted cert from %s: %r"%( f, exc))
trusted_certs = ok_trusted_certs
# Use legacy verification if this is a legacy credential
# Maybe should be (hrn, type) = urn_to_hrn(root_cred_signer.get_urn())
root_cred_signer_type = root_cred_signer.get_type()
if (root_cred_signer_type == 'authority'):
- #sfa_logger().debug('Cred signer is an authority')
+ #logger.debug('Cred signer is an authority')
# signer is an authority, see if target is in authority's domain
hrn = root_cred_signer.get_hrn()
if root_target_gid.get_hrn().startswith(hrn):
import xmlrpclib
import uuid
-from sfa.util.sfalogging import sfa_logger
+from sfa.util.sfalogging import logger
from sfa.trust.certificate import Certificate
from sfa.util.xrn import hrn_to_urn, urn_to_hrn
Certificate.__init__(self, create, subject, string, filename)
if subject:
- sfa_logger().debug("Creating GID for subject: %s" % subject)
+ logger.debug("Creating GID for subject: %s" % subject)
if uuid:
self.uuid = int(uuid)
if hrn:
import os
from sfa.util.faults import *
-from sfa.util.sfalogging import sfa_logger
+from sfa.util.sfalogging import logger
from sfa.util.xrn import get_leaf, get_authority, hrn_to_urn, urn_to_hrn
from sfa.trust.certificate import Keypair
from sfa.trust.credential import Credential
gid_filename = None
privkey_filename = None
dbinfo_filename = None
-
##
# Initialize and authority object.
#
def create_auth(self, xrn, create_parents=False):
hrn, type = urn_to_hrn(xrn)
- sfa_logger().debug("Hierarchy: creating authority: %s"% hrn)
+ logger.debug("Hierarchy: creating authority: %s"% hrn)
# create the parent authority if necessary
parent_hrn = get_authority(hrn)
pass
if os.path.exists(privkey_filename):
- sfa_logger().debug("using existing key %r for authority %r"%(privkey_filename,hrn))
+ logger.debug("using existing key %r for authority %r"%(privkey_filename,hrn))
pkey = Keypair(filename = privkey_filename)
else:
pkey = Keypair(create = True)
def get_auth_info(self, xrn):
hrn, type = urn_to_hrn(xrn)
if not self.auth_exists(hrn):
- sfa_logger().warning("Hierarchy: mising authority - xrn=%s, hrn=%s"%(xrn,hrn))
+ logger.warning("Hierarchy: mising authority - xrn=%s, hrn=%s"%(xrn,hrn))
raise MissingAuthority(hrn)
(directory, gid_filename, privkey_filename, dbinfo_filename) = \
except: print >> sys.stderr, "WARNING, could not import pgdb"
from sfa.util.faults import *
-from sfa.util.sfalogging import sfa_logger
+from sfa.util.sfalogging import logger
if not psycopg2:
is8bit = re.compile("[\x80-\xff]").search
if not params:
if self.debug:
- sfa_logger().debug('execute0 %r'%query)
+ logger.debug('execute0 %r'%query)
cursor.execute(query)
elif isinstance(params,dict):
if self.debug:
- sfa_logger().debug('execute-dict: params=[%r] query=[%r]'%(params,query%params))
+ logger.debug('execute-dict: params=[%r] query=[%r]'%(params,query%params))
cursor.execute(query,params)
elif isinstance(params,tuple) and len(params)==1:
if self.debug:
- sfa_logger().debug('execute-tuple %r'%(query%params[0]))
+ logger.debug('execute-tuple %r'%(query%params[0]))
cursor.execute(query,params[0])
else:
param_seq=(params,)
if self.debug:
for params in param_seq:
- sfa_logger().debug('executemany %r'%(query%params))
+ logger.debug('executemany %r'%(query%params))
cursor.executemany(query, param_seq)
(self.rowcount, self.description, self.lastrowid) = \
(cursor.rowcount, cursor.description, cursor.lastrowid)
except:
pass
uuid = commands.getoutput("uuidgen")
- sfa_logger().error("Database error %s:" % uuid)
- sfa_logger().error("Exception=%r"%e)
- sfa_logger().error("Query=%r"%query)
- sfa_logger().error("Params=%r"%pformat(params))
- sfa_logger().log_exc("PostgreSQL.execute caught exception")
+ logger.error("Database error %s:" % uuid)
+ logger.error("Exception=%r"%e)
+ logger.error("Query=%r"%query)
+ logger.error("Params=%r"%pformat(params))
+ logger.log_exc("PostgreSQL.execute caught exception")
raise SfaDBError("Please contact support: %s" % str(e))
return cursor
import string
import xmlrpclib
-from sfa.util.sfalogging import sfa_logger
+from sfa.util.sfalogging import logger
from sfa.trust.auth import Auth
from sfa.util.config import *
from sfa.util.faults import *
self.credential = None
self.source = None
self.time_format = "%Y-%m-%d %H:%M:%S"
- self.logger=sfa_logger
-
+ self.logger = logger
+
# load registries
from sfa.server.registry import Registries
self.registries = Registries(self)
except SfaFault, fault:
result = fault
except Exception, fault:
- sfa_logger().log_exc("BaseAPI.handle has caught Exception")
+ logger.log_exc("BaseAPI.handle has caught Exception")
result = SfaAPIError(fault)
import threading
import time
-from sfa.util.sfalogging import sfa_logger
+from sfa.util.sfalogging import logger
"""
Callids: a simple mechanism to remember the call ids served so fas
if not call_id: return False
has_lock=False
for attempt in range(_call_ids_impl.retries):
- if debug: sfa_logger().debug("Waiting for lock (%d)"%attempt)
+ if debug: logger.debug("Waiting for lock (%d)"%attempt)
if self._lock.acquire(False):
has_lock=True
- if debug: sfa_logger().debug("got lock (%d)"%attempt)
+ if debug: logger.debug("got lock (%d)"%attempt)
break
time.sleep(float(_call_ids_impl.wait_ms)/1000)
# in the unlikely event where we can't get the lock
if not has_lock:
- sfa_logger().warning("_call_ids_impl.should_handle_call_id: could not acquire lock")
+ logger.warning("_call_ids_impl.should_handle_call_id: could not acquire lock")
return False
# we're good to go
if self.has_key(call_id):
self[call_id]=time.time()
self._purge()
self._lock.release()
- if debug: sfa_logger().debug("released lock")
+ if debug: logger.debug("released lock")
return False
def _purge(self):
for (k,v) in self.iteritems():
if (now-v) >= _call_ids_impl.purge_timeout: o_keys.append(k)
for k in o_keys:
- if debug: sfa_logger().debug("Purging call_id %r (%s)"%(k,time.strftime("%H:%M:%S",time.localtime(self[k]))))
+ if debug: logger.debug("Purging call_id %r (%s)"%(k,time.strftime("%H:%M:%S",time.localtime(self[k]))))
del self[k]
if debug:
- sfa_logger().debug("AFTER PURGE")
- for (k,v) in self.iteritems(): sfa_logger().debug("%s -> %s"%(k,time.strftime("%H:%M:%S",time.localtime(v))))
+ logger.debug("AFTER PURGE")
+ for (k,v) in self.iteritems(): logger.debug("%s -> %s"%(k,time.strftime("%H:%M:%S",time.localtime(v))))
def Callids ():
if not _call_ids_impl._instance:
import SimpleXMLRPCServer
from OpenSSL import SSL
-from sfa.util.sfalogging import sfa_logger
+from sfa.util.sfalogging import logger
from sfa.trust.certificate import Keypair, Certificate
from sfa.trust.credential import *
from sfa.util.faults import *
# internal error, report as HTTP server error
self.send_response(500)
self.end_headers()
- sfa_logger().log_exc("componentserver.SecureXMLRpcRequestHandler.do_POST")
+ logger.log_exc("componentserver.SecureXMLRpcRequestHandler.do_POST")
else:
# got a valid XML RPC response
self.send_response(200)
import xmlrpclib
-from sfa.util.sfalogging import sfa_logger
+from sfa.util.sfalogging import logger
from sfa.util.faults import *
from sfa.util.parameter import Parameter, Mixed, python_type, xmlrpc_type
from sfa.trust.auth import Auth
self.type_check(name, value, expected, args)
if self.api.config.SFA_API_DEBUG:
- sfa_logger().debug("method.__call__ [%s] : BEG %s"%(self.api.interface,methodname))
+ logger.debug("method.__call__ [%s] : BEG %s"%(self.api.interface,methodname))
result = self.call(*args, **kwds)
runtime = time.time() - start
if self.api.config.SFA_API_DEBUG or hasattr(self, 'message'):
- sfa_logger().debug("method.__call__ [%s] : END %s in %02f s (%s)"%\
+ logger.debug("method.__call__ [%s] : END %s in %02f s (%s)"%\
(self.api.interface,methodname,runtime,getattr(self,'message',"[no-msg]")))
return result
# Prepend caller and method name to expected faults
fault.faultString = caller + ": " + self.name + ": " + fault.faultString
runtime = time.time() - start
- sfa_logger().log_exc("Method %s raised an exception"%self.name)
+ logger.log_exc("Method %s raised an exception"%self.name)
raise fault
from xml.dom import minidom
from lxml import etree
-from sfa.util.sfalogging import sfa_logger
+from sfa.util.sfalogging import info_logger
class RSpec:
except Exception, e:
# logging.debug("%s: web file not found" % xsdURI)
# logging.debug("Using local file %s" % self.xsd")
- sfa_logger().log_exc("rspec.parseXSD: can't find %s on the web. Continuing." % xsdURI)
+ info_logger.log_exc("rspec.parseXSD: can't find %s on the web. Continuing." % xsdURI)
if not schemaDom:
if os.path.exists(xsdURI):
# logging.debug("using local copy.")
- sfa_logger().debug("rspec.parseXSD: Using local %s" % xsdURI)
+ info_logger.debug("rspec.parseXSD: Using local %s" % xsdURI)
schemaDom = minidom.parse(xsdURI)
else:
raise Exception("rspec.parseXSD: can't find xsd locally")
from optparse import OptionParser
from sfa.util.faults import *
-from sfa.util.sfalogging import sfa_logger
+from sfa.util.sfalogging import logger
def merge_rspecs(rspecs):
"""
try:
known_networks[network.get('name')]=True
except:
- sfa_logger().error("merge_rspecs: cannot register network with no name in rspec")
+ logger.error("merge_rspecs: cannot register network with no name in rspec")
pass
def is_registered_network (network):
try:
return network.get('name') in known_networks
except:
- sfa_logger().error("merge_rspecs: cannot retrieve network with no name in rspec")
+ logger.error("merge_rspecs: cannot retrieve network with no name in rspec")
return False
# the resulting tree
tree = etree.parse(StringIO(input_rspec))
except etree.XMLSyntaxError:
# consider failing silently here
- sfa_logger().log_exc("merge_rspecs, parse error")
+ logger.log_exc("merge_rspecs, parse error")
message = str(sys.exc_info()[1]) + ' with ' + input_rspec
raise InvalidRSpec(message)
root = tree.getroot()
if not root.get("type") in ["SFA"]:
- sfa_logger().error("merge_rspecs: unexpected type for rspec root, %s"%root.get('type'))
+ logger.error("merge_rspecs: unexpected type for rspec root, %s"%root.get('type'))
continue
if rspec == None:
# we scan the first input, register all networks
from sfa.util.faults import *
from sfa.plc.api import SfaAPI
from sfa.util.cache import Cache
-from sfa.util.sfalogging import sfa_logger
+from sfa.util.sfalogging import logger
##
# Verification callback for pyOpenSSL. We do our own checking of keys because
except Exception, fault:
# This should only happen if the module is buggy
# internal error, report as HTTP server error
- sfa_logger().log_exc("server.do_POST")
+ logger.log_exc("server.do_POST")
response = self.api.prepare_response(fault)
#self.send_response(500)
#self.end_headers()
It it very similar to SimpleXMLRPCServer but it uses HTTPS for transporting XML data.
"""
- sfa_logger().debug("SecureXMLRPCServer.__init__, server_address=%s, cert_file=%s"%(server_address,cert_file))
+ logger.debug("SecureXMLRPCServer.__init__, server_address=%s, cert_file=%s"%(server_address,cert_file))
self.logRequests = logRequests
self.interface = None
self.key_file = key_file
# the client.
def _dispatch(self, method, params):
- sfa_logger().debug("SecureXMLRPCServer._dispatch, method=%s"%method)
+ logger.debug("SecureXMLRPCServer._dispatch, method=%s"%method)
try:
return SimpleXMLRPCServer.SimpleXMLRPCDispatcher._dispatch(self, method, params)
except:
self.server.interface=interface
self.trusted_cert_list = None
self.register_functions()
- sfa_logger().info("Starting SfaServer, interface=%s"%interface)
+ logger.info("Starting SfaServer, interface=%s"%interface)
##
# Register functions that will be served by the XMLRPC server. This
def __init__ (self,logfile=None,loggername=None,level=logging.INFO):
# default is to locate loggername from the logfile if avail.
if not logfile:
- loggername='console'
- handler=logging.StreamHandler()
- handler.setFormatter(logging.Formatter("%(levelname)s %(message)s"))
- else:
- if not loggername:
- loggername=os.path.basename(logfile)
- try:
- handler=logging.handlers.RotatingFileHandler(logfile,maxBytes=1000000, backupCount=5)
- except IOError:
- # This is usually a permissions error becaue the file is
- # owned by root, but httpd is trying to access it.
- tmplogfile=os.getenv("TMPDIR", "/tmp") + os.path.sep + os.path.basename(logfile)
- handler=logging.handlers.RotatingFileHandler(tmplogfile,maxBytes=1000000, backupCount=5)
- handler.setFormatter(logging.Formatter("%(asctime)s - %(levelname)s - %(message)s"))
-
+ #loggername='console'
+ #handler=logging.StreamHandler()
+ #handler.setFormatter(logging.Formatter("%(levelname)s %(message)s"))
+ logfile = "/var/log/sfa.log"
+
+ if not loggername:
+ loggername=os.path.basename(logfile)
+ try:
+ handler=logging.handlers.RotatingFileHandler(logfile,maxBytes=1000000, backupCount=5)
+ except IOError:
+ # This is usually a permissions error becaue the file is
+ # owned by root, but httpd is trying to access it.
+ tmplogfile=os.getenv("TMPDIR", "/tmp") + os.path.sep + os.path.basename(logfile)
+ handler=logging.handlers.RotatingFileHandler(tmplogfile,maxBytes=1000000, backupCount=5)
+ handler.setFormatter(logging.Formatter("%(asctime)s - %(levelname)s - %(message)s"))
self.logger=logging.getLogger(loggername)
self.logger.setLevel(level)
self.logger.addHandler(handler)
self.debug("%s BEG STACK"%message+"\n"+to_log)
self.debug("%s END STACK"%message)
-####################
-# import-related operations go in this file
-_import_logger=_SfaLogger(logfile='/var/log/sfa_import.log')
-# servers log into /var/log/sfa.log
-_server_logger=_SfaLogger(logfile='/var/log/sfa.log')
-## clients use the console
-#_console_logger=_SfaLogger()
-
-# default is to use the server-side logger
-#_the_logger=_server_logger
-
-# clients would change the default by issuing one of these call
-#def sfa_logger_goes_to_console():
-# current_module=sys.modules[globals()['__name__']]
-# current_module._the_logger=_console_logger
-#
-# clients would change the default by issuing one of these call
-#def sfa_logger_goes_to_import():
-# current_module=sys.modules[globals()['__name__']]
-# current_module._the_logger=_import_logger
-
-# this is how to retrieve the 'right' logger
-def sfa_logger():
- return _server_logger
+
+info_logger = _SfaLogger(loggername='info', level=logging.INFO)
+debug_logger = _SfaLogger(loggername='debug', level=logging.DEBUG)
+warn_logger = _SfaLogger(loggername='warning', level=logging.WARNING)
+error_logger = _SfaLogger(loggername='error', level=logging.ERROR)
+critical_logger = _SfaLogger(loggername='critical', level=logging.CRITICAL)
+logger = info_logger
########################################
import time
logger.setLevel(logging.DEBUG)
logger.debug("logger.debug again")
- #sfa_logger_goes_to_console()
- my_logger=sfa_logger()
- my_logger.info("redirected to console")
@profile(my_logger)
def sleep(seconds = 1):
import httplib
import xmlrpclib
-from sfa.util.sfalogging import sfa_logger
-
+from sfa.util.sfalogging import logger
##
# ServerException, ExceptionUnmarshaller
#
verbose = False
if options and options.debug:
verbose = True
-# sfa_logger().debug ("xmlrpcprotocol.XMLRPCServerProxy.__init__ %s (with verbose=%s)"%(url,verbose))
xmlrpclib.ServerProxy.__init__(self, url, transport, allow_none=allow_none, verbose=verbose)
def __getattr__(self, attr):
- sfa_logger().debug ("xml-rpc %s method:%s"%(self.url,attr))
+ logger.debug ("xml-rpc %s method:%s"%(self.url,attr))
return xmlrpclib.ServerProxy.__getattr__(self, attr)
import re
from sfa.util.faults import *
-from sfa.util.sfalogging import sfa_logger
# for convenience and smoother translation - we should get rid of these functions eventually
def get_leaf(hrn): return Xrn(hrn).get_leaf()
self.hrn_to_urn()
# happens all the time ..
# if not type:
-# sfa_logger().debug("type-less Xrn's are not safe")
+# debug_logger.debug("type-less Xrn's are not safe")
def get_urn(self): return self.urn
def get_hrn(self): return self.hrn