コード例 #1
0
    def _populate(self, json):
        """
        Override the populate method to map user_defined_fields to
        fancy values
        """
        Base._populate(self, json)

        mapped_udfs = []
        for udf in self.user_defined_fields:
            t = UserDefinedFieldType.text
            choices = None
            if hasattr(udf, 'oneof'):
                t = UserDefinedFieldType.select_one
                choices = udf.oneof.split(',')
            elif hasattr(udf, 'manyof'):
                t = UserDefinedFieldType.select_many
                choices = udf.manyof.split(',')

            mapped_udfs.append(
                UserDefinedField(
                    udf.name,
                    udf.label if hasattr(udf, 'label') else None,
                    udf.example if hasattr(udf, 'example') else None,
                    t,
                    choices=choices))

        self._set('user_defined_fields', mapped_udfs)
        ndist = [Image(self._client, d) for d in self.images]
        self._set('images', ndist)
コード例 #2
0
ファイル: linode.py プロジェクト: linode/python-linode-api
    def _populate(self, json):
        """
        Override the populate method to map user_defined_fields to
        fancy values
        """
        Base._populate(self, json)

        mapped_udfs = []
        for udf in self.user_defined_fields:
            t = UserDefinedFieldType.text
            choices = None
            if hasattr(udf, 'oneof'):
                t = UserDefinedFieldType.select_one
                choices = udf.oneof.split(',')
            elif hasattr(udf, 'manyof'):
                t = UserDefinedFieldType.select_many
                choices = udf.manyof.split(',')

            mapped_udfs.append(UserDefinedField(udf.name,
                    udf.label if hasattr(udf, 'label') else None,
                    udf.example if hasattr(udf, 'example') else None,
                    t, choices=choices))

        self._set('user_defined_fields', mapped_udfs)
        ndist = [ Image(self._client, d) for d in self.images ]
        self._set('images', ndist)
コード例 #3
0
    def invalidate(self):
        """ Clear out cached properties """
        if hasattr(self, '_avail_backups'):
            del self._avail_backups
        if hasattr(self, '_ips'):
            del self._ips

        Base.invalidate(self)
コード例 #4
0
ファイル: linode.py プロジェクト: linode/python-linode-api
    def invalidate(self):
        """ Clear out cached properties """
        if hasattr(self, '_avail_backups'):
            del self._avail_backups
        if hasattr(self, '_ips'):
            del self._ips

        Base.invalidate(self)
コード例 #5
0
    def _populate(self, json):
        if json is not None:
            # fixes ipv4 and ipv6 attribute of json to make base._populate work
            if 'ipv4' in json and 'address' in json['ipv4']:
                json['ipv4']['id'] = json['ipv4']['address']
            if 'ipv6' in json and isinstance(json['ipv6'], list):
                for j in json['ipv6']:
                    j['id'] = j['range']

        Base._populate(self, json)
コード例 #6
0
ファイル: linode.py プロジェクト: linode/python-linode-api
    def _populate(self, json):
        if json is not None:
            # fixes ipv4 and ipv6 attribute of json to make base._populate work
            if 'ipv4' in json and 'address' in json['ipv4']:
                json['ipv4']['id'] = json['ipv4']['address']
            if 'ipv6' in json and isinstance(json['ipv6'], list):
                for j in json['ipv6']:
                    j['id'] = j['range']

        Base._populate(self, json)
コード例 #7
0
ファイル: tag.py プロジェクト: willtejeda/linode_api4-python
    def make_instance(cls, id, client, parent_id=None, json=None):
        """
        Overrides Base's ``make_instance`` to allow dynamic creation of objects
        based on the defined type in the response json.

        :param cls: The class this was called on
        :param id: The id of the instance to create
        :param client: The client to use for this instance
        :param parent_id: The parent id for derived classes
        :param json: The JSON to populate the instance with

        :returns: A new instance of this type, populated with json
        """
        make_cls = CLASS_MAP.get(id) # in this case, ID is coming in as the type

        if make_cls is None:
            # we don't recognize this entity type - do nothing?
            return None

        # discard the envelope
        real_json = json['data']
        real_id = real_json['id']

        # make the real object type
        return Base.make(real_id, client, make_cls, parent_id=None, json=real_json)
コード例 #8
0
 def _serialize(self):
     dct = Base._serialize(self)
     dct['images'] = [d.id for d in self.images]
     return dct
コード例 #9
0
ファイル: account.py プロジェクト: linode/python-linode-api
 def invalidate(self):
     if hasattr(self, '_grants'):
         del self._grants
     Base.invalidate(self)
コード例 #10
0
ファイル: account.py プロジェクト: xswvfr/linode_api4-python
 def invalidate(self):
     if hasattr(self, '_grants'):
         del self._grants
     Base.invalidate(self)
コード例 #11
0
    def __init__(self, client, id, parent_id, json={}):
        Base.__init__(self, client, id, json=json)

        self._set(type(self).parent_id_name, parent_id)
コード例 #12
0
ファイル: linode.py プロジェクト: linode/python-linode-api
 def _serialize(self):
     dct = Base._serialize(self)
     dct['images'] = [ d.id for d in self.images ]
     return dct
コード例 #13
0
ファイル: dbase.py プロジェクト: linode/python-linode-api
    def __init__(self, client, id, parent_id, json={}):
        Base.__init__(self, client, id, json=json)

        self._set(type(self).parent_id_name, parent_id)