vagrant-xenserver 0.0.11 → 0.0.12

Sign up to get free protection for your applications and to get access to all the features.
Files changed (33) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +103 -25
  3. data/example_box/install_wheezy.sh +128 -0
  4. data/example_box/mkbox.sh +17 -0
  5. data/lib/vagrant-xenserver/action.rb +14 -4
  6. data/lib/vagrant-xenserver/action/clone_disk.rb +1 -1
  7. data/lib/vagrant-xenserver/action/clone_vm.rb +35 -0
  8. data/lib/vagrant-xenserver/action/connect_xs.rb +19 -11
  9. data/lib/vagrant-xenserver/action/create_template.rb +86 -0
  10. data/lib/vagrant-xenserver/action/create_vifs.rb +44 -23
  11. data/lib/vagrant-xenserver/action/create_vm.rb +14 -10
  12. data/lib/vagrant-xenserver/action/destroy_vm.rb +9 -6
  13. data/lib/vagrant-xenserver/action/download_xva.rb +96 -0
  14. data/lib/vagrant-xenserver/action/halt_vm.rb +1 -5
  15. data/lib/vagrant-xenserver/action/prepare_nfs_valid_ids.rb +1 -1
  16. data/lib/vagrant-xenserver/action/read_ssh_info.rb +48 -12
  17. data/lib/vagrant-xenserver/action/read_state.rb +4 -5
  18. data/lib/vagrant-xenserver/action/resume_vm.rb +3 -3
  19. data/lib/vagrant-xenserver/action/set_vm_params.rb +28 -0
  20. data/lib/vagrant-xenserver/action/start_vm.rb +7 -2
  21. data/lib/vagrant-xenserver/action/suspend_vm.rb +3 -3
  22. data/lib/vagrant-xenserver/action/upload_vhd.rb +130 -115
  23. data/lib/vagrant-xenserver/action/upload_xva.rb +63 -50
  24. data/lib/vagrant-xenserver/config.rb +45 -0
  25. data/lib/vagrant-xenserver/errors.rb +20 -0
  26. data/lib/vagrant-xenserver/plugin.rb +8 -0
  27. data/lib/vagrant-xenserver/util/exnhandler.rb +49 -0
  28. data/lib/vagrant-xenserver/version.rb +1 -1
  29. data/locales/en.yml +20 -1
  30. data/vagrant-xenserver.gemspec +1 -0
  31. metadata +24 -5
  32. data/lib/vagrant-xenserver/action/maybe_upload_disk.rb +0 -85
  33. data/test +0 -0
@@ -8,6 +8,16 @@ module VagrantPlugins
8
8
  # @return [String]
9
9
  attr_accessor :xs_host
10
10
 
11
+ # The port to communicate with the API on XenServer
12
+ #
13
+ # @return [Int]
14
+ attr_accessor :xs_port
15
+
16
+ # True if the API should be accessed over SSL/TLS
17
+ #
18
+ # @return [Bool]
19
+ attr_accessor :xs_use_ssl
20
+
11
21
  # The XenServer username
12
22
  #
13
23
  # @return [String]
@@ -18,30 +28,61 @@ module VagrantPlugins
18
28
  # @return [String]
19
29
  attr_accessor :xs_password
20
30
 
31
+ # Name of the VM
32
+ #
33
+ # @return [String]
34
+ attr_accessor :name
35
+
21
36
  # True if the VM should be PV
22
37
  #
23
38
  # @return [Bool]
24
39
  attr_accessor :pv
25
40
 
41
+ # Timeout for commands sent to XenServer
42
+ #
43
+ # @return [Int]
44
+ attr_accessor :api_timeout
45
+
26
46
  # Memory settings
27
47
  #
28
48
  # @return [Int]
29
49
  attr_accessor :memory
30
50
 
51
+ # XVA URL: If this is set, we'll assume that the XenServer should directly download an XVA from the specified URL
52
+ #
53
+ # @return [String]
54
+ attr_accessor :xva_url
55
+
56
+ # Use HIMN: If this is set, we'll use the host-internal-management-network to connect to the VM (proxying via dom0)
57
+ # Useful if the guest does not have tools installed
58
+ attr_accessor :use_himn
59
+
31
60
  def initialize
32
61
  @xs_host = UNSET_VALUE
62
+ @xs_port = UNSET_VALUE
63
+ @xs_use_ssl = UNSET_VALUE
33
64
  @xs_username = UNSET_VALUE
34
65
  @xs_password = UNSET_VALUE
66
+ @name = UNSET_VALUE
35
67
  @pv = UNSET_VALUE
68
+ @api_timeout = UNSET_VALUE
36
69
  @memory = UNSET_VALUE
70
+ @xva_url = UNSET_VALUE
71
+ @use_himn = UNSET_VALUE
37
72
  end
38
73
 
39
74
  def finalize!
40
75
  @xs_host = nil if @xs_host == UNSET_VALUE
76
+ @xs_port = 80 if @xs_port == UNSET_VALUE
77
+ @xs_use_ssl = false if @xs_use_ssl == UNSET_VALUE
41
78
  @xs_username = nil if @xs_username == UNSET_VALUE
42
79
  @xs_password = nil if @xs_password == UNSET_VALUE
80
+ @name = nil if @name == UNSET_VALUE
43
81
  @pv = nil if @pv == UNSET_VALUE
82
+ @api_timeout = 60 if @api_timeout == UNSET_VALUE
44
83
  @memory = 1024 if @memory == UNSET_VALUE
84
+ @xva_url = nil if @xva_url == UNSET_VALUE
85
+ @use_himn = false if @use_himn == UNSET_VALUE
45
86
  end
46
87
 
47
88
  def validate(machine)
@@ -50,8 +91,12 @@ module VagrantPlugins
50
91
  errors << I18n.t("vagrant_xenserver.config.username_required") if @xs_username.nil?
51
92
  errors << I18n.t("vagrant_xenserver.config.password_required") if @xs_password.nil?
52
93
 
94
+ if not (machine.config.vm.networks.any? { |type,options| type == :public_network })
95
+ errors << I18n.t("vagrant_xenserver.config.himn_required") if not @use_himn
96
+ end
53
97
  { "XenServer Provider" => errors }
54
98
  end
55
99
  end
56
100
  end
57
101
  end
102
+
@@ -26,6 +26,26 @@ module VagrantPlugins
26
26
  class UnknownOS < VagrantXenServerError
27
27
  error_key(:unknown_os)
28
28
  end
29
+
30
+ class QemuImgError < VagrantXenServerError
31
+ error_key(:qemuimg_error)
32
+ end
33
+
34
+ class NoDefaultSR < VagrantXenServerError
35
+ error_key(:nodefaultsr_error)
36
+ end
37
+
38
+ class NoHostsAvailable < VagrantXenServerError
39
+ error_key(:nohostsavailable_error)
40
+ end
41
+
42
+ class Import404 < VagrantXenServerError
43
+ error_key(:import404)
44
+ end
45
+
46
+ class InsufficientSpace < VagrantXenServerError
47
+ error_key(:insufficientspace)
48
+ end
29
49
  end
30
50
  end
31
51
  end
@@ -20,9 +20,17 @@ module VagrantPlugins
20
20
  end
21
21
 
22
22
  provider('xenserver', parallel: true) do
23
+ setup_i18n
24
+
23
25
  require_relative "provider"
24
26
  Provider
25
27
  end
28
+
29
+ def self.setup_i18n
30
+ I18n.load_path << File.expand_path('locales/en.yml',
31
+ XenServer.source_root)
32
+ I18n.reload!
33
+ end
26
34
  end
27
35
  end
28
36
  end
@@ -0,0 +1,49 @@
1
+ # Handle the errors thrown by XenServer
2
+ require "json"
3
+
4
+ module VagrantPlugins
5
+ module XenServer
6
+ module MyUtil
7
+ class Exnhandler
8
+
9
+ def self.def(api,error)
10
+ # Default case: raise generic API error
11
+ raise Errors::APIError,
12
+ api: api,
13
+ error: String(error)
14
+ end
15
+
16
+ def self.handle(api,error)
17
+ case error[0]
18
+ when "IMPORT_ERROR"
19
+ case error[1]
20
+ when "404 Not Found"
21
+ raise Errors::Import404
22
+ else
23
+ Exnhandler.def(api,error)
24
+ end
25
+ when "SR_BACKEND_FAILURE_44"
26
+ raise Errors::InsufficientSpace
27
+ else
28
+ raise Errors::APIError,
29
+ api: api,
30
+ error: String(error)
31
+ end
32
+ end
33
+
34
+ def self.handle_xenapiexn(api,e,logger)
35
+ case e
36
+ when XenApi::Errors::SRFull
37
+ raise Errors::InsufficientSpace
38
+ when XenApi::Errors::GenericError
39
+ # Grotesque hack - get the error array back by parsing the string
40
+ # representation as JSON. Bleurgh!
41
+ self.handle(api,JSON.parse(e.message))
42
+ else
43
+ self.handle(api,e)
44
+ end
45
+ end
46
+ end
47
+ end
48
+ end
49
+ end
@@ -1,6 +1,6 @@
1
1
  module VagrantPlugins
2
2
  module XenServer
3
- VERSION = "0.0.11"
3
+ VERSION = "0.0.12"
4
4
  end
5
5
  end
6
6
 
data/locales/en.yml CHANGED
@@ -7,4 +7,23 @@ en:
7
7
  The XenServer username must be defined via "xs_username"
8
8
  password_required: |-
9
9
  The password for the XenServer username must be defined via "xs_password"
10
-
10
+ himn_required: |-
11
+ Either a public network must be specified or the Host Internal Management Network
12
+ parameter must be enabled. Public networks require the XenServer tools to be
13
+ installed in the guest. If this is not the case, the HIMN must be used by specifying
14
+ 'use_himn=true' in the provider configuration.
15
+ errors:
16
+ login_error: |-
17
+ Failed to login to the XenServer. Check the "xs_username" and "xs_password" parameters
18
+ qemuimg_error: |-
19
+ Failure executing qemu-img. Check that it is installed and working, and that the VHD file referenced is valid.
20
+ nodefaultsr_error: |-
21
+ Failed to find a valid default SR for the pool. Please set one.
22
+ nohostsavailable_error: |-
23
+ No hosts were available to start the VM. Check the memory, disks and whether the hosts are enabled
24
+ import404: |-
25
+ The XVA import failed with a 404 Not Found error: Check the xva_url parameter of your box.
26
+ insufficientspace: |-
27
+ There is insufficient space available on the SR.
28
+ api_error: |-
29
+ The API call '%{api}' failed with error '%{error}'.
@@ -15,6 +15,7 @@ Gem::Specification.new do |s|
15
15
  s.add_development_dependency "rake"
16
16
  s.add_runtime_dependency "nokogiri", "~> 1.6.3"
17
17
  s.add_runtime_dependency "json"
18
+ s.add_runtime_dependency "xenapi"
18
19
 
19
20
  s.files = `git ls-files`.split($\)
20
21
  s.executables = [] # gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: vagrant-xenserver
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.11
4
+ version: 0.0.12
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jon Ludlam
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-07-21 00:00:00.000000000 Z
11
+ date: 2016-08-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake
@@ -52,6 +52,20 @@ dependencies:
52
52
  - - ">="
53
53
  - !ruby/object:Gem::Version
54
54
  version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: xenapi
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
55
69
  description: Enables Vagrant to manage XenServers.
56
70
  email: jonathan.ludlam@citrix.com
57
71
  executables: []
@@ -63,25 +77,30 @@ files:
63
77
  - LICENSE
64
78
  - README.md
65
79
  - Rakefile
80
+ - example_box/install_wheezy.sh
66
81
  - example_box/metadata.json
82
+ - example_box/mkbox.sh
67
83
  - lib/vagrant-xenserver.rb
68
84
  - lib/vagrant-xenserver/action.rb
69
85
  - lib/vagrant-xenserver/action/clone_disk.rb
86
+ - lib/vagrant-xenserver/action/clone_vm.rb
70
87
  - lib/vagrant-xenserver/action/connect_xs.rb
88
+ - lib/vagrant-xenserver/action/create_template.rb
71
89
  - lib/vagrant-xenserver/action/create_vifs.rb
72
90
  - lib/vagrant-xenserver/action/create_vm.rb
73
91
  - lib/vagrant-xenserver/action/destroy_vm.rb
92
+ - lib/vagrant-xenserver/action/download_xva.rb
74
93
  - lib/vagrant-xenserver/action/dummy.rb
75
94
  - lib/vagrant-xenserver/action/halt_vm.rb
76
95
  - lib/vagrant-xenserver/action/is_created.rb
77
96
  - lib/vagrant-xenserver/action/is_running.rb
78
97
  - lib/vagrant-xenserver/action/is_suspended.rb
79
- - lib/vagrant-xenserver/action/maybe_upload_disk.rb
80
98
  - lib/vagrant-xenserver/action/prepare_nfs_settings.rb
81
99
  - lib/vagrant-xenserver/action/prepare_nfs_valid_ids.rb
82
100
  - lib/vagrant-xenserver/action/read_ssh_info.rb
83
101
  - lib/vagrant-xenserver/action/read_state.rb
84
102
  - lib/vagrant-xenserver/action/resume_vm.rb
103
+ - lib/vagrant-xenserver/action/set_vm_params.rb
85
104
  - lib/vagrant-xenserver/action/start_vm.rb
86
105
  - lib/vagrant-xenserver/action/suspend_vm.rb
87
106
  - lib/vagrant-xenserver/action/upload_vhd.rb
@@ -90,10 +109,10 @@ files:
90
109
  - lib/vagrant-xenserver/errors.rb
91
110
  - lib/vagrant-xenserver/plugin.rb
92
111
  - lib/vagrant-xenserver/provider.rb
112
+ - lib/vagrant-xenserver/util/exnhandler.rb
93
113
  - lib/vagrant-xenserver/util/uploader.rb
94
114
  - lib/vagrant-xenserver/version.rb
95
115
  - locales/en.yml
96
- - test
97
116
  - vagrant-xenserver.gemspec
98
117
  homepage: http://github.com/jonludlam/vagrant-xenserver
99
118
  licenses:
@@ -115,7 +134,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
115
134
  version: '0'
116
135
  requirements: []
117
136
  rubyforge_project:
118
- rubygems_version: 2.2.3
137
+ rubygems_version: 2.5.1
119
138
  signing_key:
120
139
  specification_version: 4
121
140
  summary: Enables Vagrant to manage XenServers.
@@ -1,85 +0,0 @@
1
- require "log4r"
2
- require "xmlrpc/client"
3
- require "vagrant-xenserver/util/uploader"
4
- require "rexml/document"
5
-
6
- module VagrantPlugins
7
- module XenServer
8
- module Action
9
- class UploadXVA
10
- def initialize(app, env)
11
- @app = app
12
- @logger = Log4r::Logger.new("vagrant::xenserver::actions::maybe_upload_disk")
13
- end
14
-
15
- def call(env)
16
- #box_image_file = env[:machine].box.directory.join('export.xva').to_s
17
- box_image_file = "/home/jludlam/devel/vagrant-xenserver/centos-6.5.vhd"
18
- hostname = env[:machine].provider_config.xs_host
19
- session = env[:session]
20
-
21
- @logger.info("box name=" + env[:machine].box.name.to_s)
22
- @logger.info("box version=" + env[:machine].box.version.to_s)
23
-
24
- # Create a task to so we can get the result of the upload
25
- task_result = env[:xc].call("task.create", env[:session], "vagrant-xva-upload",
26
- "Task to track progress of the XVA upload from vagrant")
27
-
28
- if task_result["Status"] != "Success"
29
- raise Errors::APIError
30
- end
31
-
32
- task = task_result["Value"]
33
-
34
- url = "https://#{hostname}/import?session_id=#{session}&task_id=#{task}"
35
-
36
- uploader_options = {}
37
- uploader_options[:ui] = env[:ui]
38
- uploader_options[:insecure] = true
39
-
40
- uploader = MyUtil::Uploader.new(box_image_file, url, uploader_options)
41
-
42
- begin
43
- uploader.upload!
44
- rescue Errors::UploaderInterrupted
45
- env[:ui].info(I18n.t("vagrant.xenserver.action.upload_xva.interrupted"))
46
- raise
47
- end
48
-
49
- task_status = ""
50
-
51
- begin
52
- sleep(0.2)
53
- task_status_result = env[:xc].call("task.get_status",env[:session],task)
54
- if task_status_result["Status"] != "Success"
55
- raise Errors::APIError
56
- end
57
- task_status = task_status_result["Value"]
58
- end while task_status == "pending"
59
-
60
- @logger.info("task_status="+task_status)
61
-
62
- if task_status != "success"
63
- raise Errors::APIError
64
- end
65
-
66
- task_result_result = env[:xc].call("task.get_result",env[:session],task)
67
- if task_result_result["Status"] != "Success"
68
- raise Errors::APIError
69
- end
70
-
71
- task_result = task_result_result["Value"]
72
-
73
- doc = REXML::Document.new(task_result)
74
-
75
- doc.elements.each('value/array/data/value') do |ele|
76
- @logger.info("ele=" + ele.text)
77
- end
78
-
79
- @logger.info("task_result=" + task_result)
80
-
81
- end
82
- end
83
- end
84
- end
85
- end
data/test DELETED
Binary file