package vim25
import "github.com/vmware/govmomi/vim25"
Package vim25 provides a minimal client implementation to use with other packages in the vim25 tree. The code in this package intentionally does not take any dependendies outside the vim25 tree.
The client implementation in this package embeds the soap.Client structure. Additionally, it stores the value of the session's ServiceContent object. This object stores references to a variety of subsystems, such as the root property collector, the session manager, and the search index. The client is fully functional after serialization and deserialization, without the need for additional requests for initialization.
Index ¶
- Constants
- Variables
- func IsTemporaryNetworkError(err error) bool
- func Retry(roundTripper soap.RoundTripper, fn RetryFunc, retryAttempts ...int) soap.RoundTripper
- func RetryTemporaryNetworkError(err error) (bool, time.Duration)
- type Client
- func NewClient(ctx context.Context, rt soap.RoundTripper) (*Client, error)
- func (c *Client) IsVC() bool
- func (c *Client) MarshalJSON() ([]byte, error)
- func (c *Client) Path() string
- func (c *Client) RoundTrip(ctx context.Context, req, res soap.HasFault) error
- func (c *Client) UnmarshalJSON(b []byte) error
- func (c *Client) Valid() bool
- type RetryFunc
Examples ¶
Constants ¶
const ( Namespace = "vim25" Version = "9.0.0.0" Path = "/sdk" )
Variables ¶
var ( ServiceInstance = types.ManagedObjectReference{ Type: "ServiceInstance", Value: "ServiceInstance", } )
Functions ¶
func IsTemporaryNetworkError ¶
IsTemporaryNetworkError returns false unless the error implements a Temporary() bool method such as url.Error and net.Error. Otherwise, returns the value of the Temporary() method.
func Retry ¶
func Retry(roundTripper soap.RoundTripper, fn RetryFunc, retryAttempts ...int) soap.RoundTripper
Retry wraps the specified soap.RoundTripper and invokes the specified RetryFunc. The RetryFunc returns whether or not to retry the call, and if so, how long to wait before retrying. If the result of this function is to not retry, the original error is returned from the RoundTrip function. The soap.RoundTripper will return the original error if retryAttempts is specified and reached.
func RetryTemporaryNetworkError ¶
RetryTemporaryNetworkError returns a RetryFunc that returns IsTemporaryNetworkError(err)
Types ¶
type Client ¶
type Client struct { *soap.Client ServiceContent types.ServiceContent // RoundTripper is a separate field such that the client's implementation of // the RoundTripper interface can be wrapped by separate implementations for // extra functionality (for example, reauthentication on session timeout). RoundTripper soap.RoundTripper }
Client is a tiny wrapper around the vim25/soap Client that stores session specific state (i.e. state that only needs to be retrieved once after the client has been created). This means the client can be reused after serialization without performing additional requests for initialization.
func NewClient ¶
NewClient creates and returns a new client with the ServiceContent field filled in.
func (*Client) IsVC ¶
IsVC returns true if we are connected to a vCenter
func (*Client) MarshalJSON ¶
func (*Client) Path ¶
Path returns vim25.Path (see cache.Client)
func (*Client) RoundTrip ¶
RoundTrip dispatches to the RoundTripper field.
func (*Client) UnmarshalJSON ¶
func (*Client) Valid ¶
Valid returns whether or not the client is valid and ready for use. This should be called after unmarshalling the client.
type RetryFunc ¶
func TemporaryNetworkError ¶
TemporaryNetworkError is deprecated. Use Retry() with RetryTemporaryNetworkError and retryAttempts instead.
Code:play
Output:Example¶
package main
import (
"context"
"fmt"
"net/http"
"time"
"github.com/vmware/govmomi/find"
"github.com/vmware/govmomi/simulator"
"github.com/vmware/govmomi/vim25"
)
func main() {
simulator.Run(func(ctx context.Context, c *vim25.Client) error {
// Configure retry handler
delay := time.Millisecond * 100
retry := func(err error) (bool, time.Duration) {
return vim25.IsTemporaryNetworkError(err), delay
}
c.RoundTripper = vim25.Retry(c.Client, retry, 3)
vm, err := find.NewFinder(c).VirtualMachine(ctx, "DC0_H0_VM0")
if err != nil {
return err
}
// Tell vcsim to respond with 502 on the 1st request
simulator.StatusSDK = http.StatusBadGateway
state, err := vm.PowerState(ctx)
if err != nil {
return err
}
fmt.Println(state)
return nil
})
}
poweredOn
Source Files ¶
Directories ¶
Path | Synopsis |
---|---|
vim25/debug | |
vim25/json | Package json implements encoding and decoding of JSON as defined in RFC 7159. |
vim25/methods | |
vim25/mo | |
vim25/progress | |
vim25/soap | |
vim25/types | |
vim25/xml | Package xml implements a simple XML 1.0 parser that understands XML name spaces. |
- Version
- v0.48.1 (latest)
- Published
- Feb 11, 2025
- Platform
- linux/amd64
- Imports
- 7 packages
- Last checked
- 2 months ago –
Tools for package owners.