forj 1.0.3 → 1.0.4
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.
- checksums.yaml +4 -4
- data/.rubocop.yml +59 -0
- data/Gemfile +14 -15
- data/Rakefile +11 -3
- data/bin/forj +231 -338
- data/forj.gemspec +4 -7
- data/forj/defaults.yaml +3 -3
- data/lib/appinit.rb +21 -32
- data/lib/boot.rb +156 -0
- data/lib/cloud_connection.rb +42 -0
- data/lib/cloud_test.rb +86 -68
- data/lib/destroy.rb +97 -0
- data/lib/forj-settings.rb +350 -167
- data/lib/forj/ForjCli.rb +12 -14
- data/lib/forj/ForjCore.rb +78 -85
- data/lib/forj/process/ForjProcess.rb +1157 -771
- data/lib/get.rb +51 -0
- data/lib/ssh.rb +86 -78
- data/spec/boot_spec.rb +0 -1
- data/spec/spec_helper.rb +65 -65
- metadata +14 -22
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 502bfc6edeb25b5ff031e55b707cb8c27800dcea
|
4
|
+
data.tar.gz: a58602925d8e68d05907eb3834d959e46b080bf1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f6112e2d51cf46da0c29b44be1221135c8cff7b6cb631725c4c3bbc8204242b61f107865673cfa7ca8f242ffb136ad8a0af9079df0548b404ac7b06be96c42f0
|
7
|
+
data.tar.gz: 895f7bc30b598051e49612b21b54a3ded559dd06556a3475b131367ada6490c7da02604c53f9a20228fbcb078a85aae1b0f61734bdfb20a0bbe170ee7da0c0b1
|
data/.rubocop.yml
ADDED
@@ -0,0 +1,59 @@
|
|
1
|
+
# Copyright 2013 Hewlett-Packard Development Company, L.P.
|
2
|
+
#
|
3
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
4
|
+
# you may not use this file except in compliance with the License.
|
5
|
+
# You may obtain a copy of the License at
|
6
|
+
#
|
7
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
8
|
+
#
|
9
|
+
# Unless required by applicable law or agreed to in writing, software
|
10
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
11
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
12
|
+
# See the License for the specific language governing permissions and
|
13
|
+
# limitations under the License.
|
14
|
+
|
15
|
+
# use: rubocop --show-cops
|
16
|
+
# to validate configuration.
|
17
|
+
# rubocop config
|
18
|
+
AllCops:
|
19
|
+
Include:
|
20
|
+
- '**/Rakefile'
|
21
|
+
- '**/config.ru'
|
22
|
+
Exclude:
|
23
|
+
- 'docker/**/*'
|
24
|
+
- 'bin/scripts/**/*'
|
25
|
+
- 'git/**/*'
|
26
|
+
- 'tmp/**/*'
|
27
|
+
#Documentation:
|
28
|
+
# Enabled: false
|
29
|
+
#Metrics/LineLength:
|
30
|
+
# Max: 99
|
31
|
+
Style/HashSyntax:
|
32
|
+
EnforcedStyle: hash_rockets
|
33
|
+
|
34
|
+
# lets start with 40, but 10 is way to small..
|
35
|
+
Metrics/MethodLength:
|
36
|
+
Max: 40
|
37
|
+
# allow arguments to be longer than 15
|
38
|
+
Metrics/AbcSize:
|
39
|
+
Max: 40
|
40
|
+
# allow nested methods and classes definition
|
41
|
+
ClassAndModuleChildren:
|
42
|
+
# EnforcedStyle: compact
|
43
|
+
Enabled: false
|
44
|
+
|
45
|
+
# some files names gets an exception
|
46
|
+
Style/FileName:
|
47
|
+
Exclude: ['Gemfile',
|
48
|
+
'lib/forj/process/ForjProcess.rb',
|
49
|
+
'lib/forj/ForjCore.rb',
|
50
|
+
'lib/forj/ForjCli.rb',
|
51
|
+
'lib/forj-settings.rb' ]
|
52
|
+
|
53
|
+
# this project defines these globals
|
54
|
+
Style/GlobalVars:
|
55
|
+
AllowedVariables: ['$RT_GEM_BIN',
|
56
|
+
'$RT_VERSION_SPEC',
|
57
|
+
'$FORJ_TEMP',
|
58
|
+
'$RT_VERSION',
|
59
|
+
'$RT_GEM_HOME']
|
data/Gemfile
CHANGED
@@ -18,24 +18,23 @@
|
|
18
18
|
source 'https://rubygems.org'
|
19
19
|
|
20
20
|
gemspec
|
21
|
-
#group(:development, :test) do
|
21
|
+
# group(:development, :test) do
|
22
22
|
# gem 'rake'
|
23
23
|
# gem 'debugger'
|
24
24
|
# gem 'byebug'
|
25
25
|
# gem 'rspec', "~> 3.1.0", :require => false
|
26
|
-
#end
|
26
|
+
# end
|
27
27
|
|
28
28
|
# if updating here, update forj.gemspec as well, to be coherent.
|
29
|
-
#gem 'mime-types','1.25.1'
|
30
|
-
#gem 'excon','0.31.0'
|
31
|
-
#gem 'json','1.7.5'
|
32
|
-
#gem 'nokogiri','1.5.11'
|
33
|
-
#gem 'fog', '1.19.0'
|
34
|
-
#gem 'git', '>=1.2.7'
|
35
|
-
#gem 'rainbow'
|
36
|
-
#gem 'thor', '>=0.16.0'
|
37
|
-
#gem 'highline','>=1.6.21'
|
38
|
-
#gem 'ansi','>=1.4.3'
|
39
|
-
#gem 'encryptor','>=1.3.0'
|
40
|
-
#gem 'bundler', '1.7.3'
|
41
|
-
|
29
|
+
# gem 'mime-types','1.25.1'
|
30
|
+
# gem 'excon','0.31.0'
|
31
|
+
# gem 'json','1.7.5'
|
32
|
+
# gem 'nokogiri','1.5.11'
|
33
|
+
# gem 'fog', '1.19.0'
|
34
|
+
# gem 'git', '>=1.2.7'
|
35
|
+
# gem 'rainbow'
|
36
|
+
# gem 'thor', '>=0.16.0'
|
37
|
+
# gem 'highline','>=1.6.21'
|
38
|
+
# gem 'ansi','>=1.4.3'
|
39
|
+
# gem 'encryptor','>=1.3.0'
|
40
|
+
# gem 'bundler', '1.7.3'
|
data/Rakefile
CHANGED
@@ -15,17 +15,25 @@
|
|
15
15
|
# See the License for the specific language governing permissions and
|
16
16
|
# limitations under the License.
|
17
17
|
|
18
|
-
require '
|
19
|
-
require 'bundler/setup'
|
18
|
+
require 'bundler/gem_tasks'
|
20
19
|
require 'rspec/core/rake_task'
|
20
|
+
require 'rubocop/rake_task'
|
21
21
|
|
22
22
|
$stdout.sync = true
|
23
23
|
$stderr.sync = true
|
24
24
|
Bundler::GemHelper.install_tasks
|
25
25
|
|
26
|
-
task :default => [:spec]
|
26
|
+
task :default => [:lint, :spec]
|
27
27
|
|
28
28
|
desc 'Run the specs.'
|
29
29
|
RSpec::Core::RakeTask.new do |t|
|
30
30
|
t.pattern = 'spec/*_spec.rb'
|
31
|
+
t.rspec_opts = '-f doc'
|
32
|
+
end
|
33
|
+
|
34
|
+
desc 'Run RuboCop on the project'
|
35
|
+
RuboCop::RakeTask.new(:lint) do |task|
|
36
|
+
task.formatters = ['progress']
|
37
|
+
task.verbose = true
|
38
|
+
task.fail_on_error = true
|
31
39
|
end
|
data/bin/forj
CHANGED
@@ -16,84 +16,84 @@
|
|
16
16
|
# limitations under the License.
|
17
17
|
|
18
18
|
require 'rubygems'
|
19
|
-
#require 'debugger' # Use to debug with Ruby < 2.0
|
20
|
-
#require 'byebug' # Use to debug with Ruby >= 2.0
|
19
|
+
# require 'debugger' # Use to debug with Ruby < 2.0
|
20
|
+
# require 'byebug' # Use to debug with Ruby >= 2.0
|
21
21
|
require 'bundler/setup'
|
22
|
-
#require 'require_relative'
|
23
22
|
require 'thor'
|
24
23
|
require 'ansi'
|
25
24
|
|
26
|
-
|
27
|
-
|
25
|
+
APP_PATH = File.dirname(File.dirname(__FILE__))
|
26
|
+
LIB_PATH = File.expand_path(File.join(APP_PATH, 'lib'))
|
28
27
|
|
29
|
-
require '
|
28
|
+
require 'lorj'
|
29
|
+
PrcLib.app_name = 'forj'
|
30
|
+
PrcLib.app_defaults = File.join(APP_PATH, 'forj')
|
30
31
|
|
31
32
|
# Initialize forj paths
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
PrcLib.app_name = 'forj'
|
37
|
-
PrcLib.app_defaults = File.join($APP_PATH, 'forj')
|
33
|
+
require 'appinit.rb' # Load Application settings features
|
34
|
+
Forj.keypairs_path = File.join(PrcLib.data_path, 'keypairs')
|
35
|
+
Forj.build_path = File.join(PrcLib.data_path, '.build')
|
38
36
|
|
39
37
|
require 'forj-settings.rb' # Settings features
|
40
|
-
require 'ssh.rb'
|
41
|
-
|
42
|
-
|
43
|
-
$LIB_FORJ_DEBUG = 1 # less verbose
|
44
|
-
|
45
38
|
|
39
|
+
# This is the main Forj class
|
40
|
+
# it helps you to create and support your forge.
|
41
|
+
# rubocop:disable ClassLength
|
46
42
|
class ForjThor < Thor
|
47
|
-
|
48
43
|
class_option :debug, :aliases => '-d', :desc => 'Set debug mode'
|
49
44
|
class_option :verbose, :aliases => '-v', :desc => 'Set verbose mode'
|
50
|
-
class_option :config, :aliases => '-c', :desc => 'Path to a different forj
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
desc
|
45
|
+
class_option :config, :aliases => '-c', :desc => 'Path to a different forj'\
|
46
|
+
' config file. By default, use ~/.forj/config.yaml'
|
47
|
+
class_option :lorj_debug, :desc => 'Set lorj debug level verbosity. 1 to 5.'\
|
48
|
+
'Default is one.'
|
49
|
+
desc 'help [action]', 'Describe available FORJ actions or one specific action'
|
55
50
|
def help(task = nil, subcommand = false)
|
56
51
|
if task
|
57
|
-
|
52
|
+
self.class.task_help(shell, task)
|
58
53
|
else
|
59
|
-
|
54
|
+
puts <<-LONGDESC
|
60
55
|
Quick steps: How to create a forj?
|
61
56
|
----------------------------------
|
62
57
|
|
63
58
|
To test a forj blueprint, you will need an account on a cloud solution.
|
64
|
-
Currently forj cli supports only HPHelion (https://horizon.hp.com) but will
|
59
|
+
Currently forj cli supports only HPHelion (https://horizon.hp.com) but will
|
60
|
+
be expanded to support most of known clouds supported by FOG. (http://fog.io)
|
65
61
|
|
66
62
|
1. Setup your FORJ account.
|
67
63
|
`$ forj setup [AccountName] [--provider Provider]`
|
68
64
|
|
69
|
-
Ex: `forj setup MyForjAccount`. In this example
|
65
|
+
Ex: `forj setup MyForjAccount`. In this example:
|
66
|
+
You will setup 'MyForjAccount' with your HPHelion account.
|
67
|
+
The first time, this account will become the default one.
|
70
68
|
|
71
|
-
**IMPORTANT NOTE** By default, forj setup will propose you to create your forge
|
72
|
-
|
69
|
+
**IMPORTANT NOTE** By default, forj setup will propose you to create your forge
|
70
|
+
on HPHelion (provider 'hpcloud').
|
71
|
+
If AccountName is not set, the account name will be proposed to be name
|
72
|
+
'hpcloud' as well!
|
73
73
|
|
74
74
|
2. Create your forge on your default account
|
75
75
|
`$ forj boot <blueprint> <InstanceName>`
|
76
76
|
|
77
|
-
Ex: `forj boot redstone MyForge`. In this example
|
77
|
+
Ex: `forj boot redstone MyForge`. In this example:
|
78
|
+
Forj will create a `redstone` blueprint forge named `MyForge`,
|
79
|
+
using the default `MyForjAccount`.
|
78
80
|
|
79
81
|
forj command line details:
|
80
82
|
--------------------------
|
81
83
|
LONGDESC
|
82
|
-
|
84
|
+
self.class.help(shell, subcommand)
|
83
85
|
end
|
84
86
|
end
|
85
87
|
|
86
|
-
|
87
|
-
|
88
|
-
def version()
|
89
|
-
if Gem.loaded_specs['forj']
|
90
|
-
puts Gem.loaded_specs['forj'].version.to_s
|
91
|
-
end
|
92
|
-
end
|
88
|
+
desc 'version', 'get GEM version of forj.'
|
93
89
|
|
90
|
+
def version
|
91
|
+
puts Gem.loaded_specs['forj'].version.to_s if Gem.loaded_specs['forj']
|
92
|
+
end
|
94
93
|
|
95
|
-
################################# BOOT
|
96
|
-
desc 'boot <blueprint> <InstanceName> [options]', 'boot a Maestro box and
|
94
|
+
################################# BOOT
|
95
|
+
desc 'boot <blueprint> <InstanceName> [options]', 'boot a Maestro box and' \
|
96
|
+
' instruct it to provision the blueprint'
|
97
97
|
|
98
98
|
long_desc <<-LONGDESC
|
99
99
|
This task boot a new forge with the following options
|
@@ -102,239 +102,147 @@ This task boot a new forge with the following options
|
|
102
102
|
|
103
103
|
Ex: forj boot redstone maestro_test -a dev
|
104
104
|
|
105
|
-
When `forj boot` starts, some variables are loaded.
|
105
|
+
When `forj boot` starts, some variables are loaded.
|
106
|
+
If you want to check/updated them, use `forj get [-a account]`
|
106
107
|
|
107
108
|
LONGDESC
|
108
109
|
|
109
|
-
method_option :account_name, :aliases => '-a', :desc =>
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
method_option :
|
118
|
-
|
119
|
-
|
120
|
-
method_option :
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
method_option :
|
125
|
-
|
126
|
-
|
127
|
-
Maestro
|
128
|
-
method_option :
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
oConfig.set(:infra_repo, options[:infra])
|
159
|
-
oConfig.set(:keypair_name, options[:key_name])
|
160
|
-
oConfig.set(:keypair_path, options[:key_path])
|
161
|
-
oConfig.set(:security_group, options[:security_group])
|
162
|
-
oConfig.set(:image_name, options[:image_name])
|
163
|
-
oConfig.set(:flavor, options[:maestro_flavor])
|
164
|
-
oConfig.set(:bp_flavor, options[:bp_flavor])
|
165
|
-
oConfig.set(:maestro_repo , options[:maestro_repo])
|
166
|
-
oConfig.set(:branch , options[:branch])
|
167
|
-
oConfig.set(:test_box, File.expand_path(options[:test_box])) if options[:test_box] and File.directory?(File.expand_path(options[:test_box]))
|
168
|
-
|
169
|
-
PrcLib.warning("test_box is currently disabled in this version. It will be re-activated in newer version.") if options[:test_box]
|
170
|
-
|
171
|
-
if options[:key_path]
|
172
|
-
mFound = options[:key_path].match(/^(.*)(\.pub)?$/)
|
173
|
-
if mFound
|
174
|
-
key_path = File.expand_path(mFound[1])
|
175
|
-
if mFound[2] and not File.exists?(File.expand_path(mFound[1]+mFound[2]))
|
176
|
-
PrcLib.fatal(1, "'%s' is not a valid keypair files. At least the public key (.pub) is have to exist.")
|
177
|
-
end
|
178
|
-
oConfig.set(:keypair_path, key_path)
|
179
|
-
else
|
180
|
-
PrcLib.fatal(1, "'%s' is not a valid keypair files. At least the public key (.pub) is have to exist.")
|
181
|
-
end
|
182
|
-
end
|
183
|
-
aProcesses = []
|
184
|
-
|
185
|
-
# Defines how to manage Maestro and forges
|
186
|
-
# create a maestro box. Identify a forge instance, delete it,...
|
187
|
-
aProcesses << File.join($LIB_PATH, 'forj', 'ForjCore.rb')
|
188
|
-
|
189
|
-
# Defines how cli will control FORJ features
|
190
|
-
# boot/down/ssh/...
|
191
|
-
aProcesses << File.join($LIB_PATH, 'forj', 'ForjCli.rb')
|
192
|
-
|
193
|
-
#oCloud = ForjCloud.new(oForjAccount, oConfig[:account_name], aProcesses)
|
194
|
-
oCloud = Lorj::CloudCore.new(oForjAccount, oConfig[:account_name], aProcesses)
|
195
|
-
|
196
|
-
oConfig[:instance_name] = name
|
197
|
-
|
198
|
-
if blueprint == 'maestro'
|
199
|
-
PrcLib.info("Starting boot process of '%s'. No blueprint requested." % oConfig[:instance_name])
|
200
|
-
else
|
201
|
-
oConfig[:blueprint] = blueprint
|
202
|
-
PrcLib.info("Starting boot process of '%s' with blueprint '%s'." % [oConfig[:instance_name], oConfig[:blueprint]])
|
203
|
-
end
|
204
|
-
|
205
|
-
PrcLib.high_level_msg ("Preparing your forge '%s'. Please be patient. more output in '%s'\n" % [oConfig[:instance_name], File.join($FORJ_DATA_PATH, "forj.log")])
|
206
|
-
|
207
|
-
oCloud.Create(:forge)
|
110
|
+
method_option :account_name, :aliases => '-a', :desc => 'Set the forj' \
|
111
|
+
' account name to use. By default, uses the default account set in' \
|
112
|
+
' your local config file.' + "\n\n" + 'Following options superseed your' \
|
113
|
+
' Account, config file or forj defaults.'
|
114
|
+
method_option :maestro_repo, :aliases => '-m', :desc => 'config: ' \
|
115
|
+
' maestro_repo : To use a different Maestro repository already' \
|
116
|
+
' cloned.' + "\n" + 'By default, Maestro is systematically cloned ' \
|
117
|
+
' to ~/.forj/maestro from github.'
|
118
|
+
method_option :infra, :aliases => '-r', :desc => 'config:' \
|
119
|
+
' infra_repo : Defines your Infra directory to use while' \
|
120
|
+
' booting. You can also set FORJ_INFRA_DIR.'
|
121
|
+
method_option :key_name, :aliases => '-k', :desc => 'config:' \
|
122
|
+
' keypair_name : Keypair name to use.'
|
123
|
+
method_option :key_path, :aliases => '-p', :desc => 'config:' \
|
124
|
+
' keypair_path : Private or Public key file to use.'
|
125
|
+
method_option :security_group, :aliases => '-s', :desc => 'config:' \
|
126
|
+
' security_group: Security group name to use and configure.'
|
127
|
+
method_option :image_name, :aliases => '-i', :desc => 'config:' \
|
128
|
+
' image_name : Image name to use to build Maestro and blueprint nodes.'
|
129
|
+
method_option :maestro_flavor, :aliases => '-f', :desc => 'config:' \
|
130
|
+
' flavor : Maestro flavor to use.'
|
131
|
+
method_option :bp_flavor, :aliases => '-b', :desc => 'config:' \
|
132
|
+
' bp_flavor : Blueprint nodes default flavor to use.' \
|
133
|
+
+ "\n\n" + ' Build system options:'
|
134
|
+
method_option :boothook, :aliases => '-H', :desc => 'By default, ' \
|
135
|
+
' boothook file used is build/bin/build-tools/boothook.sh. ' \
|
136
|
+
' Use this option to set another one.'
|
137
|
+
method_option :build, :aliases => '-B', :desc => 'Replace' \
|
138
|
+
' the default build.sh'
|
139
|
+
method_option :branch, :aliases => '-R', :desc => 'Branch' \
|
140
|
+
'name to clone for maestro.' \
|
141
|
+
+ "\n\n" + 'Maestro/infra bootstrap debugging:'
|
142
|
+
method_option :test_box, :aliases => '-T', :desc => 'Identify a' \
|
143
|
+
' path to become your test-box repository.' \
|
144
|
+
"\n " \
|
145
|
+
'Ex: if your maestro is in ~/src/forj-oss, --test_box' \
|
146
|
+
' ~/src/forj-oss/maestro build.sh and' \
|
147
|
+
"\n " \
|
148
|
+
'test-box will send your local maestro repo to your box, for boot.'
|
149
|
+
|
150
|
+
def boot(blueprint, on_or_name, old_accountname = nil, as = nil,
|
151
|
+
old_name = nil)
|
152
|
+
Forj::Settings.common_options(options)
|
153
|
+
require 'boot.rb'
|
154
|
+
|
155
|
+
deprecated_name = [old_accountname, as, old_name]
|
156
|
+
|
157
|
+
Forj::Boot.boot(blueprint, on_or_name, deprecated_name, options)
|
208
158
|
end
|
209
159
|
|
210
|
-
################################# Show defaults
|
211
|
-
desc 'show <Object> [name]', 'Show Object (default valuesr, account data, etc...) values.'
|
160
|
+
################################# Show defaults
|
212
161
|
long_desc <<-LONGDESC
|
213
|
-
This command helps to show values used by 'forj' to boot a blueprint
|
162
|
+
This command helps to show values used by 'forj' to boot a blueprint
|
163
|
+
(account data, default values, etc...)
|
214
164
|
|
215
165
|
queriable Objects:
|
216
166
|
|
217
|
-
- defaults : Provide the list of predefined values, configured by forj,
|
218
|
-
|
167
|
+
- defaults : Provide the list of predefined values, configured by forj,
|
168
|
+
or by you in your ~/.forj/config.yaml (or another config file with -c)
|
169
|
+
- account [name] : without name, forj will give you the list of account saved.
|
170
|
+
Otherwise print 'name' account data.
|
219
171
|
LONGDESC
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
|
226
|
-
|
227
|
-
|
228
|
-
|
229
|
-
|
230
|
-
|
231
|
-
|
232
|
-
|
233
|
-
|
234
|
-
|
235
|
-
|
236
|
-
|
237
|
-
|
238
|
-
|
239
|
-
|
240
|
-
|
241
|
-
|
242
|
-
|
243
|
-
|
244
|
-
|
245
|
-
puts '---'
|
246
|
-
puts "To change those values, execute 'forj setup -a %s'." % options[:account_name]
|
247
|
-
end
|
248
|
-
|
249
|
-
else
|
250
|
-
PrcLib.error("object '%s' unknown." % name)
|
172
|
+
desc 'show <Object> [name]', 'Show Object (default valuesr, account data,' \
|
173
|
+
' etc...) values.'
|
174
|
+
def show(object, name = nil)
|
175
|
+
Forj::Settings.common_options(options)
|
176
|
+
|
177
|
+
case object
|
178
|
+
when 'defaults'
|
179
|
+
o_config = Lorj::Account.new
|
180
|
+
|
181
|
+
puts 'List of default values: (local refer to your config file.' \
|
182
|
+
' hash refer to your FORJ account data)'
|
183
|
+
|
184
|
+
dump = o_config.config_dump(%w(account local))
|
185
|
+
dump[:application] = o_config.config_dump(%w(default))[:default]
|
186
|
+
puts dump.to_yaml
|
187
|
+
puts '---'
|
188
|
+
puts "To change default values, use 'forj get' to check valid keys," \
|
189
|
+
" and update with 'forj set'"
|
190
|
+
when 'account'
|
191
|
+
unless name
|
192
|
+
puts "List of FORJ accounts: Use 'forj account YourAccount' " \
|
193
|
+
' to see one account details.'
|
194
|
+
o_accounts = Lorj::Accounts.new
|
195
|
+
puts o_accounts.dump.to_yaml
|
196
|
+
return
|
251
197
|
end
|
252
|
-
|
253
|
-
|
254
|
-
################################# DESTROY
|
255
|
-
desc 'destroy <InstanceName> [options]', 'delete the Maestro box and all systems installed by the blueprint'
|
256
|
-
long_desc <<-LONGDESC
|
257
|
-
This action destroy all servers found under the instance name and allow you to destroy all of them or just one of them.
|
258
|
-
|
259
|
-
Warning! This action do not remove any network/security groups cloud object.
|
260
|
-
LONGDESC
|
261
|
-
|
262
|
-
method_option :force, :aliases => "-f", :desc => "force deletion of all servers for the given InstanceName"
|
263
|
-
|
264
|
-
def destroy(name)
|
265
|
-
Forj::Settings.common_options(options)
|
266
|
-
|
267
|
-
oConfig = Lorj::Config.new(options[:config])
|
268
|
-
oConfig.set(:account_name, options[:account_name]) if options[:account_name]
|
269
|
-
oForjAccount = Lorj::Account.new(oConfig)
|
270
|
-
oForjAccount.ac_load()
|
271
|
-
|
272
|
-
aProcesses = []
|
273
|
-
|
274
|
-
# Defines how to manage Maestro and forges
|
275
|
-
# create a maestro box. Identify a forge instance, delete it,...
|
276
|
-
aProcesses << File.join($LIB_PATH, 'forj', 'ForjCore.rb')
|
277
|
-
|
278
|
-
# Defines how cli will control FORJ features
|
279
|
-
# boot/down/ssh/...
|
280
|
-
aProcesses << File.join($LIB_PATH, 'forj', 'ForjCli.rb')
|
281
|
-
|
282
|
-
oCloud = Lorj::CloudCore.new(oForjAccount, oConfig[:account_name], aProcesses)
|
283
|
-
|
284
|
-
oForge = oCloud.Get(:forge, name)
|
285
|
-
|
286
|
-
if oForge[:servers].count > 0
|
198
|
+
o_config = Lorj::Account.new
|
199
|
+
o_config[:account_name] = name
|
287
200
|
|
288
|
-
|
289
|
-
|
290
|
-
oCloud.Delete(:forge)
|
291
|
-
else
|
292
|
-
#Ask the user to get server(s) to destroy
|
293
|
-
serverList = []
|
294
|
-
index = 0
|
201
|
+
PrcLib.fatal(1, "Unable to load the account '%s'",
|
202
|
+
name) unless o_config.ac_load o_config[:account_name]
|
295
203
|
|
296
|
-
|
297
|
-
|
298
|
-
|
299
|
-
|
204
|
+
puts format("Account value for '%s':", name)
|
205
|
+
puts o_config.config_dump([%(account)]).to_yaml
|
206
|
+
puts '---'
|
207
|
+
puts format("To change those values, execute 'forj setup -a %s'.",
|
208
|
+
options[:account_name])
|
300
209
|
|
301
|
-
|
302
|
-
|
303
|
-
|
304
|
-
|
305
|
-
value = choose { | q |
|
306
|
-
q.choices(*serverList)
|
307
|
-
}
|
308
|
-
|
309
|
-
oServerNumber = serverList.index(value)
|
310
|
-
|
311
|
-
if oServerNumber >= 0 and oServerNumber < oForge[:servers].count
|
312
|
-
#Destroy selected server
|
313
|
-
oConfig.set(:forge_server, oForge[:servers][oServerNumber][:id] )
|
314
|
-
oCloud.Delete(:forge)
|
315
|
-
elsif oServerNumber == serverList.index("all")
|
316
|
-
#Destroy all servers found
|
317
|
-
oCloud.Delete(:forge)
|
318
|
-
elsif oServerNumber == serverList.index("esc")
|
319
|
-
#esc
|
320
|
-
PrcLib.high_level_msg("No server destroyed on your demand.\n" % name )
|
321
|
-
end
|
210
|
+
else
|
211
|
+
PrcLib.error("object '%s' unknown.", name)
|
212
|
+
end
|
213
|
+
end
|
322
214
|
|
323
|
-
|
215
|
+
################################# DESTROY
|
216
|
+
desc 'destroy <InstanceName> [options]', 'delete the Maestro box and all' \
|
217
|
+
' systems installed by the blueprint'
|
218
|
+
long_desc <<-LONGDESC
|
219
|
+
This action destroy all servers found under the instance name and allow you
|
220
|
+
to destroy all of them or just one of them.
|
324
221
|
|
325
|
-
|
326
|
-
|
327
|
-
end
|
222
|
+
Warning! This action do not remove any network/security groups cloud object.
|
223
|
+
LONGDESC
|
328
224
|
|
329
|
-
|
225
|
+
method_option :force, :aliases => '-f', :desc => 'force deletion of all' \
|
226
|
+
' servers for the given InstanceName'
|
227
|
+
def destroy(name)
|
228
|
+
require 'destroy.rb'
|
229
|
+
Forj::Settings.common_options(options)
|
230
|
+
Forj::Destroy.destroy(name, options)
|
231
|
+
end
|
330
232
|
|
331
|
-
################################# SET
|
332
|
-
desc 'set [key=value] [...] [options]', 'Set one or more variables in
|
233
|
+
################################# SET
|
234
|
+
desc 'set [key=value] [...] [options]', 'Set one or more variables in' \
|
235
|
+
' defaults or a forj account.'
|
333
236
|
long_desc <<-LONGDESC
|
334
|
-
You can set some variables to change 'forj' defaults
|
237
|
+
You can set some variables to change 'forj' defaults
|
238
|
+
or specifically some account data.
|
239
|
+
|
240
|
+
Ex: By default, forj use ~/.ssh/forj-id_rsa as keypair for all forge instance.
|
241
|
+
During setup, if this keypair doesn't exist, it proposes to create it for you,
|
242
|
+
with ssh-keygen.
|
335
243
|
|
336
|
-
|
337
|
-
|
244
|
+
If you want to use a keypair that already exists,
|
245
|
+
you can set it as your default, with:
|
338
246
|
|
339
247
|
`forj set keypair_name=~/.ssh/id_rsa`
|
340
248
|
|
@@ -346,112 +254,112 @@ Ex: By default, forj use ~/.ssh/forj-id_rsa as keypair for all forge instance. D
|
|
346
254
|
|
347
255
|
`forj set`
|
348
256
|
|
349
|
-
If you want to remove the key from dev, and ask for to re-use defaults
|
257
|
+
If you want to remove the key from dev, and ask for to re-use defaults
|
258
|
+
(from your config or application default)
|
350
259
|
|
351
260
|
`forj set keypair_name= -a dev`
|
352
261
|
|
353
|
-
If you want to remove the key from your default,
|
262
|
+
If you want to remove the key from your default,
|
263
|
+
and re-use application default
|
354
264
|
|
355
265
|
`forj set keypair_name=`
|
356
266
|
|
357
267
|
LONGDESC
|
358
268
|
|
359
|
-
method_option :account_name, :aliases => '-a', :desc =>
|
360
|
-
|
361
|
-
|
362
|
-
Logging.set_level(Logger::INFO) if options[:verbose]
|
363
|
-
Logging.set_level(Logger::DEBUG) if options[:debug]
|
364
|
-
|
365
|
-
oConfig=Lorj::Config.new()
|
366
|
-
|
367
|
-
if p.length == 0 and not options[:account_name]
|
368
|
-
Forj::Settings::config_show_all(oConfig)
|
269
|
+
method_option :account_name, :aliases => '-a', :desc => 'Set the forj' \
|
270
|
+
' account name to use. By default, uses the default account set in your' \
|
271
|
+
' local config file.'
|
369
272
|
|
370
|
-
|
371
|
-
|
273
|
+
def set(*p)
|
274
|
+
PrcLib.level = Logger::INFO if options[:verbose]
|
275
|
+
PrcLib.level = Logger::DEBUG if options[:debug]
|
372
276
|
|
373
|
-
|
374
|
-
|
375
|
-
|
376
|
-
|
377
|
-
|
378
|
-
|
379
|
-
end
|
277
|
+
if p.length == 0
|
278
|
+
Forj::Settings.show_settings(options)
|
279
|
+
else
|
280
|
+
Forj::Settings.set_settings(options, p)
|
281
|
+
end
|
282
|
+
end
|
380
283
|
|
381
|
-
################################# GET
|
382
|
-
|
383
|
-
|
284
|
+
################################# GET
|
285
|
+
desc 'get', 'Get data from defaults or account values.'
|
286
|
+
long_desc <<-LONGDESC
|
384
287
|
forj cli maintain a list of key/value at 3 Levels:
|
385
288
|
\x5- Application defaults
|
386
289
|
\x5- Local config defaults
|
387
290
|
\x5- Account data
|
388
291
|
|
389
|
-
This function will help you identify which value has been retrieved from
|
292
|
+
This function will help you identify which value has been retrieved from
|
293
|
+
which level.
|
390
294
|
|
391
|
-
Ex: To get the default keypair_name, from your ~/.forj/config.yaml,
|
295
|
+
Ex: To get the default keypair_name, from your ~/.forj/config.yaml,
|
296
|
+
or if not found, from application defaults.
|
392
297
|
|
393
298
|
`forj get keypair_name`
|
394
299
|
|
395
|
-
Ex: To get the keypair_name defined from the account,
|
300
|
+
Ex: To get the keypair_name defined from the account,
|
301
|
+
or from your ~/.forj/config.yaml, or if not found, from application defaults.
|
396
302
|
|
397
303
|
`forj get keypair_name -a dev`
|
398
304
|
|
399
305
|
|
400
306
|
LONGDESC
|
401
307
|
|
402
|
-
|
403
|
-
|
404
|
-
|
405
|
-
PrcLib.set_level(Logger::INFO) if options[:verbose]
|
406
|
-
PrcLib.set_level(Logger::DEBUG) if options[:debug]
|
407
|
-
|
408
|
-
oConfig = Lorj::Config.new()
|
409
|
-
if not options[:account_name] and not key
|
410
|
-
Forj::Settings::config_get_all(oConfig)
|
411
|
-
|
412
|
-
elsif options[:account_name] and key
|
413
|
-
Forj::Settings::account_get(oConfig, options[:account_name], key)
|
308
|
+
method_option :account_name, :aliases => '-a', :desc => 'Set the forj' \
|
309
|
+
' account name to use. By default, uses the default account set in your' \
|
310
|
+
' local config file.'
|
414
311
|
|
415
|
-
|
416
|
-
|
312
|
+
def get(key = nil)
|
313
|
+
PrcLib.level = Logger::INFO if options[:verbose]
|
314
|
+
PrcLib.level = Logger::DEBUG if options[:debug]
|
417
315
|
|
418
|
-
|
419
|
-
|
420
|
-
|
421
|
-
end
|
316
|
+
require 'get.rb'
|
317
|
+
Forj::Get.get(options, key)
|
318
|
+
end
|
422
319
|
|
423
|
-
################################# SSH
|
424
|
-
|
425
|
-
|
320
|
+
################################# SSH
|
321
|
+
desc 'ssh <Instance> [options]', 'connect to your forge thru ssh'
|
322
|
+
long_desc <<-LONGDESC
|
426
323
|
Connect through ssh to a node attached to an instance
|
427
324
|
|
428
325
|
ex: forj ssh myforge -n review
|
429
326
|
LONGDESC
|
430
327
|
|
431
|
-
|
432
|
-
|
328
|
+
method_option :box_name, :aliases => '-n', :desc => 'box name to' \
|
329
|
+
' create ssh connection'
|
330
|
+
method_option :identity, :aliases => '-i', :desc => 'Private key' \
|
331
|
+
' file name.'
|
332
|
+
|
333
|
+
def ssh(oInstanceName)
|
334
|
+
Forj::Settings.common_options(options)
|
335
|
+
require 'ssh.rb'
|
433
336
|
|
434
|
-
|
435
|
-
Forj::Settings.common_options(options)
|
337
|
+
account = Lorj::Account.new(options[:config])
|
436
338
|
|
437
|
-
|
339
|
+
# Setting account at runtime layer
|
340
|
+
account[:account_name] = options[:account_name] if options[:account_name]
|
341
|
+
# Setting account at account layer
|
342
|
+
account.ac_load account[:account_name]
|
438
343
|
|
439
|
-
|
440
|
-
|
344
|
+
account.set(:box_ssh, options[:box_name]) if options[:box_name]
|
345
|
+
account.set(:identity, options[:identity]) if options[:identity]
|
441
346
|
|
442
|
-
|
443
|
-
|
347
|
+
Forj::Ssh.connect(oInstanceName, account)
|
348
|
+
end
|
444
349
|
|
445
|
-
################################# SETUP
|
350
|
+
################################# SETUP
|
446
351
|
|
447
|
-
desc 'setup [AccountName [Provider]] [options]',
|
352
|
+
desc 'setup [AccountName [Provider]] [options]', 'Setup FORJ cloud account' \
|
353
|
+
' credentials and information.'
|
448
354
|
|
449
355
|
long_desc <<-LONGDESC
|
450
356
|
This setup will configure a FORJ account used to connect to your cloud system.
|
451
357
|
\x5It will ask for your cloud provider credentials and services.
|
452
358
|
|
453
|
-
If AccountName is not set, 'hpcloud' will be used for AccountName
|
454
|
-
|
359
|
+
If AccountName is not set, 'hpcloud' will be used for AccountName
|
360
|
+
and provider name, by default.
|
361
|
+
\x5If AccountName is not set without provider, 'hpcloud' provider
|
362
|
+
will be used, by default.
|
455
363
|
|
456
364
|
WARNING! Currently supports only hpcloud provider.
|
457
365
|
|
@@ -461,33 +369,18 @@ Several data will be requested like:
|
|
461
369
|
\x5- DNS settings if you want Maestro to manage it.
|
462
370
|
\x5- domain name to add to each boxes hostname
|
463
371
|
LONGDESC
|
464
|
-
def setup(sAccountName = 'hpcloud', sProvider =
|
465
|
-
|
466
|
-
|
467
|
-
oConfig=Lorj::Config.new(options[:config])
|
468
|
-
oConfig.set(:provider_name, sProvider)
|
469
|
-
oConfig.set(:account_name, sAccountName)
|
470
|
-
|
471
|
-
aProcesses = []
|
472
|
-
|
473
|
-
# Defines how to manage Maestro and forges
|
474
|
-
# create a maestro box. Identify a forge instance, delete it,...
|
475
|
-
aProcesses << File.join($LIB_PATH, 'forj', 'ForjCore.rb')
|
476
|
-
|
477
|
-
# Defines how cli will control FORJ features
|
478
|
-
# boot/down/ssh/...
|
479
|
-
aProcesses << File.join($LIB_PATH, 'forj', 'ForjCli.rb')
|
372
|
+
def setup(sAccountName = 'hpcloud', sProvider = 'hpcloud')
|
373
|
+
Forj::Settings.common_options(options)
|
374
|
+
require 'cloud_connection.rb'
|
480
375
|
|
481
|
-
|
482
|
-
|
483
|
-
|
484
|
-
|
485
|
-
oCloud.Setup(:forge, sAccountName)
|
486
|
-
oCloud.config.ac_save()
|
376
|
+
account = Lorj::Account.new(options[:config])
|
377
|
+
account.set(:provider_name, sProvider)
|
378
|
+
account.set(:account_name, sAccountName)
|
487
379
|
|
380
|
+
o_cloud = Forj::CloudConnection.connect(account)
|
381
|
+
o_cloud.setup(:forge, sAccountName)
|
382
|
+
o_cloud.config.ac_save
|
488
383
|
end
|
489
|
-
|
490
384
|
end
|
491
385
|
|
492
|
-
|
493
386
|
ForjThor.start
|