@@ -1196,13 +1196,13 @@ func (svm *SVirtualMachine) createDriverAndDisk(ctx context.Context, ds *SDatast
11961196 }, true )
11971197}
11981198
1199- func (svm * SVirtualMachine ) getDatastoreAndRootImagePath () (string , * SDatastore , error ) {
1199+ func (svm * SVirtualMachine ) getDatastoreAndRootImagePath (suffixCheck bool ) (string , * SDatastore , error ) {
12001200 layoutEx := svm .getLayoutEx ()
12011201 if layoutEx == nil || len (layoutEx .File ) == 0 {
12021202 return "" , nil , fmt .Errorf ("invalid LayoutEx" )
12031203 }
12041204 for _ , f := range layoutEx .File {
1205- if ! strings .HasSuffix (f .Name , ".vmdk" ) {
1205+ if suffixCheck && ! strings .HasSuffix (f .Name , ".vmdk" ) {
12061206 continue
12071207 }
12081208 file := f .Name
@@ -1223,21 +1223,26 @@ func (svm *SVirtualMachine) getDatastoreAndRootImagePath() (string, *SDatastore,
12231223 if datastore == nil {
12241224 return "" , nil , fmt .Errorf ("can't find storage associated with vm %q" , svm .GetName ())
12251225 }
1226- return datastore .getPathString (datastore .cleanPath (file )), datastore , nil
1226+ if strings .HasSuffix (f .Name , ".vmdk" ) {
1227+ return datastore .getPathString (datastore .cleanPath (file )), datastore , nil
1228+ }
1229+ path := datastore .cleanPath (file )
1230+ vmDir := strings .Split (path , "/" )[0 ]
1231+ return datastore .getPathString (fmt .Sprintf ("%s/%s.vmdk" , vmDir , vmDir )), datastore , nil
12271232 }
12281233 return "" , nil , fmt .Errorf ("can't find root image path" )
12291234}
12301235
12311236func (svm * SVirtualMachine ) GetRootImagePath () (string , error ) {
1232- path , _ , err := svm .getDatastoreAndRootImagePath ()
1237+ path , _ , err := svm .getDatastoreAndRootImagePath (true )
12331238 if err != nil {
12341239 return "" , err
12351240 }
12361241 return path , nil
12371242}
12381243
12391244func (svm * SVirtualMachine ) CopyRootDisk (ctx context.Context , imagePath string ) (string , error ) {
1240- newImagePath , datastore , err := svm .getDatastoreAndRootImagePath ()
1245+ newImagePath , datastore , err := svm .getDatastoreAndRootImagePath (false )
12411246 if err != nil {
12421247 return "" , errors .Wrapf (err , "GetRootImagePath" )
12431248 }
0 commit comments