Skip to content

Commit

Permalink
Added log levels
Browse files Browse the repository at this point in the history
  • Loading branch information
KeerthanaAP committed Nov 10, 2023
1 parent f3fdc21 commit 8154374
Show file tree
Hide file tree
Showing 28 changed files with 109 additions and 107 deletions.
2 changes: 1 addition & 1 deletion cmd/create/port/port.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ var Cmd = &cobra.Command{
if err != nil {
return fmt.Errorf("failed to create a port, err: %v", err)
}
klog.Infof("Successfully created a port, id: %s", *port.PortID)
klog.V(1).Infof("Successfully created a port, id: %s", *port.PortID)

table := utils.NewTable()
table.Render([]*models.NetworkPort{port}, []string{})
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 @@ -77,7 +77,7 @@ var Cmd = &cobra.Command{
if err != nil {
return fmt.Errorf("failed to delete a port, err: %v", err)
}
klog.Infof("Successfully deleted a port, id: %s", portID)
klog.V(1).Infof("Successfully deleted a port, id: %s", portID)
return nil
},
}
Expand Down
6 changes: 3 additions & 3 deletions cmd/dhcp-sync/dhcp-sync.go
Original file line number Diff line number Diff line change
Expand Up @@ -179,10 +179,10 @@ var Cmd = &cobra.Command{
if !ok {
return
}
klog.Info("event:", event)
klog.V(2).Info("event:", event)
if event.Op&fsnotify.Write == fsnotify.Write {
klog.Info("modified file:", event.Name)
klog.Info("restarting the dhcpd service")
klog.V(2).Info("modified file:", 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.V(1).Infof("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.V(1).Infof("Successfully Deleted a DHCP server")
return nil
},
}
Expand Down
14 changes: 7 additions & 7 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(3).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(3).Infof("Reading the existing service credential")
cred, ok = keys[0].Credentials["cos_hmac_keys"].(map[string]interface{})
}
if !ok {
Expand Down Expand Up @@ -200,7 +200,7 @@ pvsadm image import -n upstream-core-lon04 -b <BUCKETNAME> --object rhel-83-100
if *job.Status.State == "failed" {
return false, fmt.Errorf("image import job failed to complete, err: %v", job.Status.Message)
}
klog.Infof("Image Import Job in-progress, current state: %s", *job.Status.State)
klog.V(1).Infof("Image Import Job in-progress, current state: %s", *job.Status.State)
return false, nil
})
if pollErr == wait.ErrWaitTimeout {
Expand All @@ -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(2).Infof("Retriving 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.V(1).Infof("Importing Image %s is currently in %s state, Please check the Progress in the IBM Cloud UI\n", *image.Name, *image.State)
return nil
}

Expand All @@ -233,7 +233,7 @@ pvsadm image import -n upstream-core-lon04 -b <BUCKETNAME> --object rhel-83-100
if img.State == "active" {
return true, nil
}
klog.Infof("Import in-progress, current state: %s", img.State)
klog.V(1).Infof("Import in-progress, current state: %s", img.State)
return false, nil
})
if pollErr == wait.ErrWaitTimeout {
Expand All @@ -244,7 +244,7 @@ pvsadm image import -n upstream-core-lon04 -b <BUCKETNAME> --object rhel-83-100
return fmt.Errorf("failed to import the image, err: %v\n\nRun this command to get more information for the failure: pvsadm get events -i %s", pollErr, pvmclient.InstanceID)
}

klog.Infof("Successfully imported the image: %s with ID: %s within %s", *image.Name, *image.ImageID, time.Since(start))
klog.V(1).Infof("Successfully imported the image: %s with ID: %s within %s", *image.Name, *image.ImageID, time.Since(start))

return nil
},
Expand Down
6 changes: 3 additions & 3 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(2).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(2).Infof("Extract complete")
} else {
ova = fileName
}
Expand Down Expand Up @@ -110,7 +110,7 @@ pvsadm image info rhcos-46-12152021.ova.gz
klog.Warning("unable to find the pvsadm tool version")
return nil
}
klog.Infof("Pvsadm tool version used for creating this image: %+v", toolversion)
klog.V(1).Infof("Pvsadm tool version used for creating this image: %+v", toolversion)
return nil
},
}
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(2).Infof("Copying %s into %s", srcUrl, dest)
if err := cp(srcUrl, dest); err != nil {
return "", err
}
klog.Infof("Copy Completed!")
klog.V(2).Infof("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(2).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(2).Infof("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(2).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(2).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(2).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
2 changes: 1 addition & 1 deletion cmd/image/qcow2ova/prep/prepare.go
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,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.V(1).Infof("No image preparation required for the coreos...")
return nil
default:
return fmt.Errorf("not a supported distro: %s", dist)
Expand Down
32 changes: 16 additions & 16 deletions cmd/image/qcow2ova/qcow2ova.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ 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.")
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 @@ -160,7 +160,7 @@ 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)
klog.V(1).Infof("Autogenerated OS root password is: %s", opt.OSPassword)
if err != nil {
return err
}
Expand Down Expand Up @@ -194,7 +194,7 @@ Qcow2 images location:
signal.Notify(c, syscall.SIGINT, syscall.SIGTERM)
go func() {
<-c
klog.Infof("Received an interrupt, exiting...")
klog.V(1).Infof("Received an interrupt, exiting...")
prep.ExitChroot()
prep.UmountHostPartitions(mnt)
_ = prep.Umount(mnt)
Expand All @@ -207,7 +207,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(2).Infof("downloaded/copied the file at: %s", image)

var qcow2Img string

Expand All @@ -216,13 +216,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(2).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(2).Infof("Extract complete")
} else {
qcow2Img = image
}
Expand All @@ -235,41 +235,41 @@ Qcow2 images location:

