if vect in recordDict:
del recordDict[vect]
else:
- raise TypeError, "Argument error: Records are updated with \n" \
+ raise TypeError("Argument error: Records are updated with \n" \
"key=val1,val2,valN or\n" \
- "key+=val1,val2,valN \n%s Unknown key/val" % vect
+ "key+=val1,val2,valN \n%s Unknown key/val" % vect)
def replaceDict(newval, recordDict, options):
records = registry_proxy.Resolve (hrn, credential_string)
records=[record for record in records if record['type']==type]
if not records:
- raise RecordNotFound, "hrn %s (%s) unknown to registry %s"%(hrn,type,self.registry_url)
+ raise RecordNotFound("hrn %s (%s) unknown to registry %s"%(hrn,type,self.registry_url))
record=records[0]
self.plain_write (output, record['gid'])
self.logger.debug("SfaClientBootstrap: Wrote GID for %s (%s) in %s"% (hrn,type,output))
def assert_filename (self, filename, kind):
if not os.path.isfile (filename):
- raise IOError,"Missing %s file %s"%(kind,filename)
+ raise IOError("Missing %s file %s"%(kind,filename))
return True
def assert_private_key (self):
message="Could not produce/retrieve %s (%s -- %s)"%\
(filename,error[0],error[1])
self.logger.log_exc(message)
- raise Exception, message
+ raise Exception(message)
return wrapped
return wrap
def __getattr__(self, name):
def func(*args, **kwds):
if not name in DummyShell.direct_calls:
- raise Exception, "Illegal method call %s for DUMMY driver"%(name)
+ raise Exception("Illegal method call %s for DUMMY driver"%(name))
result=getattr(self.proxy, name)(*args, **kwds)
logger.debug('DummyShell %s returned ... '%(name))
return result
def __getattr__(self, name):
def func(*args, **kwds):
if name not in FdShell.direct_calls:
- raise Exception, "Illegal method call %s for FEDERICA driver"%(name)
+ raise Exception("Illegal method call %s for FEDERICA driver"%(name))
logger.info("Issuing %s args=%s kwds=%s to federica"%\
(name,args,kwds))
# result=getattr(self.proxy, "AggregateManager.%s"%name)(credential, *args, **kwds)
# that's what happens when there's something wrong with the db
# or any bad stuff of that kind at startup time
logger.log_exc("Failed to create a manager, startup sequence is broken")
- raise SfaAPIError,"Argument to ManagerWrapper must be a module or class"
+ raise SfaAPIError("Argument to ManagerWrapper must be a module or class")
self.interface = interface
def __getattr__(self, method):
for command in all_commands:
(status, output) = commands.getstatusoutput(command)
if status:
- raise Exception, output
+ raise Exception(output)
for filename in [key_filename, gid_filename]:
os.unlink(filename)
# xxx this code is quite old and has not run for ages
# it is obviously totally broken and needs a rewrite
def get_ticket (self, slice_urn, slice_hrn, creds, rspec_string, options):
- raise SfaNotImplemented,"NitosDriver.get_ticket needs a rewrite"
+ raise SfaNotImplemented("NitosDriver.get_ticket needs a rewrite")
# please keep this code for future reference
# slices = PlSlices(self)
# peer = slices.get_peer(slice_hrn)
actual_name=None
if name in NitosShell.direct_calls: actual_name=name
if not actual_name:
- raise Exception, "Illegal method call %s for NITOS driver"%(name)
+ raise Exception("Illegal method call %s for NITOS driver"%(name))
actual_name = "scheduler.server." + actual_name
result=getattr(self.proxy, actual_name)(*args, **kwds)
logger.debug('NitosShell %s (%s) returned ... '%(name,actual_name))
if name in PlShell.direct_calls: actual_name=name
if name in PlShell.alias_calls: actual_name=PlShell.alias_calls[name]
if not actual_name:
- raise Exception, "Illegal method call %s for PL driver"%(name)
+ raise Exception("Illegal method call %s for PL driver"%(name))
result=getattr(self.proxy, actual_name)(self.plauth, *args, **kwds)
logger.debug('PlShell %s (%s) returned ... '%(name,actual_name))
return result
@staticmethod
def add_portrs(xml, ports):
- raise Exception, "not implemented yet"
+ raise Exception("not implemented yet")
if not ports:
return
if not isinstance(ports, list):
@staticmethod
def add_port_attribute(xml, name, value):
- raise Exception, "not implemented yet"
+ raise Exception("not implemented yet")
elem = xml.add_element(name)
elem.set_text(value)
# Network
def get_networks(self):
- raise Exception, "Not implemented"
+ raise Exception("Not implemented")
network_elems = self.xml.xpath('//network')
networks = [network_elem.get_instance(fields=['name', 'slice']) for \
network_elem in network_elems]
def add_network(self, network):
- raise Exception, "Not implemented"
+ raise Exception("Not implemented")
network_tags = self.xml.xpath('//network[@name="%s"]' % network)
if not network_tags:
network_tag = self.xml.add_element('network', name=network)
if isinstance(value, Type):
f(*args)
return
- raise TypeError, "cannot marshal %s objects" % type(value)
+ raise TypeError("cannot marshal %s objects" % type(value))
else:
f(*args)
"""
# Look up method
if method not in self.methods:
- raise SfaInvalidAPIMethod, method
+ raise SfaInvalidAPIMethod(method)
# Get new instance of method
try:
return getattr(module, classname)(self)
except (ImportError, AttributeError):
self.logger.log_exc("Error importing method: %s" % method)
- raise SfaInvalidAPIMethod, method
+ raise SfaInvalidAPIMethod(method)
def call(self, source, method, *args):
"""
except:
pass
self.engine=None
- raise Exception,"Could not connect to database %s as %s with psycopg2"%(dbname,config.SFA_DB_USER)
+ raise Exception("Could not connect to database %s as %s with psycopg2"%(dbname,config.SFA_DB_USER))
# expects boolean True: debug is ON or False: debug is OFF
# documentation purposes.
return "mixed"
else:
- raise SfaAPIError, "XML-RPC cannot marshal %s objects" % arg_type
+ raise SfaAPIError("XML-RPC cannot marshal %s objects" % arg_type)
elif format == 'simple':
print(self.dump_simple())
else:
- raise Exception, "Invalid format %s" % format
+ raise Exception("Invalid format %s" % format)
def dump_text(self, dump_parents=False, sort=False):
print(40*'=')
def convert_public_key(key):
keyconvert_path = "/usr/bin/keyconvert.py"
if not os.path.isfile(keyconvert_path):
- raise IOError, "Could not find keyconvert in %s" % keyconvert_path
+ raise IOError("Could not find keyconvert in %s" % keyconvert_path)
# we can only convert rsa keys
if "ssh-dss" in key:
- raise Exception, "keyconvert: dss keys are not supported"
+ raise Exception("keyconvert: dss keys are not supported")
(ssh_f, ssh_fn) = tempfile.mkstemp()
ssl_fn = tempfile.mktemp()
# that it can be expected to see why it failed.
# TODO: for production, cleanup the temporary files
if not os.path.exists(ssl_fn):
- raise Exception, "keyconvert: generated certificate not found. keyconvert may have failed."
+ raise Exception("keyconvert: generated certificate not found. keyconvert may have failed.")
k = Keypair()
try:
if self.isCA != None:
# Can't double set properties
- raise Exception, "Cannot set basicConstraints CA:?? more than once. Was %s, trying to set as %s" % (self.isCA, val)
+ raise Exception("Cannot set basicConstraints CA:?? more than once. Was %s, trying to set as %s" % (self.isCA, val))
self.isCA = val
if val:
if expected_type in StringTypes:
if min is not None and \
len(value.encode(self.api.encoding)) < min:
- raise SfaInvalidArgument, "%s must be at least %d bytes long" % (name, min)
+ raise SfaInvalidArgument("%s must be at least %d bytes long" % (name, min))
if max is not None and \
len(value.encode(self.api.encoding)) > max:
- raise SfaInvalidArgument, "%s must be at most %d bytes long" % (name, max)
+ raise SfaInvalidArgument("%s must be at most %d bytes long" % (name, max))
elif expected_type in (list, tuple, set):
if min is not None and len(value) < min:
- raise SfaInvalidArgument, "%s must contain at least %d items" % (name, min)
+ raise SfaInvalidArgument("%s must contain at least %d items" % (name, min))
if max is not None and len(value) > max:
- raise SfaInvalidArgument, "%s must contain at most %d items" % (name, max)
+ raise SfaInvalidArgument("%s must contain at most %d items" % (name, max))
else:
if min is not None and value < min:
- raise SfaInvalidArgument, "%s must be > %s" % (name, str(min))
+ raise SfaInvalidArgument("%s must be > %s" % (name, str(min)))
if max is not None and value > max:
- raise SfaInvalidArgument, "%s must be < %s" % (name, str(max))
+ raise SfaInvalidArgument("%s must be < %s" % (name, str(max)))
# If a list with particular types of items is expected
if isinstance(expected, (list, tuple, set)):
db_file = open(self.db_filename, 'r')
dict.__init__(self, eval(db_file.read()))
elif os.path.exists(self.db_filename) and not os.path.isfile(self.db_filename):
- raise IOError, '%s exists but is not a file. please remove it and try again' \
- % self.db_filename
+ raise IOError('%s exists but is not a file. please remove it and try again' \
+ % self.db_filename)
else:
self.write()
self.load()
xml = XML(self.db_filename)
dict.__init__(self, xml.todict())
elif os.path.exists(self.db_filename) and not os.path.isfile(self.db_filename):
- raise IOError, '%s exists but is not a file. please remove it and try again' \
- % self.db_filename
+ raise IOError('%s exists but is not a file. please remove it and try again' \
+ % self.db_filename)
else:
self.write()
self.load()
def get_hrn_type(self): return (self.hrn, self.type)
def _normalize(self):
- if self.hrn is None: raise SfaAPIError, "Xrn._normalize"
+ if self.hrn is None: raise SfaAPIError("Xrn._normalize")
if not hasattr(self,'leaf'):
self.leaf=Xrn.hrn_split(self.hrn)[-1]
# self.authority keeps a list
# if not self.urn or not self.urn.startswith(Xrn.URN_PREFIX):
if not Xrn.is_urn(self.urn):
- raise SfaAPIError, "Xrn.urn_to_hrn"
+ raise SfaAPIError("Xrn.urn_to_hrn")
parts = Xrn.urn_split(self.urn)
type=parts.pop(2)
# if not self.hrn or self.hrn.startswith(Xrn.URN_PREFIX):
if Xrn.is_urn(self.hrn):
- raise SfaAPIError, "Xrn.hrn_to_urn, hrn=%s"%self.hrn
+ raise SfaAPIError("Xrn.hrn_to_urn, hrn=%s"%self.hrn)
if self.type and self.type.startswith('authority'):
self.authority = Xrn.hrn_auth_list(self.hrn)
if expected_type in StringTypes:
if min is not None and \
len(value.encode(self.api.encoding)) < min:
- raise SfaInvalidArgument, "%s must be at least %d bytes long" % (name, min)
+ raise SfaInvalidArgument("%s must be at least %d bytes long" % (name, min))
if max is not None and \
len(value.encode(self.api.encoding)) > max:
- raise SfaInvalidArgument, "%s must be at most %d bytes long" % (name, max)
+ raise SfaInvalidArgument("%s must be at most %d bytes long" % (name, max))
elif expected_type in (list, tuple, set):
if min is not None and len(value) < min:
- raise SfaInvalidArgument, "%s must contain at least %d items" % (name, min)
+ raise SfaInvalidArgument("%s must contain at least %d items" % (name, min))
if max is not None and len(value) > max:
- raise SfaInvalidArgument, "%s must contain at most %d items" % (name, max)
+ raise SfaInvalidArgument("%s must contain at most %d items" % (name, max))
else:
if min is not None and value < min:
- raise SfaInvalidArgument, "%s must be > %s" % (name, str(min))
+ raise SfaInvalidArgument("%s must be > %s" % (name, str(min)))
if max is not None and value > max:
- raise SfaInvalidArgument, "%s must be < %s" % (name, str(max))
+ raise SfaInvalidArgument("%s must be < %s" % (name, str(max)))
# If a list with particular types of items is expected
if isinstance(expected, (list, tuple, set)):
return "xsd:string"
else:
pdb.set_trace()
- raise SoapError, "Cannot handle %s objects" % arg_type
+ raise SoapError("Cannot handle %s objects" % arg_type)
def param_type(self, arg):
return (self.name_complex_type(arg))