From: Thierry Parmentelat Date: Wed, 26 Oct 2011 08:56:10 +0000 (+0200) Subject: reviewed imports and pylint'ed X-Git-Tag: sfa-1.1-1~34 X-Git-Url: http://git.onelab.eu/?p=sfa.git;a=commitdiff_plain;h=9ae60aed886194b9de65371a11daf748e86410b1 reviewed imports and pylint'ed --- diff --git a/sfa/managers/aggregate_manager.py b/sfa/managers/aggregate_manager.py index 7646dd33..923b94f1 100644 --- a/sfa/managers/aggregate_manager.py +++ b/sfa/managers/aggregate_manager.py @@ -1,29 +1,27 @@ import datetime import time -import traceback import sys -import re -from types import StringTypes -from sfa.util.faults import * +from sfa.util.faults import RecordNotFound, SliverDoesNotExist from sfa.util.xrn import get_authority, hrn_to_urn, urn_to_hrn, Xrn, urn_to_sliver_id -from sfa.util.plxrn import slicename_to_hrn, hrn_to_pl_slicename, hostname_to_urn -from sfa.util.record import SfaRecord -from sfa.util.policy import Policy -from sfa.util.record import * +from sfa.util.plxrn import slicename_to_hrn, hrn_to_pl_slicename +#from sfa.util.record import * +from sfa.util.version import version_core +from sfa.util.sfatime import utcparse +from sfa.util.callids import Callids + from sfa.trust.sfaticket import SfaTicket -from sfa.plc.slices import Slices from sfa.trust.credential import Credential +from sfa.rspecs.version_manager import VersionManager +from sfa.rspecs.rspec import RSpec + import sfa.plc.peers as peers -from sfa.plc.network import * from sfa.plc.api import SfaAPI from sfa.plc.aggregate import Aggregate -from sfa.plc.slices import * -from sfa.util.version import version_core -from sfa.rspecs.version_manager import VersionManager -from sfa.rspecs.rspec import RSpec -from sfa.util.sfatime import utcparse -from sfa.util.callids import Callids +from sfa.plc.slices import Slices +#unused? +#from sfa.plc.network import * +#from sfa.plc.slices import * def GetVersion(api): @@ -50,7 +48,7 @@ def __get_registry_objects(slice_xrn, creds, users): """ """ - hrn, type = urn_to_hrn(slice_xrn) + hrn, _ = urn_to_hrn(slice_xrn) hrn_auth = get_authority(hrn) @@ -114,7 +112,7 @@ def __get_hostnames(nodes): def SliverStatus(api, slice_xrn, creds, call_id): if Callids().already_handled(call_id): return {} - (hrn, type) = urn_to_hrn(slice_xrn) + (hrn, _) = urn_to_hrn(slice_xrn) # find out where this slice is currently running slicename = hrn_to_pl_slicename(hrn) @@ -127,8 +125,6 @@ def SliverStatus(api, slice_xrn, creds, call_id): nodes = api.plshell.GetNodes(api.plauth, {'node_id':slice['node_ids'],'peer_id':None}, ['node_id', 'hostname', 'site_id', 'boot_state', 'last_contact']) site_ids = [node['site_id'] for node in nodes] - sites = api.plshell.GetSites(api.plauth, site_ids, ['site_id', 'login_base']) - sites_dict = dict ( [ (site['site_id'],site['login_base'] ) for site in sites ] ) result = {} top_level_status = 'unknown' @@ -153,7 +149,7 @@ def SliverStatus(api, slice_xrn, creds, call_id): res['geni_status'] = 'ready' else: res['geni_status'] = 'failed' - top_level_staus = 'failed' + top_level_status = 'failed' res['geni_error'] = '' @@ -172,7 +168,7 @@ def CreateSliver(api, slice_xrn, creds, rspec_string, users, call_id): aggregate = Aggregate(api) slices = Slices(api) - (hrn, type) = urn_to_hrn(slice_xrn) + (hrn, _) = urn_to_hrn(slice_xrn) peer = slices.get_peer(hrn) sfa_peer = slices.get_sfa_peer(hrn) slice_record=None @@ -205,7 +201,7 @@ def CreateSliver(api, slice_xrn, creds, rspec_string, users, call_id): def RenewSliver(api, xrn, creds, expiration_time, call_id): if Callids().already_handled(call_id): return True - (hrn, type) = urn_to_hrn(xrn) + (hrn, _) = urn_to_hrn(xrn) slicename = hrn_to_pl_slicename(hrn) slices = api.plshell.GetSlices(api.plauth, {'name': slicename}, ['slice_id']) if not slices: @@ -220,7 +216,7 @@ def RenewSliver(api, xrn, creds, expiration_time, call_id): return False def start_slice(api, xrn, creds): - hrn, type = urn_to_hrn(xrn) + (hrn, _) = urn_to_hrn(xrn) slicename = hrn_to_pl_slicename(hrn) slices = api.plshell.GetSlices(api.plauth, {'name': slicename}, ['slice_id']) if not slices: @@ -234,7 +230,7 @@ def start_slice(api, xrn, creds): return 1 def stop_slice(api, xrn, creds): - hrn, type = urn_to_hrn(xrn) + hrn, _ = urn_to_hrn(xrn) slicename = hrn_to_pl_slicename(hrn) slices = api.plshell.GetSlices(api.plauth, {'name': slicename}, ['slice_id']) if not slices: @@ -244,7 +240,7 @@ def stop_slice(api, xrn, creds): if not slice_tags: api.plshell.AddSliceTag(api.plauth, slice_id, 'enabled', '0') elif slice_tags[0]['value'] != "0": - tag_id = attributes[0]['slice_tag_id'] + tag_id = slice_tags[0]['slice_tag_id'] api.plshell.UpdateSliceTag(api.plauth, tag_id, '0') return 1 @@ -254,7 +250,7 @@ def reset_slice(api, xrn): def DeleteSliver(api, xrn, creds, call_id): if Callids().already_handled(call_id): return "" - (hrn, type) = urn_to_hrn(xrn) + (hrn, _) = urn_to_hrn(xrn) slicename = hrn_to_pl_slicename(hrn) slices = api.plshell.GetSlices(api.plauth, {'name': slicename}) if not slices: @@ -298,7 +294,7 @@ def ListResources(api, creds, options, call_id): if Callids().already_handled(call_id): return "" # get slice's hrn from options xrn = options.get('geni_slice_urn', None) - (hrn, type) = urn_to_hrn(xrn) + (hrn, _) = urn_to_hrn(xrn) version_manager = VersionManager() # get the rspec's return format from options @@ -330,12 +326,14 @@ def ListResources(api, creds, options, call_id): def get_ticket(api, xrn, creds, rspec, users): - reg_objects = __get_registry_objects(xrn, creds, users) +#unused +# reg_objects = __get_registry_objects(xrn, creds, users) - slice_hrn, type = urn_to_hrn(xrn) - slices = Slices(api) - peer = slices.get_peer(slice_hrn) - sfa_peer = slices.get_sfa_peer(slice_hrn) + (slice_hrn, _) = urn_to_hrn(xrn) +#unused +# slices = Slices(api) +# peer = slices.get_peer(slice_hrn) +# sfa_peer = slices.get_sfa_peer(slice_hrn) # get the slice record registry = api.registries[api.hrn] @@ -344,16 +342,21 @@ def get_ticket(api, xrn, creds, rspec, users): # similar to CreateSliver, we must verify that the required records exist # at this aggregate before we can issue a ticket - site_id, remote_site_id = slices.verify_site(registry, credential, slice_hrn, - peer, sfa_peer, reg_objects) - slice = slices.verify_slice(registry, credential, slice_hrn, site_id, - remote_site_id, peer, sfa_peer, reg_objects) +#Error (E1121, get_ticket): Too many positional arguments for function call +#unused anyway +# site_id, remote_site_id = slices.verify_site(registry, credential, slice_hrn, +# peer, sfa_peer, reg_objects) +#Error (E1121, get_ticket): Too many positional arguments for function call +#unused anyway +# slice = slices.verify_slice(registry, credential, slice_hrn, site_id, +# remote_site_id, peer, sfa_peer, reg_objects) # make sure we get a local slice record record = None for tmp_record in records: if tmp_record['type'] == 'slice' and \ not tmp_record['peer_authority']: +#Error (E0602, get_ticket): Undefined variable 'SliceRecord' record = SliceRecord(dict=tmp_record) if not record: raise RecordNotFound(slice_hrn) @@ -389,16 +392,18 @@ def get_ticket(api, xrn, creds, rspec, users): def main(): - api = SfaAPI() """ rspec = ListResources(api, "plc.princeton.sapan", None, 'pl_test_sapan') #rspec = ListResources(api, "plc.princeton.coblitz", None, 'pl_test_coblitz') #rspec = ListResources(api, "plc.pl.sirius", None, 'pl_test_sirius') print rspec """ + api = SfaAPI() f = open(sys.argv[1]) xml = f.read() f.close() +#Error (E1120, main): No value passed for parameter 'users' in function call +#Error (E1120, main): No value passed for parameter 'call_id' in function call CreateSliver(api, "plc.princeton.sapan", xml, 'CreateSliver_sapan') if __name__ == "__main__": diff --git a/sfa/managers/registry_manager.py b/sfa/managers/registry_manager.py index 6052eee3..e4a5b172 100644 --- a/sfa/managers/registry_manager.py +++ b/sfa/managers/registry_manager.py @@ -1,18 +1,19 @@ import types import time -from sfa.util.faults import * +from sfa.util.faults import RecordNotFound, AccountNotEnabled, PermissionError, MissingAuthority, \ + UnknownSfaType, ExistingRecord from sfa.util.prefixTree import prefixTree from sfa.util.record import SfaRecord from sfa.util.table import SfaTable -from sfa.util.record import SfaRecord -from sfa.trust.gid import GID from sfa.util.xrn import Xrn, get_leaf, get_authority, hrn_to_urn, urn_to_hrn from sfa.util.plxrn import hrn_to_pl_login_base +from sfa.util.version import version_core + +from sfa.trust.gid import GID from sfa.trust.credential import Credential -from sfa.trust.certificate import Certificate, Keypair +from sfa.trust.certificate import Certificate, Keypair, convert_public_key from sfa.trust.gid import create_uuid -from sfa.util.version import version_core # The GENI GetVersion call def GetVersion(api): diff --git a/sfa/managers/slice_manager.py b/sfa/managers/slice_manager.py index 55bbe035..b84ef716 100644 --- a/sfa/managers/slice_manager.py +++ b/sfa/managers/slice_manager.py @@ -1,31 +1,23 @@ import sys -import time,datetime +import time from StringIO import StringIO -from types import StringTypes -from copy import deepcopy from copy import copy from lxml import etree -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 -from sfa.util.faults import * -from sfa.util.record import SfaRecord -from sfa.rspecs.rspec_converter import RSpecConverter -from sfa.client.client_helper import sfa_to_pg_users_arg -from sfa.rspecs.version_manager import VersionManager -from sfa.rspecs.rspec import RSpec -from sfa.util.policy import Policy -from sfa.util.prefixTree import prefixTree from sfa.trust.sfaticket import SfaTicket from sfa.trust.credential import Credential + +from sfa.util.sfalogging import logger +from sfa.util.rspecHelper import merge_rspecs +from sfa.util.xrn import Xrn, urn_to_hrn from sfa.util.threadmanager import ThreadManager -import sfa.util.xmlrpcprotocol as xmlrpcprotocol -import sfa.plc.peers as peers from sfa.util.version import version_core from sfa.util.callids import Callids +from sfa.rspecs.rspec_converter import RSpecConverter +from sfa.rspecs.version_manager import VersionManager +from sfa.rspecs.rspec import RSpec +from sfa.client.client_helper import sfa_to_pg_users_arg def _call_id_supported(api, server): """ @@ -89,7 +81,7 @@ def drop_slicemgr_stats(rspec): for node in stats_elements: node.getparent().remove(node) except Exception, e: - api.logger.warn("drop_slicemgr_stats failed: %s " % (str(e))) + logger.warn("drop_slicemgr_stats failed: %s " % (str(e))) def add_slicemgr_stat(rspec, callname, aggname, elapsed, status): try: @@ -101,7 +93,7 @@ def add_slicemgr_stat(rspec, callname, aggname, elapsed, status): etree.SubElement(stats_tag, "aggregate", name=str(aggname), elapsed=str(elapsed), status=str(status)) except Exception, e: - api.logger.warn("add_slicemgr_stat failed on %s: %s" %(aggname, str(e))) + logger.warn("add_slicemgr_stat failed on %s: %s" %(aggname, str(e))) def ListResources(api, creds, options, call_id): version_manager = VersionManager() @@ -216,9 +208,9 @@ def CreateSliver(api, xrn, creds, rspec_str, users, call_id): # The schema used here needs to aggregate the PL and VINI schemas # schema = "/var/www/html/schemas/pl.rng" rspec = RSpec(rspec_str) - schema = None - if schema: - rspec.validate(schema) +# schema = None +# if schema: +# rspec.validate(schema) # if there is a section, the aggregates don't care about it, # so delete it. @@ -537,11 +529,12 @@ def status(api, xrn, creds): """ return 1 -def main(): - r = RSpec() - r.parseFile(sys.argv[1]) - rspec = r.toDict() - CreateSliver(None,'plc.princeton.tmacktestslice',rspec,'create-slice-tmacktestslice') +# this is plain broken +#def main(): +# r = RSpec() +# r.parseFile(sys.argv[1]) +# rspec = r.toDict() +# CreateSliver(None,'plc.princeton.tmacktestslice',rspec,'create-slice-tmacktestslice') if __name__ == "__main__": main() diff --git a/sfa/util/record.py b/sfa/util/record.py index 7cfc752e..420cc6fb 100644 --- a/sfa/util/record.py +++ b/sfa/util/record.py @@ -6,9 +6,9 @@ from types import StringTypes -from sfa.trust.gid import * +from sfa.trust.gid import GID -from sfa.util.parameter import * +from sfa.util.parameter import Parameter from sfa.util.xrn import get_authority from sfa.util.row import Row from sfa.util.xml import XML