Class: VagrantPlugins::VMM::Driver
- Inherits:
-
Object
- Object
- VagrantPlugins::VMM::Driver
- Defined in:
- lib/vagrant-vmm/driver.rb
Constant Summary collapse
- ERROR_REGEXP =
/===Begin-Error===(.+?)===End-Error===/m
- OUTPUT_REGEXP =
/===Begin-Output===(.+?)===End-Output===/m
Instance Attribute Summary collapse
-
#machine ⇒ Object
readonly
Returns the value of attribute machine.
-
#vm_id ⇒ Object
readonly
Returns the value of attribute vm_id.
Instance Method Summary collapse
- #delete_vm(options) ⇒ Object
- #execute(path, options, print_output = false) ⇒ Object
- #get_current_state(options) ⇒ Object
- #import(options) ⇒ Object
-
#initialize(machine) ⇒ Driver
constructor
A new instance of Driver.
- #read_guest_ip(options) ⇒ Object
- #resume(options) ⇒ Object
- #start(options) ⇒ Object
- #stop(options) ⇒ Object
- #suspend(options) ⇒ Object
- #sync_folders(options) ⇒ Object
Constructor Details
#initialize(machine) ⇒ Driver
Returns a new instance of Driver.
16 17 18 19 20 |
# File 'lib/vagrant-vmm/driver.rb', line 16 def initialize(machine) @machine = machine @vm_id = machine.id @logger = Log4r::Logger.new("vagrant::provider::vmm") end |
Instance Attribute Details
#machine ⇒ Object (readonly)
Returns the value of attribute machine.
14 15 16 |
# File 'lib/vagrant-vmm/driver.rb', line 14 def machine @machine end |
#vm_id ⇒ Object (readonly)
Returns the value of attribute vm_id.
13 14 15 |
# File 'lib/vagrant-vmm/driver.rb', line 13 def vm_id @vm_id end |
Instance Method Details
#delete_vm(options) ⇒ Object
67 68 69 70 |
# File 'lib/vagrant-vmm/driver.rb', line 67 def delete_vm() ['vm_id'] = vm_id execute('delete_vm.ps1', ) end |
#execute(path, options, print_output = false) ⇒ Object
22 23 24 25 26 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 |
# File 'lib/vagrant-vmm/driver.rb', line 22 def execute(path, , print_output = false) r = execute_powershell(path, ) { |io_name, data| if print_output && ( io_name == :stderr || io_name == :stdout ) if !OUTPUT_REGEXP.match(data) && !ERROR_REGEXP.match(data) if io_name == :stdout machine.ui.output(data) end if io_name == :stderr machine.ui.error(data) end end end } if r.exit_code != 0 raise Errors::PowerShellError, script: path, stderr: r.stderr end # We only want unix-style line endings within Vagrant r.stdout.gsub!("\r\n", "\n") r.stderr.gsub!("\r\n", "\n") error_match = ERROR_REGEXP.match(r.stdout) output_match = OUTPUT_REGEXP.match(r.stdout) if error_match data = JSON.parse(error_match[1]) # We have some error data. raise Errors::PowerShellError, script: path, stderr: data["error"] end # Nothing return nil if !output_match return JSON.parse(output_match[1]) end |
#get_current_state(options) ⇒ Object
62 63 64 65 |
# File 'lib/vagrant-vmm/driver.rb', line 62 def get_current_state() ['vm_id'] = vm_id execute('get_vm_status.ps1', ) end |
#import(options) ⇒ Object
97 98 99 |
# File 'lib/vagrant-vmm/driver.rb', line 97 def import() execute('import_vm.ps1', ) end |
#read_guest_ip(options) ⇒ Object
72 73 74 75 |
# File 'lib/vagrant-vmm/driver.rb', line 72 def read_guest_ip() ['vm_id'] = vm_id execute('get_network_config.ps1', , true) end |
#resume(options) ⇒ Object
77 78 79 80 |
# File 'lib/vagrant-vmm/driver.rb', line 77 def resume() ['vm_id'] = vm_id execute('resume_vm.ps1', ) end |
#start(options) ⇒ Object
82 83 84 85 |
# File 'lib/vagrant-vmm/driver.rb', line 82 def start() ['vm_id'] = vm_id execute('start_vm.ps1', ) end |
#stop(options) ⇒ Object
87 88 89 90 |
# File 'lib/vagrant-vmm/driver.rb', line 87 def stop() ['vm_id'] = vm_id execute('stop_vm.ps1', ) end |
#suspend(options) ⇒ Object
92 93 94 95 |
# File 'lib/vagrant-vmm/driver.rb', line 92 def suspend() ['vm_id'] = vm_id execute("suspend_vm.ps1", ) end |
#sync_folders(options) ⇒ Object
101 102 103 |
# File 'lib/vagrant-vmm/driver.rb', line 101 def sync_folders() execute('sync_folders.ps1', , true) end |