-
Notifications
You must be signed in to change notification settings - Fork 912
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
govc: Add support for providing size while we create a VMFS datastore #3528
Conversation
@HaruChebrolu, you must sign our contributor license agreement before your changes are merged. Click here to sign the agreement. If you are a VMware employee, read this for further instruction. |
b6f822e
to
c259513
Compare
@HaruChebrolu, we have received your signed contributor license agreement. The review is usually completed within a week, but may take longer under certain circumstances. Another comment will be added to the pull request to notify you when the merge can proceed. |
c259513
to
373cd6e
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you @HaruChebrolu
A few general items, please
- Run
make doc
to update USAGE.md - Code needs to be gofmt'd
- Amend commit message to include
Closes #3519
, this will create a link in generated release notes and auto-close the issue when we merge your change.
One more suggestion for the size flag, to use units.ByteSize
. This allows value to be specified as (for example) -size 30M
, -size 2T
, etc. See patch below.
diff --git a/govc/datastore/create.go b/govc/datastore/create.go
index 0432e46b..fc5e11e8 100644
--- a/govc/datastore/create.go
+++ b/govc/datastore/create.go
@@ -28,13 +28,14 @@ import (
"github.com/vmware/govmomi/govc/cli"
"github.com/vmware/govmomi/govc/flags"
"github.com/vmware/govmomi/object"
+ "github.com/vmware/govmomi/units"
"github.com/vmware/govmomi/vim25/soap"
"github.com/vmware/govmomi/vim25/types"
)
const (
- sectorSize = 512 // Sector size in bytes
- startSector = 2048 // Start sector (typically fixed)
+ sectorSize = 512 // Sector size in bytes
+ startSector = 2048 // Start sector (typically fixed)
)
type create struct {
@@ -55,7 +56,7 @@ type create struct {
// Options for VMFS
DiskCanonicalName string
Version *int32
- Size int64
+ Size units.ByteSize
// Options for local
Path string
@@ -150,7 +151,7 @@ func (cmd *create) Register(ctx context.Context, f *flag.FlagSet) {
// Options for VMFS
f.StringVar(&cmd.DiskCanonicalName, "disk", "", "Canonical name of disk (VMFS only)")
f.Var(flags.NewOptionalInt32(&cmd.Version), "version", "VMFS major version")
- f.Int64Var(&cmd.Size, "size", -1, "Size of new disk")
+ f.Var(&cmd.Size, "size", "Size of new disk")
// Options for Local
f.StringVar(&cmd.Path, "path", "", "Local directory path for the datastore (local only)")
@@ -296,7 +297,7 @@ func (cmd *create) CreateVmfsDatastore(ctx context.Context, hosts []*object.Host
spec := *option.Spec.(*types.VmfsDatastoreCreateSpec)
spec.Vmfs.VolumeName = cmd.Name
if cmd.Size > 0 {
- endSector := CalculateSectors(cmd.Size)
+ endSector := CalculateSectors(int64(cmd.Size))
// set values for Sectors
spec.Partition.Partition[0].StartSector = startSector
spec.Partition.Partition[0].EndSector = endSector
@@ -314,13 +315,11 @@ func (cmd *create) CreateVmfsDatastore(ctx context.Context, hosts []*object.Host
}
// CalculateSectors calculates the start and end sectors based on the given size.
-func CalculateSectors(sizeGB int64) (endSector int64) {
- sizeInBytes := sizeGB * 1024 * 1024 * 1024
+func CalculateSectors(sizeInBytes int64) (endSector int64) {
+ totalSectors := sizeInBytes / sectorSize
+ endSector = startSector + totalSectors - 1
- totalSectors := sizeInBytes / sectorSize
- endSector = startSector + totalSectors - 1
-
- return endSector
+ return endSector
}
func (cmd *create) CreateLocalDatastore(ctx context.Context, hosts []*object.HostSystem) error {
373cd6e
to
790ca92
Compare
Done |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for updating @HaruChebrolu
But still missing govc/USAGE.md from make doc
(you can see the GH Action check failed)
See this doc on the commit message. Still want the govc:
subject prefix as you had it before, Closes should be in the body:
govc: Add '-size' flag to datastore.create
Closes #3519
790ca92
to
f38b98d
Compare
f38b98d
to
1ae50b0
Compare
5c4423f
to
373217e
Compare
@HaruChebrolu, VMware has approved your signed contributor license agreement. |
Description
govc: Add support for providing size while we create a VMFS datastore
Closes: #(issue-number)
#3519
Type of change
Please mark options that are relevant:
not work as expected)
How Has This Been Tested?
Please describe the tests that you ran to verify your changes. Provide
instructions so we can reproduce. If applicable, please also list any relevant
details for your test configuration.
Tried to create a VMFS datastore with some size in govc cli
go run main.go datastore.create -type VMFS -name vmfs61 -version 6 -disk eui.b8fa2f975ecc490ea090a46404568540 -size 30 ocsqe-virt07.lab.eng.blr.redhat.com
Tried to create a VMFS datastore without size argument in govc cli, so that it takes the entire size of disk into consideration(default case)
go run main.go datastore.create -type VMFS -name vmfs61 -version 6 -disk eui.b8fa2f975ecc490ea090a46404568540 ocsqe-virt07.lab.eng.blr.redhat.com
Checklist:
CONTRIBUTION
guidelines of this project