bosh-bootstrap 0.10.2 → 0.11.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 (162) hide show
  1. data/.rspec +1 -0
  2. data/.travis.yml +0 -1
  3. data/ChangeLog.md +23 -4
  4. data/Gemfile +5 -2
  5. data/Guardfile +2 -0
  6. data/README.md +209 -197
  7. data/TODO.md +55 -0
  8. data/bosh-bootstrap.gemspec +5 -12
  9. data/lib/bosh/cli/commands/bootstrap.rb +42 -0
  10. data/lib/bosh-bootstrap/cli/commands/delete.rb +26 -0
  11. data/lib/bosh-bootstrap/cli/commands/deploy.rb +89 -0
  12. data/lib/bosh-bootstrap/cli/commands/ssh.rb +32 -0
  13. data/lib/bosh-bootstrap/cli/helpers/bundle.rb +12 -0
  14. data/lib/bosh-bootstrap/cli/helpers/interactions.rb +15 -0
  15. data/lib/bosh-bootstrap/cli/helpers/settings.rb +61 -0
  16. data/lib/bosh-bootstrap/cli/helpers.rb +11 -0
  17. data/lib/bosh-bootstrap/key_pair.rb +21 -0
  18. data/lib/bosh-bootstrap/microbosh.rb +74 -0
  19. data/lib/bosh-bootstrap/microbosh_providers/aws.rb +104 -0
  20. data/lib/bosh-bootstrap/microbosh_providers/base.rb +50 -0
  21. data/lib/bosh-bootstrap/microbosh_providers/openstack.rb +61 -0
  22. data/lib/bosh-bootstrap/microbosh_providers/vsphere.rb +78 -0
  23. data/lib/bosh-bootstrap/microbosh_providers.rb +11 -0
  24. data/lib/bosh-bootstrap/network.rb +33 -0
  25. data/lib/bosh-bootstrap/network_providers/aws.rb +28 -0
  26. data/lib/bosh-bootstrap/network_providers/dummy.rb +10 -0
  27. data/lib/bosh-bootstrap/network_providers/openstack.rb +28 -0
  28. data/lib/bosh-bootstrap/network_providers.rb +11 -0
  29. data/lib/bosh-bootstrap/version.rb +1 -1
  30. data/lib/bosh-bootstrap.rb +3 -4
  31. data/spec/assets/microbosh_yml/micro_bosh.aws_ec2.yml +37 -0
  32. data/spec/assets/microbosh_yml/micro_bosh.aws_vpc.yml +39 -0
  33. data/spec/assets/microbosh_yml/micro_bosh.openstack.yml +30 -0
  34. data/spec/assets/microbosh_yml/micro_bosh.vsphere.yml +34 -0
  35. data/spec/integration/aws/aws_ec2_basic_spec.rb +39 -0
  36. data/spec/integration/aws/aws_helpers.rb +8 -61
  37. data/spec/spec_helper.rb +8 -3
  38. data/spec/support/capture_stdout.rb +18 -0
  39. data/spec/unit/cli/bootstrap_spec.rb +41 -0
  40. data/spec/unit/commands/delete_spec.rb +20 -0
  41. data/spec/unit/commands/deploy_spec.rb +64 -0
  42. data/spec/unit/commands/ssh_spec.rb +19 -0
  43. data/spec/unit/key_pair_spec.rb +13 -0
  44. data/spec/unit/microbosh_providers/aws_spec.rb +68 -0
  45. data/spec/unit/microbosh_providers/openstack_spec.rb +27 -0
  46. data/spec/unit/microbosh_providers/vsphere_spec.rb +42 -0
  47. data/spec/unit/microbosh_spec.rb +27 -0
  48. data/spec/unit/network_providers/aws_spec.rb +29 -0
  49. data/spec/unit/network_providers/openstack_spec.rb +29 -0
  50. data/spec/unit/network_spec.rb +17 -0
  51. metadata +71 -235
  52. data/CleanupCi.md +0 -8
  53. data/bin/bosh-bootstrap +0 -8
  54. data/docs/README.md +0 -3
  55. data/docs/devstack-openstack-tutorial.md +0 -215
  56. data/lib/bosh/providers/README.md +0 -5
  57. data/lib/bosh/providers/aws.rb +0 -258
  58. data/lib/bosh/providers/base_provider.rb +0 -48
  59. data/lib/bosh/providers/openstack.rb +0 -79
  60. data/lib/bosh/providers.rb +0 -21
  61. data/lib/bosh-bootstrap/cli.rb +0 -1347
  62. data/lib/bosh-bootstrap/commander/README.md +0 -47
  63. data/lib/bosh-bootstrap/commander/command.rb +0 -25
  64. data/lib/bosh-bootstrap/commander/commands.rb +0 -80
  65. data/lib/bosh-bootstrap/commander/local_server.rb +0 -68
  66. data/lib/bosh-bootstrap/commander/remote_script_command.rb +0 -51
  67. data/lib/bosh-bootstrap/commander/remote_server.rb +0 -137
  68. data/lib/bosh-bootstrap/commander/upload_command.rb +0 -17
  69. data/lib/bosh-bootstrap/commander.rb +0 -9
  70. data/lib/bosh-bootstrap/helpers/fog_setup.rb +0 -50
  71. data/lib/bosh-bootstrap/helpers/settings.rb +0 -99
  72. data/lib/bosh-bootstrap/helpers/settings_setter.rb +0 -41
  73. data/lib/bosh-bootstrap/helpers.rb +0 -3
  74. data/lib/bosh-bootstrap/stages/stage_micro_bosh_delete/bosh_micro_delete +0 -19
  75. data/lib/bosh-bootstrap/stages/stage_micro_bosh_delete.rb +0 -90
  76. data/lib/bosh-bootstrap/stages/stage_micro_bosh_deploy/bosh_micro_deploy +0 -79
  77. data/lib/bosh-bootstrap/stages/stage_micro_bosh_deploy/install_key_pair_for_user +0 -23
  78. data/lib/bosh-bootstrap/stages/stage_micro_bosh_deploy.rb +0 -146
  79. data/lib/bosh-bootstrap/stages/stage_micro_bosh_download/download_micro_bosh_stemcell +0 -93
  80. data/lib/bosh-bootstrap/stages/stage_micro_bosh_download.rb +0 -139
  81. data/lib/bosh-bootstrap/stages/stage_prepare_inception_vm/configure_git +0 -25
  82. data/lib/bosh-bootstrap/stages/stage_prepare_inception_vm/create_vcap_user +0 -79
  83. data/lib/bosh-bootstrap/stages/stage_prepare_inception_vm/install_base_packages +0 -30
  84. data/lib/bosh-bootstrap/stages/stage_prepare_inception_vm/install_bosh +0 -11
  85. data/lib/bosh-bootstrap/stages/stage_prepare_inception_vm/install_bosh_plugins +0 -25
  86. data/lib/bosh-bootstrap/stages/stage_prepare_inception_vm/install_hub +0 -26
  87. data/lib/bosh-bootstrap/stages/stage_prepare_inception_vm/install_ruby +0 -30
  88. data/lib/bosh-bootstrap/stages/stage_prepare_inception_vm/install_useful_gems +0 -29
  89. data/lib/bosh-bootstrap/stages/stage_prepare_inception_vm/validate_bosh_deployer +0 -18
  90. data/lib/bosh-bootstrap/stages/stage_prepare_inception_vm.rb +0 -69
  91. data/lib/bosh-bootstrap/stages/stage_salted_password/convert_salted_password +0 -11
  92. data/lib/bosh-bootstrap/stages/stage_salted_password.rb +0 -51
  93. data/lib/bosh-bootstrap/stages/stage_setup_new_bosh/setup_bosh_user +0 -29
  94. data/lib/bosh-bootstrap/stages/stage_setup_new_bosh.rb +0 -51
  95. data/lib/bosh-bootstrap/stages/stage_validate_inception_vm/validate_ubuntu +0 -6
  96. data/lib/bosh-bootstrap/stages/stage_validate_inception_vm.rb +0 -39
  97. data/lib/bosh-bootstrap/stages.rb +0 -10
  98. data/spec/assets/bosh/public_stemcells/aws_micro.out +0 -7
  99. data/spec/assets/micro_bosh_yml/micro_bosh.aws_ec2.yml +0 -35
  100. data/spec/assets/micro_bosh_yml/micro_bosh.aws_vpc.yml +0 -37
  101. data/spec/integration/aws/aws_basic_spec.rb +0 -39
  102. data/spec/integration/aws/aws_edge_prebuilt_ami_spec.rb +0 -46
  103. data/spec/integration/aws/aws_edge_prebuilt_spec.rb +0 -46
  104. data/spec/integration/aws/aws_edge_spec.rb +0 -45
  105. data/spec/unit/aws_spec.rb +0 -177
  106. data/spec/unit/bosh/providers/aws_spec.rb +0 -174
  107. data/spec/unit/cli_spec.rb +0 -134
  108. data/spec/unit/cli_ssh_spec.rb +0 -95
  109. data/spec/unit/cli_upgrade_inception_spec.rb +0 -29
  110. data/spec/unit/settings_setter_spec.rb +0 -29
  111. data/vendor/cache/POpen4-0.1.4.gem +0 -0
  112. data/vendor/cache/Platform-0.4.0.gem +0 -0
  113. data/vendor/cache/activesupport-3.2.8.gem +0 -0
  114. data/vendor/cache/awesome_print-1.1.0.gem +0 -0
  115. data/vendor/cache/aws-s3-0.6.3.gem +0 -0
  116. data/vendor/cache/blobstore_client-0.4.0.gem +0 -0
  117. data/vendor/cache/bosh_cli-1.0.3.gem +0 -0
  118. data/vendor/cache/bosh_common-0.5.4.gem +0 -0
  119. data/vendor/cache/builder-3.2.0.gem +0 -0
  120. data/vendor/cache/coderay-1.0.8.gem +0 -0
  121. data/vendor/cache/diff-lcs-1.1.3.gem +0 -0
  122. data/vendor/cache/escape-0.0.4.gem +0 -0
  123. data/vendor/cache/excon-0.20.1.gem +0 -0
  124. data/vendor/cache/fog-1.8.0.gem +0 -0
  125. data/vendor/cache/formatador-0.2.4.gem +0 -0
  126. data/vendor/cache/guard-1.6.2.gem +0 -0
  127. data/vendor/cache/guard-rspec-2.4.0.gem +0 -0
  128. data/vendor/cache/highline-1.6.18.gem +0 -0
  129. data/vendor/cache/httpclient-2.2.4.gem +0 -0
  130. data/vendor/cache/i18n-0.6.1.gem +0 -0
  131. data/vendor/cache/json_pure-1.6.8.gem +0 -0
  132. data/vendor/cache/listen-0.7.2.gem +0 -0
  133. data/vendor/cache/log4r-1.1.10.gem +0 -0
  134. data/vendor/cache/lumberjack-1.0.2.gem +0 -0
  135. data/vendor/cache/method_source-0.8.1.gem +0 -0
  136. data/vendor/cache/mime-types-1.22.gem +0 -0
  137. data/vendor/cache/multi_json-1.1.0.gem +0 -0
  138. data/vendor/cache/net-scp-1.0.4.gem +0 -0
  139. data/vendor/cache/net-ssh-2.2.2.gem +0 -0
  140. data/vendor/cache/net-ssh-gateway-1.1.0.gem +0 -0
  141. data/vendor/cache/netaddr-1.5.0.gem +0 -0
  142. data/vendor/cache/nokogiri-1.5.9.gem +0 -0
  143. data/vendor/cache/open4-1.3.0.gem +0 -0
  144. data/vendor/cache/progressbar-0.9.2.gem +0 -0
  145. data/vendor/cache/pry-0.9.11.4-java.gem +0 -0
  146. data/vendor/cache/pry-0.9.11.4.gem +0 -0
  147. data/vendor/cache/rake-10.0.3.gem +0 -0
  148. data/vendor/cache/rb-fsevent-0.9.3.gem +0 -0
  149. data/vendor/cache/redcard-1.0.0.gem +0 -0
  150. data/vendor/cache/rspec-2.12.0.gem +0 -0
  151. data/vendor/cache/rspec-core-2.12.2.gem +0 -0
  152. data/vendor/cache/rspec-expectations-2.12.1.gem +0 -0
  153. data/vendor/cache/rspec-mocks-2.12.2.gem +0 -0
  154. data/vendor/cache/ruby-atmos-pure-1.0.5.gem +0 -0
  155. data/vendor/cache/ruby-hmac-0.4.0.gem +0 -0
  156. data/vendor/cache/settingslogic-2.0.9.gem +0 -0
  157. data/vendor/cache/slop-3.4.3.gem +0 -0
  158. data/vendor/cache/spoon-0.0.1.gem +0 -0
  159. data/vendor/cache/terminal-table-1.4.5.gem +0 -0
  160. data/vendor/cache/thor-0.17.0.gem +0 -0
  161. data/vendor/cache/uuidtools-2.1.3.gem +0 -0
  162. data/vendor/cache/xml-simple-1.1.2.gem +0 -0
