Skip to content

Commit

Permalink
Renaming 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 Apr 15, 2024
1 parent 0ecc6a6 commit ed14607
Show file tree
Hide file tree
Showing 17 changed files with 55 additions and 53 deletions.
4 changes: 2 additions & 2 deletions cmd/create/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,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().StringVarP(&pkg.Options.InstanceID, "workspace-id", "i", "", "Workspace ID of the PowerVS workspace")
_ = Cmd.MarkPersistentFlagRequired("workspace-id")
}
4 changes: 2 additions & 2 deletions cmd/delete/delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,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().StringVarP(&pkg.Options.InstanceID, "workspace-id", "i", "", "Workspace ID of the PowerVS workspace")
_ = Cmd.MarkPersistentFlagRequired("workspace-id")
}
4 changes: 2 additions & 2 deletions 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,7 +212,7 @@ 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.InstanceID, "workspace-id", "i", "", "Workspace ID of the PowerVS workspace")
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
4 changes: 2 additions & 2 deletions cmd/dhcpserver/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,6 @@ 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.InstanceID, "workspace-id", "i", "", "Workspace ID of the PowerVS workspace")
_ = Cmd.MarkPersistentFlagRequired("workspace-id")
}
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: 2 additions & 2 deletions cmd/get/get.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,6 @@ 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.InstanceID, "workspace-id", "i", "", "Workspace ID of the PowerVS workspace")
Cmd.PersistentFlags().StringVarP(&pkg.Options.InstanceName, "workspace-name", "n", "", "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.Infoln("The following zones/datacenters have support for PER:", perEnabledRegions, ".", "More information at https://cloud.ibm.com/docs/overview?topic=overview-locations")
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
10 changes: 5 additions & 5 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 workspace",
Long: `Import the image into PowerVS workspace
pvsadm image import --help for information
# Set the API key or feed the --api-key commandline argument
Expand Down Expand Up @@ -92,7 +92,7 @@ pvsadm image import -n upstream-core-lon04 -b <BUCKETNAME> --object rhel-83-100
`,
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,8 @@ 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.")
Cmd.Flags().StringVarP(&pkg.ImageCMDOptions.InstanceName, "pvs-workspace-name", "n", "", "PowerVS Workspace name.")
Cmd.Flags().StringVarP(&pkg.ImageCMDOptions.InstanceID, "pvs-workspace-id", "i", "", "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: 15 additions & 15 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
# Delete all the networks along with the instance and their assigned ports
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,8 @@ 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.InstanceID, "workspace-id", "i", "", "Workspace ID of the PowerVS workspace")
Cmd.PersistentFlags().StringVarP(&pkg.Options.InstanceName, "workspace-name", "n", "", "Workspace name of the PowerVS")
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
-i, --workspace-id string Workspace ID of the PowerVS workspace
-n, --workspace-name string Workspace 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
```
5 changes: 3 additions & 2 deletions pkg/client/instance/instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,13 @@ package instance
import (
"context"
"fmt"
"regexp"
"time"

"github.com/IBM-Cloud/power-go-client/clients/instance"
"github.com/IBM-Cloud/power-go-client/ibmpisession"
"github.com/IBM-Cloud/power-go-client/power/models"
"github.com/ppc64le-cloud/pvsadm/pkg"
"regexp"
"time"
)

type Client struct {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 --pvs-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
Expand Down Expand Up @@ -542,13 +542,13 @@ function create_cos_bucket {
for i in $(seq 1 "$NO_OF_RETRY"); do
LOG_FILE="logs/create_cos_bucket-${i}_${LOGFILE}.log"
echo "Attempt: $i/$NO_OF_RETRY"
$CLI_PATH cos buckets --ibm-service-instance-id "${COS_INSTANCE_ID}" > $LOG_FILE 2>&1
$CLI_PATH cos buckets --ibm-service-workspace-id "${COS_INSTANCE_ID}" > $LOG_FILE 2>&1
if grep -Ec "(^| )${cos_bucket_name}( |$)" $LOG_FILE >/dev/null; then
log "The bucket name already exist; Press ctrl+c to exit and give a new bucket name else will proceed in 10 seconds"
sleep 10
return 0
fi
$CLI_PATH cos bucket-create --bucket "${cos_bucket_name}" --ibm-service-instance-id "${COS_INSTANCE_ID}" --region "${cos_region_name}"> $LOG_FILE 2>&1
$CLI_PATH cos bucket-create --bucket "${cos_bucket_name}" --ibm-service-workspace-id "${COS_INSTANCE_ID}" --region "${cos_region_name}"> $LOG_FILE 2>&1
if grep -c "The requested bucket name is not available" $LOG_FILE >/dev/null; then
log "The requested bucket name is not available. The bucket namespace is shared by all users of the system. Select a different name and try again"
return 1
Expand Down
2 changes: 1 addition & 1 deletion samples/image-create-and-upload-sample/README.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion samples/image-create-and-upload-sample/config.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
PVS_WORKSPACE_NAME="" #PVS workspace name where the image needs to be imported

0 comments on commit ed14607

Please sign in to comment.