Skip to content

Commit

Permalink
vcsim: add vslm VStorageObjectManager (aka FCD Global Catalog) support
Browse files Browse the repository at this point in the history
govc: make datastore (-ds flag) optional in (most) disk commands

Fixes #2542

Signed-off-by: Doug MacEachern <dougm@broadcom.com>
  • Loading branch information
dougm committed Jan 13, 2025
1 parent 8eb362f commit 30e8cfd
Show file tree
Hide file tree
Showing 23 changed files with 1,051 additions and 370 deletions.
37 changes: 5 additions & 32 deletions cli/disk/attach.go
Original file line number Diff line number Diff line change
@@ -1,18 +1,6 @@
/*
Copyright (c) 2024-2024 VMware, Inc. All Rights Reserved.
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.
*/
// © Broadcom. All Rights Reserved.
// The term “Broadcom” refers to Broadcom Inc. and/or its subsidiaries.
// SPDX-License-Identifier: Apache-2.0

package disk

Expand All @@ -22,7 +10,6 @@ import (

"github.com/vmware/govmomi/cli"
"github.com/vmware/govmomi/cli/flags"
"github.com/vmware/govmomi/vim25/mo"
)

type attach struct {
Expand Down Expand Up @@ -67,7 +54,7 @@ func (cmd *attach) Run(ctx context.Context, f *flag.FlagSet) error {
return flag.ErrHelp
}

ds, err := cmd.DatastoreIfSpecified()
m, err := NewManagerFromFlag(ctx, cmd.DatastoreFlag)
if err != nil {
return err
}
Expand All @@ -77,21 +64,7 @@ func (cmd *attach) Run(ctx context.Context, f *flag.FlagSet) error {
return err
}

if ds == nil {
var props mo.VirtualMachine
err = vm.Properties(ctx, vm.Reference(), []string{"datastore"}, &props)
if err != nil {
return err
}
if len(props.Datastore) != 1 {
ds, err = cmd.Datastore() // likely results in MultipleFoundError
if err != nil {
return err
}
}
}

id := f.Arg(0)

return vm.AttachDisk(ctx, id, ds, 0, nil)
return m.AttachDisk(ctx, vm, id)
}
37 changes: 7 additions & 30 deletions cli/disk/create.go
Original file line number Diff line number Diff line change
@@ -1,18 +1,6 @@
/*
Copyright (c) 2018-2024 VMware, Inc. All Rights Reserved.
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.
*/
// © Broadcom. All Rights Reserved.
// The term “Broadcom” refers to Broadcom Inc. and/or its subsidiaries.
// SPDX-License-Identifier: Apache-2.0

package disk

Expand All @@ -27,7 +15,6 @@ import (
"github.com/vmware/govmomi/units"
"github.com/vmware/govmomi/vim25/mo"
"github.com/vmware/govmomi/vim25/types"
"github.com/vmware/govmomi/vslm"
)

type disk struct {
Expand Down Expand Up @@ -92,7 +79,7 @@ func (cmd *disk) Run(ctx context.Context, f *flag.FlagSet) error {
return flag.ErrHelp
}

c, err := cmd.DatastoreFlag.Client()
m, err := NewManagerFromFlag(ctx, cmd.DatastoreFlag)
if err != nil {
return err
}
Expand Down Expand Up @@ -120,8 +107,6 @@ func (cmd *disk) Run(ctx context.Context, f *flag.FlagSet) error {
return err
}

m := vslm.NewObjectManager(c)

spec := types.VslmCreateSpec{
Name: name,
CapacityInMB: int64(cmd.size) / units.MB,
Expand All @@ -136,25 +121,17 @@ func (cmd *disk) Run(ctx context.Context, f *flag.FlagSet) error {
}

if cmd.StoragePodFlag.Isset() {
if err = m.PlaceDisk(ctx, &spec, pool.Reference()); err != nil {
if err = m.ObjectManager.PlaceDisk(ctx, &spec, pool.Reference()); err != nil {
return err
}
}

task, err := m.CreateDisk(ctx, spec)
if err != nil {
return nil
}

logger := cmd.DatastoreFlag.ProgressLogger(fmt.Sprintf("Creating %s...", spec.Name))

res, err := task.WaitForResult(ctx, logger)
logger.Wait()
obj, err := m.CreateDisk(ctx, spec)
if err != nil {
return err
}

fmt.Println(res.Result.(types.VStorageObject).Config.Id.Id)
fmt.Println(obj.Config.Id.Id)

return nil
}
18 changes: 3 additions & 15 deletions cli/disk/detach.go
Original file line number Diff line number Diff line change
@@ -1,18 +1,6 @@
/*
Copyright (c) 2024-2024 VMware, Inc. All Rights Reserved.
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.
*/
// © Broadcom. All Rights Reserved.
// The term “Broadcom” refers to Broadcom Inc. and/or its subsidiaries.
// SPDX-License-Identifier: Apache-2.0

package disk

Expand Down
37 changes: 7 additions & 30 deletions cli/disk/ls.go
Original file line number Diff line number Diff line change
@@ -1,18 +1,6 @@
/*
Copyright (c) 2018-2024 VMware, Inc. All Rights Reserved.
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.
*/
// © Broadcom. All Rights Reserved.
// The term “Broadcom” refers to Broadcom Inc. and/or its subsidiaries.
// SPDX-License-Identifier: Apache-2.0

package disk

Expand All @@ -30,7 +18,6 @@ import (
"github.com/vmware/govmomi/fault"
"github.com/vmware/govmomi/units"
"github.com/vmware/govmomi/vim25/types"
"github.com/vmware/govmomi/vslm"
)

type ls struct {
Expand Down Expand Up @@ -123,23 +110,13 @@ func (r *lsResult) Dump() interface{} {
}

func (cmd *ls) Run(ctx context.Context, f *flag.FlagSet) error {
c, err := cmd.Client()
if err != nil {
return err
}

ds, err := cmd.Datastore()
m, err := NewManagerFromFlag(ctx, cmd.DatastoreFlag)
if err != nil {
return err
}

m := vslm.NewObjectManager(c)
if cmd.r {
task, err := m.ReconcileDatastoreInventory(ctx, ds)
if err != nil {
return err
}
if err = task.Wait(ctx); err != nil {
if err = m.ReconcileDatastoreInventory(ctx); err != nil {
return err
}
}
Expand All @@ -151,7 +128,7 @@ func (cmd *ls) Run(ctx context.Context, f *flag.FlagSet) error {
filterNotFound = true
var oids []types.ID
if cmd.category == "" {
oids, err = m.List(ctx, ds)
oids, err = m.List(ctx)
} else {
oids, err = m.ListAttachedObjects(ctx, cmd.category, cmd.tag)
}
Expand All @@ -165,7 +142,7 @@ func (cmd *ls) Run(ctx context.Context, f *flag.FlagSet) error {
}

for _, id := range ids {
o, err := m.Retrieve(ctx, ds, id)
o, err := m.Retrieve(ctx, id)
if err != nil {
if filterNotFound && fault.Is(err, &types.NotFound{}) {
// The case when an FCD is deleted by something other than DeleteVStorageObject_Task, such as VM destroy
Expand Down
Loading

0 comments on commit 30e8cfd

Please sign in to comment.