/
session.go
45 lines (38 loc) · 1.3 KB
/
session.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
// Copyright 2017 Canonical Ltd.
// Licensed under the AGPLv3, see LICENCE file for details.
package vsphere
import (
"golang.org/x/net/context"
"github.com/juju/juju/core/network"
callcontext "github.com/juju/juju/environs/context"
)
// sessionEnviron implements common.ZonedEnviron. An instance of
// sessionEnviron is scoped to the context of a single exported
// method call.
//
// NOTE(axw) this type's methods are not safe for concurrent use.
// It is the responsibility of the environ type to ensure that
// there are no concurrent calls to sessionEnviron's methods.
type sessionEnviron struct {
// environ is the environ that created this sessionEnviron.
// Take care to synchronise access to environ's attributes
// and methods as necessary.
*environ
ctx context.Context
client Client
// zones caches the results of AvailabilityZones to reduce
// the number of API calls required by StartInstance.
// We only cache per session, so there is no issue of
// staleness.
zones network.AvailabilityZones
}
func (env *environ) withSession(callCtx callcontext.ProviderCallContext, f func(*sessionEnviron) error) error {
ctx := context.Background()
return env.withClient(ctx, callCtx, func(client Client) error {
return f(&sessionEnviron{
environ: env,
ctx: ctx,
client: client,
})
})
}