Class: VagrantPlugins::AVF::Driver
- Inherits:
-
Object
- Object
- VagrantPlugins::AVF::Driver
- Defined in:
- lib/vagrant_provider_avf/driver.rb
Constant Summary collapse
- START_TIMEOUT_SECONDS =
10- STOP_TIMEOUT_SECONDS =
10- POLL_INTERVAL_SECONDS =
0.1- SSH_INFO_MARKER =
"__AVF_SSH_INFO__ ".freeze
Instance Method Summary collapse
- #create(machine_requirements, boot_config, machine_id: nil) ⇒ Object
- #destroy(machine_id) ⇒ Object
- #fetch(machine_id) ⇒ Object
-
#initialize(machine_metadata_store:, machine_data_dir:, machine_id_generator: -> { SecureRandom.uuid }, process_control: ProcessControl.new, helper_installer: nil, linux_cloud_init_seed: LinuxCloudInitSeed.new(machine_data_dir: machine_data_dir), dhcp_leases: DhcpLeases.new, port_allocator: PortAllocator.new, ssh_forwarder: nil) ⇒ Driver
constructor
A new instance of Driver.
- #read_ssh_info(machine_id) ⇒ Object
- #read_state(machine_id) ⇒ Object
- #start(machine_id, machine_requirements:, boot_config:, shared_directories: []) ⇒ Object
- #stop(machine_id) ⇒ Object
Constructor Details
#initialize(machine_metadata_store:, machine_data_dir:, machine_id_generator: -> { SecureRandom.uuid }, process_control: ProcessControl.new, helper_installer: nil, linux_cloud_init_seed: LinuxCloudInitSeed.new(machine_data_dir: machine_data_dir), dhcp_leases: DhcpLeases.new, port_allocator: PortAllocator.new, ssh_forwarder: nil) ⇒ Driver
Returns a new instance of Driver.
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/vagrant_provider_avf/driver.rb', line 15 def initialize( machine_metadata_store:, machine_data_dir:, machine_id_generator: -> { SecureRandom.uuid }, process_control: ProcessControl.new, helper_installer: nil, linux_cloud_init_seed: LinuxCloudInitSeed.new(machine_data_dir: machine_data_dir), dhcp_leases: DhcpLeases.new, port_allocator: PortAllocator.new, ssh_forwarder: nil ) @machine_metadata_store = @paths = DriverPaths.new(machine_data_dir) @machine_id_generator = machine_id_generator @process_control = process_control @helper_installer = helper_installer || HelperInstaller.new(paths: @paths) @linux_cloud_init_seed = linux_cloud_init_seed @dhcp_leases = dhcp_leases @port_allocator = port_allocator @ssh_forwarder = ssh_forwarder || SshForwarder.new( machine_data_dir: machine_data_dir, process_control: process_control ) end |
Instance Method Details
#create(machine_requirements, boot_config, machine_id: nil) ⇒ Object
72 73 74 75 76 77 78 79 80 81 82 |
# File 'lib/vagrant_provider_avf/driver.rb', line 72 def create(machine_requirements, boot_config, machine_id: nil) = Model::MachineMetadata.stopped( machine_id || "avf-#{@machine_id_generator.call}", machine_requirements: machine_requirements, boot_config: boot_config, ssh_port: @port_allocator.allocate ) @machine_metadata_store.save() end |
#destroy(machine_id) ⇒ Object
123 124 125 126 127 128 129 130 131 132 |
# File 'lib/vagrant_provider_avf/driver.rb', line 123 def destroy(machine_id) stop(machine_id) unless blank?(machine_id) @machine_metadata_store.clear cleanup_runtime_files nil rescue Errors::MachineStopFailed raise rescue StandardError => error raise Errors::MachineDestroyFailed, error. end |
#fetch(machine_id) ⇒ Object
40 41 42 43 44 |
# File 'lib/vagrant_provider_avf/driver.rb', line 40 def fetch(machine_id) return if blank?(machine_id) @machine_metadata_store.fetch(machine_id: machine_id) end |
#read_ssh_info(machine_id) ⇒ Object
56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/vagrant_provider_avf/driver.rb', line 56 def read_ssh_info(machine_id) = fetch(machine_id) return unless && .running? unless alive?(.process_id) restore_stopped_machine() return end return .ssh_info if ssh_info_available?() guest_ssh_info = discover_guest_ssh_info() return unless guest_ssh_info persist_ssh_info(, guest_ssh_info) end |
#read_state(machine_id) ⇒ Object
46 47 48 49 50 51 52 53 54 |
# File 'lib/vagrant_provider_avf/driver.rb', line 46 def read_state(machine_id) = fetch(machine_id) return unless return .state unless .running? return :running if alive?(.process_id) restore_stopped_machine().state end |
#start(machine_id, machine_requirements:, boot_config:, shared_directories: []) ⇒ Object
84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 |
# File 'lib/vagrant_provider_avf/driver.rb', line 84 def start(machine_id, machine_requirements:, boot_config:, shared_directories: []) validate_machine_requirements!(machine_requirements) ensure_boot_artifacts!(boot_config) helper_path = install_helper runtime_disk_path = prepare_disk_image(boot_config.disk_image_path, machine_requirements.disk_gb) seed_image_path = prepare_guest_runtime(machine_id, boot_config) clean_start_files write_start_request( start_request( machine_id, machine_requirements, boot_config, runtime_disk_path, shared_directories: shared_directories, seed_image_path: seed_image_path, efi_variable_store_path: @paths.efi_variable_store_path_for(boot_config) ) ) process_id = spawn_helper(helper_path) started = wait_for_start(process_id) save_running_machine(machine_id, started, machine_requirements, boot_config) end |
#stop(machine_id) ⇒ Object
108 109 110 111 112 113 114 115 116 117 118 119 120 121 |
# File 'lib/vagrant_provider_avf/driver.rb', line 108 def stop(machine_id) return if blank?(machine_id) = fetch(machine_id) return if .nil? return unless .running? stop_ssh_forwarder() @process_control.stop(.process_id, timeout: STOP_TIMEOUT_SECONDS) if .process_id save_stopped_machine() rescue StandardError => error raise Errors::MachineStopFailed, error. end |