当前位置: 首页>>代码示例>>Python>>正文


Python connectors.Registry类代码示例

本文整理汇总了Python中cloudhands.common.connectors.Registry的典型用法代码示例。如果您正苦于以下问题:Python Registry类的具体用法?Python Registry怎么用?Python Registry使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了Registry类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_duplicate_names

 def test_duplicate_names(self):
     session = Registry().connect(sqlite3, ":memory:").session
     session.add_all([
         State(fsm="subscription", name="unchecked"),
         State(fsm="subscription", name="unchecked")])
     self.assertRaises(
         sqlalchemy.exc.IntegrityError, session.commit)
开发者ID:cedadev,项目名称:cloudhands-common,代码行数:7,代码来源:test_schema.py

示例2: setUp

 def setUp(self):
     """ Populate test database"""
     session = Registry().connect(sqlite3, ":memory:").session
     session.add_all(
         State(fsm=RegistrationState.table, name=v)
         for v in RegistrationState.values)
     session.commit()
开发者ID:cedadev,项目名称:cloudhands-common,代码行数:7,代码来源:test_registration.py

示例3: publish_user_membership

    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,代码行数:56,代码来源:observer.py

示例4: test_initialise_db

    def test_initialise_db(self):
        r = Registry()
        con = r.connect(sqlite3, ":memory:")
        self.assertEqual(0, con.session.query(State).count())

        n = initialise(con.session)
        self.assertNotEqual(0, n)
        self.assertGreaterEqual(n, con.session.query(State).count())

        self.assertEqual(0, initialise(con.session))
开发者ID:cedadev,项目名称:cloudhands-common,代码行数:10,代码来源:test_connectors.py

示例5: test_required_field

 def test_required_field(self):
     session = Registry().connect(sqlite3, ":memory:").session
     org = session.query(Organisation).one()
     mship = Membership(
         uuid=uuid.uuid4().hex,
         model=cloudhands.common.__version__,
         organisation=org)
     session.add(mship)
     self.assertRaises(
         sqlalchemy.exc.IntegrityError, session.commit)
开发者ID:cedadev,项目名称:cloudhands-common,代码行数:10,代码来源:test_schema.py

示例6: test_shared_names

 def test_shared_names(self):
     """ State names can be shared across FSMs """
     session = Registry().connect(sqlite3, ":memory:").session
     session.add_all([
         State(fsm="subscription", name="start"),
         State(fsm="host", name="start")])
     try:
         session.commit()
     except sqlalchemy.exc.IntegrityError as e:
         self.fail(e)
开发者ID:cedadev,项目名称:cloudhands-common,代码行数:10,代码来源:test_schema.py

示例7: RegistrationLifecycleTests

class RegistrationLifecycleTests(unittest.TestCase):

    def setUp(self):
        self.session = Registry().connect(sqlite3, ":memory:").session
        initialise(self.session)
        self.reg = Registration(
            uuid=uuid.uuid4().hex,
            model=cloudhands.common.__version__)
        self.session.add(self.reg)
        self.session.commit()

    def tearDown(self):
        Registry().disconnect(sqlite3, ":memory:")
开发者ID:cedadev,项目名称:cloudhands-web,代码行数:13,代码来源:test_registration.py

示例8: test_name_unique_across_organisations

    def test_name_unique_across_organisations(self):
        session = Registry().connect(sqlite3, ":memory:").session
        session.add(Organisation(
            name="BRANSTON", uuid=uuid.uuid4().hex))
        session.commit()
        orgs = session.query(Organisation).all()

        session.add_all((
            CatalogueItem(
                name="Blog Server",
                description="WordPress server VM",
                note=None,
                logo=None,
                organisation=orgs[0]
            ),
            CatalogueItem(
                name="Blog Server",
                description="Tumblr server VM",
                note=None,
                logo=None,
                organisation=orgs[1]
            )
        ))

        self.assertRaises(
            sqlalchemy.exc.IntegrityError, session.commit)
开发者ID:cedadev,项目名称:cloudhands-common,代码行数:26,代码来源:test_schema.py

示例9: setUp

 def setUp(self):
     """ Populate test database"""
     session = Registry().connect(sqlite3, ":memory:").session
     session.add_all(
         State(fsm=MembershipState.table, name=v)
         for v in MembershipState.values)
     session.add(Organisation(
         uuid=uuid.uuid4().hex,
         name="TestOrg"))
     session.add(User(handle="newuser", uuid=uuid.uuid4().hex))
     session.commit()
开发者ID:cedadev,项目名称:cloudhands-common,代码行数:11,代码来源:test_schema.py

示例10: setUp

 def setUp(self):
     self.session = Registry().connect(sqlite3, ":memory:").session
     initialise(self.session)
     self.org = Organisation(
         uuid=uuid.uuid4().hex,
         name="TestOrg")
     adminMp = Membership(
         uuid=uuid.uuid4().hex,
         model=cloudhands.common.__version__,
         organisation=self.org,
         role="admin")
     userMp = Membership(
         uuid=uuid.uuid4().hex,
         model=cloudhands.common.__version__,
         organisation=self.org,
         role="user")
     self.admin = User(handle="Administrator", uuid=uuid.uuid4().hex)
     self.user = User(handle="User", uuid=uuid.uuid4().hex)
     self.guestAddr = "[email protected]"
     active = self.session.query(MembershipState).filter(
         MembershipState.name == "active").one()
     adminMp.changes.append(
         Touch(
             artifact=adminMp, actor=self.admin, state=active,
             at=datetime.datetime.utcnow())
         )
     userMp.changes.append(
         Touch(
             artifact=userMp, actor=self.user, state=active,
             at=datetime.datetime.utcnow())
         )
     self.session.add_all(
         (self.admin, self.user, adminMp, userMp, self.org))
     self.session.commit()
