Class: OsVm::VpsadminosMachine
- Defined in:
- lib/osvm/vpsadminos_machine.rb
Overview
vpsAdminOS-specific machine driver
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, #shell_server, #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_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) ⇒ 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, #console_log_path, #destroy, #destroy_disks, #disk_path, #execute, #fails, #finalize, #initialize, #inspect, #join, #kill, #mkdir, #mkdir_p, #prepare_disks, #pull_file, #push_file, #qemu_disk_options, #qemu_virtiofs_options, #read_nonblock, #read_shell_output, #run_console_thread, #run_qemu_reaper, #running?, #shell_socket_path, #shell_up?, #socket_path, #start, #start_virtiofs, #stop, #stop_virtiofs, #succeeds, #virtiofs_log_path, #virtiofs_socket_path, #wait_for_boot, #wait_for_console_text, #wait_for_service, #wait_for_shell, #wait_for_shutdown, #wait_until_fails, #wait_until_online, #wait_until_succeeds
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_command(kernel_params: []) ⇒ Object (protected)
96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 |
# File 'lib/osvm/vpsadminos_machine.rb', line 96 def qemu_command(kernel_params: []) all_kernel_params = base_kernel_params(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 + [ '-drive', "index=0,id=drive1,file=#{config.squashfs},readonly=on,media=cdrom,format=raw,if=virtio", '-chardev', "socket,id=shell,path=#{shell_socket_path}", '-device', 'virtio-serial', '-device', 'virtconsole,chardev=shell', '-kernel', config.kernel, '-initrd', config.initrd, '-append', all_kernel_params.join(' '), '-nographic' ] + + + config. end |
#service_check_command(name) ⇒ Object (protected)
92 93 94 |
# File 'lib/osvm/vpsadminos_machine.rb', line 92 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
55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 |
# File 'lib/osvm/vpsadminos_machine.rb', line 55 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) ⇒ 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 |
# File 'lib/osvm/vpsadminos_machine.rb', line 27 def wait_for_osctl_pool(name, timeout: @default_timeout) t1 = Time.now cur_timeout = timeout loop do status, output = wait_until_succeeds( "osctl pool show -H -o state #{name}", timeout: cur_timeout ) return self if output.strip == 'active' cur_timeout = timeout - (Time.now - t1) if cur_timeout <= 0 raise TimeoutError, "Timeout occurred while waiting for pool #{name.inspect} to become active" end 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
82 83 84 85 86 87 88 |
# File 'lib/osvm/vpsadminos_machine.rb', line 82 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 |