Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for tier0 and tier5k to create boot images #648

Merged
merged 1 commit into from
Aug 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 39 additions & 12 deletions cmd/image/import/import.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ package _import

import (
"fmt"
"os"
"strings"
"time"

Expand Down Expand Up @@ -62,6 +61,31 @@ func findCOSInstanceDetails(resources []models.ServiceInstanceV2, bxCli *client.
return "", "", crn.CRN{}
}

// checkStorageTierAvailability confirms if the provided cloud instance ID supports the required storageType.
func checkStorageTierAvailability(pvsClient *client.PVMClient, storageType string) error {
// Supported tiers are Tier0, Tier1, Tier3 and Tier 5k
// The use of fixed IOPS is limited to volumes with a size of 200 GB or less, which is the break even size with Tier 0
// (200 GB @ 25 IOPS/GB = 5000 IOPS).
// Ref: https://cloud.ibm.com/docs/power-iaas?topic=power-iaas-on-cloud-architecture#storage-tiers
// API Docs for Storagetypes: https://cloud.ibm.com/docs/power-iaas?topic=power-iaas-on-cloud-architecture#IOPS-api

validStorageType := []string{"tier3", "tier1", "tier0", "tier5k"}
if !utils.Contains(validStorageType, storageType) {
return fmt.Errorf("provide valid StorageType. Allowable values are %v", validStorageType)
}

storageTiers, err := pvsClient.StorageTierClient.GetAll()
if err != nil {
return fmt.Errorf("an error occured while retriving the Storage tier availability. err:%v", err)
}
for _, storageTier := range storageTiers {
if storageTier.Name == storageType && *storageTier.State == "inactive" {
return fmt.Errorf("the requested storage tier is not available in the provided cloud instance. Please retry with a different tier")
}
}
return nil
}

var Cmd = &cobra.Command{
Use: "import",
Short: "Import the image into PowerVS workpace",
Expand Down Expand Up @@ -107,19 +131,21 @@ pvsadm image import -n upstream-core-lon04 -b <BUCKETNAME> --object rhel-83-1003
RunE: func(cmd *cobra.Command, args []string) error {
opt := pkg.ImageCMDOptions
apikey := pkg.Options.APIKey
//validate inputs
validStorageType := []string{"tier3", "tier1"}

if !utils.Contains(validStorageType, strings.ToLower(opt.StorageType)) {
klog.Errorf("provide valid StorageType. Allowable values are [tier1, tier3]")
os.Exit(1)
bxCli, err := client.NewClientWithEnv(apikey, pkg.Options.Environment, pkg.Options.Debug)
if err != nil {
return err
}

bxCli, err := client.NewClientWithEnv(apikey, pkg.Options.Environment, pkg.Options.Debug)
pvmclient, err := client.NewPVMClientWithEnv(bxCli, opt.WorkspaceID, opt.WorkspaceName, pkg.Options.Environment)
if err != nil {
return err
}

if err := checkStorageTierAvailability(pvmclient, opt.StorageType); err != nil {
return err
}

//Create AccessKey and SecretKey for the bucket provided if bucket access is private
if (opt.AccessKey == "" || opt.SecretKey == "") && (!opt.Public) {
//Find CosInstance of the bucket
Expand Down Expand Up @@ -172,10 +198,6 @@ pvsadm image import -n upstream-core-lon04 -b <BUCKETNAME> --object rhel-83-1003
opt.SecretKey = cred["secret_access_key"].(string)
}

pvmclient, err := client.NewPVMClientWithEnv(bxCli, opt.WorkspaceID, opt.WorkspaceName, pkg.Options.Environment)
if err != nil {
return err
}
//By default Bucket Access is private
bucketAccess := "private"

Expand Down Expand Up @@ -259,7 +281,12 @@ func init() {
Cmd.Flags().BoolVarP(&pkg.ImageCMDOptions.Public, "public-bucket", "p", false, "Cloud Object Storage public bucket.")
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, "pvs-storagetype", "tier3", "PowerVS Storage type, accepted values are [tier1, tier3].")
Cmd.Flags().StringVar(&pkg.ImageCMDOptions.StorageType, "pvs-storagetype", "tier3", `PowerVS Storage type, accepted values are [tier1, tier3, tier0, tier5k].
Tier 0 | 25 IOPS/GB
Tier 1 | 10 IOPS/GB
Tier 3 | 3 IOPS/GB
Fixed IOPS/Tier5k | 5000 IOPS regardless of size
Note: The use of fixed IOPS is limited to volumes with a size of 200 GB or less, which is the break even size with Tier 0 (200 GB @ 25 IOPS/GB = 5000 IOPS).`)
Cmd.Flags().StringVar(&pkg.ImageCMDOptions.ServiceCredName, "cos-service-cred", "", "IBM COS Service Credential name to be auto generated(default \""+serviceCredPrefix+"-<COS Name>\")")

_ = Cmd.MarkFlagRequired("bucket")
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ go 1.22.4

require (
github.com/IBM-Cloud/bluemix-go v0.0.0-20220221162715-e08ea9e7c175
github.com/IBM-Cloud/power-go-client v1.7.0
github.com/IBM-Cloud/power-go-client v1.7.1
github.com/IBM/go-sdk-core/v5 v5.17.4
github.com/IBM/ibm-cos-sdk-go v1.11.0
github.com/IBM/platform-services-go-sdk v0.66.0
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMT
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
github.com/IBM-Cloud/bluemix-go v0.0.0-20220221162715-e08ea9e7c175 h1:FuzMrve2T3v3O2lcI1WA71XJekrW2sX+IC35/X1gYuE=
github.com/IBM-Cloud/bluemix-go v0.0.0-20220221162715-e08ea9e7c175/go.mod h1:r4ZaLtgP9ghpBmnZd77tSjM2LwfOiCLOG6XmCoutnOQ=
github.com/IBM-Cloud/power-go-client v1.7.0 h1:/GuGwPMTKoCZACfnwt7b6wKr4v32q1VO1AMFGNETRN4=
github.com/IBM-Cloud/power-go-client v1.7.0/go.mod h1:9izycYAmNQ+NAdVPXDC3fHYxqWLjlR2YiwqKYveMv5Y=
github.com/IBM-Cloud/power-go-client v1.7.1 h1:LDEqMGH3KoxgoYfWWM/hG+2fBzy05KFCWygis2fcT3M=
github.com/IBM-Cloud/power-go-client v1.7.1/go.mod h1:bJZ0gP3MHPNewMFVDXW73/8lJFxXOf8MQR8JaeTyrYo=
github.com/IBM/go-sdk-core/v5 v5.17.4 h1:VGb9+mRrnS2HpHZFM5hy4J6ppIWnwNrw0G+tLSgcJLc=
github.com/IBM/go-sdk-core/v5 v5.17.4/go.mod h1:KsAAI7eStAWwQa4F96MLy+whYSh39JzNjklZRbN/8ns=
github.com/IBM/ibm-cos-sdk-go v1.11.0 h1:Jp55NLN3OvBwucMGpP5wNybyjncsmTZ9+GPHai/1cE8=
Expand Down
3 changes: 3 additions & 0 deletions pkg/client/pvmclient.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import (
"github.com/ppc64le-cloud/pvsadm/pkg/client/job"
"github.com/ppc64le-cloud/pvsadm/pkg/client/key"
"github.com/ppc64le-cloud/pvsadm/pkg/client/network"
"github.com/ppc64le-cloud/pvsadm/pkg/client/storagetier"
"github.com/ppc64le-cloud/pvsadm/pkg/client/volume"
)

Expand All @@ -53,6 +54,7 @@ type PVMClient struct {
JobClient *job.Client
KeyClient *key.Client
NetworkClient *network.Client
StorageTierClient *storagetier.Client
VolumeClient *volume.Client
}

Expand Down Expand Up @@ -109,6 +111,7 @@ func NewPVMClient(c *Client, instanceID, instanceName, ep string) (*PVMClient, e
pvmclient.JobClient = job.NewClient(pvmclient.PISession, instanceID)
pvmclient.KeyClient = key.NewClient(pvmclient.PISession, instanceID)
pvmclient.NetworkClient = network.NewClient(pvmclient.PISession, instanceID)
pvmclient.StorageTierClient = storagetier.NewClient(pvmclient.PISession, pvmclient.InstanceID)
pvmclient.VolumeClient = volume.NewClient(pvmclient.PISession, instanceID)
return pvmclient, nil
}
Expand Down
37 changes: 37 additions & 0 deletions pkg/client/storagetier/storagetier.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
// Copyright 2024 IBM Corp
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package storagetier

import (
"context"

"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"
)

type Client struct {
client *instance.IBMPIStorageTierClient
}

func NewClient(sess *ibmpisession.IBMPISession, powerinstanceid string) *Client {
return &Client{
client: instance.NewIBMPIStorageTierClient(context.Background(), sess, powerinstanceid),
}
}

func (c *Client) GetAll() (models.RegionStorageTiers, error) {
return c.client.GetAll()
}