本文整理汇总了Python中cloudhands.common.connectors.Registry.close方法的典型用法代码示例。如果您正苦于以下问题:Python Registry.close方法的具体用法?Python Registry.close怎么用?Python Registry.close使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类cloudhands.common.connectors.Registry
的用法示例。
在下文中一共展示了Registry.close方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: publish_user_membership
# 需要导入模块: from cloudhands.common.connectors import Registry [as 别名]
# 或者: from cloudhands.common.connectors.Registry import close [as 别名]
def publish_user_membership(self):
log = logging.getLogger(__name__ + ".publish_user_membership")
session = Registry().connect(sqlite3, self.args.db).session
initialise(session)
while True:
try:
# Unwieldy, but left outer joins seem not to work with table
# inheritance.
unpublished = [
mship for mship in session.query(Membership).join(
Touch).join(State, State.name == "accepted").all()
if not any(isinstance(r, LDAPAttribute)
for c in mship.changes for r in c.resources)]
for mship in unpublished:
user = mship.changes[1].actor
reg = next((
r for r in session.query(Registration).all()
if (r.changes[0].actor is user)), None)
if reg is None:
raise StopIteration("Failed finding registration.")
try:
uid = next(r for c in reversed(reg.changes)
for r in c.resources if isinstance(r, PosixUId))
except StopIteration:
continue
record = LDAPRecord(
dn={
("cn={},ou=Groups,ou=jasmin2,"
"ou=People,o=hpc,dc=rl,dc=ac,dc=uk").format(
mship.organisation.name.lower() + "_vcloud-admins")
},
memberUId={uid.value},
)
msg = LDAPProxy.WriteLDAPAttribute(record, mship.uuid)
yield from self.ldapQ.put(msg)
record = LDAPRecord(
dn={("cn={},ou=jasmin2,"
"ou=People,o=hpc,dc=rl,dc=ac,dc=uk").format(uid.value)},
description={
"jvo:{}".format(mship.organisation.name.lower())
},
)
msg = LDAPProxy.WriteLDAPAttribute(record, mship.uuid)
yield from self.ldapQ.put(msg)
except Exception as e:
log.error(e)
finally:
session.close()
log.debug("Waiting for {}s".format(self.args.interval))
yield from asyncio.sleep(self.args.interval)
示例2: publish_sshpublickey
# 需要导入模块: from cloudhands.common.connectors import Registry [as 别名]
# 或者: from cloudhands.common.connectors.Registry import close [as 别名]
def publish_sshpublickey(self):
log = logging.getLogger(__name__ + ".sshpublickey")
session = Registry().connect(sqlite3, self.args.db).session
initialise(session)
actor = session.query(Component).filter(
Component.handle=="identity.controller").one()
while True:
try:
unpublished = [
r for r in session.query(Registration).all() if (
r.changes[-1].state.name ==
"pre_user_ldappublickey")]
for reg in unpublished:
user = reg.changes[0].actor
resources = [r for c in reversed(reg.changes)
for r in c.resources]
key = next(
(i for i in resources if isinstance(i, PublicKey)),
None)
if key is None:
continue
uid = next(i for i in resources if isinstance(i, PosixUId))
record = LDAPRecord(
dn={("cn={},ou=jasmin2,"
"ou=People,o=hpc,dc=rl,dc=ac,dc=uk").format(uid.value)},
objectclass={"ldapPublicKey"},
sshPublicKey={key.value},
)
log.debug(record)
msg = LDAPProxy.WriteSSHPublicKey(record, reg.uuid)
yield from self.ldapQ.put(msg)
except Exception as e:
log.error(e)
finally:
session.close()
log.debug("Waiting for {}s".format(self.args.interval))
yield from asyncio.sleep(self.args.interval)