diff --git a/govc/test/datastore.bats b/govc/test/datastore.bats index a7d1bbaa1..352e1072b 100755 --- a/govc/test/datastore.bats +++ b/govc/test/datastore.bats @@ -233,7 +233,7 @@ upload_file() { } @test "datastore.disk" { - esx_env + vcsim_env id=$(new_id) vmdk="$id/$id.vmdk" @@ -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 diff --git a/internal/methods.go b/internal/methods.go index 95ccee8d2..b59770c0e 100644 --- a/internal/methods.go +++ b/internal/methods.go @@ -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 +} diff --git a/internal/types.go b/internal/types.go index 61541efa5..cada7a904 100644 --- a/internal/types.go +++ b/internal/types.go @@ -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"` } diff --git a/object/virtual_disk_manager_internal.go b/object/virtual_disk_manager_internal.go index faa9ecad5..92967788e 100644 --- a/object/virtual_disk_manager_internal.go +++ b/object/virtual_disk_manager_internal.go @@ -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, @@ -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 } @@ -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 { diff --git a/simulator/virtual_disk_manager.go b/simulator/virtual_disk_manager.go index 3843bdf8e..8cc565b3a 100644 --- a/simulator/virtual_disk_manager.go +++ b/simulator/virtual_disk_manager.go @@ -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" @@ -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), + }, + } +}