开发者ID:cedadev,项目名称:cloudhands-web,代码行数:34,代码来源:test_membership.py

示例11: setUp

 def setUp(self):
     self.session = Registry().connect(sqlite3, ":memory:").session
     initialise(self.session)
     self.reg = Registration(
         uuid=uuid.uuid4().hex,
         model=cloudhands.common.__version__)
     self.session.add(self.reg)
     self.session.commit()
开发者ID:cedadev,项目名称:cloudhands-web,代码行数:8,代码来源:test_registration.py

示例12: publish_uidnumber

    def publish_uidnumber(self):
        log = logging.getLogger(__name__ + ".uidnumber")
        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 ==
                    "user_posixaccount")]

                for reg in unpublished:
                    resources = [r for c in reversed(reg.changes)
                                 for r in c.resources]

                    emailAddr = next(i for i in resources
                                     if isinstance(i, EmailAddress))
                    uid = next(i for i in resources if isinstance(i, PosixUId))
                    uidNumber = next(i for i in resources
                                     if isinstance(i, PosixUIdNumber))
                    record = LDAPRecord(
                        dn={("cn={},ou=jasmin2,"
                        "ou=People,o=hpc,dc=rl,dc=ac,dc=uk").format(uid.value)},
                        objectclass={"posixAccount"},
                        uid={uid.value},
                        uidNumber={uidNumber.value},
                        gidNumber={uidNumber.value},
                        gecos={"{} <{}>".format(uid.value, emailAddr.value)},
                        homeDirectory={
                            self.config.get(
                                "mount", "home", fallback="/home/{}"
                            ).format(uid.value)
                        },
                        loginShell={"/bin/bash"},
                    )
                    log.debug(record)
                    msg = LDAPProxy.WriteUIdNumber(record, reg.uuid)
                    yield from self.ldapQ.put(msg)
                    session.expire(reg)
            except Exception as e:
                log.error(e)
            finally:
                log.debug("Waiting for {}s".format(self.args.interval))
                yield from asyncio.sleep(self.args.interval)
开发者ID:cedadev,项目名称:cloudhands-web,代码行数:46,代码来源:observer.py

示例13: SubscriptionLifecycleTests

class SubscriptionLifecycleTests(unittest.TestCase):

    def setUp(self):
        self.session = Registry().connect(sqlite3, ":memory:").session
        initialise(self.session)
        self.org = Organisation(
            uuid=uuid.uuid4().hex,
            name="TestOrg")
        self.providers = [
            Provider(uuid=uuid.uuid4().hex, name="JASMIN private DC"),
            Provider(uuid=uuid.uuid4().hex, name="JASMIN burst partner"),
        ]
        self.session.add_all([self.org] + self.providers)
        self.session.commit()

    def tearDown(self):
        Registry().disconnect(sqlite3, ":memory:")
开发者ID:cedadev,项目名称:cloudhands-burst,代码行数:17,代码来源:test_subscription.py

示例14: publish_uuid

    def publish_uuid(self):
        log = logging.getLogger(__name__ + ".uuid")
        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_inetorgperson_dn")]

                for reg in unpublished:
                    # TODO: Get latest PosixUId resource
                    try:
                        uid = next(r for c in reversed(reg.changes)
                            for r in c.resources if isinstance(r, PosixUId))
                    except StopIteration:
                        continue
                    log.debug(uid)
                    user = reg.changes[0].actor
                    surname = user.surname or "UNKNOWN"
                    record = LDAPRecord(
                        dn={("cn={},ou=jasmin2,"
                        "ou=People,o=hpc,dc=rl,dc=ac,dc=uk").format(reg.uuid)},
                        objectclass={"top", "person", "organizationalPerson",
                            "inetOrgPerson"},
                        description={"cluster:jasmin-login"},
                        cn={reg.uuid},
                        sn={surname},
                    )
                    resources = [
                        r for i in reg.changes for r in i.resources
                        if isinstance(r, EmailAddress)]
                    if resources:
                        record["mail"].add(resources[0].value)
                    msg = LDAPProxy.WriteCommonName(record, reg.uuid)
                    yield from self.ldapQ.put(msg)
                    session.expire(reg)
            except Exception as e:
                log.error(e)
            finally:
                log.debug("Waiting for {}s".format(self.args.interval))
                yield from asyncio.sleep(self.args.interval)
开发者ID:cedadev,项目名称:cloudhands-web,代码行数:45,代码来源:observer.py

示例15: test_connect_and_disconnect

    def test_connect_and_disconnect(self):
        r = Registry()
        self.assertEqual(0, len(list(r.items)))
        con = r.connect(sqlite3, ":memory:")
        self.assertEqual(1, len(list(r.items)))

        dup = r.connect(sqlite3, ":memory:")
        self.assertIs(con.engine, dup.engine)
        self.assertEqual(1, len(list(r.items)))

        dis = r.disconnect(sqlite3, ":memory:")
        self.assertEqual(0, len(list(r.items)))
        self.assertIs(dup.engine, dis.engine)
        self.assertIs(None, dis.session)

        dup = r.connect(sqlite3, ":memory:")
        self.assertIsNot(con.engine, dup.engine)
        self.assertEqual(1, len(list(r.items)))
开发者ID:cedadev,项目名称:cloudhands-common,代码行数:18,代码来源:test_connectors.py


注:本文中的cloudhands.common.connectors.Registry类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。