This repository was archived by the owner on Jan 21, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 269
Expand file tree
/
Copy pathopenstack.go
More file actions
110 lines (88 loc) · 3.04 KB
/
openstack.go
File metadata and controls
110 lines (88 loc) · 3.04 KB
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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
package oneview
import (
"strings"
"github.com/docker/infrakit/pkg/launch/inproc"
logutil "github.com/docker/infrakit/pkg/log"
"github.com/docker/infrakit/pkg/plugin"
"github.com/docker/infrakit/pkg/provider/openstack"
"github.com/docker/infrakit/pkg/run"
"github.com/docker/infrakit/pkg/run/local"
"github.com/docker/infrakit/pkg/run/scope"
"github.com/docker/infrakit/pkg/spi/instance"
"github.com/docker/infrakit/pkg/types"
)
var log = logutil.New("module", "cli/x")
const (
// Kind is the canonical name of the plugin for starting up, etc.
Kind = "openstack"
// EnvNamespaceTags is the env to set for namespace tags. It's k=v,...
EnvNamespaceTags = "INFRAKIT_OPENSTACK_NAMESPACE_TAGS"
// EnvOStackURL is the env for setting the OpenStack auth URL to connect to
EnvOStackURL = "INFRAKIT_OPENSTACK_AUTHURL"
// EnvOStackUser is the Open Stack Username
EnvOStackUser = "INFRAKIT_OPENSTACK_USER"
// EnvOStackPass is the Open Stack Password
EnvOStackPass = "INFRAKIT_OPENSTACK_PASS"
// EnvOStackDomain is the Open Stack API Domain
EnvOStackDomain = "INFRAKIT_OPENSTACK_DOMAIN"
// EnvOStackProject is the Open Stack Project
EnvOStackProject = "INFRAKIT_OPENSTACK_PROJECT"
)
func init() {
inproc.Register(Kind, Run, DefaultOptions)
}
// Options capture the options for starting up the plugin.
type Options struct {
// Namespace is a set of kv pairs for tags that namespaces the resource instances
// TODO - this is currently implemented in AWS and other cloud providers but not
// in Open Stack
Namespace map[string]string
// OneViews is a list of OneView Servers - each corresponds to config of a plugin instance
OpenStacks []openstack.Options
}
func defaultNamespace() map[string]string {
t := map[string]string{}
list := local.Getenv(EnvNamespaceTags, "")
for _, v := range strings.Split(list, ",") {
p := strings.Split(v, "=")
if len(p) == 2 {
t[p[0]] = p[1]
}
}
return t
}
func defaultOSOptions() openstack.Options {
return openstack.Options{
OStackAuthURL: local.Getenv(EnvOStackURL, ""),
OStackUserName: local.Getenv(EnvOStackUser, ""),
OStackPassword: local.Getenv(EnvOStackPass, ""),
OStackProject: local.Getenv(EnvOStackProject, ""),
OStackUserDomain: local.Getenv(EnvOStackDomain, ""),
}
}
// DefaultOptions return an Options with default values filled in.
var DefaultOptions = Options{
Namespace: defaultNamespace(),
OpenStacks: []openstack.Options{
defaultOSOptions(),
},
}
// Run runs the plugin, blocking the current thread. Error is returned immediately
// if the plugin cannot be started.
func Run(scope scope.Scope, name plugin.Name,
config *types.Any) (transport plugin.Transport, impls map[run.PluginCode]interface{}, onStop func(), err error) {
options := DefaultOptions
err = config.Decode(&options)
if err != nil {
return
}
bareMetal := map[string]instance.Plugin{}
for _, os := range options.OpenStacks {
bareMetal[os.OStackAuthURL] = openstack.NewOpenStackInstancePlugin(os)
}
transport.Name = name
impls = map[run.PluginCode]interface{}{
run.Instance: bareMetal,
}
return
}