Skip to content

Commit

Permalink
Merge pull request #65 from bkhadars/master
Browse files Browse the repository at this point in the history
Fix:Enhance help messages for image upload and import commands
  • Loading branch information
ltccci authored Dec 11, 2020
2 parents c49939a + bec2438 commit 31fbbe2
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 31 deletions.
46 changes: 26 additions & 20 deletions cmd/image/import/import.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,17 +34,24 @@ export IBMCLOUD_API_KEY=<IBM_CLOUD_API_KEY>
Examples:
# import image using default storage type (service credential will be autogenerated)
pvsadm image import -n upstream-core-lon04 -b <BUCKETNAME> --object-name rhel-83-10032020.ova.gz --image-name test-image -r <REGION>
pvsadm image import -n upstream-core-lon04 -b <BUCKETNAME> --object rhel-83-10032020.ova.gz --pvs-image-name test-image -r <REGION>
# import image using default storage type with specifying the accesskey and secretkey explicitly
pvsadm image import -n upstream-core-lon04 -b <BUCKETNAME> --accesskey <ACCESSKEY> --secretkey <SECRETKEY> --object-name rhel-83-10032020.ova.gz --image-name test-image -r <REGION>
pvsadm image import -n upstream-core-lon04 -b <BUCKETNAME> --accesskey <ACCESSKEY> --secretkey <SECRETKEY> --object rhel-83-10032020.ova.gz --pvs-image-name test-image -r <REGION>
# with user provided storage type
pvsadm image import -n upstream-core-lon04 -b <BUCKETNAME> -r <REGION> --storagetype <STORAGETYPE> --object-name rhel-83-10032020.ova.gz --image-name test-image -r <REGION>
pvsadm image import -n upstream-core-lon04 -b <BUCKETNAME> --pvs-storagetype <STORAGETYPE> --object rhel-83-10032020.ova.gz --pvs-image-name test-image -r <REGION>
# If user wants to specify the type of OS
pvsadm image import -n upstream-core-lon04 -b <BUCKETNAME> --object-name rhel-83-10032020.ova.gz --image-name test-image --ostype <OSTYPE> -r <REGION>
pvsadm image import -n upstream-core-lon04 -b <BUCKETNAME> --object rhel-83-10032020.ova.gz --pvs-image-name test-image --ostype <OSTYPE> -r <REGION>
`,
PersistentPreRunE: func(cmd *cobra.Command, args []string) error {
if pkg.ImageCMDOptions.InstanceID == "" && pkg.ImageCMDOptions.InstanceName == "" {
return fmt.Errorf("--pvs-instance-name or --pvs-instance-id required")
}
return nil
},

RunE: func(cmd *cobra.Command, args []string) error {
var s3client *client.S3Client
opt := pkg.ImageCMDOptions
Expand Down Expand Up @@ -216,22 +223,21 @@ pvsadm image import -n upstream-core-lon04 -b <BUCKETNAME> --object-name rhel-83
}

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", "", "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.OsType, "ostype", "redhat", "Image OS Type, accepted values are[aix, ibmi, redhat, sles]")
Cmd.Flags().BoolVarP(&pkg.ImageCMDOptions.Watch, "watch", "w", false, "After image import watch for image to be published and ready to use")
Cmd.Flags().DurationVar(&pkg.ImageCMDOptions.WatchTimeout, "watch-timeout", 1*time.Hour, "watch timeout")
Cmd.Flags().StringVar(&pkg.ImageCMDOptions.StorageType, "storagetype", "tier3", "Storage type, accepted values are [tier1, tier3]")
Cmd.Flags().StringVar(&pkg.ImageCMDOptions.ServiceCredName, "service-credential-name", "", "Service Credential name to be auto generated(default \""+serviceCredPrefix+"-<USERID>\")")
Cmd.Flags().StringVarP(&pkg.ImageCMDOptions.InstanceName, "pvs-instance-name", "n", "", "PowerVS Instance name.")
Cmd.Flags().StringVarP(&pkg.ImageCMDOptions.InstanceID, "pvs-instance-id", "i", "", "PowerVS Instance ID.")
Cmd.Flags().StringVarP(&pkg.ImageCMDOptions.BucketName, "bucket", "b", "", "Cloud Object Storage bucket name.")
Cmd.Flags().StringVarP(&pkg.ImageCMDOptions.Region, "bucket-region", "r", "", "Cloud Object Storage bucket location.")
Cmd.Flags().StringVarP(&pkg.ImageCMDOptions.ImageFilename, "object", "o", "", "Cloud Object Storage object name.")
Cmd.Flags().StringVar(&pkg.ImageCMDOptions.AccessKey, "accesskey", "", "Cloud Object Storage HMAC access key.")
Cmd.Flags().StringVar(&pkg.ImageCMDOptions.SecretKey, "secretkey", "", "Cloud Object Storage HMAC secret key.")
Cmd.Flags().StringVar(&pkg.ImageCMDOptions.ImageName, "pvs-image-name", "", "Name to PowerVS imported image.")
Cmd.Flags().StringVar(&pkg.ImageCMDOptions.OsType, "ostype", "redhat", "Image OS Type, accepted values are[aix, ibmi, redhat, sles].")
Cmd.Flags().StringVar(&pkg.ImageCMDOptions.StorageType, "pvs-storagetype", "tier3", "PowerVS Storage type, accepted values are [tier1, tier3].")
Cmd.Flags().StringVar(&pkg.ImageCMDOptions.ServiceCredName, "pvs-service-cred", "pvsadm-service-cred", "Service Credential name to be auto generated.")

_ = Cmd.MarkFlagRequired("bucket")
_ = Cmd.MarkFlagRequired("image-name")
_ = Cmd.MarkFlagRequired("object-name")
_ = Cmd.MarkFlagRequired("region")
_ = Cmd.MarkFlagRequired("bucket-region")
_ = Cmd.MarkFlagRequired("pvs-image-name")
_ = Cmd.MarkFlagRequired("object")
Cmd.Flags().SortFlags = false
}
22 changes: 11 additions & 11 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 -o rhcos-461.ova.gz --instance-name pvsadm-cos-instance
pvsadm image upload --bucket bucket0711 -f rhcos-461.ova.gz --instance-name pvsadm-cos-instance
#If user is planning to use available cos instance
pvsadm image upload --bucket bucket0911 -o rhcos-461.ova.gz
pvsadm image upload --bucket bucket0911 -f rhcos-461.ova.gz
#If user intents to create a new COS instance
pvsadm image upload --bucket basheerbucket1320 -o centos-8-latest.ova.gz --resource-group <ResourceGroup_Name>
pvsadm image upload --bucket bucket1320 -f centos-8-latest.ova.gz --resource-group <ResourceGroup_Name>
#if user is planning to create a bucket in particular region
pvsadm image upload --bucket basheerbucket1320 -o centos-8-latest.ova.gz --region <Region>
pvsadm image upload --bucket bucket1320 -f 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 basheerbucket1320 -o centos-8-latest.ova.gz --regio
}

func init() {
Cmd.Flags().StringVar(&pkg.ImageCMDOptions.ResourceGrp, "resource-group", "", "Provide Resource-Group(default: default resource group set for the account")
Cmd.Flags().StringVar(&pkg.ImageCMDOptions.ServicePlan, "service-plan", "standard", "Provide serviceplan type")
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.Flags().StringVar(&pkg.ImageCMDOptions.ResourceGrp, "resource-group", "default", "Name of user resource group.")
Cmd.Flags().StringVar(&pkg.ImageCMDOptions.ServicePlan, "cos-storageclass", "standard", "Cloud Object Storage Class type, available values are [standard, smart, cold, vault].")
Cmd.Flags().StringVarP(&pkg.ImageCMDOptions.InstanceName, "cos-instance-name", "n", "", "Cloud Object Storage instance name.")
Cmd.Flags().StringVarP(&pkg.ImageCMDOptions.BucketName, "bucket", "b", "", "Cloud Object Storage bucket name.")
Cmd.Flags().StringVarP(&pkg.ImageCMDOptions.ImageName, "file", "f", "", "The PATH to the file to upload.")
Cmd.Flags().StringVarP(&pkg.ImageCMDOptions.Region, "bucket-region", "r", "us-south", "Cloud Object Storage bucket region.")
_ = Cmd.MarkFlagRequired("bucket")
_ = Cmd.MarkFlagRequired("object-name")
_ = Cmd.MarkFlagRequired("file")
Cmd.Flags().SortFlags = false
}

0 comments on commit 31fbbe2

Please sign in to comment.