• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python sql.get_conn函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中mozpool.db.sql.get_conn函数的典型用法代码示例。如果您正苦于以下问题:Python get_conn函数的具体用法?Python get_conn怎么用?Python get_conn使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



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

示例1: get_pxe_config_for_device

def get_pxe_config_for_device(device, image=None):
    """
    Get hardware type for device and use with image to get pxe config name.
    If image is not given, use the device's last image.
    """
    conn = sql.get_conn()
    res = conn.execute(select(
            [model.devices.c.hardware_type_id,
             model.devices.c.last_image_id]).where(
            model.devices.c.name==device))
    row = res.fetchone()
    if row is None:
        raise NotFound
    hw_type_id = row[0]
    if not image:
        img_id = row[1]
    else:
        res = conn.execute(select([model.images.c.id]).where(
                model.images.c.name==image))
        row = res.fetchone()
        if row is None:
            raise NotFound
        img_id = row[0]
    res = sql.get_conn().execute(select(
            [model.pxe_configs.c.name],
            from_obj=[model.image_pxe_configs.join(
                    model.pxe_configs)]).where(and_(
                model.image_pxe_configs.c.hardware_type_id==hw_type_id,
                model.image_pxe_configs.c.image_id==img_id)))
    row = res.fetchone()
    if row is None:
        raise NotFound
    return row[0]
开发者ID:armenzg,项目名称:mozpool,代码行数:33,代码来源:data.py


示例2: set_state

def set_state(tbl, id_col, id_val, state, timeout):
    """
    Set the state of this object, without counters
    """
    sql.get_conn().execute(tbl.update().
                           where(id_col==id_val).
                           values(state=state, state_timeout=timeout))
开发者ID:armenzg,项目名称:mozpool,代码行数:7,代码来源:data.py


示例3: set_counters

def set_counters(tbl, id_col, id_val, counters):
    """
    Set the counters for this object
    """
    sql.get_conn().execute(tbl.update().
                           where(id_col==id_val).
                           values(state_counters=json.dumps(counters)))
开发者ID:armenzg,项目名称:mozpool,代码行数:7,代码来源:data.py


示例4: add_pxe_config

def add_pxe_config(name, description="Boot image",
                  contents="BOOT THIS THINGIE WITH THIS CONFIG",
                  id=None, active=True):
    sql.get_conn().execute(model.pxe_configs.insert(), name=name,
                           description=description,
                           contents=contents,
                           id=id,
                           active=active)
开发者ID:jhopkinsmoz,项目名称:mozpool,代码行数:8,代码来源:util.py


示例5: add_image

def add_image(name, boot_config_keys='[]', can_reuse=False, id=None,
              hidden=False, has_sut_agent=True):
    sql.get_conn().execute(model.images.insert(),
                           id=id,
                           name=name,
                           boot_config_keys=boot_config_keys,
                           can_reuse=can_reuse,
                           hidden=hidden,
                           has_sut_agent=has_sut_agent)
开发者ID:armenzg,项目名称:mozpool,代码行数:9,代码来源:util.py


示例6: update_pxe_config

def update_pxe_config(name, description=None, active=None, contents=None):
    updates = {}
    if description:
        updates["description"] = description
    if active is not None:
        updates["active"] = active
    if contents is not None:
        updates["contents"] = contents
    sql.get_conn().execute(model.pxe_configs.update(model.pxe_configs.c.name == name), **updates)
开发者ID:jhopkinsmoz,项目名称:mozpool,代码行数:9,代码来源:data.py


示例7: insert_device

def insert_device(values):
    """Insert a new device into the DB.  VALUES should be in the dictionary
    format used for inventorysync - see inventorysync.py"""
    values = values.copy()

    # convert imaging_server to its ID, and add a default state and counters
    values["imaging_server_id"] = find_imaging_server_id(values.pop("imaging_server"))
    values["state"] = "new"
    values["state_counters"] = "{}"

    sql.get_conn().execute(model.devices.insert(), [values])
开发者ID:jhopkinsmoz,项目名称:mozpool,代码行数:11,代码来源:data.py


示例8: update_device

def update_device(id, values):
    """Update an existing device with id ID into the DB.  VALUES should be in
    the dictionary format used for inventorysync - see inventorysync.py"""
    values = values.copy()

    # convert imaging_server to its ID, and strip the id
    values["imaging_server_id"] = find_imaging_server_id(values.pop("imaging_server"))
    if "id" in values:
        values.pop("id")

    sql.get_conn().execute(model.devices.update(whereclause=(model.devices.c.id == id)), **values)
开发者ID:jhopkinsmoz,项目名称:mozpool,代码行数:11,代码来源:data.py


示例9: update_device

