10
10
from dataclasses import dataclass
11
11
12
12
FILE_STORAGE_TYPE = "FILE_STORAGE"
13
+ OBJECT_STORAGE_TYPE = "OBJECT_STORAGE"
13
14
14
15
15
16
@dataclass
@@ -182,9 +183,53 @@ def update_from_dsc_model(cls, dsc_model) -> dict:
182
183
"dest" : dsc_model .destination_directory_name
183
184
}
184
185
186
+ @dataclass
187
+ class OCIObjectStorage (DSCFileSystem ):
188
+
189
+ storage_type : str = OBJECT_STORAGE_TYPE
190
+
191
+ def update_to_dsc_model (self ) -> dict :
192
+ arguments = {
193
+ "destinationDirectoryName" : self .dest ,
194
+ "storageType" : self .storage_type
195
+ }
196
+ src_list = self .src .split ("@" )
197
+ bucket_segment = src_list [0 ]
198
+ namespace_segment = src_list [1 ].strip ("/" )
199
+ arguments ["bucket" ] = bucket_segment [6 :]
200
+ if "/" in namespace_segment :
201
+ first_slash_index = namespace_segment .index ("/" )
202
+ arguments ["namespace" ] = namespace_segment [:first_slash_index ]
203
+ arguments ["prefix" ] = namespace_segment [first_slash_index + 1 :]
204
+ else :
205
+ arguments ["namespace" ] = namespace_segment
206
+ return arguments
207
+
208
+ @classmethod
209
+ def update_from_dsc_model (cls , dsc_model ) -> dict :
210
+ if not dsc_model .namespace :
211
+ raise ValueError (
212
+ "Missing parameter `namespace` from service. Check service log to see the error."
213
+ )
214
+ if not dsc_model .bucket :
215
+ raise ValueError (
216
+ "Missing parameter `bucket` from service. Check service log to see the error."
217
+ )
218
+ if not dsc_model .destination_directory_name :
219
+ raise ValueError (
220
+ "Missing parameter `destination_directory_name` from service. Check service log to see the error."
221
+ )
222
+
223
+ return {
224
+ "src" : f"oci://{ dsc_model .bucket } @{ dsc_model .namespace } /{ dsc_model .prefix or '' } " ,
225
+ "dest" : dsc_model .destination_directory_name
226
+ }
227
+
185
228
186
229
class DSCFileSystemManager :
187
230
231
+ storage_mount_dest = set ()
232
+
188
233
@classmethod
189
234
def initialize (cls , arguments : dict ) -> dict :
190
235
"""Initialize and update arguments to dsc model.
@@ -204,6 +249,16 @@ def initialize(cls, arguments: dict) -> dict:
204
249
"Parameter `dest` is required for mounting file storage system."
205
250
)
206
251
252
+ if arguments ["dest" ] in cls .storage_mount_dest :
253
+ raise ValueError (
254
+ "Duplicate `dest` found. Please specify different `dest` for each file system to be mounted."
255
+ )
256
+ cls .storage_mount_dest .add (arguments ["dest" ])
257
+
258
+ # case oci://bucket@namespace/prefix
259
+ if arguments ["src" ].startswith ("oci://" ) and "@" in arguments ["src" ]:
260
+ return OCIObjectStorage (** arguments ).update_to_dsc_model ()
261
+
207
262
first_segment = arguments ["src" ].split (":" )[0 ]
208
263
# case <mount_target_id>:<export_id>
209
264
if first_segment .startswith ("ocid" ):
0 commit comments