knife-xapi 0.3.4 → 0.3.5

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.
@@ -86,7 +86,7 @@ class Chef::Knife
86
86
 
87
87
  def locate_config_value(key)
88
88
  key = key.to_sym
89
- Chef::Config[:knife][key] || config[key]
89
+ config[key] || Chef::Config[:knife][key]
90
90
  end
91
91
 
92
92
  # get template by name_label
@@ -295,5 +295,18 @@ class Chef::Knife
295
295
  vbd_ref = get_task_ref(task)
296
296
  end
297
297
 
298
+ # try to get a guest ip and return it
299
+ def get_guest_ip(vm_ref)
300
+ guest_ip = "unknown"
301
+ vgm = xapi.VM.get_guest_metrics(vm_ref)
302
+ unless "OpaqueRef:NULL" == vgm
303
+ networks = xapi.VM_guest_metrics.get_networks(vgm)
304
+ if networks.has_key?("0/ip")
305
+ guest_ip = networks["0/ip"]
306
+ end
307
+ end
308
+ return guest_ip
309
+ end
310
+
298
311
  end
299
312
  end
@@ -165,7 +165,7 @@ class Chef
165
165
  tcp_socket && tcp_socket.close
166
166
  end
167
167
 
168
- def get_guest_ip(vm_ref)
168
+ def wait_for_guest_ip(vm_ref)
169
169
  begin
170
170
  timeout(480) do
171
171
  ui.msg "Waiting for guest ip address"
@@ -308,7 +308,7 @@ class Chef
308
308
  exit 0
309
309
  end
310
310
 
311
- guest_addr = get_guest_ip(vm_ref)
311
+ guest_addr = wait_for_guest_ip(vm_ref)
312
312
  if guest_addr.nil? or guest_addr.empty?
313
313
  ui.msg("ip seems wrong using host+domain name instead")
314
314
  guest_addr = "#{host_name}.#{domainname}"
@@ -27,15 +27,31 @@ class Chef
27
27
 
28
28
  banner "knife xapi guest list"
29
29
 
30
+ option :id,
31
+ :short => "-i",
32
+ :long => "--show-id",
33
+ :description => "Enable printing of UUID and OpaqueRefs for vm"
34
+
35
+
30
36
  def run
31
37
  vms = xapi.VM.get_all
32
- printf "%-25s %-12s %-46s %-36s \n", "Name Label", "State", "Ref", "UUID"
38
+ if locate_config_value(:id)
39
+ printf "%-25s %-12s %-16s %-46s %-36s \n", "Name Label", "State", "IP Address", "Ref", "UUID"
40
+ else
41
+ printf "%-25s %-12s %-16s\n", "Name Label", "State", "IP Address"
42
+ end
43
+
33
44
  vms.each do |vm|
34
45
  record = xapi.VM.get_record(vm)
46
+ ip_address = get_guest_ip(vm)
35
47
  # make sure you can't do bad things to these VM's
36
48
  next if record['is_a_template']
37
49
  next if record['name_label'] =~ /control domain/i
38
- printf "%-25s %-12s %46s %36s \n", record['name_label'], record['power_state'], vm, record['uuid']
50
+ if locate_config_value(:id)
51
+ printf "%-25s %-12s %-16s %46s %36s \n", record['name_label'], record['power_state'], ip_address, vm, record['uuid']
52
+ else
53
+ printf "%-25s %-12s %-16s\n", record['name_label'], record['power_state'], ip_address
54
+ end
39
55
  end
40
56
  end
41
57
 
@@ -1,3 +1,3 @@
1
1
  module KnifeXenserver
2
- VERSION = "0.3.4"
2
+ VERSION = "0.3.5"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: knife-xapi
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.4
4
+ version: 0.3.5
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors: