bosh-bootstrap 0.5.0

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.
Files changed (47) hide show
  1. data/.gitignore +18 -0
  2. data/Gemfile +4 -0
  3. data/LICENSE.txt +22 -0
  4. data/README.md +318 -0
  5. data/Rakefile +1 -0
  6. data/bin/bosh-bootstrap +8 -0
  7. data/bosh-bootstrap.gemspec +34 -0
  8. data/lib/bosh-bootstrap.rb +10 -0
  9. data/lib/bosh-bootstrap/cli.rb +1024 -0
  10. data/lib/bosh-bootstrap/commander.rb +9 -0
  11. data/lib/bosh-bootstrap/commander/README.md +47 -0
  12. data/lib/bosh-bootstrap/commander/command.rb +25 -0
  13. data/lib/bosh-bootstrap/commander/commands.rb +80 -0
  14. data/lib/bosh-bootstrap/commander/local_server.rb +68 -0
  15. data/lib/bosh-bootstrap/commander/remote_script_command.rb +48 -0
  16. data/lib/bosh-bootstrap/commander/remote_server.rb +121 -0
  17. data/lib/bosh-bootstrap/commander/upload_command.rb +17 -0
  18. data/lib/bosh-bootstrap/helpers.rb +2 -0
  19. data/lib/bosh-bootstrap/helpers/fog_setup.rb +50 -0
  20. data/lib/bosh-bootstrap/helpers/settings.rb +36 -0
  21. data/lib/bosh-bootstrap/stages.rb +8 -0
  22. data/lib/bosh-bootstrap/stages/stage_micro_bosh_delete.rb +90 -0
  23. data/lib/bosh-bootstrap/stages/stage_micro_bosh_delete/bosh_micro_delete +19 -0
  24. data/lib/bosh-bootstrap/stages/stage_micro_bosh_deploy.rb +135 -0
  25. data/lib/bosh-bootstrap/stages/stage_micro_bosh_deploy/bosh_micro_deploy +36 -0
  26. data/lib/bosh-bootstrap/stages/stage_micro_bosh_deploy/download_micro_bosh_stemcell +132 -0
  27. data/lib/bosh-bootstrap/stages/stage_micro_bosh_deploy/install_key_pair_for_user +23 -0
  28. data/lib/bosh-bootstrap/stages/stage_prepare_inception_vm.rb +52 -0
  29. data/lib/bosh-bootstrap/stages/stage_prepare_inception_vm/convert_salted_password +9 -0
  30. data/lib/bosh-bootstrap/stages/stage_prepare_inception_vm/create_vcap_user +79 -0
  31. data/lib/bosh-bootstrap/stages/stage_prepare_inception_vm/install_base_packages +13 -0
  32. data/lib/bosh-bootstrap/stages/stage_prepare_inception_vm/install_bosh +54 -0
  33. data/lib/bosh-bootstrap/stages/stage_prepare_inception_vm/install_ruby +33 -0
  34. data/lib/bosh-bootstrap/stages/stage_prepare_inception_vm/install_useful_gems +24 -0
  35. data/lib/bosh-bootstrap/stages/stage_prepare_inception_vm/validate_bosh_deployer +21 -0
  36. data/lib/bosh-bootstrap/stages/stage_setup_new_bosh.rb +52 -0
  37. data/lib/bosh-bootstrap/stages/stage_setup_new_bosh/cleanup_permissions +14 -0
  38. data/lib/bosh-bootstrap/stages/stage_setup_new_bosh/setup_bosh_user +29 -0
  39. data/lib/bosh-bootstrap/stages/stage_validate_inception_vm.rb +39 -0
  40. data/lib/bosh-bootstrap/stages/stage_validate_inception_vm/validate_ubuntu +6 -0
  41. data/lib/bosh-bootstrap/version.rb +5 -0
  42. data/lib/bosh/providers.rb +21 -0
  43. data/lib/bosh/providers/README.md +5 -0
  44. data/lib/bosh/providers/aws.rb +77 -0
  45. data/lib/bosh/providers/base_provider.rb +20 -0
  46. data/lib/bosh/providers/openstack.rb +40 -0
  47. metadata +239 -0
@@ -0,0 +1,6 @@
1
+ #!/usr/bin/env bash
2
+
3
+ if [[ $(uname -a | grep "Ubuntu") == "" ]]; then
4
+ echo "Inception VM must be a Ubuntu server"
5
+ exit 1
6
+ fi
@@ -0,0 +1,5 @@
1
+ module Bosh
2
+ module Bootstrap
3
+ VERSION = "0.5.0"
4
+ end
5
+ end
@@ -0,0 +1,21 @@
1
+ # Copyright (c) 2012-2013 Stark & Wayne, LLC
2
+
3
+ module Bosh; end
4
+
5
+ module Bosh::Providers
6
+ extend self
7
+ # returns a BOSH provider (CPI) specific object
8
+ # with helpers related to that provider
9
+ def for_bosh_provider_name(provider_name, fog_compute)
10
+ case provider_name.to_sym
11
+ when :aws
12
+ require "bosh/providers/aws"
13
+ Bosh::Providers::AWS.new(fog_compute)
14
+ when :openstack
15
+ require "bosh/providers/openstack"
16
+ Bosh::Providers::OpenStack.new(fog_compute)
17
+ else
18
+ raise "please support #{provider_name} provider"
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,5 @@
1
+ # Providers
2
+
3
+ Currently these files are kept in sync with bosh-cloudfoundry project.
4
+
5
+ TODO - extract into shared library.
@@ -0,0 +1,77 @@
1
+ # Copyright (c) 2012-2013 Stark & Wayne, LLC
2
+
3
+ module Bosh; module Providers; end; end
4
+
5
+ require "bosh/providers/base_provider"
6
+
7
+ class Bosh::Providers::AWS < Bosh::Providers::BaseProvider
8
+ # supported by fog 1.6.0
9
+ # FIXME weird that fog has no method to return this list
10
+ def region_labels
11
+ ['ap-northeast-1', 'ap-southeast-1', 'eu-west-1', 'sa-east-1', 'us-east-1', 'us-west-1', 'us-west-2']
12
+ end
13
+
14
+ def default_region_label
15
+ 'us-east-1'
16
+ end
17
+
18
+ # @return [Integer] megabytes of RAM for requested flavor of server
19
+ def ram_for_server_flavor(server_flavor_id)
20
+ if flavor = fog_compute_flavor(server_flavor_id)
21
+ flavor[:ram]
22
+ else
23
+ raise "Unknown AWS flavor '#{server_flavor_id}'"
24
+ end
25
+ end
26
+
27
+ # @return [Hash] e.g. { :bits => 0, :cores => 2, :disk => 0,
28
+ # :id => 't1.micro', :name => 'Micro Instance', :ram => 613}
29
+ # or nil if +server_flavor_id+ is not a supported flavor ID
30
+ def fog_compute_flavor(server_flavor_id)
31
+ aws_compute_flavors.find { |fl| fl[:id] == server_flavor_id }
32
+ end
33
+
34
+ # @return [Array] of [Hash] for each supported compute flavor
35
+ # Example [Hash] { :bits => 0, :cores => 2, :disk => 0,
36
+ # :id => 't1.micro', :name => 'Micro Instance', :ram => 613}
37
+ def aws_compute_flavors
38
+ Fog::Compute::AWS::FLAVORS
39
+ end
40
+
41
+ def aws_compute_flavor_ids
42
+ aws_compute_flavors.map { |fl| fl[:id] }
43
+ end
44
+
45
+ # Creates or reuses an AWS security group and opens ports.
46
+ #
47
+ # +security_group_name+ is the name to be created or reused
48
+ # +ports+ is a hash of name/port for ports to open, for example:
49
+ # {
50
+ # ssh: 22,
51
+ # http: 80,
52
+ # https: 443
53
+ # }
54
+ def create_security_group(security_group_name, description, ports)
55
+ unless sg = fog_compute.security_groups.get(security_group_name)
56
+ sg = fog_compute.security_groups.create(name: security_group_name, description: description)
57
+ puts "Created security group #{security_group_name}"
58
+ else
59
+ puts "Reusing security group #{security_group_name}"
60
+ end
61
+ ip_permissions = sg.ip_permissions
62
+ ports_opened = 0
63
+ ports.each do |name, port|
64
+ unless port_open?(ip_permissions, port)
65
+ sg.authorize_port_range(port..port)
66
+ puts " -> opened #{name} port #{port}"
67
+ ports_opened += 1
68
+ end
69
+ end
70
+ puts " -> no additional ports opened" if ports_opened == 0
71
+ true
72
+ end
73
+
74
+ def port_open?(ip_permissions, port)
75
+ ip_permissions && ip_permissions.find {|ip| ip["fromPort"] <= port && ip["toPort"] >= port }
76
+ end
77
+ end
@@ -0,0 +1,20 @@
1
+ # Copyright (c) 2012-2013 Stark & Wayne, LLC
2
+
3
+ module Bosh; module Providers; end; end
4
+
5
+ class Bosh::Providers::BaseProvider
6
+ attr_reader :fog_compute
7
+
8
+ def initialize(fog_compute)
9
+ @fog_compute = fog_compute
10
+ end
11
+
12
+ # @return [String] provisions a new public IP address in target region
13
+ # TODO nil if none available
14
+ def provision_public_ip_address
15
+ address = fog_compute.addresses.create
16
+ address.public_ip
17
+ # TODO catch error and return nil
18
+ end
19
+
20
+ end
@@ -0,0 +1,40 @@
1
+ # Copyright (c) 2012-2013 Stark & Wayne, LLC
2
+
3
+ module Bosh; module Providers; end; end
4
+
5
+ require "bosh/providers/base_provider"
6
+
7
+ class Bosh::Providers::OpenStack < Bosh::Providers::BaseProvider
8
+ # Creates or reuses an OpenStack security group and opens ports.
9
+ #
10
+ # +security_group_name+ is the name to be created or reused
11
+ # +ports+ is a hash of name/port for ports to open, for example:
12
+ # {
13
+ # ssh: 22,
14
+ # http: 80,
15
+ # https: 443
16
+ # }
17
+ def create_security_group(security_group_name, description, ports)
18
+ unless sg = fog_compute.security_groups.get(security_group_name)
19
+ sg = fog_compute.security_groups.create(name: security_group_name, description: description)
20
+ puts "Created security group #{security_group_name}"
21
+ else
22
+ puts "Reusing security group #{security_group_name}"
23
+ end
24
+ ip_permissions = sg.ip_permissions
25
+ ports_opened = 0
26
+ ports.each do |name, port|
27
+ unless port_open?(ip_permissions, port)
28
+ sg.create_security_group_rule(port, port)
29
+ puts " -> opened #{name} port #{port}"
30
+ ports_opened += 1
31
+ end
32
+ end
33
+ puts " -> no additional ports opened" if ports_opened == 0
34
+ true
35
+ end
36
+
37
+ def port_open?(ip_permissions, port)
38
+ ip_permissions && ip_permissions.find {|ip| ip["fromPort"] <= port && ip["toPort"] >= port }
39
+ end
40
+ end
metadata ADDED
@@ -0,0 +1,239 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: bosh-bootstrap
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.5.0
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Dr Nic Williams
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-01-27 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: thor
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: '0'
30
+ - !ruby/object:Gem::Dependency
31
+ name: highline
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ type: :runtime
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
46
+ - !ruby/object:Gem::Dependency
47
+ name: settingslogic
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ! '>='
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
+ type: :runtime
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ - !ruby/object:Gem::Dependency
63
+ name: POpen4
64
+ requirement: !ruby/object:Gem::Requirement
65
+ none: false
66
+ requirements:
67
+ - - ! '>='
68
+ - !ruby/object:Gem::Version
69
+ version: '0'
70
+ type: :runtime
71
+ prerelease: false
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ! '>='
76
+ - !ruby/object:Gem::Version
77
+ version: '0'
78
+ - !ruby/object:Gem::Dependency
79
+ name: net-scp
80
+ requirement: !ruby/object:Gem::Requirement
81
+ none: false
82
+ requirements:
83
+ - - ! '>='
84
+ - !ruby/object:Gem::Version
85
+ version: '0'
86
+ type: :runtime
87
+ prerelease: false
88
+ version_requirements: !ruby/object:Gem::Requirement
89
+ none: false
90
+ requirements:
91
+ - - ! '>='
92
+ - !ruby/object:Gem::Version
93
+ version: '0'
94
+ - !ruby/object:Gem::Dependency
95
+ name: fog
96
+ requirement: !ruby/object:Gem::Requirement
97
+ none: false
98
+ requirements:
99
+ - - ~>
100
+ - !ruby/object:Gem::Version
101
+ version: 1.8.0
102
+ type: :runtime
103
+ prerelease: false
104
+ version_requirements: !ruby/object:Gem::Requirement
105
+ none: false
106
+ requirements:
107
+ - - ~>
108
+ - !ruby/object:Gem::Version
109
+ version: 1.8.0
110
+ - !ruby/object:Gem::Dependency
111
+ name: escape
112
+ requirement: !ruby/object:Gem::Requirement
113
+ none: false
114
+ requirements:
115
+ - - ! '>='
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ type: :runtime
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ none: false
122
+ requirements:
123
+ - - ! '>='
124
+ - !ruby/object:Gem::Version
125
+ version: '0'
126
+ - !ruby/object:Gem::Dependency
127
+ name: bosh_cli
128
+ requirement: !ruby/object:Gem::Requirement
129
+ none: false
130
+ requirements:
131
+ - - ! '>='
132
+ - !ruby/object:Gem::Version
133
+ version: '0'
134
+ type: :runtime
135
+ prerelease: false
136
+ version_requirements: !ruby/object:Gem::Requirement
137
+ none: false
138
+ requirements:
139
+ - - ! '>='
140
+ - !ruby/object:Gem::Version
141
+ version: '0'
142
+ - !ruby/object:Gem::Dependency
143
+ name: bosh_deployer
144
+ requirement: !ruby/object:Gem::Requirement
145
+ none: false
146
+ requirements:
147
+ - - ! '>='
148
+ - !ruby/object:Gem::Version
149
+ version: '0'
150
+ type: :development
151
+ prerelease: false
152
+ version_requirements: !ruby/object:Gem::Requirement
153
+ none: false
154
+ requirements:
155
+ - - ! '>='
156
+ - !ruby/object:Gem::Version
157
+ version: '0'
158
+ description: Bootstrap a micro BOSH universe from one CLI
159
+ email:
160
+ - drnicwilliams@gmail.com
161
+ executables:
162
+ - bosh-bootstrap
163
+ extensions: []
164
+ extra_rdoc_files: []
165
+ files:
166
+ - .gitignore
167
+ - Gemfile
168
+ - LICENSE.txt
169
+ - README.md
170
+ - Rakefile
171
+ - bin/bosh-bootstrap
172
+ - bosh-bootstrap.gemspec
173
+ - lib/bosh-bootstrap.rb
174
+ - lib/bosh-bootstrap/cli.rb
175
+ - lib/bosh-bootstrap/commander.rb
176
+ - lib/bosh-bootstrap/commander/README.md
177
+ - lib/bosh-bootstrap/commander/command.rb
178
+ - lib/bosh-bootstrap/commander/commands.rb
179
+ - lib/bosh-bootstrap/commander/local_server.rb
180
+ - lib/bosh-bootstrap/commander/remote_script_command.rb
181
+ - lib/bosh-bootstrap/commander/remote_server.rb
182
+ - lib/bosh-bootstrap/commander/upload_command.rb
183
+ - lib/bosh-bootstrap/helpers.rb
184
+ - lib/bosh-bootstrap/helpers/fog_setup.rb
185
+ - lib/bosh-bootstrap/helpers/settings.rb
186
+ - lib/bosh-bootstrap/stages.rb
187
+ - lib/bosh-bootstrap/stages/stage_micro_bosh_delete.rb
188
+ - lib/bosh-bootstrap/stages/stage_micro_bosh_delete/bosh_micro_delete
189
+ - lib/bosh-bootstrap/stages/stage_micro_bosh_deploy.rb
190
+ - lib/bosh-bootstrap/stages/stage_micro_bosh_deploy/bosh_micro_deploy
191
+ - lib/bosh-bootstrap/stages/stage_micro_bosh_deploy/download_micro_bosh_stemcell
192
+ - lib/bosh-bootstrap/stages/stage_micro_bosh_deploy/install_key_pair_for_user
193
+ - lib/bosh-bootstrap/stages/stage_prepare_inception_vm.rb
194
+ - lib/bosh-bootstrap/stages/stage_prepare_inception_vm/convert_salted_password
195
+ - lib/bosh-bootstrap/stages/stage_prepare_inception_vm/create_vcap_user
196
+ - lib/bosh-bootstrap/stages/stage_prepare_inception_vm/install_base_packages
197
+ - lib/bosh-bootstrap/stages/stage_prepare_inception_vm/install_bosh
198
+ - lib/bosh-bootstrap/stages/stage_prepare_inception_vm/install_ruby
199
+ - lib/bosh-bootstrap/stages/stage_prepare_inception_vm/install_useful_gems
200
+ - lib/bosh-bootstrap/stages/stage_prepare_inception_vm/validate_bosh_deployer
201
+ - lib/bosh-bootstrap/stages/stage_setup_new_bosh.rb
202
+ - lib/bosh-bootstrap/stages/stage_setup_new_bosh/cleanup_permissions
203
+ - lib/bosh-bootstrap/stages/stage_setup_new_bosh/setup_bosh_user
204
+ - lib/bosh-bootstrap/stages/stage_validate_inception_vm.rb
205
+ - lib/bosh-bootstrap/stages/stage_validate_inception_vm/validate_ubuntu
206
+ - lib/bosh-bootstrap/version.rb
207
+ - lib/bosh/providers.rb
208
+ - lib/bosh/providers/README.md
209
+ - lib/bosh/providers/aws.rb
210
+ - lib/bosh/providers/base_provider.rb
211
+ - lib/bosh/providers/openstack.rb
212
+ homepage: https://github.com/StarkAndWayne/bosh-bootstrap
213
+ licenses: []
214
+ post_install_message:
215
+ rdoc_options: []
216
+ require_paths:
217
+ - lib
218
+ required_ruby_version: !ruby/object:Gem::Requirement
219
+ none: false
220
+ requirements:
221
+ - - ! '>='
222
+ - !ruby/object:Gem::Version
223
+ version: '0'
224
+ required_rubygems_version: !ruby/object:Gem::Requirement
225
+ none: false
226
+ requirements:
227
+ - - ! '>='
228
+ - !ruby/object:Gem::Version
229
+ version: '0'
230
+ requirements: []
231
+ rubyforge_project:
232
+ rubygems_version: 1.8.24
233
+ signing_key:
234
+ specification_version: 3
235
+ summary: Now very simple to bootstrap a micro BOSH from a single, local CLI. The bootstrapper
236
+ first creates an inception VM and then uses bosh_deployer (bosh micro deploy) to
237
+ deploy micro BOSH from an available stemcell.
238
+ test_files: []
239
+ has_rdoc: