config.go 1.07 KB
Newer Older
Yann KAISER's avatar
Yann KAISER committed
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
46
47
48
49
50
51
52
53
54
55
56
package one

import (
	"opennebula-go/client"
	"opennebula-go/image"
	"opennebula-go/network"
	"opennebula-go/oneflow"
	"opennebula-go/system"
	"opennebula-go/vm"
)

/*
Config struct
*/
type Config struct {
	endpoint    string
	username    string
	password    string
	oneflowHost string
}

/*
Client struct
*/
type Client struct {
	Session        *client.Client
	VMSession      *vm.Client
	ImageSession   *image.Client
	ServiceSession *oneflow.Client
	NetworkSession *network.Client
	SystemSession  *system.Client
}

/*
Client method that creates a new client
*/
func (c *Config) Client() (interface{}, error) {
	var oclient Client

	nc, err := client.NewClient(c.endpoint, c.username, c.password)
	if err != nil {
		return nil, err
	}

	oclient.Session = nc
	oclient.VMSession = vm.Session(nc)
	oclient.ImageSession = image.Session(nc)
	oclient.NetworkSession = network.Session(nc)
	oclient.SystemSession = system.Session(nc)
	oclient.ServiceSession = oneflow.Session(&client.OneflowClient{
		Username: c.username,
		Password: c.password,
		Host:     c.oneflowHost,
	})
	return &oclient, nil
}