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


Python OrderedDict.items方法代码示例

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


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

示例1: pprint_network

# 需要导入模块: from synnefo.lib.ordereddict import OrderedDict [as 别名]
# 或者: from synnefo.lib.ordereddict.OrderedDict import items [as 别名]
def pprint_network(network, display_mails=False, stdout=None, title=None):
    if stdout is None:
        stdout = sys.stdout
    if title is None:
        title = "State of Network %s in DB" % network.id

    ucache = UserCache(ASTAKOS_AUTH_URL, ASTAKOS_TOKEN)
    userid = network.userid

    db_network = OrderedDict([
        ("name", network.name),
        ("backend-name", network.backend_id),
        ("state", network.state),
        ("userid", userid),
        ("username", ucache.get_name(userid) if display_mails else None),
        ("public", network.public),
        ("floating_ip_pool", network.floating_ip_pool),
        ("external_router", network.external_router),
        ("drained", network.drained),
        ("MAC prefix", network.mac_prefix),
        ("flavor", network.flavor),
        ("link", network.link),
        ("mode", network.mode),
        ("deleted", network.deleted),
        ("tags", "), ".join(network.backend_tag)),
        ("action", network.action)])

    pprint_table(stdout, db_network.items(), None, separator=" | ",
                 title=title)
开发者ID:antonis-m,项目名称:synnefo,代码行数:31,代码来源:pprint.py

示例2: pprint_ippool

# 需要导入模块: from synnefo.lib.ordereddict import OrderedDict [as 别名]
# 或者: from synnefo.lib.ordereddict.OrderedDict import items [as 别名]
def pprint_ippool(subnet, stdout=None, title=None):
    """Pretty print IP Pools of a subnet. Only IPv4 subnets have IP Pools"""

    if int(subnet.ipversion) != 4:
        return 0

    if stdout is None:
        stdout = sys.stdout

    stdout.write("IP Pools of subnet %s:\n\n" % subnet.id)

    for pool in subnet.get_ip_pools():
        size = pool.pool_size
        available = pool.available.count()
        info = OrderedDict([("First_IP", pool.return_start()),
                            ("Last_IP", pool.return_end()),
                            ("Size", size),
                            ("Available", available)])
        pprint_table(stdout, info.items(), None, separator=" | ", title=None)

        reserved = [pool.index_to_value(index)
                    for index, ip in enumerate(pool.reserved[:size])
                    if ip is False]

        if reserved != []:
            stdout.write("\nExternally Reserved IPs:\n\n")
            stdout.write(", ".join(reserved) + "\n")

        ip_sum = pool.available[:size] & pool.reserved[:size]
        pprint_pool(None, bitarray_to_map(ip_sum), 80, stdout)
        stdout.write("\n\n")
开发者ID:antonis-m,项目名称:synnefo,代码行数:33,代码来源:pprint.py

示例3: pprint_volume

# 需要导入模块: from synnefo.lib.ordereddict import OrderedDict [as 别名]
# 或者: from synnefo.lib.ordereddict.OrderedDict import items [as 别名]
def pprint_volume(volume, display_mails=False, stdout=None, title=None):
    if stdout is None:
        stdout = sys.stdout
    if title is None:
        title = "State of volume %s in DB" % volume.id

    ucache = UserCache(ASTAKOS_AUTH_URL, ASTAKOS_TOKEN)
    userid = volume.userid

    volume_type = volume.volume_type
    volume_dict = OrderedDict([
        ("id", volume.id),
        ("size", volume.size),
        ("disk_template", volume_type.template),
        ("disk_provider", volume_type.provider),
        ("server_id", volume.machine_id),
        ("userid", volume.userid),
        ("project", volume.project),
        ("username", ucache.get_name(userid) if display_mails else None),
        ("index", volume.index),
        ("name", volume.name),
        ("state", volume.status),
        ("delete_on_termination", volume.delete_on_termination),
        ("deleted", volume.deleted),
        ("backendjobid", volume.backendjobid),
        ])

    pprint_table(stdout, volume_dict.items(), None, separator=" | ",
                 title=title)
开发者ID:AthinaB,项目名称:synnefo,代码行数:31,代码来源:pprint.py

示例4: pprint_floating_ip

