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


Python r.table函数代码示例

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


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

示例1: insert_app_and_delete_old

 def insert_app_and_delete_old(self, app, lower_apps, conn=None):
     try:
         (r.table(AppCollections.SupportedAppsPerAgent).insert(app).run(conn))
         for lower_app in lower_apps:
             (r.table(AppCollections.AppsPerAgent).get(lower_app[AppsPerAgentKey.Id]).delete().run(conn))
     except Exception as e:
         logger.exception(e)
开发者ID:ttysteale,项目名称:vFense,代码行数:7,代码来源:syncer.py

示例2: fetch_agent_info

def fetch_agent_info(agent_id, keys_to_pluck=None, conn=None):
    """Retrieve information of an agent
    Args:
        agent_id(str): 36 character uuid of the agent you are updating

    Kwargs:
        keys_to_pluck(list): (Optional) Specific keys that you are retrieving
        from the database

    Basic Usage:
        >>> from vFense.core.agent._db import fetch_agent_info
        >>> agent_id = '52faa1db-290a-47a7-a4cf-e4ad70e25c38'
        >>> keys_to_pluck = ['production_level', 'needs_reboot']
        >>> fetch_agent_info(agent_id, keys_to_pluck)

    Return:
        Dictionary of the agent data
        {
            u'agent_id': u'52faa1db-290a-47a7-a4cf-e4ad70e25c38',
            u'production_level': u'Development'
        }
    """
    data = {}
    try:
        if agent_id and keys_to_pluck:
            data = r.table(AgentCollections.Agents).get(agent_id).merge(Merge.TAGS).pluck(keys_to_pluck).run(conn)

        elif agent_id and not keys_to_pluck:
            data = r.table(AgentCollections.Agents).get(agent_id).merge(Merge.TAGS).run(conn)

    except Exception as e:
        logger.exception(e)

    return data
开发者ID:ttysteale,项目名称:vFense,代码行数:34,代码来源:_db.py

示例3: delete_multiple_jobs

def delete_multiple_jobs(job_ids, conn=None):
    """Delete all multiple jobs in the queue by job ids.
        DO NOT CALL DIRECTLY
    Args:
        job_ids (list): List of job ids to delete ['id1', 'id2']

    Basic Usage:
        >>> from vFense.queue._db import delete_multiple_jobs
        >>> job_ids = ['id1', 'id2']
        >>> delete_multiple_jobs(job_ids)

    Returns:
        Tuple (status_code, count, error, generated ids)
        >>> (2001, 1, None, [])
    """
    jobs_deleted = 0
    try:
        if isinstance(job_ids, list):
            jobs = r.table(QueueCollections.Agent).get_all(*job_ids).delete().run(conn)
            jobs_deleted = jobs.get("deleted")

        else:
            jobs = r.table(QueueCollections.Agent).get(job_ids).delete().run(conn)
            jobs_deleted = jobs.get("deleted")

    except Exception as e:
        logger.exception(e)

    return jobs_deleted
开发者ID:ttysteale,项目名称:vFense,代码行数:29,代码来源:_db.py

示例4: get_users_of_customer

def get_users_of_customer(customer_name=None, conn=None):

    if not customer_name:
        return None

    users = (
        r.table(Collection.UsersPerCustomer)
        .get_all(
            customer_name,
            index=UsersPerCustomerKey.CustomerId
        )
        .pluck(UsersPerCustomerKey.UserId)
        .eq_join(
            UsersPerCustomerKey.UserId,
            r.table(Collection.Users),
            index=UserKey.UserName
        )
        .zip()
        .run(conn)
    )

    u = []
    for user in users:
        u.append(user)

    return u
开发者ID:akaasjager,项目名称:vFense,代码行数:26,代码来源:actions.py

示例5: get_customers_of_user

