Skip to content

Commit

Permalink
Deprecating instance-id and instance-name
Browse files Browse the repository at this point in the history
Signed-off-by: Varad Ahirwadkar <varad.ahirwadkar1@ibm.com>
  • Loading branch information
varad-ahirwadkar committed May 22, 2024
1 parent b0ad45b commit 446acb9
Show file tree
Hide file tree
Showing 21 changed files with 89 additions and 41 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
3 changes: 2 additions & 1 deletion cmd/create/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,6 @@ 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().MarkDeprecated("instance-id", "instance-id is deprecated, workspace-id should be used")
Cmd.PersistentFlags().StringVarP(&pkg.Options.InstanceID, "workspace-id", "", "", "Workspace ID of the PowerVS workspace")
}
6 changes: 6 additions & 0 deletions cmd/create/port/port.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.InstanceID == "" {
return fmt.Errorf("--workspace-id required")
}
return nil
},
RunE: func(cmd *cobra.Command, args []string) error {
opt := pkg.Options

Expand Down
3 changes: 2 additions & 1 deletion cmd/delete/delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,6 @@ 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().MarkDeprecated("instance-id", "instance-id is deprecated, workspace-id should be used")
Cmd.PersistentFlags().StringVarP(&pkg.Options.InstanceID, "workspace-id", "", "", "Workspace ID of the PowerVS instance")
}
6 changes: 6 additions & 0 deletions cmd/delete/port/port.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.InstanceID == "" {
return fmt.Errorf("--workspace-id required")
}
return nil
},
RunE: func(cmd *cobra.Command, args []string) error {
opt := pkg.Options

Expand Down
4 changes: 3 additions & 1 deletion cmd/dhcp-sync/dhcp-sync.go
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ var Cmd = &cobra.Command{
GroupID: "dhcp",
PreRunE: func(cmd *cobra.Command, args []string) error {
if pkg.Options.InstanceID == "" {
return fmt.Errorf("--instance-id is required")
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")
Expand Down Expand Up @@ -212,6 +212,8 @@ var Cmd = &cobra.Command{

func init() {
Cmd.Flags().StringVarP(&pkg.Options.InstanceID, "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.InstanceID, "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")
Expand Down
6 changes: 5 additions & 1 deletion cmd/dhcpserver/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.InstanceID == "" {
return fmt.Errorf("--workspace-id required")
}
return nil
},
RunE: func(cmd *cobra.Command, args []string) error {
Expand All @@ -44,5 +47,6 @@ func init() {
Cmd.AddCommand(deleteCmd)

Cmd.PersistentFlags().StringVarP(&pkg.Options.InstanceID, "instance-id", "i", "", "Instance ID of the PowerVS instance")
_ = Cmd.MarkPersistentFlagRequired("instance-id")
Cmd.PersistentFlags().MarkDeprecated("instance-id", "instance-id is deprecated, workspace-id should be used")
Cmd.PersistentFlags().StringVarP(&pkg.Options.InstanceID, "workspace-id", "", "", "Workspace ID of the PowerVS instance")
}
2 changes: 1 addition & 1 deletion cmd/get/events/events.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ var Cmd = &cobra.Command{
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")
return fmt.Errorf("--workspace-id or --workspace-name required")
}
return nil
},
Expand Down
4 changes: 4 additions & 0 deletions cmd/get/get.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,5 +37,9 @@ func init() {
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().MarkDeprecated("instance-id", "instance-id is deprecated, workspace-id should be used")
Cmd.PersistentFlags().StringVarP(&pkg.Options.InstanceName, "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.InstanceID, "workspace-id", "", "", "Workspace ID of the PowerVS instance")
Cmd.PersistentFlags().StringVarP(&pkg.Options.InstanceName, "workspace-name", "", "", "Workspace name of the PowerVS")
}
6 changes: 3 additions & 3 deletions cmd/get/peravailability/peravailability.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ var Cmd = &cobra.Command{
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")
return fmt.Errorf("--workspace-id or --workspace-name required")
}
return nil
},
Expand Down Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion cmd/get/ports/ports.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ var Cmd = &cobra.Command{
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")
return fmt.Errorf("--workspace-id or --workspace-name required")
}
return nil
},
Expand Down
13 changes: 9 additions & 4 deletions cmd/image/import/import.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,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
Expand All @@ -88,11 +88,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")
return fmt.Errorf("--pvs-workspace-name or --pvs-workspace-id required")
}

case1 := pkg.ImageCMDOptions.AccessKey == "" && pkg.ImageCMDOptions.SecretKey != ""
Expand Down Expand Up @@ -251,8 +251,13 @@ pvsadm image import -n upstream-core-lon04 -b <BUCKETNAME> --object rhel-83-100
}

func init() {
// TODO pvs-instance-name and pvs-instance-id is deprecated and will be removed in a future release
Cmd.Flags().StringVarP(&pkg.ImageCMDOptions.InstanceName, "pvs-instance-name", "n", "", "PowerVS Instance name.")
Cmd.Flags().MarkDeprecated("pvs-instance-name", "pvs-instance-name is deprecated, pvs-workspace-name should be used")
Cmd.Flags().StringVarP(&pkg.ImageCMDOptions.InstanceID, "pvs-instance-id", "i", "", "PowerVS Instance ID.")
Cmd.Flags().MarkDeprecated("pvs-instance-id", "pvs-instance-id is deprecated, pvs-workspace-id should be used")
Cmd.Flags().StringVarP(&pkg.ImageCMDOptions.InstanceName, "pvs-workspace-name", "", "", "PowerVS Workspace name.")
Cmd.Flags().StringVarP(&pkg.ImageCMDOptions.InstanceID, "pvs-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
Expand Down
1 change: 1 addition & 0 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.

2 changes: 1 addition & 1 deletion cmd/purge/images/images.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.InstanceID)
opt := pkg.Options

c, err := client.NewClientWithEnv(opt.APIKey, opt.Environment, opt.Debug)
Expand Down
30 changes: 17 additions & 13 deletions cmd/purge/purge.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -85,7 +85,7 @@ Examples:
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")
return fmt.Errorf("--workspace-id or --workspace-name required")
}
return nil
},
Expand All @@ -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.InstanceID, "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.InstanceName, "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.InstanceID, "workspace-id", "", "", "Workspace ID of the PowerVS workspace")
Cmd.PersistentFlags().StringVarP(&pkg.Options.InstanceName, "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")
Expand Down
20 changes: 10 additions & 10 deletions docs/How to Import Image to PowerVS Instance.md
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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
--pvs-workspace-id string Instance ID of the PowerVS workspace
--pvs-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
Expand All @@ -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
Expand All @@ -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
```
2 changes: 2 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ require (
github.com/go-playground/locales v0.14.1 // indirect
github.com/go-playground/universal-translator v0.18.1 // indirect
github.com/go-playground/validator/v10 v10.19.0 // indirect
github.com/golang/mock v1.6.0 // indirect
github.com/google/go-cmp v0.6.0 // indirect
github.com/google/uuid v1.6.0 // indirect
github.com/hashicorp/go-cleanhttp v0.5.2 // indirect
Expand Down Expand Up @@ -90,6 +91,7 @@ require (
golang.org/x/sys v0.19.0 // indirect
golang.org/x/term v0.19.0 // indirect
golang.org/x/text v0.14.0 // indirect
golang.org/x/tools v0.16.1 // indirect
gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)
Loading

0 comments on commit 446acb9

Please sign in to comment.