coral_core 0.2.26 → 0.2.30
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/Gemfile +7 -2
- data/Gemfile.lock +84 -15
- data/VERSION +1 -1
- data/coral_core.gemspec +51 -16
- data/lib/{coral_core/command.rb → coral/command/shell.rb} +12 -116
- data/lib/coral/machine/fog.rb +215 -0
- data/lib/coral/network/default.rb +26 -0
- data/lib/coral/node/rackspace.rb +23 -0
- data/lib/coral_core.rb +249 -134
- data/lib/coral_core/config.rb +233 -275
- data/lib/coral_core/config/collection.rb +57 -0
- data/lib/coral_core/config/options.rb +70 -0
- data/lib/coral_core/config/project.rb +225 -0
- data/lib/coral_core/core.rb +19 -173
- data/lib/coral_core/event/puppet_event.rb +98 -0
- data/lib/coral_core/mixin/config_collection.rb +52 -0
- data/lib/coral_core/mixin/config_ops.rb +51 -0
- data/lib/coral_core/mixin/config_options.rb +38 -0
- data/lib/coral_core/mixin/lookup.rb +211 -0
- data/lib/coral_core/mixin/macro/object_interface.rb +292 -0
- data/lib/coral_core/mixin/macro/plugin_interface.rb +277 -0
- data/lib/coral_core/mixin/settings.rb +46 -0
- data/lib/coral_core/mixin/sub_config.rb +208 -0
- data/lib/coral_core/mod/hash.rb +29 -0
- data/lib/{hiera_backend.rb → coral_core/mod/hiera_backend.rb} +0 -0
- data/lib/coral_core/plugin.rb +261 -0
- data/lib/coral_core/plugin/command.rb +95 -0
- data/lib/coral_core/plugin/machine.rb +152 -0
- data/lib/coral_core/plugin/network.rb +24 -0
- data/lib/coral_core/plugin/node.rb +184 -0
- data/lib/coral_core/plugin_base.rb +147 -0
- data/lib/coral_core/repository.rb +471 -82
- data/lib/coral_core/util/cli.rb +293 -0
- data/lib/coral_core/util/data.rb +178 -8
- data/lib/coral_core/util/disk.rb +13 -0
- data/lib/coral_core/util/git.rb +35 -10
- data/lib/coral_core/{interface.rb → util/interface.rb} +31 -21
- data/lib/coral_core/util/process.rb +43 -0
- data/locales/en.yml +8 -0
- data/spec/coral_core/interface_spec.rb +45 -45
- metadata +109 -34
- data/.gitmodules +0 -12
- data/lib/coral_core/memory.rb +0 -226
- data/lib/coral_core/util/git/base.rb +0 -65
- data/lib/coral_core/util/git/lib.rb +0 -89
- data/lib/coral_core/util/git/remote.rb +0 -12
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
|
|
2
|
+
module Coral
|
|
3
|
+
module Plugin
|
|
4
|
+
class Command < Base
|
|
5
|
+
|
|
6
|
+
#-----------------------------------------------------------------------------
|
|
7
|
+
# Command plugin interface
|
|
8
|
+
|
|
9
|
+
def to_s
|
|
10
|
+
return build(export)
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
#-----------------------------------------------------------------------------
|
|
14
|
+
# Property accessor / modifiers
|
|
15
|
+
|
|
16
|
+
def command(default = '')
|
|
17
|
+
return string(get(:command, default))
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
#---
|
|
21
|
+
|
|
22
|
+
def command=command
|
|
23
|
+
set(:command, string(command))
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
#---
|
|
27
|
+
|
|
28
|
+
def args(default = [])
|
|
29
|
+
return array(get(:args, default))
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
#---
|
|
33
|
+
|
|
34
|
+
def args=args
|
|
35
|
+
set(:args, array(args))
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
#---
|
|
39
|
+
|
|
40
|
+
def flags(default = [])
|
|
41
|
+
return array(get(:flags, default))
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
#---
|
|
45
|
+
|
|
46
|
+
def flags=flags
|
|
47
|
+
set(:flags, array(flags))
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
#---
|
|
51
|
+
|
|
52
|
+
def data(default = {})
|
|
53
|
+
return hash(get(:data, default))
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
#---
|
|
57
|
+
|
|
58
|
+
def data=data
|
|
59
|
+
set(:data, hash(data))
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
#---
|
|
63
|
+
|
|
64
|
+
def subcommand=subcommand
|
|
65
|
+
unless Util::Data.empty?(subcommand)
|
|
66
|
+
set(:subcommand, new(hash(subcommand)))
|
|
67
|
+
end
|
|
68
|
+
end
|
|
69
|
+
|
|
70
|
+
#-----------------------------------------------------------------------------
|
|
71
|
+
# Plugin operations
|
|
72
|
+
|
|
73
|
+
|
|
74
|
+
#-----------------------------------------------------------------------------
|
|
75
|
+
# Command operations
|
|
76
|
+
|
|
77
|
+
def build(components = {}, overrides = nil, override_key = false)
|
|
78
|
+
return '' # Implement in sub classes
|
|
79
|
+
end
|
|
80
|
+
|
|
81
|
+
#---
|
|
82
|
+
|
|
83
|
+
def exec!(options = {}, overrides = nil)
|
|
84
|
+
# Implement in sub classes (don't forget the yield!)
|
|
85
|
+
return true
|
|
86
|
+
end
|
|
87
|
+
|
|
88
|
+
#---
|
|
89
|
+
|
|
90
|
+
def exec(options = {}, overrides = nil)
|
|
91
|
+
return exec!(options, overrides)
|
|
92
|
+
end
|
|
93
|
+
end
|
|
94
|
+
end
|
|
95
|
+
end
|
|
@@ -0,0 +1,152 @@
|
|
|
1
|
+
|
|
2
|
+
module Coral
|
|
3
|
+
module Plugin
|
|
4
|
+
class Machine < Base
|
|
5
|
+
|
|
6
|
+
#-----------------------------------------------------------------------------
|
|
7
|
+
# Machine plugin interface
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
#-----------------------------------------------------------------------------
|
|
11
|
+
# Checks
|
|
12
|
+
|
|
13
|
+
def created?
|
|
14
|
+
return false
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
#---
|
|
18
|
+
|
|
19
|
+
def running?
|
|
20
|
+
return ( created? && false )
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
#-----------------------------------------------------------------------------
|
|
24
|
+
# Property accessors / modifiers
|
|
25
|
+
|
|
26
|
+
def hostname
|
|
27
|
+
return get(:hostname, '')
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
#---
|
|
31
|
+
|
|
32
|
+
def state
|
|
33
|
+
return get(:state, nil)
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
#---
|
|
37
|
+
|
|
38
|
+
def public_ip
|
|
39
|
+
return get(:public_ip, nil)
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
#---
|
|
43
|
+
|
|
44
|
+
def private_ip
|
|
45
|
+
return get(:private_ip, nil)
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
#-----------------------------------------------------------------------------
|
|
49
|
+
# Management
|
|
50
|
+
|
|
51
|
+
def create(options = {})
|
|
52
|
+
unless created?
|
|
53
|
+
|
|
54
|
+
end
|
|
55
|
+
return true
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
#---
|
|
59
|
+
|
|
60
|
+
def start(options = {})
|
|
61
|
+
unless running?
|
|
62
|
+
|
|
63
|
+
end
|
|
64
|
+
return true
|
|
65
|
+
end
|
|
66
|
+
|
|
67
|
+
#---
|
|
68
|
+
|
|
69
|
+
def stop(options = {})
|
|
70
|
+
if running?
|
|
71
|
+
|
|
72
|
+
end
|
|
73
|
+
return true
|
|
74
|
+
end
|
|
75
|
+
|
|
76
|
+
#---
|
|
77
|
+
|
|
78
|
+
def reload(options = {})
|
|
79
|
+
if created?
|
|
80
|
+
|
|
81
|
+
end
|
|
82
|
+
return true
|
|
83
|
+
end
|
|
84
|
+
|
|
85
|
+
#---
|
|
86
|
+
|
|
87
|
+
def destroy(options = {})
|
|
88
|
+
if created?
|
|
89
|
+
|
|
90
|
+
end
|
|
91
|
+
return true
|
|
92
|
+
end
|
|
93
|
+
|
|
94
|
+
#---
|
|
95
|
+
|
|
96
|
+
def exec(options = {})
|
|
97
|
+
if running?
|
|
98
|
+
config = Config.ensure(options)
|
|
99
|
+
if commands = config.delete(:commands)
|
|
100
|
+
commands.each do |command|
|
|
101
|
+
Util::Shell.exec!(command, config) do |line|
|
|
102
|
+
yield(line) if block_given?
|
|
103
|
+
end
|
|
104
|
+
end
|
|
105
|
+
end
|
|
106
|
+
end
|
|
107
|
+
return true
|
|
108
|
+
end
|
|
109
|
+
|
|
110
|
+
#---
|
|
111
|
+
|
|
112
|
+
def provision(options = {})
|
|
113
|
+
if running?
|
|
114
|
+
config = Config.ensure(options)
|
|
115
|
+
|
|
116
|
+
# TODO: Abstract this out so it does not depend on Puppet functionality.
|
|
117
|
+
|
|
118
|
+
puppet = config.delete(:puppet, :puppet) # puppet (community) or puppetlabs (enterprise)
|
|
119
|
+
command = Coral.command({
|
|
120
|
+
:command => :puppet,
|
|
121
|
+
:flags => config.delete(:puppet_flags, ''),
|
|
122
|
+
:subcommand => {
|
|
123
|
+
:command => config.delete(:puppet_op, :apply),
|
|
124
|
+
:flags => config.delete(:puppet_op_flags, ''),
|
|
125
|
+
:data => config.delete(:puppet_op_data, {}).merge({
|
|
126
|
+
'modulepath=' => array(config.delete(:puppet_modules, "/etc/#{puppet}/modules")).join(':')
|
|
127
|
+
}),
|
|
128
|
+
:args => config.delete(:puppet_manifest, "/etc/#{puppet}/manifests/site.pp")
|
|
129
|
+
}
|
|
130
|
+
}, config.get(:provider, :shell))
|
|
131
|
+
|
|
132
|
+
config[:commands] = [ command.to_s ]
|
|
133
|
+
return exec(config)
|
|
134
|
+
end
|
|
135
|
+
return true
|
|
136
|
+
end
|
|
137
|
+
|
|
138
|
+
#---
|
|
139
|
+
|
|
140
|
+
def create_image(options = {})
|
|
141
|
+
if created?
|
|
142
|
+
|
|
143
|
+
end
|
|
144
|
+
return true
|
|
145
|
+
end
|
|
146
|
+
|
|
147
|
+
#-----------------------------------------------------------------------------
|
|
148
|
+
# Utilities
|
|
149
|
+
|
|
150
|
+
end
|
|
151
|
+
end
|
|
152
|
+
end
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
|
|
2
|
+
module Coral
|
|
3
|
+
module Plugin
|
|
4
|
+
class Network < Base
|
|
5
|
+
|
|
6
|
+
ensure_plugin_collection
|
|
7
|
+
|
|
8
|
+
#-----------------------------------------------------------------------------
|
|
9
|
+
# Cloud plugin interface
|
|
10
|
+
|
|
11
|
+
def normalize
|
|
12
|
+
@config = Config::Project.new(self._export)
|
|
13
|
+
super
|
|
14
|
+
|
|
15
|
+
init_nodes
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
#-----------------------------------------------------------------------------
|
|
19
|
+
# Property accessors / modifiers
|
|
20
|
+
|
|
21
|
+
plugin_collection :node
|
|
22
|
+
end
|
|
23
|
+
end
|
|
24
|
+
end
|
|
@@ -0,0 +1,184 @@
|
|
|
1
|
+
|
|
2
|
+
module Coral
|
|
3
|
+
module Plugin
|
|
4
|
+
class Node < Base
|
|
5
|
+
|
|
6
|
+
#-----------------------------------------------------------------------------
|
|
7
|
+
# Node plugin interface
|
|
8
|
+
|
|
9
|
+
def normalize
|
|
10
|
+
super
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
#-----------------------------------------------------------------------------
|
|
14
|
+
# Checks
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
#-----------------------------------------------------------------------------
|
|
18
|
+
# Property accessors / modifiers
|
|
19
|
+
|
|
20
|
+
def network
|
|
21
|
+
return plugin_parent
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
#---
|
|
25
|
+
|
|
26
|
+
def network=network
|
|
27
|
+
self.plugin_parent = network
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
#---
|
|
31
|
+
|
|
32
|
+
def setting(property, default = nil, format = false)
|
|
33
|
+
return network.node_setting(plugin_provider, name, property, default, format)
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
#---
|
|
37
|
+
|
|
38
|
+
def search(property, default = nil, format = false)
|
|
39
|
+
return network.search_node(plugin_provider, name, property, default, format)
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
#---
|
|
43
|
+
|
|
44
|
+
def set_setting(property, value = nil)
|
|
45
|
+
network.set_node_setting(plugin_provider, name, property, value)
|
|
46
|
+
return self
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
#---
|
|
50
|
+
|
|
51
|
+
def delete_setting(property)
|
|
52
|
+
network.delete_node_setting(plugin_provider, name, property)
|
|
53
|
+
return self
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
#-----------------------------------------------------------------------------
|
|
57
|
+
|
|
58
|
+
def machine
|
|
59
|
+
return get(:machine, nil)
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
#---
|
|
63
|
+
|
|
64
|
+
def machine=machine
|
|
65
|
+
set(:machine, machine)
|
|
66
|
+
end
|
|
67
|
+
|
|
68
|
+
#---
|
|
69
|
+
|
|
70
|
+
def create_machine(provider, options = {})
|
|
71
|
+
if provider.is_a?(String) || provider.is_a?(Symbol)
|
|
72
|
+
set(:machine, Coral.machine(options, provider))
|
|
73
|
+
end
|
|
74
|
+
return self
|
|
75
|
+
end
|
|
76
|
+
|
|
77
|
+
#---
|
|
78
|
+
|
|
79
|
+
def public_ip # Must be set at machine level
|
|
80
|
+
return machine.public_ip if machine
|
|
81
|
+
return nil
|
|
82
|
+
end
|
|
83
|
+
|
|
84
|
+
#---
|
|
85
|
+
|
|
86
|
+
def private_ip # Must be set at machine level
|
|
87
|
+
return machine.private_ip if machine
|
|
88
|
+
return nil
|
|
89
|
+
end
|
|
90
|
+
|
|
91
|
+
#---
|
|
92
|
+
|
|
93
|
+
def hostname # Must be set at machine level
|
|
94
|
+
return machine.hostname if machine
|
|
95
|
+
return ''
|
|
96
|
+
end
|
|
97
|
+
|
|
98
|
+
#---
|
|
99
|
+
|
|
100
|
+
def state # Must be set at machine level
|
|
101
|
+
return machine.state if machine
|
|
102
|
+
return nil
|
|
103
|
+
end
|
|
104
|
+
|
|
105
|
+
#-----------------------------------------------------------------------------
|
|
106
|
+
# Machine operations
|
|
107
|
+
|
|
108
|
+
def start(options = {})
|
|
109
|
+
return true unless machine
|
|
110
|
+
return machine.start(options)
|
|
111
|
+
end
|
|
112
|
+
|
|
113
|
+
#---
|
|
114
|
+
|
|
115
|
+
def stop(options = {})
|
|
116
|
+
return true unless machine && machine.running?
|
|
117
|
+
return machine.stop(options)
|
|
118
|
+
end
|
|
119
|
+
|
|
120
|
+
#---
|
|
121
|
+
|
|
122
|
+
def reload(options = {})
|
|
123
|
+
return true unless machine && machine.created?
|
|
124
|
+
return machine.reload(options)
|
|
125
|
+
end
|
|
126
|
+
|
|
127
|
+
#---
|
|
128
|
+
|
|
129
|
+
def destroy(options = {})
|
|
130
|
+
return true unless machine
|
|
131
|
+
|
|
132
|
+
config = Config.ensure(options)
|
|
133
|
+
|
|
134
|
+
if machine.created?
|
|
135
|
+
run = false
|
|
136
|
+
|
|
137
|
+
if config[:force]
|
|
138
|
+
run = true
|
|
139
|
+
else
|
|
140
|
+
choice = nil
|
|
141
|
+
begin
|
|
142
|
+
choice = ui.ask("Are you sure you want to remove: #{name}?")
|
|
143
|
+
run = choice.upcase == "Y"
|
|
144
|
+
rescue Errors::UIExpectsTTY
|
|
145
|
+
run = false
|
|
146
|
+
end
|
|
147
|
+
end
|
|
148
|
+
|
|
149
|
+
if run
|
|
150
|
+
return machine.destroy(config)
|
|
151
|
+
end
|
|
152
|
+
end
|
|
153
|
+
return true
|
|
154
|
+
end
|
|
155
|
+
|
|
156
|
+
#---
|
|
157
|
+
|
|
158
|
+
def exec(commands, options = {})
|
|
159
|
+
return true unless machine && machine.running?
|
|
160
|
+
|
|
161
|
+
config = Config.ensure(options)
|
|
162
|
+
return machine.exec(config.import({ :commands => commands }))
|
|
163
|
+
end
|
|
164
|
+
|
|
165
|
+
#---
|
|
166
|
+
|
|
167
|
+
def provision(options = {})
|
|
168
|
+
return true unless machine && machine.running?
|
|
169
|
+
return machine.provision(options)
|
|
170
|
+
end
|
|
171
|
+
|
|
172
|
+
#---
|
|
173
|
+
|
|
174
|
+
def create_image(options = {})
|
|
175
|
+
return true unless machine && machine.running?
|
|
176
|
+
return machine.create_image(options)
|
|
177
|
+
end
|
|
178
|
+
|
|
179
|
+
#-----------------------------------------------------------------------------
|
|
180
|
+
# Utilities
|
|
181
|
+
|
|
182
|
+
end
|
|
183
|
+
end
|
|
184
|
+
end
|