def get_customers_of_user(user_name=None, conn=None):

    if not user_name:
        return None

    customers = (
        r.table(Collection.UsersPerCustomer)
        .get_all(
            user_name,
            index=UsersPerCustomerKey.UserId
        )
        .pluck(UsersPerCustomerKey.CustomerId)
        .eq_join(
            UsersPerCustomerKey.CustomerId,
            r.table(Collection.Customers),
            index=CustomerKey.CustomerName
        )
        .zip()
        .run(conn)
    )

    c = []
    for customer in customers:
        c.append(customer)

    return c
开发者ID:akaasjager,项目名称:vFense,代码行数:26,代码来源:actions.py

示例6: update_supported_apps

def update_supported_apps(json_data):

    try:
        rv_q = Queue("downloader", connection=RQ_PKG_POOL)
        conn = db_connect()

        inserted_count = 0
        all_customers = list(r.table(Collection.Customers).map(lambda x: x[CustomerKey.CustomerName]).run(conn))

        for i in range(len(json_data)):
            json_data[i][SupportedAppsKey.Customers] = all_customers
            json_data[i][SupportedAppsKey.ReleaseDate] = r.epoch_time(json_data[i][SupportedAppsKey.ReleaseDate])
            json_data[i][SupportedAppsKey.FilesDownloadStatus] = PackageCodes.FilePendingDownload
            json_data[i][SupportedAppsKey.Hidden] = "no"
            json_data[i][SupportedAppsKey.VulnerabilityId] = ""

            insert_app_data(json_data[i], DownloadCollections.LatestDownloadedSupported)
            file_data = json_data[i].get(SupportedAppsKey.FileData)
            add_file_data(json_data[i][SupportedAppsKey.AppId], file_data)
            data_to_update = {SupportedAppsKey.Customers: all_customers}
            exists = r.table(AppCollections.SupportedApps).get(json_data[i][SupportedAppsKey.AppId]).run(conn)

            if exists:
                updated = (
                    r.table(AppCollections.SupportedApps)
                    .get(json_data[i][SupportedAppsKey.AppId])
                    .update(data_to_update)
                    .run(conn)
                )

            else:
                updated = r.table(AppCollections.SupportedApps).insert(json_data[i]).run(conn)

            rv_q.enqueue_call(
                func=download_all_files_in_app,
                args=(
                    json_data[i][SupportedAppsKey.AppId],
                    json_data[i][SupportedAppsKey.OsCode],
                    None,
                    file_data,
                    0,
                    AppCollections.SupportedApps,
                ),
                timeout=86400,
            )

            inserted_count += updated["inserted"]

        conn.close()

        update_apps = IncomingSupportedApps()
        update_apps.sync_supported_updates_to_all_agents(json_data)

    except Exception as e:
        logger.exception(e)
开发者ID:ttysteale,项目名称:vFense,代码行数:55,代码来源:syncer.py

示例7: fetch_agent_ids

def fetch_agent_ids(customer_name=None, agent_os=None, conn=None):
    """Retrieve a list of agent ids
    Kwargs:
        customer_name (str): Name of the customer, where the agent is located
        agent_os (str):  The os code you are filtering on.
            (linux or windows or darwin)

    Basic Usage:
        >>> from vFense.core.agent._db import fetch_agent_ids
        >>> customer_name = 'default'
        >>> os_code = 'os_code'
        >>> fetch_agent_ids(customer_name, os_code)

    Returns:
        List of agent ids
        [
            u'52faa1db-290a-47a7-a4cf-e4ad70e25c38',
            u'3ea8fd7a-8aad-40da-aff0-8da6fa5f8766'
        ]
    """
    data = []
    try:
        if customer_name and agent_os:
            data = list(
                r.table(AgentCollections.Agents)
                .get_all(customer_name, index=AgentIndexes.CustomerName)
                .filter({AgentKey.OsCode: agent_os})
                .map(lambda x: x[AgentKey.AgentId])
                .run(conn)
            )

        elif customer_name and not agent_os:
            data = list(
                r.table(AgentCollections.Agents)
                .get_all(customer_name, index=AgentIndexes.CustomerName)
                .map(lambda x: x[AgentKey.AgentId])
                .run(conn)
            )

        elif agent_os and not customer_name:
            data = list(
                r.table(AgentCollections.Agents)
                .filter({AgentKey.OsCode: agent_os})
                .map(lambda x: x[AgentKey.AgentId])
                .run(conn)
            )

        elif not agent_os and not customer_name:
            data = list(r.table(AgentCollections.Agents).map(lambda x: x[AgentKey.AgentId]).run(conn))

    except Exception as e:
        logger.exception(e)

    return data
