#!/usr/bin/python
+
+# pylint: disable=c0111, c0103, w0402, w0622
+
from __future__ import print_function
import os
import sys
import copy
-from pprint import pformat, PrettyPrinter
+from pprint import PrettyPrinter
from optparse import OptionParser
from sfa.generic import Generic
from sfa.trust.gid import GID
from sfa.trust.certificate import convert_public_key
-from sfa.client.common import optparse_listvalue_callback, optparse_dictvalue_callback, terminal_render, filter_records
+from sfa.client.common import (optparse_listvalue_callback,
+ optparse_dictvalue_callback,
+ terminal_render, filter_records)
from sfa.client.candidates import Candidates
from sfa.client.sfi import save_records_to_file
try:
help_basedir = Hierarchy().basedir
-except:
+except Exception:
help_basedir = '*unable to locate Hierarchy().basedir'
version = self.api.manager.GetVersion(self.api, {})
pprinter.pprint(version)
-
- @add_options('-x', '--xrn', dest='xrn', metavar='<xrn>', help='authority to list (hrn/urn - mandatory)')
- @add_options('-t', '--type', dest='type', metavar='<type>', help='object type', default='all')
- @add_options('-r', '--recursive', dest='recursive', metavar='<recursive>', help='list all child records',
+ @add_options('-x', '--xrn', dest='xrn', metavar='<xrn>',
+ help='authority to list (hrn/urn - mandatory)')
+ @add_options('-t', '--type', dest='type', metavar='<type>',
+ help='object type', default='all')
+ @add_options('-r', '--recursive', dest='recursive', metavar='<recursive>',
+ help='list all child records',
+ action='store_true', default=False)
+ @add_options('-v', '--verbose', dest='verbose',
action='store_true', default=False)
- @add_options('-v', '--verbose', dest='verbose', action='store_true', default=False)
def list(self, xrn, type=None, recursive=False, verbose=False):
- """List names registered at a given authority - possibly filtered by type"""
+ """
+ List names registered at a given authority, possibly filtered by type
+ """
xrn = Xrn(xrn, type)
options_dict = {'recursive': recursive}
records = self.api.manager.List(
list = filter_records(type, records)
# terminal_render expects an options object
- class Options:
- pass
- options = Options()
- options.verbose = verbose
- terminal_render(list, options)
+ class Options: # pylint: disable=r0903
+ def __init__(self, verbose):
+ self.verbose = verbose
+ options = Options(verbose)
+ terminal_render(list, options)
- @add_options('-x', '--xrn', dest='xrn', metavar='<xrn>', help='object hrn/urn (mandatory)')
- @add_options('-t', '--type', dest='type', metavar='<type>', help='object type', default=None)
- @add_options('-o', '--outfile', dest='outfile', metavar='<outfile>', help='save record to file')
- @add_options('-f', '--format', dest='format', metavar='<display>', type='choice',
- choices=('text', 'xml', 'simple'), help='display record in different formats')
+ @add_options('-x', '--xrn', dest='xrn', metavar='<xrn>',
+ help='object hrn/urn (mandatory)')
+ @add_options('-t', '--type', dest='type', metavar='<type>',
+ help='object type', default=None)
+ @add_options('-o', '--outfile', dest='outfile', metavar='<outfile>',
+ help='save record to file')
+ @add_options('-f', '--format', dest='format', metavar='<display>',
+ type='choice', choices=('text', 'xml', 'simple'),
+ help='display record in different formats')
def show(self, xrn, type=None, format=None, outfile=None):
"""Display details for a registered object"""
records = self.api.manager.Resolve(self.api, xrn, type, details=True)
if outfile:
save_records_to_file(outfile, records)
- def _record_dict(self, xrn, type, email, key,
+ @staticmethod
+ def _record_dict(xrn, type, email, key,
slices, researchers, pis,
url, description, extras):
record_dict = {}
record_dict.update(extras)
return record_dict
-
- @add_options('-x', '--xrn', dest='xrn', metavar='<xrn>', help='object hrn/urn', default=None)
- @add_options('-t', '--type', dest='type', metavar='<type>', help='object type (mandatory)')
- @add_options('-a', '--all', dest='all', metavar='<all>', action='store_true', default=False, help='check all users GID')
- @add_options('-v', '--verbose', dest='verbose', metavar='<verbose>', action='store_true', default=False, help='verbose mode: display user\'s hrn ')
+ @add_options('-x', '--xrn', dest='xrn', metavar='<xrn>',
+ help='object hrn/urn', default=None)
+ @add_options('-t', '--type', dest='type', metavar='<type>',
+ help='object type (mandatory)')
+ @add_options('-a', '--all', dest='all', metavar='<all>',
+ action='store_true', default=False,
+ help='check all users GID')
+ @add_options('-v', '--verbose', dest='verbose', metavar='<verbose>',
+ action='store_true', default=False,
+ help='verbose mode: display user\'s hrn ')
def check_gid(self, xrn=None, type=None, all=None, verbose=None):
"""Check the correspondance between the GID and the PubKey"""
db_pubkey_str = record.reg_keys[0].key
try:
db_pubkey_obj = convert_public_key(db_pubkey_str)
- except:
+ except Exception:
ERROR.append(record.hrn)
continue
else:
print("Users NOT having a PubKey: %s\n\
Users having a non RSA PubKey: %s\n\
Users having a GID/PubKey correpondence OK: %s\n\
-Users having a GID/PubKey correpondence Not OK: %s\n" % (len(NOKEY), len(ERROR), len(OK), len(NOK)))
+Users having a GID/PubKey correpondence Not OK: %s\n"
+ % (len(NOKEY), len(ERROR), len(OK), len(NOK)))
else:
print("Users NOT having a PubKey: %s and are: \n%s\n\n\
Users having a non RSA PubKey: %s and are: \n%s\n\n\
Users having a GID/PubKey correpondence OK: %s and are: \n%s\n\n\
-Users having a GID/PubKey correpondence NOT OK: %s and are: \n%s\n\n" % (len(NOKEY), NOKEY, len(ERROR), ERROR, len(OK), OK, len(NOK), NOK))
+Users having a GID/PubKey correpondence NOT OK: %s and are: \n%s\n\n"
+ % (len(NOKEY), NOKEY, len(ERROR), ERROR,
+ len(OK), OK, len(NOK), NOK))
- @add_options('-x', '--xrn', dest='xrn', metavar='<xrn>', help='object hrn/urn (mandatory)')
- @add_options('-t', '--type', dest='type', metavar='<type>', help='object type', default=None)
+ @add_options('-x', '--xrn', dest='xrn', metavar='<xrn>',
+ help='object hrn/urn (mandatory)')
+ @add_options('-t', '--type', dest='type', metavar='<type>',
+ help='object type', default=None)
@add_options('-e', '--email', dest='email', default="",
help="email (mandatory for users)")
@add_options('-u', '--url', dest='url', metavar='<url>', default=None,
help="URL, useful for slices")
- @add_options('-d', '--description', dest='description', metavar='<description>',
+ @add_options('-d', '--description', dest='description',
+ metavar='<description>',
help='Description, useful for slices', default=None)
- @add_options('-k', '--key', dest='key', metavar='<key>', help='public key string or file',
+ @add_options('-k', '--key', dest='key', metavar='<key>',
+ help='public key string or file',
default=None)
- @add_options('-s', '--slices', dest='slices', metavar='<slices>', help='Set/replace slice xrns',
- default='', type="str", action='callback', callback=optparse_listvalue_callback)
- @add_options('-r', '--researchers', dest='researchers', metavar='<researchers>', help='Set/replace slice researchers',
- default='', type="str", action='callback', callback=optparse_listvalue_callback)
+ @add_options('-s', '--slices', dest='slices', metavar='<slices>',
+ help='Set/replace slice xrns',
+ default='', type="str", action='callback',
+ callback=optparse_listvalue_callback)
+ @add_options('-r', '--researchers', dest='researchers',
+ metavar='<researchers>', help='Set/replace slice researchers',
+ default='', type="str", action='callback',
+ callback=optparse_listvalue_callback)
@add_options('-p', '--pis', dest='pis', metavar='<PIs>',
help='Set/replace Principal Investigators/Project Managers',
- default='', type="str", action='callback', callback=optparse_listvalue_callback)
- @add_options('-X', '--extra', dest='extras', default={}, type='str', metavar="<EXTRA_ASSIGNS>",
- action="callback", callback=optparse_dictvalue_callback, nargs=1,
- help="set extra/testbed-dependent flags, e.g. --extra enabled=true")
+ default='', type="str", action='callback',
+ callback=optparse_listvalue_callback)
+ @add_options('-X', '--extra', dest='extras',
+ default={}, type='str', metavar="<EXTRA_ASSIGNS>",
+ action="callback", callback=optparse_dictvalue_callback,
+ nargs=1,
+ help="set extra/testbed-dependent flags,"
+ " e.g. --extra enabled=true")
def register(self, xrn, type=None, email='', key=None,
slices='', pis='', researchers='',
url=None, description=None, extras={}):
"""Create a new Registry record"""
- record_dict = self._record_dict(xrn=xrn, type=type, email=email, key=key,
- slices=slices, researchers=researchers, pis=pis,
- url=url, description=description, extras=extras)
+ record_dict = self._record_dict(
+ xrn=xrn, type=type, email=email, key=key,
+ slices=slices, researchers=researchers, pis=pis,
+ url=url, description=description, extras=extras)
self.api.manager.Register(self.api, record_dict)
-
- @add_options('-x', '--xrn', dest='xrn', metavar='<xrn>', help='object hrn/urn (mandatory)')
- @add_options('-t', '--type', dest='type', metavar='<type>', help='object type', default=None)
- @add_options('-u', '--url', dest='url', metavar='<url>', help='URL', default=None)
- @add_options('-d', '--description', dest='description', metavar='<description>',
+ @add_options('-x', '--xrn', dest='xrn', metavar='<xrn>',
+ help='object hrn/urn (mandatory)')
+ @add_options('-t', '--type', dest='type', metavar='<type>',
+ help='object type', default=None)
+ @add_options('-u', '--url', dest='url', metavar='<url>',
+ help='URL', default=None)
+ @add_options('-d', '--description', dest='description',
+ metavar='<description>',
help='Description', default=None)
- @add_options('-k', '--key', dest='key', metavar='<key>', help='public key string or file',
+ @add_options('-k', '--key', dest='key', metavar='<key>',
+ help='public key string or file',
default=None)
- @add_options('-s', '--slices', dest='slices', metavar='<slices>', help='Set/replace slice xrns',
- default='', type="str", action='callback', callback=optparse_listvalue_callback)
- @add_options('-r', '--researchers', dest='researchers', metavar='<researchers>', help='Set/replace slice researchers',
- default='', type="str", action='callback', callback=optparse_listvalue_callback)
+ @add_options('-s', '--slices', dest='slices', metavar='<slices>',
+ help='Set/replace slice xrns',
+ default='', type="str", action='callback',
+ callback=optparse_listvalue_callback)
+ @add_options('-r', '--researchers', dest='researchers',
+ metavar='<researchers>', help='Set/replace slice researchers',
+ default='', type="str", action='callback',
+ callback=optparse_listvalue_callback)
@add_options('-p', '--pis', dest='pis', metavar='<PIs>',
help='Set/replace Principal Investigators/Project Managers',
- default='', type="str", action='callback', callback=optparse_listvalue_callback)
- @add_options('-X', '--extra', dest='extras', default={}, type='str', metavar="<EXTRA_ASSIGNS>",
- action="callback", callback=optparse_dictvalue_callback, nargs=1,
- help="set extra/testbed-dependent flags, e.g. --extra enabled=true")
+ default='', type="str", action='callback',
+ callback=optparse_listvalue_callback)
+ @add_options('-X', '--extra', dest='extras', default={}, type='str',
+ metavar="<EXTRA_ASSIGNS>", nargs=1,
+ action="callback", callback=optparse_dictvalue_callback,
+ help="set extra/testbed-dependent flags,"
+ " e.g. --extra enabled=true")
def update(self, xrn, type=None, email='', key=None,
slices='', pis='', researchers='',
url=None, description=None, extras={}):
"""Update an existing Registry record"""
- record_dict = self._record_dict(xrn=xrn, type=type, email=email, key=key,
- slices=slices, researchers=researchers, pis=pis,
- url=url, description=description, extras=extras)
+ record_dict = self._record_dict(
+ xrn=xrn, type=type, email=email, key=key,
+ slices=slices, researchers=researchers, pis=pis,
+ url=url, description=description, extras=extras)
self.api.manager.Update(self.api, record_dict)
-
- @add_options('-x', '--xrn', dest='xrn', metavar='<xrn>', help='object hrn/urn (mandatory)')
- @add_options('-t', '--type', dest='type', metavar='<type>', help='object type', default=None)
+ @add_options('-x', '--xrn', dest='xrn', metavar='<xrn>',
+ help='object hrn/urn (mandatory)')
+ @add_options('-t', '--type', dest='type', metavar='<type>',
+ help='object type', default=None)
def remove(self, xrn, type=None):
"""Remove given object from the registry"""
xrn = Xrn(xrn, type)
self.api.manager.Remove(self.api, xrn)
-
- @add_options('-x', '--xrn', dest='xrn', metavar='<xrn>', help='object hrn/urn (mandatory)')
- @add_options('-t', '--type', dest='type', metavar='<type>', help='object type', default=None)
+ @add_options('-x', '--xrn', dest='xrn', metavar='<xrn>',
+ help='object hrn/urn (mandatory)')
+ @add_options('-t', '--type', dest='type', metavar='<type>',
+ help='object type', default=None)
def credential(self, xrn, type=None):
"""Invoke GetCredential"""
cred = self.api.manager.GetCredential(
dbschema.init_or_upgrade()
- @add_options('-a', '--all', dest='all', metavar='<all>', action='store_true', default=False,
- help='Remove all registry records and all files in %s area' % help_basedir)
- @add_options('-c', '--certs', dest='certs', metavar='<certs>', action='store_true', default=False,
- help='Remove all cached certs/gids found in %s' % help_basedir)
- @add_options('-0', '--no-reinit', dest='reinit', metavar='<reinit>', action='store_false', default=True,
- help='Prevents new DB schema from being installed after cleanup')
+ @add_options('-a', '--all', dest='all', metavar='<all>',
+ action='store_true', default=False,
+ help='Remove all registry records and all files in %s area'
+ % help_basedir)
+ @add_options('-c', '--certs', dest='certs',
+ metavar='<certs>', action='store_true', default=False,
+ help='Remove all cached certs/gids found in %s'
+ % help_basedir)
+ @add_options('-0', '--no-reinit', dest='reinit', metavar='<reinit>',
+ action='store_false', default=True,
+ help="Prevents new DB schema"
+ " from being installed after cleanup")
def nuke(self, all=False, certs=False, reinit=True):
- """Cleanup local registry DB, plus various additional filesystem cleanups optionally"""
+ """
+ Cleanup local registry DB, plus various additional
+ filesystem cleanups optionally
+ """
from sfa.storage.dbschema import DBSchema
from sfa.util.sfalogging import _SfaLogger
logger = _SfaLogger(
dbschema = DBSchema()
dbschema.nuke()
- # for convenience we re-create the schema here, so there's no need for an explicit
+ # for convenience we re-create the schema here,
+ # so there's no need for an explicit
# service sfa restart
# however in some (upgrade) scenarios this might be wrong
if reinit:
def import_gid(self, xrn):
pass
- @add_options('-x', '--xrn', dest='xrn', metavar='<xrn>', help='object hrn/urn (mandatory)')
- @add_options('-t', '--type', dest='type', metavar='<type>', help='object type', default=None)
- @add_options('-o', '--outfile', dest='outfile', metavar='<outfile>', help='output file', default=None)
+ @add_options('-x', '--xrn', dest='xrn', metavar='<xrn>',
+ help='object hrn/urn (mandatory)')
+ @add_options('-t', '--type', dest='type', metavar='<type>',
+ help='object type', default=None)
+ @add_options('-o', '--outfile', dest='outfile', metavar='<outfile>',
+ help='output file', default=None)
def export(self, xrn, type=None, outfile=None):
"""Fetch an object's GID from the Registry"""
from sfa.storage.model import RegRecord
try:
auth_info = hierarchy.get_auth_info(hrn)
gid = auth_info.gid_object
- except:
+ except Exception:
print("Record: %s not found" % hrn)
sys.exit(1)
# save to file
outfile = os.path.abspath('./%s.gid' % gid.get_hrn())
gid.save_to_file(outfile, save_parents=True)
- @add_options('-g', '--gidfile', dest='gid', metavar='<gid>', help='path of gid file to display (mandatory)')
+ @add_options('-g', '--gidfile', dest='gid', metavar='<gid>',
+ help='path of gid file to display (mandatory)')
def display(self, gidfile):
"""Print contents of a GID file"""
gid_path = os.path.abspath(gidfile)
version = self.api.manager.GetVersion(self.api, {})
pprinter.pprint(version)
- @add_options('-x', '--xrn', dest='xrn', metavar='<xrn>', help='object hrn/urn (mandatory)')
+ @add_options('-x', '--xrn', dest='xrn', metavar='<xrn>',
+ help='object hrn/urn (mandatory)')
def status(self, xrn):
- """Retrieve the status of the slivers belonging to the named slice (Status)"""
+ """
+ Retrieve the status of the slivers
+ belonging to the named slice (Status)
+ """
urns = [Xrn(xrn, 'slice').get_urn()]
status = self.api.manager.Status(self.api, urns, [], {})
pprinter.pprint(status)
- @add_options('-r', '--rspec-version', dest='rspec_version', metavar='<rspec_version>',
- default='GENI', help='version/format of the resulting rspec response')
+ @add_options('-r', '--rspec-version', dest='rspec_version',
+ metavar='<rspec_version>', default='GENI',
+ help='version/format of the resulting rspec response')
def resources(self, rspec_version='GENI'):
"""Display the available resources at an aggregate"""
options = {'geni_rspec_version': rspec_version}
resources = self.api.manager.ListResources(self.api, [], options)
print(resources)
- @add_options('-x', '--xrn', dest='xrn', metavar='<xrn>', help='slice hrn/urn (mandatory)')
- @add_options('-r', '--rspec', dest='rspec', metavar='<rspec>', help='rspec file (mandatory)')
+ @add_options('-x', '--xrn', dest='xrn', metavar='<xrn>',
+ help='slice hrn/urn (mandatory)')
+ @add_options('-r', '--rspec', dest='rspec', metavar='<rspec>',
+ help='rspec file (mandatory)')
def allocate(self, xrn, rspec):
"""Allocate slivers"""
xrn = Xrn(xrn, 'slice')
self.api, slice_urn, [], rspec_string, options)
print(manifest)
- @add_options('-x', '--xrn', dest='xrn', metavar='<xrn>', help='slice hrn/urn (mandatory)')
+ @add_options('-x', '--xrn', dest='xrn', metavar='<xrn>',
+ help='slice hrn/urn (mandatory)')
def provision(self, xrn):
"""Provision slivers"""
xrn = Xrn(xrn, 'slice')
self.api, [slice_urn], [], options)
print(manifest)
- @add_options('-x', '--xrn', dest='xrn', metavar='<xrn>', help='slice hrn/urn (mandatory)')
+ @add_options('-x', '--xrn', dest='xrn', metavar='<xrn>',
+ help='slice hrn/urn (mandatory)')
def delete(self, xrn):
"""Delete slivers"""
self.api.manager.Delete(self.api, [xrn], [], {})
if name.startswith('_'):
continue
margin = 15
- format = "%%-%ds" % margin
print("%-15s" % name, end=' ')
doc = getattr(method, '__doc__', None)
if not doc:
sys.exit(0)
except TypeError:
print("Possible wrong number of arguments supplied")
- #import traceback
- # traceback.print_exc()
print(command.__doc__)
parser.print_help()
sys.exit(1)
from sfa.rspecs.rspec import RSpec
from sfa.planetlab.vlink import VLink
from sfa.planetlab.topology import Topology
-from sfa.planetlab.plxrn import PlXrn, hrn_to_pl_slicename, xrn_to_hostname, top_auth, hash_loginbase
+from sfa.planetlab.plxrn import (PlXrn, hrn_to_pl_slicename, xrn_to_hostname,
+ top_auth, hash_loginbase)
from sfa.storage.model import SliverAllocation
MAXINT = 2L**31 - 1
person_ids = list(person_ids)
all_slice_tag_ids = list(all_slice_tag_ids)
# Get user information
- all_persons_list = self.driver.shell.GetPersons({'person_id': person_ids, 'enabled': True},
- ['person_id', 'enabled', 'key_ids'])
+ all_persons_list = self.driver.shell.GetPersons(
+ {'person_id': person_ids, 'enabled': True},
+ ['person_id', 'enabled', 'key_ids'])
all_persons = {}
for person in all_persons_list:
all_persons[person['person_id']] = person
sliver_attributes = []
if node is not None:
- for sliver_attribute in filter(lambda a: a['node_id'] == node['node_id'], slice_tags):
+ for sliver_attribute in filter(
+ lambda a: a['node_id'] == node['node_id'],
+ slice_tags):
sliver_attributes.append(sliver_attribute['tagname'])
attributes.append({'tagname': sliver_attribute['tagname'],
'value': sliver_attribute['value']})
# set nodegroup slice attributes
- for slice_tag in filter(lambda a: a['nodegroup_id'] in node['nodegroup_ids'], slice_tags):
+ for slice_tag in filter(
+ lambda a: a['nodegroup_id'] in node['nodegroup_ids'],
+ slice_tags):
# Do not set any nodegroup slice attributes for
# which there is at least one sliver attribute
# already set.
attributes.append({'tagname': slice_tag['tagname'],
'value': slice_tag['value']})
- for slice_tag in filter(lambda a: a['node_id'] is None, slice_tags):
+ for slice_tag in filter(
+ lambda a: a['node_id'] is None,
+ slice_tags):
# Do not set any global slice attributes for
# which there is at least one sliver attribute
# already set.
def verify_slice_leases(self, slice, rspec_requested_leases):
- leases = self.driver.shell.GetLeases({'name': slice['name'], 'clip': int(time.time())},
- ['lease_id', 'name', 'hostname', 't_from', 't_until'])
+ leases = self.driver.shell.GetLeases(
+ {'name': slice['name'], 'clip': int(time.time())},
+ ['lease_id', 'name', 'hostname', 't_from', 't_until'])
grain = self.driver.shell.GetLeaseGranularity()
requested_leases = []
if slice_name != slice['name']:
continue
- elif Xrn(lease['component_id']).get_authority_urn().split(':')[0] != self.driver.hrn:
+ elif (Xrn(lease['component_id']).get_authority_urn().split(':')[0]
+ != self.driver.hrn):
continue
hostname = xrn_to_hostname(lease['component_id'])
# prepare actual slice leases by lease_id
leases_by_id = {}
for lease in leases:
- leases_by_id[lease['lease_id']] = {'name': lease['name'], 'hostname': lease['hostname'],
- 't_from': lease['t_from'], 't_until': lease['t_until']}
+ leases_by_id[lease['lease_id']] = {
+ 'name': lease['name'], 'hostname': lease['hostname'],
+ 't_from': lease['t_from'], 't_until': lease['t_until']}
added_leases = []
kept_leases_id = []
try:
self.driver.shell.DeleteLeases(deleted_leases_id)
for lease in added_leases:
- self.driver.shell.AddLeases(lease['hostname'], slice['name'], lease[
- 't_from'], lease['t_until'])
+ self.driver.shell.AddLeases(
+ lease['hostname'], slice['name'],
+ lease['t_from'], lease['t_until'])
- except:
+ except Exception:
logger.log_exc('Failed to add/remove slice leases')
return leases
self.driver.shell.DeleteSliceFromNodes(
slice['name'], deleted_nodes)
- except:
+ except Exception:
logger.log_exc('Failed to add/remove slice from nodes')
slices = self.driver.shell.GetSlices(slice['name'], ['node_ids'])
self.verify_slice_tags(slice, slice_tags, {
'pltags': 'append'}, admin=True)
- def verify_site(self, slice_xrn, slice_record=None, sfa_peer=None, options=None):
+ def verify_site(self, slice_xrn,
+ slice_record=None, sfa_peer=None, options=None):
if slice_record is None:
slice_record = {}
if options is None:
login_base = hash_loginbase(site_hrn)
# filter sites by hrn
- sites = self.driver.shell.GetSites({'peer_id': None, 'hrn': site_hrn},
- ['site_id', 'name', 'abbreviated_name', 'login_base', 'hrn'])
+ sites = self.driver.shell.GetSites(
+ {'peer_id': None, 'hrn': site_hrn},
+ ['site_id', 'name', 'abbreviated_name', 'login_base', 'hrn'])
# alredy exists
if sites:
return site
- def verify_slice(self, slice_hrn, slice_record, sfa_peer, expiration, options=None):
+ def verify_slice(self, slice_hrn, slice_record,
+ sfa_peer, expiration, options=None):
if options is None:
options = {}
top_auth_hrn = top_auth(slice_hrn)
expires = int(datetime_to_epoch(utcparse(expiration)))
# Filter slices by HRN
- slices = self.driver.shell.GetSlices({'peer_id': None, 'hrn': slice_hrn},
- ['slice_id', 'name', 'hrn', 'expires'])
+ slices = self.driver.shell.GetSlices(
+ {'peer_id': None, 'hrn': slice_hrn},
+ ['slice_id', 'name', 'hrn', 'expires'])
if slices:
slice = slices[0]
return person_id
- def verify_persons(self, slice_hrn, slice_record, users, sfa_peer, options=None):
+ def verify_persons(self, slice_hrn, slice_record,
+ users, sfa_peer, options=None):
if options is None:
options = {}
site_id = site['site_id']
# locate the slice object
- slice = self.driver.shell.GetSlices({'peer_id': None, 'hrn': slice_hrn}, [
- 'slice_id', 'hrn', 'person_ids'])[0]
+ slice = self.driver.shell.GetSlices(
+ {'peer_id': None, 'hrn': slice_hrn},
+ ['slice_id', 'hrn', 'person_ids'])[0]
slice_id = slice['slice_id']
slice_person_ids = slice['person_ids']
# and for this we need all the Person objects; we already have the target_existing ones
# also we avoid issuing a call if possible
target_created_persons = [] if not target_created_person_ids \
- else self.driver.shell.GetPersons \
- ({'peer_id': None, 'person_id': target_created_person_ids}, person_fields)
- persons_by_person_id = {person['person_id']: person
- for person in target_existing_persons + target_created_persons}
+ else self.driver.shell.GetPersons(
+ {'peer_id': None, 'person_id': target_created_person_ids},
+ person_fields)
+ persons_by_person_id = {
+ person['person_id']: person
+ for person in target_existing_persons + target_created_persons}
def user_by_person_id(person_id):
person = persons_by_person_id[person_id]
# return hrns of the newly added persons
- return [persons_by_person_id[person_id]['hrn'] for person_id in add_person_ids]
+ return [persons_by_person_id[person_id]['hrn']
+ for person_id in add_person_ids]
def verify_keys(self, persons_to_verify_keys, options=None):
if options is None:
key = {'key': key_string, 'key_type': 'ssh'}
self.driver.shell.AddPersonKey(int(person_id), key)
- def verify_slice_tags(self, slice, requested_slice_attributes, options=None, admin=False):
+ def verify_slice_tags(self, slice, requested_slice_attributes,
+ options=None, admin=False):
"""
This function deals with slice tags, and supports 3 modes described
in the 'pltags' option that can be either
(*) 'ignore' (default) - do nothing
(*) 'append' - only add incoming tags, that do not match an existing tag
- (*) 'sync' - tries to do the plain wholesale thing,
+ (*) 'sync' - tries to do the plain wholesale thing,
i.e. to leave the db in sync with incoming tags
"""
if options is None:
# be removed
tag_found = False
for requested_attribute in requested_slice_attributes:
- if requested_attribute['name'] == slice_tag['tagname'] and \
- requested_attribute['value'] == slice_tag['value']:
+ if (requested_attribute['name'] == slice_tag['tagname'] and
+ requested_attribute['value'] == slice_tag['value']):
tag_found = True
break
# remove tags only if not in append mode
if requested_attribute['name'] in valid_tag_names:
tag_found = False
for existing_attribute in existing_slice_tags:
- if requested_attribute['name'] == existing_attribute['tagname'] and \
- requested_attribute['value'] == existing_attribute['value']:
+ if (requested_attribute['name'] == existing_attribute['tagname'] and \
+ requested_attribute['value'] == existing_attribute['value']):
tag_found = True
break
if not tag_found:
name = tag_or_att[
'tagname'] if 'tagname' in tag_or_att else tag_or_att['name']
return "SliceTag slice={}, tagname={} value={}, node_id={}"\
- .format(slice['name'], tag_or_att['name'], tag_or_att['value'], tag_or_att.get('node_id'))
+ .format(slice['name'], tag_or_att['name'],
+ tag_or_att['value'], tag_or_att.get('node_id'))
# remove stale tags
for tag in slice_tags_to_remove:
friendly_message(tag)))
self.driver.shell.DeleteSliceTag(tag['slice_tag_id'])
except Exception as e:
- logger.warn("Failed to remove slice tag {}\nCause:{}"
- .format(friendly_message(tag), e))
+ logger.warning("Failed to remove slice tag {}\nCause:{}"
+ .format(friendly_message(tag), e))
# add requested_tags
for attribute in slice_attributes_to_add:
try:
logger.info("Adding Slice Tag {}".format(
friendly_message(attribute)))
- self.driver.shell.AddSliceTag(slice['name'], attribute['name'],
- attribute['value'], attribute.get('node_id', None))
+ self.driver.shell.AddSliceTag(
+ slice['name'], attribute['name'],
+ attribute['value'], attribute.get('node_id', None))
except Exception as e:
- logger.warn("Failed to add slice tag {}\nCause:{}"
- .format(friendly_message(attribute), e))
+ logger.warning("Failed to add slice tag {}\nCause:{}"
+ .format(friendly_message(attribute), e))