Skip to content

Commit

Permalink
Merge pull request #81 from mkumatag/image-name-check
Browse files Browse the repository at this point in the history
Add image-name check
  • Loading branch information
ltccci authored Dec 11, 2020
2 parents fda0f1a + 0ecffc5 commit 57c47c5
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
26 changes: 26 additions & 0 deletions cmd/image/qcow2ova/validate/image-name/image-name.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package image_name

// Validate if same image name exist in the folder, don't overwrite
import (
"fmt"
"github.com/ppc64le-cloud/pvsadm/pkg"
"os"
)

type Rule struct {
}

func (p *Rule) String() string {
return "image-name"
}

func (p *Rule) Verify() error {
if _, err := os.Stat(pkg.ImageCMDOptions.ImageName + ".ova.gz"); !os.IsNotExist(err) {
return fmt.Errorf("file already exist with name: %s", pkg.ImageCMDOptions.ImageName+".ova.gz")
}
return nil
}

func (p *Rule) Hint() string {
return "Please choose a different image-name and retry"
}
2 changes: 2 additions & 0 deletions cmd/image/qcow2ova/validate/register.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package validate

import (
"github.com/ppc64le-cloud/pvsadm/cmd/image/qcow2ova/validate/diskspace"
image_name "github.com/ppc64le-cloud/pvsadm/cmd/image/qcow2ova/validate/image-name"
"github.com/ppc64le-cloud/pvsadm/cmd/image/qcow2ova/validate/platform"
"github.com/ppc64le-cloud/pvsadm/cmd/image/qcow2ova/validate/tools"
"github.com/ppc64le-cloud/pvsadm/cmd/image/qcow2ova/validate/user"
Expand All @@ -11,6 +12,7 @@ func init() {
//TODO: Add Operating system check
AddRule(&user.Rule{})
AddRule(&platform.Rule{})
AddRule(&image_name.Rule{})
AddRule(&tools.Rule{})
AddRule(&diskspace.Rule{})
}

0 comments on commit 57c47c5

Please sign in to comment.