Skip to content

Commit

Permalink
vim25: Move internal stuff to internal package
Browse files Browse the repository at this point in the history
  • Loading branch information
Yongkun Anfernee Gui committed Sep 26, 2017
1 parent afc0002 commit e294422
Show file tree
Hide file tree
Showing 5 changed files with 85 additions and 82 deletions.
10 changes: 5 additions & 5 deletions govc/host/esxcli/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import (
"fmt"
"strings"

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

type Command struct {
Expand Down Expand Up @@ -92,7 +92,7 @@ func (c *Command) Moid() string {

// Parse generates a flag.FlagSet based on the given []CommandInfoParam and
// returns arguments for use with methods.ExecuteSoap
func (c *Command) Parse(params []CommandInfoParam) ([]types.ReflectManagedMethodExecuterSoapArgument, error) {
func (c *Command) Parse(params []CommandInfoParam) ([]internal.ReflectManagedMethodExecuterSoapArgument, error) {
flags := flag.NewFlagSet(strings.Join(c.name, " "), flag.ExitOnError)
vals := make([]string, len(params))

Expand All @@ -109,7 +109,7 @@ func (c *Command) Parse(params []CommandInfoParam) ([]types.ReflectManagedMethod
return nil, err
}

args := []types.ReflectManagedMethodExecuterSoapArgument{}
args := []internal.ReflectManagedMethodExecuterSoapArgument{}

for i, p := range params {
if vals[i] == "" {
Expand All @@ -121,8 +121,8 @@ func (c *Command) Parse(params []CommandInfoParam) ([]types.ReflectManagedMethod
return args, nil
}

func (c *Command) Argument(name string, val string) types.ReflectManagedMethodExecuterSoapArgument {
return types.ReflectManagedMethodExecuterSoapArgument{
func (c *Command) Argument(name string, val string) internal.ReflectManagedMethodExecuterSoapArgument {
return internal.ReflectManagedMethodExecuterSoapArgument{
Name: name,
Val: fmt.Sprintf("<%s>%s</%s>", name, val, name),
}
Expand Down
5 changes: 3 additions & 2 deletions govc/host/esxcli/command_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"reflect"
"testing"

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

Expand Down Expand Up @@ -71,7 +72,7 @@ func TestSystemSettingsAdvancedSetCommand(t *testing.T) {
t.Fatal(err)
}

expect := []types.ReflectManagedMethodExecuterSoapArgument{
expect := []internal.ReflectManagedMethodExecuterSoapArgument{
{
DynamicData: types.DynamicData{},
Name: "intvalue",
Expand Down Expand Up @@ -116,7 +117,7 @@ func TestNetworkVmListCommand(t *testing.T) {
t.Fatal(err)
}

expect := []types.ReflectManagedMethodExecuterSoapArgument{}
expect := []internal.ReflectManagedMethodExecuterSoapArgument{}

if !reflect.DeepEqual(args, expect) {
t.Errorf("%s != %s", args, expect)
Expand Down
27 changes: 13 additions & 14 deletions govc/host/esxcli/executor.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,18 +21,17 @@ import (
"errors"
"fmt"

"github.com/vmware/govmomi/internal"
"github.com/vmware/govmomi/object"
"github.com/vmware/govmomi/vim25"
"github.com/vmware/govmomi/vim25/methods"
"github.com/vmware/govmomi/vim25/types"
"github.com/vmware/govmomi/vim25/xml"
)

type Executor struct {
c *vim25.Client
host *object.HostSystem
mme *types.ReflectManagedMethodExecuter
dtm *types.InternalDynamicTypeManager
mme *internal.ReflectManagedMethodExecuter
dtm *internal.InternalDynamicTypeManager
info map[string]*CommandInfo
}

Expand All @@ -45,11 +44,11 @@ func NewExecutor(c *vim25.Client, host *object.HostSystem) (*Executor, error) {
}

{
req := types.RetrieveManagedMethodExecuter{
req := internal.RetrieveManagedMethodExecuterRequest{
This: host.Reference(),
}

res, err := methods.RetrieveManagedMethodExecuter(ctx, c, &req)
res, err := internal.RetrieveManagedMethodExecuter(ctx, c, &req)
if err != nil {
return nil, err
}
Expand All @@ -58,11 +57,11 @@ func NewExecutor(c *vim25.Client, host *object.HostSystem) (*Executor, error) {
}

{
req := types.RetrieveDynamicTypeManager{
req := internal.RetrieveDynamicTypeManagerRequest{
This: host.Reference(),
}

res, err := methods.RetrieveDynamicTypeManager(ctx, c, &req)
res, err := internal.RetrieveDynamicTypeManager(ctx, c, &req)
if err != nil {
return nil, err
}
Expand All @@ -79,10 +78,10 @@ func (e *Executor) CommandInfo(c *Command) (*CommandInfoMethod, error) {
var ok bool

if info, ok = e.info[ns]; !ok {
req := types.ExecuteSoap{
req := internal.ExecuteSoapRequest{
Moid: "ha-dynamic-type-manager-local-cli-cliinfo",
Method: "vim.CLIInfo.FetchCLIInfo",
Argument: []types.ReflectManagedMethodExecuterSoapArgument{
Argument: []internal.ReflectManagedMethodExecuterSoapArgument{
c.Argument("typeName", "vim.EsxCLI."+ns),
},
}
Expand All @@ -105,7 +104,7 @@ func (e *Executor) CommandInfo(c *Command) (*CommandInfoMethod, error) {
return nil, fmt.Errorf("method '%s' not found in name space '%s'", name, c.Namespace())
}

func (e *Executor) NewRequest(args []string) (*types.ExecuteSoap, *CommandInfoMethod, error) {
func (e *Executor) NewRequest(args []string) (*internal.ExecuteSoapRequest, *CommandInfoMethod, error) {
c := NewCommand(args)

info, err := e.CommandInfo(c)
Expand All @@ -118,7 +117,7 @@ func (e *Executor) NewRequest(args []string) (*types.ExecuteSoap, *CommandInfoMe
return nil, nil, err
}

sreq := types.ExecuteSoap{
sreq := internal.ExecuteSoapRequest{
Moid: c.Moid(),
Method: c.Method(),
Argument: sargs,
Expand All @@ -127,12 +126,12 @@ func (e *Executor) NewRequest(args []string) (*types.ExecuteSoap, *CommandInfoMe
return &sreq, info, nil
}

func (e *Executor) Execute(req *types.ExecuteSoap, res interface{}) error {
func (e *Executor) Execute(req *internal.ExecuteSoapRequest, res interface{}) error {
ctx := context.TODO()
req.This = e.mme.ManagedObjectReference
req.Version = "urn:vim25/5.0"

x, err := methods.ExecuteSoap(ctx, e.c, req)
x, err := internal.ExecuteSoap(ctx, e.c, req)
if err != nil {
return err
}
Expand Down
33 changes: 16 additions & 17 deletions vim25/methods/internal.go → internal/methods.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,24 +14,23 @@ See the License for the specific language governing permissions and
limitations under the License.
*/

package methods
package internal

import (
"context"

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

type RetrieveDynamicTypeManagerBody struct {
Req *types.RetrieveDynamicTypeManager `xml:"urn:vim25 RetrieveDynamicTypeManager"`
Res *types.RetrieveDynamicTypeManagerResponse `xml:"urn:vim25 RetrieveDynamicTypeManagerResponse"`
Req *RetrieveDynamicTypeManagerRequest `xml:"urn:vim25 RetrieveDynamicTypeManager"`
Res *RetrieveDynamicTypeManagerResponse `xml:"urn:vim25 RetrieveDynamicTypeManagerResponse"`
Fault_ *soap.Fault
}

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

func RetrieveDynamicTypeManager(ctx context.Context, r soap.RoundTripper, req *types.RetrieveDynamicTypeManager) (*types.RetrieveDynamicTypeManagerResponse, error) {
func RetrieveDynamicTypeManager(ctx context.Context, r soap.RoundTripper, req *RetrieveDynamicTypeManagerRequest) (*RetrieveDynamicTypeManagerResponse, error) {
var reqBody, resBody RetrieveDynamicTypeManagerBody

reqBody.Req = req
Expand All @@ -44,14 +43,14 @@ func RetrieveDynamicTypeManager(ctx context.Context, r soap.RoundTripper, req *t
}

type RetrieveManagedMethodExecuterBody struct {
Req *types.RetrieveManagedMethodExecuter `xml:"urn:vim25 RetrieveManagedMethodExecuter"`
Res *types.RetrieveManagedMethodExecuterResponse `xml:"urn:vim25 RetrieveManagedMethodExecuterResponse"`
Req *RetrieveManagedMethodExecuterRequest `xml:"urn:vim25 RetrieveManagedMethodExecuter"`
Res *RetrieveManagedMethodExecuterResponse `xml:"urn:vim25 RetrieveManagedMethodExecuterResponse"`
Fault_ *soap.Fault
}

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

func RetrieveManagedMethodExecuter(ctx context.Context, r soap.RoundTripper, req *types.RetrieveManagedMethodExecuter) (*types.RetrieveManagedMethodExecuterResponse, error) {
func RetrieveManagedMethodExecuter(ctx context.Context, r soap.RoundTripper, req *RetrieveManagedMethodExecuterRequest) (*RetrieveManagedMethodExecuterResponse, error) {
var reqBody, resBody RetrieveManagedMethodExecuterBody

reqBody.Req = req
Expand All @@ -64,14 +63,14 @@ func RetrieveManagedMethodExecuter(ctx context.Context, r soap.RoundTripper, req
}

type DynamicTypeMgrQueryMoInstancesBody struct {
Req *types.DynamicTypeMgrQueryMoInstances `xml:"urn:vim25 DynamicTypeMgrQueryMoInstances"`
Res *types.DynamicTypeMgrQueryMoInstancesResponse `xml:"urn:vim25 DynamicTypeMgrQueryMoInstancesResponse"`
Req *DynamicTypeMgrQueryMoInstancesRequest `xml:"urn:vim25 DynamicTypeMgrQueryMoInstances"`
Res *DynamicTypeMgrQueryMoInstancesResponse `xml:"urn:vim25 DynamicTypeMgrQueryMoInstancesResponse"`
Fault_ *soap.Fault
}

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

func DynamicTypeMgrQueryMoInstances(ctx context.Context, r soap.RoundTripper, req *types.DynamicTypeMgrQueryMoInstances) (*types.DynamicTypeMgrQueryMoInstancesResponse, error) {
func DynamicTypeMgrQueryMoInstances(ctx context.Context, r soap.RoundTripper, req *DynamicTypeMgrQueryMoInstancesRequest) (*DynamicTypeMgrQueryMoInstancesResponse, error) {
var reqBody, resBody DynamicTypeMgrQueryMoInstancesBody

reqBody.Req = req
Expand All @@ -84,14 +83,14 @@ func DynamicTypeMgrQueryMoInstances(ctx context.Context, r soap.RoundTripper, re
}

type DynamicTypeMgrQueryTypeInfoBody struct {
Req *types.DynamicTypeMgrQueryTypeInfo `xml:"urn:vim25 DynamicTypeMgrQueryTypeInfo"`
Res *types.DynamicTypeMgrQueryTypeInfoResponse `xml:"urn:vim25 DynamicTypeMgrQueryTypeInfoResponse"`
Req *DynamicTypeMgrQueryTypeInfoRequest `xml:"urn:vim25 DynamicTypeMgrQueryTypeInfo"`
Res *DynamicTypeMgrQueryTypeInfoResponse `xml:"urn:vim25 DynamicTypeMgrQueryTypeInfoResponse"`
Fault_ *soap.Fault
}

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

func DynamicTypeMgrQueryTypeInfo(ctx context.Context, r soap.RoundTripper, req *types.DynamicTypeMgrQueryTypeInfo) (*types.DynamicTypeMgrQueryTypeInfoResponse, error) {
func DynamicTypeMgrQueryTypeInfo(ctx context.Context, r soap.RoundTripper, req *DynamicTypeMgrQueryTypeInfoRequest) (*DynamicTypeMgrQueryTypeInfoResponse, error) {
var reqBody, resBody DynamicTypeMgrQueryTypeInfoBody

reqBody.Req = req
Expand All @@ -104,14 +103,14 @@ func DynamicTypeMgrQueryTypeInfo(ctx context.Context, r soap.RoundTripper, req *
}

type ExecuteSoapBody struct {
Req *types.ExecuteSoap `xml:"urn:vim25 ExecuteSoap"`
Res *types.ExecuteSoapResponse `xml:"urn:vim25 ExecuteSoapResponse"`
Req *ExecuteSoapRequest `xml:"urn:vim25 ExecuteSoap"`
Res *ExecuteSoapResponse `xml:"urn:vim25 ExecuteSoapResponse"`
Fault_ *soap.Fault
}

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

func ExecuteSoap(ctx context.Context, r soap.RoundTripper, req *types.ExecuteSoap) (*types.ExecuteSoapResponse, error) {
func ExecuteSoap(ctx context.Context, r soap.RoundTripper, req *ExecuteSoapRequest) (*ExecuteSoapResponse, error) {
var reqBody, resBody ExecuteSoapBody

reqBody.Req = req
Expand Down
Loading

0 comments on commit e294422

Please sign in to comment.