# 需要导入模块: from synnefo.lib.ordereddict import OrderedDict [as 别名]
# 或者: from synnefo.lib.ordereddict.OrderedDict import items [as 别名]
def pprint_floating_ip(ip, display_mails=False, stdout=None, title=None):
    if stdout is None:
        stdout = sys.stdout
    if title is None:
        title = "Floating IP %s" % ip.id

    ucache = UserCache(ASTAKOS_AUTH_URL, ASTAKOS_TOKEN)
    userid = ip.userid

    vtype_info = OrderedDict([
        ("id", ip.id),
        ("address", ip.address),
        ("network", ip.network_id),
        ("port", ip.nic_id),
        ("server", ip.nic.machine_id),
        ("userid", userid),
        ("username", ucache.get_name(userid) if (display_mails and userid is
                                                 not None) else None),
        ("project", ip.project),
        ("shared_to_project", ip.shared_to_project),
        ("deleted", ip.deleted),
        ("created", ip.created),
        ("updated", ip.updated),
    ])

    pprint_table(stdout, vtype_info.items(), separator=" | ", title=title)
开发者ID:gvsurenderreddy,项目名称:synnefo-1,代码行数:28,代码来源:pprint.py

示例5: pprint_server_in_ganeti

# 需要导入模块: from synnefo.lib.ordereddict import OrderedDict [as 别名]
# 或者: from synnefo.lib.ordereddict.OrderedDict import items [as 别名]
def pprint_server_in_ganeti(server, print_jobs=False, stdout=None, title=None):
    if stdout is None:
        stdout = sys.stdout
    if title is None:
        title = "State of Server %s in Ganeti" % server.id

    client = server.get_client()
    try:
        server_info = client.GetInstance(server.backend_vm_id)
    except GanetiApiError as e:
        if e.code == 404:
            stdout.write("Server '%s' does not exist in backend '%s'\n"
                         % (server.id, server.backend.clustername))
            return
        raise e
    server.put_client(client)

    GANETI_INSTANCE_FIELDS = ('name', 'oper_state', 'admin_state', 'status',
                              'pnode', 'snode', 'network_port',
                              'disk_template', 'disk_usage',
                              'oper_ram', 'oper_vcpus', 'mtime')
    server_dict = OrderedDict([(k, server_info.get(k))
                              for k in GANETI_INSTANCE_FIELDS])

    pprint_table(stdout, server_dict.items(), None, separator=" | ",
                 title=title)
    stdout.write("\n")

    nics = nics_from_instance(server_info)
    nics_keys = ["ip", "mac", "name", "network"]
    nics_values = [[nic[key] for key in nics_keys] for nic in nics]
    pprint_table(stdout, nics_values, nics_keys, separator=" | ",
                 title="NICs of Server %s in Ganeti" % server.id)

    stdout.write("\n")
    disks = disks_from_instance(server_info)
    disks_keys = ["name", "size"]
    disks_values = [[disk[key] for key in disks_keys] for disk in disks]
    pprint_table(stdout, disks_values, disks_keys, separator=" | ",
                 title="Disks of Server %s in Ganeti" % server.id)

    if not print_jobs:
        return

    client = server.get_client()
    jobs = client.GetJobs(bulk=True)
    server_jobs = filter(
        lambda x: server.backend_vm_id in (" ".join(x.get("summary"))), jobs)

    GANETI_JOB_FIELDS = ('id', 'status', 'summary', 'opresult', 'opstatus',
                         'oplog', 'start_ts', 'end_ts')
    for server_job in server_jobs:
        stdout.write("\n")
        values = [server_job.get(k) for k in GANETI_JOB_FIELDS]
        pprint_table(stdout, zip(GANETI_JOB_FIELDS, values), None,
                     separator=" | ",
                     title="Ganeti Job %s" % server_job["id"])
    server.put_client(client)
开发者ID:AthinaB,项目名称:synnefo,代码行数:60,代码来源:pprint.py

示例6: pprint_volume_type

# 需要导入模块: from synnefo.lib.ordereddict import OrderedDict [as 别名]
# 或者: from synnefo.lib.ordereddict.OrderedDict import items [as 别名]
def pprint_volume_type(volume_type, stdout=None, title=None):
    if stdout is None:
        stdout = sys.stdout
    if title is None:
        title = "Volume Type %s" % volume_type.id

    vtype_info = OrderedDict([
        ("name", volume_type.name),
        ("disk template", volume_type.disk_template),
        ("deleted", volume_type.deleted),
    ])

    pprint_table(stdout, vtype_info.items(), separator=" | ", title=title)
开发者ID:AthinaB,项目名称:synnefo,代码行数:15,代码来源:pprint.py

示例7: pprint_port

