本文整理汇总了Python中sfa.trust.gid.GID.save_to_string方法的典型用法代码示例。如果您正苦于以下问题:Python GID.save_to_string方法的具体用法?Python GID.save_to_string怎么用?Python GID.save_to_string使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类sfa.trust.gid.GID
的用法示例。
在下文中一共展示了GID.save_to_string方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: install_gids
# 需要导入模块: from sfa.trust.gid import GID [as 别名]
# 或者: from sfa.trust.gid.GID import save_to_string [as 别名]
def install_gids(api, slivers):
# install node gid
node_gid_file = api.config.config_path + os.sep + "node.gid"
node_gid = GID(filename=node_gid_file)
node_gid_str = node_gid.save_to_string(save_parents=True)
node_hrn = node_gid.get_hrn()
# get currently installed slice and node gids
interface_hrn = api.config.SFA_INTERFACE_HRN
slice_gids = {}
node_gids = {}
for slicename in slivers:
slice_gid_filename = "/vservers/%s/etc/slice.gid" % slicename
node_gid_filename = "/vservers/%s/etc/node.gid" % slicename
if os.path.isfile(slice_gid_filename):
gid_file = open(slice_gid_filename, 'r')
slice_gids[sliver] = gid_file.read()
gid_file.close()
if os.path.isfile(node_gid_filename):
gid_file = open(node_gid_filename, 'r')
node_gids[sliver] = gid_file.read()
gid_file.close()
# convert slicenames to hrns
hrns = [slicename_to_hrn(interface_hrn, slicename) \
for slicename in slivers]
# get current gids from registry
cred = api.getCredential()
registry = api.get_registry()
#records = registry.GetGids(cred, hrns)
records = registry.get_gids(cred, hrns)
for record in records:
# skip if this isnt a slice record
if not record['type'] == 'slice':
continue
vserver_path = "/vservers/%(slicename)s" % locals()
# skip if the slice isnt instantiated
if not os.path.exists(vserver_path):
continue
# install slice gid if it doesnt already exist or has changed
slice_gid_str = record['gid']
slicename = hrn_to_pl_slicename(record['hrn'])
if slicename not in slice_gids or slice_gids[slicename] != slice_gid_str:
gid_filename = os.sep.join([vserver_path, "etc", "slice.gid"])
GID(string=slice_gid_str).save_to_file(gid_filename, save_parents=True)
# install slice gid if it doesnt already exist or has changed
if slicename not in node_gids or node_gids[slicename] != node_gid_str:
gid_filename = os.sep.join([vserver_path, "etc", "node.gid"])
GID(string=node_gid_str).save_to_file(gid_filename, save_parents=True)
示例2: import_gid
# 需要导入模块: from sfa.trust.gid import GID [as 别名]
# 或者: from sfa.trust.gid.GID import save_to_string [as 别名]
def import_gid(options):
"""
Import the specified gid into the registry (db and authorities
hierarchy) overwriting any previous gid.
"""
from sfa.util.table import SfaTable
from sfa.util.record import SfaRecord
# load the gid
gidfile = os.path.abspath(options.importgid)
if not gidfile or not os.path.isfile(gidfile):
print "No such gid: %s" % gidfile
sys.exit(1)
gid = GID(filename=gidfile)
# check if it exists within the hierarchy
hierarchy = Hierarchy()
if not hierarchy.auth_exists(gid.get_hrn()):
print "%s not found in hierarchy" % gid.get_hrn()
sys.exit(1)
# check if record exists in db
table = SfaTable()
records = table.find({'hrn': gid.get_hrn(), 'type': 'authority'})
if not records:
print "%s not found in record database" % get.get_hrn()
sys.exit(1)
# update the database record
record = records[0]
record['gid'] = gid.save_to_string(save_parents=True)
table.update(record)
if options.verbose:
print "Imported %s gid into db" % record['hrn']
# update the hierarchy
auth_info = hierarchy.get_auth_info(gid.get_hrn())
filename = auth_info.gid_filename
gid.save_to_file(filename, save_parents=True)
if options.verbose:
print "Writing %s gid to %s" % (gid.get_hrn(), filename)
# ending here
return
示例3: __init__
# 需要导入模块: from sfa.trust.gid import GID [as 别名]
# 或者: from sfa.trust.gid.GID import save_to_string [as 别名]
#.........这里部分代码省略.........
# try to get registry issued cert
try:
self.logger.info("Getting Registry issued cert")
self.read_config()
# *hack. need to set registyr before _get_gid() is called
self.registry = xmlrpcprotocol.get_server(self.reg_url, key_file, cert_file, timeout=self.options.timeout, verbose=self.options.debug)
gid = self._get_gid(type='user')
self.registry = None
self.logger.info("Writing certificate to %s"%cert_file)
gid.save_to_file(cert_file)
except:
self.logger.info("Failed to download Registry issued cert")
return cert_file
def get_cached_gid(self, file):
"""
Return a cached gid
"""
gid = None
if (os.path.isfile(file)):
gid = GID(filename=file)
return gid
# xxx opts unused
def get_gid(self, opts, args):
"""
Get the specify gid and save it to file
"""
hrn = None
if args:
hrn = args[0]
gid = self._get_gid(hrn)
self.logger.debug("Sfi.get_gid-> %s",gid.save_to_string(save_parents=True))
return gid
def _get_gid(self, hrn=None, type=None):
"""
git_gid helper. Retrive the gid from the registry and save it to file.
"""
if not hrn:
hrn = self.user
gidfile = os.path.join(self.options.sfi_dir, hrn + ".gid")
gid = self.get_cached_gid(gidfile)
if not gid:
user_cred = self.get_user_cred()
records = self.registry.Resolve(hrn, user_cred.save_to_string(save_parents=True))
if not records:
raise RecordNotFound(args[0])
record = records[0]
if type:
record=None
for rec in records:
if type == rec['type']:
record = rec
if not record:
raise RecordNotFound(args[0])
gid = GID(string=record['gid'])
self.logger.info("Writing gid to %s"%gidfile)
gid.save_to_file(filename=gidfile)
return gid