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.
data/lib/get.rb ADDED
@@ -0,0 +1,51 @@
1
+ #!/usr/bin/env ruby
2
+ # encoding: UTF-8
3
+
4
+ # (c) Copyright 2014 Hewlett-Packard Development Company, L.P.
5
+ #
6
+ # Licensed under the Apache License, Version 2.0 (the "License");
7
+ # you may not use this file except in compliance with the License.
8
+ # You may obtain a copy of the License at
9
+ #
10
+ # http://www.apache.org/licenses/LICENSE-2.0
11
+ #
12
+ # Unless required by applicable law or agreed to in writing, software
13
+ # distributed under the License is distributed on an "AS IS" BASIS,
14
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
+ # See the License for the specific language governing permissions and
16
+ # limitations under the License.
17
+
18
+ require 'highline/import'
19
+
20
+ #
21
+ # Get module
22
+ #
23
+ module Forj
24
+ # This module gets your account/default configuration
25
+ module Get
26
+ def self.get(options, key)
27
+ @account = Lorj::Account.new
28
+ if options[:account_name]
29
+ get_account(options, key)
30
+ else
31
+ get_default(key)
32
+ end
33
+ end
34
+
35
+ def self.get_account(options, key)
36
+ if key
37
+ Forj::Settings.account_get(@account, options[:account_name], key)
38
+ else
39
+ Forj::Settings.account_get_all(@account, options[:account_name])
40
+ end
41
+ end
42
+
43
+ def self.get_default(key)
44
+ if !key
45
+ Forj::Settings.config_get_all(@account)
46
+ else
47
+ Forj::Settings.config_get(@account, key)
48
+ end
49
+ end
50
+ end
51
+ end
data/lib/ssh.rb CHANGED
@@ -15,97 +15,105 @@
15
15
  # See the License for the specific language governing permissions and
16
16
  # limitations under the License.
17
17
 
18
- #~ require 'rubygems'
19
-
18
+ # ~ require 'rubygems'
19
+ require 'lorj'
20
20
  require 'highline/import'
21
+ require 'cloud_connection.rb'
21
22
 
22
- #~ require 'security.rb'
23
- #~ include SecurityGroup
23
+ # ~ require 'security.rb'
24
+ # ~ include SecurityGroup
24
25
 
25
26
  #
26
27
  # ssh module
27
28
  #
28
29
  module Forj
29
- module Ssh
30
-
31
- def Ssh.connect(name, oConfig)
32
- oForjAccount = Lorj::Account.new(oConfig)
33
-
34
- oForjAccount.ac_load()
35
-
36
- aProcesses = []
37
-
38
- # Defines how to manage Maestro and forges
39
- # create a maestro box. Identify a forge instance, delete it,...
40
- aProcesses << File.join($LIB_PATH, 'forj', 'ForjCore.rb')
41
-
42
- # Defines how cli will control FORJ features
43
- # boot/down/ssh/...
44
- aProcesses << File.join($LIB_PATH, 'forj', 'ForjCli.rb')
45
-
46
- oCloud = Lorj::CloudCore.new(oForjAccount, oConfig[:account_name], aProcesses)
47
-
48
- PrcLib.state("Getting information about forge '%s'" % name)
49
-
50
- oForge = oCloud.Get(:forge, name)
51
-
52
- if oForge[:servers].count > 0
53
- if oConfig[:box_ssh]
54
- box_ssh = oConfig[:box_ssh]
55
-
56
- oServer = nil
57
- regex = Regexp.new('%s\.%s$' % [box_ssh, name])
58
-
59
- oForge[:servers].each { |server|
60
- oName = server[:name]
61
- next if (regex =~ oName) == nil
62
- oServer = server
63
- break
64
- }
65
-
66
- if oServer != nil
67
- #Property for :forge
68
- oConfig.set(:instance_name, name)
69
- #Property for :ssh
70
- oConfig.set(:forge_server, oServer[:id])
71
-
72
- oCloud.Create(:ssh)
73
- else
74
- PrcLib.debug("server '%s.%s' was not found" % [oConfig[:box_ssh], name] )
75
- PrcLib.high_level_msg("server '%s.%s' was not found.\n" % [oConfig[:box_ssh], name] )
76
- end
30
+ # This module provides the behavior to create a ssh connection
31
+ module Ssh
32
+ def self.connect(name, account)
33
+ o_cloud = Forj::CloudConnection.connect(account)
34
+
35
+ PrcLib.state(format("Getting information about forge '%s'", name))
36
+
37
+ o_forge = o_cloud.get(:forge, name)
38
+
39
+ if o_forge[:servers].count > 0
40
+ if account[:box_ssh]
41
+ o_server = validate_server_name(name, account, o_forge)
42
+
43
+ if !o_server.nil?
44
+ ssh_connection(account, o_cloud, name, o_server[:id])
45
+ else
46
+ PrcLib.debug("server '%s.%s' was not found",
47
+ account[:box_ssh], name)
48
+ PrcLib.high_level_msg("server '%s.%s' was not found.\n",
49
+ account[:box_ssh], name)
50
+ end
51
+ else
52
+ o_server_number = select_forge_server(o_forge)
53
+
54
+ ssh_connection(
55
+ account,
56
+ o_cloud,
57
+ name,
58
+ o_forge[:servers][o_server_number][:id]
59
+ )
60
+ end
61
+ else
62
+ PrcLib.high_level_msg("No server(s) found for instance name '%s' \n",
63
+ name)
64
+ end
65
+ end
66
+
67
+ def self.select_forge_server(o_forge)
68
+ # Ask the user to get server(s) to create ssh connection
69
+ server_list = []
70
+ index = 0
71
+ s_default = nil
72
+ o_forge[:servers].each do |server|
73
+ server_list[index] = server[:name]
74
+ s_default = server[:name] if server[:name].include? 'maestro'
75
+ index += 1
76
+ end
77
77
 
