coral_core 0.2.26 → 0.2.30
Sign up to get free protection for your applications and to get access to all the features.
- 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
data/Gemfile
CHANGED
@@ -1,9 +1,14 @@
|
|
1
1
|
source "http://rubygems.org"
|
2
2
|
|
3
3
|
gem "log4r", "~> 1.1"
|
4
|
+
gem "i18n", "~> 0.6"
|
4
5
|
gem "deep_merge", "~> 1.0"
|
5
|
-
gem "
|
6
|
-
gem "
|
6
|
+
gem "multi_json", "~> 1.7"
|
7
|
+
gem "grit", "~> 2.5"
|
8
|
+
gem "fog", "~> 1"
|
9
|
+
gem "rgen", "~> 0.6"
|
10
|
+
gem "facter", "~> 1.7"
|
11
|
+
gem "puppet", "~> 3.2"
|
7
12
|
|
8
13
|
group :development do
|
9
14
|
gem "bundler", "~> 1.2"
|
data/Gemfile.lock
CHANGED
@@ -1,28 +1,92 @@
|
|
1
1
|
GEM
|
2
2
|
remote: http://rubygems.org/
|
3
3
|
specs:
|
4
|
+
addressable (2.3.5)
|
5
|
+
builder (3.2.2)
|
4
6
|
deep_merge (1.0.0)
|
5
|
-
diff-lcs (1.2.
|
6
|
-
|
7
|
-
|
7
|
+
diff-lcs (1.2.5)
|
8
|
+
excon (0.31.0)
|
9
|
+
facter (1.7.4)
|
10
|
+
faraday (0.8.9)
|
11
|
+
multipart-post (~> 1.2.0)
|
12
|
+
fog (1.19.0)
|
13
|
+
builder
|
14
|
+
excon (~> 0.31.0)
|
15
|
+
formatador (~> 0.2.0)
|
16
|
+
mime-types
|
17
|
+
multi_json (~> 1.0)
|
18
|
+
net-scp (~> 1.1)
|
19
|
+
net-ssh (>= 2.1.3)
|
20
|
+
nokogiri (~> 1.5)
|
21
|
+
ruby-hmac
|
22
|
+
formatador (0.2.4)
|
23
|
+
git (1.2.6)
|
24
|
+
github_api (0.10.1)
|
25
|
+
addressable
|
26
|
+
faraday (~> 0.8.1)
|
27
|
+
hashie (>= 1.2)
|
28
|
+
multi_json (~> 1.4)
|
29
|
+
nokogiri (~> 1.5.2)
|
30
|
+
oauth2
|
31
|
+
grit (2.5.0)
|
32
|
+
diff-lcs (~> 1.1)
|
33
|
+
mime-types (~> 1.15)
|
34
|
+
posix-spawn (~> 0.3.6)
|
35
|
+
hashie (2.0.5)
|
36
|
+
hiera (1.3.0)
|
37
|
+
json_pure
|
38
|
+
highline (1.6.20)
|
39
|
+
httpauth (0.2.0)
|
40
|
+
i18n (0.6.9)
|
41
|
+
jeweler (1.8.8)
|
42
|
+
builder
|
8
43
|
bundler (~> 1.0)
|
9
44
|
git (>= 1.2.5)
|
45
|
+
github_api (= 0.10.1)
|
46
|
+
highline (>= 1.6.15)
|
47
|
+
nokogiri (= 1.5.10)
|
10
48
|
rake
|
11
49
|
rdoc
|
12
|
-
json (1.8.
|
50
|
+
json (1.8.1)
|
51
|
+
json_pure (1.8.1)
|
52
|
+
jwt (0.1.10)
|
53
|
+
multi_json (>= 1.5)
|
13
54
|
log4r (1.1.10)
|
14
|
-
|
55
|
+
mime-types (1.25.1)
|
56
|
+
multi_json (1.8.4)
|
57
|
+
multi_xml (0.5.5)
|
58
|
+
multipart-post (1.2.0)
|
59
|
+
net-scp (1.1.2)
|
60
|
+
net-ssh (>= 2.6.5)
|
61
|
+
net-ssh (2.7.0)
|
62
|
+
nokogiri (1.5.10)
|
63
|
+
oauth2 (0.9.2)
|
64
|
+
faraday (~> 0.8)
|
65
|
+
httpauth (~> 0.2)
|
66
|
+
jwt (~> 0.1.4)
|
67
|
+
multi_json (~> 1.0)
|
68
|
+
multi_xml (~> 0.5)
|
69
|
+
rack (~> 1.2)
|
70
|
+
posix-spawn (0.3.8)
|
71
|
+
puppet (3.4.2)
|
72
|
+
facter (~> 1.6)
|
73
|
+
hiera (~> 1.0)
|
74
|
+
rgen (~> 0.6.5)
|
75
|
+
rack (1.5.2)
|
76
|
+
rake (10.1.1)
|
15
77
|
rdoc (3.12.2)
|
16
78
|
json (~> 1.4)
|
17
|
-
|
18
|
-
|
19
|
-
rspec-
|
20
|
-
rspec-
|
21
|
-
|
22
|
-
rspec-
|
79
|
+
rgen (0.6.6)
|
80
|
+
rspec (2.14.1)
|
81
|
+
rspec-core (~> 2.14.0)
|
82
|
+
rspec-expectations (~> 2.14.0)
|
83
|
+
rspec-mocks (~> 2.14.0)
|
84
|
+
rspec-core (2.14.7)
|
85
|
+
rspec-expectations (2.14.4)
|
23
86
|
diff-lcs (>= 1.1.3, < 2.0)
|
24
|
-
rspec-mocks (2.
|
25
|
-
|
87
|
+
rspec-mocks (2.14.4)
|
88
|
+
ruby-hmac (0.4.0)
|
89
|
+
yard (0.8.7.3)
|
26
90
|
|
27
91
|
PLATFORMS
|
28
92
|
ruby
|
@@ -30,10 +94,15 @@ PLATFORMS
|
|
30
94
|
DEPENDENCIES
|
31
95
|
bundler (~> 1.2)
|
32
96
|
deep_merge (~> 1.0)
|
33
|
-
|
97
|
+
facter (~> 1.7)
|
98
|
+
fog (~> 1)
|
99
|
+
grit (~> 2.5)
|
100
|
+
i18n (~> 0.6)
|
34
101
|
jeweler (~> 1.8)
|
35
|
-
json (>= 1.4)
|
36
102
|
log4r (~> 1.1)
|
103
|
+
multi_json (~> 1.7)
|
104
|
+
puppet (~> 3.2)
|
37
105
|
rdoc (~> 3.12)
|
106
|
+
rgen (~> 0.6)
|
38
107
|
rspec (~> 2.10)
|
39
108
|
yard (~> 0.8)
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.2.
|
1
|
+
0.2.30
|
data/coral_core.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = "coral_core"
|
8
|
-
s.version = "0.2.
|
8
|
+
s.version = "0.2.30"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Adrian Webb"]
|
12
|
-
s.date = "
|
12
|
+
s.date = "2014-01-15"
|
13
13
|
s.description = "= coral_core\n\nThis library provides core data elements and utilities used in other Coral gems.\n\nThe Coral core library contains functionality that is utilized by other\nCoral gems by providing basic utilities like Git, Shell, Disk, and Data\nmanipulation libraries, a UI system, and a core data model that supports\nEvents, Commands, Repositories, and Memory (version controlled JSON \nobjects). This library is only used as a starting point for other systems.\n\nNote: This library is still very early in development!\n\n== Contributing to coral_core\n \n* Check out the latest {major}.{minor} branch to make sure the feature hasn't \n been implemented or the bug hasn't been fixed yet.\n* Check out the issue tracker to make sure someone already hasn't requested \n it and/or contributed it.\n* Fork the project.\n* Start a feature/bugfix branch.\n* Commit and push until you are happy with your contribution.\n* Make sure to add tests for it. This is important so I don't break it in a \n future version unintentionally.\n* Please try not to mess with the Rakefile, version, or history. If you want \n to have your own version, or is otherwise necessary, that is fine, but \n please isolate to its own commit so I can cherry-pick around it.\n\n== Copyright\n\nLicensed under GPLv3. See LICENSE.txt for further details.\n\nCopyright (c) 2013 Adrian Webb <adrian.webb@coraltech.net>\nCoral Technology Group LLC"
|
14
14
|
s.email = "adrian.webb@coraltech.net"
|
15
15
|
s.extra_rdoc_files = [
|
@@ -18,7 +18,6 @@ Gem::Specification.new do |s|
|
|
18
18
|
]
|
19
19
|
s.files = [
|
20
20
|
".document",
|
21
|
-
".gitmodules",
|
22
21
|
"Gemfile",
|
23
22
|
"Gemfile.lock",
|
24
23
|
"LICENSE.txt",
|
@@ -26,14 +25,35 @@ Gem::Specification.new do |s|
|
|
26
25
|
"Rakefile",
|
27
26
|
"VERSION",
|
28
27
|
"coral_core.gemspec",
|
28
|
+
"lib/coral/command/shell.rb",
|
29
|
+
"lib/coral/machine/fog.rb",
|
30
|
+
"lib/coral/network/default.rb",
|
31
|
+
"lib/coral/node/rackspace.rb",
|
29
32
|
"lib/coral_core.rb",
|
30
|
-
"lib/coral_core/command.rb",
|
31
33
|
"lib/coral_core/config.rb",
|
34
|
+
"lib/coral_core/config/collection.rb",
|
35
|
+
"lib/coral_core/config/options.rb",
|
36
|
+
"lib/coral_core/config/project.rb",
|
32
37
|
"lib/coral_core/core.rb",
|
33
38
|
"lib/coral_core/event.rb",
|
39
|
+
"lib/coral_core/event/puppet_event.rb",
|
34
40
|
"lib/coral_core/event/regexp_event.rb",
|
35
|
-
"lib/coral_core/
|
36
|
-
"lib/coral_core/
|
41
|
+
"lib/coral_core/mixin/config_collection.rb",
|
42
|
+
"lib/coral_core/mixin/config_ops.rb",
|
43
|
+
"lib/coral_core/mixin/config_options.rb",
|
44
|
+
"lib/coral_core/mixin/lookup.rb",
|
45
|
+
"lib/coral_core/mixin/macro/object_interface.rb",
|
46
|
+
"lib/coral_core/mixin/macro/plugin_interface.rb",
|
47
|
+
"lib/coral_core/mixin/settings.rb",
|
48
|
+
"lib/coral_core/mixin/sub_config.rb",
|
49
|
+
"lib/coral_core/mod/hash.rb",
|
50
|
+
"lib/coral_core/mod/hiera_backend.rb",
|
51
|
+
"lib/coral_core/plugin.rb",
|
52
|
+
"lib/coral_core/plugin/command.rb",
|
53
|
+
"lib/coral_core/plugin/machine.rb",
|
54
|
+
"lib/coral_core/plugin/network.rb",
|
55
|
+
"lib/coral_core/plugin/node.rb",
|
56
|
+
"lib/coral_core/plugin_base.rb",
|
37
57
|
"lib/coral_core/repository.rb",
|
38
58
|
"lib/coral_core/resource.rb",
|
39
59
|
"lib/coral_core/template.rb",
|
@@ -41,14 +61,14 @@ Gem::Specification.new do |s|
|
|
41
61
|
"lib/coral_core/template/json.rb",
|
42
62
|
"lib/coral_core/template/wrapper.rb",
|
43
63
|
"lib/coral_core/template/yaml.rb",
|
64
|
+
"lib/coral_core/util/cli.rb",
|
44
65
|
"lib/coral_core/util/data.rb",
|
45
66
|
"lib/coral_core/util/disk.rb",
|
46
67
|
"lib/coral_core/util/git.rb",
|
47
|
-
"lib/coral_core/util/
|
48
|
-
"lib/coral_core/util/
|
49
|
-
"lib/coral_core/util/git/remote.rb",
|
68
|
+
"lib/coral_core/util/interface.rb",
|
69
|
+
"lib/coral_core/util/process.rb",
|
50
70
|
"lib/coral_core/util/shell.rb",
|
51
|
-
"
|
71
|
+
"locales/en.yml",
|
52
72
|
"spec/coral_core/interface_spec.rb",
|
53
73
|
"spec/coral_mock_input.rb",
|
54
74
|
"spec/coral_test_kernel.rb",
|
@@ -68,9 +88,14 @@ Gem::Specification.new do |s|
|
|
68
88
|
|
69
89
|
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
70
90
|
s.add_runtime_dependency(%q<log4r>, ["~> 1.1"])
|
91
|
+
s.add_runtime_dependency(%q<i18n>, ["~> 0.6"])
|
71
92
|
s.add_runtime_dependency(%q<deep_merge>, ["~> 1.0"])
|
72
|
-
s.add_runtime_dependency(%q<
|
73
|
-
s.add_runtime_dependency(%q<
|
93
|
+
s.add_runtime_dependency(%q<multi_json>, ["~> 1.7"])
|
94
|
+
s.add_runtime_dependency(%q<grit>, ["~> 2.5"])
|
95
|
+
s.add_runtime_dependency(%q<fog>, ["~> 1"])
|
96
|
+
s.add_runtime_dependency(%q<rgen>, ["~> 0.6"])
|
97
|
+
s.add_runtime_dependency(%q<facter>, ["~> 1.7"])
|
98
|
+
s.add_runtime_dependency(%q<puppet>, ["~> 3.2"])
|
74
99
|
s.add_development_dependency(%q<bundler>, ["~> 1.2"])
|
75
100
|
s.add_development_dependency(%q<jeweler>, ["~> 1.8"])
|
76
101
|
s.add_development_dependency(%q<rspec>, ["~> 2.10"])
|
@@ -78,9 +103,14 @@ Gem::Specification.new do |s|
|
|
78
103
|
s.add_development_dependency(%q<yard>, ["~> 0.8"])
|
79
104
|
else
|
80
105
|
s.add_dependency(%q<log4r>, ["~> 1.1"])
|
106
|
+
s.add_dependency(%q<i18n>, ["~> 0.6"])
|
81
107
|
s.add_dependency(%q<deep_merge>, ["~> 1.0"])
|
82
|
-
s.add_dependency(%q<
|
83
|
-
s.add_dependency(%q<
|
108
|
+
s.add_dependency(%q<multi_json>, ["~> 1.7"])
|
109
|
+
s.add_dependency(%q<grit>, ["~> 2.5"])
|
110
|
+
s.add_dependency(%q<fog>, ["~> 1"])
|
111
|
+
s.add_dependency(%q<rgen>, ["~> 0.6"])
|
112
|
+
s.add_dependency(%q<facter>, ["~> 1.7"])
|
113
|
+
s.add_dependency(%q<puppet>, ["~> 3.2"])
|
84
114
|
s.add_dependency(%q<bundler>, ["~> 1.2"])
|
85
115
|
s.add_dependency(%q<jeweler>, ["~> 1.8"])
|
86
116
|
s.add_dependency(%q<rspec>, ["~> 2.10"])
|
@@ -89,9 +119,14 @@ Gem::Specification.new do |s|
|
|
89
119
|
end
|
90
120
|
else
|
91
121
|
s.add_dependency(%q<log4r>, ["~> 1.1"])
|
122
|
+
s.add_dependency(%q<i18n>, ["~> 0.6"])
|
92
123
|
s.add_dependency(%q<deep_merge>, ["~> 1.0"])
|
93
|
-
s.add_dependency(%q<
|
94
|
-
s.add_dependency(%q<
|
124
|
+
s.add_dependency(%q<multi_json>, ["~> 1.7"])
|
125
|
+
s.add_dependency(%q<grit>, ["~> 2.5"])
|
126
|
+
s.add_dependency(%q<fog>, ["~> 1"])
|
127
|
+
s.add_dependency(%q<rgen>, ["~> 0.6"])
|
128
|
+
s.add_dependency(%q<facter>, ["~> 1.7"])
|
129
|
+
s.add_dependency(%q<puppet>, ["~> 3.2"])
|
95
130
|
s.add_dependency(%q<bundler>, ["~> 1.2"])
|
96
131
|
s.add_dependency(%q<jeweler>, ["~> 1.8"])
|
97
132
|
s.add_dependency(%q<rspec>, ["~> 2.10"])
|
@@ -1,116 +1,17 @@
|
|
1
1
|
|
2
2
|
module Coral
|
3
|
-
|
4
|
-
|
3
|
+
module Command
|
4
|
+
class Shell < Plugin::Command
|
5
|
+
|
5
6
|
#-----------------------------------------------------------------------------
|
6
|
-
#
|
7
|
-
|
8
|
-
attr_accessor :name
|
9
|
-
attr_reader :subcommand
|
10
|
-
|
11
|
-
#-----------------------------------------------------------------------------
|
12
|
-
# Constructor / Destructor
|
13
|
-
|
14
|
-
def initialize(options = {})
|
15
|
-
|
16
|
-
if options.is_a?(String) || options.is_a?(Symbol)
|
17
|
-
options = string(options)
|
18
|
-
options = { :name => options, :command => options }
|
19
|
-
end
|
20
|
-
|
21
|
-
config = Config.ensure(options)
|
22
|
-
|
23
|
-
super(config)
|
24
|
-
|
25
|
-
@properties = {}
|
26
|
-
|
27
|
-
self.subcommand = config.get(:subcommand, nil)
|
28
|
-
|
29
|
-
@name = config.get(:name, '')
|
30
|
-
|
31
|
-
@properties = config.options
|
32
|
-
@properties[:command] = executable(config)
|
33
|
-
end
|
34
|
-
|
35
|
-
#-----------------------------------------------------------------------------
|
36
|
-
# Property accessors / modifiers
|
37
|
-
|
38
|
-
def command_base
|
39
|
-
return @properties[:command]
|
40
|
-
end
|
41
|
-
|
42
|
-
#---
|
43
|
-
|
44
|
-
def command=command
|
45
|
-
@properties[:command] = executable({ :command => command })
|
46
|
-
end
|
47
|
-
|
48
|
-
#---
|
49
|
-
|
50
|
-
def vagrant=command
|
51
|
-
@properties[:command] = executable({ :vagrant => command })
|
52
|
-
end
|
53
|
-
|
54
|
-
#---
|
55
|
-
|
56
|
-
def coral=command
|
57
|
-
@properties[:command] = executable({ :coral => command })
|
58
|
-
end
|
59
|
-
|
60
|
-
#---
|
61
|
-
|
62
|
-
def args
|
63
|
-
return array(@properties[:args])
|
64
|
-
end
|
65
|
-
|
66
|
-
#---
|
67
|
-
|
68
|
-
def args=args
|
69
|
-
@properties[:args] = array(args)
|
70
|
-
end
|
71
|
-
|
72
|
-
#---
|
73
|
-
|
74
|
-
def flags
|
75
|
-
return array(@properties[:flags])
|
76
|
-
end
|
77
|
-
|
78
|
-
#---
|
79
|
-
|
80
|
-
def flags=flags
|
81
|
-
@properties[:flags] = array(flags)
|
82
|
-
end
|
83
|
-
|
84
|
-
#---
|
85
|
-
|
86
|
-
def data
|
87
|
-
return hash(@properties[:data])
|
88
|
-
end
|
89
|
-
|
90
|
-
#---
|
7
|
+
# Command operations
|
91
8
|
|
92
|
-
def
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
#---
|
97
|
-
|
98
|
-
def subcommand=subcommand
|
99
|
-
unless Util::Data.empty?(subcommand)
|
100
|
-
@properties[:subcommand] = hash(subcommand)
|
101
|
-
@subcommand = self.class.new(@properties[:subcommand])
|
102
|
-
end
|
9
|
+
def normalize
|
10
|
+
super
|
11
|
+
set(:command, executable(self))
|
103
12
|
end
|
104
13
|
|
105
|
-
|
106
|
-
# Import / Export
|
107
|
-
|
108
|
-
def export
|
109
|
-
return symbol_map(@properties)
|
110
|
-
end
|
111
|
-
|
112
|
-
#-----------------------------------------------------------------------------
|
113
|
-
# Command functions
|
14
|
+
#---
|
114
15
|
|
115
16
|
def build(components = {}, overrides = nil, override_key = false)
|
116
17
|
|
@@ -212,18 +113,12 @@ class Command < Core
|
|
212
113
|
config = Config.ensure(options)
|
213
114
|
|
214
115
|
config[:ui] = @ui
|
215
|
-
success =
|
116
|
+
success = Util::Shell.exec!(build(properties, overrides), config) do |line|
|
216
117
|
block_given? ? yield(line) : true
|
217
118
|
end
|
218
119
|
return success
|
219
120
|
end
|
220
121
|
|
221
|
-
#---
|
222
|
-
|
223
|
-
def exec(options = {}, overrides = nil)
|
224
|
-
return exec!(options, overrides)
|
225
|
-
end
|
226
|
-
|
227
122
|
#-----------------------------------------------------------------------------
|
228
123
|
# Utilities
|
229
124
|
|
@@ -239,6 +134,7 @@ class Command < Core
|
|
239
134
|
elsif config.get(:command, false)
|
240
135
|
return config[:command]
|
241
136
|
end
|
242
|
-
end
|
137
|
+
end
|
138
|
+
end
|
139
|
+
end
|
243
140
|
end
|
244
|
-
end
|
@@ -0,0 +1,215 @@
|
|
1
|
+
|
2
|
+
module Coral
|
3
|
+
module Machine
|
4
|
+
class Fog < Plugin::Machine
|
5
|
+
|
6
|
+
include Mixin::SubConfig
|
7
|
+
|
8
|
+
#-----------------------------------------------------------------------------
|
9
|
+
# Machine plugin interface
|
10
|
+
|
11
|
+
def normalize
|
12
|
+
super
|
13
|
+
set_connection
|
14
|
+
end
|
15
|
+
|
16
|
+
#-----------------------------------------------------------------------------
|
17
|
+
# Checks
|
18
|
+
|
19
|
+
def created?
|
20
|
+
return server && ! server.state != 'DELETED'
|
21
|
+
end
|
22
|
+
|
23
|
+
#---
|
24
|
+
|
25
|
+
def running?
|
26
|
+
return created? && server.ready?
|
27
|
+
end
|
28
|
+
|
29
|
+
#-----------------------------------------------------------------------------
|
30
|
+
# Property accessors / modifiers
|
31
|
+
|
32
|
+
def set_connection
|
33
|
+
set(:compute, Fog::Compute.new(_export))
|
34
|
+
end
|
35
|
+
protected :set_connection
|
36
|
+
|
37
|
+
#---
|
38
|
+
|
39
|
+
def compute
|
40
|
+
return get(:compute)
|
41
|
+
end
|
42
|
+
|
43
|
+
#---
|
44
|
+
|
45
|
+
def server
|
46
|
+
return get(:server)
|
47
|
+
end
|
48
|
+
|
49
|
+
#---
|
50
|
+
|
51
|
+
def name
|
52
|
+
return ( server ? server.id : '' )
|
53
|
+
end
|
54
|
+
|
55
|
+
#---
|
56
|
+
|
57
|
+
def name=id
|
58
|
+
set(:server, compute.servers.get(id)) if id
|
59
|
+
end
|
60
|
+
|
61
|
+
#---
|
62
|
+
|
63
|
+
def hostname
|
64
|
+
return server.name if server
|
65
|
+
return ''
|
66
|
+
end
|
67
|
+
|
68
|
+
#---
|
69
|
+
|
70
|
+
def state
|
71
|
+
return server.state if server
|
72
|
+
return nil
|
73
|
+
end
|
74
|
+
|
75
|
+
#---
|
76
|
+
|
77
|
+
def public_ip
|
78
|
+
return server.public_ip_address if server
|
79
|
+
return nil
|
80
|
+
end
|
81
|
+
|
82
|
+
#---
|
83
|
+
|
84
|
+
def private_ip
|
85
|
+
return server.private_ip_address if server
|
86
|
+
return nil
|
87
|
+
end
|
88
|
+
|
89
|
+
#---
|
90
|
+
|
91
|
+
def flavors
|
92
|
+
return compute.flavors if compute
|
93
|
+
return nil
|
94
|
+
end
|
95
|
+
|
96
|
+
#---
|
97
|
+
|
98
|
+
def flavor
|
99
|
+
return server.flavor if server
|
100
|
+
return nil
|
101
|
+
end
|
102
|
+
|
103
|
+
#---
|
104
|
+
|
105
|
+
def images
|
106
|
+
return compute.images if compute
|
107
|
+
return nil
|
108
|
+
end
|
109
|
+
|
110
|
+
#---
|
111
|
+
|
112
|
+
def image
|
113
|
+
return server.image if server
|
114
|
+
return nil
|
115
|
+
end
|
116
|
+
|
117
|
+
#-----------------------------------------------------------------------------
|
118
|
+
# Management
|
119
|
+
|
120
|
+
def create(options = {})
|
121
|
+
success = super(options)
|
122
|
+
if success && ! created?
|
123
|
+
set(:server, compute.servers.bootstrap(options))
|
124
|
+
end
|
125
|
+
return success
|
126
|
+
end
|
127
|
+
|
128
|
+
#---
|
129
|
+
|
130
|
+
def start(options = {})
|
131
|
+
success = super(options)
|
132
|
+
if success
|
133
|
+
unless created?
|
134
|
+
return create(options)
|
135
|
+
end
|
136
|
+
unless running?
|
137
|
+
server_info = compute.servers.create(options)
|
138
|
+
|
139
|
+
Fog.wait_for do
|
140
|
+
compute.servers.get(server_info.id).ready? ? true : false
|
141
|
+
end
|
142
|
+
@server = compute.servers.get(server_info.id)
|
143
|
+
end
|
144
|
+
end
|
145
|
+
return success
|
146
|
+
end
|
147
|
+
|
148
|
+
#---
|
149
|
+
|
150
|
+
def stop(options = {})
|
151
|
+
success = super(options)
|
152
|
+
if success && running?
|
153
|
+
if image_id = create_image(name)
|
154
|
+
|
155
|
+
Fog.wait_for do
|
156
|
+
compute.images.get(image_id).ready? ? true : false
|
157
|
+
end
|
158
|
+
|
159
|
+
server.destroy
|
160
|
+
return image_id
|
161
|
+
end
|
162
|
+
end
|
163
|
+
return success
|
164
|
+
end
|
165
|
+
|
166
|
+
#---
|
167
|
+
|
168
|
+
def reload(options = {})
|
169
|
+
success = super(options)
|
170
|
+
if success && created?
|
171
|
+
# Don't quite know what this should do yet??
|
172
|
+
return server.reboot(options)
|
173
|
+
end
|
174
|
+
return success
|
175
|
+
end
|
176
|
+
|
177
|
+
#---
|
178
|
+
|
179
|
+
def destroy(options = {})
|
180
|
+
success = super(options)
|
181
|
+
if success && created?
|
182
|
+
return server.destroy(options)
|
183
|
+
end
|
184
|
+
return success
|
185
|
+
end
|
186
|
+
|
187
|
+
#---
|
188
|
+
|
189
|
+
def exec(options = {})
|
190
|
+
success = super(options)
|
191
|
+
if success && running?
|
192
|
+
if commands = options.delete(:commands)
|
193
|
+
return server.ssh(commands, options)
|
194
|
+
end
|
195
|
+
end
|
196
|
+
return success
|
197
|
+
end
|
198
|
+
|
199
|
+
#---
|
200
|
+
|
201
|
+
def create_image(name, options = {})
|
202
|
+
success = super(options)
|
203
|
+
if success && created?
|
204
|
+
image = server.create_image(name, options)
|
205
|
+
return ( image ? image.id : false )
|
206
|
+
end
|
207
|
+
return success
|
208
|
+
end
|
209
|
+
|
210
|
+
#-----------------------------------------------------------------------------
|
211
|
+
# Utilities
|
212
|
+
|
213
|
+
end
|
214
|
+
end
|
215
|
+
end
|