rawImg := filepath.Join(ovaImgDir, ova.VolNameRaw)

klog.Infof("Converting Qcow2(%s) image to raw(%s) format", qcow2Img, rawImg)
klog.V(1).Infof("Converting Qcow2(%s) image to raw(%s) format", qcow2Img, rawImg)
err = qemuImgConvertQcow2Raw(qcow2Img, rawImg)
if err != nil {
return err
}
klog.Infof("Conversion completed")
klog.V(1).Infof("Conversion completed")

klog.Infof("Resizing the image %s to %dG", rawImg, opt.ImageSize)
klog.V(1).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.V(1).Infof("Resize completed")

klog.Infof("Preparing the image")
klog.V(1).Infof("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.V(1).Infof("Preparation completed")

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

klog.Infof("Compressing an OVA file")
klog.V(1).Infof("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.V(1).Infof("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.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ func (p *Rule) Verify() error {
}
free := (stat.Bavail * uint64(stat.Bsize)) / GB
need := opt.ImageSize + BUFFER
klog.Infof("free: %dG, need: %dG", free, need)
klog.V(1).Infof("free: %dG, need: %dG", free, need)
if free < need {
return fmt.Errorf("%s does not have enough space for the conversion need: %d but got %d", opt.TempDir, need, free)
}
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.V(1).Infof("%s found at %s\n", 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.V(1).Infof("Checking: %s\n", ruleStr)
if utils.Contains(pkg.ImageCMDOptions.PreflightSkip, ruleStr) {
klog.Infof("SKIPPED!")
klog.V(1).Infof("SKIPPED!")
continue
}
err := rule.Verify()
Expand Down
10 changes: 5 additions & 5 deletions cmd/image/sync/sync.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,14 +51,14 @@ const (
func copyWorker(copyJobs <-chan copyWorkload, results chan<- bool, workerId int) {
for copyJob := range copyJobs {
start := time.Now()
klog.Infof("Copying object: %s src bucket: %s dest bucket: %s", copyJob.srcObject, copyJob.srcBucket, copyJob.tgtBucket)
klog.V(1).Infof("Copying object: %s src bucket: %s dest bucket: %s", copyJob.srcObject, copyJob.srcBucket, copyJob.tgtBucket)
err := copyJob.s3Cli.CopyObjectToBucket(copyJob.srcBucket, copyJob.tgtBucket, copyJob.srcObject)
if err != nil {
klog.Errorf("ERROR: %v, Copy object %s failed", err, copyJob.srcObject)
results <- false
}
duration := time.Since(start)
klog.Infof("Copying object: %s from bucket: %s to bucket: %s took %v", copyJob.srcObject, copyJob.srcBucket, copyJob.tgtBucket, duration)
klog.V(1).Infof("Copying object: %s from bucket: %s to bucket: %s took %v", copyJob.srcObject, copyJob.srcBucket, copyJob.tgtBucket, duration)
results <- true
}
}
Expand Down Expand Up @@ -118,7 +118,7 @@ func copyObjects(spec []pkg.Spec, instanceList []InstanceItem, copyJobs chan<- c
return err
}

klog.Infof("Selected Objects from bucket %s: %s", item.Source.Bucket, strings.Join(selectedObjects, ", "))
klog.V(1).Infof("Selected Objects from bucket %s: %s", item.Source.Bucket, strings.Join(selectedObjects, ", "))
for targetItemNo, targetItem := range item.Target {
_, err = instanceList[item_no].Target[targetItemNo].CheckBucketLocationConstraint(targetItem.Bucket, targetItem.Region+"-"+targetItem.StorageClass)
if err != nil {
Expand Down Expand Up @@ -152,7 +152,7 @@ func getResults(results <-chan bool, totalChannels int) bool {
}
passedCopies = passedCopies + 1
}
klog.Infof("No of copies passed: %d No of copies failed: %d", passedCopies, failedCopies)
klog.V(1).Infof("No of copies passed: %d No of copies failed: %d", passedCopies, failedCopies)
return failedCopies == 0
}

Expand Down Expand Up @@ -282,7 +282,7 @@ Sample spec.yaml file:

// Calculate total elapsed time
duration := time.Since(start)
klog.Infof("Total elapsed time: %v", duration)
klog.V(1).Infof("Total elapsed time: %v", duration)
return nil
},
}
Expand Down
Loading

0 comments on commit 8154374

Please sign in to comment.