Skip to content

Commit

Permalink
Added log levels
Browse files Browse the repository at this point in the history
  • Loading branch information
KeerthanaAP committed Jan 12, 2024
1 parent 14fc57b commit 48589cc
Show file tree
Hide file tree
Showing 17 changed files with 75 additions and 63 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).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
1 change: 1 addition & 0 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 Down
6 changes: 3 additions & 3 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).Infof("Reading the existing service credential")
cred, ok = keys[0].Credentials["cos_hmac_keys"].(map[string]interface{})
}
if !ok {
Expand Down Expand Up @@ -217,7 +217,7 @@ 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).Infof("Retriving image details")
}

if !opt.Watch {
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).Infof("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).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(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).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(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
1 change: 0 additions & 1 deletion cmd/image/qcow2ova/prep/prepare.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import (
"strings"

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

"k8s.io/klog/v2"
)

Expand Down
26 changes: 20 additions & 6 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 @@ -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).Infof("Extract complete")
} else {
qcow2Img = image
}
Expand Down
14 changes: 5 additions & 9 deletions cmd/image/sync/mock/sync_client_generated.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

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).Infoln("Specfile :", 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).Infoln("STEP: Generating Spec")
specSlice := make([]pkg.Spec, 0)
for i := 0; i < noOfSources; i++ {
specSlice = append(specSlice, utils.GenerateSpec(noOfTargetsPerSource))
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).Infof("Using an API key from IBMCLOUD_API_KEY environment variable")
pkg.Options.APIKey = key
}
}
Expand Down
1 change: 1 addition & 0 deletions pkg/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import (
"github.com/IBM-Cloud/bluemix-go/rest"
bxsession "github.com/IBM-Cloud/bluemix-go/session"
"k8s.io/klog/v2"

//"golang.org/x/oauth2/jwt"
"github.com/golang-jwt/jwt"
)
Expand Down
2 changes: 1 addition & 1 deletion pkg/client/network/network.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ func (c *Client) GetAll() (*models.Networks, error) {
resp, err := c.session.Power.PCloudNetworks.PcloudNetworksGetall(params, c.session.AuthInfo(c.instanceID))

if err != nil || resp.Payload == nil {
klog.Infof("Failed to perform the operation... %v", err)
klog.V(1).Infof("Failed to perform the operation... %v", err)
return nil, errors.ToError(err)
}

Expand Down
4 changes: 2 additions & 2 deletions pkg/client/pvmclient.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,8 @@ func NewPVMClient(c *Client, instanceID, instanceName, ep string) (*PVMClient, e
}
found := false
for _, svc := range svcs {
klog.V(4).Infof("Service ID: %s, region_id: %s, Name: %s", svc.Guid, svc.RegionID, svc.Name)
klog.V(4).Infof("crn: %v", svc.Crn)
klog.V(3).Infof("Service ID: %s, region_id: %s, Name: %s", svc.Guid, svc.RegionID, svc.Name)
klog.V(3).Infof("crn: %v", svc.Crn)
if svc.Name == instanceName {
instanceID = svc.Guid
found = true
Expand Down
12 changes: 6 additions & 6 deletions pkg/client/s3client.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,8 @@ func NewS3Client(c *Client, instanceName, region string) (s3client *S3Client, er
}
found := false
for _, svc := range svcs {
klog.V(4).Infof("Service ID: %s, region_id: %s, Name: %s", svc.Guid, svc.RegionID, svc.Name)
klog.V(4).Infof("crn: %v", svc.Crn)
klog.V(3).Infof("Service ID: %s, region_id: %s, Name: %s", svc.Guid, svc.RegionID, svc.Name)
klog.V(3).Infof("crn: %v", svc.Crn)
if svc.Name == instanceName {
instanceID = svc.Guid
found = true
Expand Down Expand Up @@ -118,7 +118,7 @@ func NewS3Client(c *Client, instanceName, region string) (s3client *S3Client, er
func (c *S3Client) CheckBucketExists(bucketName string) (bool, error) {
result, err := c.S3Session.ListBuckets(nil)
if err != nil {
klog.Infof("Unable to list buckets, %v\n", err)
klog.V(1).Infof("Unable to list buckets, %v\n", err)
return false, err
}

Expand Down Expand Up @@ -151,7 +151,7 @@ func (c *S3Client) SelectObjects(bucketName string, regex string) ([]string, err
return true
})
if err != nil {
klog.Infof("failed to list objects, %v\n", err)
klog.V(1).Infof("failed to list objects %v\n", err)
return nil, err
}
return matchedObjects, err
Expand All @@ -166,7 +166,7 @@ func (c *S3Client) CheckBucketLocationConstraint(bucketName string, bucketLocati

result, err := c.S3Session.GetBucketLocation(getParams)
if err != nil {
klog.Infof("Unable to get bucket location %v\n", err)
klog.V(1).Infof("Unable to get bucket location %v\n", err)
return false, err
}

Expand All @@ -187,7 +187,7 @@ func (c *S3Client) CheckIfObjectExists(bucketName, objectName string) (bool, err
if err != nil {
if aerr, ok := err.(awserr.Error); ok {
if aerr.Code() == s3.ErrCodeNoSuchKey {
klog.Infof("Object %s not found in %s bucket", objectName, bucketName)
klog.V(1).Infof("Object %s not found in %s bucket", objectName, bucketName)
return false, nil
}
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/client/volume/volume.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ func (c *Client) DeleteVolume(id string) error {
}

func (c *Client) GetAll() (*models.Volumes, error) {
klog.Infof("Calling the Power Volumes GetAll Method")
klog.V(1).Infof("Calling the Power Volumes GetAll Method")
params := p_cloud_volumes.NewPcloudCloudinstancesVolumesGetallParamsWithTimeout(pkg.TIMEOUT).WithCloudInstanceID(c.instanceID)
resp, err := c.session.Power.PCloudVolumes.PcloudCloudinstancesVolumesGetall(params, c.session.AuthInfo(c.instanceID))
if err != nil {
Expand Down
Loading

0 comments on commit 48589cc

Please sign in to comment.