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


Python utils.NestedDict类代码示例

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


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

示例1: get_standard_package

    def get_standard_package(self, server_id, is_cci=True):
        """ Retrieves the standard firewall package for the CCI.

        :param int server_id: The ID of the server to create the firewall for
        :param bool is_cci: True if the id provided is for a CCI,
                            False for a server
        :returns: A dictionary containing the standard CCI firewall package
        """
        mask = ('mask[primaryNetworkComponent[speed]]')
        if is_cci:
            svc = self.client['Virtual_Guest']
        else:
            svc = self.client['Hardware_Server']

        item = svc.getObject(mask=mask, id=server_id)

        _filter = NestedDict({})
        _value = "%s%s" % (item['primaryNetworkComponent']['speed'],
                           "Mbps Hardware Firewall")
        _filter['items']['description'] = query_filter(_value)

        kwargs = NestedDict({})
        kwargs['id'] = 0  # look at package id 0
        kwargs['filter'] = _filter.to_dict()
        return self.prod_pkg.getItems(**kwargs)
开发者ID:MayaY2014,项目名称:softlayer-python,代码行数:25,代码来源:firewall.py

示例2: find_free_volume

    def find_free_volume(self, size, imported):
        """
        Find a volume in the pool of the given size.

        :param size: size to search for.
        :param imported: list of imported volumes

        :returns: sl_vol: SoftLayer iSCSI volume representation
        """
        _filter = NestedDict({})
        if self.configuration.sl_vol_order_ceil:
            _filter['iscsiNetworkStorage'][
                'capacityGb'] = query_filter('>=%s' % size)
        else:
            _filter['iscsiNetworkStorage']['capacityGb'] = query_filter(size)
        _filter['iscsiNetworkStorage'][
            'billingItem'][
            'location'][
            'id'] = query_filter(self.location)
        sl_volumes = self.client['Account'].getIscsiNetworkStorage(
            mask='mask[id,capacityGb,'
            'username,password,billingItem[id]]',
            filter=_filter.to_dict())
        if len(sl_volumes) == 0:
            return None
        sl_volumes = sorted(sl_volumes, key=lambda x: int(x['capacityGb']))
        for sl_vol in sl_volumes:
            if sl_vol['id'] in imported:
                continue
            return self._get_vol(sl_vol['id'])
        LOG.warn(_("No free volume found of size %s" % size))
        return None
开发者ID:amol,项目名称:softlayer-cinder-driver,代码行数:32,代码来源:api.py

示例3: get_private_images

    def get_private_images(self, guid=None, name=None, limit=None,
                           marker=None):
        _filter = NestedDict()
        if name:
            _filter['privateBlockDeviceTemplateGroups']['name'] = \
                query_filter(name)

        if marker is not None:
            _filter['privateBlockDeviceTemplateGroups']['globalIdentifier'] = \
                query_filter('> %s' % marker)

        if guid:
            _filter['privateBlockDeviceTemplateGroups'] = {
                'globalIdentifier': query_filter(guid)}

        params = {}
        params['mask'] = self.image_mask

        if _filter:
            params['filter'] = _filter.to_dict()

        if limit:
            params['limit'] = limit

        account = self.client['Account']
        return account.getPrivateBlockDeviceTemplateGroups(**params)
开发者ID:hartsock,项目名称:jumpgate,代码行数:26,代码来源:images.py

示例4: _find_item

    def _find_item(self, size, category_code, ceil):
        """
        Find the item_price IDs for the iSCSIs of given size

        :param int size: iSCSI volume size
        :returns: Returns a list of item price IDs matching
                  the given volume size or first large enough size, if the
                 `sl_vol_order_ceil` configuration value is se
        """
        _filter = NestedDict({})
        _filter[
            'items'][
            'categories'][
            'categoryCode'] = query_filter(category_code)
        if ceil:
            _filter['items'][
                'capacity'] = query_filter('>=%s' % size)
        else:
            _filter['items']['capacity'] = query_filter(size)
        iscsi_item_prices = self.client['Product_Package'].getItems(
            id=0,
            mask=','.join(('id', 'prices', 'capacity')),
            filter=_filter.to_dict())
        if len(iscsi_item_prices) == 0:
            return None
        iscsi_item_prices = sorted(
            iscsi_item_prices,
            key=lambda x: float(x['capacity']))

        return iscsi_item_prices[0]['prices'][0]['id']