78
- else
79
- #Ask the user to get server(s) to create ssh connection
80
- serverList = []
81
- index = 0
82
- sDefault = nil
83
- oForge[:servers].each{ |server|
84
- serverList[index] = server[:name]
85
- sDefault = server[:name] if server[:name].include? "maestro"
86
- index = index + 1
87
- }
78
+ say(format(
79
+ 'Select box for ssh connection %s',
80
+ ((s_default.nil?) ? '' : format(
81
+ 'Default: ' + "|%s|\n", s_default
82
+ ))
83
+ )
84
+ )
85
+ value = choose do |q|
86
+ q.choices(*server_list)
87
+ q.default = s_default unless s_default.nil?
88
+ end
88
89
 
89
- say("Select box for ssh connection %s" % ((sDefault.nil?)? "" : "Default: " + "|%s|\n" % sDefault))
90
- value = choose { | q |
91
- q.choices(*serverList)
92
- q.default = sDefault if not sDefault.nil?
93
- }
90
+ o_server_number = server_list.index(value)
91
+ o_server_number
92
+ end
94
93
 
95
- oServerNumber = serverList.index(value)
94
+ def self.ssh_connection(account, o_cloud, name, server_id)
95
+ # Property for :forge
96
+ account.set(:instance_name, name)
97
+ # Property for :ssh
98
+ account.set(:forge_server, server_id)
96
99
 
97
- #Property for :forge
98
- oConfig.set(:instance_name, name)
99
- #Property for :ssh
100
- oConfig.set(:forge_server, oForge[:servers][oServerNumber][:id])
100
+ o_cloud.create(:ssh)
101
+ end
101
102
 
102
- oCloud.Create(:ssh)
103
+ def self.validate_server_name(name, account, o_forge)
104
+ box_ssh = account[:box_ssh]
103
105
 
104
- end
105
- else
106
- PrcLib.high_level_msg("No server(s) found for instance name '%s' \n" % name )
107
- end
106
+ o_server = nil
107
+ regex = Regexp.new(format('%s\.%s$', box_ssh, name))
108
108
 
109
+ o_forge[:servers].each do |server|
110
+ o_name = server[:name]
111
+ next if (regex =~ o_name).nil?
112
+ o_server = server
113
+ break
109
114
  end
110
- end
115
+
116
+ o_server
117
+ end
118
+ end
111
119
  end
data/spec/boot_spec.rb CHANGED
@@ -14,4 +14,3 @@
14
14
  # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
15
  # See the License for the specific language governing permissions and
16
16
  # limitations under the License.
17
-
data/spec/spec_helper.rb CHANGED
@@ -1,12 +1,13 @@
1
1
  # This file was generated by the `rspec --init` command. Conventionally, all
2
2
  # specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
3
- # The generated `.rspec` file contains `--require spec_helper` which will cause this
4
- # file to always be loaded, without a need to explicitly require it in any files.
3
+ # The generated `.rspec` file contains `--require spec_helper` which will
4
+ # cause this file to always be loaded, without a need to explicitly require it
5
+ # in any files.
5
6
  #
6
7
  # Given that it is always loaded, you are encouraged to keep this file as
7
8
  # light-weight as possible. Requiring heavyweight dependencies from this file
