vop-plugins 0.3.1 → 0.3.5

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 (195) hide show
  1. checksums.yaml +4 -4
  2. data/Rakefile +2 -2
  3. data/extended/hetzner/commands/add_ssh_key.rb +22 -0
  4. data/extended/hetzner/commands/disable_linux_install.rb +26 -0
  5. data/extended/hetzner/commands/enable_linux_install.rb +41 -0
  6. data/extended/hetzner/commands/hetzner_http.rb +24 -0
  7. data/extended/hetzner/commands/hetzner_machines.rb +11 -0
  8. data/extended/hetzner/commands/hetzner_server_list.rb +26 -0
  9. data/extended/hetzner/commands/linux_install_options.rb +29 -0
  10. data/extended/hetzner/commands/list_ssh_keys.rb +16 -0
  11. data/extended/hetzner/entities/hetzner_account.rb +9 -0
  12. data/extended/hetzner/hetzner.plugin +3 -0
  13. data/extended/hetzner_vop_0_2_x/commands/list_old_v2_vms.rb +46 -0
  14. data/extended/hetzner_vop_0_2_x/commands/old_libvirt_machines.rb +16 -0
  15. data/extended/hetzner_vop_0_2_x/commands/vop_0_2_x_ssh_options.rb +20 -0
  16. data/extended/hetzner_vop_0_2_x/hetzner_vop_0_2_x.plugin +5 -0
  17. data/extended/libvirt/commands/delete_vm.rb +32 -0
  18. data/extended/libvirt/commands/libvirt_config_file.rb +5 -0
  19. data/extended/libvirt/commands/libvirt_machines.rb +17 -0
  20. data/extended/libvirt/commands/libvirt_ssh_options.rb +29 -0
  21. data/extended/libvirt/commands/list_networks.rb +21 -0
  22. data/extended/libvirt/commands/list_pools.rb +20 -0
  23. data/extended/libvirt/commands/list_vms.rb +28 -0
  24. data/extended/libvirt/commands/list_vms_for_scan.rb +12 -0
  25. data/extended/libvirt/commands/list_vms_with_addresses.rb +20 -0
  26. data/extended/libvirt/commands/new_vm.rb +110 -0
  27. data/extended/libvirt/commands/parent.rb +10 -0
  28. data/extended/libvirt/commands/rename_vm.rb +34 -0
  29. data/extended/libvirt/commands/start_vm.rb +7 -0
  30. data/extended/libvirt/commands/stop_vm.rb +8 -0
  31. data/extended/libvirt/commands/vm_address.rb +7 -0
  32. data/extended/libvirt/commands/vm_addresses.rb +32 -0
  33. data/extended/libvirt/commands/vnc_ports.rb +32 -0
  34. data/extended/libvirt/helpers/helper.rb +3 -0
  35. data/extended/libvirt/libvirt.plugin +5 -0
  36. data/extended/libvirt/services/libvirt.rb +19 -0
  37. data/extended/libvirt_with_proxy/commands/reverse_proxy.rb +13 -0
  38. data/extended/libvirt_with_proxy/commands/vms_with_domains.rb +18 -0
  39. data/extended/libvirt_with_proxy/entities/_vms_with_domains.rbx +24 -0
  40. data/extended/libvirt_with_proxy/libvirt_with_proxy.plugin +1 -0
  41. data/extended/rails_machines/commands/rails_machines.rb +6 -0
  42. data/extended/rails_machines/commands/update_status.rb +38 -0
  43. data/extended/rails_machines/commands/write_found_machines_into_rails_db.rb.not +30 -0
  44. data/extended/rails_machines/rails_machines.plugin +1 -0
  45. data/extended/redis_cache/commands/flush_cache.rb +5 -0
  46. data/extended/redis_cache/commands/invalidate_cache.rb +26 -0
  47. data/extended/redis_cache/filters/cache_filter.rb +78 -0
  48. data/extended/redis_cache/helpers/cache_wrapper.rb +35 -0
  49. data/extended/redis_cache/redis_cache.plugin +8 -0
  50. data/extended/spares/commands/convert_spare.rb +93 -0
  51. data/extended/spares/commands/list_spares.rb +9 -0
  52. data/extended/spares/commands/new_vm_from_spare.rb +24 -0
  53. data/extended/spares/commands/post_convert_spare.rb +13 -0
  54. data/extended/spares/commands/prepare_spares.rb +17 -0
  55. data/extended/spares/commands/wait.rb +29 -0
  56. data/extended/spares/commands/wtf.rb +9 -0
  57. data/extended/spares/spares.plugin +1 -0
  58. data/standard/apt/apt.plugin +0 -0
  59. data/standard/apt/commands/add_apt_repo.rb +14 -0
  60. data/standard/git/commands/deploy.rb +19 -0
  61. data/standard/git/commands/deploy_from_git.rb +34 -0
  62. data/standard/git/commands/deploy_from_github.rb +12 -0
  63. data/standard/git/commands/git_clone.rb +7 -0
  64. data/standard/git/commands/git_clone_web.rb +22 -0
  65. data/standard/git/git.plugin +0 -0
  66. data/standard/linux/commands/append_to_file.rb +14 -0
  67. data/standard/linux/commands/chmod.rb +7 -0
  68. data/standard/linux/commands/curl.rb +15 -0
  69. data/standard/linux/commands/current_user.rb +5 -0
  70. data/standard/linux/commands/distro.rb +2 -1
  71. data/standard/linux/commands/download_file.rb +6 -6
  72. data/standard/linux/commands/external_ip.rb +15 -0
  73. data/standard/linux/commands/file_exists.rb +7 -0
  74. data/standard/linux/commands/home.rb +7 -0
  75. data/standard/linux/commands/hostname.rb +5 -0
  76. data/standard/linux/commands/internal_ip.rb +14 -0
  77. data/standard/linux/commands/ipaddress.rb +10 -0
  78. data/standard/linux/commands/list_files.rb +8 -6
  79. data/standard/linux/commands/list_ip_addresses.rb +22 -0
  80. data/standard/linux/commands/listen_ports.rb +3 -2
  81. data/standard/linux/commands/maybe_sudo.rb +8 -0
  82. data/standard/linux/commands/mkdirs.rb +12 -0
  83. data/standard/linux/commands/processes.rb +8 -6
  84. data/standard/linux/commands/processes_like.rb +7 -7
  85. data/standard/linux/commands/processes_top.rb +23 -0
  86. data/standard/linux/commands/processes_top_cpu.rb +8 -0
  87. data/standard/linux/commands/processes_top_mem.rb +8 -0
  88. data/standard/linux/commands/read_file.rb +7 -2
  89. data/standard/linux/commands/replace_in_file.rb +22 -0
  90. data/standard/linux/commands/set_hostname.rb +36 -0
  91. data/standard/linux/commands/update_hosts_file.rb +27 -0
  92. data/standard/linux/commands/write_file.rb +8 -21
  93. data/standard/linux/linux.plugin +1 -2
  94. data/standard/machines/commands/delete_old_machines.rb +17 -0
  95. data/standard/machines/commands/localhost.rb +7 -2
  96. data/standard/machines/commands/localhost_ssh_options.rb +9 -0
  97. data/standard/machines/commands/new_machine.rb +24 -0
  98. data/standard/machines/commands/new_vm_from_scratch.rb +25 -0
  99. data/standard/machines/commands/old_machines.rb +6 -0
  100. data/standard/machines/commands/select_machine.rb +4 -5
  101. data/standard/machines/entities/machine.rb +12 -0
  102. data/standard/machines/machines.plugin +1 -1
  103. data/standard/redis_machines/commands/installation_status.rb +10 -0
  104. data/standard/redis_machines/commands/track_installation_status.rb +13 -0
  105. data/standard/redis_machines/redis_machines.plugin +3 -0
  106. data/standard/rpm/commands/list_rpm_packages.rb +24 -0
  107. data/standard/rpm/rpm.plugin +1 -0
  108. data/standard/scanner/commands/clean_metadata.rb +8 -0
  109. data/standard/scanner/commands/fresh_ssh_test.rb +6 -0
  110. data/standard/scanner/commands/inspect_async.rb +6 -0
  111. data/standard/scanner/commands/inspect_machine.rb +42 -0
  112. data/standard/scanner/commands/machines_found.rb +35 -0
  113. data/standard/scanner/commands/metadata.rb +9 -0
  114. data/standard/scanner/commands/redis_machines.rb +11 -0
  115. data/standard/scanner/commands/scan.rb +5 -0
  116. data/standard/scanner/commands/scan_host.rb +7 -0
  117. data/standard/scanner/commands/scan_machines.rb +11 -0
  118. data/standard/scanner/commands/trigger_ssh_test.rb +8 -0
  119. data/standard/scanner/scanner.plugin +5 -0
  120. data/standard/services/commands/describe_service.rb +7 -0
  121. data/standard/services/commands/describe_service_installation.rb +13 -0
  122. data/standard/services/commands/detect_services.rb +34 -0
  123. data/standard/services/commands/install_service.rb +134 -0
  124. data/standard/services/commands/list_known_services.rb +14 -0
  125. data/standard/services/commands/load_plugin_services.rb +17 -0
  126. data/standard/services/entities/service.rb +3 -0
  127. data/standard/services/helpers/service.rb +31 -0
  128. data/standard/services/helpers/service_loader.rb +50 -0
  129. data/standard/services/helpers/service_syntax.rb +126 -0
  130. data/standard/services/services.plugin +9 -0
  131. data/standard/ssh/commands/clean_known_host.rb +11 -0
  132. data/standard/ssh/commands/clear_ssh_cache.rb +9 -0
  133. data/standard/ssh/commands/get_ssh_connection.rb +36 -0
  134. data/standard/ssh/commands/scp_down.rb +9 -0
  135. data/standard/ssh/commands/scp_up.rb +9 -0
  136. data/standard/ssh/commands/ssh.rb +20 -0
  137. data/standard/ssh/commands/ssh_call.rb +98 -0
  138. data/standard/ssh/commands/ssh_connection.rb +55 -0
  139. data/standard/ssh/commands/ssh_extended.rb +6 -0
  140. data/standard/ssh/commands/ssh_options.rb +12 -0
  141. data/standard/ssh/commands/sudo.rb +12 -0
  142. data/standard/ssh/commands/test_ssh.rb +43 -0
  143. data/standard/{linux → ssh}/helpers/regex.rb +0 -0
  144. data/standard/ssh/ssh.plugin +10 -0
  145. data/standard/ssh_keys/commands/add_authorized_key.rb +14 -0
  146. data/standard/ssh_keys/commands/disable_ssh_key_check.rb +11 -0
  147. data/standard/ssh_keys/commands/generate_keypair.rb +17 -0
  148. data/standard/ssh_keys/ssh_keys.plugin +0 -0
  149. data/standard/systemd/commands/disable_systemd_service.rb +8 -0
  150. data/standard/systemd/commands/enable_systemd_service.rb +8 -0
  151. data/standard/systemd/commands/list_systemd_services.rb +23 -0
  152. data/standard/systemd/commands/start_systemd_service.rb +6 -0
  153. data/standard/systemd/commands/stop_systemd_service.rb +6 -0
  154. data/standard/systemd/commands/systemd_service_status.rb +6 -0
  155. data/standard/systemd/commands/write_systemd_config.rb +16 -0
  156. data/standard/systemd/helpers/param_service.rb +7 -0
  157. data/standard/systemd/systemd.plugin +0 -0
  158. data/standard/systemd/templates/systemd_service.erb +11 -0
  159. data/standard/templates/commands/read_template.rb +8 -0
  160. data/standard/templates/commands/write_template.rb +37 -0
  161. data/standard/templates/templates.plugin +3 -0
  162. data/vop-plugins.gemspec +6 -7
  163. metadata +156 -55
  164. data/Gemfile +0 -3
  165. data/Gemfile.lock +0 -68
  166. data/standard/debian-iso/commands/fetch_debian_iso.rb +0 -3
  167. data/standard/debian-iso/commands/fetch_ubuntu_iso.rb +0 -22
  168. data/standard/debian-iso/commands/list_isos.rb +0 -6
  169. data/standard/debian-iso/commands/rebuild_debian_iso.rb +0 -40
  170. data/standard/debian-iso/debian-iso.plugin +0 -2
  171. data/standard/debian-iso/files/rebuild-debian-iso +0 -74
  172. data/standard/debian-iso/templates/preseed.cfg +0 -45
  173. data/standard/libvirt/commands/delete_vm.rb +0 -16
  174. data/standard/libvirt/commands/list_local_vms.rb +0 -4
  175. data/standard/libvirt/commands/list_vms.rb +0 -15
  176. data/standard/libvirt/commands/new_vm.rb +0 -61
  177. data/standard/libvirt/commands/start_vm.rb +0 -6
  178. data/standard/libvirt/commands/stop_vm.rb +0 -6
  179. data/standard/libvirt/libvirt.plugin +0 -2
  180. data/standard/linux/commands/disk_free.rb +0 -26
  181. data/standard/linux/commands/disk_used.rb +0 -4
  182. data/standard/linux/commands/find.rb +0 -15
  183. data/standard/linux/commands/mkdir.rb +0 -6
  184. data/standard/linux/todo +0 -2
  185. data/standard/machines/commands/list_machines_old.rb +0 -7
  186. data/standard/machines/commands/machine.rb +0 -3
  187. data/standard/machines/commands/run_command.rb +0 -10
  188. data/standard/plugin.vop +0 -1
  189. data/standard/services/loader/service.rb +0 -3
  190. data/standard/vagrant/commands/vagrant_global_status.rb +0 -32
  191. data/standard/vagrant/vagrant.plugin +0 -1
  192. data/standard/working_copies/commands/git_working_copies.rb +0 -11
  193. data/standard/working_copies/commands/list_project_folders.rb +0 -8
  194. data/standard/working_copies/commands/working_copy.rb +0 -3
  195. data/standard/working_copies/working_copies.plugin +0 -1
