本文整理汇总了Python中cloudhands.common.connectors.Registry.add_all方法的典型用法代码示例。如果您正苦于以下问题:Python Registry.add_all方法的具体用法?Python Registry.add_all怎么用?Python Registry.add_all使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类cloudhands.common.connectors.Registry
的用法示例。
在下文中一共展示了Registry.add_all方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_duplicate_names
# 需要导入模块: from cloudhands.common.connectors import Registry [as 别名]
# 或者: from cloudhands.common.connectors.Registry import add_all [as 别名]
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)
示例2: test_name_unique_across_organisations
# 需要导入模块: from cloudhands.common.connectors import Registry [as 别名]
# 或者: from cloudhands.common.connectors.Registry import add_all [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)
示例3: setUp
# 需要导入模块: from cloudhands.common.connectors import Registry [as 别名]
# 或者: from cloudhands.common.connectors.Registry import add_all [as 别名]
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()
示例4: test_names_are_not_unique
# 需要导入模块: from cloudhands.common.connectors import Registry [as 别名]
# 或者: from cloudhands.common.connectors.Registry import add_all [as 别名]
def test_names_are_not_unique(self):
session = Registry().connect(sqlite3, ":memory:").session
session.add_all((
Label(name="Test", description="Test description"),
Label(name="Test", description="Test description"),
))
session.commit()
self.assertEqual(2, session.query(Label).count())
示例5: test_descriptions_may_be_omitted
# 需要导入模块: from cloudhands.common.connectors import Registry [as 别名]
# 或者: from cloudhands.common.connectors.Registry import add_all [as 别名]
def test_descriptions_may_be_omitted(self):
session = Registry().connect(sqlite3, ":memory:").session
session.add_all((
Label(name="One"),
Label(name="Two"),
))
session.commit()
self.assertEqual(2, session.query(Label).count())
示例6: setUp
# 需要导入模块: from cloudhands.common.connectors import Registry [as 别名]
# 或者: from cloudhands.common.connectors.Registry import add_all [as 别名]
def setUp(self):
""" Populate test database"""
session = Registry().connect(sqlite3, ":memory:").session
session.add_all(
State(fsm=AccessState.table, name=v)
for v in AccessState.values)
session.add(
Group(uuid=uuid.uuid4().hex, name="TestGroup", number=7654321))
session.commit()
示例7: test_shared_names
# 需要导入模块: from cloudhands.common.connectors import Registry [as 别名]
# 或者: from cloudhands.common.connectors.Registry import add_all [as 别名]
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)
示例8: test_directory_attaches_to_membership
# 需要导入模块: from cloudhands.common.connectors import Registry [as 别名]
# 或者: from cloudhands.common.connectors.Registry import add_all [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_reallocate_ip
# 需要导入模块: from cloudhands.common.connectors import Registry [as 别名]
# 或者: from cloudhands.common.connectors.Registry import add_all [as 别名]
def test_reallocate_ip(self):
session = Registry().connect(sqlite3, ":memory:").session
session.autoflush = False # http://stackoverflow.com/a/4202016
oName = "TestOrg"
providerName = "testcloud.io"
handle = "Test User"
hName = "mynode.test.org"
ipAddr = "192.168.1.1"
user = User(handle=handle, uuid=uuid.uuid4().hex)
org = session.query(Organisation).one()
provider = Provider(
name=providerName, uuid=uuid.uuid4().hex)
session.add_all((user, org, provider))
session.commit()
scheduling = session.query(HostState).filter(
HostState.name == "scheduling").one()
up = session.query(HostState).filter(
HostState.name == "up").one()
hosts = [
Host(
uuid=uuid.uuid4().hex,
model=cloudhands.common.__version__,
organisation=org,
name=hName),
Host(
uuid=uuid.uuid4().hex,
model=cloudhands.common.__version__,
organisation=org,
name=hName),
]
now = datetime.datetime.utcnow()
hosts[0].changes.append(
Touch(artifact=hosts[0], actor=user, state=up, at=now))
hosts[1].changes.append(
Touch(artifact=hosts[1], actor=user, state=scheduling, at=now))
session.add_all(hosts)
session.commit()
ip = allocate_ip(session, hosts[0], provider, ipAddr)
self.assertIn(ip, [r for c in hosts[0].changes for r in c.resources])
ip = allocate_ip(session, hosts[1], provider, ipAddr)
self.assertNotIn(
ip, [r for c in hosts[0].changes for r in c.resources])
self.assertIn(ip, [r for c in hosts[1].changes for r in c.resources])
示例10: SubscriptionLifecycleTests
# 需要导入模块: from cloudhands.common.connectors import Registry [as 别名]
# 或者: from cloudhands.common.connectors.Registry import add_all [as 别名]
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:")
示例11: AgentTesting
# 需要导入模块: from cloudhands.common.connectors import Registry [as 别名]
# 或者: from cloudhands.common.connectors.Registry import add_all [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:")
示例12: test_organisation_oversubscribes_to_archive
# 需要导入模块: from cloudhands.common.connectors import Registry [as 别名]
# 或者: from cloudhands.common.connectors.Registry import add_all [as 别名]
def test_organisation_oversubscribes_to_archive(self):
session = Registry().connect(sqlite3, ":memory:").session
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),
Subscription(
uuid=uuid.uuid4().hex,
model=cloudhands.common.__version__,
organisation=org,
provider=archive)]
session.add_all(subs)
self.assertRaises(
sqlalchemy.exc.IntegrityError, session.commit)
session.rollback()
self.assertEqual(0, len(org.subscriptions))
示例13: MembershipLifecycleTests
# 需要导入模块: from cloudhands.common.connectors import Registry [as 别名]
# 或者: from cloudhands.common.connectors.Registry import add_all [as 别名]
class MembershipLifecycleTests(unittest.TestCase):
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()
def tearDown(self):
Registry().disconnect(sqlite3, ":memory:")
示例14: test_name_unique_within_organisation
# 需要导入模块: from cloudhands.common.connectors import Registry [as 别名]
# 或者: from cloudhands.common.connectors.Registry import add_all [as 别名]
def test_name_unique_within_organisation(self):
session = Registry().connect(sqlite3, ":memory:").session
org = session.query(Organisation).one()
session.add_all((
CatalogueItem(
name="Web Server",
description="Apache web server VM",
note=None,
logo=None,
organisation=org
),
CatalogueItem(
name="Web Server",
description="Nginx web server VM",
note=None,
logo=None,
organisation=org
)
))
self.assertRaises(
sqlalchemy.exc.IntegrityError, session.commit)
示例15: test_single_host_lifecycle_with_sdn
# 需要导入模块: from cloudhands.common.connectors import Registry [as 别名]
# 或者: from cloudhands.common.connectors.Registry import add_all [as 别名]
def test_single_host_lifecycle_with_sdn(self):
session = Registry().connect(sqlite3, ":memory:").session
# 0. Set up User
user = User(handle="Anon", uuid=uuid.uuid4().hex)
# 1. User creates a new host
now = datetime.datetime.utcnow()
org = session.query(Organisation).one()
requested = session.query(HostState).filter(
HostState.name == "requested").one()
host = Host(
uuid=uuid.uuid4().hex,
model=cloudhands.common.__version__,
organisation=org,
name="userwantsthishostname"
)
act = Touch(artifact=host, actor=user, state=requested, at=now)
osImg = OSImage(name="CentOS 6.5", touch=act)
host.changes.append(act)
session.add_all((osImg, host))
session.commit()
# 2. Burst controller finds hosts in 'requested' and provisions them
latest = (h.changes[-1] for h in session.query(Host).all())
jobs = [(t.actor, t.artifact) for t in latest if t.state is requested]
self.assertIn((user, host), jobs)
now = datetime.datetime.utcnow()
scheduling = session.query(HostState).filter(
HostState.name == "scheduling").one()
act = Touch(artifact=host, actor=user, state=scheduling, at=now)
host.changes.append(act)
session.commit()
# 3. Burst controller raises a node
now = datetime.datetime.utcnow()
provider = session.query(Provider).one()
act = Touch(artifact=host, actor=user, state=scheduling, at=now)
host.changes.append(act)
node = Node(name=host.name, touch=act, provider=provider)
sdn = SoftwareDefinedNetwork(name="bridge_routed_external", touch=act)
session.add_all((sdn, node))
session.commit()
# 4. Burst controller allocates an IP
now = datetime.datetime.utcnow()
act = Touch(artifact=host, actor=user, state=scheduling, at=now)
host.changes.append(act)
ip = IPAddress(value="192.168.1.4", touch=act, provider=provider)
session.add(ip)
self.assertIn(act, session)
session.commit()
# 5. Burst controller marks Host as unknown
now = datetime.datetime.utcnow()
unknown = session.query(HostState).filter(
HostState.name == "unknown").one()
host.changes.append(
Touch(artifact=host, actor=user, state=unknown, at=now))
# 6. Recovering details of provisioning of this host
resources = [r for i in session.query(Touch).filter(
Touch.artifact == host).all() for r in i.resources]
self.assertIn(node, resources)
self.assertIn(sdn, resources)
self.assertIn(ip, resources)