8
- # will add to the boot time of your test.rb suite on EVERY test.rb run, even for an
9
- # individual file that may not need all of that loaded. Instead, make a
9
+ # will add to the boot time of your test.rb suite on EVERY test.rb run, even for
10
+ # an individual file that may not need all of that loaded. Instead, make a
10
11
  # separate helper file that requires this one and then use it only in the specs
11
12
  # that actually need it.
12
13
  #
@@ -14,65 +15,64 @@
14
15
  # users commonly want.
15
16
  #
16
17
  # See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
17
- RSpec.configure do |config|
18
- # The settings below are suggested to provide a good initial experience
19
- # with RSpec, but feel free to customize to your heart's content.
20
- =begin
21
- # These two settings work together to allow you to limit a spec run
22
- # to individual examples or groups you care about by tagging them with
23
- # `:focus` metadata. When nothing is tagged with `:focus`, all examples
24
- # get run.
25
- config.filter_run :focus
26
- config.run_all_when_everything_filtered = true
27
-
28
- # Many RSpec users commonly either run the entire suite or an individual
29
- # file, and it's useful to allow more verbose output when running an
30
- # individual spec file.
31
- if config.files_to_run.one?
32
- # Use the documentation formatter for detailed output,
33
- # unless a formatter has already been configured
34
- # (e.g. via a command-line flag).
35
- config.default_formatter = 'doc'
36
- end
37
-
38
- # Print the 10 slowest examples and example groups at the
39
- # end of the spec run, to help surface which specs are running
40
- # particularly slow.
41
- config.profile_examples = 10
42
-
43
- # Run specs in random order to surface order dependencies. If you find an
44
- # order dependency and want to debug it, you can fix the order by providing
45
- # the seed, which is printed after each run.
46
- # --seed 1234
47
- config.order = :random
48
-
49
- # Seed global randomization in this process using the `--seed` CLI option.
50
- # Setting this allows you to use `--seed` to deterministically reproduce
51
- # test.rb failures related to randomization by passing the same `--seed` value
52
- # as the one that triggered the failure.
53
- Kernel.srand config.seed
54
-
55
- # rspec-expectations config goes here. You can use an alternate
56
- # assertion/expectation library such as wrong or the stdlib/minitest
57
- # assertions if you prefer.
58
- config.expect_with :rspec do |expectations|
59
- # Enable only the newer, non-monkey-patching expect syntax.
60
- # For more details, see:
61
- # - http://myronmars.to/n/dev-blog/2012/06/rspecs-new-expectation-syntax
62
- expectations.syntax = :expect
63
- end
64
-
65
- # rspec-mocks config goes here. You can use an alternate test.rb double
66
- # library (such as bogus or mocha) by changing the `mock_with` option here.
67
- config.mock_with :rspec do |mocks|
68
- # Enable only the newer, non-monkey-patching expect syntax.
69
- # For more details, see:
70
- # - http://teaisaweso.me/blog/2013/05/27/rspecs-new-message-expectation-syntax/
71
- mocks.syntax = :expect
72
-
73
- # Prevents you from mocking or stubbing a method that does not exist on
74
- # a real object. This is generally recommended.
75
- mocks.verify_partial_doubles = true
76
- end
77
- =end
18
+ RSpec.configure do |_config|
19
+ # The settings below are suggested to provide a good initial experience
20
+ # with RSpec, but feel free to customize to your heart's content.
21
+ # # These two settings work together to allow you to limit a spec run
22
+ # # to individual examples or groups you care about by tagging them with
23
+ # # `:focus` metadata. When nothing is tagged with `:focus`, all examples
24
+ # # get run.
25
+ # config.filter_run :focus
26
+ # config.run_all_when_everything_filtered = true
27
+ #
28
+ # # Many RSpec users commonly either run the entire suite or an individual
29
+ # # file, and it's useful to allow more verbose output when running an
30
+ # # individual spec file.
31
+ # if config.files_to_run.one?
32
+ # # Use the documentation formatter for detailed output,
33
+ # # unless a formatter has already been configured
34
+ # # (e.g. via a command-line flag).
35
+ # config.default_formatter = 'doc'
36
+ # end
37
+ #
38
+ # # Print the 10 slowest examples and example groups at the
39
+ # # end of the spec run, to help surface which specs are running
40
+ # # particularly slow.
41
+ # config.profile_examples = 10
42
+ #
43
+ # # Run specs in random order to surface order dependencies. If you find an
44
+ # # order dependency and want to debug it, you can fix the order by
45
+ # # providing the seed, which is printed after each run.
46
+ # # --seed 1234
47
+ # config.order = :random
48
+ #
49
+ # # Seed global randomization in this process using the `--seed` CLI option.
50
+ # # Setting this allows you to use `--seed` to deterministically reproduce
51
+ # # test.rb failures related to randomization by passing the same `--seed`
52
+ # # value as the one that triggered the failure.
53
+ # Kernel.srand config.seed
54
+ #
55
+ # # rspec-expectations config goes here. You can use an alternate
56
+ # # assertion/expectation library such as wrong or the stdlib/minitest
57
+ # # assertions if you prefer.
58
+ # config.expect_with :rspec do |expectations|
59
+ # # Enable only the newer, non-monkey-patching expect syntax.
60
+ # # For more details, see:
61
+ # # - http://myronmars.to/n/dev-blog/2012/06/rspecs-new-expectation-syntax
62
+ # expectations.syntax = :expect
63
+ # end
64
+ #
65
+ # # rspec-mocks config goes here. You can use an alternate test.rb double
66
+ # # library (such as bogus or mocha) by changing the `mock_with`
67
+ # # option here.
68
+ # config.mock_with :rspec do |mocks|
69
+ # # Enable only the newer, non-monkey-patching expect syntax.
70
+ # # For more details, see:
71
+ # # - http://teaisaweso.me/blog/2013/05/27/rspecs-new-message-expectation-syntax/
72
+ # mocks.syntax = :expect
73
+ #
74
+ # # Prevents you from mocking or stubbing a method that does not exist on
75
+ # # a real object. This is generally recommended.
76
+ # mocks.verify_partial_doubles = true
77
+ # end
78
78
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: forj
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.3
4
+ version: 1.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - forj team
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-12-19 00:00:00.000000000 Z
11
+ date: 2015-02-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: thor
@@ -28,16 +28,16 @@ dependencies:
28
28
  name: fog
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - '='
31
+ - - ~>
32
32
  - !ruby/object:Gem::Version
