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


Python ordereddict.OrderedDict类代码示例

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


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

示例1: project_fields

def project_fields(project):
    app = project.last_application
    pending_app = (app.id if app and app.state == app.PENDING
                   else None)

    d = OrderedDict([
        ('project id', project.uuid),
        ('name', project.realname),
        ('status', project.state_display()),
        ('pending_app', pending_app),
        ('owner', project.owner),
        ('homepage', project.homepage),
        ('description', project.description),
        ('creation date', project.creation_date),
        ('request end date', project.end_date),
        ])

    deact = project.last_deactivation()
    if deact is not None:
        d['deactivation date'] = deact.date

    d.update([
            ('join policy', project.member_join_policy_display),
            ('leave policy', project.member_leave_policy_display),
            ('max members', units.show(project.limit_on_members_number, None)),
            ('total members', project.members_count()),
    ])

    return d
开发者ID:AthinaB,项目名称:synnefo,代码行数:29,代码来源:project-show.py

示例2: pprint_floating_ip

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,代码行数:26,代码来源:pprint.py

示例3: pprint_ippool

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,代码行数:31,代码来源:pprint.py

示例4: __init__

    def __init__(self, hosts=settings.AMQP_HOSTS, max_retries=30,
                 confirms=True, confirm_buffer=100, logger=None):
        """
        Format hosts as "amqp://username:[email protected]:port"
        max_retries=0 defaults to unlimited retries

        """

        self.hosts = hosts
        shuffle(self.hosts)

        self.max_retries = max_retries
        self.confirms = confirms
        self.confirm_buffer = confirm_buffer

        self.connection = None
        self.channel = None
        self.consumers = {}
        self.unacked = OrderedDict()
        self.unsend = OrderedDict()
        self.consume_promises = []
        self.exchanges = []
        if logger:
            self.log = logger
        else:
            logger = logging.getLogger("amqp")
            logging.basicConfig()
            self.log = logger
开发者ID:AthinaB,项目名称:synnefo,代码行数:28,代码来源:amqp_puka.py

示例5: pprint_volume

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,代码行数:29,代码来源:pprint.py

示例6: pprint_network

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,代码行数:29,代码来源:pprint.py

示例7: pprint_server_in_ganeti

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,代码行数:58,代码来源:pprint.py

示例8: pprint_volume_type

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,代码行数:13,代码来源:pprint.py

示例9: __init__

    def __init__(self, user=None, identifier=None, **provider_params):
        """
        3 ways to initialize (no args, user, user and identifier).

        no args: Used for anonymous unauthenticated users.
        >>> p = auth_providers.get_provider('local')
        >>> # check that global settings allows us to create a new account
        >>> # using `local` provider.
        >>> print p.is_available_for_create()

        user and identifier: Used to provide details about a user's specific
        login method.
        >>> p = auth_providers.get_provider('google', user,
        >>>                                 identifier='1421421')
        >>> # provider (google) details prompt
        >>> print p.get_method_details()
        "Google account: 1421421"
        """

        # handle AnonymousUser instance
        self.user = None
        if user and hasattr(user, 'pk') and user.pk:
            self.user = user

        self.identifier = identifier
        self._instance = None
        if 'instance' in provider_params:
            self._instance = provider_params['instance']
            del provider_params['instance']

        # initialize policies
        self.module_policies = copy.copy(self.default_policies)
        for policy, value in self.policies.iteritems():
            setting_key = "%s_POLICY" % policy.upper()
            if self.has_setting(setting_key):
                self.module_policies[policy] = self.get_setting(setting_key)
            else:
                self.module_policies[policy] = value

        # messages cache
        self.message_tpls_compiled = OrderedDict()

        # module specific messages
        self.message_tpls = OrderedDict(self.message_tpls)
        for key, value in self.messages.iteritems():
            self.message_tpls[key] = value

        self._provider_details = provider_params

        self.resolve_available_methods = True
开发者ID:grnet,项目名称:synnefo,代码行数:50,代码来源:auth_providers.py

示例10: pprint_port

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,代码行数:17,代码来源:pprint.py

示例11: pprint_subnet_in_db

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,代码行数:18,代码来源:pprint.py

示例12: handle

    def handle(self, *args, **options):
        if len(args) != 1:
            raise CommandError("Please provide a component name or ID.")

        identifier = args[0]
        if identifier.isdigit():
            try:
                component = Component.objects.get(id=int(identifier))
            except Component.DoesNotExist:
                raise CommandError('No component found with ID %s.' %
                                   identifier)
        else:
            try:
                component = Component.objects.get(name=identifier)
            except Component.DoesNotExist:
                raise CommandError('No component found named %s.' % identifier)

        kv = OrderedDict(
            [
                ('id', component.id),
                ('name', component.name),
                ('base url', component.base_url),
                ('ui url', component.url),
                ('token', component.auth_token),
                ('token created', component.auth_token_created),
                ('token expires', component.auth_token_expires),
            ])

        utils.pprint_table(self.stdout, [kv.values()], kv.keys(),
                           options["output_format"], vertical=True)

        services = component.service_set.all()

        service_data = []
        for service in services:
            service_data.append((service.id, service.name, service.type))

        if service_data:
            self.stdout.write('\n')
            labels = ('id', 'name', 'type')
            utils.pprint_table(self.stdout, service_data, labels,
                               options["output_format"],
                               title='Registered services')
开发者ID:antonis-m,项目名称:synnefo,代码行数:43,代码来源:component-show.py

示例13: pprint_server

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,代码行数:40,代码来源:pprint.py

示例14: __init__

    def __init__(self, hosts=settings.AMQP_HOSTS, max_retries=30,
                 confirms=True, confirm_buffer=200):
        self.hosts = hosts
        shuffle(self.hosts)

        self.max_retries = max_retries
        self.confirms = confirms
        self.confirm_buffer = confirm_buffer

        self.connection = None
        self.channel = None
        self.consumers = {}
        self.unacked = OrderedDict()
开发者ID:grnet,项目名称:synnefo,代码行数:13,代码来源:amqp_haigha.py

示例15: pprint_port

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,代码行数:22,代码来源:pprint.py


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