本文整理匯總了Python中cloudhands.common.connectors.Registry.autoflush方法的典型用法代碼示例。如果您正苦於以下問題:Python Registry.autoflush方法的具體用法?Python Registry.autoflush怎麽用?Python Registry.autoflush使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類cloudhands.common.connectors.Registry
的用法示例。
在下文中一共展示了Registry.autoflush方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: test_reallocate_ip
# 需要導入模塊: from cloudhands.common.connectors import Registry [as 別名]
# 或者: from cloudhands.common.connectors.Registry import autoflush [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])