@@ -6,6 +6,7 @@ package commonruntime
66
77import (
88 "fmt"
9+ "os"
910
1011 ccm "github.com/cloud-barista/cb-spider/cloud-control-manager"
1112 cres "github.com/cloud-barista/cb-spider/cloud-control-manager/cloud-driver/interfaces/resources"
@@ -14,7 +15,13 @@ import (
1415
1516// -------- IID Info for FileSystem
1617
17- type FileSystemIIDInfo ZoneLevelIIDInfo
18+ type FileSystemIIDInfo struct {
19+ ConnectionName string `gorm:"primaryKey"` // ex) "aws-seoul-config"
20+ ZoneId string // ex) "ap-southeast-2a"
21+ NameId string `gorm:"primaryKey"` // ex) "my_filesystem"
22+ SystemId string // ID in CSP, ex) "fs-12345678"
23+ OwnerVPCName string // ex) "my_vpc" - NOT primaryKey
24+ }
1825
1926func (FileSystemIIDInfo ) TableName () string {
2027 return "filesystem_iid_infos"
@@ -41,6 +48,65 @@ func CreateFileSystem(connectionName string, reqInfo cres.FileSystemInfo) (*cres
4148 return nil , err
4249 }
4350
51+ vpcSPLock .RLock (connectionName , reqInfo .VpcIID .NameId )
52+ defer vpcSPLock .RUnlock (connectionName , reqInfo .VpcIID .NameId )
53+
54+ //+++++++++++++++++++++++++++++++++++++++++++
55+ // set VPC's SystemId
56+ var vpcIIDInfo VPCIIDInfo
57+ if os .Getenv ("PERMISSION_BASED_CONTROL_MODE" ) != "" {
58+ var iidInfoList []* VPCIIDInfo
59+ err = getAuthIIDInfoList (connectionName , & iidInfoList )
60+ if err != nil {
61+ cblog .Error (err )
62+ return nil , err
63+ }
64+ castedIIDInfo , err := getAuthIIDInfo (& iidInfoList , reqInfo .VpcIID .NameId )
65+ if err != nil {
66+ cblog .Error (err )
67+ return nil , err
68+ }
69+ vpcIIDInfo = * castedIIDInfo .(* VPCIIDInfo )
70+ } else {
71+ err = infostore .GetByConditions (& vpcIIDInfo , CONNECTION_NAME_COLUMN , connectionName , NAME_ID_COLUMN , reqInfo .VpcIID .NameId )
72+ if err != nil {
73+ cblog .Error (err )
74+ return nil , err
75+ }
76+ }
77+ cblog .Infof ("CreateFileSystem - Found VPC in infostore: NameId='%s', SystemId='%s'" , vpcIIDInfo .NameId , vpcIIDInfo .SystemId )
78+ reqInfo .VpcIID = getDriverIID (cres.IID {NameId : vpcIIDInfo .NameId , SystemId : vpcIIDInfo .SystemId })
79+ //+++++++++++++++++++++++++++++++++++++++++++
80+
81+ // AccessSubnetList is optional, set SystemId if provided
82+ if reqInfo .AccessSubnetList != nil && len (reqInfo .AccessSubnetList ) > 0 {
83+ for idx , subnetIID := range reqInfo .AccessSubnetList {
84+ var subnetIIDInfo SubnetIIDInfo
85+ if os .Getenv ("PERMISSION_BASED_CONTROL_MODE" ) != "" {
86+ var iidInfoList []* SubnetIIDInfo
87+ err = getAuthIIDInfoList (connectionName , & iidInfoList )
88+ if err != nil {
89+ cblog .Error (err )
90+ return nil , err
91+ }
92+ castedIIDInfo , err := getAuthIIDInfo (& iidInfoList , subnetIID .NameId )
93+ if err != nil {
94+ cblog .Error (err )
95+ return nil , err
96+ }
97+ subnetIIDInfo = * castedIIDInfo .(* SubnetIIDInfo )
98+ } else {
99+ err = infostore .GetByConditions (& subnetIIDInfo , CONNECTION_NAME_COLUMN , connectionName , NAME_ID_COLUMN , subnetIID .NameId )
100+ if err != nil {
101+ cblog .Error (err )
102+ return nil , err
103+ }
104+ }
105+ reqInfo .AccessSubnetList [idx ] = getDriverIID (cres.IID {NameId : subnetIIDInfo .NameId , SystemId : subnetIIDInfo .SystemId })
106+ }
107+ }
108+ //+++++++++++++++++++++++++++++++++++++++++++
109+
44110 fsSPLock .Lock (connectionName , reqInfo .IId .NameId )
45111 defer fsSPLock .Unlock (connectionName , reqInfo .IId .NameId )
46112
@@ -65,14 +131,17 @@ func CreateFileSystem(connectionName string, reqInfo cres.FileSystemInfo) (*cres
65131 return nil , err
66132 }
67133
134+ // Log FileSystemType before calling driver
135+ cblog .Infof ("Calling driver CreateFileSystem - Type: '%s', Zone: '%s', VPC: '%s'" , reqInfo .FileSystemType , reqInfo .Zone , reqInfo .VpcIID .SystemId )
136+
68137 info , err := handler .CreateFileSystem (reqInfo )
69138 if err != nil {
70139 cblog .Error (err )
71140 return nil , err
72141 }
73142
74143 spiderIID := cres.IID {NameId : reqInfo .IId .NameId , SystemId : info .IId .SystemId }
75- err = infostore .Insert (& FileSystemIIDInfo {ConnectionName : connectionName , ZoneId : reqInfo .Zone , NameId : spiderIID .NameId , SystemId : spiderIID .SystemId })
144+ err = infostore .Insert (& FileSystemIIDInfo {ConnectionName : connectionName , ZoneId : reqInfo .Zone , NameId : spiderIID .NameId , SystemId : spiderIID .SystemId , OwnerVPCName : vpcIIDInfo . NameId })
76145 if err != nil {
77146 cblog .Error (err )
78147 // rollback
@@ -86,6 +155,36 @@ func CreateFileSystem(connectionName string, reqInfo cres.FileSystemInfo) (*cres
86155 }
87156
88157 info .IId = cres.IID {NameId : spiderIID .NameId , SystemId : spiderIID .SystemId }
158+
159+ // Set VPC NameId from vpcIIDInfo (already fetched above) - like SecurityGroup pattern
160+ info .VpcIID = getUserIID (cres.IID {NameId : vpcIIDInfo .NameId , SystemId : info .VpcIID .SystemId })
161+ cblog .Infof ("CreateFileSystem - Set VpcIID: NameId='%s', SystemId='%s'" , info .VpcIID .NameId , info .VpcIID .SystemId )
162+
163+ // Set NameId for AccessSubnetList
164+ accessSubnetList := []cres.IID {}
165+ for _ , subnetIID := range info .AccessSubnetList {
166+ var subnetIIDInfo SubnetIIDInfo
167+ err := infostore .GetByConditionsAndContain (& subnetIIDInfo , CONNECTION_NAME_COLUMN , connectionName ,
168+ OWNER_VPC_NAME_COLUMN , vpcIIDInfo .NameId , SYSTEM_ID_COLUMN , subnetIID .SystemId )
169+ if err != nil {
170+ // if not found, use SystemId only
171+ if checkNotFoundError (err ) {
172+ cblog .Info (err )
173+ accessSubnetList = append (accessSubnetList , subnetIID )
174+ continue
175+ }
176+ cblog .Error (err )
177+ // don't fail the whole creation, just skip this subnet NameId resolution
178+ accessSubnetList = append (accessSubnetList , subnetIID )
179+ continue
180+ }
181+ if subnetIIDInfo .NameId != "" {
182+ subnetIID .NameId = subnetIIDInfo .NameId
183+ }
184+ accessSubnetList = append (accessSubnetList , subnetIID )
185+ }
186+ info .AccessSubnetList = accessSubnetList
187+
89188 info .KeyValueList = cres .StructToKeyValueList (info )
90189 return & info , nil
91190}
@@ -113,6 +212,67 @@ func ListFileSystem(connectionName string) ([]*cres.FileSystemInfo, error) {
113212 continue
114213 }
115214 info .IId = cres.IID {NameId : iid .NameId , SystemId : iid .SystemId }
215+
216+ // Set VPC NameId from FileSystemIIDInfo's OwnerVPCName (already stored)
217+ if iid .OwnerVPCName != "" {
218+ // Fetch VPC SystemId from infostore to match with driver's SystemId
219+ var vpcIIDInfo VPCIIDInfo
220+ err := infostore .GetByConditions (& vpcIIDInfo , CONNECTION_NAME_COLUMN , iid .ConnectionName , NAME_ID_COLUMN , iid .OwnerVPCName )
221+ if err == nil {
222+ info .VpcIID .NameId = vpcIIDInfo .NameId
223+ cblog .Infof ("VPC NameId resolved from OwnerVPCName: %s (SystemId: %s)" , vpcIIDInfo .NameId , info .VpcIID .SystemId )
224+ } else {
225+ cblog .Warnf ("Failed to resolve VPC info for OwnerVPCName: %s, err: %v" , iid .OwnerVPCName , err )
226+ }
227+ } else if info .VpcIID .SystemId != "" {
228+ // Fallback: try to resolve VPC NameId from SystemId (for old data)
229+ var vpcIIDInfo VPCIIDInfo
230+ err := infostore .GetByConditionsAndContain (& vpcIIDInfo , CONNECTION_NAME_COLUMN , iid .ConnectionName ,
231+ NAME_ID_COLUMN , "" , SYSTEM_ID_COLUMN , info .VpcIID .SystemId )
232+ if err == nil && vpcIIDInfo .NameId != "" {
233+ info .VpcIID .NameId = vpcIIDInfo .NameId
234+ cblog .Infof ("VPC NameId resolved from SystemId (fallback): %s (SystemId: %s)" , vpcIIDInfo .NameId , info .VpcIID .SystemId )
235+ } else {
236+ cblog .Warnf ("Failed to resolve VPC NameId for SystemId: %s, err: %v" , info .VpcIID .SystemId , err )
237+ }
238+ }
239+
240+ // Set NameId for AccessSubnetList (use OwnerVPCName if available)
241+ vpcNameForSubnet := iid .OwnerVPCName
242+ if vpcNameForSubnet == "" {
243+ vpcNameForSubnet = info .VpcIID .NameId
244+ }
245+ accessSubnetList := []cres.IID {}
246+ for _ , subnetIID := range info .AccessSubnetList {
247+ if vpcNameForSubnet == "" {
248+ // If VPC NameId is not available, just use SystemId for subnet
249+ cblog .Warnf ("VPC NameId not available, keeping subnet SystemId only: %s" , subnetIID .SystemId )
250+ accessSubnetList = append (accessSubnetList , subnetIID )
251+ continue
252+ }
253+
254+ var subnetIIDInfo SubnetIIDInfo
255+ err := infostore .GetByConditionsAndContain (& subnetIIDInfo , CONNECTION_NAME_COLUMN , iid .ConnectionName ,
256+ OWNER_VPC_NAME_COLUMN , vpcNameForSubnet , SYSTEM_ID_COLUMN , subnetIID .SystemId )
257+ if err != nil {
258+ // if not found, use SystemId only
259+ if checkNotFoundError (err ) {
260+ cblog .Info (err )
261+ accessSubnetList = append (accessSubnetList , subnetIID )
262+ continue
263+ }
264+ cblog .Error (err )
265+ // don't fail the whole list, just skip this subnet NameId resolution
266+ accessSubnetList = append (accessSubnetList , subnetIID )
267+ continue
268+ }
269+ if subnetIIDInfo .NameId != "" {
270+ subnetIID .NameId = subnetIIDInfo .NameId
271+ }
272+ accessSubnetList = append (accessSubnetList , subnetIID )
273+ }
274+ info .AccessSubnetList = accessSubnetList
275+
116276 infoList = append (infoList , & info )
117277 }
118278 return infoList , nil
@@ -138,6 +298,65 @@ func GetFileSystem(connectionName string, nameID string) (*cres.FileSystemInfo,
138298 return nil , err
139299 }
140300 info .IId = cres.IID {NameId : iidInfo .NameId , SystemId : iidInfo .SystemId }
301+
302+ // Set VPC NameId from FileSystemIIDInfo's OwnerVPCName (already stored)
303+ if iidInfo .OwnerVPCName != "" {
304+ // Fetch VPC SystemId from infostore to match with driver's SystemId
305+ var vpcIIDInfo VPCIIDInfo
306+ err := infostore .GetByConditions (& vpcIIDInfo , CONNECTION_NAME_COLUMN , iidInfo .ConnectionName , NAME_ID_COLUMN , iidInfo .OwnerVPCName )
307+ if err == nil {
308+ info .VpcIID .NameId = vpcIIDInfo .NameId
309+ cblog .Infof ("VPC NameId resolved from OwnerVPCName: %s (SystemId: %s)" , vpcIIDInfo .NameId , info .VpcIID .SystemId )
310+ } else {
311+ cblog .Warnf ("Failed to resolve VPC info for OwnerVPCName: %s, err: %v" , iidInfo .OwnerVPCName , err )
312+ }
313+ } else if info .VpcIID .SystemId != "" {
314+ // Fallback: try to resolve VPC NameId from SystemId (for old data)
315+ var vpcIIDInfo VPCIIDInfo
316+ err := infostore .GetByConditionsAndContain (& vpcIIDInfo , CONNECTION_NAME_COLUMN , iidInfo .ConnectionName ,
317+ NAME_ID_COLUMN , "" , SYSTEM_ID_COLUMN , info .VpcIID .SystemId )
318+ if err == nil && vpcIIDInfo .NameId != "" {
319+ info .VpcIID .NameId = vpcIIDInfo .NameId
320+ cblog .Infof ("VPC NameId resolved from SystemId (fallback): %s (SystemId: %s)" , vpcIIDInfo .NameId , info .VpcIID .SystemId )
321+ } else {
322+ cblog .Warnf ("Failed to resolve VPC NameId for SystemId: %s, err: %v" , info .VpcIID .SystemId , err )
323+ }
324+ }
325+
326+ // Set NameId for AccessSubnetList (use OwnerVPCName if available)
327+ vpcNameForSubnet := iidInfo .OwnerVPCName
328+ if vpcNameForSubnet == "" {
329+ vpcNameForSubnet = info .VpcIID .NameId
330+ }
331+ accessSubnetList := []cres.IID {}
332+ for _ , subnetIID := range info .AccessSubnetList {
333+ if vpcNameForSubnet == "" {
334+ // If VPC NameId is not available, just use SystemId for subnet
335+ cblog .Warnf ("VPC NameId not available, keeping subnet SystemId only: %s" , subnetIID .SystemId )
336+ accessSubnetList = append (accessSubnetList , subnetIID )
337+ continue
338+ }
339+
340+ var subnetIIDInfo SubnetIIDInfo
341+ err := infostore .GetByConditionsAndContain (& subnetIIDInfo , CONNECTION_NAME_COLUMN , iidInfo .ConnectionName ,
342+ OWNER_VPC_NAME_COLUMN , vpcNameForSubnet , SYSTEM_ID_COLUMN , subnetIID .SystemId )
343+ if err != nil {
344+ // if not found, use SystemId only
345+ if checkNotFoundError (err ) {
346+ cblog .Info (err )
347+ accessSubnetList = append (accessSubnetList , subnetIID )
348+ continue
349+ }
350+ cblog .Error (err )
351+ return nil , err
352+ }
353+ if subnetIIDInfo .NameId != "" {
354+ subnetIID .NameId = subnetIIDInfo .NameId
355+ }
356+ accessSubnetList = append (accessSubnetList , subnetIID )
357+ }
358+ info .AccessSubnetList = accessSubnetList
359+
141360 return & info , nil
142361}
143362
@@ -174,6 +393,33 @@ func AddAccessSubnet(connectionName string, nameID string, subnetIID cres.IID) (
174393 if err != nil {
175394 return nil , err
176395 }
396+
397+ //+++++++++++++++++++++++++++++++++++++++++++
398+ // set Subnet's SystemId
399+ var subnetIIDInfo SubnetIIDInfo
400+ if os .Getenv ("PERMISSION_BASED_CONTROL_MODE" ) != "" {
401+ var iidInfoList []* SubnetIIDInfo
402+ err = getAuthIIDInfoList (connectionName , & iidInfoList )
403+ if err != nil {
404+ cblog .Error (err )
405+ return nil , err
406+ }
407+ castedIIDInfo , err := getAuthIIDInfo (& iidInfoList , subnetIID .NameId )
408+ if err != nil {
409+ cblog .Error (err )
410+ return nil , err
411+ }
412+ subnetIIDInfo = * castedIIDInfo .(* SubnetIIDInfo )
413+ } else {
414+ err = infostore .GetByConditions (& subnetIIDInfo , CONNECTION_NAME_COLUMN , connectionName , NAME_ID_COLUMN , subnetIID .NameId )
415+ if err != nil {
416+ cblog .Error (err )
417+ return nil , err
418+ }
419+ }
420+ subnetIID = getDriverIID (cres.IID {NameId : subnetIIDInfo .NameId , SystemId : subnetIIDInfo .SystemId })
421+ //+++++++++++++++++++++++++++++++++++++++++++
422+
177423 cldConn , err := ccm .GetZoneLevelCloudConnection (connectionName , iidInfo .ZoneId )
178424 if err != nil {
179425 return nil , err
@@ -197,6 +443,33 @@ func RemoveAccessSubnet(connectionName string, nameID string, subnetIID cres.IID
197443 if err != nil {
198444 return false , err
199445 }
446+
447+ //+++++++++++++++++++++++++++++++++++++++++++
448+ // set Subnet's SystemId
449+ var subnetIIDInfo SubnetIIDInfo
450+ if os .Getenv ("PERMISSION_BASED_CONTROL_MODE" ) != "" {
451+ var iidInfoList []* SubnetIIDInfo
452+ err = getAuthIIDInfoList (connectionName , & iidInfoList )
453+ if err != nil {
454+ cblog .Error (err )
455+ return false , err
456+ }
457+ castedIIDInfo , err := getAuthIIDInfo (& iidInfoList , subnetIID .NameId )
458+ if err != nil {
459+ cblog .Error (err )
460+ return false , err
461+ }
462+ subnetIIDInfo = * castedIIDInfo .(* SubnetIIDInfo )
463+ } else {
464+ err = infostore .GetByConditions (& subnetIIDInfo , CONNECTION_NAME_COLUMN , connectionName , NAME_ID_COLUMN , subnetIID .NameId )
465+ if err != nil {
466+ cblog .Error (err )
467+ return false , err
468+ }
469+ }
470+ subnetIID = getDriverIID (cres.IID {NameId : subnetIIDInfo .NameId , SystemId : subnetIIDInfo .SystemId })
471+ //+++++++++++++++++++++++++++++++++++++++++++
472+
200473 cldConn , err := ccm .GetZoneLevelCloudConnection (connectionName , iidInfo .ZoneId )
201474 if err != nil {
202475 return false , err
0 commit comments