From a1a8e5f83966205ad632d1ecef2b2ea7f9c88a49 Mon Sep 17 00:00:00 2001 From: Varad Ahirwadkar <varad.ahirwadkar1@ibm.com> Date: Wed, 15 May 2024 22:31:49 -0700 Subject: [PATCH] Deprecating instance-id and instance-name Signed-off-by: Varad Ahirwadkar <varad.ahirwadkar1@ibm.com> --- README.md | 2 +- cmd/create/create.go | 5 ++- cmd/create/port/port.go | 8 +++- cmd/delete/delete.go | 5 ++- cmd/delete/port/port.go | 8 +++- cmd/dhcp-sync/dhcp-sync.go | 10 +++-- cmd/dhcpserver/cmd.go | 8 +++- cmd/dhcpserver/create.go | 2 +- cmd/dhcpserver/delete.go | 2 +- cmd/dhcpserver/get.go | 2 +- cmd/dhcpserver/list.go | 2 +- cmd/get/events/events.go | 6 +-- cmd/get/get.go | 8 +++- cmd/get/peravailability/peravailability.go | 10 ++--- cmd/get/ports/ports.go | 6 +-- cmd/image/import/import.go | 21 ++++++---- cmd/image/sync/mock/sync_client_generated.go | 1 + cmd/image/upload/upload.go | 31 +++++++------- cmd/purge/images/images.go | 4 +- cmd/purge/keys/keys.go | 2 +- cmd/purge/networks/networks.go | 2 +- cmd/purge/purge.go | 34 ++++++++------- cmd/purge/vms/vms.go | 2 +- cmd/purge/volumes/volumes.go | 2 +- ...How to Import Image to PowerVS Instance.md | 20 ++++----- pkg/options.go | 42 +++++++++---------- .../convert-upload-images-powervs | 2 +- .../image-create-and-upload-sample/README.md | 2 +- .../image-create-and-upload-sample/config.sh | 2 +- .../image_create_and_upload_script.sh | 2 +- 30 files changed, 144 insertions(+), 109 deletions(-) diff --git a/README.md b/README.md index 022df209..365fb90d 100644 --- a/README.md +++ b/README.md @@ -36,7 +36,7 @@ The typical image workflow comprises of the following steps: - How to convert RHEL qcow2 to ova image format - [guide](docs/RHEL%20Qcow2%20to%20OVA.md) - How to convert RHCOS(Red Hat CoreOS) qcow2 to ova image format - [guide](docs/RHCOS%20Qcow2%20to%20OVA.md) - Advanced scenarios for Qcow2 to ova image conversion - [guide](docs/Advanced%20Scenarios%20for%20Qcow2%20to%20OVA.md) -- How to import image to PowerVS instance from COS - [guide](docs/How%20to%20Import%20Image%20to%20PowerVS%20Instance.md) +- How to import image to PowerVS workspace from COS - [guide](docs/How%20to%20Import%20Image%20to%20PowerVS%20Instance.md) - How to upload image to COS bucket using pvsadm - [guide](docs/How%20to%20Upload%20Image%20to%20COS.md) - How to build DHCP supported centos image - [guide](docs/Build%20DHCP%20enabled%20Centos%20Images.md) diff --git a/cmd/create/create.go b/cmd/create/create.go index 0760b1e6..5173878f 100644 --- a/cmd/create/create.go +++ b/cmd/create/create.go @@ -30,6 +30,7 @@ var Cmd = &cobra.Command{ func init() { Cmd.AddCommand(port.Cmd) - Cmd.PersistentFlags().StringVarP(&pkg.Options.InstanceID, "instance-id", "i", "", "Instance ID of the PowerVS instance") - _ = Cmd.MarkPersistentFlagRequired("instance-id") + Cmd.PersistentFlags().StringVarP(&pkg.Options.WorkspaceID, "instance-id", "i", "", "Instance ID of the PowerVS instance") + Cmd.PersistentFlags().MarkDeprecated("instance-id", "instance-id is deprecated, workspace-id should be used") + Cmd.PersistentFlags().StringVarP(&pkg.Options.WorkspaceID, "workspace-id", "", "", "Workspace ID of the PowerVS workspace") } diff --git a/cmd/create/port/port.go b/cmd/create/port/port.go index ebf9c5d5..99e4c3bc 100644 --- a/cmd/create/port/port.go +++ b/cmd/create/port/port.go @@ -35,6 +35,12 @@ var Cmd = &cobra.Command{ Use: "port", Short: "Create PowerVS network port", Long: `Create PowerVS network port`, + PreRunE: func(cmd *cobra.Command, args []string) error { + if pkg.Options.WorkspaceID == "" { + return fmt.Errorf("--workspace-id required") + } + return nil + }, RunE: func(cmd *cobra.Command, args []string) error { opt := pkg.Options @@ -44,7 +50,7 @@ var Cmd = &cobra.Command{ return err } - pvmclient, err := client.NewPVMClientWithEnv(c, opt.InstanceID, opt.InstanceName, opt.Environment) + pvmclient, err := client.NewPVMClientWithEnv(c, opt.WorkspaceID, opt.WorkspaceName, opt.Environment) if err != nil { return err } diff --git a/cmd/delete/delete.go b/cmd/delete/delete.go index 12161f52..126f79b5 100644 --- a/cmd/delete/delete.go +++ b/cmd/delete/delete.go @@ -30,6 +30,7 @@ var Cmd = &cobra.Command{ func init() { Cmd.AddCommand(port.Cmd) - Cmd.PersistentFlags().StringVarP(&pkg.Options.InstanceID, "instance-id", "i", "", "Instance ID of the PowerVS instance") - _ = Cmd.MarkPersistentFlagRequired("instance-id") + Cmd.PersistentFlags().StringVarP(&pkg.Options.WorkspaceID, "instance-id", "i", "", "Instance ID of the PowerVS instance") + Cmd.PersistentFlags().MarkDeprecated("instance-id", "instance-id is deprecated, workspace-id should be used") + Cmd.PersistentFlags().StringVarP(&pkg.Options.WorkspaceID, "workspace-id", "", "", "Workspace ID of the PowerVS instance") } diff --git a/cmd/delete/port/port.go b/cmd/delete/port/port.go index ba7cf58f..2f3dc5a3 100644 --- a/cmd/delete/port/port.go +++ b/cmd/delete/port/port.go @@ -34,6 +34,12 @@ var Cmd = &cobra.Command{ Use: "port", Short: "Delete PowerVS network port", Long: `Delete PowerVS network port`, + PreRunE: func(cmd *cobra.Command, args []string) error { + if pkg.Options.WorkspaceID == "" { + return fmt.Errorf("--workspace-id required") + } + return nil + }, RunE: func(cmd *cobra.Command, args []string) error { opt := pkg.Options @@ -43,7 +49,7 @@ var Cmd = &cobra.Command{ return err } - pvmclient, err := client.NewPVMClientWithEnv(c, opt.InstanceID, opt.InstanceName, opt.Environment) + pvmclient, err := client.NewPVMClientWithEnv(c, opt.WorkspaceID, opt.WorkspaceName, opt.Environment) if err != nil { return err } diff --git a/cmd/dhcp-sync/dhcp-sync.go b/cmd/dhcp-sync/dhcp-sync.go index 76d9b652..8c506fe5 100644 --- a/cmd/dhcp-sync/dhcp-sync.go +++ b/cmd/dhcp-sync/dhcp-sync.go @@ -87,7 +87,7 @@ func syncDHCPD() { klog.Fatalf("failed to create a session with IBM cloud: %v", err) } - pvmclient, err := client.NewPVMClientWithEnv(c, pkg.Options.InstanceID, "", "prod") + pvmclient, err := client.NewPVMClientWithEnv(c, pkg.Options.WorkspaceID, "", "prod") if err != nil { klog.Fatalf("failed to create a PVM client: %v", err) } @@ -159,8 +159,8 @@ var Cmd = &cobra.Command{ Long: `dhcp-sync tool is a tool populating the dhcpd.conf file from the PowerVS network and restart the dhcpd service.`, GroupID: "dhcp", PreRunE: func(cmd *cobra.Command, args []string) error { - if pkg.Options.InstanceID == "" { - return fmt.Errorf("--instance-id is required") + if pkg.Options.WorkspaceID == "" { + return fmt.Errorf("--workspace-id is required") } if pkg.Options.APIKey == "" { return fmt.Errorf("api-key can't be empty, pass the token via --api-key or set IBMCLOUD_API_KEY environment variable") @@ -211,7 +211,9 @@ var Cmd = &cobra.Command{ } func init() { - Cmd.Flags().StringVarP(&pkg.Options.InstanceID, "instance-id", "i", "", "Instance ID of the PowerVS instance") + Cmd.Flags().StringVarP(&pkg.Options.WorkspaceID, "instance-id", "i", "", "Instance ID of the PowerVS instance") + Cmd.Flags().MarkDeprecated("instance-id", "instance-id is deprecated, workspace-id should be used") + Cmd.Flags().StringVarP(&pkg.Options.WorkspaceID, "workspace-id", "w", "", "Workspace ID of the PowerVS instance") Cmd.Flags().StringVar(&networkID, "network-id", "", "Network ID to be monitored") Cmd.Flags().StringVar(&file, "file", "/etc/dhcp/dhcpd.conf", "DHCP conf file") Cmd.Flags().StringVar(&gateway, "gateway", "", "Override the gateway value with") diff --git a/cmd/dhcpserver/cmd.go b/cmd/dhcpserver/cmd.go index 3b4859d4..244f1850 100644 --- a/cmd/dhcpserver/cmd.go +++ b/cmd/dhcpserver/cmd.go @@ -30,6 +30,9 @@ var Cmd = &cobra.Command{ if pkg.Options.APIKey == "" { return fmt.Errorf("api-key can't be empty, pass the token via --api-key or set IBMCLOUD_API_KEY environment variable") } + if pkg.Options.WorkspaceID == "" { + return fmt.Errorf("--workspace-id required") + } return nil }, RunE: func(cmd *cobra.Command, args []string) error { @@ -43,6 +46,7 @@ func init() { Cmd.AddCommand(getCmd) Cmd.AddCommand(deleteCmd) - Cmd.PersistentFlags().StringVarP(&pkg.Options.InstanceID, "instance-id", "i", "", "Instance ID of the PowerVS instance") - _ = Cmd.MarkPersistentFlagRequired("instance-id") + Cmd.PersistentFlags().StringVarP(&pkg.Options.WorkspaceID, "instance-id", "i", "", "Instance ID of the PowerVS instance") + Cmd.PersistentFlags().MarkDeprecated("instance-id", "instance-id is deprecated, workspace-id should be used") + Cmd.PersistentFlags().StringVarP(&pkg.Options.WorkspaceID, "workspace-id", "", "", "Workspace ID of the PowerVS instance") } diff --git a/cmd/dhcpserver/create.go b/cmd/dhcpserver/create.go index d49c745f..0a331291 100644 --- a/cmd/dhcpserver/create.go +++ b/cmd/dhcpserver/create.go @@ -45,7 +45,7 @@ var createCmd = &cobra.Command{ return err } - pvmclient, err := client.NewPVMClientWithEnv(c, opt.InstanceID, opt.InstanceName, opt.Environment) + pvmclient, err := client.NewPVMClientWithEnv(c, opt.WorkspaceID, opt.WorkspaceName, opt.Environment) if err != nil { return err } diff --git a/cmd/dhcpserver/delete.go b/cmd/dhcpserver/delete.go index af98cb5d..effa541e 100644 --- a/cmd/dhcpserver/delete.go +++ b/cmd/dhcpserver/delete.go @@ -38,7 +38,7 @@ var deleteCmd = &cobra.Command{ return err } - pvmclient, err := client.NewPVMClientWithEnv(c, opt.InstanceID, opt.InstanceName, opt.Environment) + pvmclient, err := client.NewPVMClientWithEnv(c, opt.WorkspaceID, opt.WorkspaceName, opt.Environment) if err != nil { return err } diff --git a/cmd/dhcpserver/get.go b/cmd/dhcpserver/get.go index 98aa1074..45795d76 100644 --- a/cmd/dhcpserver/get.go +++ b/cmd/dhcpserver/get.go @@ -42,7 +42,7 @@ var getCmd = &cobra.Command{ return err } - pvmclient, err := client.NewPVMClientWithEnv(c, opt.InstanceID, opt.InstanceName, opt.Environment) + pvmclient, err := client.NewPVMClientWithEnv(c, opt.WorkspaceID, opt.WorkspaceName, opt.Environment) if err != nil { return err } diff --git a/cmd/dhcpserver/list.go b/cmd/dhcpserver/list.go index 96c28a66..94ac4d87 100644 --- a/cmd/dhcpserver/list.go +++ b/cmd/dhcpserver/list.go @@ -38,7 +38,7 @@ var listCmd = &cobra.Command{ return err } - pvmclient, err := client.NewPVMClientWithEnv(c, opt.InstanceID, opt.InstanceName, opt.Environment) + pvmclient, err := client.NewPVMClientWithEnv(c, opt.WorkspaceID, opt.WorkspaceName, opt.Environment) if err != nil { return err } diff --git a/cmd/get/events/events.go b/cmd/get/events/events.go index e6aaf19a..e74be022 100644 --- a/cmd/get/events/events.go +++ b/cmd/get/events/events.go @@ -35,8 +35,8 @@ var Cmd = &cobra.Command{ Short: "Get Powervs events", Long: `Get the PowerVS events`, PreRunE: func(cmd *cobra.Command, args []string) error { - if pkg.Options.InstanceID == "" && pkg.Options.InstanceName == "" { - return fmt.Errorf("--instance-id or --instance-name required") + if pkg.Options.WorkspaceID == "" && pkg.Options.WorkspaceName == "" { + return fmt.Errorf("--workspace-id or --workspace-name required") } return nil }, @@ -49,7 +49,7 @@ var Cmd = &cobra.Command{ return err } - pvmclient, err := client.NewPVMClientWithEnv(c, opt.InstanceID, opt.InstanceName, opt.Environment) + pvmclient, err := client.NewPVMClientWithEnv(c, opt.WorkspaceID, opt.WorkspaceName, opt.Environment) if err != nil { return err } diff --git a/cmd/get/get.go b/cmd/get/get.go index e6aaee2e..2fcd444c 100644 --- a/cmd/get/get.go +++ b/cmd/get/get.go @@ -36,6 +36,10 @@ func init() { Cmd.AddCommand(events.Cmd) Cmd.AddCommand(peravailability.Cmd) Cmd.AddCommand(ports.Cmd) - Cmd.PersistentFlags().StringVarP(&pkg.Options.InstanceID, "instance-id", "i", "", "Instance ID of the PowerVS instance") - Cmd.PersistentFlags().StringVarP(&pkg.Options.InstanceName, "instance-name", "n", "", "Instance name of the PowerVS") + Cmd.PersistentFlags().StringVarP(&pkg.Options.WorkspaceID, "instance-id", "i", "", "Instance ID of the PowerVS instance") + Cmd.PersistentFlags().MarkDeprecated("instance-id", "instance-id is deprecated, workspace-id should be used") + Cmd.PersistentFlags().StringVarP(&pkg.Options.WorkspaceName, "instance-name", "n", "", "Instance name of the PowerVS") + Cmd.PersistentFlags().MarkDeprecated("instance-name", "instance-name is deprecated, workspace-name should be used") + Cmd.PersistentFlags().StringVarP(&pkg.Options.WorkspaceID, "workspace-id", "", "", "Workspace ID of the PowerVS instance") + Cmd.PersistentFlags().StringVarP(&pkg.Options.WorkspaceName, "workspace-name", "", "", "Workspace name of the PowerVS") } diff --git a/cmd/get/peravailability/peravailability.go b/cmd/get/peravailability/peravailability.go index ee923715..8443c8b7 100644 --- a/cmd/get/peravailability/peravailability.go +++ b/cmd/get/peravailability/peravailability.go @@ -32,8 +32,8 @@ var Cmd = &cobra.Command{ Short: "List regions that support PER", Long: "List regions that support Power Edge Router (PER)", PreRunE: func(cmd *cobra.Command, args []string) error { - if pkg.Options.InstanceID == "" && pkg.Options.InstanceName == "" { - return fmt.Errorf("--instance-id or --instance-name required") + if pkg.Options.WorkspaceID == "" && pkg.Options.WorkspaceName == "" { + return fmt.Errorf("--workspace-id or --workspace-name required") } return nil }, @@ -46,7 +46,7 @@ var Cmd = &cobra.Command{ return err } - pvmclient, err := client.NewPVMClientWithEnv(c, opt.InstanceID, opt.InstanceName, opt.Environment) + pvmclient, err := client.NewPVMClientWithEnv(c, opt.WorkspaceID, opt.WorkspaceName, opt.Environment) if err != nil { return err } @@ -64,9 +64,9 @@ var Cmd = &cobra.Command{ } } if !supportsPER { - klog.Infof("%s, where the current instance is present does not support PER.", pvmclient.Zone) + klog.Infof("%s, where the current workspace is present does not support PER.", pvmclient.Zone) } else { - klog.Infof("%s, where the current instance is present supports PER.", pvmclient.Zone) + klog.Infof("%s, where the current workspace is present supports PER.", pvmclient.Zone) } sort.Strings(perEnabledRegions) klog.Infof("The following zones/datacenters have support for PER:%v.More information at https://cloud.ibm.com/docs/overview?topic=overview-locations", perEnabledRegions) diff --git a/cmd/get/ports/ports.go b/cmd/get/ports/ports.go index 00757a07..90ddc004 100644 --- a/cmd/get/ports/ports.go +++ b/cmd/get/ports/ports.go @@ -35,8 +35,8 @@ var Cmd = &cobra.Command{ Short: "Get PowerVS network ports", Long: `Get PowerVS network ports`, PreRunE: func(cmd *cobra.Command, args []string) error { - if pkg.Options.InstanceID == "" && pkg.Options.InstanceName == "" { - return fmt.Errorf("--instance-id or --instance-name required") + if pkg.Options.WorkspaceID == "" && pkg.Options.WorkspaceName == "" { + return fmt.Errorf("--workspace-id or --workspace-name required") } return nil }, @@ -49,7 +49,7 @@ var Cmd = &cobra.Command{ return err } - pvmclient, err := client.NewPVMClientWithEnv(c, opt.InstanceID, opt.InstanceName, opt.Environment) + pvmclient, err := client.NewPVMClientWithEnv(c, opt.WorkspaceID, opt.WorkspaceName, opt.Environment) if err != nil { return err } diff --git a/cmd/image/import/import.go b/cmd/image/import/import.go index a45263b5..3a020071 100644 --- a/cmd/image/import/import.go +++ b/cmd/image/import/import.go @@ -64,8 +64,8 @@ func findCOSInstanceDetails(resources []models.ServiceInstanceV2, bxCli *client. var Cmd = &cobra.Command{ Use: "import", - Short: "Import the image into PowerVS instances", - Long: `Import the image into PowerVS instances + Short: "Import the image into PowerVS workpace", + Long: `Import the image into PowerVS workpace pvsadm image import --help for information # Set the API key or feed the --api-key commandline argument @@ -90,11 +90,11 @@ pvsadm image import -n upstream-core-lon04 -b <BUCKETNAME> --pvs-storagetype <ST pvsadm image import -n upstream-core-lon04 -b <BUCKETNAME> --object rhel-83-10032020.ova.gz --pvs-image-name test-image -r <REGION> # import image from a public IBM Cloud Storage bucket -pvsadm image import -n upstream-core-lon04 -b <BUCKETNAME> --object rhel-83-10032020.ova.gz --pvs-image-name test-image -r <REGION> --public-bucket +pvsadm image import -n upstream-core-lon04 -b <BUCKETNAME> --object rhel-83-10032020.ova.gz --pvs-image-name test-image -r <REGION> --public-bucket `, PreRunE: 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") + if pkg.ImageCMDOptions.WorkspaceID == "" && pkg.ImageCMDOptions.WorkspaceName == "" { + return fmt.Errorf("--workspace-name or --workspace-id required") } case1 := pkg.ImageCMDOptions.AccessKey == "" && pkg.ImageCMDOptions.SecretKey != "" @@ -174,7 +174,7 @@ pvsadm image import -n upstream-core-lon04 -b <BUCKETNAME> --object rhel-83-100 opt.SecretKey = cred["secret_access_key"].(string) } - pvmclient, err := client.NewPVMClientWithEnv(bxCli, opt.InstanceID, opt.InstanceName, pkg.Options.Environment) + pvmclient, err := client.NewPVMClientWithEnv(bxCli, opt.WorkspaceID, opt.WorkspaceName, pkg.Options.Environment) if err != nil { return err } @@ -242,8 +242,13 @@ pvsadm image import -n upstream-core-lon04 -b <BUCKETNAME> --object rhel-83-100 } func init() { - 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.") + // TODO pvs-instance-name and pvs-instance-id is deprecated and will be removed in a future release + Cmd.Flags().StringVarP(&pkg.ImageCMDOptions.WorkspaceName, "pvs-instance-name", "n", "", "PowerVS Instance name.") + Cmd.Flags().MarkDeprecated("pvs-instance-name", "pvs-instance-name is deprecated, workspace-name should be used") + Cmd.Flags().StringVarP(&pkg.ImageCMDOptions.WorkspaceID, "pvs-instance-id", "i", "", "PowerVS Instance ID.") + Cmd.Flags().MarkDeprecated("pvs-instance-id", "pvs-instance-id is deprecated, workspace-id should be used") + Cmd.Flags().StringVarP(&pkg.ImageCMDOptions.WorkspaceName, "workspace-name", "", "", "PowerVS Workspace name.") + Cmd.Flags().StringVarP(&pkg.ImageCMDOptions.WorkspaceID, "workspace-id", "", "", "PowerVS Workspace ID.") Cmd.Flags().StringVarP(&pkg.ImageCMDOptions.BucketName, "bucket", "b", "", "Cloud Object Storage bucket name.") Cmd.Flags().StringVarP(&pkg.ImageCMDOptions.COSInstanceName, "cos-instance-name", "s", "", "Cloud Object Storage instance name.") // TODO It's deprecated and will be removed in a future release diff --git a/cmd/image/sync/mock/sync_client_generated.go b/cmd/image/sync/mock/sync_client_generated.go index e109cf72..92ea897f 100644 --- a/cmd/image/sync/mock/sync_client_generated.go +++ b/cmd/image/sync/mock/sync_client_generated.go @@ -19,6 +19,7 @@ // // mockgen -source=./sync_client.go -destination=./mock/sync_client_generated.go -package=mock -copyright_file=../../../hack/copyright_file // + // Package mock is a generated GoMock package. package mock diff --git a/cmd/image/upload/upload.go b/cmd/image/upload/upload.go index 709f4f7a..08b417b9 100644 --- a/cmd/image/upload/upload.go +++ b/cmd/image/upload/upload.go @@ -119,8 +119,8 @@ pvsadm image upload --bucket bucket1320 -f centos-8-latest.ova.gz --bucket-regio } //check if bucket exists - if opt.InstanceName != "" { - s3Cli, err = client.NewS3Client(bxCli, opt.InstanceName, opt.Region) + if opt.COSInstanceName != "" { + s3Cli, err = client.NewS3Client(bxCli, opt.COSInstanceName, opt.Region) if err != nil { return err } @@ -131,7 +131,7 @@ pvsadm image upload --bucket bucket1320 -f centos-8-latest.ova.gz --bucket-regio } if !bucketExists { - klog.Infof("Bucket %s not found in the instance %s provided", opt.BucketName, opt.InstanceName) + klog.Infof("Bucket %s not found in the instance %s provided", opt.BucketName, opt.COSInstanceName) } } else if len(instances) != 0 { @@ -148,8 +148,8 @@ pvsadm image upload --bucket bucket1320 -f centos-8-latest.ova.gz --bucket-regio } if bucketExists { - opt.InstanceName = instanceName - klog.Infof("Found bucket %s in the %s instance", opt.BucketName, opt.InstanceName) + opt.COSInstanceName = instanceName + klog.Infof("Found bucket %s in the %s instance", opt.BucketName, opt.COSInstanceName) break } } @@ -158,7 +158,7 @@ pvsadm image upload --bucket bucket1320 -f centos-8-latest.ova.gz --bucket-regio } // Ask if user likes to use existing instance - if opt.InstanceName == "" && len(instances) != 0 { + if opt.COSInstanceName == "" && len(instances) != 0 { klog.Infof("Bucket %s not found in the account provided", opt.BucketName) if utils.AskConfirmation(UseExistingPromptMessage) { availableInstances := []string{} @@ -169,13 +169,13 @@ pvsadm image upload --bucket bucket1320 -f centos-8-latest.ova.gz --bucket-regio if err != nil { return err } - opt.InstanceName = selectedInstance - klog.Infof("Selected InstanceName is %s", opt.InstanceName) + opt.COSInstanceName = selectedInstance + klog.Infof("Selected InstanceName is %s", opt.COSInstanceName) } } //Create a new instance - if opt.InstanceName == "" { + if opt.COSInstanceName == "" { if !utils.AskConfirmation(CreatePromptMessage) { return fmt.Errorf("create Cloud Object Storage instance either offline or use the pvsadm command") } @@ -200,10 +200,10 @@ 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", opt.InstanceName) + opt.COSInstanceName = utils.ReadUserInput("Type Name of the Cloud Object Storage instance:") + klog.Infof("Creating a new cos %s instance", opt.COSInstanceName) - _, err = bxCli.CreateServiceInstance(opt.InstanceName, ServiceType, opt.ServicePlan, + _, err = bxCli.CreateServiceInstance(opt.COSInstanceName, ServiceType, opt.ServicePlan, opt.ResourceGrp, ResourceGroupAPIRegion) if err != nil { return err @@ -211,7 +211,7 @@ pvsadm image upload --bucket bucket1320 -f centos-8-latest.ova.gz --bucket-regio } //create s3 client - s3Cli, err = client.NewS3Client(bxCli, opt.InstanceName, opt.Region) + s3Cli, err = client.NewS3Client(bxCli, opt.COSInstanceName, opt.Region) if err != nil { return err } @@ -226,7 +226,7 @@ pvsadm image upload --bucket bucket1320 -f centos-8-latest.ova.gz --bucket-regio } else { //Create a new bucket klog.Infof("Creating a new bucket %s", opt.BucketName) - s3Cli, err = client.NewS3Client(bxCli, opt.InstanceName, opt.Region) + s3Cli, err = client.NewS3Client(bxCli, opt.COSInstanceName, opt.Region) if err != nil { return err } @@ -249,7 +249,8 @@ pvsadm image upload --bucket bucket1320 -f centos-8-latest.ova.gz --bucket-regio func init() { Cmd.Flags().StringVar(&pkg.ImageCMDOptions.ResourceGrp, "resource-group", "", "Name of user resource group.") Cmd.Flags().StringVar(&pkg.ImageCMDOptions.ServicePlan, "cos-serviceplan", "standard", "Cloud Object Storage Class type, available values are [standard, lite].") - Cmd.Flags().StringVarP(&pkg.ImageCMDOptions.InstanceName, "cos-instance-name", "n", "", "Cloud Object Storage instance name.") + Cmd.Flags().StringVarP(&pkg.ImageCMDOptions.COSInstanceName, "cos-instance-name", "n", "", "Cloud Object Storage instance name.") + Cmd.Flags().MarkShorthandDeprecated("cos-instance-name", "please use --cos-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.ObjectName, "cos-object-name", "o", "", "Cloud Object Storage Object Name(Default: filename from --file|-f option)") diff --git a/cmd/purge/images/images.go b/cmd/purge/images/images.go index b794b34f..c1001c80 100644 --- a/cmd/purge/images/images.go +++ b/cmd/purge/images/images.go @@ -34,7 +34,7 @@ var Cmd = &cobra.Command{ pvsadm purge --help for information `, RunE: func(cmd *cobra.Command, args []string) error { - klog.Infof("Purge the images for the instance: %v", pkg.Options.InstanceID) + klog.Infof("Purge the images for the workspace: %v", pkg.Options.WorkspaceID) opt := pkg.Options c, err := client.NewClientWithEnv(opt.APIKey, opt.Environment, opt.Debug) @@ -43,7 +43,7 @@ pvsadm purge --help for information return err } - pvmclient, err := client.NewPVMClientWithEnv(c, opt.InstanceID, opt.InstanceName, pkg.Options.Environment) + pvmclient, err := client.NewPVMClientWithEnv(c, opt.WorkspaceID, opt.WorkspaceName, pkg.Options.Environment) if err != nil { return err } diff --git a/cmd/purge/keys/keys.go b/cmd/purge/keys/keys.go index dc858132..10f6e6e5 100644 --- a/cmd/purge/keys/keys.go +++ b/cmd/purge/keys/keys.go @@ -50,7 +50,7 @@ pvsadm purge --help for information return err } - pvmclient, err := client.NewPVMClientWithEnv(c, opt.InstanceID, opt.InstanceName, opt.Environment) + pvmclient, err := client.NewPVMClientWithEnv(c, opt.WorkspaceID, opt.WorkspaceName, opt.Environment) if err != nil { return err } diff --git a/cmd/purge/networks/networks.go b/cmd/purge/networks/networks.go index 8b852d94..822619f9 100644 --- a/cmd/purge/networks/networks.go +++ b/cmd/purge/networks/networks.go @@ -45,7 +45,7 @@ pvsadm purge --help for information return err } - pvmclient, err := client.NewPVMClientWithEnv(c, opt.InstanceID, opt.InstanceName, pkg.Options.Environment) + pvmclient, err := client.NewPVMClientWithEnv(c, opt.WorkspaceID, opt.WorkspaceName, pkg.Options.Environment) if err != nil { return err } diff --git a/cmd/purge/purge.go b/cmd/purge/purge.go index 03f0b0f1..ffdf13fb 100644 --- a/cmd/purge/purge.go +++ b/cmd/purge/purge.go @@ -37,37 +37,37 @@ export IBMCLOUD_API_KEY=<IBM_CLOUD_API_KEY> Examples: # Delete all the virtual machines which are created before 4hrs - pvsadm purge vms --instance-name upstream-core --before 4h + pvsadm purge vms --workspace-name upstream-core --before 4h # Delete all the virtual machines created since 24hrs - pvsadm purge vms --instance-name upstream-core --since 24h + pvsadm purge vms --workspace-name upstream-core --since 24h # Delete all the volumes which aren't assigned to any virtual machines - pvsadm purge volumes --instance-name upstream-core + pvsadm purge volumes --workspace-name upstream-core # Delete all the networks and ignore if any errors during the delete operation - pvsadm purge networks --instance-name upstream-core --ignore-errors + pvsadm purge networks --workspace-name upstream-core --ignore-errors # Delete all the networks along with the instances and their assigned ports - pvsadm purge networks --instance-name upstream-core --instances true --ports true + pvsadm purge networks --workspace-name upstream-core --instances true --ports true # Delete all the images without asking any confirmation - pvsadm purge images --instance-name upstream-core --no-prompt + pvsadm purge images --workspace-name upstream-core --no-prompt # Delete all the images with debugging logs for IBM cloud APIs - pvsadm purge images --instance-name upstream-core --debug + pvsadm purge images --workspace-name upstream-core --debug # Delete all the virtual machines starts with k8s-cluster- - pvsadm purge vms --instance-name upstream-core --regexp "^k8s-cluster-.*" + pvsadm purge vms --workspace-name upstream-core --regexp "^k8s-cluster-.*" # List the purgeable candidate virtual machines and exit without deleting - pvsadm purge vms --instance-name upstream-core --dry-run + pvsadm purge vms --workspace-name upstream-core --dry-run # Delete all the ssh keys which are created before 12hrs - pvsadm purge keys --instance-name upstream-core --before 12h --regexp "^rdr-.*" + pvsadm purge keys --workspace-name upstream-core --before 12h --regexp "^rdr-.*" # Delete all the ssh keys starts with rdr- - pvsadm purge keys --instance-name upstream-core --regexp "^rdr-.*" + pvsadm purge keys --workspace-name upstream-core --regexp "^rdr-.*" `, GroupID: "resource", PersistentPreRunE: func(cmd *cobra.Command, args []string) error { @@ -84,8 +84,8 @@ Examples: if pkg.Options.Since != 0 && pkg.Options.Before != 0 { return fmt.Errorf("--since and --before options can not be set at a time") } - if pkg.Options.InstanceID == "" && pkg.Options.InstanceName == "" { - return fmt.Errorf("--instance-id or --instance-name required") + if pkg.Options.WorkspaceID == "" && pkg.Options.WorkspaceName == "" { + return fmt.Errorf("--workspace-id or --workspace-name required") } return nil }, @@ -97,8 +97,12 @@ func init() { Cmd.AddCommand(networks.Cmd) Cmd.AddCommand(volumes.Cmd) Cmd.AddCommand(keys.Cmd) - Cmd.PersistentFlags().StringVarP(&pkg.Options.InstanceID, "instance-id", "i", "", "Instance ID of the PowerVS instance") - Cmd.PersistentFlags().StringVarP(&pkg.Options.InstanceName, "instance-name", "n", "", "Instance name of the PowerVS") + Cmd.PersistentFlags().StringVarP(&pkg.Options.WorkspaceID, "instance-id", "i", "", "Instance ID of the PowerVS workspace") + Cmd.PersistentFlags().MarkDeprecated("instance-id", "instance-id is deprecated, workspace-id should be used") + Cmd.PersistentFlags().StringVarP(&pkg.Options.WorkspaceName, "instance-name", "n", "", "Instance name of the PowerVS") + Cmd.PersistentFlags().MarkDeprecated("instance-name", "instance-name is deprecated, workspace-name should be used") + Cmd.PersistentFlags().StringVarP(&pkg.Options.WorkspaceID, "workspace-id", "", "", "Workspace ID of the PowerVS workspace") + Cmd.PersistentFlags().StringVarP(&pkg.Options.WorkspaceName, "workspace-name", "", "", "Workspace name of the PowerVS workspace") Cmd.PersistentFlags().BoolVar(&pkg.Options.DryRun, "dry-run", false, "dry run the action and don't delete the actual resources") Cmd.PersistentFlags().DurationVar(&pkg.Options.Since, "since", 0*time.Second, "Remove resources since mentioned duration(format: 99h99m00s), mutually exclusive with --before") Cmd.PersistentFlags().DurationVar(&pkg.Options.Before, "before", 0*time.Second, "Remove resources before mentioned duration(format: 99h99m00s), mutually exclusive with --since") diff --git a/cmd/purge/vms/vms.go b/cmd/purge/vms/vms.go index 277a62e6..0f14d23e 100644 --- a/cmd/purge/vms/vms.go +++ b/cmd/purge/vms/vms.go @@ -42,7 +42,7 @@ pvsadm purge --help for information return err } - pvmclient, err := client.NewPVMClientWithEnv(c, opt.InstanceID, opt.InstanceName, pkg.Options.Environment) + pvmclient, err := client.NewPVMClientWithEnv(c, opt.WorkspaceID, opt.WorkspaceName, pkg.Options.Environment) if err != nil { return err } diff --git a/cmd/purge/volumes/volumes.go b/cmd/purge/volumes/volumes.go index 5c392203..0fc40c3f 100644 --- a/cmd/purge/volumes/volumes.go +++ b/cmd/purge/volumes/volumes.go @@ -45,7 +45,7 @@ pvsadm purge --help for information return err } - pvmclient, err := client.NewPVMClientWithEnv(c, opt.InstanceID, opt.InstanceName, pkg.Options.Environment) + pvmclient, err := client.NewPVMClientWithEnv(c, opt.WorkspaceID, opt.WorkspaceName, pkg.Options.Environment) if err != nil { return err } diff --git a/docs/How to Import Image to PowerVS Instance.md b/docs/How to Import Image to PowerVS Instance.md index c5de1ca7..ca87c290 100644 --- a/docs/How to Import Image to PowerVS Instance.md +++ b/docs/How to Import Image to PowerVS Instance.md @@ -1,11 +1,11 @@ # Overview -This guide talks about how to import image to PowerVs instance using pvsadm. +This guide talks about how to import image to PowerVs workspace using pvsadm. # Prerequisite - pvsadm tool - IBMCLOUD_API_KEY. [How to create api key](https://cloud.ibm.com/docs/account?topic=account-userapikey#create_user_key) - S3 BucketName, Bucket Region, ObjectName -- PowerVS Instance Name/PowerVS Instance ID. +- PowerVS Workspace Name/PowerVS Workspace ID. # Image import Command help ```shell @@ -15,8 +15,8 @@ Flags: -b, --bucket string Cloud Storage bucket name -h, --help help for import --image-name string Name to give imported image - -i, --instance-id string Instance ID of the PowerVS instance - -n, --instance-name string Instance name of the PowerVS + --workspace-id string Instance ID of the PowerVS workspace + --workspace-name string Instance name of the PowerVS -o, --object-name string Cloud Storage image filename -r, --region string COS bucket location -p, --public-bucket Cloud Storage public bucket @@ -26,7 +26,7 @@ Flags: ``` -# Importing Image to PowerVS instance from S3 Bucket using pvsadm +# Importing Image to PowerVS workspace from S3 Bucket using pvsadm Set the API key variable ```shell @@ -36,29 +36,29 @@ $export IBMCLOUD_API_KEY=<IBM_CLOUD_API_KEY> ### case 1: Importing the image using auto-generated s3 credential ```shell -$pvsadm image import -n <POWERVS_INSTANCE_NAME> -b <BUCKETNAME> --object rhel-83-10032020.ova.gz --pvs-image-name test-image -r <REGION> +$pvsadm image import -n <POWERVS_WORKSPACE_NAME> -b <BUCKETNAME> --object rhel-83-10032020.ova.gz --pvs-image-name test-image -r <REGION> ``` ### case 2: Importing the image using accesskey and secretkey ```shell -$pvsadm image import -n <POWERVS_INSTANCE_NAME> -b <BUCKETNAME> --accesskey <ACCESSKEY> --secretkey <SECRETKEY> --object rhel-83-10032020.ova.gz --pvs-image-name test-image -r <REGION> +$pvsadm image import -n <POWERVS_WORKSPACE_NAME> -b <BUCKETNAME> --accesskey <ACCESSKEY> --secretkey <SECRETKEY> --object rhel-83-10032020.ova.gz --pvs-image-name test-image -r <REGION> ``` ### case 3: If user wants to specify the PowerVS storage type for importing the image ```shell -$pvsadm image import -n <POWERVS_INSTANCE_NAME> -b <BUCKETNAME> --object rhel-83-10032020.ova.gz --pvs-image-name test-image -r <REGION> --storagetype <POWERVS_STORAGE_TYPE> +$pvsadm image import -n <POWERVS_WORKSPACE_NAME> -b <BUCKETNAME> --object rhel-83-10032020.ova.gz --pvs-image-name test-image -r <REGION> --storagetype <POWERVS_STORAGE_TYPE> ``` ### case 4: If user wants to specify type of OS ```shell -$pvsadm image import -n <POWERVS_INSTANCE_NAME> -b <BUCKETNAME> --object rhel-83-10032020.ova.gz --pvs-image-name test-image -r <REGION> +$pvsadm image import -n <POWERVS_WORKSPACE_NAME> -b <BUCKETNAME> --object rhel-83-10032020.ova.gz --pvs-image-name test-image -r <REGION> ``` ### case 5: Importing the image from public bucket ```shell -$pvsadm image import -n <POWERVS_INSTANCE_NAME> -b <BUCKETNAME> --object rhel-83-10032020.ova.gz --pvs-image-name test-image -r <REGION> --public-bucket +$pvsadm image import -n <POWERVS_WORKSPACE_NAME> -b <BUCKETNAME> --object rhel-83-10032020.ova.gz --pvs-image-name test-image -r <REGION> --public-bucket ``` diff --git a/pkg/options.go b/pkg/options.go index bbff8dfe..49d3820a 100644 --- a/pkg/options.go +++ b/pkg/options.go @@ -19,20 +19,20 @@ import "time" var Options = &options{} type options struct { - InstanceID string - APIKey string - Environment string - Region string - Zone string - DryRun bool - Debug bool - Since time.Duration - Before time.Duration - InstanceName string - NoPrompt bool - IgnoreErrors bool - AuditFile string - Expr string + WorkspaceID string + APIKey string + Environment string + Region string + Zone string + DryRun bool + Debug bool + Since time.Duration + Before time.Duration + WorkspaceName string + NoPrompt bool + IgnoreErrors bool + AuditFile string + Expr string } // Options for pvsadm image command @@ -56,19 +56,19 @@ type imageCMDOptions struct { CloudConfigDefault bool OSPasswordSkip bool //upload options - InstanceName string - Region string - BucketName string - ResourceGrp string - ServicePlan string - ObjectName string + WorkspaceName string + Region string + BucketName string + ResourceGrp string + ServicePlan string + ObjectName string //import options COSInstanceName string ImageFilename string AccessKey string SecretKey string StorageType string - InstanceID string + WorkspaceID string ServiceCredName string Public bool Watch bool diff --git a/samples/convert-upload-images-powervs/convert-upload-images-powervs b/samples/convert-upload-images-powervs/convert-upload-images-powervs index 58cfc96d..554fb430 100755 --- a/samples/convert-upload-images-powervs/convert-upload-images-powervs +++ b/samples/convert-upload-images-powervs/convert-upload-images-powervs @@ -493,7 +493,7 @@ function import_image_remote { for i in $(seq 1 "$NO_OF_RETRY"); do echo "Attempt: $i/$NO_OF_RETRY" LOG_FILE="logs/import_image_remote_${service_name}_${i}_${LOGFILE}.log" - import_cmd="cd \"$REMOTE_TEMP_DIR\"; pvsadm image import --pvs-instance-name \"$service_name\" --bucket \"$cos_bucket_name\" --bucket-region \"$cos_bucket_region\" --object \"$object_name\" --pvs-image-name \"$image_name\" --api-key \"$IBMCLOUD_API_KEY\" -w --watch-timeout 2h " + import_cmd="cd \"$REMOTE_TEMP_DIR\"; pvsadm image import --workspace-name \"$service_name\" --bucket \"$cos_bucket_name\" --bucket-region \"$cos_bucket_region\" --object \"$object_name\" --pvs-image-name \"$image_name\" --api-key \"$IBMCLOUD_API_KEY\" -w --watch-timeout 2h " if [ -n "${access_key}" ] && [ -n "${secret_key}" ] ; then import_cmd+="--accesskey \"$access_key\" --secretkey \"$secret_key\" " fi diff --git a/samples/image-create-and-upload-sample/README.md b/samples/image-create-and-upload-sample/README.md index c528fe22..93c8c2e1 100644 --- a/samples/image-create-and-upload-sample/README.md +++ b/samples/image-create-and-upload-sample/README.md @@ -1,5 +1,5 @@ #### Overview -The `image_create_and_upload_script` helps to create ova image from qcow2 image, upload the images to a bucket (new/existing) and import them as boot image to pvs instance using the pvsadm tool +The `image_create_and_upload_script` helps to create ova image from qcow2 image, upload the images to a bucket (new/existing) and import them as boot image to pvs workspace using the pvsadm tool #### Prerequisite 1. Access to shell on IBM Power® logical partition (LPAR) running RHEL 8.x or CentOS 8.x with internet connectivity and minimum 250GB of free disk space 2. Need a valid RedHat subscription for the RHEL image conversion diff --git a/samples/image-create-and-upload-sample/config.sh b/samples/image-create-and-upload-sample/config.sh index 3f97dc7e..ac2dc3e2 100644 --- a/samples/image-create-and-upload-sample/config.sh +++ b/samples/image-create-and-upload-sample/config.sh @@ -21,4 +21,4 @@ RHEL_PASSWORD="" #Rhel Password required for rhel image conversion BUCKET_NAME="test-bucket" #Bucket name for uploading image. (Can be a new or an existing bucket) BUCKET_REGION="us-south" #Region where the bucket is present RESOURCE_GROUP="default" #Resource group required while uploading image -PVS_INSTANCE_NAME="" #PVS instance name where the image needs to be imported +WORKSPACE_NAME="" #PVS workspace name where the image needs to be imported diff --git a/samples/image-create-and-upload-sample/image_create_and_upload_script.sh b/samples/image-create-and-upload-sample/image_create_and_upload_script.sh index 15dea1a8..f2f2ad5e 100644 --- a/samples/image-create-and-upload-sample/image_create_and_upload_script.sh +++ b/samples/image-create-and-upload-sample/image_create_and_upload_script.sh @@ -59,7 +59,7 @@ function create_and_upload_image() { echo "Uploading $DISTRO image" pvsadm image upload --bucket $BUCKET_NAME --file $OBJECT_NAME --bucket-region $BUCKET_REGION --resource-group $RESOURCE_GROUP echo "Importing $DISTRO Image" - pvsadm image import --pvs-instance-name $PVS_INSTANCE_NAME --bucket $BUCKET_NAME --object $OBJECT_NAME --pvs-image-name $IMAGE_NAME --bucket-region $BUCKET_REGION + pvsadm image import --workspace-name $WORKSPACE_NAME --bucket $BUCKET_NAME --object $OBJECT_NAME --pvs-image-name $IMAGE_NAME --bucket-region $BUCKET_REGION } dnf install -y qemu-img cloud-utils-growpart