bebox 0.1.3 → 0.1.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +3 -18
- data/bebox.gemspec +1 -1
- data/lib/bebox.rb +1 -0
- data/lib/bebox/cli.rb +7 -1
- data/lib/bebox/commands/commands_helper.rb +2 -2
- data/lib/bebox/commands/environment_commands.rb +6 -6
- data/lib/bebox/commands/general_commands.rb +2 -2
- data/lib/bebox/commands/node_commands.rb +18 -14
- data/lib/bebox/commands/prepare_commands.rb +17 -14
- data/lib/bebox/commands/profile_commands.rb +8 -8
- data/lib/bebox/commands/provision_commands.rb +7 -7
- data/lib/bebox/commands/role_commands.rb +14 -14
- data/lib/bebox/logger.rb +2 -0
- data/lib/bebox/node.rb +0 -1
- data/lib/bebox/profile.rb +1 -1
- data/lib/bebox/project.rb +1 -1
- data/lib/bebox/vagrant_helper.rb +5 -3
- data/lib/bebox/version.rb +1 -1
- data/lib/bebox/wizards/environment_wizard.rb +5 -5
- data/lib/bebox/wizards/node_wizard.rb +23 -22
- data/lib/bebox/wizards/profile_wizard.rb +24 -25
- data/lib/bebox/wizards/project_wizard.rb +34 -28
- data/lib/bebox/wizards/provision_wizard.rb +13 -12
- data/lib/bebox/wizards/role_wizard.rb +15 -21
- data/lib/i18n/en.yml +198 -0
- data/spec/cli_spec.rb +66 -26
- data/spec/fixtures/commands/environment_help.erb.test +1 -0
- data/spec/fixtures/commands/general_help.erb.test +1 -0
- data/spec/fixtures/commands/in_project_help.erb.test +1 -0
- data/spec/fixtures/commands/node_help.erb.test +1 -0
- data/spec/fixtures/commands/profile_help.erb.test +1 -0
- data/spec/fixtures/commands/role_help.erb.test +1 -0
- data/spec/spec_helper.rb +7 -1
- data/spec/wizards/profile_wizard_spec.rb +12 -0
- metadata +23 -22
- data/spec/fixtures/commands/environment_help.test +0 -1
- data/spec/fixtures/commands/general_help.test +0 -1
- data/spec/fixtures/commands/in_project_help.test +0 -1
- data/spec/fixtures/commands/node_help.test +0 -1
- data/spec/fixtures/commands/profile_help.test +0 -1
- data/spec/fixtures/commands/role_help.test +0 -1
data/lib/bebox/logger.rb
CHANGED
data/lib/bebox/node.rb
CHANGED
data/lib/bebox/profile.rb
CHANGED
@@ -65,7 +65,7 @@ module Bebox
|
|
65
65
|
#Split the name and validate each path part
|
66
66
|
pathname.split('/').each do |path_child|
|
67
67
|
valid_name = (path_child =~ /\A[a-z][a-z0-9_]*\Z/).nil? ? false : true
|
68
|
-
valid_name
|
68
|
+
valid_name &&= !Bebox::RESERVED_WORDS.include?(path_child)
|
69
69
|
return false unless valid_name
|
70
70
|
end
|
71
71
|
# Return true if all parts are valid
|
data/lib/bebox/project.rb
CHANGED
@@ -25,7 +25,6 @@ module Bebox
|
|
25
25
|
create_puppet_base
|
26
26
|
create_project_config
|
27
27
|
create_checkpoints
|
28
|
-
info "Bundle project ..."
|
29
28
|
bundle_project
|
30
29
|
end
|
31
30
|
|
@@ -200,6 +199,7 @@ module Bebox
|
|
200
199
|
|
201
200
|
# Bundle install packages for project
|
202
201
|
def bundle_project
|
202
|
+
info _('model.project.bundle')
|
203
203
|
system("cd #{self.path} && BUNDLE_GEMFILE=Gemfile bundle install")
|
204
204
|
end
|
205
205
|
|
data/lib/bebox/vagrant_helper.rb
CHANGED
@@ -30,7 +30,7 @@ module Bebox
|
|
30
30
|
|
31
31
|
# Backup and add the vagrant hosts to local hosts file
|
32
32
|
def configure_local_hosts(project_name, node)
|
33
|
-
info
|
33
|
+
info _('model.vagrant_helper.local_password_advice')
|
34
34
|
backup_local_hosts(project_name)
|
35
35
|
add_to_local_hosts(node)
|
36
36
|
end
|
@@ -64,8 +64,8 @@ module Bebox
|
|
64
64
|
def add_vagrant_node(project_name, vagrant_box_base, node)
|
65
65
|
already_installed_boxes = installed_vagrant_box_names(node)
|
66
66
|
box_name = "#{project_name}-#{node.hostname}"
|
67
|
-
info
|
68
|
-
info
|
67
|
+
info _('model.vagrant_helper.add_to_vagrant')%{node: node.hostname}
|
68
|
+
info _('model.vagrant_helper.network_interface_advice')
|
69
69
|
`cd #{node.project_root} && vagrant box add #{box_name} #{vagrant_box_base}` unless already_installed_boxes.include? box_name
|
70
70
|
end
|
71
71
|
|
@@ -73,11 +73,13 @@ module Bebox
|
|
73
73
|
def self.up_vagrant_nodes(project_root)
|
74
74
|
pid = fork {exec("cd #{project_root} && vagrant up --provision")}
|
75
75
|
Process.wait(pid)
|
76
|
+
ok _('model.vagrant_helper.nodes_running')
|
76
77
|
end
|
77
78
|
|
78
79
|
# Halt the vagrant boxes running
|
79
80
|
def self.halt_vagrant_nodes(project_root)
|
80
81
|
`cd #{project_root} && vagrant halt`
|
82
|
+
ok _('model.vagrant_helper.nodes_halted')
|
81
83
|
end
|
82
84
|
|
83
85
|
# Generate the Vagrantfile
|
data/lib/bebox/version.rb
CHANGED
@@ -7,24 +7,24 @@ module Bebox
|
|
7
7
|
# Create a new environment
|
8
8
|
def create_new_environment(project_root, environment_name)
|
9
9
|
# Check if the environment exist
|
10
|
-
return error(
|
10
|
+
return error(_('wizard.environment.name_exist')%{environment: environment_name}) if Bebox::Environment.environment_exists?(project_root, environment_name)
|
11
11
|
# Environment creation
|
12
12
|
environment = Bebox::Environment.new(environment_name, project_root)
|
13
13
|
output = environment.create
|
14
|
-
ok '
|
14
|
+
ok _('wizard.environment.creation_success')
|
15
15
|
return output
|
16
16
|
end
|
17
17
|
|
18
18
|
# Removes an existing environment
|
19
19
|
def remove_environment(project_root, environment_name)
|
20
20
|
# Check if the environment exist
|
21
|
-
return error(
|
21
|
+
return error(_('wizard.environment.name_not_exist')%{environment: environment_name}) unless Bebox::Environment.environment_exists?(project_root, environment_name)
|
22
22
|
# Confirm deletion
|
23
|
-
return warn('
|
23
|
+
return warn(_('wizard.no_changes')) unless confirm_action?(_('wizard.environment.confirm_deletion'))
|
24
24
|
# Environment deletion
|
25
25
|
environment = Bebox::Environment.new(environment_name, project_root)
|
26
26
|
output = environment.remove
|
27
|
-
ok '
|
27
|
+
ok _('wizard.environment.deletion_success')
|
28
28
|
return output
|
29
29
|
end
|
30
30
|
end
|
@@ -14,7 +14,7 @@ module Bebox
|
|
14
14
|
# Node creation
|
15
15
|
node = Bebox::Node.new(environment, project_root, hostname, ip)
|
16
16
|
output = node.create
|
17
|
-
ok '
|
17
|
+
ok _('wizard.node.creation_success')
|
18
18
|
return output
|
19
19
|
end
|
20
20
|
|
@@ -23,17 +23,17 @@ module Bebox
|
|
23
23
|
# Ask for a node to remove
|
24
24
|
nodes = Bebox::Node.list(project_root, environment, 'nodes')
|
25
25
|
if nodes.count > 0
|
26
|
-
hostname = choose_option(nodes, '
|
26
|
+
hostname = choose_option(nodes, _('wizard.node.choose_node'))
|
27
27
|
else
|
28
|
-
error
|
28
|
+
error _('wizard.node.no_nodes')%{environment: environment}
|
29
29
|
return true
|
30
30
|
end
|
31
31
|
# Ask for deletion confirmation
|
32
|
-
return warn('
|
32
|
+
return warn(_('wizard.no_changes')) unless confirm_action?(_('wizard.node.confirm_deletion'))
|
33
33
|
# Node deletion
|
34
34
|
node = Bebox::Node.new(environment, project_root, hostname, nil)
|
35
35
|
output = node.remove
|
36
|
-
ok '
|
36
|
+
ok _('wizard.node.deletion_success')
|
37
37
|
return output
|
38
38
|
end
|
39
39
|
|
@@ -41,10 +41,10 @@ module Bebox
|
|
41
41
|
def set_role(project_root, environment)
|
42
42
|
roles = Bebox::Role.list(project_root)
|
43
43
|
nodes = Bebox::Node.list(project_root, environment, 'nodes')
|
44
|
-
node = choose_option(nodes, '
|
45
|
-
role = choose_option(roles, '
|
44
|
+
node = choose_option(nodes, _('wizard.choose_node'))
|
45
|
+
role = choose_option(roles, _('wizard.choose_role'))
|
46
46
|
output = Bebox::Provision.associate_node_role(project_root, environment, node, role)
|
47
|
-
ok '
|
47
|
+
ok _('wizard.node.role_set_success')
|
48
48
|
return output
|
49
49
|
end
|
50
50
|
|
@@ -54,28 +54,30 @@ module Bebox
|
|
54
54
|
nodes_to_prepare = check_nodes_to_prepare(project_root, environment)
|
55
55
|
# Output the nodes to be prepared
|
56
56
|
if nodes_to_prepare.count > 0
|
57
|
-
title '
|
57
|
+
title _('wizard.node.prepare_title')
|
58
58
|
nodes_to_prepare.each{|node| msg(node.hostname)}
|
59
59
|
linebreak
|
60
60
|
# For all environments regenerate the deploy file
|
61
61
|
Bebox::Node.regenerate_deploy_file(project_root, environment, nodes_to_prepare)
|
62
62
|
# If environment is 'vagrant' Prepare and Up the machines
|
63
|
-
if environment == 'vagrant'
|
64
|
-
Bebox::VagrantHelper.generate_vagrantfile(nodes_to_prepare)
|
65
|
-
nodes_to_prepare.each{|node| prepare_vagrant(node)}
|
66
|
-
Bebox::VagrantHelper.up_vagrant_nodes(project_root)
|
67
|
-
end
|
63
|
+
up_vagrant_machines(project_root, nodes_to_prepare) if environment == 'vagrant'
|
68
64
|
# For all the environments do the preparation
|
69
65
|
nodes_to_prepare.each do |node|
|
70
66
|
node.prepare
|
71
|
-
ok '
|
67
|
+
ok _('wizard.node.preparation_success')
|
72
68
|
end
|
73
69
|
else
|
74
|
-
warn '
|
70
|
+
warn _('wizard.node.no_prepare_nodes')
|
75
71
|
end
|
76
72
|
return true
|
77
73
|
end
|
78
74
|
|
75
|
+
def up_vagrant_machines(project_root, nodes_to_prepare)
|
76
|
+
Bebox::VagrantHelper.generate_vagrantfile(nodes_to_prepare)
|
77
|
+
nodes_to_prepare.each{|node| prepare_vagrant(node)}
|
78
|
+
Bebox::VagrantHelper.up_vagrant_nodes(project_root)
|
79
|
+
end
|
80
|
+
|
79
81
|
# Check the nodes already prepared and ask confirmation to re-do-it
|
80
82
|
def check_nodes_to_prepare(project_root, environment)
|
81
83
|
nodes_to_prepare = []
|
@@ -83,8 +85,7 @@ module Bebox
|
|
83
85
|
prepared_nodes = Bebox::Node.list(project_root, environment, 'prepared_nodes')
|
84
86
|
nodes.each do |node|
|
85
87
|
if prepared_nodes.include?(node.hostname)
|
86
|
-
|
87
|
-
message = "The node '#{node.hostname}' was already prepared #{checkpoint_status}.\nDo you want to re-prepare it?"
|
88
|
+
message = _('wizard.node.confirm_preparation')%{hostname: node.hostname, start: node.checkpoint_parameter_from_file('prepared_nodes', 'started_at'), end: node.checkpoint_parameter_from_file('prepared_nodes', 'finished_at')}
|
88
89
|
nodes_to_prepare << node if confirm_action?(message)
|
89
90
|
else
|
90
91
|
nodes_to_prepare << node
|
@@ -103,7 +104,7 @@ module Bebox
|
|
103
104
|
hostname = ask_hostname(project_root, environment)
|
104
105
|
# Check if the node not exist
|
105
106
|
if node_exists?(project_root, environment, hostname)
|
106
|
-
error '
|
107
|
+
error _('wizard.node.hostname_exist')
|
107
108
|
ask_hostname(project_root, environment)
|
108
109
|
else
|
109
110
|
return hostname
|
@@ -112,19 +113,19 @@ module Bebox
|
|
112
113
|
|
113
114
|
# Ask for the hostname
|
114
115
|
def ask_hostname(project_root, environment)
|
115
|
-
write_input('
|
116
|
+
write_input(_('wizard.node.ask_hostname'), nil, /\.(.*)/, _('wizard.node.valid_hostname'))
|
116
117
|
end
|
117
118
|
|
118
119
|
# Ask for the ip until is valid
|
119
120
|
def ask_ip(environment)
|
120
|
-
ip = write_input('
|
121
|
+
ip = write_input(_('wizard.node.ask_ip'), nil, /\.(.*)/, _('wizard.node.valid_ip'))
|
121
122
|
# If the environment is not vagrant don't check ip free
|
122
123
|
return ip if environment != 'vagrant'
|
123
124
|
# Check if the ip address is free
|
124
125
|
if free_ip?(ip)
|
125
126
|
return ip
|
126
127
|
else
|
127
|
-
error '
|
128
|
+
error _('wizard.node.non_free_ip')
|
128
129
|
ask_ip(environment)
|
129
130
|
end
|
130
131
|
end
|
@@ -6,54 +6,53 @@ module Bebox
|
|
6
6
|
|
7
7
|
# Create a new profile
|
8
8
|
def create_new_profile(project_root, profile_name, profile_base_path)
|
9
|
+
# Clean the profile_path to make it a valid path
|
10
|
+
profile_base_path = Bebox::Profile.cleanpath(profile_base_path)
|
9
11
|
# Check if the profile name is valid
|
10
|
-
return
|
11
|
-
\n* Lowercase letters
|
12
|
-
\n* Numbers
|
13
|
-
\n* Underscores
|
14
|
-
\n* Must begin with an Lowercase letter
|
15
|
-
\n* Can not be any of: #{Bebox::RESERVED_WORDS.join(', ')}
|
16
|
-
\n\nNo changes were made." unless valid_puppet_class_name?(profile_name)
|
17
|
-
unless profile_base_path.empty?
|
18
|
-
# Clean the profile_path to make it a valid path
|
19
|
-
profile_base_path = Bebox::Profile.cleanpath(profile_base_path)
|
20
|
-
# Check if the path name is valid
|
21
|
-
return error "Each part of the path can only contain:\n
|
22
|
-
\n* Lowercase letters
|
23
|
-
\n* Numbers
|
24
|
-
\n* Underscores
|
25
|
-
\n* Must begin with an Lowercase letter
|
26
|
-
\n* Can not be any of: #{Bebox::RESERVED_WORDS.join(', ')}
|
27
|
-
\n\nNo changes were made." unless Bebox::Profile.valid_pathname?(profile_base_path)
|
28
|
-
end
|
12
|
+
return unless name_valid?(profile_name, profile_base_path)
|
29
13
|
# Check if the profile exist
|
30
14
|
profile_path = profile_base_path.empty? ? profile_name : profile_complete_path(profile_base_path, profile_name)
|
31
|
-
return error(
|
15
|
+
return error(_('wizard.profile.name_exist')%{profile: profile_path}) if profile_exists?(project_root, profile_path)
|
32
16
|
# Profile creation
|
33
17
|
profile = Bebox::Profile.new(profile_name, project_root, profile_base_path)
|
34
18
|
output = profile.create
|
35
|
-
ok
|
19
|
+
ok _('wizard.profile.creation_success')%{profile: profile_path}
|
36
20
|
return output
|
37
21
|
end
|
38
22
|
|
23
|
+
# Check if the profile name is valid
|
24
|
+
def name_valid?(profile_name, profile_base_path)
|
25
|
+
unless valid_puppet_class_name?(profile_name)
|
26
|
+
error _('wizard.profile.invalid_name')%{words: Bebox::RESERVED_WORDS.join(', ')}
|
27
|
+
return false
|
28
|
+
end
|
29
|
+
return true if profile_base_path.empty?
|
30
|
+
# Check if the path name is valid
|
31
|
+
unless Bebox::Profile.valid_pathname?(profile_base_path)
|
32
|
+
error _('wizard.profile.invalid_path')%{words: Bebox::RESERVED_WORDS.join(', ')}
|
33
|
+
return false
|
34
|
+
end
|
35
|
+
true
|
36
|
+
end
|
37
|
+
|
39
38
|
# Removes an existing profile
|
40
39
|
def remove_profile(project_root)
|
41
40
|
# Choose a profile from the availables
|
42
41
|
profiles = Bebox::Profile.list(project_root)
|
43
42
|
# Get a profile if exist
|
44
43
|
if profiles.count > 0
|
45
|
-
profile = choose_option(profiles, '
|
44
|
+
profile = choose_option(profiles, _('wizard.choose_remove_profile'))
|
46
45
|
else
|
47
|
-
return error
|
46
|
+
return error _('wizard.profile.no_deletion_profiles')
|
48
47
|
end
|
49
48
|
# Ask for deletion confirmation
|
50
|
-
return warn('
|
49
|
+
return warn(_('wizard.no_changes')) unless confirm_action?(_('wizard.profile.confirm_deletion'))
|
51
50
|
# Profile deletion
|
52
51
|
profile_name = profile.split('/').last
|
53
52
|
profile_base_path = profile.split('/')[0...-1].join('/')
|
54
53
|
profile = Bebox::Profile.new(profile_name, project_root, profile_base_path)
|
55
54
|
output = profile.remove
|
56
|
-
ok '
|
55
|
+
ok _('wizard.profile.deletion_success')
|
57
56
|
return output
|
58
57
|
end
|
59
58
|
|
@@ -9,20 +9,20 @@ module Bebox
|
|
9
9
|
# Asks for the project parameters and create the project skeleton
|
10
10
|
def create_new_project(project_name)
|
11
11
|
# Check project existence
|
12
|
-
(error('
|
12
|
+
(error(_('wizard.project.name_exist')); return false) if project_exists?(Dir.pwd, project_name)
|
13
13
|
# Setup the bebox boxes directory
|
14
14
|
bebox_boxes_setup
|
15
15
|
# Asks to choose an existing box
|
16
16
|
current_box = choose_box(get_existing_boxes)
|
17
17
|
vagrant_box_base = "#{BEBOX_BOXES_PATH}/#{get_valid_box_uri(current_box)}"
|
18
18
|
# Asks user to choose vagrant box provider
|
19
|
-
vagrant_box_provider = choose_option(%w{virtualbox vmware}, '
|
19
|
+
vagrant_box_provider = choose_option(%w{virtualbox vmware}, _('wizard.project.choose_box_provider'))
|
20
20
|
# Set default environments
|
21
21
|
default_environments = %w{vagrant staging production}
|
22
22
|
# Project creation
|
23
23
|
project = Bebox::Project.new(project_name, vagrant_box_base, Dir.pwd, vagrant_box_provider, default_environments)
|
24
24
|
output = project.create
|
25
|
-
ok
|
25
|
+
ok _('wizard.project.creation_success')%{project_name: project_name}
|
26
26
|
return output
|
27
27
|
end
|
28
28
|
|
@@ -35,7 +35,7 @@ module Bebox
|
|
35
35
|
# Asks vagrant box location to user if not choose an existing box
|
36
36
|
valid_box_uri = ask_uri
|
37
37
|
# Confirm if the box already exist
|
38
|
-
confirm = box_exists?(valid_box_uri) ? confirm_action?('
|
38
|
+
confirm = box_exists?(valid_box_uri) ? confirm_action?(_('wizard.project.box_exist')) : true
|
39
39
|
end while !confirm
|
40
40
|
# Setup the box with the valid uri
|
41
41
|
set_box(valid_box_uri)
|
@@ -56,7 +56,7 @@ module Bebox
|
|
56
56
|
|
57
57
|
# Asks vagrant box location to user until is valid
|
58
58
|
def ask_uri
|
59
|
-
vbox_uri = write_input('
|
59
|
+
vbox_uri = write_input(_('wizard.project.ask_box_uri'), 'http://puppet-vagrant-boxes.puppetlabs.com/ubuntu-server-12042-x64-vbox4210-nocm.box')
|
60
60
|
# If valid return uri if not keep asking for uri
|
61
61
|
uri_valid?(vbox_uri) ? (return vbox_uri) : ask_uri
|
62
62
|
end
|
@@ -66,7 +66,7 @@ module Bebox
|
|
66
66
|
require 'uri'
|
67
67
|
uri = URI.parse(box_uri)
|
68
68
|
if %w{http https}.include?(uri.scheme)
|
69
|
-
info '
|
69
|
+
info _('wizard.project.downloading_box')
|
70
70
|
download_box(uri)
|
71
71
|
else
|
72
72
|
`ln -fs #{uri.path} #{BEBOX_BOXES_PATH}/#{uri.path.split('/').last}`
|
@@ -84,12 +84,12 @@ module Bebox
|
|
84
84
|
require 'net/http'
|
85
85
|
request = Net::HTTP.new uri.host
|
86
86
|
response = request.request_head uri.path
|
87
|
-
error('
|
88
|
-
( response.code.to_i == 200) ? (return true) : error('
|
87
|
+
error(_('wizard.project.no_redirections')) if response.code.to_i == 302
|
88
|
+
( response.code.to_i == 200) ? (return true) : error(_('wizard.project.not_valid_link'))
|
89
89
|
end
|
90
90
|
|
91
91
|
def file_uri_valid?(uri)
|
92
|
-
File.file?(uri.path) ? (return true) : error('
|
92
|
+
File.file?(uri.path) ? (return true) : error(_('wizard.project.not_exist_file'))
|
93
93
|
end
|
94
94
|
|
95
95
|
# Check if a box with the same name already exist
|
@@ -111,36 +111,42 @@ module Bebox
|
|
111
111
|
# Asks to choose an existing box in the bebox boxes directory
|
112
112
|
def choose_box(boxes)
|
113
113
|
# Menu to choose vagrant box provider
|
114
|
-
other_box_message = '
|
114
|
+
other_box_message = _('wizard.project.download_select_box')
|
115
115
|
boxes << other_box_message
|
116
|
-
current_box = choose_option(boxes, '
|
116
|
+
current_box = choose_option(boxes, _('wizard.project.choose_box'))
|
117
117
|
current_box = (current_box == other_box_message) ? nil : current_box
|
118
118
|
end
|
119
119
|
|
120
120
|
# Download a box by the specified uri
|
121
121
|
def download_box(uri)
|
122
|
-
@counter = 0
|
123
|
-
url = uri.path
|
124
|
-
file_name = uri.path.split('/').last
|
125
|
-
expanded_directory = File.expand_path(BEBOX_BOXES_PATH)
|
126
|
-
# Download file to bebox boxes tmp
|
127
122
|
require 'net/http'
|
128
123
|
require 'uri'
|
124
|
+
url = uri.path
|
125
|
+
# Download file to bebox boxes tmp
|
129
126
|
Net::HTTP.start(uri.host) do |http|
|
130
127
|
response = http.request_head(URI.escape(url))
|
131
|
-
|
132
|
-
pbar = ProgressBar.new('file name:', response['content-length'].to_i)
|
133
|
-
File.open("#{expanded_directory}/tmp/#{file_name}", 'w') {|f|
|
134
|
-
http.get(URI.escape(url)) do |str|
|
135
|
-
f.write str
|
136
|
-
@counter += str.length
|
137
|
-
pbar.set(@counter)
|
138
|
-
end
|
139
|
-
}
|
140
|
-
# In download completion move from tmp to bebox boxes dir
|
141
|
-
pbar.finish
|
142
|
-
`mv #{BEBOX_BOXES_PATH}/tmp/#{file_name} #{BEBOX_BOXES_PATH}/`
|
128
|
+
write_remote_file(uri, http, response)
|
143
129
|
end
|
144
130
|
end
|
131
|
+
|
132
|
+
def write_remote_file(uri, http, response)
|
133
|
+
@counter = 0
|
134
|
+
url = uri.path
|
135
|
+
file_name = uri.path.split('/').last
|
136
|
+
expanded_directory = File.expand_path(BEBOX_BOXES_PATH)
|
137
|
+
|
138
|
+
ProgressBar
|
139
|
+
pbar = ProgressBar.new('file name:', response['content-length'].to_i)
|
140
|
+
File.open("#{expanded_directory}/tmp/#{file_name}", 'w') {|f|
|
141
|
+
http.get(URI.escape(url)) do |str|
|
142
|
+
f.write str
|
143
|
+
@counter += str.length
|
144
|
+
pbar.set(@counter)
|
145
|
+
end
|
146
|
+
}
|
147
|
+
# In download completion move from tmp to bebox boxes dir
|
148
|
+
pbar.finish
|
149
|
+
`mv #{BEBOX_BOXES_PATH}/tmp/#{file_name} #{BEBOX_BOXES_PATH}/`
|
150
|
+
end
|
145
151
|
end
|
146
152
|
end
|
@@ -6,10 +6,10 @@ module Bebox
|
|
6
6
|
# Apply a step for the nodes in a environment
|
7
7
|
def apply_step(project_root, environment, step)
|
8
8
|
# Check if environment has configured the ssh keys
|
9
|
-
(return warn
|
9
|
+
(return warn _('wizard.provision.ssh_key_advice')%{environment: environment}) unless Bebox::Environment.check_environment_access(project_root, environment)
|
10
10
|
nodes_to_step = Bebox::Node.nodes_in_environment(project_root, environment, previous_checkpoint(step))
|
11
11
|
# Check if there are nodes for provisioning step-N
|
12
|
-
(return warn
|
12
|
+
(return warn _('wizard.provision.no_provision_nodes')%{step: step}) unless nodes_to_step.count > 0
|
13
13
|
nodes_for_provisioning(nodes_to_step, step)
|
14
14
|
# Apply the nodes provisioning for step-N
|
15
15
|
in_step_nodes = Bebox::Node.list(project_root, environment, "steps/#{step}")
|
@@ -22,29 +22,30 @@ module Bebox
|
|
22
22
|
end
|
23
23
|
|
24
24
|
def provision_step_in_node(project_root, environment, step, in_step_nodes, node)
|
25
|
-
title
|
25
|
+
title _('wizard.provision.title')%{step: step, hostname: node.hostname}
|
26
|
+
generate_pre_provision_files(project_root, step, node)
|
27
|
+
provision = Bebox::Provision.new(project_root, environment, node, step)
|
28
|
+
output = provision.apply.success?
|
29
|
+
output ? (ok _('wizard.provision.apply_success')%{hostname: node.hostname, step: step}) : (error _('wizard.provision.apply_failure')%{step: step, hostname: node.hostname})
|
30
|
+
return output
|
31
|
+
end
|
32
|
+
|
33
|
+
def generate_pre_provision_files(project_root, step, node)
|
26
34
|
role = Bebox::Provision.role_from_node(project_root, step, node.hostname)
|
27
35
|
profiles = Bebox::Provision.profiles_from_role(project_root, role) unless role.nil?
|
28
36
|
# Before apply generate the Puppetfile with modules from all associated profiles
|
29
37
|
Bebox::Provision.generate_puppetfile(project_root, step, profiles) unless profiles.nil?
|
30
38
|
# Before apply generate the roles and profiles modules structure for puppet step
|
31
39
|
Bebox::Provision.generate_roles_and_profiles(project_root, step, role, profiles)
|
32
|
-
provision = Bebox::Provision.new(project_root, environment, node, step)
|
33
|
-
output = provision.apply.success?
|
34
|
-
output ? (ok "Node '#{node.hostname}' provisioned to #{step}.") : (error "An error ocurred in the provision of #{step} for node '#{node.hostname}'")
|
35
|
-
return output
|
36
40
|
end
|
37
41
|
|
38
42
|
def check_node_to_step(node, in_step_nodes, step)
|
39
43
|
return true unless in_step_nodes.include?(node.hostname)
|
40
|
-
|
41
|
-
message += " (start: #{node.checkpoint_parameter_from_file('steps/' + step, 'started_at')} - end: #{node.checkpoint_parameter_from_file('steps/' + step, 'finished_at')})."
|
42
|
-
message += "\nDo you want to re-provision it?"
|
43
|
-
confirm_action?(message)
|
44
|
+
confirm_action?(_('wizard.provision.confirm_reprovision')%{hostname: node.hostname, step: step, start: node.checkpoint_parameter_from_file('steps/' + step, 'started_at'), end: node.checkpoint_parameter_from_file('steps/' + step, 'finished_at')})
|
44
45
|
end
|
45
46
|
|
46
47
|
def nodes_for_provisioning(nodes, step)
|
47
|
-
title
|
48
|
+
title _('wizard.provision.nodes_title')%{step: step}
|
48
49
|
nodes.each{|node| msg(node.hostname)}
|
49
50
|
linebreak
|
50
51
|
end
|