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.
- checksums.yaml +4 -4
- data/Rakefile +2 -2
- data/extended/hetzner/commands/add_ssh_key.rb +22 -0
- data/extended/hetzner/commands/disable_linux_install.rb +26 -0
- data/extended/hetzner/commands/enable_linux_install.rb +41 -0
- data/extended/hetzner/commands/hetzner_http.rb +24 -0
- data/extended/hetzner/commands/hetzner_machines.rb +11 -0
- data/extended/hetzner/commands/hetzner_server_list.rb +26 -0
- data/extended/hetzner/commands/linux_install_options.rb +29 -0
- data/extended/hetzner/commands/list_ssh_keys.rb +16 -0
- data/extended/hetzner/entities/hetzner_account.rb +9 -0
- data/extended/hetzner/hetzner.plugin +3 -0
- data/extended/hetzner_vop_0_2_x/commands/list_old_v2_vms.rb +46 -0
- data/extended/hetzner_vop_0_2_x/commands/old_libvirt_machines.rb +16 -0
- data/extended/hetzner_vop_0_2_x/commands/vop_0_2_x_ssh_options.rb +20 -0
- data/extended/hetzner_vop_0_2_x/hetzner_vop_0_2_x.plugin +5 -0
- data/extended/libvirt/commands/delete_vm.rb +32 -0
- data/extended/libvirt/commands/libvirt_config_file.rb +5 -0
- data/extended/libvirt/commands/libvirt_machines.rb +17 -0
- data/extended/libvirt/commands/libvirt_ssh_options.rb +29 -0
- data/extended/libvirt/commands/list_networks.rb +21 -0
- data/extended/libvirt/commands/list_pools.rb +20 -0
- data/extended/libvirt/commands/list_vms.rb +28 -0
- data/extended/libvirt/commands/list_vms_for_scan.rb +12 -0
- data/extended/libvirt/commands/list_vms_with_addresses.rb +20 -0
- data/extended/libvirt/commands/new_vm.rb +110 -0
- data/extended/libvirt/commands/parent.rb +10 -0
- data/extended/libvirt/commands/rename_vm.rb +34 -0
- data/extended/libvirt/commands/start_vm.rb +7 -0
- data/extended/libvirt/commands/stop_vm.rb +8 -0
- data/extended/libvirt/commands/vm_address.rb +7 -0
- data/extended/libvirt/commands/vm_addresses.rb +32 -0
- data/extended/libvirt/commands/vnc_ports.rb +32 -0
- data/extended/libvirt/helpers/helper.rb +3 -0
- data/extended/libvirt/libvirt.plugin +5 -0
- data/extended/libvirt/services/libvirt.rb +19 -0
- data/extended/libvirt_with_proxy/commands/reverse_proxy.rb +13 -0
- data/extended/libvirt_with_proxy/commands/vms_with_domains.rb +18 -0
- data/extended/libvirt_with_proxy/entities/_vms_with_domains.rbx +24 -0
- data/extended/libvirt_with_proxy/libvirt_with_proxy.plugin +1 -0
- data/extended/rails_machines/commands/rails_machines.rb +6 -0
- data/extended/rails_machines/commands/update_status.rb +38 -0
- data/extended/rails_machines/commands/write_found_machines_into_rails_db.rb.not +30 -0
- data/extended/rails_machines/rails_machines.plugin +1 -0
- data/extended/redis_cache/commands/flush_cache.rb +5 -0
- data/extended/redis_cache/commands/invalidate_cache.rb +26 -0
- data/extended/redis_cache/filters/cache_filter.rb +78 -0
- data/extended/redis_cache/helpers/cache_wrapper.rb +35 -0
- data/extended/redis_cache/redis_cache.plugin +8 -0
- data/extended/spares/commands/convert_spare.rb +93 -0
- data/extended/spares/commands/list_spares.rb +9 -0
- data/extended/spares/commands/new_vm_from_spare.rb +24 -0
- data/extended/spares/commands/post_convert_spare.rb +13 -0
- data/extended/spares/commands/prepare_spares.rb +17 -0
- data/extended/spares/commands/wait.rb +29 -0
- data/extended/spares/commands/wtf.rb +9 -0
- data/extended/spares/spares.plugin +1 -0
- data/standard/apt/apt.plugin +0 -0
- data/standard/apt/commands/add_apt_repo.rb +14 -0
- data/standard/git/commands/deploy.rb +19 -0
- data/standard/git/commands/deploy_from_git.rb +34 -0
- data/standard/git/commands/deploy_from_github.rb +12 -0
- data/standard/git/commands/git_clone.rb +7 -0
- data/standard/git/commands/git_clone_web.rb +22 -0
- data/standard/git/git.plugin +0 -0
- data/standard/linux/commands/append_to_file.rb +14 -0
- data/standard/linux/commands/chmod.rb +7 -0
- data/standard/linux/commands/curl.rb +15 -0
- data/standard/linux/commands/current_user.rb +5 -0
- data/standard/linux/commands/distro.rb +2 -1
- data/standard/linux/commands/download_file.rb +6 -6
- data/standard/linux/commands/external_ip.rb +15 -0
- data/standard/linux/commands/file_exists.rb +7 -0
- data/standard/linux/commands/home.rb +7 -0
- data/standard/linux/commands/hostname.rb +5 -0
- data/standard/linux/commands/internal_ip.rb +14 -0
- data/standard/linux/commands/ipaddress.rb +10 -0
- data/standard/linux/commands/list_files.rb +8 -6
- data/standard/linux/commands/list_ip_addresses.rb +22 -0
- data/standard/linux/commands/listen_ports.rb +3 -2
- data/standard/linux/commands/maybe_sudo.rb +8 -0
- data/standard/linux/commands/mkdirs.rb +12 -0
- data/standard/linux/commands/processes.rb +8 -6
- data/standard/linux/commands/processes_like.rb +7 -7
- data/standard/linux/commands/processes_top.rb +23 -0
- data/standard/linux/commands/processes_top_cpu.rb +8 -0
- data/standard/linux/commands/processes_top_mem.rb +8 -0
- data/standard/linux/commands/read_file.rb +7 -2
- data/standard/linux/commands/replace_in_file.rb +22 -0
- data/standard/linux/commands/set_hostname.rb +36 -0
- data/standard/linux/commands/update_hosts_file.rb +27 -0
- data/standard/linux/commands/write_file.rb +8 -21
- data/standard/linux/linux.plugin +1 -2
- data/standard/machines/commands/delete_old_machines.rb +17 -0
- data/standard/machines/commands/localhost.rb +7 -2
- data/standard/machines/commands/localhost_ssh_options.rb +9 -0
- data/standard/machines/commands/new_machine.rb +24 -0
- data/standard/machines/commands/new_vm_from_scratch.rb +25 -0
- data/standard/machines/commands/old_machines.rb +6 -0
- data/standard/machines/commands/select_machine.rb +4 -5
- data/standard/machines/entities/machine.rb +12 -0
- data/standard/machines/machines.plugin +1 -1
- data/standard/redis_machines/commands/installation_status.rb +10 -0
- data/standard/redis_machines/commands/track_installation_status.rb +13 -0
- data/standard/redis_machines/redis_machines.plugin +3 -0
- data/standard/rpm/commands/list_rpm_packages.rb +24 -0
- data/standard/rpm/rpm.plugin +1 -0
- data/standard/scanner/commands/clean_metadata.rb +8 -0
- data/standard/scanner/commands/fresh_ssh_test.rb +6 -0
- data/standard/scanner/commands/inspect_async.rb +6 -0
- data/standard/scanner/commands/inspect_machine.rb +42 -0
- data/standard/scanner/commands/machines_found.rb +35 -0
- data/standard/scanner/commands/metadata.rb +9 -0
- data/standard/scanner/commands/redis_machines.rb +11 -0
- data/standard/scanner/commands/scan.rb +5 -0
- data/standard/scanner/commands/scan_host.rb +7 -0
- data/standard/scanner/commands/scan_machines.rb +11 -0
- data/standard/scanner/commands/trigger_ssh_test.rb +8 -0
- data/standard/scanner/scanner.plugin +5 -0
- data/standard/services/commands/describe_service.rb +7 -0
- data/standard/services/commands/describe_service_installation.rb +13 -0
- data/standard/services/commands/detect_services.rb +34 -0
- data/standard/services/commands/install_service.rb +134 -0
- data/standard/services/commands/list_known_services.rb +14 -0
- data/standard/services/commands/load_plugin_services.rb +17 -0
- data/standard/services/entities/service.rb +3 -0
- data/standard/services/helpers/service.rb +31 -0
- data/standard/services/helpers/service_loader.rb +50 -0
- data/standard/services/helpers/service_syntax.rb +126 -0
- data/standard/services/services.plugin +9 -0
- data/standard/ssh/commands/clean_known_host.rb +11 -0
- data/standard/ssh/commands/clear_ssh_cache.rb +9 -0
- data/standard/ssh/commands/get_ssh_connection.rb +36 -0
- data/standard/ssh/commands/scp_down.rb +9 -0
- data/standard/ssh/commands/scp_up.rb +9 -0
- data/standard/ssh/commands/ssh.rb +20 -0
- data/standard/ssh/commands/ssh_call.rb +98 -0
- data/standard/ssh/commands/ssh_connection.rb +55 -0
- data/standard/ssh/commands/ssh_extended.rb +6 -0
- data/standard/ssh/commands/ssh_options.rb +12 -0
- data/standard/ssh/commands/sudo.rb +12 -0
- data/standard/ssh/commands/test_ssh.rb +43 -0
- data/standard/{linux → ssh}/helpers/regex.rb +0 -0
- data/standard/ssh/ssh.plugin +10 -0
- data/standard/ssh_keys/commands/add_authorized_key.rb +14 -0
- data/standard/ssh_keys/commands/disable_ssh_key_check.rb +11 -0
- data/standard/ssh_keys/commands/generate_keypair.rb +17 -0
- data/standard/ssh_keys/ssh_keys.plugin +0 -0
- data/standard/systemd/commands/disable_systemd_service.rb +8 -0
- data/standard/systemd/commands/enable_systemd_service.rb +8 -0
- data/standard/systemd/commands/list_systemd_services.rb +23 -0
- data/standard/systemd/commands/start_systemd_service.rb +6 -0
- data/standard/systemd/commands/stop_systemd_service.rb +6 -0
- data/standard/systemd/commands/systemd_service_status.rb +6 -0
- data/standard/systemd/commands/write_systemd_config.rb +16 -0
- data/standard/systemd/helpers/param_service.rb +7 -0
- data/standard/systemd/systemd.plugin +0 -0
- data/standard/systemd/templates/systemd_service.erb +11 -0
- data/standard/templates/commands/read_template.rb +8 -0
- data/standard/templates/commands/write_template.rb +37 -0
- data/standard/templates/templates.plugin +3 -0
- data/vop-plugins.gemspec +6 -7
- metadata +156 -55
- data/Gemfile +0 -3
- data/Gemfile.lock +0 -68
- data/standard/debian-iso/commands/fetch_debian_iso.rb +0 -3
- data/standard/debian-iso/commands/fetch_ubuntu_iso.rb +0 -22
- data/standard/debian-iso/commands/list_isos.rb +0 -6
- data/standard/debian-iso/commands/rebuild_debian_iso.rb +0 -40
- data/standard/debian-iso/debian-iso.plugin +0 -2
- data/standard/debian-iso/files/rebuild-debian-iso +0 -74
- data/standard/debian-iso/templates/preseed.cfg +0 -45
- data/standard/libvirt/commands/delete_vm.rb +0 -16
- data/standard/libvirt/commands/list_local_vms.rb +0 -4
- data/standard/libvirt/commands/list_vms.rb +0 -15
- data/standard/libvirt/commands/new_vm.rb +0 -61
- data/standard/libvirt/commands/start_vm.rb +0 -6
- data/standard/libvirt/commands/stop_vm.rb +0 -6
- data/standard/libvirt/libvirt.plugin +0 -2
- data/standard/linux/commands/disk_free.rb +0 -26
- data/standard/linux/commands/disk_used.rb +0 -4
- data/standard/linux/commands/find.rb +0 -15
- data/standard/linux/commands/mkdir.rb +0 -6
- data/standard/linux/todo +0 -2
- data/standard/machines/commands/list_machines_old.rb +0 -7
- data/standard/machines/commands/machine.rb +0 -3
- data/standard/machines/commands/run_command.rb +0 -10
- data/standard/plugin.vop +0 -1
- data/standard/services/loader/service.rb +0 -3
- data/standard/vagrant/commands/vagrant_global_status.rb +0 -32
- data/standard/vagrant/vagrant.plugin +0 -1
- data/standard/working_copies/commands/git_working_copies.rb +0 -11
- data/standard/working_copies/commands/list_project_folders.rb +0 -8
- data/standard/working_copies/commands/working_copy.rb +0 -3
- data/standard/working_copies/working_copies.plugin +0 -1
@@ -0,0 +1,20 @@
|
|
1
|
+
param! :machine
|
2
|
+
|
3
|
+
run do |machine|
|
4
|
+
result = []
|
5
|
+
|
6
|
+
input = machine.ssh "command" => "sudo virsh pool-list", "request_pty" => true
|
7
|
+
input.lines[2..-1].each do |line|
|
8
|
+
line.strip!
|
9
|
+
next if line.empty?
|
10
|
+
|
11
|
+
(name, state, autostart) = line.strip.split
|
12
|
+
result << {
|
13
|
+
"name" => name,
|
14
|
+
"state" => state,
|
15
|
+
"autostart" => autostart
|
16
|
+
}
|
17
|
+
end
|
18
|
+
|
19
|
+
result
|
20
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
param! :machine
|
2
|
+
param "with_addresses", default: false
|
3
|
+
|
4
|
+
read_only
|
5
|
+
|
6
|
+
run do |machine, with_addresses|
|
7
|
+
ext_result = machine.ssh_call("command" => "which virsh")
|
8
|
+
if ext_result["result_code"].to_i > 0
|
9
|
+
$logger.warn "no 'virsh' found on #{machine.name}"
|
10
|
+
[]
|
11
|
+
else
|
12
|
+
# TODO should we source /etc/profile generally before all ssh commands?
|
13
|
+
output = machine.ssh ". /etc/profile && virsh list --all"
|
14
|
+
|
15
|
+
data = output.strip.lines[2,output.length-1]
|
16
|
+
data.map do |line|
|
17
|
+
(unused_id, name, *state) = line.strip.split
|
18
|
+
h = {
|
19
|
+
"name" => name,
|
20
|
+
"state" => state.join(" ")
|
21
|
+
}
|
22
|
+
if with_addresses
|
23
|
+
h["ip"] = machine.vm_address(name)
|
24
|
+
end
|
25
|
+
h
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
param! :machine
|
2
|
+
|
3
|
+
run do |machine|
|
4
|
+
machine.list_vms.map do |vm|
|
5
|
+
$logger.debug "vm : #{vm.pretty_inspect}"
|
6
|
+
|
7
|
+
metadata = @op.metadata("#{vm["name"]}.#{machine.name}")
|
8
|
+
# workaround for old vop 0.2.x-style VMs that do not have domifaddr:
|
9
|
+
if metadata.has_key?("source") && metadata["source"] == "list_old_v2_vms"
|
10
|
+
if metadata.has_key?("ip")
|
11
|
+
vm["address"] = metadata["ip"]
|
12
|
+
end
|
13
|
+
else
|
14
|
+
if vm["state"] == "running"
|
15
|
+
vm["address"] = machine.vm_address("name" => vm["name"])
|
16
|
+
end
|
17
|
+
end
|
18
|
+
vm
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,110 @@
|
|
1
|
+
param! :machine
|
2
|
+
|
3
|
+
param! "name"
|
4
|
+
|
5
|
+
param "memory", description: "in MB", default: 512
|
6
|
+
param "cpu_count", default: 1
|
7
|
+
param "disk_size", description: "in GB", default: 25
|
8
|
+
param "iso_path", description: "path to the ISO image of an installation CD",
|
9
|
+
default: "/data/libvirt/isos/ubuntu-16.04.3-server-amd64.rebuilt17.iso"
|
10
|
+
param "vnc_listen_address", description: "address on which the VM should be accessible through VNC", default: "127.0.0.1"
|
11
|
+
|
12
|
+
param "no_os_variant", default: true # On Ubuntu 17.10, there's no OS variant for ubuntu 17.10...
|
13
|
+
|
14
|
+
run do |machine, name, memory, cpu_count, disk_size, iso_path, vnc_listen_address, no_os_variant|
|
15
|
+
@op.track_installation_status(
|
16
|
+
host_name: machine.name,
|
17
|
+
vm_name: name,
|
18
|
+
status: "provisioning"
|
19
|
+
)
|
20
|
+
|
21
|
+
$logger.info "starting to install VM '#{name}' on '#{machine.name}'"
|
22
|
+
|
23
|
+
begin
|
24
|
+
image_dir = "/var/lib/libvirt/images"
|
25
|
+
image_path = "#{image_dir}/#{name}.img"
|
26
|
+
|
27
|
+
os_type = "linux"
|
28
|
+
os_variant = nil
|
29
|
+
file_name = File.basename(iso_path)
|
30
|
+
# TODO would be nice if this would support more distros
|
31
|
+
if file_name =~ /ubuntu-([\d\.]+)-/
|
32
|
+
numbers = $1
|
33
|
+
version = numbers.split(".")[0..1].join(".")
|
34
|
+
os_variant = "ubuntu#{version}"
|
35
|
+
end
|
36
|
+
|
37
|
+
command = "virt-install" \
|
38
|
+
" --name #{name}" \
|
39
|
+
" --ram #{memory}" \
|
40
|
+
" --vcpus #{cpu_count}" \
|
41
|
+
" --os-type=#{os_type}"
|
42
|
+
|
43
|
+
if os_variant && ! no_os_variant
|
44
|
+
command += " --os-variant=#{os_variant}"
|
45
|
+
end
|
46
|
+
|
47
|
+
command += " --accelerate" \
|
48
|
+
" --network network=default,model=virtio" \
|
49
|
+
" --disk path=#{image_path},size=#{disk_size},sparse=false,cache=none,bus=virtio" \
|
50
|
+
" --cdrom #{iso_path}" \
|
51
|
+
" --graphics vnc,listen=#{vnc_listen_address}" \
|
52
|
+
" -v"
|
53
|
+
machine.sudo(command)
|
54
|
+
|
55
|
+
scanned = machine.list_vms_for_scan
|
56
|
+
@op.machines_found(scanned)
|
57
|
+
|
58
|
+
host_name = machine.name
|
59
|
+
full_name = "#{name}.#{host_name}"
|
60
|
+
vm = @op.machines[full_name]
|
61
|
+
$logger.info "vm setup complete, testing SSH connect to #{vm.name}..."
|
62
|
+
$logger.debug "ssh options : #{vm.ssh_options}"
|
63
|
+
|
64
|
+
# remove old host key
|
65
|
+
machine.vm_addresses!(name: name)
|
66
|
+
vm_address = machine.vm_address(name: name)
|
67
|
+
@op.clean_known_host(ip: vm_address)
|
68
|
+
|
69
|
+
$logger.info "waiting 5"
|
70
|
+
sleep 5
|
71
|
+
|
72
|
+
success = 0
|
73
|
+
max_tries = 25
|
74
|
+
max_tries.downto(0) do |idx|
|
75
|
+
break if success >= 3
|
76
|
+
$logger.info "waiting 2 [##{idx}]"
|
77
|
+
sleep 2
|
78
|
+
begin
|
79
|
+
machine.vm_addresses!("name" => name)
|
80
|
+
vm.ssh_options!
|
81
|
+
if vm.test_ssh!
|
82
|
+
success += 1
|
83
|
+
$logger.info "ssh connects successful : #{success}"
|
84
|
+
end
|
85
|
+
rescue => e
|
86
|
+
$logger.error "ssh connect failed : #{e.message}"
|
87
|
+
end
|
88
|
+
end
|
89
|
+
|
90
|
+
@op.track_installation_status(
|
91
|
+
host_name: machine.name,
|
92
|
+
vm_name: name,
|
93
|
+
status: "provisioned"
|
94
|
+
)
|
95
|
+
rescue => e
|
96
|
+
@op.track_installation_status(
|
97
|
+
host_name: machine.name,
|
98
|
+
vm_name: name,
|
99
|
+
status: "provisioning_failed"
|
100
|
+
)
|
101
|
+
$logger.error("provisiong of vm #{name} on host #{machine.name} failed: #{e.message}\n#{e.backtrace.join("\n")}")
|
102
|
+
end
|
103
|
+
|
104
|
+
$logger.info "new machine #{name} provisioned on host #{machine.name}"
|
105
|
+
|
106
|
+
machine.list_vms!
|
107
|
+
machine.processes!
|
108
|
+
|
109
|
+
vm
|
110
|
+
end
|
@@ -0,0 +1,10 @@
|
|
1
|
+
param! :machine
|
2
|
+
|
3
|
+
run do |machine|
|
4
|
+
parts = machine.name.split(".")
|
5
|
+
if parts.size < 3
|
6
|
+
raise "the machine name consists of two parts only - are you sure that you're not on a host?"
|
7
|
+
end
|
8
|
+
parent_name = parts[1..-1].join(".")
|
9
|
+
@op.machines[parent_name]
|
10
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
require "xmlsimple"
|
2
|
+
|
3
|
+
description "renames a VM (config file and storage pool)"
|
4
|
+
|
5
|
+
param! :machine
|
6
|
+
param! "vm_name"
|
7
|
+
param! "new_name", "the name for the new VM"
|
8
|
+
|
9
|
+
run do |machine, vm_name, new_name, params|
|
10
|
+
# prepare new config
|
11
|
+
xml_file_name = libvirt_config_file(vm_name)
|
12
|
+
new_file_name = (xml_file_name.split("/")[0..-2] << "#{new_name}.xml").join("/")
|
13
|
+
|
14
|
+
machine.sudo "cp #{xml_file_name} #{new_file_name}"
|
15
|
+
machine.replace_in_file("file_name" => new_file_name, "source" => vm_name, "target" => new_name, "sudo" => true)
|
16
|
+
|
17
|
+
# move volume
|
18
|
+
pools = machine.list_pools.map { |x| x["name"] }
|
19
|
+
pool = pools.include?("images") ? "images" : "default"
|
20
|
+
|
21
|
+
old_volume_definition = machine.ssh "virsh vol-dumpxml --pool #{pool} #{vm_name}.img"
|
22
|
+
old_volume = XmlSimple.xml_in(old_volume_definition)
|
23
|
+
old_path = old_volume["target"].first["path"].first
|
24
|
+
new_path = (old_path.split("/")[0..-2] << "#{new_name}.img").join("/")
|
25
|
+
|
26
|
+
machine.ssh "mv #{old_path} #{new_path}"
|
27
|
+
machine.ssh "touch #{old_path}"
|
28
|
+
|
29
|
+
# swap
|
30
|
+
machine.delete_vm("name" => vm_name)
|
31
|
+
machine.sudo "virsh define #{new_file_name}"
|
32
|
+
|
33
|
+
machine.list_vms!
|
34
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
param! :machine, description: "parent virtualization host"
|
2
|
+
param! "name"
|
3
|
+
|
4
|
+
read_only
|
5
|
+
|
6
|
+
run do |machine, name|
|
7
|
+
$logger.debug "reading IP address of VM #{name}"
|
8
|
+
|
9
|
+
input = machine.ssh("command" => "virsh domifaddr #{name}")
|
10
|
+
|
11
|
+
# compare headers vs. expectations
|
12
|
+
header_line = input.lines.first
|
13
|
+
headers = header_line.split
|
14
|
+
expected = ["Name", "MAC", "address", "Protocol", "Address"]
|
15
|
+
unless headers & expected == expected
|
16
|
+
raise "unexpected headers : #{headers}\nexpected : #{expected}"
|
17
|
+
end
|
18
|
+
|
19
|
+
result = []
|
20
|
+
data = input.lines[2..-1].each do |line|
|
21
|
+
line.strip!
|
22
|
+
next if line.empty?
|
23
|
+
(name, mac, protocol, address) = line.strip.split
|
24
|
+
result << {
|
25
|
+
"name" => name,
|
26
|
+
"mac_address" => mac,
|
27
|
+
"protocol" => protocol,
|
28
|
+
"address" => address.split("/").first
|
29
|
+
}
|
30
|
+
end
|
31
|
+
result
|
32
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
param! :machine
|
2
|
+
|
3
|
+
show columns: %w|vm vnc vnc_port command|
|
4
|
+
|
5
|
+
invalidate do |machine|
|
6
|
+
machine.processes!
|
7
|
+
end
|
8
|
+
|
9
|
+
run do |machine, params|
|
10
|
+
machine.processes.map do |process|
|
11
|
+
command = process["command"]
|
12
|
+
h = {
|
13
|
+
"command" => command[0..99]
|
14
|
+
}
|
15
|
+
if /virt-install/ =~ command
|
16
|
+
if /--name\s+(\S+)/ =~ command
|
17
|
+
h["vm"] = $1
|
18
|
+
end
|
19
|
+
elsif /qemu-system/ =~ command
|
20
|
+
if /guest=([^,]+)/ =~ command
|
21
|
+
h["vm"] = $1
|
22
|
+
end
|
23
|
+
end
|
24
|
+
if h["vm"]
|
25
|
+
if /vnc(?:,listen=|\s+)?([\d\.]+)(?:\:(\d+))?/ =~ process["command"]
|
26
|
+
h["vnc"] = $1
|
27
|
+
h["vnc_port"] = $2
|
28
|
+
end
|
29
|
+
end
|
30
|
+
h.has_key?("vm") ? h : nil
|
31
|
+
end.compact
|
32
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
process_regex /libvirtd/
|
2
|
+
|
3
|
+
# https://help.ubuntu.com/lts/serverguide/libvirt.html
|
4
|
+
deploy package: ["qemu-kvm", "libvirt-bin"]
|
5
|
+
deploy package: "virtinst"
|
6
|
+
deploy package: "libosinfo-bin"
|
7
|
+
|
8
|
+
deploy do |machine|
|
9
|
+
root_in_group_libvirt = !! /libvirt/.match(machine.ssh("id"))
|
10
|
+
unless root_in_group_libvirt
|
11
|
+
machine.sudo "adduser root libvirt"
|
12
|
+
end
|
13
|
+
|
14
|
+
active_networks = machine.list_networks.select { |network| network["state"] == "active" }.map { |x| x["name"] }
|
15
|
+
unless active_networks.include? "default"
|
16
|
+
machine.sudo "virsh net-start default"
|
17
|
+
end
|
18
|
+
machine.sudo "virsh net-autostart default"
|
19
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
description "called on a (libvirt) virtualization host, this will return the reverse proxy running on it (if any)"
|
2
|
+
|
3
|
+
param! :machine
|
4
|
+
|
5
|
+
run do |machine|
|
6
|
+
result = nil
|
7
|
+
if machine.detect_services.include?("libvirt.libvirt")
|
8
|
+
if machine.list_vms.map { |x| x["name"] }.include? "proxy"
|
9
|
+
result = @op.machines["proxy.#{machine.name}"]
|
10
|
+
end
|
11
|
+
end
|
12
|
+
result
|
13
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
param! :machine
|
2
|
+
|
3
|
+
run do |machine|
|
4
|
+
vms = machine.list_vms_with_addresses.map do |vm|
|
5
|
+
[ vm["address"], vm ]
|
6
|
+
end.to_h
|
7
|
+
|
8
|
+
proxy = @op.machines["proxy.#{machine.name}"]
|
9
|
+
proxy.vhosts.map do |vhost|
|
10
|
+
if vhost["proxy"]
|
11
|
+
ip = vhost["proxy"]["host"]
|
12
|
+
if vms.has_key? ip
|
13
|
+
vhost["proxy"]["hostname"] = vms[ip]["name"]
|
14
|
+
end
|
15
|
+
end
|
16
|
+
vhost.data
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
#description "called on a virtualization host, this will return all VMs with their associated domains"
|
2
|
+
|
3
|
+
key "name"
|
4
|
+
|
5
|
+
on :machine
|
6
|
+
|
7
|
+
entity do |machine|
|
8
|
+
machine = @op.machines[machine]
|
9
|
+
|
10
|
+
vms = machine.list_vms_with_addresses.map do |vm|
|
11
|
+
[ vm["address"], vm ]
|
12
|
+
end.to_h
|
13
|
+
|
14
|
+
proxy = @op.machines["proxy.#{machine.name}"]
|
15
|
+
proxy.vhosts.map do |vhost|
|
16
|
+
if vhost["proxy"]
|
17
|
+
ip = vhost["proxy"]["host"]
|
18
|
+
if vms.has_key? ip
|
19
|
+
vhost["proxy"]["hostname"] = vms[ip]["name"]
|
20
|
+
end
|
21
|
+
end
|
22
|
+
vhost.data
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
depends_on :machines
|
@@ -0,0 +1,38 @@
|
|
1
|
+
param! :machine
|
2
|
+
param "status_verb",
|
3
|
+
description: "a verb that is used as prefix for -'ing' and -'ed' to build the current status (e.g. 'deploy' becomes 'deploying' and 'deployed')",
|
4
|
+
default_param: true,
|
5
|
+
default: "deploy"
|
6
|
+
param "from", description: "the first status", default: nil
|
7
|
+
param "to", description: "the status at the end", default: nil
|
8
|
+
block_param!
|
9
|
+
|
10
|
+
run do |machine, status_verb, params, block|
|
11
|
+
# TODO something is wrong here with the block - when "from" and "to" are block params
|
12
|
+
# (without detaults), "from" gets the block value
|
13
|
+
from = params["from"]
|
14
|
+
to = params["to"]
|
15
|
+
unless status_verb || (from && to)
|
16
|
+
raise "missing arguments: need either 'status_verb' or 'from' and 'to'"
|
17
|
+
end
|
18
|
+
if status_verb
|
19
|
+
if from.nil?
|
20
|
+
from = "#{status_verb}ing"
|
21
|
+
end
|
22
|
+
|
23
|
+
if to.nil?
|
24
|
+
to = "#{status_verb}ed"
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
|
29
|
+
installation = Installation.find_or_create_by(host_name: machine.parent.name, vm_name: machine.name.split(".").first)
|
30
|
+
installation.status = from
|
31
|
+
installation.save!
|
32
|
+
|
33
|
+
block.call
|
34
|
+
#yield
|
35
|
+
|
36
|
+
installation.status = to
|
37
|
+
installation.save!
|
38
|
+
end
|