# 需要导入模块: from synnefo.lib.ordereddict import OrderedDict [as 别名]
# 或者: from synnefo.lib.ordereddict.OrderedDict import items [as 别名]
def pprint_port(port, stdout=None, title=None):
    if stdout is None:
        stdout = sys.stdout
    if title is None:
        title = "State of Port %s in DB" % port.id
    port = OrderedDict([
        ("id", port.id),
        ("name", port.name),
        ("userid", port.userid),
        ("server", port.machine_id),
        ("network", port.network_id),
        ("device_owner", port.device_owner),
        ("mac", port.mac),
        ("state", port.state)])

    pprint_table(stdout, port.items(), None, separator=" | ",
                 title=title)
开发者ID:antonis-m,项目名称:synnefo,代码行数:19,代码来源:pprint.py

示例8: pprint_subnet_in_db

# 需要导入模块: from synnefo.lib.ordereddict import OrderedDict [as 别名]
# 或者: from synnefo.lib.ordereddict.OrderedDict import items [as 别名]
def pprint_subnet_in_db(subnet, stdout=None, title=None):
    if stdout is None:
        stdout = sys.stdout
    if title is None:
        title = "State of Subnet %s in DB" % subnet.id
    info = OrderedDict([("ID", subnet.id),
                        ("Network_ID", subnet.network.id),
                        # If a user names his subnet "-", what happens then?
                        ("User_ID", subnet.userid),
                        ("Name", "-" if subnet.name == "" else subnet.name),
                        ("IP_Version", subnet.ipversion),
                        ("CIDR", subnet.cidr),
                        ("Gateway", subnet.gateway),
                        ("Public", subnet.public),
                        ("DHCP/SLAAC", subnet.dhcp),
                        ("Host_Routes", subnet.host_routes),
                        ("DNS_Nameservers", subnet.dns_nameservers)])
    pprint_table(stdout, info.items(), None, separator=" | ", title=title)
开发者ID:antonis-m,项目名称:synnefo,代码行数:20,代码来源:pprint.py

示例9: pprint_server

# 需要导入模块: from synnefo.lib.ordereddict import OrderedDict [as 别名]
# 或者: from synnefo.lib.ordereddict.OrderedDict import items [as 别名]
def pprint_server(server, display_mails=False, stdout=None, title=None):
    if stdout is None:
        stdout = sys.stdout
    if title is None:
        title = "State of Server %s in DB" % server.id

    ucache = UserCache(ASTAKOS_AUTH_URL, ASTAKOS_TOKEN)
    userid = server.userid

    try:
        image = get_image(server.imageid, server.userid)['name']
    except:
        image = server.imageid

    server_dict = OrderedDict([
        ("id", server.id),
        ("name", server.name),
        ("userid", server.userid),
        ("username", ucache.get_name(userid) if display_mails else None),
        ("project", server.project),
        ("shared_to_project", server.shared_to_project),
        ("flavor_id", server.flavor_id),
        ("flavor_name", server.flavor.name),
        ("imageid", server.imageid),
        ("image_name", image),
        ("created", server.created),
        ("state", server.operstate),
        ("backend", server.backend),
        ("deleted", server.deleted),
        ("action", server.action),
        ("task", server.task),
        ("task_job_id", server.task_job_id),
        ("backendjobid", server.backendjobid),
        ("backendopcode", server.backendopcode),
        ("backendjobstatus", server.backendjobstatus),
        ("backend_time", server.backendtime),
        ])

    pprint_table(stdout, server_dict.items(), None, separator=" | ",
                 title=title)
开发者ID:gvsurenderreddy,项目名称:synnefo-1,代码行数:42,代码来源:pprint.py

示例10: pprint_port

# 需要导入模块: from synnefo.lib.ordereddict import OrderedDict [as 别名]
# 或者: from synnefo.lib.ordereddict.OrderedDict import items [as 别名]
def pprint_port(port, display_mails=False, stdout=None, title=None):
    if stdout is None:
        stdout = sys.stdout
    if title is None:
        title = "State of Port %s in DB" % port.id

    ucache = UserCache(ASTAKOS_AUTH_URL, ASTAKOS_TOKEN)
    userid = port.userid

    port = OrderedDict([
        ("id", port.id),
        ("name", port.name),
        ("userid", port.userid),
        ("username", ucache.get_name(userid) if display_mails else None),
        ("server", port.machine_id),
        ("network", port.network_id),
        ("device_owner", port.device_owner),
        ("mac", port.mac),
        ("state", port.state)])

    pprint_table(stdout, port.items(), None, separator=" | ",
                 title=title)
开发者ID:AthinaB,项目名称:synnefo,代码行数:24,代码来源:pprint.py


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