def _populate(self, json): """ Map devices more nicely while populating. """ # needed here to avoid circular imports from .volume import Volume # pylint: disable=import-outside-toplevel DerivedBase._populate(self, json) devices = {} for device_index, device in json['devices'].items(): if not device: devices[device_index] = None continue dev = None if 'disk_id' in device and device['disk_id']: # this is a disk dev = Disk.make_instance(device['disk_id'], self._client, parent_id=self.linode_id) else: dev = Volume.make_instance(device['volume_id'], self._client, parent_id=self.linode_id) devices[device_index] = dev self._set('devices', MappedObject(**devices))
def __init__(self, client, id, parent_id, nodebalancer_id=None, json=None): """ We need a special constructor here because this object's parent has a parent itself. """ if not nodebalancer_id and not isinstance(parent_id, tuple): raise ValueError('NodeBalancerNode must either be created with a nodebalancer_id or a tuple of ' '(config_id, nodebalancer_id) for parent_id!') if isinstance(parent_id, tuple): nodebalancer_id = parent_id[1] parent_id = parent_id[0] DerivedBase.__init__(self, client, id, parent_id, json=json) self._set('nodebalancer_id', nodebalancer_id)
def _populate(self, json): """ Map devices more nicely while populating. """ # needed here to avoid circular imports from .volume import Volume # pylint: disable=import-outside-toplevel DerivedBase._populate(self, json) devices = {} for device_index, device in json['devices'].items(): if not device: devices[device_index] = None continue dev = None if 'disk_id' in device and device['disk_id']: # this is a disk dev = Disk.make_instance(device['disk_id'], self._client, parent_id=self.linode_id) else: dev = Volume.make_instance(device['volume_id'], self._client, parent_id=self.linode_id) devices[device_index] = dev self._set('devices', MappedObject(**devices)) interfaces = [] if "interfaces" in json: interfaces = [ ConfigInterface(c["purpose"], label=c["label"], ipam_address=c["ipam_address"]) for c in json["interfaces"] ] self._set("interfaces", interfaces)
def _populate(self, json): """ Map devices more nicely while populating. """ from .volume import Volume DerivedBase._populate(self, json) devices = {} for device_index, device in json['devices'].items(): if not device: devices[device_index] = None continue dev = None if 'disk_id' in device and device['disk_id']: # this is a disk dev = Disk.make_instance(device['disk_id'], self._client, parent_id=self.linode_id) else: dev = Volume.make_instance(device['volume_id'], self._client, parent_id=self.linode_id) devices[device_index] = dev self._set('devices', MappedObject(**devices))
def _serialize(self): """ Overrides _serialize to transform interfaces into json """ partial = DerivedBase._serialize(self) interfaces = [] for c in self.interfaces: if isinstance(c, ConfigInterface): interfaces.append(c._serialize()) else: interfaces.append(c) partial["interfaces"] = interfaces return partial