本文整理汇总了Python中empower.persistence.Session.commit方法的典型用法代码示例。如果您正苦于以下问题:Python Session.commit方法的具体用法?Python Session.commit怎么用?Python Session.commit使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类empower.persistence.Session
的用法示例。
在下文中一共展示了Session.commit方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: request_tenant
# 需要导入模块: from empower.persistence import Session [as 别名]
# 或者: from empower.persistence.Session import commit [as 别名]
def request_tenant(self, owner, desc, tenant_name, bssid_type,
tenant_id=None):
"""Request new Tenant."""
if tenant_id in self.tenants:
raise ValueError("Tenant %s exists", tenant_id)
if self.load_pending_tenant(tenant_id):
raise ValueError("Tenant %s exists", tenant_id)
try:
session = Session()
if tenant_id:
request = TblPendingTenant(tenant_id=tenant_id,
owner=owner,
tenant_name=tenant_name,
desc=desc,
bssid_type=bssid_type)
else:
request = TblPendingTenant(owner=owner,
tenant_name=tenant_name,
desc=desc,
bssid_type=bssid_type)
session.add(request)
session.commit()
except IntegrityError:
session.rollback()
raise ValueError("Tenant name %s exists", tenant_name)
return request.tenant_id
示例2: add_tenant
# 需要导入模块: from empower.persistence import Session [as 别名]
# 或者: from empower.persistence.Session import commit [as 别名]
def add_tenant(self, owner, desc, tenant_name, tenant_id=None):
"""Create new Tenant."""
if tenant_id in self.tenants:
raise ValueError("Tenant %s exists", tenant_id)
try:
session = Session()
if tenant_id:
request = TblTenant(tenant_id=tenant_id,
tenant_name=tenant_name,
owner=owner,
desc=desc)
else:
request = TblTenant(owner=owner,
tenant_name=tenant_name,
desc=desc)
session.add(request)
session.commit()
except IntegrityError:
session.rollback()
raise ValueError("Tenant name %s exists", tenant_name)
self.tenants[request.tenant_id] = \
Tenant(request.tenant_id,
request.tenant_name,
self.accounts[owner].username,
desc)
return request.tenant_id
示例3: add_pnfdev
# 需要导入模块: from empower.persistence import Session [as 别名]
# 或者: from empower.persistence.Session import commit [as 别名]
def add_pnfdev(self, pnfdev):
"""Add a new PNF Dev to the Tenant.
Args:
pnfdev, a PNFDev object
Returns:
None
Raises:
KeyError, if the pnfdev is not available
"""
pnfdevs = getattr(self, pnfdev.ALIAS)
if pnfdev.addr in pnfdevs:
return
pnfdevs[pnfdev.addr] = pnfdev
belongs = TblBelongs(tenant_id=self.tenant_id, addr=pnfdev.addr)
session = Session()
session.add(belongs)
session.commit()
示例4: generate_default_accounts
# 需要导入模块: from empower.persistence import Session [as 别名]
# 或者: from empower.persistence.Session import commit [as 别名]
def generate_default_accounts():
"""Generate default accounts.
Three default accounts (one root account and two user accounts are created
the first time the controller is started.
"""
if not Session().query(TblAccount).all():
LOG.info("Generating default accounts")
session = Session()
session.add(TblAccount(username="root",
password="root",
role="admin",
name="Administrator",
surname="",
email="[email protected]"))
session.add(TblAccount(username="foo",
password="foo",
role="user",
name="Foo",
surname="",
email="[email protected]"))
session.add(TblAccount(username="bar",
password="bar",
role="user",
name="Bar",
surname="",
email="[email protected]"))
session.commit()
示例5: remove_pnfdev
# 需要导入模块: from empower.persistence import Session [as 别名]
# 或者: from empower.persistence.Session import commit [as 别名]
def remove_pnfdev(self, pnfdev):
"""Remove a PNFDev from the Tenant.
Args:
addr, a PNFDev object
Returns:
None
Raises:
KeyError, if the pnfdev is not available
"""
pnfdevs = getattr(self, pnfdev.ALIAS)
if pnfdev.addr not in pnfdevs:
return
del pnfdevs[pnfdev.addr]
belongs = Session().query(TblBelongs) \
.filter(TblBelongs.tenant_id == self.tenant_id,
TblBelongs.addr == pnfdev.addr) \
.first()
session = Session()
session.delete(belongs)
session.commit()
示例6: name
# 需要导入模块: from empower.persistence import Session [as 别名]
# 或者: from empower.persistence.Session import commit [as 别名]
def name(self, name):
"""Set name."""
session = Session()
account = session.query(TblAccount) \
.filter(TblAccount.username == self.username) \
.first()
account.name = name
session.commit()
self._name = name
示例7: surname
# 需要导入模块: from empower.persistence import Session [as 别名]
# 或者: from empower.persistence.Session import commit [as 别名]
def surname(self, surname):
"""Set surname."""
session = Session()
account = Session().query(TblAccount) \
.filter(TblAccount.username == self.username) \
.first()
account.surname = surname
session.commit()
self._surname = surname
示例8: email
# 需要导入模块: from empower.persistence import Session [as 别名]
# 或者: from empower.persistence.Session import commit [as 别名]
def email(self, email):
"""Set email."""
session = Session()
account = Session().query(TblAccount) \
.filter(TblAccount.username == self.username) \
.first()
account.email = email
session.commit()
self._email = email
示例9: add_feed
# 需要导入模块: from empower.persistence import Session [as 别名]
# 或者: from empower.persistence.Session import commit [as 别名]
def add_feed(self):
"""Create new Feed."""
feed_id = self.feed_id
RUNTIME.feeds[feed_id] = Feed(feed_id)
session = Session()
session.add(TblFeed(feed_id=feed_id,
created=RUNTIME.feeds[feed_id].created,
updated=RUNTIME.feeds[feed_id].updated))
session.commit()
return RUNTIME.feeds[feed_id]
示例10: add_pnfdev
# 需要导入模块: from empower.persistence import Session [as 别名]
# 或者: from empower.persistence.Session import commit [as 别名]
def add_pnfdev(self, addr, label):
"""Add PNFDev."""
if addr in self.pnfdevs:
raise KeyError(addr)
self.pnfdevs[addr] = self.PNFDEV(addr, label)
session = Session()
session.add(self.TBL_PNFDEV(addr=addr, label=label))
session.commit()
return self.pnfdevs[addr]
示例11: reject_tenant
# 需要导入模块: from empower.persistence import Session [as 别名]
# 或者: from empower.persistence.Session import commit [as 别名]
def reject_tenant(cls, tenant_id):
"""Reject previously requested Tenant."""
pending = Session().query(TblPendingTenant) \
.filter(TblPendingTenant.tenant_id == tenant_id) \
.first()
if not pending:
raise KeyError(tenant_id)
session = Session()
session.delete(pending)
session.commit()
示例12: remove_denied
# 需要导入模块: from empower.persistence import Session [as 别名]
# 或者: from empower.persistence.Session import commit [as 别名]
def remove_denied(self, sta_addr):
""" Remove entry from ACL. """
deny = Session().query(TblDeny) \
.filter(TblDeny.addr == sta_addr) \
.first()
if not deny:
raise KeyError(sta_addr)
session = Session()
session.delete(deny)
session.commit()
del self.denied[sta_addr]
示例13: remove_allowed
# 需要导入模块: from empower.persistence import Session [as 别名]
# 或者: from empower.persistence.Session import commit [as 别名]
def remove_allowed(self, sta_addr):
""" Remove entry from ACL. """
allow = Session().query(TblAllow) \
.filter(TblAllow.addr == sta_addr) \
.first()
if not allow:
raise KeyError(sta_addr)
session = Session()
session.delete(allow)
session.commit()
del self.allowed[sta_addr]
示例14: remove_imsi2mac
# 需要导入模块: from empower.persistence import Session [as 别名]
# 或者: from empower.persistence.Session import commit [as 别名]
def remove_imsi2mac(self, imsi):
"""Remove IMSI to MAC mapped value from table."""
imsi2mac = Session().query(TblIMSI2MAC) \
.filter(TblIMSI2MAC.imsi == imsi) \
.first()
if not imsi2mac:
raise KeyError(imsi)
session = Session()
session.delete(imsi2mac)
session.commit()
del self.imsi2mac[imsi]
示例15: pnfdev
# 需要导入模块: from empower.persistence import Session [as 别名]
# 或者: from empower.persistence.Session import commit [as 别名]
def pnfdev(self, pnfdev):
"""Set the PNFDev and update database."""
self.__pnfdev = pnfdev
session = Session()
feed = Session().query(TblFeed) \
.filter(TblFeed.feed_id == self.feed_id) \
.first()
if self.pnfdev:
feed.pnfdev_addr = self.pnfdev.addr
else:
feed.pnfdev_addr = None
session.commit()