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)
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)
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)
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)
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)
def _serialize(self): dct = Base._serialize(self) dct['images'] = [d.id for d in self.images] return dct
def invalidate(self): if hasattr(self, '_grants'): del self._grants Base.invalidate(self)
def __init__(self, client, id, parent_id, json={}): Base.__init__(self, client, id, json=json) self._set(type(self).parent_id_name, parent_id)
def _serialize(self): dct = Base._serialize(self) dct['images'] = [ d.id for d in self.images ] return dct