vagrant-vminfo 0.0.1 → 0.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 5c194b9b479d86cccae9feefe259f49c159c90e8
4
- data.tar.gz: a1b02c6989c7e0be5e7fb251367978f5bfe1badb
3
+ metadata.gz: 3960cb4c45ffc61d4ef3c245fe2e542194b1918a
4
+ data.tar.gz: 1c2a06995dcd130043204caef0e7f8c8dc73e9ab
5
5
  SHA512:
6
- metadata.gz: 251f6d132de0aa47d507b3b1caa6a8cd5a23f0538e15537952ae4c7f28b28fbe859b927dac62a84e3b6e7aff3b0b4841b22bf3ac4d7235aca26021baa38ad857
7
- data.tar.gz: 10206ab67fced12985a97a2d2fb423eafe920194ab90e3fa3f90deff4e0505da9aab89ffa818b68f2e7efb1515f6a43071985ef4f707d2220691ff94d4fc3682
6
+ metadata.gz: 8d47741cb4586a6a7a484dce17ac421db1c1da5894cc5e322ab843b5c7ad6eb87003eb822ce7b542018ec5b3fdd097b71981ebc93aaac1122de1ce5756344127
7
+ data.tar.gz: 3ea642275c86306cc72809e444736f54aa043eae6f4e7b067049bf581cc7b473e3a312e2ec406b01deb10f2aa47a94972039b77661fa1afeecac046fac3828d8
@@ -28,6 +28,100 @@ module VagrantVminfo
28
28
  class InfoCommand < Vagrant.plugin(2, :command)
29
29
  include VagrantPlugins::CommandUp::StartMixins
30
30
 
