Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Aug 19th, 2012  |  syntax: None  |  size: 0.71 KB  |  hits: 11  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. require 'fog'
  2. require 'pp'
  3.  
  4. conn = Fog::Compute.new({
  5.   :provider => 'XenServer',
  6.   :xenserver_url => 'xenserver-test',
  7.   :xenserver_username => 'root',
  8.   :xenserver_password => 'changeme',
  9. })
  10.  
  11. # Get the default network
  12. default = conn.default_network
  13.  
  14. # Get VIFs associated to this network
  15. default.vifs
  16.  
  17. # Get PIFs associated to this network
  18. default.pifs
  19.  
  20. # Iterate over all the available networks
  21. conn.networks.each do |n|
  22. end
  23.  
  24. # Find servers in default network
  25. set = conn.servers.find_all do |s|
  26.   associated = false
  27.   s.networks.each do |n|
  28.     if n.name == default.name
  29.       associated = true
  30.       break
  31.     end
  32.   end
  33.   associated
  34. end
  35. set.each { |s| puts "server #{s.name} is in default network '#{default.name}'" }