@@ -26,45 +26,43 @@ func NewCreateStemcellMethod(driverClient driver.Client, stemcellClient stemcell
2626}
2727
2828func (c CreateStemcellMethod ) CreateStemcell (localImagePath string , stemcellCloudProps apiv1.StemcellCloudProps ) (apiv1.StemcellCID , error ) {
29+ defer c .stemcellStore .Cleanup ()
30+
2931 stemcellUuid , _ := c .uuidGen .Generate ()
3032 stemcellId := "cs-" + stemcellUuid
3133 stemcellCID := apiv1 .NewStemcellCID (stemcellUuid )
32- imagePath := ""
34+ storeImagePath := ""
3335
34- c .logger .DebugWithDetails ("cpi" , "stemcellCloudProps:" , stemcellCloudProps )
36+ c .logger .Debug ("cpi" , "stemcellCloudProps: %#+v " , stemcellCloudProps )
3537 stemcellProps , err := stemcell .NewStemcellProps (stemcellCloudProps )
3638 if err != nil {
3739 return stemcellCID , err
3840 }
3941
40- c .logger .DebugWithDetails ("cpi" , "LocalImagePath:" , localImagePath )
42+ c .logger .Debug ("cpi" , "LocalImagePath: %s" , localImagePath )
43+
44+ storeImagePath , err = c .stemcellStore .GetByImagePathMapping (localImagePath )
45+ if err != nil {
46+ c .logger .Debug ("cpi" , "Stemcell image found at path:" , localImagePath )
47+
48+ return stemcellCID , err
49+ }
4150
42- if c .fs .FileExists (localImagePath ) {
43- imagePath = localImagePath
44- } else {
45- defer c .stemcellStore .Cleanup ()
46- storeImagePath , err := c .stemcellStore .GetByImagePathMapping (localImagePath )
51+ if storeImagePath == "" {
52+ storeImagePath , err = c .stemcellStore .GetByMetadata (stemcellProps .Name , stemcellProps .Version )
4753 if err != nil {
54+ c .logger .Debug ("cpi" , "Stemcell image found by metadata" )
4855 return stemcellCID , err
4956 }
57+ }
5058
51- if storeImagePath == "" {
52- storeImagePath , err = c .stemcellStore .GetByMetadata (stemcellProps .Name , stemcellProps .Version )
53- if err != nil {
54- return stemcellCID , err
55- }
56- }
57-
58- c .logger .DebugWithDetails ("cpi" , "StoreImagePath:" , storeImagePath )
59+ c .logger .DebugWithDetails ("cpi" , "StoreImagePath:" , storeImagePath )
5960
60- if c .fs .FileExists (storeImagePath ) {
61- imagePath = storeImagePath
62- } else {
63- return stemcellCID , errors .New ("stemcell image not found locally or in image store" )
64- }
61+ if storeImagePath == "" {
62+ return stemcellCID , errors .New ("stemcell image not found locally or in image store" )
6563 }
6664
67- ovfPath , err := c .stemcellClient .ExtractOvf (imagePath )
65+ ovfPath , err := c .stemcellClient .ExtractOvf (storeImagePath )
6866 if err != nil {
6967 return stemcellCID , err
7068 }
0 commit comments