data/TODO.md ADDED
@@ -0,0 +1,55 @@
1
+ ## Known issues
2
+
3
+ * target & create user after deployment
4
+ * upgrade (if its already running successfully; else delete & redeploy)
5
+ * multiple deployments
6
+ * bosh name (currently fixed at test-bosh)
7
+ * ~/.microbosh folder is singular
8
+
9
+ ### Display status
10
+
11
+ ```
12
+ $ ~/.microbosh/deployments
13
+ $ bundle exec bosh micro status
14
+ Stemcell CID ami-53137a3a
15
+ Stemcell name ami-53137a3a
16
+ VM CID i-78046912
17
+ Disk CID vol-cebe9196
18
+ Micro BOSH CID bm-2b31bf69-b676-4db1-a084-fd1ac49377ac
19
+ Deployment /Users/drnic/.microbosh/deployments/test-bosh/micro_bosh.yml
20
+ Target https://107.21.94.132:25555
21
+ ```
22
+ ### Create user
23
+
24
+ Collect user/password at start of process; then target & create user at the end
25
+
26
+ ```
27
+ bosh -u admin -p admin target https://107.21.94.132:25555
28
+ bosh -u admin -p admin create user drnic PASSWORD (do not display password)
29
+ ```
30
+
31
+ ## Multiple deployments
32
+
33
+ * bosh name (currently fixed at test-bosh)
34
+ * ~/.microbosh folder is singular
35
+
36
+ ## Bonus
37
+
38
+ * AWS/us-east-1 - upload light stemcell
39
+ * Others - upload normal base stemcell
40
+
41
+ ## Validations
42
+
43
+ If using stemcells, then must be Ubuntu with following packages installed:
44
+
45
+ * libsqlite3-dev
46
+ * genisoimage
47
+
48
+ * IP address - like key pair, check that its still available else create new one
49
+
50
+ How can we validate that there is enough disk space to download & prepare the stemcell?
51
+
52
+ ### AWS
53
+
54
+ * check if this server is in AWS & same region as target region, else only use AMIs (and switch to us-east-1)
55
+
@@ -8,10 +8,9 @@ Gem::Specification.new do |gem|
8
8
  gem.version = Bosh::Bootstrap::VERSION