33
- version: 1.19.0
33
+ version: 1.26.0
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - '='
38
+ - - ~>
39
39
  - !ruby/object:Gem::Version
40
- version: 1.19.0
40
+ version: 1.26.0
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: git
43
43
  requirement: !ruby/object:Gem::Requirement
@@ -142,28 +142,14 @@ dependencies:
142
142
  requirements:
143
143
  - - ~>
144
144
  - !ruby/object:Gem::Version
145
- version: 0.2.0
145
+ version: 1.0.2
146
146
  type: :runtime
147
147
  prerelease: false
148
148
  version_requirements: !ruby/object:Gem::Requirement
149
149
  requirements:
150
150
  - - ~>
151
151
  - !ruby/object:Gem::Version
152
- version: 0.2.0
153
- - !ruby/object:Gem::Dependency
154
- name: bundler
155
- requirement: !ruby/object:Gem::Requirement
156
- requirements:
157
- - - '>='
158
- - !ruby/object:Gem::Version
159
- version: '0'
160
- type: :development
161
- prerelease: false
162
- version_requirements: !ruby/object:Gem::Requirement
163
- requirements:
164
- - - '>='
165
- - !ruby/object:Gem::Version
166
- version: '0'
152
+ version: 1.0.2
167
153
  - !ruby/object:Gem::Dependency
168
154
  name: rake
169
155
  requirement: !ruby/object:Gem::Requirement
@@ -202,6 +188,7 @@ extra_rdoc_files: []
202
188
  files:
203
189
  - .gitignore
204
190
  - .gitreview
191
+ - .rubocop.yml
205
192
  - Gemfile
206
193
  - README.md
207
194
  - Rakefile
@@ -209,14 +196,18 @@ files:
209
196
  - forj.gemspec
210
197
  - forj/defaults.yaml
211
198
  - lib/appinit.rb
199
+ - lib/boot.rb
212
200
  - lib/build_tmpl/bootstrap_build.sh
213
201
  - lib/build_tmpl/build-env.py
214
202
  - lib/build_tmpl/write-mime-multipart.py
203
+ - lib/cloud_connection.rb
215
204
  - lib/cloud_test.rb
205
+ - lib/destroy.rb
216
206
  - lib/forj-settings.rb
217
207
  - lib/forj/ForjCli.rb
218
208
  - lib/forj/ForjCore.rb
219
209
  - lib/forj/process/ForjProcess.rb
210
+ - lib/get.rb
220
211
  - lib/ssh.rb
221
212
  - spec/boot_spec.rb
222
213
  - spec/down_spec.rb
@@ -259,3 +250,4 @@ test_files:
259
250
  - spec/setup_spec.rb
260
251
  - spec/spec_helper.rb
261
252
  - spec/ssh_spec.rb
253
+ has_rdoc: