forj 0.0.21 → 0.0.22

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/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --color
2
+ --warnings
3
+ --require spec_helper
data/.rubocop.yml ADDED
@@ -0,0 +1,22 @@
1
+ # (c) Copyright 2014 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
+ # limit lines to 80 characters.
16
+ LineLength:
17
+ Max: 200
18
+ Enabled: true
19
+ # disabled while we still support ruby 1.8
20
+ HashSyntax:
21
+ Description: 'Prefer Ruby 1.9 hash syntax over 1.8 syntax'
22
+ Enabled: false
data/Gemfile ADDED
@@ -0,0 +1,17 @@
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
+
data/README.md ADDED
@@ -0,0 +1,20 @@
1
+ Forj cli
2
+ =====================
3
+
4
+
5
+ How to use it
6
+ =====================
7
+
8
+
9
+ FORJ Team
10
+
11
+
12
+ Contributing to Forj
13
+ =====================
14
+ We welcome all types of contributions. Checkout our website (http://docs.forj.io/en/latest/dev/contribute.html)
15
+ to start hacking on Forj. Also join us in our community (https://www.forj.io/community/) to help grow and foster Forj for
16
+ your development today!
17
+
18
+ License
19
+ =====================
20
+ forj cli is licensed under the Apache License, Version 2.0. See LICENSE for full license text.
data/Rakefile ADDED
@@ -0,0 +1,31 @@
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
+
19
+ require 'rspec/core/rake_task'
20
+
21
+ task :default => [:spec]
22
+
23
+ desc 'Run the specs.'
24
+ RSpec::Core::RakeTask.new do |t|
25
+ t.pattern = 'spec/boot_spec.rb'
26
+ end
27
+
28
+ desc 'Run the specs whenever a relevant file changes.'
29
+ task :watch do
30
+ puts 'test'
31
+ end
data/bin/forj CHANGED
@@ -42,6 +42,7 @@ class Forj < Thor
42
42
  puts ' -as: just because :)'
43
43
  puts ' -name: name for the maestro box'
44
44
  puts ' -test: this will delete everything after it finish to install the forge'
45
+ puts ' example: forj boot redstone on hpcloud as redstone01'
45
46
  puts ' down: delete the Maestro box and all systems installed by the blueprint'
46
47
  puts ' -name: name for the maestro box'
47
48
  puts ' setup: set the credentials for forj cli'
@@ -54,11 +55,6 @@ class Forj < Thor
54
55
  puts ' tenant_id: id for the tenant you want to use'
55
56
  puts ' availability_zone: which availability zone will be deployed'
56
57
  puts ''
57
- puts ' openstack:'
58
- puts ' openstack_username: your openstack username'
59
- puts ' openstack_api_key: your openstack password'
60
- puts ' openstack_auth_url: your openstack identity endpoint'
61
- puts ''
62
58
  end
63
59
 
64
60
  desc 'boot', 'boot a Maestro box and instruct it to provision the blueprint'
data/lib/boot.rb CHANGED
@@ -25,6 +25,10 @@ require_relative 'security.rb'
25
25
  include SecurityGroup
26
26
  require_relative 'repositories.rb'
27
27
  include Repositories
28
+ require_relative 'log.rb'
29
+ include Logging
30
+ require_relative 'helpers.rb'
31
+ include Helpers
28
32
 
29
33
  #
30
34
  # Boot module
@@ -32,26 +36,23 @@ include Repositories
32
36
  module Boot
33
37
  def boot(blueprint, cloud_provider, name, build_config_dir, branch, test = false)
34
38
  begin
39
+ initial_msg = format('booting %{blueprint} on %{cloud_provider}',
40
+ blueprint: blueprint , cloud_provider: cloud_provider)
41
+ Logging.info(initial_msg)
42
+ puts (initial_msg)
35
43
 
36
- puts format('booting %{blueprint} on %{cloud_provider}',
37
- blueprint: blueprint , cloud_provider: cloud_provider)
38
-
39
- # get definitions from yaml
40
44
  forj_dir = File.expand_path(File.dirname(__FILE__))
41
45
  Dir.chdir(forj_dir)
42
46
  definitions = YamlParse.get_values('../lib/catalog.yaml')
43
47
 
44
- # clone the maestro repo
45
48
  Repositories.clone_repo
46
49
 
47
- # create the network where maestro will land
48
50
  network = Network.create_network(name)
49
51
  subnet = Network.create_subnet(network.id, name)
50
52
  router = Network.get_router(definitions[blueprint]['router'])
51
- Network::create_router_interface(subnet.id, router)
53
+ Network.create_router_interface(subnet.id, router)
52
54
 
53
- # create the security groups for the blueprint
54
- security_group = SecurityGroup::create_security_group(blueprint)
55
+ security_group = SecurityGroup.create_security_group(blueprint)
55
56
 
56
57
  ports = definitions['redstone']['ports']
57
58
 
@@ -61,21 +62,21 @@ module Boot
61
62
 
62
63
  ENV['FORJ_HPC_NETID'] = network.id
63
64
  ENV['FORJ_SECURITY_GROUP'] = security_group.name
64
- ENV['FORJ_KEYPAIR'] = definitions[blueprint]['keypair']
65
- ENV['FORJ_HPC_NOVA_KEYPUB'] = definitions[blueprint]['keypair']
65
+ #ENV['FORJ_KEYPAIR'] = definitions[blueprint]['keypair']
66
+ #ENV['FORJ_HPC_NOVA_KEYPUB'] = definitions[blueprint]['keypair']
66
67
 
67
68
  # run build.sh to boot maestro
68
69
  current_dir = Dir.pwd
69
- home = File.expand_path('~')
70
- build_path = home + '/.hpcloud/maestro/build'
70
+ home = Helpers.get_home_path
71
+ build_path = home + '/.forj/maestro/build'
71
72
  Dir.chdir(build_path)
72
73
 
73
74
  if build_config_dir
74
75
  command = format('bin/build.sh --build_ID maestro.%{name} --box-name maestro --build-conf-dir %{build_config_dir} --build-config box-13.5 --gitBranch %{branch}', name: name, build_config_dir: build_config_dir, branch: branch)
75
- #elsif name != 'redstone'
76
- # command = format('bin/build.sh --build_ID %{name} --box-name maestro --build-conf-dir ~/.hpcloud/maestro/build/conf --build-config box --blueprint %{blueprint_name}', name: name, blueprint_name: blueprint)
76
+ elsif blueprint != 'redstone'
77
+ command = format('bin/build.sh --build_ID %{name} --box-name maestro --build-conf-dir ~/.forj/maestro/build/conf --build-config box --blueprint %{blueprint_name}', name: name, blueprint_name: blueprint)
77
78
  else
78
- command = format('bin/build.sh --build_ID %{name} --box-name maestro --build-conf-dir ~/.hpcloud/maestro/build/conf --build-config box', name: name)
79
+ command = format('bin/build.sh --build_ID %{name} --box-name maestro --build-conf-dir ~/.forj/maestro/build/conf --build-config box', name: name)
79
80
  end
80
81
 
81
82
  Kernel.system(command)
@@ -89,9 +90,11 @@ module Boot
89
90
  end
90
91
 
91
92
  rescue SystemExit, Interrupt
92
- puts 'process interrupted by user'
93
+ msg = format('%{name} interrupted by user')
94
+ puts msg
95
+ Logging.info(msg)
93
96
  rescue StandardError => e
94
- puts e
97
+ Logging.error(e.message)
95
98
  end
96
99
  end
97
100
  end
data/lib/connection.rb CHANGED
@@ -25,36 +25,42 @@ include YamlParse
25
25
  # Connection module
26
26
  #
27
27
  module Connection
28
-
29
28
  def compute
30
- credentials = get_credentials
31
- Fog::Compute.new({
32
- :provider => 'HP',
33
- :hp_access_key => credentials['access_key'],
34
- :hp_secret_key => credentials['secret_key'],
35
- :hp_auth_uri => credentials['auth_uri'],
36
- :hp_tenant_id => credentials['tenant_id'],
37
- :hp_avl_zone => credentials['availability_zone'],
38
- :version => 'v2'
39
- })
29
+ begin
30
+ credentials = get_credentials
31
+ Fog::Compute.new({
32
+ :provider => 'HP',
33
+ :hp_access_key => credentials['access_key'],
34
+ :hp_secret_key => credentials['secret_key'],
35
+ :hp_auth_uri => credentials['auth_uri'],
36
+ :hp_tenant_id => credentials['tenant_id'],
37
+ :hp_avl_zone => credentials['availability_zone'],
38
+ :version => 'v2'
39
+ })
40
+ rescue => e
41
+ Logging.error(e.message)
42
+ end
40
43
  end
41
44
 
42
45
  def network
43
- credentials = get_credentials
44
- Fog::HP::Network.new({
45
- :hp_access_key => credentials['access_key'],
46
- :hp_secret_key => credentials['secret_key'],
47
- :hp_auth_uri => credentials['auth_uri'],
48
- :hp_tenant_id => credentials['tenant_id'],
49
- :hp_avl_zone => credentials['availability_zone']
50
- })
46
+ begin
47
+ credentials = get_credentials
48
+ Fog::HP::Network.new({
49
+ :hp_access_key => credentials['access_key'],
50
+ :hp_secret_key => credentials['secret_key'],
51
+ :hp_auth_uri => credentials['auth_uri'],
52
+ :hp_tenant_id => credentials['tenant_id'],
53
+ :hp_avl_zone => credentials['availability_zone']
54
+ })
55
+ rescue => e
56
+ Logging.error(e.message)
57
+ end
51
58
  end
52
-
53
59
  end
54
60
 
55
61
  def get_credentials
56
62
  home = File.expand_path('~')
57
- creds = '%s/.hpcloud/accounts/hp' % [home]
63
+ creds = format('%{home}/.hpcloud/accounts/hp', home: home)
58
64
  template = YAML.load_file(creds)
59
65
  credentials = Hash.new
60
66
 
@@ -63,10 +69,10 @@ def get_credentials
63
69
  credentials['secret_key'] = template[:credentials][:secret_key]
64
70
  credentials['auth_uri'] = template[:credentials][:auth_uri]
65
71
  credentials['tenant_id'] = template[:credentials][:tenant_id]
66
- credentials['availability_zone'] = template[:regions][:monitoring]
67
- rescue
68
- puts 'your credentials are not configured, delete the file %s and run forj setup again' % [creds]
72
+ credentials['availability_zone'] = template[:regions][:compute]
73
+ rescue => e
74
+ puts format('your credentials are not configured, delete the file %{creds} and run forj setup again', creds: creds)
75
+ Logging.error(e.message)
69
76
  end
70
-
71
77
  credentials
72
78
  end
data/lib/down.rb CHANGED
@@ -35,9 +35,6 @@ module Down
35
35
 
36
36
  definitions = YamlParse::get_values('../lib/catalog.yaml')
37
37
 
38
- # first step is to delete the instance
39
- Compute.delete_instance(name)
40
-
41
38
  # get the subnet
42
39
  subnet = Network::get_subnet(name)
43
40
 
data/lib/helpers.rb ADDED
@@ -0,0 +1,28 @@
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
+ module Helpers
19
+ def get_home_path
20
+ File.expand_path('~')
21
+ end
22
+
23
+ def create_directory(path)
24
+ unless File.directory?(path)
25
+ Dir.mkdir path
26
+ end
27
+ end
28
+ end
data/lib/log.rb ADDED
@@ -0,0 +1,63 @@
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
+
19
+ # create a forj.log file in ~/.hpcloud/forj.log
20
+
21
+ require 'logger'
22
+
23
+ require 'require_relative'
24
+
25
+ require_relative 'helpers.rb'
26
+ include Helpers
27
+
28
+ #
29
+ # Logging module
30
+ #
31
+ module Logging
32
+ def info(message)
33
+ home = Helpers.get_home_path
34
+ Helpers.create_directory(format('%{home}/.forj/', home: home))
35
+
36
+ log = format('%{home}/.forj/forj.log', home: home)
37
+ log = Logger.new(log)
38
+ log.level = Logger::DEBUG
39
+
40
+ log.formatter = proc do |severity, datetime, progname, msg|
41
+ "#{progname} : #{datetime}: #{severity}: #{msg} \n"
42
+ end
43
+
44
+ log.info(message)
45
+ end
46
+
47
+ def error(message)
48
+ home = Helpers.get_home_path
49
+ Helpers.create_directory(format('%{home}/.forj/', home: home))
50
+
51
+ log = format('%{home}/.forj/forj.log', home: home)
52
+ log = Logger.new(log)
53
+ log.level = Logger::ERROR
54
+
55
+ log.formatter = proc do |severity, datetime, progname, msg|
56
+ "#{progname} : #{datetime}: #{severity}: #{msg} \n"
57
+ end
58
+
59
+ log.error(message)
60
+ end
61
+ end
62
+
63
+
data/lib/network.rb CHANGED
@@ -19,107 +19,152 @@ require 'require_relative'
19
19
 
20
20
  require_relative 'connection.rb'
21
21
  include Connection
22
+ require_relative 'log.rb'
23
+ include Logging
22
24
 
23
25
  #
24
26
  # Network module
25
27
  #
26
28
  module Network
27
-
28
29
  def create_network(name)
29
- Connection.network.networks.create(:name => name)
30
+ begin
31
+ Logging.info(format('creating network %{name}', name: name))
32
+ Connection.network.networks.create(:name => name)
33
+ rescue => e
34
+ Logging.error(e.message)
35
+ end
30
36
  end
31
37
 
32
38
  def delete_network(network_name)
33
- network = Connection.network.networks.all(:name => network_name)[0]
34
- Connection.network.networks.get(network.id).destroy
39
+ begin
40
+ network = Connection.network.networks.all(:name => network_name)[0]
41
+ Connection.network.networks.get(network.id).destroy
42
+ rescue => e
43
+ Logging.error(e.message)
44
+ end
35
45
  end
36
46
 
37
47
  def create_subnet(network_id, name)
38
- Connection.network.subnets.create(
39
- :network_id => network_id,
40
- :name => name,
41
- :cidr => get_next_subnet,
42
- :ip_version => '4'
43
- )
48
+ begin
49
+ Connection.network.subnets.create(
50
+ :network_id => network_id,
51
+ :name => name,
52
+ :cidr => get_next_subnet,
53
+ :ip_version => '4'
54
+ )
55
+ rescue => e
56
+ Logging.error(e.message)
57
+ end
44
58
  end
45
59
 
46
60
  def delete_subnet(subnet_id)
47
- Connection.network.subnets.get(subnet_id).destroy
61
+ begin
62
+ Connection.network.subnets.get(subnet_id).destroy
63
+ rescue => e
64
+ Logging.error(e.message)
65
+ end
48
66
  end
49
67
 
50
68
  def get_subnet(name)
51
- Connection.network.subnets.all(:name => name)[0]
69
+ begin
70
+ Connection.network.subnets.all(:name => name)[0]
71
+ rescue => e
72
+ Logging.error(e.message)
73
+ end
52
74
  end
53
75
 
54
76
  def get_router(name)
55
- routers = Connection.network.routers.all({:name => name})
56
- router = nil
77
+ begin
78
+ routers = Connection.network.routers.all({:name => name})
79
+ router = nil
57
80
 
58
- routers.each do|r|
59
- router = r
60
- end
81
+ routers.each do|r|
82
+ router = r
83
+ end
61
84
 
62
- router
85
+ router
86
+ rescue => e
87
+ Logging.error(e.message)
88
+ end
63
89
  end
64
90
 
65
91
  def create_router_interface(subnet_id, router)
66
- router.add_interface(subnet_id, nil)
92
+ begin
93
+ router.add_interface(subnet_id, nil)
94
+ rescue => e
95
+ Logging.error(e.message)
96
+ end
67
97
  end
68
98
 
69
99
  def delete_router_interface(subnet_id, router)
70
- router.remove_interface(subnet_id)
100
+ begin
101
+ router.remove_interface(subnet_id)
102
+ rescue => e
103
+ Logging.error(e.message)
104
+ end
71
105
  end
72
106
 
73
107
  def create_router(name)
74
- Connection.network.routers.create(
75
- :name => name,
76
- :admin_state_up => true
77
- )
108
+ begin
109
+ Connection.network.routers.create(
110
+ :name => name,
111
+ :admin_state_up => true
112
+ )
113
+ rescue => e
114
+ Logging.error(e.message)
115
+ end
78
116
  end
79
117
 
80
118
  def delete_router(router_id)
81
- Connection.network.routers.get(router_id).destroy
119
+ begin
120
+ Connection.network.routers.get(router_id).destroy
121
+ rescue => e
122
+ Logging.error(e.message)
123
+ end
82
124
  end
83
-
84
125
  end
85
126
 
86
127
 
87
128
  def get_next_subnet
88
- subnet_values = Array.new
89
- subnets = Connection.network.subnets.all
129
+ begin
130
+ subnet_values = Array.new
131
+ subnets = Connection.network.subnets.all
90
132
 
91
- subnets.each do|s|
92
- subnet_values.push(s.cidr)
93
- end
133
+ subnets.each do|s|
134
+ subnet_values.push(s.cidr)
135
+ end
94
136
 
95
- gap = false
96
- count = 0
97
- range_used = Array.new
98
- new_subnet = 0
99
- new_cidr = ''
137
+ gap = false
138
+ count = 0
139
+ range_used = Array.new
140
+ new_subnet = 0
141
+ new_cidr = ''
100
142
 
101
- subnet_values = subnet_values.sort!
143
+ subnet_values = subnet_values.sort!
102
144
 
103
- subnet_values.each do|value|
104
- range_used.push(value[5])
105
- end
145
+ subnet_values.each do|value|
146
+ range_used.push(value[5])
147
+ end
106
148
 
107
- range_used.each do |n|
108
- if count.to_i == n.to_i
109
- else
110
- new_subnet = count
111
- gap = true
112
- break
149
+ range_used.each do |n|
150
+ if count.to_i == n.to_i
151
+ else
152
+ new_subnet = count
153
+ gap = true
154
+ break
155
+ end
156
+ count += 1
113
157
  end
114
- count += 1
115
- end
116
158
 
117
- if gap
118
- new_cidr = '10.0.%s.0/24' % [count]
119
- else
120
- max_value = range_used.max
121
- new_subnet = max_value.to_i + 1
122
- new_cidr = '10.0.%s.0/24' % [new_subnet]
159
+ if gap
160
+ new_cidr = '10.0.%s.0/24' % [count]
161
+ else
162
+ max_value = range_used.max
163
+ new_subnet = max_value.to_i + 1
164
+ new_cidr = '10.0.%s.0/24' % [new_subnet]
165
+ end
166
+ new_cidr
167
+ rescue => e
168
+ Logging.error(e.message)
123
169
  end
124
- new_cidr
125
170
  end
data/lib/repositories.rb CHANGED
@@ -21,6 +21,8 @@ require 'require_relative'
21
21
 
22
22
  require_relative 'yaml_parse.rb'
23
23
  include YamlParse
24
+ require_relative 'log.rb'
25
+ include Logging
24
26
 
25
27
  #
26
28
  # Repositories module
@@ -28,22 +30,29 @@ include YamlParse
28
30
  module Repositories
29
31
  def clone_repo
30
32
 
31
- definitions = YamlParse::get_values('../lib/catalog.yaml')
32
- maestro_url = definitions['default']['maestro']
33
+ current_dir = Dir.pwd
34
+ forj_dir = File.expand_path(File.dirname(__FILE__))
35
+ Dir.chdir(forj_dir)
33
36
 
34
- home = File.expand_path('~')
35
- path = home + '/.hpcloud/'
37
+ definitions = YamlParse::get_values('../lib/catalog.yaml')
38
+ maestro_url = definitions['default']['maestro']
36
39
 
37
- begin
38
- if File.directory?(path)
39
- if File.directory?(path + 'maestro')
40
- FileUtils.rm_r path + 'maestro'
40
+ home = File.expand_path('~')
41
+ path = home + '/.forj/'
42
+
43
+ begin
44
+ if File.directory?(path)
45
+ if File.directory?(path + 'maestro')
46
+ FileUtils.rm_r path + 'maestro'
47
+ end
48
+ Logging.info('cloning the maestro repo')
49
+ Git.clone(maestro_url, 'maestro', :path => path)
41
50
  end
42
- Git.clone(maestro_url, 'maestro', :path => path)
51
+ rescue => e
52
+ puts format('Error while cloning the repo from %{maestro_url}', maestro_url: maestro_url)
53
+ puts 'If this error persist you could clone the repo manually in ~/.forj/'
54
+ Logging.error(e.message)
43
55
  end
44
- rescue
45
- puts format('Error while cloning the repo from %{maestro_url}', maestro_url: maestro_url)
46
- puts 'If this error persist you could clone the repo manually in ~/.hpcloud/'
56
+ Dir.chdir(current_dir)
47
57
  end
48
- end
49
- end
58
+ end
data/lib/security.rb CHANGED
@@ -19,6 +19,8 @@ require 'require_relative'
19
19
 
20
20
  require_relative 'connection.rb'
21
21
  include Connection
22
+ require_relative 'log.rb'
23
+ include Logging
22
24
 
23
25
  #
24
26
  # SecurityGroup module
@@ -26,15 +28,30 @@ include Connection
26
28
  module SecurityGroup
27
29
 
28
30
  def create_security_group(name)
29
- description = format('Security group for blueprint %{name}', name: name)
30
- Connection.network.security_groups.create(
31
- :name => name,
32
- :description => description
33
- )
31
+ begin
32
+ sec_groups = get_security_group(name)
33
+ if sec_groups.length >= 1
34
+ sec_groups[0]
35
+ else
36
+ description = format('Security group for blueprint %{name}', name: name)
37
+ Logging.info(description)
38
+ Connection.network.security_groups.create(
39
+ :name => name,
40
+ :description => description
41
+ )
42
+ end
43
+ rescue => e
44
+ Logging.error(e.message)
45
+ end
34
46
  end
35
47
 
36
- def delete_security_group(security_group_id)
37
- Connection.network.security_groups.get(security_group_id).destroy
48
+ def delete_security_group(security_group)
49
+ begin
50
+ sec_group = get_security_group(security_group)
51
+ Connection.network.security_groups.get(sec_group.id).destroy
52
+ rescue => e
53
+ Logging.error(e.message)
54
+ end
38
55
  end
39
56
 
40
57
  def create_security_group_rule(security_group_id, protocol, port_min, port_max)
@@ -47,12 +64,26 @@ module SecurityGroup
47
64
  :port_range_max => port_max,
48
65
  :remote_ip_prefix => '0.0.0.0/0'
49
66
  )
50
- rescue StandardError
51
- puts format('error creating the rule for port %{port_min}', port_min: port_min)
67
+ rescue StandardError => e
68
+ msg = format('error creating the rule for port %{port_min}', port_min: port_min)
69
+ puts msg
70
+ Logging.error(e.message)
52
71
  end
53
72
  end
54
73
 
55
74
  def delete_security_group_rule(rule_id)
56
- Connection.network.security_group_rules.get(rule_id).destroy
75
+ begin
76
+ Connection.network.security_group_rules.get(rule_id).destroy
77
+ rescue => e
78
+ Logging.error(e.message)
79
+ end
80
+ end
81
+
82
+ def get_security_group(name)
83
+ begin
84
+ Connection.network.security_groups.all({:name => name})
85
+ rescue => e
86
+ Logging.error(e.message)
87
+ end
57
88
  end
58
89
  end
data/lib/yaml_parse.rb CHANGED
@@ -16,12 +16,19 @@
16
16
  # limitations under the License.
17
17
 
18
18
  require 'yaml'
19
+ require_relative 'log.rb'
20
+ include Logging
19
21
 
20
22
  #
21
23
  # YamlParse module
22
24
  #
23
25
  module YamlParse
24
26
  def get_values(path_to_yaml)
25
- YAML.load_file(path_to_yaml)
27
+ begin
28
+ Logging.info('getting values from catalog.yaml, this will be a service catalog.forj.io')
29
+ YAML.load_file(path_to_yaml)
30
+ rescue => e
31
+ Logging.error(e.message)
32
+ end
26
33
  end
27
34
  end
data/spec/boot_spec.rb ADDED
@@ -0,0 +1,27 @@
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 'require_relative'
19
+
20
+ require_relative '../lib/boot.rb'
21
+ include Boot
22
+
23
+ require 'spec_helper'
24
+
25
+ describe 'boot' do
26
+ it 'is booting maestro'
27
+ end
@@ -0,0 +1,55 @@
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 'spec_helper'
19
+
20
+ require 'fog'
21
+
22
+ require_relative '../lib/connection.rb'
23
+ include Connection
24
+
25
+ class TestClass
26
+ end
27
+
28
+ describe 'network' do
29
+ it 'is connecting to hpcloud' do
30
+ @test_class = TestClass.new
31
+ @test_class.extend(Connection)
32
+
33
+ Fog.mock!
34
+
35
+ conn = @test_class.network
36
+ expect(conn).to be
37
+
38
+ Fog::Mock.reset
39
+ end
40
+ end
41
+
42
+
43
+ describe 'compute' do
44
+ it 'is connecting to hpcloud' do
45
+ @test_class = TestClass.new
46
+ @test_class.extend(Connection)
47
+
48
+ Fog.mock!
49
+
50
+ conn = @test_class.compute
51
+ expect(conn).to be
52
+
53
+ Fog::Mock.reset
54
+ end
55
+ end
data/spec/down_spec.rb ADDED
@@ -0,0 +1,16 @@
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.
@@ -0,0 +1,16 @@
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.
@@ -0,0 +1,36 @@
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 'spec_helper'
19
+
20
+ require 'fog'
21
+
22
+ require_relative '../lib/repositories.rb'
23
+ include Repositories
24
+
25
+ class TestClass
26
+ end
27
+
28
+ describe 'repositories' do
29
+ it 'its clonning the repo' do
30
+ @test_class = TestClass.new
31
+ @test_class.extend(Repositories)
32
+
33
+ repo = @test_class.clone_repo
34
+ expect(repo).to be
35
+ end
36
+ end
@@ -0,0 +1,16 @@
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.
@@ -0,0 +1,78 @@
1
+ # This file was generated by the `rspec --init` command. Conventionally, all
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.
5
+ #
6
+ # Given that it is always loaded, you are encouraged to keep this file as
7
+ # light-weight as possible. Requiring heavyweight dependencies from this file
8
+ # will add to the boot time of your test suite on EVERY test run, even for an
9
+ # individual file that may not need all of that loaded. Instead, make a
10
+ # separate helper file that requires this one and then use it only in the specs
11
+ # that actually need it.
12
+ #
13
+ # The `.rspec` file also contains a few flags that are not defaults but that
14
+ # users commonly want.
15
+ #
16
+ # 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 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 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
78
+ end
data/spec/ssh_spec.rb ADDED
@@ -0,0 +1,16 @@
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.
@@ -0,0 +1,16 @@
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.
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: forj
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.21
4
+ version: 0.0.22
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -13,7 +13,7 @@ date: 2014-06-12 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: thor
16
- requirement: &7349140 !ruby/object:Gem::Requirement
16
+ requirement: &16918740 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: 0.16.0
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *7349140
24
+ version_requirements: *16918740
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: fog
27
- requirement: &7348600 !ruby/object:Gem::Requirement
27
+ requirement: &16918200 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ! '>='
@@ -32,10 +32,10 @@ dependencies:
32
32
  version: 1.22.1
33
33
  type: :runtime
34
34
  prerelease: false
35
- version_requirements: *7348600
35
+ version_requirements: *16918200
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: hpcloud
38
- requirement: &7348000 !ruby/object:Gem::Requirement
38
+ requirement: &16917580 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ! '>='
@@ -43,10 +43,10 @@ dependencies:
43
43
  version: 2.0.6
44
44
  type: :runtime
45
45
  prerelease: false
46
- version_requirements: *7348000
46
+ version_requirements: *16917580
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: git
49
- requirement: &7347400 !ruby/object:Gem::Requirement
49
+ requirement: &16916860 !ruby/object:Gem::Requirement
50
50
  none: false
51
51
  requirements:
52
52
  - - ! '>='
@@ -54,10 +54,10 @@ dependencies:
54
54
  version: 1.2.7
55
55
  type: :runtime
56
56
  prerelease: false
57
- version_requirements: *7347400
57
+ version_requirements: *16916860
58
58
  - !ruby/object:Gem::Dependency
59
59
  name: rbx-require-relative
60
- requirement: &7346620 !ruby/object:Gem::Requirement
60
+ requirement: &16915980 !ruby/object:Gem::Requirement
61
61
  none: false
62
62
  requirements:
63
63
  - - ! '>='
@@ -65,7 +65,7 @@ dependencies:
65
65
  version: 0.0.9
66
66
  type: :runtime
67
67
  prerelease: false
68
- version_requirements: *7346620
68
+ version_requirements: *16915980
69
69
  description: forj command line
70
70
  email:
71
71
  - forj@forj.io
@@ -85,6 +85,22 @@ files:
85
85
  - lib/setup.rb
86
86
  - lib/repositories.rb
87
87
  - lib/ssh.rb
88
+ - lib/log.rb
89
+ - lib/helpers.rb
90
+ - spec/boot_spec.rb
91
+ - spec/connection_spec.rb
92
+ - spec/down_spec.rb
93
+ - spec/network_spec.rb
94
+ - spec/repositories_spec.rb
95
+ - spec/setup_spec.rb
96
+ - spec/spec_helper.rb
97
+ - spec/ssh_spec.rb
98
+ - spec/yaml_parse_spec.rb
99
+ - Rakefile
100
+ - Gemfile
101
+ - README.md
102
+ - .rspec
103
+ - .rubocop.yml
88
104
  homepage: https://forj.io
89
105
  licenses:
90
106
  - Apache License, Version 2.0.