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


Python sql.get_conn函数代码示例

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


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


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