Class: OsVm::VpsadminosMachine

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

Overview

vpsAdminOS-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, #poweroff_command, #prepare_disks, #pull_file, #push_file, #qemu_boot_options, #qemu_disk_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

#osctl_json(cmd) ⇒ Hash

osctl command without osctl, output is returned as JSON

Parameters:

  • cmd (String)

Returns:

  • (Hash)


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)



178
179
180
181
182
183
184
185
# File 'lib/osvm/vpsadminos_machine.rb', line 178

def qemu_boot_media_options
  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)



162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
# File 'lib/osvm/vpsadminos_machine.rb', line 162

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

#service_check_command(name) ⇒ Object (protected)



158
159
160
# File 'lib/osvm/vpsadminos_machine.rb', line 158

def service_check_command(name)
  "sv check #{name}"
end

#wait_for_osctl_container(id, state: 'running', timeout: @default_timeout, poll_timeout: 60) ⇒ Machine

Wait for osctl container to exist and be in a given state

Parameters:

  • id (String)
  • state (String) (defaults to: 'running')
  • timeout (Numeric) (defaults to: @default_timeout)
  • poll_timeout (Numeric) (defaults to: 60)

Returns:



78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
# File 'lib/osvm/vpsadminos_machine.rb', line 78

def wait_for_osctl_container(id, state: 'running', timeout: @default_timeout, poll_timeout: 60)
  last_state = nil
  last_error = nil
  probe_timeout_message = "Timeout occurred while waiting for container #{id.inspect} to become #{state}"
  timeout_message = lambda do
    message = probe_timeout_message
    message += ", last state: #{last_state.inspect}" if last_state
    message += ", last error: #{last_error.message.inspect}" if last_error
    message
  end
  deadline = monotonic_deadline(timeout)
  probe_timeout = [poll_timeout, timeout / 2.0].min

  loop do
    status = nil
    remaining = remaining_time!(deadline, timeout_message.call)

    # Do not start a probe which can consume the caller's deadline. A
    # protocol timeout resets the shell and is not a state-wait timeout.
    sleep_with_deadline(remaining, deadline, timeout_message.call) if remaining <= probe_timeout

    begin
      status, output = execute(
        "osctl ct show -H -o state #{id}",
        timeout: probe_timeout,
        deadline:,
        timeout_message: probe_timeout_message
      )
      last_state = output.strip
      last_error = nil
    rescue TimeoutError => e
      last_error = e
      raise UnrecoverableTimeoutError, timeout_message.call if e.is_a?(UnrecoverableTimeoutError)
    end

    remaining_time!(deadline, timeout_message.call)
    return self if status == 0 && last_state == state

    sleep_with_deadline(1, deadline, timeout_message.call)
  end
end

#wait_for_osctl_pool(name, timeout: 20 * 60, poll_timeout: 60) ⇒ Machine

Wait for pool to be imported into osctld

Parameters:

  • name (String)
  • timeout (Integer) (defaults to: 20 * 60)

Returns:



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
65
66
67
68
69
70
# File 'lib/osvm/vpsadminos_machine.rb', line 27

def wait_for_osctl_pool(name, timeout: 20 * 60, poll_timeout: 60)
  last_state = nil
  last_error = nil
  probe_timeout_message = "Timeout occurred while waiting for pool #{name.inspect} to become active"
  timeout_message = lambda do
    message = probe_timeout_message
    message += ", last state: #{last_state.inspect}" if last_state
    message += ", last error: #{last_error.message.inspect}" if last_error
    message
  end
  deadline = monotonic_deadline(timeout)

  remaining_time!(deadline, timeout_message.call)
  start(deadline:, timeout_message: timeout_message.call) unless running?
  wait_for_boot(
    timeout: remaining_time!(deadline, timeout_message.call),
    deadline:,
    timeout_message: timeout_message.call
  )

  loop do
    status = nil
    cur_timeout = remaining_time!(deadline, timeout_message.call)

    begin
      status, output = execute(
        "osctl pool show -H -o state #{name}",
        timeout: [poll_timeout, cur_timeout].min,
        deadline:,
        timeout_message: probe_timeout_message
      )
      last_state = output.strip
      last_error = nil
    rescue TimeoutError => e
      last_error = e
      raise UnrecoverableTimeoutError, timeout_message.call if e.is_a?(UnrecoverableTimeoutError)
    end

    remaining_time!(deadline, timeout_message.call)
    return self if status == 0 && last_state == 'active'

    sleep_with_deadline(1, deadline, timeout_message.call)
  end
end

#wait_for_zpool(name, timeout: @default_timeout) ⇒ Machine

Wait for zpool

Parameters:

  • name (String)
  • timeout (Integer) (defaults to: @default_timeout)

Returns:



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, poll_timeout: 60) ⇒ Machine

Wait until container's network is operational, including DNS

Parameters:

  • ctid (String)
  • poll_timeout (Numeric) (defaults to: 60)

Returns:



124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
# File 'lib/osvm/vpsadminos_machine.rb', line 124

def wait_until_container_online(ctid, timeout: @default_timeout, poll_timeout: 60)
  command =
    "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_message = "Timeout occurred while waiting for container #{ctid.inspect} to come online"
  deadline = monotonic_deadline(timeout)
  probe_timeout = [poll_timeout, timeout / 2.0].min

  loop do
    remaining = remaining_time!(deadline, timeout_message)

    # A protocol timeout resets the non-reconnectable guest shell, so leave
    # enough time for each complete probe or expire without starting it.
    sleep_with_deadline(remaining, deadline, timeout_message) if remaining <= probe_timeout

    begin
      status, = execute(
        command,
        timeout: probe_timeout,
        deadline:,
        timeout_message:
      )
    rescue TimeoutError => e
      raise UnrecoverableTimeoutError, timeout_message if e.is_a?(UnrecoverableTimeoutError)
    end

    remaining_time!(deadline, timeout_message)
    return self if status == 0

    sleep_with_deadline(1, deadline, timeout_message)
  end
end