Class: OsVm::VpsadminosMachine
- Defined in:
- lib/osvm/vpsadminos_machine.rb
Overview
vpsAdminOS-specific machine driver
Constant Summary
Constants inherited from Machine
Instance Attribute Summary
Attributes inherited from Machine
#config, #console_thread, #hash_base, #log, #name, #qemu_pid, #qemu_read, #qemu_reaper, #shared_dir, #shared_filesystems, #shell_instances, #sockdir, #start_kernel_params, #tmpdir, #virtiofsd_pids
Instance Method Summary collapse
-
#osctl_json(cmd) ⇒ Hash
osctl command without
osctl, output is returned as JSON. - #qemu_boot_media_options ⇒ Object protected
- #qemu_command(kernel_params: []) ⇒ Object protected
- #service_check_command(name) ⇒ Object protected
-
#wait_for_osctl_container(id, state: 'running', timeout: @default_timeout) ⇒ Machine
Wait for osctl container to exist and be in a given state.
-
#wait_for_osctl_pool(name, timeout: @default_timeout, poll_timeout: 10) ⇒ Machine
Wait for pool to be imported into osctld.
-
#wait_for_zpool(name, timeout: @default_timeout) ⇒ Machine
Wait for zpool.
-
#wait_until_container_online(ctid, timeout: @default_timeout) ⇒ Machine
Wait until container's network is operational, including DNS.
Methods inherited from Machine
#all_fail, #all_succeed, #base_kernel_params, #booted?, #can_execute?, #cleanup, #command_shell, #console_log_path, #console_output, #current_shell, #current_shell_index, #custom_qemu_numa_memory_backend?, #destroy, #destroy_disks, #disk_path, #execute, #fails, #finalize, #initialize, #inspect, #join, #kill, #mkdir, #mkdir_p, #mount_shared_dir_once, #poweroff_command, #prepare_disks, #pull_file, #push_file, #qemu_boot_options, #qemu_disk_options, #qemu_shell_options, #qemu_virtiofs_options, #read_nonblock, #run_console_thread, #run_qemu_reaper, #running?, #shell_chardev_id, #shell_for, #shell_log_path, #shell_socket_path, #shells, #socket_path, #start, #start_virtiofs, #stop, #stop_virtiofs, #succeeds, #validate_shell_index, #virtiofs_log_path, #virtiofs_socket_path, #wait_for_boot, #wait_for_console_text, #wait_for_service, #wait_for_shutdown, #wait_until_fails, #wait_until_online, #wait_until_succeeds, with_shell
Constructor Details
This class inherits a constructor from OsVm::Machine
Instance Method Details
#osctl_json(cmd) ⇒ Hash
osctl command without osctl, output is returned as JSON
9 10 11 12 |
# File 'lib/osvm/vpsadminos_machine.rb', line 9 def osctl_json(cmd) status, output = succeeds("osctl -j #{cmd}") JSON.parse(output) end |
#qemu_boot_media_options ⇒ Object (protected)
126 127 128 129 130 131 132 133 |
# File 'lib/osvm/vpsadminos_machine.rb', line 126 def ret = super return ret if config.squashfs.nil? ret + [ '-drive', "index=0,id=drive1,file=#{config.squashfs},readonly=on,media=cdrom,format=raw,if=virtio" ] end |
#qemu_command(kernel_params: []) ⇒ Object (protected)
111 112 113 114 115 116 117 118 119 120 121 122 123 124 |
# File 'lib/osvm/vpsadminos_machine.rb', line 111 def qemu_command(kernel_params: []) [ "#{config.qemu}/bin/qemu-kvm", '-name', "os-vm-#{name}", '-m', config.memory.to_s, '-cpu', 'host', '-smp', "cpus=#{config.cpus},cores=#{config.cpu.cores},threads=#{config.cpu.threads},sockets=#{config.cpu.sockets}", '--no-reboot', '-device', 'ahci,id=ahci' ] + config.networks.map(&:qemu_options).flatten + \ + + [ '-nographic' ] + (kernel_params) + + + config. end |
#service_check_command(name) ⇒ Object (protected)
107 108 109 |
# File 'lib/osvm/vpsadminos_machine.rb', line 107 def service_check_command(name) "sv check #{name}" end |
#wait_for_osctl_container(id, state: 'running', timeout: @default_timeout) ⇒ Machine
Wait for osctl container to exist and be in a given state
70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 |
# File 'lib/osvm/vpsadminos_machine.rb', line 70 def wait_for_osctl_container(id, state: 'running', timeout: @default_timeout) t1 = Time.now cur_timeout = timeout loop do status, output = wait_until_succeeds( "osctl ct show -H -o state #{id}", timeout: cur_timeout ) return self if output.strip == state cur_timeout = timeout - (Time.now - t1) if cur_timeout <= 0 raise TimeoutError, "Timeout occurred while waiting for container #{id.inspect} to become #{state}" end sleep(1) end self end |
#wait_for_osctl_pool(name, timeout: @default_timeout, poll_timeout: 10) ⇒ Machine
Wait for pool to be imported into osctld
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/osvm/vpsadminos_machine.rb', line 27 def wait_for_osctl_pool(name, timeout: @default_timeout, poll_timeout: 10) t1 = Time.now cur_timeout = timeout last_state = nil last_error = nil loop do status = nil if cur_timeout <= 0 = "Timeout occurred while waiting for pool #{name.inspect} to become active" += ", last state: #{last_state.inspect}" if last_state += ", last error: #{last_error..inspect}" if last_error raise TimeoutError, end begin status, output = execute( "osctl pool show -H -o state #{name}", timeout: [poll_timeout, cur_timeout].min ) last_state = output.strip last_error = nil rescue TimeoutError => e raise if e.is_a?(UnrecoverableTimeoutError) last_error = e end return self if status == 0 && last_state == 'active' cur_timeout = timeout - (Time.now - t1) sleep(1) end self end |
#wait_for_zpool(name, timeout: @default_timeout) ⇒ Machine
Wait for zpool
18 19 20 21 |
# File 'lib/osvm/vpsadminos_machine.rb', line 18 def wait_for_zpool(name, timeout: @default_timeout) wait_until_succeeds("zpool list #{name}", timeout:) self end |
#wait_until_container_online(ctid, timeout: @default_timeout) ⇒ Machine
Wait until container's network is operational, including DNS
97 98 99 100 101 102 103 |
# File 'lib/osvm/vpsadminos_machine.rb', line 97 def wait_until_container_online(ctid, timeout: @default_timeout) wait_until_succeeds( "osctl ct exec #{ctid} sh -c 'ping -c 1 check-online.vpsadminos.org || curl --head https://check-online.vpsadminos.org || wget -O - https://check-online.vpsadminos.org || getent hosts check-online.vpsadminos.org'", timeout: ) self end |