def update_device(id, values):
    """Update an existing device with id ID into the DB.  VALUES should be in
    the dictionary format used for inventorysync - see inventorysync.py"""
    values = values.copy()

    # convert imaging_server to its ID, and strip the id
    values['imaging_server_id'] = find_imaging_server_id(values.pop('imaging_server'))
    if 'hardware_type' in values or 'hardware_model' in values:
        values['hardware_type_id'] = find_hardware_type_id(
            values.pop('hardware_type'), values.pop('hardware_model'))
    if 'id' in values:
        values.pop('id')

    sql.get_conn().execute(model.devices.update(whereclause=(model.devices.c.id==id)), **values)
开发者ID:armenzg,项目名称:mozpool,代码行数:14,代码来源:data.py


示例10: insert_device

def insert_device(values, _now=None):
    """Insert a new device into the DB.  VALUES should be in the dictionary
    format used for inventorysync - see inventorysync.py"""
    values = values.copy()

    # convert imaging_server to its ID, and add a default state and counters
    values['imaging_server_id'] = find_imaging_server_id(values.pop('imaging_server'))
    values['hardware_type_id'] = find_hardware_type_id(
        values.pop('hardware_type'), values.pop('hardware_model'))
    # set up the state machine in the 'new' state, with an immediate timeout
    values['state'] = 'new'
    values['state_timeout'] = _now or datetime.datetime.now()
    values['state_counters'] = '{}'

    sql.get_conn().execute(model.devices.insert(), [ values ])
开发者ID:armenzg,项目名称:mozpool,代码行数:15,代码来源:data.py


示例11: pxe_config_details

def pxe_config_details(name):
    conn = sql.get_conn()
    res = conn.execute(select([model.pxe_configs], model.pxe_configs.c.name == name))
    row = res.fetchone()
    if row is None:
        raise NotFound
    return {"details": row_to_dict(row, model.pxe_configs, omit_cols=["id"])}
开发者ID:jhopkinsmoz,项目名称:mozpool,代码行数:7,代码来源:data.py


示例12: dump_devices

def dump_devices(*device_names):
    """
    Dump device data.  This returns a list of dictionaries with keys id, name,
    fqdn, invenetory_id, mac_address, imaging_server, relay_info, and state.
    Zero or more device names should be passed in as positional arguments.  If
    none are given, dumps all device data.
    """
    conn = sql.get_conn()
    devices = model.devices
    img_svrs = model.imaging_servers
    stmt = sqlalchemy.select(
        [
            devices.c.id,
            devices.c.name,
            devices.c.fqdn,
            devices.c.inventory_id,
            devices.c.mac_address,
            img_svrs.c.fqdn.label("imaging_server"),
            devices.c.relay_info,
            devices.c.state,
        ],
        from_obj=[devices.join(img_svrs)],
    )
    if device_names:
        id_exprs = []
        for i in device_names:
            id_exprs.append('devices.name=="%s"' % i)
        if len(id_exprs) == 1:
            id_exprs = id_exprs[0]
        else:
            id_exprs = or_(*id_exprs)
        stmt = stmt.where(id_exprs)
    res = conn.execute(stmt)
    return [dict(row) for row in res]
开发者ID:jhopkinsmoz,项目名称:mozpool,代码行数:34,代码来源:data.py


示例13: device_fqdn

def device_fqdn(device):
    """
    Get the fqdn of device.
    """
    res = sql.get_conn().execute(select([model.devices.c.fqdn], model.devices.c.name == device))
    row = res.fetchone()
    return row["fqdn"]
开发者ID:jhopkinsmoz,项目名称:mozpool,代码行数:7,代码来源:data.py


示例14: image_is_reusable

def image_is_reusable(image):
    res = sql.get_conn().execute(select([model.images.c.can_reuse],
                                        model.images.c.name==image))
    row = res.fetchone()
    if not row:
        raise NotFound
    return row[0]
开发者ID:armenzg,项目名称:mozpool,代码行数:7,代码来源:data.py


示例15: testInsertBoard

 def testInsertBoard(self):
     data.insert_device(dict(name='device2', fqdn='device2.fqdn', inventory_id=23,
         mac_address='aabbccddeeff', imaging_server='server2',
             relay_info='relay-2:bank2:relay2'))
     # device with existing imaging_server to test the insert-if-not-found behavior
     data.insert_device(dict(name='device3', fqdn='device3.fqdn', inventory_id=24,
         mac_address='aabbccddeeff', imaging_server='server1',
             relay_info='relay-2:bank2:relay2'))
     conn = sql.get_conn()
     res = conn.execute(model.devices.select())
     self.assertEquals(sorted([ dict(r) for r in res.fetchall() ]),
     sorted([
         {u'state': u'new', u'state_counters': u'{}', u'state_timeout': None,
          u'relay_info': u'relay-2:bank2:relay2', u'name': u'device2',
          u'fqdn': u'device2.fqdn', u'inventory_id': 23, u'imaging_server_id': 2,
          u'boot_config': None, u'mac_address': u'aabbccddeeff', u'id': 2,
          u'last_pxe_config_id': None},
         {u'state': u'new',u'state_counters': u'{}', u'state_timeout': None,
          u'relay_info': u'relay-2:bank2:relay2', u'name': u'device3',
          u'fqdn': u'device3.fqdn', u'inventory_id': 24, u'imaging_server_id': 1,
          u'boot_config': None, u'mac_address': u'aabbccddeeff', u'id': 3,
          u'last_pxe_config_id': None},
         {u'state': u'offline',u'state_counters': u'{}', u'state_timeout': None,
          u'relay_info': u'relay-1:bank1:relay1', u'name': u'device1',
          u'fqdn': u'device1', u'inventory_id': 1, u'imaging_server_id': 1,
          u'boot_config': u'{}', u'mac_address': u'000000000000', u'id': 1,
          u'last_pxe_config_id': None},
         ]))
