@@ -20,6 +20,7 @@ def __init__(self,
2020 location : str = "FIN1" ,
2121 instance_id : str = None ,
2222 ssh_key_ids : List [str ] = [],
23+ deleted_at : str = None ,
2324 ) -> None :
2425 """Initialize the volume object
2526
@@ -45,6 +46,8 @@ def __init__(self,
4546 :type instance_id: str
4647 :param ssh_key_ids: list of ssh keys ids
4748 :type ssh_key_ids: List[str]
49+ :param deleted_at: the time the volume was deleted (UTC), defaults to None
50+ :type deleted_at: str, optional
4851 """
4952 self ._id = id
5053 self ._status = status
@@ -57,6 +60,7 @@ def __init__(self,
5760 self ._location = location
5861 self ._instance_id = instance_id
5962 self ._ssh_key_ids = ssh_key_ids
63+ self ._deleted_at = deleted_at
6064
6165 @property
6266 def id (self ) -> str :
@@ -157,6 +161,26 @@ def ssh_key_ids(self) -> List[str]:
157161 """
158162 return self ._ssh_key_ids
159163
164+ @property
165+ def deleted_at (self ) -> Optional [str ]:
166+ """Get the time when the volume was deleted (UTC)
167+
168+ :return: time
169+ :rtype: str
170+ """
171+ return self ._deleted_at
172+
173+ @classmethod
174+ def create_from_dict (cls : 'Volume' , volume_dict : dict ) -> 'Volume' :
175+ """Create a Volume object from a dictionary
176+
177+ :param volume_dict: dictionary representing the volume
178+ :type volume_dict: dict
179+ :return: Volume
180+ :rtype: Volume
181+ """
182+ return cls (** volume_dict )
183+
160184 def __str__ (self ) -> str :
161185 """Returns a string of the json representation of the volume
162186
@@ -182,21 +206,7 @@ def get(self, status: str = None) -> List[Volume]:
182206 """
183207 volumes_dict = self ._http_client .get (
184208 VOLUMES_ENDPOINT , params = {'status' : status }).json ()
185- volumes = list (map (lambda volume_dict : Volume (
186- id = volume_dict ['id' ],
187- status = volume_dict ['status' ],
188- name = volume_dict ['name' ],
189- size = volume_dict ['size' ],
190- type = volume_dict ['type' ],
191- is_os_volume = volume_dict ['is_os_volume' ],
192- created_at = volume_dict ['created_at' ],
193- target = volume_dict ['target' ] if 'target' in volume_dict else None ,
194- location = volume_dict ['location' ],
195- instance_id = volume_dict ['instance_id' ] if 'instance_id' in volume_dict else None ,
196- ssh_key_ids = volume_dict ['ssh_key_ids' ] if 'ssh_key_ids' in volume_dict else [
197- ],
198- ), volumes_dict ))
199- return volumes
209+ return list (map (Volume .create_from_dict , volumes_dict ))
200210
201211 def get_by_id (self , id : str ) -> Volume :
202212 """Get a specific volume by its
@@ -208,21 +218,20 @@ def get_by_id(self, id: str) -> Volume:
208218 """
209219 volume_dict = self ._http_client .get (
210220 VOLUMES_ENDPOINT + f'/{ id } ' ).json ()
211- volume = Volume (
212- id = volume_dict ['id' ],
213- status = volume_dict ['status' ],
214- name = volume_dict ['name' ],
215- size = volume_dict ['size' ],
216- type = volume_dict ['type' ],
217- is_os_volume = volume_dict ['is_os_volume' ],
218- created_at = volume_dict ['created_at' ],
219- target = volume_dict ['target' ] if 'target' in volume_dict else None ,
220- location = volume_dict ['location' ],
221- instance_id = volume_dict ['instance_id' ] if 'instance_id' in volume_dict else None ,
222- ssh_key_ids = volume_dict ['ssh_key_ids' ] if 'ssh_key_ids' in volume_dict else [
223- ],
224- )
225- return volume
221+
222+ return Volume .create_from_dict (volume_dict )
223+
224+ def get_in_trash (self ) -> List [Volume ]:
225+ """Get all volumes that are in trash
226+
227+ :return: list of volume details objects
228+ :rtype: List[Volume]
229+ """
230+ volumes_dicts = self ._http_client .get (
231+ VOLUMES_ENDPOINT + '/trash'
232+ ).json ()
233+
234+ return list (map (Volume .create_from_dict , volumes_dicts ))
226235
227236 def create (self ,
228237 type : str ,
@@ -358,7 +367,7 @@ def increase_size(self, id_list: Union[List[str], str], size: int) -> None:
358367 self ._http_client .put (VOLUMES_ENDPOINT , json = payload )
359368 return
360369
361- def delete (self , id_list : Union [List [str ], str ]) -> None :
370+ def delete (self , id_list : Union [List [str ], str ], is_permanent : bool = False ) -> None :
362371 """Delete multiple volumes or single volume
363372 Note: if attached to any instances, they need to be shut-down (offline)
364373
@@ -368,6 +377,7 @@ def delete(self, id_list: Union[List[str], str]) -> None:
368377 payload = {
369378 "id" : id_list ,
370379 "action" : VolumeActions .DELETE ,
380+ "is_permanent" : is_permanent
371381 }
372382
373383 self ._http_client .put (VOLUMES_ENDPOINT , json = payload )
0 commit comments