9
9
  gem.authors = ["Dr Nic Williams"]
10
10
  gem.email = ["drnicwilliams@gmail.com"]
11
- gem.description = %q{Bootstrap a micro BOSH universe from one CLI}
11
+ gem.description = %q{Bootstrap a micro bosh universe from one CLI}
12
12
  gem.summary = <<-EOS
13
- bosh-bootstrap is a command line tool that you can run on your laptop and
14
- automatically get a microbosh (and an inception VM) deployed on either
13
+ bosh-bootstrap configures and deploys a microbosh deployed on either
15
14
  AWS or OpenStack.
16
15
  EOS
17
16
  gem.homepage = "https://github.com/StarkAndWayne/bosh-bootstrap"
@@ -23,17 +22,11 @@ EOS
23
22
  gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
24
23
  gem.require_paths = ["lib"]
25
24
 
26
- gem.add_dependency "thor"
27
- gem.add_dependency "highline"
28
- gem.add_dependency "settingslogic"
29
- gem.add_dependency "POpen4"
30
- gem.add_dependency "net-ssh", "~> 2.2.1"
31
- gem.add_dependency "net-scp", "~> 1.0.4"
32
- gem.add_dependency "fog", "~>1.8.0"
33
- gem.add_dependency "escape"
25
+ gem.add_dependency "cyoi"
26
+ gem.add_dependency "readwritesettings", "~> 3.0"
34
27
  gem.add_dependency "redcard"
35
28
  gem.add_dependency "bosh_cli"
36
29
  gem.add_development_dependency "rake"
37
30
  gem.add_development_dependency "rspec"
38
- gem.add_development_dependency "activesupport", ">= 3.0.0"
31
+ gem.add_development_dependency "fakeweb"
39
32
  end
@@ -0,0 +1,42 @@
1
+ # Copyright (c) 2012-2013 Stark & Wayne, LLC
2
+
3
+ require "bosh-bootstrap"
4
+
5
+ module Bosh::Cli::Command
6
+ class Bootstrap < Base
7
+ usage "bootstrap"
8
+ desc "show bootstrap sub-commands"
9
+ def help
10
+ say("bosh bootstrap sub-commands:")
11
+ nl
12
+ cmds = Bosh::Cli::Config.commands.values.find_all {|c|
13
+ c.usage =~ /^bootstrap/
14
+ }
15
+ Bosh::Cli::Command::Help.list_commands(cmds)
16
+ end
17
+
18
+ usage "bootstrap deploy"
19
+ desc "Configure and bootstrap a micro bosh; or deploy/upgrade existing Micro Bosh"
20
+ def deploy
21
+ require "bosh-bootstrap/cli/commands/deploy"
22
+ deploy_cmd = Bosh::Bootstrap::Cli::Commands::Deploy.new
23
+ deploy_cmd.perform
24
+ end
25
+
26
+ usage "bootstrap ssh"
27
+ desc "SSH into micro bosh"
28
+ def ssh
29
+ require "bosh-bootstrap/cli/commands/ssh"
30
+ cmd = Bosh::Bootstrap::Cli::Commands::SSH.new
31
+ cmd.perform
32
+ end
33
+
34
+ usage "bootstrap delete"
35
+ desc "Delete existing Micro Bosh (does not delete any bosh deployments running)"
36
+ def delete
37
+ require "bosh-bootstrap/cli/commands/delete"
38
+ cmd = Bosh::Bootstrap::Cli::Commands::Delete.new
39
+ cmd.perform
40
+ end
41
+ end
42
+ end
@@ -0,0 +1,26 @@
1
+ # Copyright (c) 2012-2013 Stark & Wayne, LLC
2
+
3
+ module Bosh; module Bootstrap; module Cli; module Commands; end; end; end; end
4
+
5
+ require "bosh-bootstrap/cli/helpers"
6
+
7
+ # Runs SSH to the microbosh server
8
+ class Bosh::Bootstrap::Cli::Commands::Delete
9
+ include Bosh::Bootstrap::Cli::Helpers
10
+
11
+ def perform
12
+ chdir(deployment_dir) do
13
+ bundle "exec bosh -n micro deployment #{bosh_name}"
14
+ bundle "exec bosh -n micro delete"
15
+ end
16
+ end
17
+
18
+ protected
19
+ def bosh_name
20
+ settings.bosh.name
21
+ end
22
+
23
+ def deployment_dir
24
+ File.join(settings_dir, "deployments")
25
+ end
26
+ end
@@ -0,0 +1,89 @@
1
+ module Bosh; module Bootstrap; module Cli; module Commands; end; end; end; end
2
+
3
+ require "cyoi/cli/provider"
4
+ require "cyoi/cli/address"
5
+ require "cyoi/cli/key_pair"
6
+ require "bosh-bootstrap/cli/helpers"
7
+ require "bosh-bootstrap/microbosh"
8
+
9
+ class Bosh::Bootstrap::Cli::Commands::Deploy
10
+ include Bosh::Bootstrap::Cli::Helpers
11
+
12
+ # * select_provider
13
+ # * select_or_provision_public_networking # public_ip or ip/network/gateway
14
+ # * select_public_image_or_download_stemcell # download if stemcell
15
+ # * create_microbosh_manifest
16
+ # * microbosh_deploy
17
+ def perform
18
+ settings.set_default("bosh.name", "firstbosh")
19
+ save_settings!
20
+
21
+ select_provider
22
+ select_or_provision_public_networking
23
+ setup_keypair
24
+ select_public_image_or_download_stemcell
25
+ perform_microbosh_deploy
26
+ end
27
+
28
+ protected
29
+ def select_provider
30
+ provider = Cyoi::Cli::Provider.new([settings_dir])
31
+ provider.execute!
32
+ reload_settings!
33
+ end
34
+
35
+ def provider_client
36
+ @provider_client ||= Cyoi::Providers.provider_client(settings.provider)
37
+ end
38
+
39
+ # public_ip or ip/network/gateway
40
+ def select_or_provision_public_networking
41
+ address = Cyoi::Cli::Address.new([settings_dir])
42
+ address.execute!
43
+ reload_settings!
44
+
45
+ # TODO why passing provider_client rather than a Cyoi::Cli::Network object?
46
+ network = Bosh::Bootstrap::Network.new(settings.provider.name, provider_client)
47
+ network.deploy
48
+ end
49
+
50
+ def setup_keypair
51
+ key_pair_name = settings.exists?("key_pair.name") || settings.bosh.name
52
+ cli = Cyoi::Cli::KeyPair.new([key_pair_name, settings_dir])
53
+ cli.execute!
54
+ reload_settings!
55
+
56
+ key_pair = Bosh::Bootstrap::KeyPair.new(settings_dir, settings.key_pair.name, settings.key_pair.private_key)
57
+ key_pair.execute!
58
+ settings.set("key_pair.path", key_pair.path)
59
+ end
60
+
61
+ # TODO should this go inside Microbosh, like NetworkProvider is to Network?
62
+ def microbosh_provider
63
+ @microbosh_provider ||= begin
64
+ provider_name = settings.provider.name
65
+ require "bosh-bootstrap/microbosh_providers/#{provider_name}"
66
+ klass = Bosh::Bootstrap::MicroboshProviders.provider_class(provider_name)
67
+ klass.new(File.join(settings_dir, "deployments/#{settings.bosh.name}/micro_bosh.yml"), settings)
68
+ end
69
+ end
70
+
71
+ # download if stemcell
72
+ def select_public_image_or_download_stemcell
73
+ print "Determining stemcell image/file to use... "
74
+ stemcell = microbosh_provider.stemcell
75
+ while (stemcell || "").size == 0
76
+ puts "failed. Retrying..."
77
+ print "Determining stemcell image/file to use... "
78
+ stemcell = microbosh_provider.stemcell
79
+ end
80
+ settings.set("bosh.stemcell", stemcell)
81
+ puts settings.bosh.stemcell
82
+ end
83
+
84
+ def perform_microbosh_deploy
85
+ settings.set("bosh.persistent_disk", 16384)
86
+ @microbosh ||= Bosh::Bootstrap::Microbosh.new(settings_dir, microbosh_provider)
87
+ @microbosh.deploy(settings)
88
+ end
89
+ end
@@ -0,0 +1,32 @@
1
+ # Copyright (c) 2012-2013 Stark & Wayne, LLC
2
+
3
+ module Bosh; module Bootstrap; module Cli; module Commands; end; end; end; end
4
+
5
+ require "bosh-bootstrap/cli/helpers"
6
+
7
+ # for the #sh helper
8
+ require "rake"
9
+ require "rake/file_utils"
10
+
11
+ # Runs SSH to the microbosh server
12
+ class Bosh::Bootstrap::Cli::Commands::SSH
13
+ include Bosh::Bootstrap::Cli::Helpers
14
+ include FileUtils
15
+
16
+ def perform
17
+ sh "ssh -i #{private_key_path} #{user}@#{host}"
18
+ end
19
+
20
+ protected
21
+ def user
22
+ "vcap"
23
+ end
24
+
25
+ def host
26
+ settings.address.ip
27
+ end
28
+
29
+ def private_key_path
30
+ File.expand_path(settings.key_pair.path)
31
+ end
32
+ end
@@ -0,0 +1,12 @@
1
+ # for the #sh helper
2
+ require "rake"
3
+ require "rake/file_utils"
4
+
5
+ module Bosh::Bootstrap::Cli::Helpers::Bundle
6
+ def bundle(*args)
7
+ Bundler.with_clean_env {
8
+ ENV.delete 'RUBYOPT'
9
+ sh "bundle #{args.join(' ')}"
10
+ }
11
+ end
12
+ end
@@ -0,0 +1,15 @@
1
+ require "highline"
2
+
3
+ module Bosh::Bootstrap::Cli::Helpers::Interactions
4
+ def cyan; "\033[36m" end
5
+ def clear; "\033[0m" end
6
+ def bold; "\033[1m" end
7
+ def red; "\033[31m" end
8
+ def green; "\033[32m" end
9
+ def yellow; "\033[33m" end
10
+
11
+ # Helper to access HighLine for ask & menu prompts
12
+ def hl
13
+ @hl ||= HighLine.new(@stdin, @stdout)
14
+ end
15
+ end
@@ -0,0 +1,61 @@
1
+ require "readwritesettings"
2
+ require "fileutils"
3
+
4
+ module Bosh::Bootstrap::Cli::Helpers::Settings
5
+ include FileUtils
6
+
7
+ # The base directory for holding the manifest settings file
8
+ # and private keys
9
+ #
10
+ # Defaults to ~/.bosh_inception; and can be overridden with either:
11
+ # * $SETTINGS - to a folder (supported method)
12
+ def settings_dir
13
+ @settings_dir ||= File.expand_path(ENV["SETTINGS"] || "~/.microbosh")
14
+ end
15
+
16
+ def settings_dir=(settings_dir)
17
+ @settings_dir = File.expand_path(settings_dir)
18
+ reload_settings!
19
+ end
20
+
21
+ def settings_ssh_dir
22
+ File.join(settings_dir, "ssh")
23
+ end
24
+
25
+ def settings_path
26
+ @settings_path ||= File.join(settings_dir, "settings.yml")
27
+ end
28
+
29
+ def settings
30
+ @settings ||= begin
31
+ unless File.exists?(settings_path)
32
+ mkdir_p(settings_dir)
33
+ File.open(settings_path, "w") { |file| file << "--- {}" }
34
+ end
35
+ chmod(0600, settings_path)
36
+ chmod(0700, settings_ssh_dir) if File.directory?(settings_ssh_dir)
37
+ ReadWriteSettings.new(settings_path)
38
+ end
39
+ end
40
+
41
+ # Set a nested setting with "key1.key2.key3" notation
42
+ def setting(nested_key, value)
43
+ settings.set(nested_key, value)
44
+ save_settings!
45
+ end
46
+
47
+ # Saves current nested ReadWriteSettings into pure Hash-based YAML file
48
+ # Recreates accessors on ReadWriteSettings object (since something has changed)
49
+ def save_settings!
50
+ File.open(settings_path, "w") { |f| f << settings.to_nested_hash.to_yaml }
51
+ settings.create_accessors!
52
+ end
53
+
54
+ def reload_settings!
55
+ @settings = nil
56
+ settings
57
+ end
58
+
59
+ def migrate_old_settings
60
+ end
61
+ end
@@ -0,0 +1,11 @@
1
+ module Bosh; module Bootstrap; module Cli; module Helpers; end; end; end; end
2
+
3
+ require "bosh-bootstrap/cli/helpers/bundle"
4
+ require "bosh-bootstrap/cli/helpers/interactions"
5
+ require "bosh-bootstrap/cli/helpers/settings"
6
+
7
+ module Bosh::Bootstrap::Cli::Helpers
8
+ include Bosh::Bootstrap::Cli::Helpers::Bundle
9
+ include Bosh::Bootstrap::Cli::Helpers::Interactions
10
+ include Bosh::Bootstrap::Cli::Helpers::Settings
11
+ end
@@ -0,0 +1,21 @@
1
+ class Bosh::Bootstrap::KeyPair
2
+ include FileUtils
3
+
4
+ attr_reader :base_path, :keyname, :private_key
5
+
6
+ def initialize(base_path, keyname, private_key)
7
+ @base_path, @keyname, @private_key = base_path, keyname, private_key
8
+ end
9
+
10
+ def execute!
11
+ mkdir_p(File.dirname(path))
12
+ chmod(0700, File.dirname(path))
13
+
14
+ File.open(path, "w") { |file| file << private_key }
15
+ chmod(0600, path)
16
+ end
17
+
18
+ def path
19
+ @path ||= File.join(base_path, "ssh", keyname)
20
+ end
21
+ end
@@ -0,0 +1,74 @@
1
+ require "bosh-bootstrap/microbosh_providers"
2
+ require "bosh-bootstrap/cli/helpers"
3
+
4
+ # Configures and deploys (or re-deploys) a micro bosh.
5
+ # A "micro bosh" is a single VM containing all necessary parts of bosh
6
+ # and is deployed from the terminal; rather than from another bosh.
7
+ #
8
+ # Usage:
9
+ # microbosh = Bosh::Bootstrap::Microbosh.new(project_path)
10
+ # settings = ReadWriteSettings.new({
11
+ # "provider" => {"name" => "aws", "credentials" => {...}},
12
+ # "address" => {"ip" => "1.2.3.4"},
13
+ # "bosh" => {
14
+ # "name" => "test-bosh",
15
+ # "stemcell" => "ami-123456",
16
+ # "salted_password" => "452435hjg2345hjg2435ghk3452"
17
+ # }
18
+ # })
19
+ # microbosh.deploy("aws", settings)
20
+ class Bosh::Bootstrap::Microbosh
21
+ include FileUtils
22
+ include Bosh::Bootstrap::Cli::Helpers::Bundle
23
+
24
+ attr_reader :base_path
25
+ attr_reader :provider
26
+ attr_reader :bosh_name
27
+ attr_reader :deployments_dir
28
+ attr_reader :manifest_yml
29
+
30
+ def initialize(base_path, provider)
31
+ @base_path = base_path
32
+ @provider = provider
33
+ end
34
+
35
+ def deploy(settings)
36
+ @bosh_name = settings.bosh.name
37
+ @deployments_dir = File.join(base_path, "deployments")
38
+ @manifest_yml = File.join(deployments_dir, bosh_name, "micro_bosh.yml")
39
+ mkdir_p(File.dirname(manifest_yml))
40
+ chdir(base_path) do
41
+ setup_base_path
42
+ create_microbosh_yml(settings)
43
+ deploy_or_update(settings.bosh.name, settings.bosh.stemcell)
44
+ end
45
+ end
46
+
47
+ protected
48
+ def setup_base_path
49
+ gempath = File.expand_path("../../..", __FILE__)
50
+ pwd = File.expand_path(".")
51
+ File.open("Gemfile", "w") do |f|
52
+ f << <<-RUBY
53
+ source 'https://rubygems.org'
54
+ source 'https://s3.amazonaws.com/bosh-jenkins-gems/'
55
+
56
+ gem "bosh-bootstrap", path: "#{gempath}"
57
+ gem "bosh_cli_plugin_micro"
58
+ RUBY
59
+ end
60
+ rm_rf "Gemfile.lock"
61
+ bundle "install"
62
+ end
63
+
64
+ def create_microbosh_yml(settings)
65
+ provider.create_microbosh_yml(settings)
66
+ end
67
+
68
+ def deploy_or_update(bosh_name, stemcell)
69
+ chdir("deployments") do
70
+ bundle "exec bosh micro deployment", bosh_name
71
+ bundle "exec bosh -n micro deploy", stemcell
72
+ end
73
+ end
74
+ end
@@ -0,0 +1,104 @@
1
+ require "bosh-bootstrap/microbosh_providers/base"
2
+
3
+ module Bosh::Bootstrap::MicroboshProviders
4
+ class AWS < Base
5
+ # if us-east-1 -> ami
6
+ # if not running in target aws region -> error "Must either use us-east-1 or run 'bosh bootstrap deploy' within target AWS region"
7
+ # else download stemcell & return path
8
+ def stemcell
9
+ unless settings.exists?("bosh.stemcell")
10
+ if ami_region?
11
+ fetch_ami
12
+ else
13
+ download_stemcell
14
+ end
15
+ end
16
+ end
17
+
18
+ def to_hash
19
+ super.merge({
20
+ "network"=>{"type"=>"dynamic", "vip"=>public_ip},
21
+ "resources"=>
22
+ {"persistent_disk"=>persistent_disk,
23
+ "cloud_properties"=>resources_cloud_properties},
24
+ "cloud"=>
25
+ {"plugin"=>"aws",
26
+ "properties"=>
27
+ {"aws"=>cloud_properties}},
28
+ "apply_spec"=>
29
+ {"agent"=>
30
+ {"blobstore"=>{"address"=>public_ip},
31
+ "nats"=>{"address"=>public_ip}},
32
+ "properties"=>{"aws_registry"=>{"address"=>public_ip}}}})
33
+ end
34
+
35
+ def persistent_disk
36
+ settings.bosh.persistent_disk
37
+ end
38
+
39
+ def resources_cloud_properties
40
+ {"instance_type"=>"m1.medium"}
41
+ end
42
+
43
+ def cloud_properties
44
+ {"access_key_id"=>settings.provider.credentials.aws_access_key_id,
45
+ "secret_access_key"=>settings.provider.credentials.aws_secret_access_key,
46
+ "region"=>settings.provider.region,
47
+ "ec2_endpoint"=>"ec2.#{settings.provider.region}.amazonaws.com",
48
+ "default_security_groups"=>security_groups,
49
+ "default_key_name"=>microbosh_name,
50
+ "ec2_private_key"=>private_key_path}
51
+ end
52
+
53
+ def security_groups
54
+ ["ssh",
55
+ "bosh_agent_http",
56
+ "bosh_nats_server",
57
+ "bosh_blobstore",
58
+ "bosh_director",
59
+ "bosh_registry"]
60
+ end
61
+
62
+ def aws_region
63
+ settings.provider.region
64
+ end
65
+
66
+ # only us-east-1 has AMIs published currently
67
+ def ami_region?
68
+ aws_region == "us-east-1"
69
+ end
70
+
71
+ def aws_jenkins_bucket
72
+ "bosh-jenkins-artifacts"
73
+ end
74
+
75
+ def fetch_ami
76
+ Net::HTTP.get("#{aws_jenkins_bucket}.s3.amazonaws.com", ami_uri_path(aws_region)).strip
77
+ end
78
+
79
+ def ami_uri_path(region)
80
+ "/last_successful_micro-bosh-stemcell-aws_ami_#{region}"
81
+ end
82
+
83
+ def stemcell_uri
84
+ "http://#{aws_jenkins_bucket}.s3.amazonaws.com/last_successful_micro-bosh-stemcell-aws.tgz"
85
+ end
86
+
87
+ # downloads latest stemcell & returns path
88
+ def download_stemcell
89
+ mkdir_p(stemcell_dir)
90
+ chdir(stemcell_dir) do
91
+ stemcell_path = File.expand_path(File.basename(stemcell_uri))
92
+ unless File.exists?(stemcell_path)
93
+ sh "curl -O '#{stemcell_uri}'"
94
+ end
95
+ return stemcell_path
96
+ end
97
+ end
98
+
99
+ def stemcell_dir
100
+ File.dirname(manifest_path)
101
+ end
102
+ end
103
+ end
104
+ Bosh::Bootstrap::MicroboshProviders.register_provider("aws", Bosh::Bootstrap::MicroboshProviders::AWS)
@@ -0,0 +1,50 @@
1
+ require "bosh-bootstrap/microbosh_providers"
2
+
3
+ # for the #sh helper
4
+ require "rake"
5
+ require "rake/file_utils"
6
+
7
+ class Bosh::Bootstrap::MicroboshProviders::Base
8
+ include FileUtils
9
+
10
+ attr_reader :manifest_path
11
+ attr_reader :settings
12
+
13
+ def initialize(manifest_path, settings)
14
+ @manifest_path = manifest_path
15
+ @settings = settings.is_a?(Hash) ? ReadWriteSettings.new(settings) : settings
16
+ raise "@settings must be ReadWriteSettings (or Hash)" unless @settings.is_a?(ReadWriteSettings)
17
+ end
18
+
19
+ def create_microbosh_yml(settings)
20
+ @settings = settings.is_a?(Hash) ? ReadWriteSettings.new(settings) : settings
21
+ raise "@settings must be ReadWriteSettings (or Hash)" unless @settings.is_a?(ReadWriteSettings)
22
+ mkdir_p(File.dirname(manifest_path))
23
+ File.open(manifest_path, "w") do |f|
24
+ f << self.to_hash.to_yaml
25
+ end
26
+ end
27
+
28
+ def to_hash
29
+ {"name"=>microbosh_name,
30
+ "logging"=>{"level"=>"DEBUG"}
31
+ }
32
+ end
33
+
34
+ def microbosh_name
35
+ settings.bosh.name
36
+ end
37
+
38
+ def salted_password
39
+ # BCrypt::Password.create(settings.bosh.password).to_s.force_encoding("UTF-8")
40
+ settings.bosh.salted_password
41
+ end
42
+
43
+ def public_ip
44
+ settings.address.ip
45
+ end
46
+
47
+ def private_key_path
48
+ settings.key_pair.path
49
+ end
50
+ end