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 14, 2024
1 parent 38c9866 commit fd46b99
Show file tree
Hide file tree
Showing 23 changed files with 97 additions and 81 deletions.
6 changes: 3 additions & 3 deletions cmd/dhcp-sync/dhcp-sync.go
Original file line number Diff line number Diff line change
Expand Up @@ -184,10 +184,10 @@ 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("modified file:%s", event.Name)
klog.V(2).Info("restarting the dhcpd service")
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
3 changes: 2 additions & 1 deletion 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 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
2 changes: 1 addition & 1 deletion cmd/dhcpserver/delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -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/get/peravailability/peravailability.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
},
}
8 changes: 4 additions & 4 deletions cmd/image/import/import.go
Original file line number Diff line number Diff line change
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("Importing Image %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.Fatalf("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 file : %s/%s", 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/tools/tools.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ func (p *Rule) Verify() error {
p.failedCommand = command
return err
}
klog.Infof("%s found at %s\n", command, path)
klog.Infof("%s found at %s", command, path)
}
return nil
}
Expand Down
4 changes: 2 additions & 2 deletions cmd/image/qcow2ova/validate/validate.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,9 @@ func AddRule(r Rule) {
func Validate() error {
for _, rule := range rules {
ruleStr := rule.String()
klog.Infof("Checking: %s\n", ruleStr)
klog.Infof("Checking: %s", ruleStr)
if utils.Contains(pkg.ImageCMDOptions.PreflightSkip, ruleStr) {
klog.Infof("SKIPPED!")
klog.Info("SKIPPED!")
continue
}
err := rule.Verify()
Expand Down
4 changes: 2 additions & 2 deletions cmd/image/sync/sync_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ func TestGetSpec(t *testing.T) {

SpecFileName := file.Name()
defer os.Remove(SpecFileName)
klog.Infoln("Specfile :", SpecFileName)
klog.V(1).Infof("Specfile :%s", SpecFileName)

specString, merr := yaml.Marshal(&spec)
require.NoError(t, merr, "Error in Unmarshalling Specfile")
Expand Down Expand Up @@ -247,7 +247,7 @@ func mockCreateInstances(mockSyncClient *mocksync.MockSyncClient) []InstanceItem
}

func mockCreateSpec() []pkg.Spec {
klog.Infoln("STEP: Generating Spec")
klog.V(1).Info("STEP: Generating Spec")
specSlice := make([]pkg.Spec, 0)
for i := 0; i < noOfSources; i++ {
specSlice = append(specSlice, utils.GenerateSpec(noOfTargetsPerSource))
Expand Down
10 changes: 5 additions & 5 deletions cmd/image/upload/upload.go
Original file line number Diff line number Diff line change
Expand Up @@ -149,20 +149,20 @@ pvsadm image upload --bucket bucket1320 -f centos-8-latest.ova.gz --bucket-regio
}
}
} else if len(instances) == 0 {
klog.Infof("No active Cloud Object Storage instances were found in the account\n")
klog.Info("No active Cloud Object Storage instances were found in the account")
}

// Ask if user likes to use existing instance
if opt.InstanceName == "" && len(instances) != 0 {
klog.Infof("Bucket %s not found in the account provided\n", opt.BucketName)
klog.Infof("Bucket %s not found in the account provided", opt.BucketName)
if utils.AskConfirmation(UseExistingPromptMessage) {
availableInstances := []string{}
for name := range instances {
availableInstances = append(availableInstances, name)
}
selectedInstance := utils.SelectItem("Select Cloud Object Storage Instance:", availableInstances)
opt.InstanceName = selectedInstance
klog.Infof("Selected InstanceName is %s\n", opt.InstanceName)
klog.Infof("Selected InstanceName is %s", opt.InstanceName)
}
}

Expand Down Expand Up @@ -190,7 +190,7 @@ pvsadm image upload --bucket bucket1320 -f centos-8-latest.ova.gz --bucket-regio
}

opt.InstanceName = utils.ReadUserInput("Type Name of the Cloud Object Storage instance:")
klog.Infof("Creating a new cos %s instance\n", opt.InstanceName)
klog.Infof("Creating a new cos %s instance", opt.InstanceName)

_, err = bxCli.CreateServiceInstance(opt.InstanceName, ServiceType, opt.ServicePlan,
opt.ResourceGrp, ResourceGroupAPIRegion)
Expand All @@ -215,7 +215,7 @@ pvsadm image upload --bucket bucket1320 -f centos-8-latest.ova.gz --bucket-regio

//Create a new bucket
if !bucketExists {
klog.Infof("Creating a new bucket %s\n", opt.BucketName)
klog.Infof("Creating a new bucket %s", opt.BucketName)
s3Cli, err = client.NewS3Client(bxCli, opt.InstanceName, opt.Region)
if err != nil {
return err
Expand Down
2 changes: 1 addition & 1 deletion cmd/purge/volumes/volumes.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ pvsadm purge --help for information
t.Table.Render()

if !opt.DryRun && len(volumes) != 0 {
klog.Infof("Deleting all the volumes in available state")
klog.Info("Deleting all the volumes in available state")
if opt.NoPrompt || utils.AskYesOrNo(deletePromptMessage) {
for _, volume := range volumes {
if *volume.State == "available" {
Expand Down
2 changes: 1 addition & 1 deletion cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ This is a tool built for the Power Systems Virtual Server helps managing and mai
PersistentPreRunE: func(cmd *cobra.Command, args []string) error {
if pkg.Options.APIKey == "" {
if key := os.Getenv("IBMCLOUD_API_KEY"); key != "" {
klog.Infof("Using an API key from IBMCLOUD_API_KEY environment variable")
klog.V(1).Info("Using an API key from IBMCLOUD_API_KEY environment variable")
pkg.Options.APIKey = key
}
}
Expand Down
Loading

0 comments on commit fd46b99

Please sign in to comment.