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


Python Session.add方法代码示例

本文整理汇总了Python中empower.persistence.Session.add方法的典型用法代码示例。如果您正苦于以下问题:Python Session.add方法的具体用法?Python Session.add怎么用?Python Session.add使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在empower.persistence.Session的用法示例。


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

示例1: add_pnfdev

# 需要导入模块: from empower.persistence import Session [as 别名]
# 或者: from empower.persistence.Session import add [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()
开发者ID:archam,项目名称:empower-runtime,代码行数:27,代码来源:tenant.py

示例2: request_tenant

# 需要导入模块: from empower.persistence import Session [as 别名]
# 或者: from empower.persistence.Session import add [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
开发者ID:herlesupreeth,项目名称:5G-Controller,代码行数:36,代码来源:core.py

示例3: add_tenant

# 需要导入模块: from empower.persistence import Session [as 别名]
# 或者: from empower.persistence.Session import add [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
开发者ID:archam,项目名称:empower-runtime,代码行数:36,代码来源:core.py

示例4: add_feed

# 需要导入模块: from empower.persistence import Session [as 别名]
# 或者: from empower.persistence.Session import add [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]
开发者ID:archam,项目名称:empower-runtime,代码行数:14,代码来源:energinoserver.py

示例5: add_pnfdev

# 需要导入模块: from empower.persistence import Session [as 别名]
# 或者: from empower.persistence.Session import add [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]
开发者ID:gastontelfe,项目名称:empower-runtime,代码行数:15,代码来源:pnfpserver.py

示例6: add_denied

# 需要导入模块: from empower.persistence import Session [as 别名]
# 或者: from empower.persistence.Session import add [as 别名]
    def add_denied(self, sta_addr, label):
        """ Add entry to ACL. """

        deny = Session().query(TblDeny) \
                        .filter(TblDeny.addr == sta_addr) \
                        .first()
        if deny:
            raise ValueError(sta_addr)

        session = Session()
        session.add(TblDeny(addr=sta_addr, label=label))
        session.commit()

        acl = ACL(sta_addr, label)
        self.denied[sta_addr] = acl

        return acl
开发者ID:Panagiotis-Kon,项目名称:empower-runtime,代码行数:19,代码来源:core.py

示例7: add_allowed

# 需要导入模块: from empower.persistence import Session [as 别名]
# 或者: from empower.persistence.Session import add [as 别名]
    def add_allowed(self, sta_addr, label):
        """ Add entry to ACL. """

        allow = Session().query(TblAllow) \
                         .filter(TblAllow.addr == sta_addr) \
                         .first()
        if allow:
            raise ValueError(sta_addr)

        session = Session()
        session.add(TblAllow(addr=sta_addr, label=label))
        session.commit()

        acl = ACL(sta_addr, label)
        self.allowed[sta_addr] = acl

        return acl
开发者ID:Panagiotis-Kon,项目名称:empower-runtime,代码行数:19,代码来源:core.py

示例8: add_imsi2mac

# 需要导入模块: from empower.persistence import Session [as 别名]
# 或者: from empower.persistence.Session import add [as 别名]
    def add_imsi2mac(self, imsi, addr):
        """Add IMSI to MAC mapped value to table."""

        imsi2mac = Session().query(TblIMSI2MAC) \
                         .filter(TblIMSI2MAC.imsi == imsi) \
                         .first()
        if imsi2mac:
            raise ValueError(imsi)

        try:

            session = Session()

            session.add(TblIMSI2MAC(imsi=imsi, addr=addr))
            session.commit()

        except IntegrityError:
            session.rollback()
            raise ValueError("MAC address must be unique %s", addr)

        self.imsi2mac[imsi] = addr
开发者ID:5g-empower,项目名称:empower-runtime,代码行数:23,代码来源:core.py

示例9: generate_default_accounts

# 需要导入模块: from empower.persistence import Session [as 别名]
# 或者: from empower.persistence.Session import add [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()
开发者ID:Panagiotis-Kon,项目名称:empower-runtime,代码行数:33,代码来源:core.py

示例10: create_account

# 需要导入模块: from empower.persistence import Session [as 别名]
# 或者: from empower.persistence.Session import add [as 别名]
    def create_account(self, username, password, role, name, surname, email):
        """Create a new account."""

        if username in self.accounts:
            LOG.error("'%s' already registered", username)
            raise ValueError("%s already registered" % username)

        session = Session()
        account = TblAccount(username=username,
                             password=password,
                             role=role,
                             name=name,
                             surname=surname,
                             email=email)

        session.add(account)
        session.commit()

        self.accounts[account.username] = Account(account.username,
                                                  account.password,
                                                  account.name,
                                                  account.surname,
                                                  account.email,
                                                  account.role)
开发者ID:Panagiotis-Kon,项目名称:empower-runtime,代码行数:26,代码来源:core.py


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