當前位置: 首頁>>代碼示例>>Python>>正文


Python Registry.close方法代碼示例

本文整理匯總了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)
開發者ID:cedadev,項目名稱:cloudhands-web,代碼行數:58,代碼來源:observer.py

示例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)
開發者ID:cedadev,項目名稱:cloudhands-web,代碼行數:43,代碼來源:observer.py


注:本文中的cloudhands.common.connectors.Registry.close方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。