本文整理汇总了Python中cloudhands.common.connectors.Registry.add方法的典型用法代码示例。如果您正苦于以下问题:Python Registry.add方法的具体用法?Python Registry.add怎么用?Python Registry.add使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类cloudhands.common.connectors.Registry
的用法示例。
在下文中一共展示了Registry.add方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_name_unique_across_organisations
# 需要导入模块: from cloudhands.common.connectors import Registry [as 别名]
# 或者: from cloudhands.common.connectors.Registry import add [as 别名]
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)
示例2: setUp
# 需要导入模块: from cloudhands.common.connectors import Registry [as 别名]
# 或者: from cloudhands.common.connectors.Registry import add [as 别名]
def setUp(self):
""" Populate test database"""
session = Registry().connect(sqlite3, ":memory:").session
initialise(session)
session.add_all((
Organisation(
uuid=uuid.uuid4().hex,
name="TestOrg"),
Provider(
uuid=uuid.uuid4().hex,
name="testcloud.io"),
)
)
session.commit()
org = session.query(Organisation).one()
provider = session.query(Provider).one()
actor = session.query(Component).filter(
Component.handle == "burst.controller").one()
active = session.query(SubscriptionState).filter(
SubscriptionState.name == "active").one()
subs = Subscription(
uuid=uuid.uuid4().hex,
model=cloudhands.common.__version__,
organisation=org, provider=provider)
session.add(subs)
session.commit()
now = datetime.datetime.utcnow()
act = Touch(artifact=subs, actor=actor, state=active, at=now)
net = ipaddress.ip_network("172.16.144.0/29")
session.add_all(
(IPAddress(value=str(ip), provider=provider, touch=act)
for ip in net.hosts()))
session.commit()
self.assertEqual(6, session.query(IPAddress).count())
session.add_all((
CatalogueItem(
uuid=uuid.uuid4().hex,
name="Web Server",
description="Apache server VM",
note=None,
logo=None,
natrouted=True,
organisation=org,
),
CatalogueItem(
uuid=uuid.uuid4().hex,
name="File Server",
description="OpenSSH server VM",
note=None,
logo=None,
natrouted=False,
organisation=org,
)
))
session.commit()
示例3: test_required_field
# 需要导入模块: from cloudhands.common.connectors import Registry [as 别名]
# 或者: from cloudhands.common.connectors.Registry import add [as 别名]
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)
示例4: test_using_touches
# 需要导入模块: from cloudhands.common.connectors import Registry [as 别名]
# 或者: from cloudhands.common.connectors.Registry import add [as 别名]
def test_using_touches(self):
then = datetime.datetime.utcnow() - datetime.timedelta(seconds=1)
session = Registry().connect(sqlite3, ":memory:").session
user = User(handle=None, uuid=uuid.uuid4().hex)
org = session.query(Organisation).one()
mship = Membership(
uuid=uuid.uuid4().hex,
model=cloudhands.common.__version__,
organisation=org,
role="user")
invite = session.query(MembershipState).filter(
MembershipState.name == "created").one()
mship.changes.append(
Touch(artifact=mship, actor=user, state=invite, at=then))
session.add(mship)
session.commit()
self.assertIs(mship.changes[0].state, invite)
self.assertIs(session.query(Touch).first().state, invite)
self.assertEqual(session.query(Touch).count(), 1)
now = datetime.datetime.utcnow()
self.assertTrue(now > then)
active = session.query(MembershipState).filter(
MembershipState.name == "active").one()
mship.changes.append(
Touch(artifact=mship, actor=user, state=active, at=now))
session.commit()
self.assertIs(mship.changes[1].state, active)
self.assertIs(
session.query(Touch).order_by(Touch.at)[-1].state, active)
self.assertEqual(session.query(Touch).count(), 2)
self.assertEqual(
session.query(Touch).filter(Touch.at < now).first(),
mship.changes[0])
self.assertIs(
session.query(Touch).filter(
Touch.at > then).first(),
mship.changes[1])
mship.changes.sort(key=operator.attrgetter("at"), reverse=True)
self.assertEqual(
session.query(Touch).filter(
Touch.at < now).first(),
mship.changes[1])
self.assertIs(
session.query(Touch).filter(
Touch.at > then).first(),
mship.changes[0])
示例5: test_using_touches
# 需要导入模块: from cloudhands.common.connectors import Registry [as 别名]
# 或者: from cloudhands.common.connectors.Registry import add [as 别名]
def test_using_touches(self):
then = datetime.datetime.utcnow() - datetime.timedelta(seconds=1)
session = Registry().connect(sqlite3, ":memory:").session
user = User(handle=None, uuid=uuid.uuid4().hex)
reg = Registration(
uuid=uuid.uuid4().hex,
model=cloudhands.common.__version__)
preconfirm = session.query(RegistrationState).filter(
RegistrationState.name == "pre_registration_inetorgperson").one()
reg.changes.append(
Touch(artifact=reg, actor=user, state=preconfirm, at=then))
session.add(reg)
session.commit()
self.assertIs(reg.changes[0].state, preconfirm)
self.assertIs(session.query(Touch).first().state, preconfirm)
self.assertEqual(session.query(Touch).count(), 1)
now = datetime.datetime.utcnow()
self.assertTrue(now > then)
valid = session.query(RegistrationState).filter(
RegistrationState.name == "valid").one()
act = Touch(artifact=reg, actor=user, state=valid, at=now)
reg.changes.append(act)
hash = BcryptedPassword(value="a" * 60, touch=act, provider=None)
session.add(hash)
session.commit()
self.assertIs(reg.changes[1].state, valid)
self.assertIs(
session.query(Touch).order_by(Touch.at)[-1].state, valid)
self.assertEqual(session.query(Touch).count(), 2)
self.assertEqual(
session.query(Touch).filter(Touch.at < now).first(),
reg.changes[0])
self.assertIs(
session.query(Touch).filter(
Touch.at > then).first(),
reg.changes[1])
reg.changes.sort(key=operator.attrgetter("at"), reverse=True)
self.assertEqual(
session.query(Touch).filter(
Touch.at < now).first(),
reg.changes[1])
self.assertIs(
session.query(Touch).filter(
Touch.at > then).first(),
reg.changes[0])
示例6: test_organisation_field
# 需要导入模块: from cloudhands.common.connectors import Registry [as 别名]
# 或者: from cloudhands.common.connectors.Registry import add [as 别名]
def test_organisation_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,
role="user")
session.add(mship)
session.commit()
self.assertIs(mship, session.query(Membership).first())
self.assertIs(org, mship.organisation)
示例7: RegistrationLifecycleTests
# 需要导入模块: from cloudhands.common.connectors import Registry [as 别名]
# 或者: from cloudhands.common.connectors.Registry import add [as 别名]
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:")
示例8: test_directory_attaches_to_membership
# 需要导入模块: from cloudhands.common.connectors import Registry [as 别名]
# 或者: from cloudhands.common.connectors.Registry import add [as 别名]
def test_directory_attaches_to_membership(self):
session = Registry().connect(sqlite3, ":memory:").session
session.flush()
archive = session.query(Archive).filter(
Archive.name == "NITS").first()
org = session.query(Organisation).one()
subs = Subscription(
uuid=uuid.uuid4().hex,
model=cloudhands.common.__version__,
organisation=org, provider=archive)
user = User(handle=None, uuid=uuid.uuid4().hex)
session.add_all((subs, user))
session.commit()
mship = Membership(
uuid=uuid.uuid4().hex,
model=cloudhands.common.__version__,
organisation=org,
role="user")
now = datetime.datetime.utcnow()
invite = session.query(MembershipState).filter(
MembershipState.name == "created").one()
mship.changes.append(
Touch(artifact=mship, actor=user, state=invite, at=now))
session.add(mship)
session.commit()
# illustrates user onboarding - membership gets decorated with
# directory resources
now = datetime.datetime.utcnow()
for subs in org.subscriptions:
if isinstance(subs.provider, Archive):
d = Directory(
description="CEDA data archive",
mount_path="/{mount}/panfs/ceda") # anticipates templating
latest = mship.changes[-1]
act = Touch(
artifact=mship, actor=user, state=latest.state, at=now)
d.touch = act
mship.changes.append(act)
session.add(d)
session.commit()
# Check we can get at the resources from the membership
self.assertIs(
d,
session.query(Resource).join(Touch).join(Membership).filter(
Membership.id == mship.id).one())
示例9: test_organisation_subscribes_to_archive
# 需要导入模块: from cloudhands.common.connectors import Registry [as 别名]
# 或者: from cloudhands.common.connectors.Registry import add [as 别名]
def test_organisation_subscribes_to_archive(self):
session = Registry().connect(sqlite3, ":memory:").session
archive = session.query(Archive).filter(
Archive.name == "NITS").first()
self.assertTrue(archive)
org = session.query(Organisation).one()
subs = Subscription(
uuid=uuid.uuid4().hex,
model=cloudhands.common.__version__,
organisation=org, provider=archive)
session.add(subs)
session.commit()
self.assertEqual(
1, session.query(Subscription, Organisation, Archive).filter(
Organisation.id == org.id).filter(
Archive.id == archive.id).count())
self.assertEqual(1, len(org.subscriptions))
示例10: AgentTesting
# 需要导入模块: from cloudhands.common.connectors import Registry [as 别名]
# 或者: from cloudhands.common.connectors.Registry import add [as 别名]
class AgentTesting(unittest.TestCase):
def setUp(self):
""" Populate test database"""
self.session = Registry().connect(sqlite3, ":memory:").session
initialise(self.session)
self.session.add_all((
Organisation(
uuid=uuid.uuid4().hex,
name="TestOrg"),
Provider(
uuid=uuid.uuid4().hex,
name="cloudhands.jasmin.vcloud.phase04.cfg"),
User(handle="testuser", uuid=uuid.uuid4().hex),
))
self.session.commit()
org, user = (
self.session.query(Organisation).one(),
self.session.query(User).one(),
)
self.session.add(
Membership(
uuid=uuid.uuid4().hex,
model=cloudhands.common.__version__,
organisation=org,
role="user")
)
self.session.commit()
self.mship = self.session.query(Membership).one()
accepted = self.session.query(
MembershipState).filter(
MembershipState.name == "accepted").one()
now = datetime.datetime.utcnow()
act = Touch(artifact=self.mship, actor=user, state=accepted, at=now)
self.session.add(act)
self.session.commit()
def tearDown(self):
""" Every test gets its own in-memory database """
r = Registry()
r.disconnect(sqlite3, ":memory:")
示例11: test_ldapattribute_attaches_to_membership
# 需要导入模块: from cloudhands.common.connectors import Registry [as 别名]
# 或者: from cloudhands.common.connectors.Registry import add [as 别名]
def test_ldapattribute_attaches_to_membership(self):
def find_mships_without_attributes(session):
return [
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)]
session = Registry().connect(sqlite3, ":memory:").session
session.flush()
user = session.query(User).one()
org = session.query(Organisation).one()
mship = Membership(
uuid=uuid.uuid4().hex,
model=cloudhands.common.__version__,
organisation=org,
role="user")
accepted = session.query(MembershipState).filter(
MembershipState.name == "accepted").one()
now = datetime.datetime.utcnow()
session.add(Touch(artifact=mship, actor=user, state=accepted, at=now))
session.commit()
remaining = find_mships_without_attributes(session)
self.assertEqual(1, len(remaining))
now = datetime.datetime.utcnow()
act = Touch(artifact=mship, actor=user, state=accepted, at=now)
resource = LDAPAttribute(
dn="cn={},ou=jasmin,ou=Groups,o=hpc,dc=rl,dc=ac,dc=uk".format(org.name),
key="memberUid", value=user.uuid, verb="add", touch=act)
session.add(resource)
session.commit()
# Check we can get at the resources from the membership
self.assertEqual(
(mship, resource),
session.query(Membership, LDAPAttribute).join(Touch).join(LDAPAttribute).filter(
Membership.id == mship.id).one())
remaining = find_mships_without_attributes(session)
self.assertFalse(remaining, remaining)
示例12: test_time_query
# 需要导入模块: from cloudhands.common.connectors import Registry [as 别名]
# 或者: from cloudhands.common.connectors.Registry import add [as 别名]
def test_time_query(self):
session = Registry().connect(sqlite3, ":memory:").session
agent = session.query(Component).one()
state = session.query(MembershipState).first()
reg = Registration(
uuid=uuid.uuid4().hex,
model=cloudhands.common.__version__)
start = now = datetime.datetime.now()
then = start + datetime.timedelta(minutes=90)
end = start + datetime.timedelta(hours=24)
act = Touch(artifact=reg, actor=agent, state=state, at=now)
limit = TimeInterval(end=then, touch=act)
session.add(limit)
session.commit()
self.assertEqual(session.query(TimeInterval).filter(
TimeInterval.end > now).count(), 1)
self.assertIs(reg,
session.query(Registration).join(Touch).join(TimeInterval).filter(
TimeInterval.end.between(start, end)).first())
示例13: test_organisation_join
# 需要导入模块: from cloudhands.common.connectors import Registry [as 别名]
# 或者: from cloudhands.common.connectors.Registry import add [as 别名]
def test_organisation_join(self):
session = Registry().connect(sqlite3, ":memory:").session
org = session.query(Organisation).one()
self.assertEqual(0, session.query(CatalogueItem).count())
ci = CatalogueItem(
uuid=uuid.uuid4().hex,
name="Web Server",
description="Headless VM with Web server",
note=textwrap.dedent("""
<p>This VM runs Apache on CentOS 6.5.
It has 8GB RAM and 4 CPU cores.
It is used for hosting websites and applications with a
Web API.</p>
"""),
logo="headless",
natrouted=True,
organisation=org
)
session.add(ci)
session.commit()
self.assertEqual(1, session.query(CatalogueItem).join(Organisation).filter(
Organisation.uuid == org.uuid).count())
示例14: mailer
# 需要导入模块: from cloudhands.common.connectors import Registry [as 别名]
# 或者: from cloudhands.common.connectors.Registry import add [as 别名]
def mailer(self):
log = logging.getLogger(__name__ + ".mailer")
session = Registry().connect(sqlite3, self.args.db).session
initialise(session)
actor = session.query(Component).filter(
Component.handle=="identity.controller").one()
invited = session.query(MembershipState).filter(
RegistrationState.name == "invited").one()
while True:
unsent = [
i for i in session.query(Membership).all()
if i.changes[-1].state.name == "created"]
for mship in unsent:
try:
user = mship.changes[-1].actor
email = session.query(EmailAddress).join(Touch).join(User).filter(
User.id == user.id).order_by(desc(Touch.at)).first().value
host = "http://{}:8080".format(platform.node()) # FIXME
except Exception as e:
log.error(e)
break
else:
msg = (email, host, mship.uuid)
log.debug(msg)
now = datetime.datetime.utcnow()
act = Touch(artifact=mship, actor=actor, state=invited, at=now)
yield from self.emailQ.put(msg)
try:
session.add(act)
session.commit()
except Exception as e:
log.error(e)
session.rollback()
break
log.debug("Waiting for {}s".format(self.args.interval))
yield from asyncio.sleep(self.args.interval)
示例15: test_group_is_parent_of_access
# 需要导入模块: from cloudhands.common.connectors import Registry [as 别名]
# 或者: from cloudhands.common.connectors.Registry import add [as 别名]
def test_group_is_parent_of_access(self):
session = Registry().connect(sqlite3, ":memory:").session
session.flush()
grp = session.query(Group).one()
user = User(handle=None, uuid=uuid.uuid4().hex)
session.add(user)
session.commit()
access = Access(
uuid=uuid.uuid4().hex,
model=cloudhands.common.__version__,
group=grp,
role="user")
now = datetime.datetime.utcnow()
created = session.query(AccessState).filter(
AccessState.name == "created").one()
act = Touch(artifact=access, actor=user, state=created, at=now)
session.add(act)
session.commit()
# illustrates user onboarding - access gets decorated with
# posix resource(s)
latest = access.changes[-1]
now = datetime.datetime.utcnow()
gid = PosixGId(value=grp.number)
act = Touch(
artifact=access, actor=user, state=latest.state, at=now)
gid.touch = act
session.add(gid)
session.commit()
# Check we can get at the resource from the access
self.assertIs(
gid,
session.query(Resource).join(Touch).join(Access).filter(
Access.id == access.id).one())