开发者ID:jhopkinsmoz,项目名称:mozpool,代码行数:28,代码来源:runtests.py


示例16: add

 def add(self, name, message, source="webapp"):
     conn = sql.get_conn()
     values = {self.foreign_key_col.name: self._get_object_id(name),
               "ts": datetime.datetime.now(),
               "source": source,
               "message": message}
     conn.execute(self.logs_table.insert(), values)
开发者ID:armenzg,项目名称:mozpool,代码行数:7,代码来源:logs.py


示例17: request_config

def request_config(request_id):
    conn = sql.get_conn()
    res = conn.execute(
        select(
            [
                model.requests.c.requested_device,
                model.requests.c.assignee,
                model.requests.c.expires,
                model.requests.c.boot_config,
            ],
            model.requests.c.id == request_id,
        )
    )
    row = res.fetchone()
    if row is None:
        raise NotFound

    request = {
        "id": request_id,
        "requested_device": row[0].encode("utf-8"),
        "assignee": row[1].encode("utf-8"),
        "expires": row[2].isoformat(),
        "boot_config": row[3].encode("utf-8"),
        "assigned_device": "",
        "url": "http://%s/api/request/%d/" % (config.get("server", "fqdn"), request_id),
    }

    assigned_device = get_assigned_device(request_id)
    if assigned_device:
        request["assigned_device"] = assigned_device
    return request
开发者ID:jhopkinsmoz,项目名称:mozpool,代码行数:31,代码来源:data.py


示例18: object_status

def object_status(tbl, id_col, id_val, logs_obj):
    """
    Get the status of device.
    """
    res = sql.get_conn().execute(select([tbl.c.state], id_col == id_val))
    row = res.fetchall()[0]
    return {"state": row["state"].encode("utf-8"), "log": logs_obj.get(id_val)}
开发者ID:jhopkinsmoz,项目名称:mozpool,代码行数:7,代码来源:data.py


示例19: add_request

def add_request(server, assignee="slave", state="new", expires=None,
                device='any', boot_config='{}'):
    if not expires:
        expires = datetime.datetime.now() + datetime.timedelta(hours=1)
    conn = sql.get_conn()
    server_id = conn.execute(select([model.imaging_servers.c.id],
                                    model.imaging_servers.c.fqdn==server)).fetchone()[0]
    if server_id is None:
        raise data.NotFound
    res = conn.execute(model.requests.insert(),
                       imaging_server_id=server_id,
                       requested_device=device,
                       assignee=assignee,
                       expires=expires,
                       boot_config=boot_config,
                       state=state,
                       state_counters='{}')
    request_id = res.lastrowid
    if device and state != 'closed':
        device_id = conn.execute(select(
                [model.devices.c.id],
                model.devices.c.name==device)).fetchone()[0]
        conn.execute(model.device_requests.insert(),
                     request_id=request_id,
                     device_id=device_id)
开发者ID:jhopkinsmoz,项目名称:mozpool,代码行数:25,代码来源:util.py


示例20: add_device

def add_device(device, server="server", state="offline",
              mac_address="000000000000",
              log=[], config='{}', relayinfo="",
              last_image_id=None, hardware_type_id=1,
              environment=None):
    global inventory_id
    conn = sql.get_conn()
    id = conn.execute(select([model.imaging_servers.c.id],
                              model.imaging_servers.c.fqdn==server)).fetchone()[0]
    if id is None:
        raise data.NotFound
    conn.execute(model.devices.insert(),
                 name=device,
                 fqdn=device, #XXX
                 inventory_id=inventory_id,
                 state=state,
                 state_counters='{}',
                 mac_address=mac_address,
                 imaging_server_id=id,
                 relay_info=relayinfo,
                 boot_config=config,
                 last_image_id=last_image_id,
                 hardware_type_id=hardware_type_id,
                 environment=environment)
    inventory_id += 1
开发者ID:armenzg,项目名称:mozpool,代码行数:25,代码来源:util.py



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python mozprocess.ProcessHandler类代码示例发布时间:2022-05-27
下一篇:
Python path.splitext函数代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap