Guest User

Untitled

a guest
Sep 21st, 2018
117
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.52 KB | None | 0 0
  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. :xenserver_defaults => {
  10. :template => "squeeze-test"
  11. }
  12. })
  13.  
  14. # Create a VM using the default template
  15. #vm = conn.servers.create :name => 'foobar'
  16. #
  17.  
  18. #
  19. # Create a VM using a specific template
  20. #
  21. vm = conn.servers.create :name => 'foobarXX',
  22. :template_name => 'squeeze-test'
  23. #
  24. # Create a VM with 2 nics
  25. #
  26. vm2 = conn.servers.create :name => 'foobar2NIC',
  27. :template_name => 'squeeze-test',
  28. :networks => [conn.default_network, conn.default_network, conn.default_network]
  29.  
  30. #
  31. # Force shutdown
  32. vm.hard_shutdown
  33. vm2.hard_shutdown
  34.  
  35. #
  36. # Destroy VM and associated VDIs
  37. # Force shutdown the VM too
  38. vm.destroy
  39. vm2.destroy
  40.  
  41. # Create the server from template squeeze-test
  42. # plus two additional NICs in network 'Integration-VLAN'
  43. net = conn.networks.find { |n| n.name == "Integration-VLAN" }
  44. s = conn.servers.create :name => 'my-foo-server',
  45. :template_name => 'squeeze-test',
  46. :networks => [net, net]
  47.  
  48. # Advanced VIF creation mode
  49. # with custom MAC and device number
  50. config = {
  51. 'MAC_autogenerated' => 'False',
  52. 'VM' => s.reference,
  53. 'network' => net.reference,
  54. 'MAC' => '11:22:33:44:55:66',
  55. 'device' => '4',
  56. 'MTU' => '0',
  57. 'other_config' => {},
  58. 'qos_algorithm_type' => 'ratelimit',
  59. 'qos_algorithm_params' => {}
  60. }
  61. conn.create_vif_custom config
Add Comment
Please, Sign In to add comment