info

package
v0.1.14 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 1, 2024 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Cmd = &cobra.Command{
	Use:   "info",
	Short: "Provide info about the image",
	Long: `Provide info about the image
pvsadm image info --help for information

Examples:
# To get the pvsadm tool version by specifying the image
pvsadm image info rhcos-46-12152021.ova.gz

`,
	RunE: func(cmd *cobra.Command, args []string) error {

		if len(args) == 0 {
			return fmt.Errorf("Image filepath is required")
		}

		fileName := args[0]
		var ova string
		ovaImgDir, err := os.MkdirTemp(os.TempDir(), "ova-img-dir")
		if err != nil {
			return err
		}

		defer os.RemoveAll(ovaImgDir)

		checkGzip, err := utils.IsGzip(fileName)
		if err != nil {
			return fmt.Errorf("failed to detect the image filetype: %v", err)
		}
		if checkGzip {
			klog.Infof("Image %s is in gzip format, extracting it", fileName)
			ova = filepath.Join(ovaImgDir, "image.ova")
			err = utils.GunzipIt(fileName, ova)
			if err != nil {
				return err
			}
			klog.Infof("Extract complete")
		} else {
			ova = fileName
		}

		err = utils.Untar(ova, ovaImgDir, "*.ovf")
		if err != nil {
			return err
		}
		ovfFilePath := ovaImgDir + "/*.ovf"
		matches, err := filepath.Glob(ovfFilePath)
		if err != nil {
			return err
		}
		if len(matches) == 0 {
			return fmt.Errorf(".ovf file is not found in %s image", fileName)
		}
		filename := matches[0]

		type Ovf struct {
			Pvsadmversionsection struct {
				Info        string `xml:"Info"`
				BuildNumber string `xml:"BuildNumber"`
			} `xml:"pvsadmversionsection"`
		}

		xmlFile, err := os.Open(filename)
		if err != nil {
			return err
		}
		defer xmlFile.Close()
		var version Ovf
		byteValue, err := io.ReadAll(xmlFile)
		if err != nil {
			return err
		}
		err = xml.Unmarshal(byteValue, &version)
		if err != nil {
			return err
		}
		toolversion := version.Pvsadmversionsection.BuildNumber
		if toolversion == "" {
			klog.Warning("unable to find the pvsadm tool version")
			return nil
		}
		klog.Infof("Pvsadm tool version used for creating this image: %+v", toolversion)
		return nil
	},
}

Functions

This section is empty.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL