2
Copyright (c) 2014 VMware, Inc. All Rights Reserved.
4
Licensed under the Apache License, Version 2.0 (the "License");
5
you may not use this file except in compliance with the License.
6
You may obtain a copy of the License at
8
http://www.apache.org/licenses/LICENSE-2.0
10
Unless required by applicable law or agreed to in writing, software
11
distributed under the License is distributed on an "AS IS" BASIS,
12
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
See the License for the specific language governing permissions and
14
limitations under the License.
18
This package is the root package of the govmomi library.
20
The library is structured as follows:
24
The minimal usable functionality is available through the vim25 package.
25
It contains subpackages that contain generated types, managed objects, and all
26
available methods. The vim25 package is entirely independent of the other
27
packages in the govmomi tree -- it has no dependencies on its peers.
29
The vim25 package itself contains a client structure that is
30
passed around throughout the entire library. It abstracts a session and its
31
immutable state. See the vim25 package for more information.
35
The session package contains an abstraction for the session manager that allows
36
a user to login and logout. It also provides access to the current session
37
(i.e. to determine if the user is in fact logged in)
41
The object package contains wrappers for a selection of managed objects. The
42
constructors of these objects all take a *vim25.Client, which they pass along
43
to derived objects, if applicable.
47
The govc package contains the govc CLI. The code in this tree is not intended
48
to be used as a library. Any functionality that govc contains that _could_ be
49
used as a library function but isn't, _should_ live in a root level package.
53
Other packages, such as "event", "guest", or "license", provide wrappers for
54
the respective subsystems. They are typically not needed in normal workflows so
55
are kept outside the object package.
62
"github.com/juju/govmomi/property"
63
"github.com/juju/govmomi/session"
64
"github.com/juju/govmomi/vim25"
65
"github.com/juju/govmomi/vim25/soap"
66
"github.com/juju/govmomi/vim25/types"
67
"golang.org/x/net/context"
73
SessionManager *session.Manager
76
// NewClient creates a new client from a URL. The client authenticates with the
77
// server before returning if the URL contains user information.
78
func NewClient(ctx context.Context, u *url.URL, insecure bool) (*Client, error) {
79
soapClient := soap.NewClient(u, insecure)
80
vimClient, err := vim25.NewClient(ctx, soapClient)
87
SessionManager: session.NewManager(vimClient),
90
// Only login if the URL contains user information.
92
err = c.Login(ctx, u.User)
101
// Login dispatches to the SessionManager.
102
func (c *Client) Login(ctx context.Context, u *url.Userinfo) error {
103
return c.SessionManager.Login(ctx, u)
106
// Logout dispatches to the SessionManager.
107
func (c *Client) Logout(ctx context.Context) error {
108
// Close any idle connections after logging out.
109
defer c.Client.CloseIdleConnections()
110
return c.SessionManager.Logout(ctx)
113
// PropertyCollector returns the session's default property collector.
114
func (c *Client) PropertyCollector() *property.Collector {
115
return property.DefaultCollector(c.Client)
118
// RetrieveOne dispatches to the Retrieve function on the default property collector.
119
func (c *Client) RetrieveOne(ctx context.Context, obj types.ManagedObjectReference, p []string, dst interface{}) error {
120
return c.PropertyCollector().RetrieveOne(ctx, obj, p, dst)
123
// Retrieve dispatches to the Retrieve function on the default property collector.
124
func (c *Client) Retrieve(ctx context.Context, objs []types.ManagedObjectReference, p []string, dst interface{}) error {
125
return c.PropertyCollector().Retrieve(ctx, objs, p, dst)
128
// Wait dispatches to property.Wait.
129
func (c *Client) Wait(ctx context.Context, obj types.ManagedObjectReference, ps []string, f func([]types.PropertyChange) bool) error {
130
return property.Wait(ctx, c.PropertyCollector(), obj, ps, f)