开发者ID:ttysteale,项目名称:vFense,代码行数:54,代码来源:_db.py

示例8: get_severity_bar_chart_stats_for_tag

def get_severity_bar_chart_stats_for_tag(username, customer_name,
                                         uri, method, tag_id, conn=None):
    try:
        sevs = (
            r
            .table(TagsPerAgentCollection, use_outdated=True)
            .get_all(tag_id, index=TagsPerAgentIndexes.TagId)
            .pluck(TagsPerAgentKey.AgentId)
            .eq_join(
                lambda x: [
                    CommonAppKeys.AVAILABLE,
                    x[AppsPerAgentKey.AgentId]
                ],
                r.table(AppCollections.AppsPerAgent),
                index=AppsPerAgentIndexes.StatusAndAgentId
            )
            .map(
                {
                    AppsKey.AppId: r.row['right'][AppsKey.AppId],
                }
            )
            .eq_join(AppsKey.AppId, r.table(AppCollections.UniqueApplications))
            .filter(
                lambda x: x['right'][AppsKey.Hidden] == CommonKeys.NO
            )
            .map(
                {
                    AppsKey.AppId: r.row['right'][AppsKey.AppId],
                    AppsKey.RvSeverity: r.row['right'][AppsKey.RvSeverity]
                }
            )
            .group(AppsKey.RvSeverity)
            .count()
            .ungroup()
            .order_by(r.desc('reduction'))
            .run(conn)
        )
        data = app_stats_by_severity(sevs)

        results = (
            GenericResults(
                username, uri, method
            ).information_retrieved(data, len(CommonSeverityKeys.ValidRvSeverities))
        )

    except Exception as e:
        results = (
            GenericResults(
                username, uri, method
            ).something_broke('widget severity stats', 'widget', e)
        )
        logger.exception(results)

    return(results)
开发者ID:akaasjager,项目名称:vFense,代码行数:54,代码来源:stats.py

示例9: validate_permission_for_user

def validate_permission_for_user(username, customer_name, permission, conn=None):
    permission_exist = False
    try:
        is_empty = (
            r
            .table(GroupCollections.GroupsPerUser)
            .get_all(username, index=GroupsPerUserIndexes.UserName)
            .filter({GroupsPerUserKeys.CustomerName: customer_name})
            .eq_join(
                lambda group: group[GroupsPerUserKeys.GroupName],
                r.table(GroupCollections.Groups),
                index=GroupIndexes.GroupName
            )
            .zip()
            .filter(r.row[GroupKeys.Permissions].contains(permission))
            .is_empty()
            .run(conn)
        )
        if not is_empty:
            permission_exist = True

        else:
            is_admin_empty = (
                r
                .table(GroupCollections.GroupsPerUser)
                .get_all(username, index=GroupsPerUserIndexes.UserName)
                .filter({GroupsPerUserKeys.CustomerName: customer_name})
                .eq_join(
                    lambda group: group[GroupsPerUserKeys.GroupName],
                    r.table(GroupCollections.Groups),
                    index=GroupIndexes.GroupName
                )
                .zip()
                .filter(
                    r.row[GroupKeys.Permissions].contains(
                        Permissions.ADMINISTRATOR
                    )
                )
                .is_empty()
                .run(conn)
            )

            if not is_admin_empty:
                permission_exist = True

    except Exception as e:
        logger.exception(e)

    return(permission_exist)
