1- from typing import Optional
1+ from typing import Optional , Union
22
33from upcloud_api .storage import Storage
44from upcloud_api .storage_import import StorageImport
@@ -29,7 +29,7 @@ def get_templates(self):
2929 templates .append ({item .get ('title' ): item .get ('uuid' )})
3030 return templates
3131
32- def get_storage (self , storage ) :
32+ def get_storage (self , storage : str ) -> Storage :
3333 """
3434 Return a Storage object from the API.
3535 """
@@ -38,12 +38,12 @@ def get_storage(self, storage):
3838
3939 def create_storage (
4040 self ,
41- size = 10 ,
42- tier = 'maxiops' ,
43- title = 'Storage disk' ,
44- zone = 'fi-hel1' ,
41+ size : int = 10 ,
42+ tier : str = 'maxiops' ,
43+ title : str = 'Storage disk' ,
44+ zone : str = 'fi-hel1' ,
4545 backup_rule : Optional [dict ] = None ,
46- ):
46+ ) -> Storage :
4747 """
4848 Create a Storage object. Returns an object based on the API's response.
4949 """
@@ -71,7 +71,9 @@ def _modify_storage(self, storage, size, title, backup_rule: Optional[dict] = No
7171 body ['storage' ]['backup_rule' ] = backup_rule
7272 return self .put_request ('/storage/' + str (storage ), body )
7373
74- def modify_storage (self , storage , size , title , backup_rule : Optional [dict ] = None ):
74+ def modify_storage (
75+ self , storage : str , size : int , title : str , backup_rule : Optional [dict ] = None
76+ ) -> Storage :
7577 """
7678 Modify a Storage object. Returns an object based on the API's response.
7779 """
@@ -84,13 +86,16 @@ def delete_storage(self, UUID):
8486 """
8587 return self .delete_request ('/storage/' + UUID )
8688
87- def clone_storage (self , storage , title , zone , tier = None ):
89+ def clone_storage (
90+ self , storage : Union [Storage , str ], title : str , zone : str , tier = None
91+ ) -> Storage :
8892 """
8993 Clones a Storage object. Returns an object based on the API's response.
9094 """
9195 body = {'storage' : {'title' : title , 'zone' : zone }}
9296 if tier :
9397 body ['storage' ]['tier' ] = tier
98+ # TODO: `str(storage)` seems unsafe
9499 res = self .post_request (f'/storage/{ str (storage )} /clone' , body )
95100 return Storage (cloud_manager = self , ** res ['storage' ])
96101
@@ -144,7 +149,7 @@ def eject_cd_rom(self, server):
144149 res = self .post_request (url )
145150 return Storage ._create_storage_objs (res ['server' ]['storage_devices' ], cloud_manager = self )
146151
147- def create_storage_backup (self , storage , title ) :
152+ def create_storage_backup (self , storage : str , title : str ) -> Storage :
148153 """
149154 Creates a point-in-time backup of a storage resource.
150155 """
@@ -160,7 +165,7 @@ def restore_storage_backup(self, storage):
160165 url = f'/storage/{ storage } /restore'
161166 return self .post_request (url )
162167
163- def templatize_storage (self , storage , title ) :
168+ def templatize_storage (self , storage : str , title : str ) -> Storage :
164169 """
165170 Creates an exact copy of an existing storage resource which can be used as a template for creating new servers.
166171 """
@@ -169,7 +174,9 @@ def templatize_storage(self, storage, title):
169174 res = self .post_request (url , body )
170175 return Storage (cloud_manager = self , ** res ['storage' ])
171176
172- def create_storage_import (self , storage , source , source_location = None ):
177+ def create_storage_import (
178+ self , storage : str , source : str , source_location = None
179+ ) -> StorageImport :
173180 """
174181 Creates an import task to import data into an existing storage.
175182 Source types: http_import or direct_upload.
@@ -190,15 +197,15 @@ def upload_file_for_storage_import(self, storage_import, file):
190197 body = {'data' : data }
191198 return self .put_request (url , body , timeout = 600 , request_to_api = False )
192199
193- def get_storage_import_details (self , storage ) :
200+ def get_storage_import_details (self , storage : str ) -> StorageImport :
194201 """
195202 Returns detailed information of an ongoing or finished import task.
196203 """
197204 url = f'/storage/{ storage } /import'
198205 res = self .get_request (url )
199206 return StorageImport (** res ['storage_import' ])
200207
201- def cancel_storage_import (self , storage ) :
208+ def cancel_storage_import (self , storage : str ) -> StorageImport :
202209 """
203210 Cancels an ongoing import task.
204211 """
0 commit comments