31
+ def get_vm_info(vm)
32
+ # Get some provider specific details for vm
33
+ provider = vm.provider_name.id2name
34
+ if provider == 'virtualbox'
35
+ return get_vm_info_virtualbox(vm)
36
+ elsif provider == 'vmware_workstation'
37
+ return get_vm_info_vmware_workstation(vm)
38
+ end
39
+ end
40
+
41
+ def get_vm_info_virtualbox(vm)
42
+ # Get VM info by virtualbox provider
43
+ # All we need is network interfaces details
44
+
45
+ networks = []
46
+ begin
47
+ nic_count = vm.provider.driver.execute("guestproperty", "get", vm.id, "/VirtualBox/GuestInfo/Net/Count")[/Value: (\d)/, 1]
48
+ rescue Exception => e
49
+ @logger.warn(e.message)
50
+ nic_count = 0
51
+ else
52
+ nic_count = Integer(nic_count)
53
+ end
54
+ # Check nic_count is not defined in case of VBox Guest Additions not install, or some other issue
55
+ if nic_count > 0
56
+ (0..(nic_count-1)).each do |i|
57
+ nic_ip = vm.provider.driver.execute("guestproperty", "get", vm.id, "/VirtualBox/GuestInfo/Net/#{i}/V4/IP")[/Value: (.*)/, 1]
58
+ nic_mac = vm.provider.driver.execute("guestproperty", "get", vm.id, "/VirtualBox/GuestInfo/Net/#{i}/MAC")[/Value: (.*)/, 1]
59
+ nic_broadcast = vm.provider.driver.execute("guestproperty", "get", vm.id, "/VirtualBox/GuestInfo/Net/#{i}/V4/Broadcast")[/Value: (.*)/, 1]
60
+ nic_netmask = vm.provider.driver.execute("guestproperty", "get", vm.id, "/VirtualBox/GuestInfo/Net/#{i}/V4/Netmask")[/Value: (.*)/, 1]
61
+ # Get the number of this network device based on the mac address
62
+ # TODO: probably just should just get a hash of all of this info somehow, my ruby foo is weak
63
+ nic_number = vm.provider.driver.execute("showvminfo", vm.id, "--machinereadable")[/\w*(\d)=\"#{nic_mac}\"/, 1]
64
+ nic_type = vm.provider.driver.execute("showvminfo", vm.id, "--machinereadable")[/nic#{nic_number}=\"(.*)\"/, 1]
65
+ networks << {'ip' => nic_ip,
66
+ 'mac' => nic_mac,
67
+ 'netmask' => nic_netmask,
68
+ 'broadcast' => nic_broadcast,
69
+ 'type' => nic_type}
70
+ end
71
+ end
72
+ return {"networks" => networks}
73
+ end
74
+
75
+ def get_vm_info_vmware_workstation(vm)
76
+ # Get VM info by virtualbox provider
77
+ # We can get some network interfaces details and current IP address
78
+
79
+ # Collect details for all the network interfaces
80
+ nics = {}
81
+ vm.provider.driver.send(:read_vmx_data).each do |key, val|
82
+ key1, key2 = key.split('.')
83
+ m = /^ethernet\d+$/.match(key1)
84
+ if m
85
+ if !nics.include?(m[0])
86
+ nics[m[0]] = {}
87
+ end
88
+ nics[m[0]][key2] = val
89
+ end
90
+ end
91
+
92
+ # Check and normalize collected network information
93
+ networks = []
94
+ nics.values.each do |nic|
95
+ nic_type = nic['connectiontype']
96
+ nic_addresstype = nic['addresstype']
97
+ nic_mac = nic_addresstype == 'generated' ? nic['generatedaddress'] : nic['address']
98
+ #TODO: For now I don't know simple way to retrieve these details
99
+ #nic_ip = nil
100
+ #nic_netmask = nil
101
+ #nic_broadcast = nil
102
+
103
+ networks << {#'ip' => nic_ip,
104
+ 'mac' => nic_mac,
105
+ #'netmask' => nic_netmask,
106
+ #'broadcast' => nic_broadcast,
107
+ 'type' => nic_type}
108
+ end
109
+
110
+ # We can try to get IP address for VM but can not assign it to any network interface
111
+ ip = nil
112
+ begin
113
+ resp = vm.provider.driver.send(:vmrun, *['getGuestIPAddress', vm.id])
114
+ rescue Exception => e
115
+ @logger.warn(e.message)
116
+ else
117
+ m = /(?<ip>\d{1,3}\.\d{1,3}.\d{1,3}\.\d{1,3})/.match(resp.stdout)
118
+ ip = (resp.exit_code == 0 and m) ? m['ip'] : nil
119
+ end
120
+
121
+ return {'ip' => ip,
122
+ 'networks' => networks }
123
+ end
124
+
31
125
  def execute
32
126
  # Not sure if this is the only way to do this? How else would I get argv?
33
127
  argv = parse_options(OptionParser.new)
@@ -36,35 +130,14 @@ module VagrantVminfo
36
130
 
37
131
  with_target_vms(argv) do |vm|
38
132
  info["name"] = vm.name.id2name
39
- info["id"] = vm.id
40
- info["provider"] = vm.provider_name.id2name
41
- info["networks"] = []
42
-
43
- @nic_count = Integer(vm.provider.driver.execute("guestproperty", "get", vm.id, "/VirtualBox/GuestInfo/Net/Count")[/Value: (\d)/, 1])
44
- (0..(@nic_count-1)).each do |i|
45
- nic = {}
46
-
47
- @nic_ip = vm.provider.driver.execute("guestproperty", "get", vm.id, "/VirtualBox/GuestInfo/Net/#{i}/V4/IP")[/Value: (.*)/, 1]
48
- @nic_mac = vm.provider.driver.execute("guestproperty", "get", vm.id, "/VirtualBox/GuestInfo/Net/#{i}/MAC")[/Value: (.*)/, 1]
49
- @nic_broadcast = vm.provider.driver.execute("guestproperty", "get", vm.id, "/VirtualBox/GuestInfo/Net/#{i}/V4/Broadcast")[/Value: (.*)/, 1]
50
- @nic_netmask = vm.provider.driver.execute("guestproperty", "get", vm.id, "/VirtualBox/GuestInfo/Net/#{i}/V4/Netmask")[/Value: (.*)/, 1]
51
-
52
- # Get the number of this network device based on the mac address
53
- # TODO: probably just should just get a hash of all of this info somehow, my ruby foo is weak
54
- @nic_number = vm.provider.driver.execute("showvminfo", vm.id, "--machinereadable")[/\w*(\d)=\"#{@nic_mac}\"/, 1]
55
- @nic_type = vm.provider.driver.execute("showvminfo", vm.id, "--machinereadable")[/nic#{@nic_number}=\"(.*)\"/, 1]
56
-
57
- nic['ip'] = @nic_ip
58
- nic['mac'] = @nic_mac
59
- nic['netmask'] = @nic_netmask
60
- nic['broadcast'] = @nic_broadcast
61
- nic['type'] = @nic_type
62
-
63
- # Append to the networks array
64
- info["networks"] << nic
133
+ info["status"] = vm.state.id.id2name
134
+ # Check if vm is running - try to get some provider specific details
135
+ if vm.state.id == :running
136
+ info["id"] = vm.id
137
+ info["provider"] = vm.provider_name.id2name
138
+ info.merge!(get_vm_info(vm))
65
139
  end
66
140
  end
67
-
68
141
  puts info.to_yaml
69
142
  end
70
143
  end
@@ -1,3 +1,3 @@
1
1
  module VagrantVminfo
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: vagrant-vminfo
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Lin Salisbury
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-09-12 00:00:00.000000000 Z
11
+ date: 2014-01-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake
@@ -73,14 +73,14 @@ executables: []
73
73
  extensions: []
74
74
  extra_rdoc_files: []
75
75
  files:
76
+ - Rakefile
76
77
  - Gemfile
78
+ - vagrant-vminfo.gemspec
77
79
  - LICENSE
78
- - README.md
79
- - Rakefile
80
- - lib/vagrant-vminfo/plugin.rb
81
80
  - lib/vagrant-vminfo/version.rb
81
+ - lib/vagrant-vminfo/plugin.rb
82
82
  - lib/vagrant-vminfo.rb
83
- - vagrant-vminfo.gemspec
83
+ - README.md
84
84
  - .gitignore
85
85
  homepage: https://github.com/d3vz3r0/vagrant-vminfo
86
86
  licenses: []
@@ -101,7 +101,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
101
101
  version: '0'
102
102
  requirements: []
103
103
  rubyforge_project:
104
- rubygems_version: 2.0.3
104
+ rubygems_version: 2.0.14
105
105
  signing_key:
106
106
  specification_version: 4
107
107
  summary: Gets detailed information about the VM, including network interfaes