开发者ID:akaasjager,项目名称:vFense,代码行数:49,代码来源:_db.py

示例10: get_all_expired_jobs

def get_all_expired_jobs(now=None, conn=None):
    """Retrieve all expired jobs
    Kwargs:
        now (float): The epoch time to compare against,
            during the retrieval process.
            Default: (Is to use the epoch time of right now)

    Basic Usage:
        >>> from vFense.queue._db import get_all_expired_jobs
        >>> now = 1396780822.0
        >>> get_all_expired_jobs(now)

    Returns:
        List of dictionairies
        [
            {
                "agent_queue_ttl": 1396778416, 
                "plugin": "rv", 
                "order_id": 1, 
                "server_queue_ttl": 1396777816, 
                "agent_id": "d4119b36-fe3c-4973-84c7-e8e3d72a3e02", 
                "created_time": 1396777216, 
                "operation_id": "b95837d9-5df7-4ab0-9449-a7be196a2b12", 
                "operation": "updatesapplications", 
                "id": "f9817e07-6877-4857-aef3-e80f57022ac8", 
                "expire_minutes": 10, 
                "customer_name": "default"
            }
        ]
    """
    expired_jobs = []
    try:
        if not now:
            expired_jobs = list(
                r.table(QueueCollections.Agent).filter(lambda x: x[AgentQueueKey.ServerQueueTTL] <= r.now()).run(conn)
            )

        else:
            expired_jobs = list(
                r.table(QueueCollections.Agent)
                .filter(lambda x: x[AgentQueueKey.ServerQueueTTL].to_epoch_time() <= now)
                .run(conn)
            )

    except Exception as e:
        logger.exception(e)

    return expired_jobs
开发者ID:ttysteale,项目名称:vFense,代码行数:48,代码来源:_db.py

示例11: get_all_stats_by_appid

def get_all_stats_by_appid(
    username, customer_name, uri, method, app_id, collection=AppCollections.AppsPerAgent, conn=None
):

    if collection == AppCollections.AppsPerAgent:
        CurrentAppsPerAgentCollection = AppCollections.AppsPerAgent
        CurrentAppsPerAgentKey = AppsPerAgentKey
        CurrentAppsPerAgentIndexes = AppsPerAgentIndexes

    elif collection == AppCollections.SupportedAppsPerAgent:
        CurrentAppsPerAgentCollection = AppCollections.SupportedAppsPerAgent
        CurrentAppsPerAgentKey = SupportedAppsPerAgentKey
        CurrentAppsPerAgentIndexes = SupportedAppsPerAgentIndexes

    elif collection == AppCollections.CustomAppsPerAgent:
        CurrentAppsPerAgentCollection = AppCollections.CustomAppsPerAgent
        CurrentAppsPerAgentKey = CustomAppsPerAgentKey
        CurrentAppsPerAgentIndexes = CustomAppsPerAgentIndexes

    elif collection == AppCollections.vFenseAppsPerAgent:
        CurrentAppsPerAgentCollection = AppCollections.vFenseAppsPerAgent
        CurrentAppsPerAgentKey = AgentAppsPerAgentKey
        CurrentAppsPerAgentIndexes = AgentAppsPerAgentIndexes

    try:
        data = []
        apps = (
            r.table(CurrentAppsPerAgentCollection)
            .get_all([app_id, customer_name], index=CurrentAppsPerAgentIndexes.AppIdAndCustomer)
            .group(CurrentAppsPerAgentKey.Status)
            .count()
            .ungroup()
            .run(conn)
        )
        if apps:
            for i in apps:
                new_data = i["reduction"]
                new_data = {
                    CurrentAppsPerAgentKey.Status: i["group"],
                    CommonAppKeys.COUNT: i["reduction"],
                    CommonAppKeys.NAME: i["group"].capitalize(),
                }
                data.append(new_data)

        statuses = map(lambda x: x["status"], data)
        difference = set(CommonAppKeys.ValidPackageStatuses).difference(statuses)
        if len(difference) > 0:
            for status in difference:
                status = {CommonAppKeys.COUNT: 0, CommonAppKeys.STATUS: status, CommonAppKeys.NAME: status.capitalize()}
                data.append(status)

        results = GenericResults(username, uri, method).information_retrieved(data, len(data))

        logger.info(results)

    except Exception as e:
        results = GenericResults(username, uri, method).something_broke("getting_pkg_stats", "updates", e)

        logger.info(results)
    return results
开发者ID:ttysteale,项目名称:vFense,代码行数:60,代码来源:db_calls.py

示例12: insert_agent_data

def insert_agent_data(agent_data, conn=None):
    """ Insert a new agent and its properties into the database
        This function should not be called directly.
    Args:
        agent_data (list|dict): Can either be a list of
            dictionaries or a dictionary of the data
            you are inserting.

    Basic Usage:
        >>> from vFense.core.agent._db import insert_agent_data
        >>> agent_data = {'customer_name': 'vFense', 'needs_reboot': 'no'}
        >>> insert_agent_data(agent_data)

    Return:
        Tuple (status_code, count, error, generated ids)
        >>> (2001, 1, None, [])
    """
    data = {}
    try:
        data = r.table(AgentCollections.Agents).insert(agent_data).run(conn)

    except Exception as e:
        logger.exception(e)

    return data
开发者ID:ttysteale,项目名称:vFense,代码行数:25,代码来源:_db.py

示例13: _delete_old_supported_apps_from_agent

 def _delete_old_supported_apps_from_agent(self, agent_id, conn):
     (
         r.table(AppCollections.SupportedAppsPerAgent)
         .get_all(agent_id, index=SupportedAppsPerAgentIndexes.AgentId)
         .delete()
         .run(conn)
     )
开发者ID:ttysteale,项目名称:vFense,代码行数:7,代码来源:syncer.py

示例14: fetch_supported_os_strings

def fetch_supported_os_strings(customer_name, conn=None):
    """Retrieve all the operating systems that is in the database
    Args:
        customer_name (str): Name of the customer, where the agent is located

    Basic Usage:
        >>> from vFense.core.agent._db import fetch_supported_os_strings
        >>> customer_name = 'default'
        >>> fetch_supported_os_strings(customer_name)

    Returns:
        List of available operating system strings in the database
        [
            u'CentOS 6.5',
            u'Ubuntu 12.04',
            u'Windows 7 Professional Service Pack 1',
            u'Windows 8.1 '
        ]
    """
    data = []
    try:
        data = (
            r.table(AgentCollections.Agents)
            .get_all(customer_name, index=AgentIndexes.CustomerName)
            .pluck(AgentKey.OsString)
            .distinct()
            .map(lambda x: x[AgentKey.OsString])
            .run(conn)
        )

    except Exception as e:
        logger.exception(e)

    return data
开发者ID:ttysteale,项目名称:vFense,代码行数:34,代码来源:_db.py

示例15: get_email_config

def get_email_config(customer_name=None, conn=None):
    mail_config = None
    config_exists = False
    msg = ""
    try:
        mail_config = list(
            r.table(NotificationCollections.NotificationPlugins)
            .get_all(customer_name, index=NotificationPluginIndexes.CustomerName)
            .filter({NotificationPluginKeys.PluginName: "email"})
            .run(conn)
        )
        if not mail_config:
            mail_config = {
                "modified_time": "",
                "username": "",
                "password": "",
                "server": "",
                "port": "",
                "is_tls": "",
                "is_ssl": "",
                "from_email": "",
                "to_email": "",
                "last_modify_user": "",
            }
            msg = "mail_config does not exist"
        else:
            config_exists = True

    except Exception as e:
        msg = "Failed to get mail config: %s" % (str(e))
        logger.exception(e)

    return {"pass": config_exists, "message": msg, "data": mail_config}
开发者ID:ttysteale,项目名称:vFense,代码行数:33,代码来源:mailer.py


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