Skip to content

Commit

Permalink
Added log levels
Browse files Browse the repository at this point in the history
  • Loading branch information
KeerthanaAP committed Feb 27, 2024
1 parent 3f24a6f commit ad45d00
Show file tree
Hide file tree
Showing 32 changed files with 153 additions and 138 deletions.
2 changes: 1 addition & 1 deletion cmd/create/port/port.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ var Cmd = &cobra.Command{

c, err := client.NewClientWithEnv(opt.APIKey, opt.Environment, opt.Debug)
if err != nil {
klog.Errorf("failed to create a session with IBM cloud: %v", err)
klog.Errorf("failed to create a session with IBM cloud, err: %v", err)
return err
}

Expand Down
2 changes: 1 addition & 1 deletion cmd/delete/port/port.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ var Cmd = &cobra.Command{

c, err := client.NewClientWithEnv(opt.APIKey, opt.Environment, opt.Debug)
if err != nil {
klog.Errorf("failed to create a session with IBM cloud: %v", err)
klog.Errorf("failed to create a session with IBM cloud, err: %v", err)
return err
}

Expand Down
5 changes: 2 additions & 3 deletions cmd/dhcp-sync/dhcp-sync.go
Original file line number Diff line number Diff line change
Expand Up @@ -184,10 +184,9 @@ var Cmd = &cobra.Command{
if !ok {
return
}
klog.Info("event:", event)
klog.V(2).Infof("event: %v", event)
if event.Op&fsnotify.Write == fsnotify.Write {
klog.Info("modified file:", event.Name)
klog.Info("restarting the dhcpd service")
klog.V(2).Infof("%s has been modified, proceeding to restart dhcpd service", event.Name)
exitcode, out, err := utils.RunCMD("systemctl", "restart", "dhcpd")
if exitcode != 0 {
klog.Errorf("failed to restart the dhcpd service, exitcode: %d, stdout: %s, err: %s", exitcode, out, err)
Expand Down
5 changes: 3 additions & 2 deletions cmd/dhcpserver/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ package dhcpserver

import (
"fmt"

"github.com/IBM/go-sdk-core/v5/core"

"github.com/spf13/cobra"
Expand All @@ -40,7 +41,7 @@ var createCmd = &cobra.Command{

c, err := client.NewClientWithEnv(opt.APIKey, opt.Environment, opt.Debug)
if err != nil {
klog.Errorf("failed to create a session with IBM cloud: %v", err)
klog.Errorf("failed to create a session with IBM cloud, err: %v", err)
return err
}

Expand Down Expand Up @@ -69,7 +70,7 @@ var createCmd = &cobra.Command{
return fmt.Errorf("failed to create a dhcpserver, err: %v", err)
}

klog.Infof("Successfully created a DHCP server")
klog.Info("Successfully created a DHCP server")
return nil
},
}
Expand Down
4 changes: 2 additions & 2 deletions cmd/dhcpserver/delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ var deleteCmd = &cobra.Command{

c, err := client.NewClientWithEnv(opt.APIKey, opt.Environment, opt.Debug)
if err != nil {
klog.Errorf("failed to create a session with IBM cloud: %v", err)
klog.Errorf("failed to create a session with IBM cloud, err: %v", err)
return err
}

Expand All @@ -48,7 +48,7 @@ var deleteCmd = &cobra.Command{
return fmt.Errorf("failed to delete a dhcpserver, err: %v", err)
}

klog.Infof("Successfully Deleted a DHCP server")
klog.Info("Successfully Deleted a DHCP server")
return nil
},
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/dhcpserver/get.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ var getCmd = &cobra.Command{

c, err := client.NewClientWithEnv(opt.APIKey, opt.Environment, opt.Debug)
if err != nil {
klog.Errorf("failed to create a session with IBM cloud: %v", err)
klog.Errorf("failed to create a session with IBM cloud, err: %v", err)
return err
}

Expand Down
2 changes: 1 addition & 1 deletion cmd/dhcpserver/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ var listCmd = &cobra.Command{

c, err := client.NewClientWithEnv(opt.APIKey, opt.Environment, opt.Debug)
if err != nil {
klog.Errorf("failed to create a session with IBM cloud: %v", err)
klog.Errorf("failed to create a session with IBM cloud, err: %v", err)
return err
}

Expand Down
2 changes: 1 addition & 1 deletion cmd/get/events/events.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ var Cmd = &cobra.Command{

c, err := client.NewClientWithEnv(opt.APIKey, opt.Environment, opt.Debug)
if err != nil {
klog.Errorf("failed to create a session with IBM cloud: %v", err)
klog.Errorf("failed to create a session with IBM cloud, err: %v", err)
return err
}

Expand Down
4 changes: 2 additions & 2 deletions cmd/get/peravailability/peravailability.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ var Cmd = &cobra.Command{
opt := pkg.Options
c, err := client.NewClientWithEnv(opt.APIKey, opt.Environment, opt.Debug)
if err != nil {
klog.Errorf("failed to create a session with IBM cloud: %v", err)
klog.Errorf("failed to create a session with IBM cloud, err: %v", err)
return err
}

Expand All @@ -69,7 +69,7 @@ var Cmd = &cobra.Command{
klog.Infof("%s, where the current instance is present supports PER.", pvmclient.Zone)
}
sort.Strings(perEnabledRegions)
klog.Infoln("The following zones/datacenters have support for PER:", perEnabledRegions, ".", "More information at https://cloud.ibm.com/docs/overview?topic=overview-locations")
klog.Infof("The following zones/datacenters have support for PER:%v.More information at https://cloud.ibm.com/docs/overview?topic=overview-locations", perEnabledRegions)
return nil
},
}
2 changes: 1 addition & 1 deletion cmd/get/ports/ports.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ var Cmd = &cobra.Command{

c, err := client.NewClientWithEnv(opt.APIKey, opt.Environment, opt.Debug)
if err != nil {
klog.Errorf("failed to create a session with IBM cloud: %v", err)
klog.Errorf("failed to create a session with IBM cloud, err: %v", err)
return err
}

Expand Down
10 changes: 5 additions & 5 deletions cmd/image/import/import.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ pvsadm image import -n upstream-core-lon04 -b <BUCKETNAME> --object rhel-83-100
validStorageType := []string{"tier3", "tier1"}

if !utils.Contains(validStorageType, strings.ToLower(opt.StorageType)) {
klog.Errorf("Provide valid StorageType.. allowable values are [tier1, tier3]")
klog.Errorf("provide valid StorageType. Allowable values are [tier1, tier3]")
os.Exit(1)
}

Expand Down Expand Up @@ -148,7 +148,7 @@ pvsadm image import -n upstream-core-lon04 -b <BUCKETNAME> --object rhel-83-100
}

// Create the service credential if does not exist
klog.Infof("Auto Generating the COS Service credential for importing the image with name: %s", opt.ServiceCredName)
klog.V(2).Infof("Auto Generating the COS Service credential for importing the image with name: %s", opt.ServiceCredName)
CreateServiceKeyRequest := controller.CreateServiceKeyRequest{
Name: opt.ServiceCredName,
SourceCRN: crn,
Expand All @@ -161,7 +161,7 @@ pvsadm image import -n upstream-core-lon04 -b <BUCKETNAME> --object rhel-83-100
cred, ok = newKey.Credentials["cos_hmac_keys"].(map[string]interface{})
} else {
// Use the service credential already created
klog.Infof("Reading the existing service credential")
klog.V(2).Info("Reading the existing service credential")
cred, ok = keys[0].Credentials["cos_hmac_keys"].(map[string]interface{})
}
if !ok {
Expand Down Expand Up @@ -217,11 +217,11 @@ pvsadm image import -n upstream-core-lon04 -b <BUCKETNAME> --object rhel-83-100
if err != nil {
return err
}
klog.Infof("Retriving image details")
klog.V(1).Info("Retrieving image details")
}

if !opt.Watch {
klog.Infof("Importing Image %s is currently in %s state, Please check the Progress in the IBM Cloud UI\n", *image.Name, *image.State)
klog.Infof("Image import for %s is currently in %s state, Please check the progress in the IBM cloud UI", *image.Name, *image.State)
return nil
}

Expand Down
4 changes: 2 additions & 2 deletions cmd/image/info/info.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,13 +58,13 @@ pvsadm image info rhcos-46-12152021.ova.gz
return fmt.Errorf("failed to detect the image filetype: %v", err)
}
if checkGzip {
klog.Infof("Image %s is in gzip format, extracting it", fileName)
klog.V(1).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")
klog.V(1).Info("Extract complete")
} else {
ova = fileName
}
Expand Down
8 changes: 4 additions & 4 deletions cmd/image/qcow2ova/get-image.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,18 +40,18 @@ func getImage(downloadDir string, srcUrl string, timeout time.Duration) (string,
if !fileExists(srcUrl) {
return "", fmt.Errorf("not a valid URL or file does not exist at %s", srcUrl)
}
klog.Infof("Copying %s into %s", srcUrl, dest)
klog.V(1).Infof("Copying %s into %s", srcUrl, dest)
if err := cp(srcUrl, dest); err != nil {
return "", err
}
klog.Infof("Copy Completed!")
klog.V(1).Info("Copy Completed!")
} else {
out, err := os.Create(dest)
if err != nil {
return "", err
}
defer out.Close()
klog.Infof("Downloading %s into %s", srcUrl, dest)
klog.V(1).Infof("Downloading %s into %s", srcUrl, dest)
client := http.Client{
Timeout: timeout,
}
Expand All @@ -69,7 +69,7 @@ func getImage(downloadDir string, srcUrl string, timeout time.Duration) (string,
if err != nil {
return "", err
}
klog.Infof("Download Completed!")
klog.V(1).Info("Download Completed!")
}
return dest, nil
}
Expand Down
6 changes: 3 additions & 3 deletions cmd/image/qcow2ova/prep/loop.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,11 +108,11 @@ func Umount(dir string) error {
exitcode, out, err := utils.RunCMD("umount", dir)
if exitcode != 0 {
if strings.Contains(err, "not mounted") {
klog.Infof("Ignoring 'not mounted' error for %s", dir)
klog.V(1).Infof("Ignoring 'not mounted' error for %s", dir)
return nil
}
if strings.Contains(err, "no mount point specified") {
klog.Infof("Ignoring 'no mount point specified' error for %s", dir)
klog.V(1).Infof("Ignoring 'no mount point specified' error for %s", dir)
return nil
}
if strings.Contains(err, "target is busy") {
Expand All @@ -122,7 +122,7 @@ func Umount(dir string) error {
return nil
}
}
klog.Infof(" As '%s' is busy, unmounting it using lazy unmount", dir)
klog.V(1).Infof("As '%s' is busy, unmounting it using lazy unmount", dir)
exitcode, out, err = utils.RunCMD("umount", "-lf", dir)
if exitcode == 0 {
return nil
Expand Down
6 changes: 3 additions & 3 deletions cmd/image/qcow2ova/prep/prepare.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ import (
"path/filepath"
"strings"

"github.com/ppc64le-cloud/pvsadm/pkg/utils"

"k8s.io/klog/v2"

"github.com/ppc64le-cloud/pvsadm/pkg/utils"
)

var (
Expand Down Expand Up @@ -146,7 +146,7 @@ func Prepare4capture(mnt, volume, dist, rhnuser, rhnpasswd, rootpasswd string) e
case "rhel", "centos":
return prepare(mnt, volume, dist, rhnuser, rhnpasswd, rootpasswd)
case "coreos":
klog.Infof("No image preparation required for the coreos...")
klog.Info("No image preparation required for the coreos.")
return nil
default:
return fmt.Errorf("not a supported distro: %s", dist)
Expand Down
42 changes: 28 additions & 14 deletions cmd/image/qcow2ova/qcow2ova.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ package qcow2ova

import (
"fmt"
"io/ioutil"
"os"
"os/signal"
"path/filepath"
Expand Down Expand Up @@ -96,8 +97,8 @@ Qcow2 images location:
if strings.ToLower(opt.ImageDist) == "coreos" {
return fmt.Errorf("--prep-template option is not supported for coreos distro")
} else {
klog.Info("Overriding with the user defined image preparation template.")
content, err := os.ReadFile(opt.PrepTemplate)
klog.V(2).Info("Overriding with the user defined image preparation template.")
content, err := ioutil.ReadFile(opt.PrepTemplate)
if err != nil {
return err
}
Expand Down Expand Up @@ -159,10 +160,23 @@ Qcow2 images location:
if opt.ImageDist != "coreos" && opt.OSPassword == "" && !opt.OSPasswordSkip {
var err error
opt.OSPassword, err = GeneratePassword(12)
klog.Infof("Autogenerated OS root password is: %s", opt.OSPassword)
if err != nil {
return err
}
passwordfile, err := os.Create("password.txt")
if err != nil {
klog.Errorf("failed to create password file, err: %v", err)
return err
}

passwordfile.WriteString(fmt.Sprintf("Root Password : %s", opt.OSPassword))
cwd, err := os.Getwd()
if err != nil {
return err
}

klog.Infof("Autogenerated OS root password is updated in %s", filepath.Join(cwd, passwordfile.Name()))

}

// preflight checks validations
Expand Down Expand Up @@ -193,7 +207,7 @@ Qcow2 images location:
signal.Notify(c, syscall.SIGINT, syscall.SIGTERM)
go func() {
<-c
klog.Infof("Received an interrupt, exiting...")
klog.Info("Received an interrupt, exiting.")
prep.ExitChroot()
prep.UmountHostPartitions(mnt)
_ = prep.Umount(mnt)
Expand All @@ -206,7 +220,7 @@ Qcow2 images location:
return fmt.Errorf("failed to download the %s into %s, error: %v", opt.ImageURL, tmpDir, err)
}

klog.Infof("downloaded/copied the file at: %s", image)
klog.V(1).Infof("downloaded/copied the file at: %s", image)

var qcow2Img string

Expand All @@ -215,13 +229,13 @@ Qcow2 images location:
return fmt.Errorf("failed to detect the image filetype: %v", err)
}
if checkGzip {
klog.Infof("Image %s is in gzip format, extracting it", image)
klog.V(1).Infof("Image %s is in gzip format, extracting it", image)
qcow2Img = filepath.Join(tmpDir, ova.VolName+".qcow2")
err = utils.GunzipIt(image, qcow2Img)
if err != nil {
return err
}
klog.Infof("Extract complete")
klog.V(1).Info("Extract complete")
} else {
qcow2Img = image
}
Expand All @@ -239,36 +253,36 @@ Qcow2 images location:
if err != nil {
return err
}
klog.Infof("Conversion completed")
klog.Info("Conversion completed")

klog.Infof("Resizing the image %s to %dG", rawImg, opt.ImageSize)
err = qemuImgResize("-f", "raw", rawImg, fmt.Sprintf("%dG", opt.ImageSize))
if err != nil {
return err
}
klog.Infof("Resize completed")
klog.Info("Resize completed")

klog.Infof("Preparing the image")
klog.Info("Preparing the image")
err = prep.Prepare4capture(mnt, rawImg, opt.ImageDist, opt.RHNUser, opt.RHNPassword, opt.OSPassword)
if err != nil {
return fmt.Errorf("failed while preparing the image for %s distro, err: %v", opt.ImageDist, err)
}
klog.Infof("Preparation completed")
klog.Info("Preparation completed")

klog.Infof("Creating an OVA bundle")
klog.Info("Creating an OVA bundle")
ovafile := filepath.Join(tmpDir, opt.ImageName+".ova")
if err := ova.CreateTarArchive(ovaImgDir, ovafile, opt.TargetDiskSize, opt.ImageDist, volumeDiskName); err != nil {
return fmt.Errorf("failed to create ova bundle, err: %v", err)
}
klog.Infof("OVA bundle creation completed: %s", ovafile)

klog.Infof("Compressing an OVA file")
klog.Info("Compressing an OVA file")
ovaGZfile := filepath.Join(cwd, opt.ImageName+".ova.gz")
err = utils.GzipIt(ovafile, ovaGZfile)
if err != nil {
return err
}
klog.Infof("OVA file Compression completed")
klog.Info("OVA file Compression completed")

fmt.Printf("\n\nSuccessfully converted Qcow2 image to OVA format, find at %s\nOS root password: %s\n", ovaGZfile, opt.OSPassword)
return nil
Expand Down
2 changes: 1 addition & 1 deletion cmd/image/qcow2ova/validate/diskspace/diskspace_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ func (p *Rule) String() string {
}

func (p *Rule) Verify() error {
return fmt.Errorf("Not supported on Windows platform")
return fmt.Errorf("not supported on Windows platform")
}

func (p *Rule) Hint() string {
Expand Down
Loading

0 comments on commit ad45d00

Please sign in to comment.