@@ -0,0 +1,30 @@
1
+ param! "machines", multi: true
2
+
3
+ contribute to: "machines_found" do |machines|
4
+ stats = Hash.new { |h,k| h[k] = 0 }
5
+
6
+ machines.each do |machine_row|
7
+ name = machine_row["name"]
8
+
9
+ if name.nil?
10
+ $logger.error "a machine has been found without a name : #{machine_row.pretty_inspect}"
11
+ end
12
+ existing = Machine.find_by_name(name)
13
+ if existing
14
+ existing.seen_at = Time.now()
15
+ existing.save
16
+ stats[:existing] += 1
17
+ $logger.debug "updating #{name}"
18
+ else
19
+ new_machine = Machine.create!(name: name)
20
+ stats[:new] += 1
21
+ $logger.debug "new #{name}"
22
+ end
23
+ end
24
+
25
+ # TODO maybe invalidate only if there are new machines?
26
+ @op.rails_machines!
27
+ @op.redis_machines!
28
+
29
+ stats
30
+ end
@@ -0,0 +1 @@
1
+ depends_on :machines
@@ -0,0 +1,5 @@
1
+ run do |plugin|
2
+ redis = plugin.state[:redis]
3
+
4
+ redis.flushall
5
+ end
@@ -0,0 +1,26 @@
1
+ param! "command"
2
+ param! "raw_params", default: {}
3
+
4
+ run do |params, plugin|
5
+ redis = plugin.state[:redis]
6
+
7
+ request = Request.new(@op, params["command"], params["raw_params"])
8
+ $logger.debug "invalidating #{request.cache_key}"
9
+
10
+ count = redis.del request.cache_key
11
+ $logger.debug "removed #{count} key(s) from cache : #{request.cache_key}"
12
+
13
+ command = @op.commands[params["command"]]
14
+ raise "no such command #{params["command"]}" if command.nil?
15
+
16
+ if command.invalidation_block
17
+ $logger.debug "calling custom invalidation block for #{command.name}"
18
+
19
+ block_param_names = command.invalidation_block.parameters.map { |x| x.last }
20
+ payload = @op.executor.prepare_payload(request, {}, block_param_names)
21
+
22
+ command.invalidation_block.call(*payload)
23
+ end
24
+
25
+ count
26
+ end
@@ -0,0 +1,78 @@
1
+ require_relative "../helpers/cache_wrapper"
2
+
3
+ run do |command, request, plugin|
4
+ should_cache = command.read_only
5
+
6
+ if should_cache
7
+ # TODO we need this workaround (to get the plugin) because the above "plugin" is the one for the command that's executed
8
+ redis = @op.plugin("redis_cache").state[:redis]
9
+ raise "no redis connection" unless redis
10
+
11
+ cache_wrapper = CacheWrapper.from_json redis.get(request.cache_key)
12
+ cached = nil
13
+ if cache_wrapper
14
+ cache_state = "hit"
15
+ cached = cache_wrapper.data
16
+ origin_class = cache_wrapper.options["origin"]
17
+ (main, child) = origin_class.split("/")
18
+ if main == "Array" && child == "Vop::Entity"
19
+ cached.map! do |entity_data|
20
+ Entity.json_create(plugin.op, entity_data)
21
+ end
22
+ end
23
+ else
24
+ cache_state = "miss"
25
+ end
26
+ $logger.debug "cache #{cache_state} : #{request.cache_key}"
27
+
28
+ result = nil
29
+ response = nil
30
+ unless cached.nil?
31
+ result = cached
32
+
33
+ description = if result.respond_to? :size
34
+ size_text = " "
35
+ size_text += result.size.to_s
36
+ size_text += if result.is_a? Array
37
+ " lines"
38
+ else
39
+ " bytes (?)"
40
+ end
41
+ size_text
42
+ else
43
+ result
44
+ end
45
+
46
+ timestamp = nil
47
+ begin
48
+ timestamp = Time.at(cache_wrapper.timestamp)
49
+ rescue TypeError => detail
50
+ $logger.error("cannot parse timestamp #{cache_wrapper.timestamp}")
51
+ end
52
+ response = Response.new(result, {}, timestamp)
53
+ else
54
+ response = request.next_filter.execute(request)
55
+ fresh_result = response.result
56
+ context = response.context
57
+
58
+ origin_class = fresh_result.class.to_s
59
+ if fresh_result.is_a?(Array)
60
+ origin_class += "/#{fresh_result.first.class.to_s}"
61
+ end
62
+ for_cache = CacheWrapper.new(fresh_result, {"origin" => origin_class})
63
+ json = nil
64
+ begin
65
+ # TODO filter sensitive data
66
+ json = for_cache.to_json
67
+ $logger.debug "caching for #{request.cache_key} (#{origin_class}) : #{json}"
68
+ redis.set(request.cache_key, json)
69
+ rescue => detail
70
+ $logger.warn("could not cache #{request.cache_key} - response not serializable")
71
+ end
72
+ result = fresh_result
73
+ end
74
+ raise ::Vop::InterruptChain.new(response)
75
+ else
76
+ request.next_filter.execute(request)
77
+ end
78
+ end
@@ -0,0 +1,35 @@
1
+ module Vop
2
+
3
+ class CacheWrapper
4
+
5
+ attr_reader :data, :options, :timestamp
6
+
7
+ def initialize(data, options = {}, timestamp = nil)
8
+ @data = data
9
+ @options = options
10
+ @timestamp = timestamp || Time.now
11
+ end
12
+
13
+ def to_json
14
+ begin
15
+ JSON.generate({
16
+ "options" => options,
17
+ "data" => data,
18
+ "timestamp" => @timestamp.to_i
19
+ })
20
+ rescue => detail
21
+ $logger.warn("problem generating JSON : #{detail.message}")
22
+ $logger.debug("offending payload : #{data.pretty_inspect}")
23
+ raise detail
24
+ end
25
+ end
26
+
27
+ def self.from_json string
28
+ return if string.nil?
29
+ payload = JSON.load(string)
30
+ self.new(payload["data"], payload["options"], payload["timestamp"])
31
+ end
32
+
33
+ end
34
+
35
+ end
@@ -0,0 +1,8 @@
1
+ require "redis"
2
+
3
+ on :init do |plugin|
4
+ plugin.state[:redis] = Redis.new()
5
+ $logger.debug "redis_cache init : #{plugin.state[:redis]}"
6
+ end
7
+
8
+ #autoload false
@@ -0,0 +1,93 @@
1
+ description "converts a pre-installed spare machine into a usable installation"
2
+
3
+ param! :machine, "the spare to convert"
4
+ param! "new_name", "name for the new machine"
5
+
6
+ run do |machine, new_name|
7
+ host = machine.parent
8
+
9
+ # TODO sanity check that this is called on a spare vm, not a host?
10
+ # TODO sanity check that the spare is in a usable state?
11
+ host_name = machine.name
12
+
13
+ @op.track_installation_status(
14
+ host_name: host_name,
15
+ vm_name: new_name,
16
+ status: "converting"
17
+ )
18
+
19
+ vm_name = machine.name.split(".").first
20
+ $logger.info "converting #{vm_name} into #{new_name} ..."
21
+
22
+ begin
23
+ # rename and shutdown
24
+ machine.set_hostname("new_name" => new_name)
25
+ begin
26
+ machine.sudo "shutdown -h now"
27
+ rescue
28
+ $logger.info "caught exception during VM shutdown, probably normal"
29
+ end
30
+
31
+ @op.wait("timeout" => 120, "block" => lambda do
32
+ vm = host.list_vms!.select { |x| x["name"] == vm_name }.first
33
+ raise "vm #{vm_name} not found on #{host.name}" if vm.nil?
34
+
35
+ vm["state"] == "shut off"
36
+ end)
37
+
38
+ # libvirt rename
39
+ host.rename_vm("vm_name" => vm_name, "new_name" => new_name)
40
+
41
+ # scan again so that we have SSH connect metadata
42
+ scanned = host.list_vms_for_scan
43
+ @op.machines_found(scanned)
44
+
45
+ # TODO adjust memory, CPU and disk (see 0.2.x)
46
+
47
+ # start converted VM
48
+ host.start_vm("name" => new_name)
49
+
50
+ @op.wait("timeout" => 120, "block" => lambda do
51
+ new_vm_list = @op.list_vms!("machine" => host.name)
52
+ vm = new_vm_list.select { |x| x["name"] == new_name }.first
53
+ raise "vm #{new_name} not found on #{host.name}" if vm.nil?
54
+
55
+ vm["state"] == "running"
56
+ end)
57
+
58
+ full_name = "#{new_name}.#{host.name}"
59
+
60
+ # wait until vm_addresses returns a meaningful result
61
+ @op.wait(
62
+ "timeout" => 30,
63
+ "block" => lambda do
64
+ addresses = host.vm_addresses!("name" => new_name)
65
+ $logger.debug "addresses : #{addresses.pretty_inspect}"
66
+ ! addresses.nil? && ! addresses.empty?
67
+ end
68
+ )
69
+
70
+ @op.ssh_options!("machine" => full_name)
71
+
72
+ # clean previous SSH keys for VMs with the same name/IP
73
+ vm_address = host.vm_address(name: new_name)
74
+ @op.clean_known_host(ip: vm_address)
75
+
76
+ @op.track_installation_status(
77
+ host_name: host_name,
78
+ vm_name: new_name,
79
+ status: "converted"
80
+ )
81
+ rescue => detail
82
+ $logger.error "problem converting spare #{vm_name} into #{new_name} : #{detail.message}"
83
+ @op.track_installation_status(
84
+ host_name: host_name,
85
+ vm_name: new_name,
86
+ status: "converting_failed"
87
+ )
88
+ ensure
89
+ host.post_convert_spare("converted" => vm_name)
90
+ end
91
+
92
+ full_name
93
+ end
@@ -0,0 +1,9 @@
1
+ param! :machine
2
+
3
+ run do |machine|
4
+ machine.list_vms.map do |vm|
5
+ vm["name"] =~ /^spare/ &&
6
+ vm["state"] == "running" &&
7
+ @op.test_ssh("machine" => "#{vm['name']}.#{machine.name}") ? vm["name"] : nil
8
+ end.compact
9
+ end
@@ -0,0 +1,24 @@
1
+ param! "name"
2
+
3
+ param! :machine, description: "a virtualization host on which the VM should be created"
4
+
5
+ run do |machine, name, params|
6
+ spare = full_name = nil
7
+
8
+ spares = machine.list_spares
9
+ # TODO this should happen within a lock
10
+ # TODO also, we should only use spares that have been installed completely
11
+ if spares.size > 0
12
+ spare = spares.first
13
+ spare_full_name = "#{spare}.#{machine.name}"
14
+ p = { :machine => spare_full_name, "new_name" => name }
15
+ $logger.info "calling convert_spare : #{p.pretty_inspect}"
16
+ full_name = @op.convert_spare(p)
17
+ end
18
+
19
+ if spare.nil?
20
+ full_name = machine.new_vm_from_scratch(params)
21
+ end
22
+
23
+ full_name
24
+ end
@@ -0,0 +1,13 @@
1
+ description "hook that is called when a spare has been converted"
2
+
3
+ param! :machine
4
+ param "converted"
5
+
6
+ run do |machine, converted|
7
+ $logger.info "post_convert_spare #{machine.name} (#{converted})"
8
+ # TODO cleanup
9
+ #PrepareSparesWorker.perform_async(machine.name)
10
+
11
+ request = ::Vop::Request.new(@op, "prepare_spares", {"machine" => machine.name})
12
+ @op.execute_async(request)
13
+ end
@@ -0,0 +1,17 @@
1
+ param! :machine
2
+ param "count", description: "number of spares that should be available", default: 3
3
+
4
+ run do |machine, count|
5
+ existing = machine.list_spares
6
+
7
+ result = []
8
+ 1.upto(count.to_i) do |idx|
9
+ vm_name = "spare#{sprintf('%02d', idx)}"
10
+
11
+ unless existing.include? vm_name
12
+ machine.new_vm_from_scratch("name" => vm_name)
13
+ result << vm_name
14
+ end
15
+ end
16
+ result
17
+ end
@@ -0,0 +1,29 @@
1
+ description "waits until a condition has been met"
2
+
3
+ param! "block", "the block that should be executed periodically. should return true if the condition is met, false otherwise"
4
+ param! "timeout", description: "number of seconds to wait for the condition to be met", default: 60
5
+ param! "interval", description: "seconds to wait between tries", default: 1
6
+ param "error_text", description: "text that is displayed when the specified timeout is reached", default: "condition not met"
7
+
8
+ run do |timeout, interval, error_text, params|
9
+ block = params["block"]
10
+ seconds_waited = 0
11
+
12
+ current_result = false
13
+ while (seconds_waited < timeout.to_i) do
14
+ begin
15
+ current_result = block.call()
16
+ rescue Exception => e
17
+ $logger.warn("got an exception while waiting : #{e.message}")
18
+ end
19
+
20
+ $logger.debug("checked condition : #{current_result}")
21
+ break if current_result
22
+
23
+ sleep(interval.to_i)
24
+ seconds_waited += interval.to_i
25
+ end
26
+
27
+ raise Exception.new(error_text) unless current_result
28
+ current_result
29
+ end
@@ -0,0 +1,9 @@
1
+ param! :machine
2
+ param! "name"
3
+
4
+ run do |machine, name|
5
+ full_name = machine.convert_spare("new_name" => name)
6
+ vm = @op.machines[full_name]
7
+ host = vm.parent
8
+ host.vm_addresses!("name" => name)
9
+ end
@@ -0,0 +1 @@
1
+ depends_on :rails_machines
File without changes
@@ -0,0 +1,14 @@
1
+ param! :machine
2
+ param! "url"
3
+ param! "dist", default: "stable"
4
+ param! "alias"
5
+ param! "key"
6
+ param "component", default: ""
7
+
8
+ run do |params, machine, component|
9
+ # TODO verify that repo[:alias] is a valid filename?
10
+ machine.ssh("request_pty" => true,
11
+ "command" => "echo 'deb #{params["url"]} #{params["dist"]} #{component}' | sudo tee /etc/apt/sources.list.d/#{params["alias"]}.list")
12
+ machine.ssh("request_pty" => true, "command" => "wget -qO - #{params["key"]} | sudo apt-key add")
13
+ machine.sudo("apt-get update")
14
+ end
@@ -0,0 +1,19 @@
1
+ param! :machine
2
+ param! "git_url", description: "URL to the github repository to deploy"
3
+ param! "domain", multi: true, description: "the domain on which the project should be deployed"
4
+ param "subfolder", description: "folder inside git checkout that should be published (as web root)"
5
+
6
+ contribute to: "deploy" do |machine, git_url, domain, params, subfolder|
7
+ machine.install_service("service" => "apache.apache")
8
+
9
+ web_root = machine.git_clone_web(git_url)
10
+ if subfolder
11
+ web_root = File.join(web_root, subfolder)
12
+ end
13
+ machine.add_static_vhost("server_name" => domain, "web_root" => web_root)
14
+
15
+ machine.parent.reverse_proxy.add_reverse_proxy(
16
+ "server_name" => domain,
17
+ "target_url" => "http://#{machine.internal_ip}/"
18
+ )
19
+ end
@@ -0,0 +1,34 @@
1
+ param! :machine
2
+ param! "git_url", description: "URL to the github repository to deploy"
3
+ param! "domain", multi: true, description: "the domain on which the project should be deployed"
4
+ param "subfolder", description: "folder inside git checkout that should be published (as web root)"
5
+
6
+ contribute to: "deploy" do |machine, git_url, domain, params, subfolder|
7
+ host_name = machine.parent.name
8
+ @op.track_installation_status(
9
+ host_name: host_name,
10
+ vm_name: machine.name.split(".").first,
11
+ status: "deploying"
12
+ )
13
+
14
+ machine.install_service("service" => "apache.apache")
15
+
16
+ web_root = machine.git_clone_web(git_url)
17
+ if subfolder
18
+ web_root = File.join(web_root, subfolder)
19
+ end
20
+ machine.add_static_vhost("server_name" => domain, "web_root" => web_root)
21
+
22
+ # TODO actually, this should maybe be machine.publish(machine.internal_ip => domain)
23
+ # (and the apache-specific add_reverse_proxy contributes to publish)
24
+ machine.parent.reverse_proxy.add_reverse_proxy(
25
+ "server_name" => domain,
26
+ "target_url" => "http://#{machine.internal_ip}/"
27
+ )
28
+
29
+ @op.track_installation_status(
30
+ host_name: host_name,
31
+ vm_name: machine.name.split(".").first,
32
+ status: "deployed"
33
+ )
34
+ end