Skip to content

Commit 7b0edc7

Browse files
authored
Iops (#1641)
* wip for balloon memory stats for onprem * . * . * . * adding capability to set iops && throughput for aws volumes * . * .
1 parent 9f02a0e commit 7b0edc7

File tree

23 files changed

+150
-62
lines changed

23 files changed

+150
-62
lines changed

cmd/cmd_volume.go

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ func VolumeCommands() *cobra.Command {
4545
}
4646

4747
func volumeCreateCommand() *cobra.Command {
48-
var data, size, typeof string
48+
var data, size, typeof, iops, throughput string
4949
cmdVolumeCreate := &cobra.Command{
5050
Use: "create <volume_name>",
5151
Short: "create volume",
@@ -55,6 +55,9 @@ func volumeCreateCommand() *cobra.Command {
5555
cmdVolumeCreate.PersistentFlags().StringVarP(&data, "data", "d", "", "volume data source")
5656
cmdVolumeCreate.PersistentFlags().StringVarP(&size, "size", "s", "", "volume initial size")
5757
cmdVolumeCreate.PersistentFlags().StringVarP(&typeof, "typeof", "", "", "volume type")
58+
cmdVolumeCreate.PersistentFlags().StringVarP(&iops, "iops", "", "", "volume iops")
59+
cmdVolumeCreate.PersistentFlags().StringVarP(&throughput, "throughput", "", "", "volume throughput")
60+
5861
return cmdVolumeCreate
5962
}
6063

@@ -63,6 +66,8 @@ func volumeCreateCommandHandler(cmd *cobra.Command, args []string) {
6366
data, _ := cmd.Flags().GetString("data")
6467
size, _ := cmd.Flags().GetString("size")
6568
typeof, _ := cmd.Flags().GetString("typeof")
69+
iops, _ := cmd.Flags().GetString("iops")
70+
throughput, _ := cmd.Flags().GetString("throughput")
6671

6772
c, err := getVolumeCommandDefaultConfig(cmd)
6873
if err != nil {
@@ -77,7 +82,26 @@ func volumeCreateCommandHandler(cmd *cobra.Command, args []string) {
7782
log.Fatal(err)
7883
}
7984

80-
res, err := p.CreateVolume(ctx, name, data, typeof, c.CloudConfig.Platform)
85+
cv := types.CloudVolume{
86+
Name: name,
87+
Typeof: typeof,
88+
}
89+
90+
if iops != "" {
91+
cv.Iops, err = strconv.ParseInt(iops, 10, 64)
92+
if err != nil {
93+
fmt.Println(err)
94+
}
95+
}
96+
97+
if throughput != "" {
98+
cv.Throughput, err = strconv.ParseInt(throughput, 10, 64)
99+
if err != nil {
100+
fmt.Println(err)
101+
}
102+
}
103+
104+
res, err := p.CreateVolume(ctx, cv, data, c.CloudConfig.Platform)
81105
if err != nil {
82106
exitWithError(err.Error())
83107
}

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ require (
1616
github.com/Azure/go-autorest/autorest/azure/auth v0.5.3
1717
github.com/Azure/go-autorest/autorest/to v0.4.0
1818
github.com/UpCloudLtd/upcloud-go-api/v6 v6.5.0
19-
github.com/aws/aws-sdk-go v1.35.20
19+
github.com/aws/aws-sdk-go v1.55.2
2020
github.com/bramvdbogaerde/go-scp v1.0.0
2121
github.com/digitalocean/godo v1.57.0
2222
github.com/distribution/reference v0.6.0

go.sum

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,8 @@ github.com/armon/go-radix v0.0.0-20180808171621-7fddfc383310/go.mod h1:ufUuZ+zHj
116116
github.com/asaskevich/govalidator v0.0.0-20190424111038-f61b66f89f4a/go.mod h1:lB+ZfQJz7igIIfQNfa7Ml4HSf2uFQQRzpGGRXenZAgY=
117117
github.com/aws/aws-sdk-go v1.35.20 h1:Hs7x9Czh+MMPnZLQqHhsuZKeNFA3Vuf7pdy2r5QlVb0=
118118
github.com/aws/aws-sdk-go v1.35.20/go.mod h1:tlPOdRjfxPBpNIwqDj61rmsnA85v9jc0Ps9+muhnW+k=
119+
github.com/aws/aws-sdk-go v1.55.2 h1:/2OFM8uFfK9e+cqHTw9YPrvTzIXT2XkFGXRM7WbJb7E=
120+
github.com/aws/aws-sdk-go v1.55.2/go.mod h1:eRwEWoyTWFMVYVQzKMNHWP5/RV4xIUGMQfXQHfHkpNU=
119121
github.com/bgentry/speakeasy v0.1.0/go.mod h1:+zsyZBPWlz7T6j88CTgSN5bM796AkVf0kBD4zp0CCIs=
120122
github.com/bketelsen/crypt v0.0.4/go.mod h1:aI6NrJ0pMGgvZKL1iVgXLnfIFJtfV+bKCoqOes/6LfM=
121123
github.com/blang/semver/v4 v4.0.0 h1:1PFHFE6yCCTv8C1TeyNNarDzntLi7wMI5i/pzqYIsAM=

lepton/provider.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ type Storage interface {
6969

7070
// VolumeService is an interface for volume related operations
7171
type VolumeService interface {
72-
CreateVolume(ctx *Context, volumeName, data, typeof string, provider string) (NanosVolume, error)
72+
CreateVolume(ctx *Context, cv types.CloudVolume, data string, provider string) (NanosVolume, error)
7373
GetAllVolumes(ctx *Context) (*[]NanosVolume, error)
7474
DeleteVolume(ctx *Context, volumeName string) error
7575
AttachVolume(ctx *Context, instanceName, volumeName string, attachID int) error

provider/aws/aws_volume.go

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,11 @@ import (
1212
"github.com/aws/aws-sdk-go/aws"
1313
"github.com/aws/aws-sdk-go/service/ec2"
1414
"github.com/nanovms/ops/lepton"
15+
"github.com/nanovms/ops/types"
1516
)
1617

1718
// CreateVolume creates a snapshot and use it to create a volume
18-
func (a *AWS) CreateVolume(ctx *lepton.Context, name, data, volType, provider string) (lepton.NanosVolume, error) {
19+
func (a *AWS) CreateVolume(ctx *lepton.Context, cv types.CloudVolume, data string, provider string) (lepton.NanosVolume, error) {
1920
config := ctx.Config()
2021
var sizeInGb int64
2122
var vol lepton.NanosVolume
@@ -29,7 +30,7 @@ func (a *AWS) CreateVolume(ctx *lepton.Context, name, data, volType, provider st
2930
}
3031

3132
// Create volume
32-
vol, err := lepton.CreateLocalVolume(config, name, data, provider)
33+
vol, err := lepton.CreateLocalVolume(config, cv.Name, data, provider)
3334
if err != nil {
3435
return vol, fmt.Errorf("create local volume: %v", err)
3536
}
@@ -74,7 +75,7 @@ func (a *AWS) CreateVolume(ctx *lepton.Context, name, data, volType, provider st
7475
}
7576

7677
// Create tags to assign to the volume
77-
tags, _ := buildAwsTags(config.CloudConfig.Tags, name)
78+
tags, _ := buildAwsTags(config.CloudConfig.Tags, cv.Name)
7879

7980
// Create volume from snapshot
8081
createVolumeInput := &ec2.CreateVolumeInput{
@@ -88,8 +89,26 @@ func (a *AWS) CreateVolume(ctx *lepton.Context, name, data, volType, provider st
8889
},
8990
}
9091

91-
if volType != "" {
92-
createVolumeInput.VolumeType = aws.String(volType)
92+
if cv.Typeof != "" {
93+
createVolumeInput.VolumeType = aws.String(cv.Typeof)
94+
}
95+
96+
if cv.Iops != 0 {
97+
if cv.Typeof == "" {
98+
fmt.Println("Setting iops is not supported for gp2")
99+
os.Exit(1)
100+
}
101+
102+
createVolumeInput.Iops = aws.Int64(cv.Iops)
103+
}
104+
105+
if cv.Throughput != 0 {
106+
if cv.Typeof == "" {
107+
fmt.Println("You can not provision iops without setting type to gp3")
108+
os.Exit(1)
109+
}
110+
111+
createVolumeInput.Throughput = aws.Int64(cv.Throughput)
93112
}
94113

95114
if sizeInGb != 0 {

provider/azure/azure_volume.go

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,11 @@ import (
1313
"github.com/Azure/go-autorest/autorest/to"
1414
"github.com/nanovms/ops/lepton"
1515
"github.com/nanovms/ops/log"
16+
"github.com/nanovms/ops/types"
1617
)
1718

1819
// CreateVolume uploads the volume raw file and creates a disk from it
19-
func (a *Azure) CreateVolume(ctx *lepton.Context, name, data, typeof, provider string) (lepton.NanosVolume, error) {
20+
func (a *Azure) CreateVolume(ctx *lepton.Context, cv types.CloudVolume, data string, provider string) (lepton.NanosVolume, error) {
2021
config := ctx.Config()
2122

2223
var vol lepton.NanosVolume
@@ -38,13 +39,13 @@ func (a *Azure) CreateVolume(ctx *lepton.Context, name, data, typeof, provider s
3839
sizeInGb = int64(size)
3940
}
4041

41-
vol, err = lepton.CreateLocalVolume(config, name, data, provider)
42+
vol, err = lepton.CreateLocalVolume(config, cv.Name, data, provider)
4243
if err != nil {
4344
return vol, fmt.Errorf("create local volume: %v", err)
4445
}
4546
defer os.Remove(vol.Path)
4647

47-
config.CloudConfig.ImageName = name
48+
config.CloudConfig.ImageName = cv.Name
4849

4950
err = a.Storage.CopyToBucket(config, vol.Path)
5051
if err != nil {
@@ -57,13 +58,13 @@ func (a *Azure) CreateVolume(ctx *lepton.Context, name, data, typeof, provider s
5758
}
5859

5960
container := "quickstart-nanos"
60-
disk := name + ".vhd"
61+
disk := cv.Name + ".vhd"
6162

6263
sourceURI := "https://" + bucket + ".blob.core.windows.net/" + container + "/" + disk
6364

6465
diskParams := compute.Disk{
6566
Location: to.StringPtr(location),
66-
Name: to.StringPtr(name),
67+
Name: to.StringPtr(cv.Name),
6768
DiskProperties: &compute.DiskProperties{
6869
HyperVGeneration: compute.V1,
6970
DiskSizeGB: to.Int32Ptr(int32(sizeInGb)),
@@ -75,7 +76,7 @@ func (a *Azure) CreateVolume(ctx *lepton.Context, name, data, typeof, provider s
7576
},
7677
}
7778

78-
_, err = disksClient.CreateOrUpdate(context.TODO(), a.groupName, name, diskParams)
79+
_, err = disksClient.CreateOrUpdate(context.TODO(), a.groupName, cv.Name, diskParams)
7980
if err != nil {
8081
return vol, err
8182
}

provider/digitalocean/digital_ocean_volume.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,13 @@
22

33
package digitalocean
44

5-
import "github.com/nanovms/ops/lepton"
5+
import (
6+
"github.com/nanovms/ops/lepton"
7+
"github.com/nanovms/ops/types"
8+
)
69

710
// CreateVolume is a stub to satisfy VolumeService interface
8-
func (do *DigitalOcean) CreateVolume(ctx *lepton.Context, name, data, typeof, provider string) (lepton.NanosVolume, error) {
11+
func (do *DigitalOcean) CreateVolume(ctx *lepton.Context, cv types.CloudVolume, data string, provider string) (lepton.NanosVolume, error) {
912
var vol lepton.NanosVolume
1013
return vol, nil
1114
}

provider/gcp/gcp_volume.go

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,16 @@ import (
1111
"strings"
1212

1313
"github.com/nanovms/ops/lepton"
14+
"github.com/nanovms/ops/types"
15+
1416
compute "google.golang.org/api/compute/v1"
1517
)
1618

1719
// CreateVolume creates local volume and converts it to GCP format before orchestrating the necessary upload procedures
18-
func (g *GCloud) CreateVolume(ctx *lepton.Context, name, data, typeof, provider string) (lepton.NanosVolume, error) {
20+
func (g *GCloud) CreateVolume(ctx *lepton.Context, cv types.CloudVolume, data string, provider string) (lepton.NanosVolume, error) {
1921
config := ctx.Config()
2022

21-
arch := name + ".tar.gz"
23+
arch := cv.Name + ".tar.gz"
2224

2325
var sizeInGb int64
2426
var vol lepton.NanosVolume
@@ -31,7 +33,7 @@ func (g *GCloud) CreateVolume(ctx *lepton.Context, name, data, typeof, provider
3133
sizeInGb = int64(size)
3234
}
3335

34-
lv, err := lepton.CreateLocalVolume(config, name, data, provider)
36+
lv, err := lepton.CreateLocalVolume(config, cv.Name, data, provider)
3537
if err != nil {
3638
return lv, err
3739
}
@@ -65,7 +67,7 @@ func (g *GCloud) CreateVolume(ctx *lepton.Context, name, data, typeof, provider
6567

6668
labels := buildGcpLabels(nil, "")
6769
img := &compute.Image{
68-
Name: name,
70+
Name: cv.Name,
6971
Labels: labels,
7072
RawDisk: &compute.ImageRawDisk{
7173
Source: fmt.Sprintf(GCPStorageURL, config.CloudConfig.BucketName, arch),
@@ -81,10 +83,10 @@ func (g *GCloud) CreateVolume(ctx *lepton.Context, name, data, typeof, provider
8183
}
8284

8385
disk := &compute.Disk{
84-
Name: name,
86+
Name: cv.Name,
8587
Labels: labels,
8688
SizeGb: sizeInGb,
87-
SourceImage: "global/images/" + name,
89+
SourceImage: "global/images/" + cv.Name,
8890
Type: fmt.Sprintf("projects/%s/zones/%s/diskTypes/pd-standard", config.CloudConfig.ProjectID, config.CloudConfig.Zone),
8991
}
9092

provider/hyperv/hyperv.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ func (p *Provider) Initialize(c *types.ProviderConfig) error {
4242
}
4343

4444
// CreateVolume is a stub
45-
func (p *Provider) CreateVolume(ctx *lepton.Context, name, data, typeof, provider string) (lepton.NanosVolume, error) {
45+
func (p *Provider) CreateVolume(ctx *lepton.Context, cv types.CloudVolume, data string, provider string) (lepton.NanosVolume, error) {
4646
return lepton.NanosVolume{}, errors.New("Unsupported")
4747
}
4848

provider/ibm/ibm_volume.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,13 @@
22

33
package ibm
44

5-
import "github.com/nanovms/ops/lepton"
5+
import (
6+
"github.com/nanovms/ops/lepton"
7+
"github.com/nanovms/ops/types"
8+
)
69

710
// CreateVolume is a stub to satisfy VolumeService interface
8-
func (v *IBM) CreateVolume(ctx *lepton.Context, name, data, typeof, provider string) (lepton.NanosVolume, error) {
11+
func (v *IBM) CreateVolume(ctx *lepton.Context, cv types.CloudVolume, data string, provider string) (lepton.NanosVolume, error) {
912
var vol lepton.NanosVolume
1013
return vol, nil
1114
}

0 commit comments

Comments
 (0)