Skip to content

Commit

Permalink
Merge pull request #52 from bkhadars/master
Browse files Browse the repository at this point in the history
Fix: Consistent flag names across image upload and import sub-commands
  • Loading branch information
ltccci authored Dec 8, 2020
2 parents 39b774f + 9639fc1 commit 0dff459
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 11 deletions.
4 changes: 2 additions & 2 deletions cmd/image/import/import.go
Original file line number Diff line number Diff line change
Expand Up @@ -181,11 +181,11 @@ func init() {
Cmd.Flags().StringVarP(&pkg.ImageCMDOptions.InstanceName, "instance-name", "n", "", "Instance name of the PowerVS")
Cmd.Flags().StringVarP(&pkg.ImageCMDOptions.InstanceID, "instance-id", "i", "", "Instance ID of the PowerVS instance")
Cmd.Flags().StringVarP(&pkg.ImageCMDOptions.BucketName, "bucket", "b", "", "Cloud Storage bucket name")
Cmd.Flags().StringVarP(&pkg.ImageCMDOptions.Region, "region", "r", "", "Cloud Storage Region")
Cmd.Flags().StringVarP(&pkg.ImageCMDOptions.Region, "region", "r", "", "COS bucket location")
Cmd.Flags().StringVarP(&pkg.ImageCMDOptions.ImageFilename, "object-name", "o", "", "Cloud Storage image filename")
Cmd.Flags().StringVar(&pkg.ImageCMDOptions.AccessKey, "accesskey", "", "Cloud Storage access key")
Cmd.Flags().StringVar(&pkg.ImageCMDOptions.SecretKey, "secretkey", "", "Cloud Storage secret key")
Cmd.Flags().StringVar(&pkg.ImageCMDOptions.ImageName, "image-name", "", "Name to give imported image")
Cmd.Flags().StringVar(&pkg.ImageCMDOptions.ImageFilename, "object-name", "", "Cloud Storage image filename")
Cmd.Flags().StringVar(&pkg.ImageCMDOptions.OsType, "ostype", "redhat", "Image OS Type, accepted values are[aix, ibmi, redhat, sles]")
Cmd.Flags().StringVar(&pkg.ImageCMDOptions.StorageType, "storagetype", "tier3", "Storage type, accepted values are [tier1, tier3]")
Cmd.Flags().StringVar(&pkg.ImageCMDOptions.ServiceCredName, "service-credential-name", "pvsadm-service-cred", "Service Credential name to be auto generated")
Expand Down
2 changes: 2 additions & 0 deletions cmd/image/qcow2ova/validate/register.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,12 @@ import (
"github.com/ppc64le-cloud/pvsadm/cmd/image/qcow2ova/validate/diskspace"
"github.com/ppc64le-cloud/pvsadm/cmd/image/qcow2ova/validate/platform"
"github.com/ppc64le-cloud/pvsadm/cmd/image/qcow2ova/validate/tools"
"github.com/ppc64le-cloud/pvsadm/cmd/image/qcow2ova/validate/user"
)

func init() {
//TODO: Add Operating system check
AddRule(&user.Rule{})
AddRule(&platform.Rule{})
AddRule(&tools.Rule{})
AddRule(&diskspace.Rule{})
Expand Down
24 changes: 24 additions & 0 deletions cmd/image/qcow2ova/validate/user/user.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package user

import (
"fmt"
"os"
)

type Rule struct {
}

func (p *Rule) String() string {
return "user"
}

func (p *Rule) Verify() error {
if os.Geteuid() != 0 {
return fmt.Errorf("non-root user is executing the qcow2ova sub-command")
}
return nil
}

func (p *Rule) Hint() string {
return "Expected root user to execute the qcow2ova subcommand"
}
18 changes: 9 additions & 9 deletions cmd/image/upload/upload.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,16 +28,16 @@ export IBMCLOUD_API_KEY=<IBM_CLOUD_API_KEY>
Examples:
# using InstanceName
pvsadm image upload --bucket bucket0711 -i rhcos-461.ova.gz --instance-name pvsadm-cos-instance
pvsadm image upload --bucket bucket0711 -o rhcos-461.ova.gz --instance-name pvsadm-cos-instance
#If user is planning to use available cos instance
pvsadm image upload --bucket bucket0911 -i rhcos-461.ova.gz
pvsadm image upload --bucket bucket0911 -o rhcos-461.ova.gz
#If user intents to create a new COS instance
pvsadm image upload --bucket-name basheerbucket1320 -i centos-8-latest.ova.gz --resource-group <ResourceGroup_Name>
pvsadm image upload --bucket basheerbucket1320 -o centos-8-latest.ova.gz --resource-group <ResourceGroup_Name>
#if user is planning to create a bucket in particular region
pvsadm image upload --bucket-name basheerbucket1320 -i centos-8-latest.ova.gz --region <Region>
pvsadm image upload --bucket basheerbucket1320 -o centos-8-latest.ova.gz --region <Region>
`,
RunE: func(cmd *cobra.Command, args []string) error {
var s3Cli *client.S3Client
Expand Down Expand Up @@ -155,13 +155,13 @@ pvsadm image upload --bucket-name basheerbucket1320 -i centos-8-latest.ova.gz --
}

func init() {
Cmd.Flags().StringVar(&pkg.ImageCMDOptions.InstanceName, "instance-name", "", "Instance Name of the COS to be used")
Cmd.Flags().StringVar(&pkg.ImageCMDOptions.ResourceGrp, "resource-group", "default", "Provide Resource-Group")
Cmd.Flags().StringVar(&pkg.ImageCMDOptions.ServicePlan, "service-plan", "standard", "Provide serviceplan type")
Cmd.Flags().StringVarP(&pkg.ImageCMDOptions.BucketName, "bucket-name", "b", "", "Region of the COS instance")
Cmd.Flags().StringVarP(&pkg.ImageCMDOptions.ImageName, "image-name", "i", "", "S3 object name to be uploaded to the COS")
Cmd.Flags().StringVarP(&pkg.ImageCMDOptions.InstanceName, "instance-name", "n", "", "Instance Name of the COS to be used")
Cmd.Flags().StringVarP(&pkg.ImageCMDOptions.BucketName, "bucket", "b", "", "Region of the COS instance")
Cmd.Flags().StringVarP(&pkg.ImageCMDOptions.ImageName, "object-name", "o", "", "S3 object name to be uploaded to the COS")
Cmd.Flags().StringVarP(&pkg.ImageCMDOptions.Region, "region", "r", "us-south", "Region of the COS instance")
_ = Cmd.MarkFlagRequired("bucket-name")
_ = Cmd.MarkFlagRequired("image-name")
_ = Cmd.MarkFlagRequired("bucket")
_ = Cmd.MarkFlagRequired("object-name")
Cmd.Flags().SortFlags = false
}

0 comments on commit 0dff459

Please sign in to comment.