开发者ID:amol,项目名称:softlayer-cinder-driver,代码行数:30,代码来源:api.py

示例5: list_subnets

    def list_subnets(self, identifier=None, datacenter=None, version=0, subnet_type=None, **kwargs):
        """ Display a list of all subnets on the account.

        This provides a quick overview of all subnets including information
        about data center residence and the number of devices attached.

        :param string identifier: If specified, the list will only contain the
                                    subnet matching this network identifier.
        :param string datacenter: If specified, the list will only contain
                                    subnets in the specified data center.
        :param int version: Only returns subnets of this version (4 or 6).
        :param string subnet_type: If specified, it will only returns subnets
                                     of this type.
        :param dict \\*\\*kwargs: response-level options (mask, limit, etc.)
        """
        if "mask" not in kwargs:
            kwargs["mask"] = DEFAULT_SUBNET_MASK

        _filter = NestedDict(kwargs.get("filter") or {})

        if identifier:
            _filter["subnets"]["networkIdentifier"] = query_filter(identifier)
        if datacenter:
            _filter["subnets"]["datacenter"]["name"] = query_filter(datacenter)
        if version:
            _filter["subnets"]["version"] = query_filter(version)
        if subnet_type:
            _filter["subnets"]["subnetType"] = query_filter(subnet_type)
        else:
            # This filters out global IPs from the subnet listing.
            _filter["subnets"]["subnetType"] = {"operation": "!= GLOBAL_IP"}

        kwargs["filter"] = _filter.to_dict()

        return self.account.getSubnets(**kwargs)
开发者ID:TimurNurlygayanov,项目名称:softlayer-python,代码行数:35,代码来源:network.py

示例6: list_vlans

    def list_vlans(self, datacenter=None, vlan_number=None, name=None, **kwargs):
        """ Display a list of all VLANs on the account.

        This provides a quick overview of all VLANs including information about
        data center residence and the number of devices attached.

        :param string datacenter: If specified, the list will only contain
                                    VLANs in the specified data center.
        :param int vlan_number: If specified, the list will only contain the
                                  VLAN matching this VLAN number.
        :param int name: If specified, the list will only contain the
                                  VLAN matching this VLAN name.
        :param dict \\*\\*kwargs: response-level options (mask, limit, etc.)

        """
        _filter = NestedDict(kwargs.get("filter") or {})

        if vlan_number:
            _filter["networkVlans"]["vlanNumber"] = query_filter(vlan_number)

        if name:
            _filter["networkVlans"]["name"] = query_filter(name)

        if datacenter:
            _filter["networkVlans"]["primaryRouter"]["datacenter"]["name"] = query_filter(datacenter)

        kwargs["filter"] = _filter.to_dict()

        if "mask" not in kwargs:
            kwargs["mask"] = DEFAULT_VLAN_MASK

        return self.account.getNetworkVlans(**kwargs)
开发者ID:TimurNurlygayanov,项目名称:softlayer-python,代码行数:32,代码来源:network.py

示例7: list_vlans

    def list_vlans(self, datacenter=None, vlan_number=None, name=None,
                   **kwargs):
        """ Display a list of all VLANs on the account.

        This provides a quick overview of all VLANs including information about
        data center residence and the number of devices attached.

        :param string datacenter: If specified, the list will only contain
                                    VLANs in the specified data center.
        :param int vlan_number: If specified, the list will only contain the
                                  VLAN matching this VLAN number.
        :param int name: If specified, the list will only contain the
                                  VLAN matching this VLAN name.
        :param dict \*\*kwargs: response-level arguments (limit, offset, etc.)

        """
        _filter = NestedDict(kwargs.get('filter') or {})

        if vlan_number:
            _filter['networkVlans']['vlanNumber'] = query_filter(vlan_number)

        if name:
            _filter['networkVlans']['name'] = query_filter(name)

        if datacenter:
            _filter['networkVlans']['primaryRouter']['datacenter']['name'] = \
                query_filter(datacenter)

        kwargs['filter'] = _filter.to_dict()

        if 'mask' not in kwargs:
            kwargs['mask'] = self._get_vlan_mask()

        return self.account.getNetworkVlans(**kwargs)
开发者ID:mattmarcum,项目名称:softlayer-python,代码行数:34,代码来源:network.py

示例8: get_records

    def get_records(self, zone_id, ttl=None, data=None, host=None,
                    type=None, **kwargs):
        """ List, and optionally filter, records within a zone.

        :param zone: the zone name in which to search.
        :param int ttl: optionally, time in seconds:
        :param data: optionally, the records data
        :param host: optionally, record's host
        :param type: optionally, the type of record:

        :returns: A list of dictionaries representing the matching records
                  within the specified zone.
        """
        _filter = NestedDict()

        if ttl:
            _filter['resourceRecords']['ttl'] = query_filter(ttl)

        if host:
            _filter['resourceRecords']['host'] = query_filter(host)

        if data:
            _filter['resourceRecords']['data'] = query_filter(data)

        if type:
            _filter['resourceRecords']['type'] = query_filter(type.lower())

        results = self.service.getResourceRecords(
            id=zone_id,
            mask='id,expire,domainId,host,minimum,refresh,retry,'
            'mxPriority,ttl,type,data,responsiblePerson',
            filter=_filter.to_dict(),
        )

        return results
开发者ID:loles,项目名称:softlayer-api-python-client,代码行数:35,代码来源:dns.py

示例9: list_keys

    def list_keys(self, label=None):
        """ Lists all SSH keys on the account.

        :param string label: Filter list based on SSH key label
        :returns: A list of dictionaries with information about each key
        """
        _filter = NestedDict({})
        if label:
            _filter['sshKeys']['label'] = query_filter(label)

        return self.client['Account'].getSshKeys(filter=_filter.to_dict())
开发者ID:anil-kumbhar,项目名称:softlayer-python,代码行数:11,代码来源:sshkey.py

示例10: list_global_ips

    def list_global_ips(self, version=0):
        """ Returns a list of all global IP address records on the account.

        :param int version: Only returns IPs of this version (4 or 6).
        """
        mask = ['destinationIpAddress[hardware, virtualGuest]', 'ipAddress']
        mask = 'mask[%s]' % ','.join(mask)
        _filter = NestedDict({})
        if version:
            v = query_filter(version)
            _filter['globalIpRecords']['ipAddress']['subnet']['version'] = v
        _filter = _filter.to_dict()
        return self.account.getGlobalIpRecords(filter=_filter, mask=mask)
开发者ID:crvidya,项目名称:softlayer-api-python-client,代码行数:13,代码来源:network.py

示例11: _order_iscsi

    def _order_iscsi(self, item):
        """
        Places an order for volume.

        :param item: item price id to be used to order
        """
        iscsi_order = self._build_order(item)
        try:
            self.product_order.verifyOrder(iscsi_order)
            LOG.debug(_("Order verified successfully"))
            order = self.product_order.placeOrder(iscsi_order)
        except SoftLayerAPIError as ex:
            LOG.debug(_("Cannot place order: %s" % ex))
            raise exception.VolumeBackendAPIException(data=ex.message)
        LOG.debug(_("Order placed successfully"))
        billing_item_id = order['placedOrder']['items'][0]['id']
        LOG.debug(_("Billing item id: %s associated" % billing_item_id))
        billing_svc = self.client['Billing_Order_Item']
        for retry in xrange(self.configuration.sl_vol_active_retry):
            billing_item = billing_svc.getBillingItem(
                id=billing_item_id)
            if billing_item and \
                    billing_item.get('notes'):
                # iscsi is available
                break
            LOG.debug("Ordered volume is not in active state, "
                      "sleeping after %s retries" % retry)
            time.sleep(self.configuration.sl_vol_active_wait)

        if not billing_item.get('notes'):
            raise exception.VolumeBackendAPIException(
                data="Unable to retrive the "
                "billing item for the order placed. "
                "Order Id: %s" %
                order.get('id'))
        LOG.debug(_("Billing Item associated: '%s'" % billing_item))
        user_name = billing_item['notes']
        _filter = NestedDict({})
        _filter[
            'iscsiNetworkStorage'][
            'username'] = query_filter(
            user_name)
        result = self.client['Account'].\
            getIscsiNetworkStorage(mask='mask[billingItem[id]]',
                                   filter=_filter.to_dict())
        sl_vol = result[0]
        return sl_vol
开发者ID:amol,项目名称:softlayer-cinder-driver,代码行数:47,代码来源:api.py

