Skip to content

Commit

Permalink
vcsim: add VirtualDiskManager.QueryVirtualDiskInfo
Browse files Browse the repository at this point in the history
Fixes vmware#3000
Fixes vmware#2555

Signed-off-by: Doug MacEachern <dougm@broadcom.com>
  • Loading branch information
dougm committed Dec 13, 2024
1 parent b1027ba commit f398e78
Show file tree
Hide file tree
Showing 5 changed files with 89 additions and 59 deletions.
8 changes: 4 additions & 4 deletions govc/test/datastore.bats
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ upload_file() {
}

@test "datastore.disk" {
esx_env
vcsim_env

id=$(new_id)
vmdk="$id/$id.vmdk"
Expand Down Expand Up @@ -275,9 +275,9 @@ upload_file() {
run govc datastore.disk.info -json "$vmdk"
assert_success

# should fail due to: ddb.deletable=false
run govc datastore.rm "$vmdk"
assert_failure
# TODO: # should fail due to: ddb.deletable=false
# run govc datastore.rm "$vmdk"
# assert_failure

run govc datastore.rm -f "$vmdk"
assert_success
Expand Down
25 changes: 25 additions & 0 deletions internal/methods.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,3 +121,28 @@ func ExecuteSoap(ctx context.Context, r soap.RoundTripper, req *ExecuteSoapReque

return resBody.Res, nil
}

type QueryVirtualDiskInfoTaskBody struct {
Req *QueryVirtualDiskInfoTaskRequest `xml:"urn:internalvim25 QueryVirtualDiskInfo_Task,omitempty"`
Res *QueryVirtualDiskInfo_TaskResponse `xml:"urn:vim25 QueryVirtualDiskInfo_TaskResponse,omitempty"`
InternalRes *QueryVirtualDiskInfo_TaskResponse `xml:"urn:internalvim25 QueryVirtualDiskInfo_TaskResponse,omitempty"`
Fault_ *soap.Fault `xml:"http://schemas.xmlsoap.org/soap/envelope/ Fault,omitempty"`
}

func (b *QueryVirtualDiskInfoTaskBody) Fault() *soap.Fault { return b.Fault_ }

func QueryVirtualDiskInfoTask(ctx context.Context, r soap.RoundTripper, req *QueryVirtualDiskInfoTaskRequest) (*QueryVirtualDiskInfo_TaskResponse, error) {
var reqBody, resBody QueryVirtualDiskInfoTaskBody

reqBody.Req = req

if err := r.RoundTrip(ctx, &reqBody, &resBody); err != nil {
return nil, err
}

if resBody.Res != nil {
return resBody.Res, nil
}

return resBody.InternalRes, nil
}
27 changes: 27 additions & 0 deletions internal/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -293,4 +293,31 @@ type ExecuteSoapResponse struct {

func init() {
types.Add("ExecuteSoap", reflect.TypeOf((*ExecuteSoapRequest)(nil)).Elem())

types.Add("ArrayOfVirtualDiskInfo", reflect.TypeOf((*ArrayOfVirtualDiskInfo)(nil)).Elem())

types.Add("VirtualDiskInfo", reflect.TypeOf((*VirtualDiskInfo)(nil)).Elem())

types.Add("QueryVirtualDiskInfo_Task", reflect.TypeOf((*QueryVirtualDiskInfoTaskRequest)(nil)).Elem())
}

type VirtualDiskInfo struct {
Name string `xml:"unit>name"`
DiskType string `xml:"diskType"`
Parent string `xml:"parent,omitempty"`
}

type ArrayOfVirtualDiskInfo struct {
VirtualDiskInfo []VirtualDiskInfo `xml:"VirtualDiskInfo,omitempty"`
}

type QueryVirtualDiskInfoTaskRequest struct {
This types.ManagedObjectReference `xml:"_this"`
Name string `xml:"name"`
Datacenter *types.ManagedObjectReference `xml:"datacenter,omitempty"`
IncludeParents bool `xml:"includeParents"`
}

type QueryVirtualDiskInfo_TaskResponse struct {
Returnval types.ManagedObjectReference `xml:"returnval"`
}
60 changes: 5 additions & 55 deletions object/virtual_disk_manager_internal.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,66 +18,16 @@ package object

import (
"context"
"reflect"

"github.com/vmware/govmomi/internal"
"github.com/vmware/govmomi/vim25/soap"
"github.com/vmware/govmomi/vim25/types"
)

func init() {
types.Add("ArrayOfVirtualDiskInfo", reflect.TypeOf((*arrayOfVirtualDiskInfo)(nil)).Elem())

types.Add("VirtualDiskInfo", reflect.TypeOf((*VirtualDiskInfo)(nil)).Elem())
}

type arrayOfVirtualDiskInfo struct {
VirtualDiskInfo []VirtualDiskInfo `xml:"VirtualDiskInfo,omitempty"`
}

type queryVirtualDiskInfoTaskRequest struct {
This types.ManagedObjectReference `xml:"_this"`
Name string `xml:"name"`
Datacenter *types.ManagedObjectReference `xml:"datacenter,omitempty"`
IncludeParents bool `xml:"includeParents"`
}

type queryVirtualDiskInfoTaskResponse struct {
Returnval types.ManagedObjectReference `xml:"returnval"`
}

type queryVirtualDiskInfoTaskBody struct {
Req *queryVirtualDiskInfoTaskRequest `xml:"urn:internalvim25 QueryVirtualDiskInfo_Task,omitempty"`
Res *queryVirtualDiskInfoTaskResponse `xml:"urn:vim25 QueryVirtualDiskInfo_TaskResponse,omitempty"`
InternalRes *queryVirtualDiskInfoTaskResponse `xml:"urn:internalvim25 QueryVirtualDiskInfo_TaskResponse,omitempty"`
Err *soap.Fault `xml:"http://schemas.xmlsoap.org/soap/envelope/ Fault,omitempty"`
}

func (b *queryVirtualDiskInfoTaskBody) Fault() *soap.Fault { return b.Err }

func queryVirtualDiskInfoTask(ctx context.Context, r soap.RoundTripper, req *queryVirtualDiskInfoTaskRequest) (*queryVirtualDiskInfoTaskResponse, error) {
var reqBody, resBody queryVirtualDiskInfoTaskBody

reqBody.Req = req

if err := r.RoundTrip(ctx, &reqBody, &resBody); err != nil {
return nil, err
}

if resBody.Res != nil {
return resBody.Res, nil
}

return resBody.InternalRes, nil
}

type VirtualDiskInfo struct {
Name string `xml:"unit>name"`
DiskType string `xml:"diskType"`
Parent string `xml:"parent,omitempty"`
}
type VirtualDiskInfo = internal.VirtualDiskInfo

func (m VirtualDiskManager) QueryVirtualDiskInfo(ctx context.Context, name string, dc *Datacenter, includeParents bool) ([]VirtualDiskInfo, error) {
req := queryVirtualDiskInfoTaskRequest{
req := internal.QueryVirtualDiskInfoTaskRequest{
This: m.Reference(),
Name: name,
IncludeParents: includeParents,
Expand All @@ -88,7 +38,7 @@ func (m VirtualDiskManager) QueryVirtualDiskInfo(ctx context.Context, name strin
req.Datacenter = &ref
}

res, err := queryVirtualDiskInfoTask(ctx, m.Client(), &req)
res, err := internal.QueryVirtualDiskInfoTask(ctx, m.Client(), &req)
if err != nil {
return nil, err
}
Expand All @@ -98,7 +48,7 @@ func (m VirtualDiskManager) QueryVirtualDiskInfo(ctx context.Context, name strin
return nil, err
}

return info.Result.(arrayOfVirtualDiskInfo).VirtualDiskInfo, nil
return info.Result.(internal.ArrayOfVirtualDiskInfo).VirtualDiskInfo, nil
}

type createChildDiskTaskRequest struct {
Expand Down
28 changes: 28 additions & 0 deletions simulator/virtual_disk_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (

"github.com/google/uuid"

"github.com/vmware/govmomi/internal"
"github.com/vmware/govmomi/vim25/methods"
"github.com/vmware/govmomi/vim25/mo"
"github.com/vmware/govmomi/vim25/soap"
Expand Down Expand Up @@ -289,3 +290,30 @@ func (m *VirtualDiskManager) SetVirtualDiskUuid(_ *Context, req *types.SetVirtua
body.Res = new(types.SetVirtualDiskUuidResponse)
return body
}

func (m *VirtualDiskManager) QueryVirtualDiskInfoTask(ctx *Context, req *internal.QueryVirtualDiskInfoTaskRequest) soap.HasFault {
task := CreateTask(m, "queryVirtualDiskInfo", func(*Task) (types.AnyType, types.BaseMethodFault) {
var res []internal.VirtualDiskInfo

fm := ctx.Map.FileManager()

_, fault := fm.resolve(req.Datacenter, req.Name)
if fault != nil {
return nil, fault
}

res = append(res, internal.VirtualDiskInfo{Name: req.Name, DiskType: "thin"})

if req.IncludeParents {
// TODO
}

return res, nil
})

return &internal.QueryVirtualDiskInfoTaskBody{
Res: &internal.QueryVirtualDiskInfo_TaskResponse{
Returnval: task.Run(ctx),
},
}
}

0 comments on commit f398e78

Please sign in to comment.