@@ -2,30 +2,35 @@ package instance
2
2
3
3
import (
4
4
"encoding/json"
5
+
6
+ "github.com/docker/infrakit/pkg/plugin"
5
7
rpc_client "github.com/docker/infrakit/pkg/rpc/client"
6
8
"github.com/docker/infrakit/pkg/spi/instance"
7
9
)
8
10
9
11
// NewClient returns a plugin interface implementation connected to a plugin
10
- func NewClient (socketPath string ) instance.Plugin {
11
- return & client {client : rpc_client .New (socketPath , instance .InterfaceSpec )}
12
+ func NewClient (name plugin. Name , socketPath string ) instance.Plugin {
13
+ return & client {name : name , client : rpc_client .New (socketPath , instance .InterfaceSpec )}
12
14
}
13
15
14
16
type client struct {
17
+ name plugin.Name
15
18
client rpc_client.Client
16
19
}
17
20
18
21
// Validate performs local validation on a provision request.
19
22
func (c client ) Validate (properties json.RawMessage ) error {
20
- req := ValidateRequest {Properties : & properties }
23
+ _ , instanceType := c .name .GetLookupAndType ()
24
+ req := ValidateRequest {Properties : & properties , Type : instanceType }
21
25
resp := ValidateResponse {}
22
26
23
27
return c .client .Call ("Instance.Validate" , req , & resp )
24
28
}
25
29
26
30
// Provision creates a new instance based on the spec.
27
31
func (c client ) Provision (spec instance.Spec ) (* instance.ID , error ) {
28
- req := ProvisionRequest {Spec : spec }
32
+ _ , instanceType := c .name .GetLookupAndType ()
33
+ req := ProvisionRequest {Spec : spec , Type : instanceType }
29
34
resp := ProvisionResponse {}
30
35
31
36
if err := c .client .Call ("Instance.Provision" , req , & resp ); err != nil {
@@ -37,15 +42,17 @@ func (c client) Provision(spec instance.Spec) (*instance.ID, error) {
37
42
38
43
// Destroy terminates an existing instance.
39
44
func (c client ) Destroy (instance instance.ID ) error {
40
- req := DestroyRequest {Instance : instance }
45
+ _ , instanceType := c .name .GetLookupAndType ()
46
+ req := DestroyRequest {Instance : instance , Type : instanceType }
41
47
resp := DestroyResponse {}
42
48
43
49
return c .client .Call ("Instance.Destroy" , req , & resp )
44
50
}
45
51
46
52
// DescribeInstances returns descriptions of all instances matching all of the provided tags.
47
53
func (c client ) DescribeInstances (tags map [string ]string ) ([]instance.Description , error ) {
48
- req := DescribeInstancesRequest {Tags : tags }
54
+ _ , instanceType := c .name .GetLookupAndType ()
55
+ req := DescribeInstancesRequest {Tags : tags , Type : instanceType }
49
56
resp := DescribeInstancesResponse {}
50
57
51
58
err := c .client .Call ("Instance.DescribeInstances" , req , & resp )
0 commit comments