示例12: list_subnets

    def list_subnets(self, identifier=None, datacenter=None, version=0,
                     subnet_type=None, **kwargs):
        """ Display a list of all subnets on the account.

        This provides a quick overview of all subnets including information
        about data center residence and the number of devices attached.

        :param string identifier: If specified, the list will only contain the
                                    subnet matching this network identifier.
        :param string datacenter: If specified, the list will only contain
                                    subnets in the specified data center.
        :param int version: Only returns subnets of this version (4 or 6).
        :param string subnet_type: If specified, it will only returns subnets
                                     of this type.
        :param dict \*\*kwargs: response-level arguments (limit, offset, etc.)

        """
        if 'mask' not in kwargs:
            mask = self._get_subnet_mask()
            kwargs['mask'] = 'mask[%s]' % ','.join(mask)

        _filter = NestedDict(kwargs.get('filter') or {})

        if identifier:
            _filter['subnets']['networkIdentifier'] = query_filter(identifier)
        if datacenter:
            _filter['subnets']['datacenter']['name'] = \
                query_filter(datacenter)
        if version:
            _filter['subnets']['version'] = query_filter(version)
        if subnet_type:
            _filter['subnets']['subnetType'] = query_filter(subnet_type)
        else:
            # This filters out global IPs from the subnet listing.
            _filter['subnets']['subnetType'] = {'operation': 'not null'}

        kwargs['filter'] = _filter.to_dict()

        results = []

        # Filtering out routed global IPs here. This is being done in code
        # because of complications getting the object filter syntax working.
        for subnet in self.account.getSubnets(**kwargs):
            if 'GLOBAL_IP' not in subnet['subnetType']:
                results.append(subnet)

        return results
开发者ID:crvidya,项目名称:softlayer-api-python-client,代码行数:47,代码来源:network.py

示例13: reset_service_group

    def reset_service_group(self, loadbal_id, group_id):
        """ Resets all the connections on the service group
        :param int loadbal_id: The id of the loadbal
        :param int group_id: The id of the service group to reset
        """
        _filter = NestedDict({})
        _filter['virtualServers']['id'] = query_filter(group_id)

        kwargs = NestedDict({})
        kwargs['filter'] = _filter.to_dict()
        kwargs['mask'] = 'mask[serviceGroups]'

        virtual_servers = self.lb_svc.getVirtualServers(id=loadbal_id,
                                                        **kwargs)
        actual_id = virtual_servers[0]['serviceGroups'][0]['id']

        svc = self.client['Network_Application_Delivery_Controller'
                          '_LoadBalancer_Service_Group']
        return svc.kickAllConnections(id=actual_id)
开发者ID:MayaY2014,项目名称:softlayer-python,代码行数:19,代码来源:load_balancer.py

示例14: get_lb_pkgs

    def get_lb_pkgs(self):
        """ Retrieves the local load balancer packages.

        :returns: A dictionary containing the load balancer packages
        """

        lb_filter = '*Load Balancer*'
        _filter = NestedDict({})
        _filter['items']['description'] = query_filter(lb_filter)

        kwargs = NestedDict({})
        kwargs['id'] = 0  # look at package id 0
        kwargs['filter'] = _filter.to_dict()
        packages = self.prod_pkg.getItems(**kwargs)
        pkgs = []
        for package in packages:
            if not package['description'].startswith('Global'):
                pkgs.append(package)
        return pkgs
开发者ID:MayaY2014,项目名称:softlayer-python,代码行数:19,代码来源:load_balancer.py

示例15: list_public_images

    def list_public_images(self, guid=None, name=None, **kwargs):
        """ List all public images.

        :param string guid: filter based on GUID
        :param string name: filter based on name
        :param dict \*\*kwargs: response-level arguments (limit, offset, etc.)
        """
        if 'mask' not in kwargs:
            kwargs['mask'] = IMAGE_MASK

        _filter = NestedDict(kwargs.get('filter') or {})
        if name:
            _filter['name'] = query_filter(name)

        if guid:
            _filter['globalIdentifier'] = query_filter(guid)

        kwargs['filter'] = _filter.to_dict()

        return self.vgbdtg.getPublicImages(**kwargs)
开发者ID:anil-kumbhar,项目名称:softlayer-python,代码行数:20,代码来源:image.py


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