Class: OsVm::NixosMachine

Inherits:
Machine
  • Object
show all
Defined in:
lib/osvm/nixos_machine.rb

Overview

NixOS-specific machine driver

Constant Summary

Constants inherited from Machine

Machine::BOOT_INPUT_PATH, Machine::BOOT_OBSERVATION_TIMEOUT, Machine::KERNEL_FAILURE_PATTERN, Machine::SHELL_INDEX_KEY, Machine::SOCKET_HASH_IDENTITIES, Machine::SOCKET_HASH_LENGTH, Machine::SOCKET_HASH_MUTEX

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

Methods inherited from Machine

#all_fail, #all_succeed, #allow_kernel_failure, #append_console_output, #base_kernel_params, #boot_host_snapshot, #boot_input_path, #boot_option, #boot_positive_integer, #boot_process_stat, #booted?, #can_execute?, #checked_boot_process_stat, #cleanup, #cleanup_runtime_resources, #command_shell, #console_log_path, #console_output, #current_shell, #current_shell_index, #custom_qemu_numa_memory_backend?, #destroy, #destroy_disks, #disk_path, #execute, #expanded_extra_qemu_options, #fails, #fails_with_retries, #finalize, #initialize, #inspect, #join, #kernel_failed?, #kill, #kill_after_kernel_failure, #mark_runtime_stopped, #mkdir, #mkdir_p, #monotonic_deadline, #monotonic_now, #mount_shared_dir_once, #prepare_disks, #pull_file, #push_file, #qemu_boot_media_options, #qemu_boot_options, #qemu_shell_options, #qemu_virtiofs_options, #raise_if_kernel_failed!, #read_nonblock, #record_boot_launch, #record_boot_wait_failure, #remaining_time!, #reset_kernel_failure, #rollback_start, #run_console_thread, #run_qemu_reaper, #running?, #shell_chardev_id, #shell_for, #shell_log_path, #shell_socket_path, #shells, #sleep_with_deadline, #socket_hash, #socket_identity_digest, #socket_path, #spawned_boot_process_identity, #start, #start_virtiofs, #stop, #stop_virtiofs, #succeeds, #succeeds_with_retries, #terminate_unreaped_child, #validate_shell_index, #virtiofs_log_path, #virtiofs_socket_path, #wait_for_boot, #wait_for_console_text, #wait_for_reaper, #wait_for_service, #wait_for_shutdown, #wait_until_fails, #wait_until_online, #wait_until_succeeds, #with_boot_process, #with_deadline, with_shell

Constructor Details

This class inherits a constructor from OsVm::Machine

Instance Method Details

#poweroff_command ⇒ Object (protected)



10
11
12
# File 'lib/osvm/nixos_machine.rb', line 10

def poweroff_command
  'poweroff'
end

#qemu_command(kernel_params: []) ⇒ Object (protected)



14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/osvm/nixos_machine.rb', line 14

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 + qemu_boot_media_options + qemu_shell_options + [
    '-nographic',
    '-vga', 'none'
  ] + qemu_boot_options(kernel_params) + qemu_disk_options + qemu_virtiofs_options + expanded_extra_qemu_options
end

#qemu_disk_options ⇒ Object (protected)



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/osvm/nixos_machine.rb', line 29

def qemu_disk_options
  ret = []

  if config.root_disk
    ret << '-drive' << "id=diskroot,file=#{root_disk_path},if=none,format=raw"
    ret << '-device' << 'ide-hd,drive=diskroot,bus=ahci.0'
  end

  config.disks.each_with_index do |disk, i|
    idx = config.root_disk ? i + 1 : i
    ret << '-drive' << "id=disk#{idx},file=#{disk_path(disk.device)},if=none,format=raw"
    ret << '-device' << "ide-hd,drive=disk#{idx},bus=ahci.#{idx}"
  end

  ret
end

#root_disk_path ⇒ Object (protected)



46
47
48
# File 'lib/osvm/nixos_machine.rb', line 46

def root_disk_path
  disk_path(config.root_disk.device)
end

#service_check_command(name) ⇒ Object (protected)



6
7
8
# File 'lib/osvm/nixos_machine.rb', line 6

def service_check_command(name)
  "systemctl is-active --quiet #{name}"
end