vagrant-xenserver-jc 0.0.13

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.
Files changed (48) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +9 -0
  3. data/CHANGELOG.md +40 -0
  4. data/Gemfile +14 -0
  5. data/LICENSE +8 -0
  6. data/README.md +167 -0
  7. data/Rakefile +14 -0
  8. data/example_box/install_wheezy.sh +128 -0
  9. data/example_box/metadata.json +3 -0
  10. data/example_box/mkbox.sh +17 -0
  11. data/lib/vagrant-xenserver/action/clone_disk.rb +30 -0
  12. data/lib/vagrant-xenserver/action/clone_vm.rb +30 -0
  13. data/lib/vagrant-xenserver/action/configure_network.rb +61 -0
  14. data/lib/vagrant-xenserver/action/connect_xs.rb +47 -0
  15. data/lib/vagrant-xenserver/action/create_template.rb +87 -0
  16. data/lib/vagrant-xenserver/action/create_vifs.rb +86 -0
  17. data/lib/vagrant-xenserver/action/create_vm.rb +95 -0
  18. data/lib/vagrant-xenserver/action/destroy_vm.rb +37 -0
  19. data/lib/vagrant-xenserver/action/download_xva.rb +101 -0
  20. data/lib/vagrant-xenserver/action/dummy.rb +16 -0
  21. data/lib/vagrant-xenserver/action/halt_vm.rb +23 -0
  22. data/lib/vagrant-xenserver/action/is_created.rb +20 -0
  23. data/lib/vagrant-xenserver/action/is_running.rb +20 -0
  24. data/lib/vagrant-xenserver/action/is_suspended.rb +20 -0
  25. data/lib/vagrant-xenserver/action/prepare_nfs_settings.rb +85 -0
  26. data/lib/vagrant-xenserver/action/prepare_nfs_valid_ids.rb +17 -0
  27. data/lib/vagrant-xenserver/action/read_ssh_info.rb +97 -0
  28. data/lib/vagrant-xenserver/action/read_state.rb +35 -0
  29. data/lib/vagrant-xenserver/action/resume_vm.rb +30 -0
  30. data/lib/vagrant-xenserver/action/set_vm_params.rb +28 -0
  31. data/lib/vagrant-xenserver/action/start_vm.rb +31 -0
  32. data/lib/vagrant-xenserver/action/suspend_vm.rb +30 -0
  33. data/lib/vagrant-xenserver/action/upload_vhd.rb +164 -0
  34. data/lib/vagrant-xenserver/action/upload_xva.rb +100 -0
  35. data/lib/vagrant-xenserver/action/validate_network.rb +112 -0
  36. data/lib/vagrant-xenserver/action/wait_himn.rb +58 -0
  37. data/lib/vagrant-xenserver/action.rb +272 -0
  38. data/lib/vagrant-xenserver/config.rb +102 -0
  39. data/lib/vagrant-xenserver/errors.rb +68 -0
  40. data/lib/vagrant-xenserver/plugin.rb +70 -0
  41. data/lib/vagrant-xenserver/provider.rb +36 -0
  42. data/lib/vagrant-xenserver/util/exnhandler.rb +49 -0
  43. data/lib/vagrant-xenserver/util/uploader.rb +215 -0
  44. data/lib/vagrant-xenserver/version.rb +6 -0
  45. data/lib/vagrant-xenserver.rb +17 -0
  46. data/locales/en.yml +38 -0
  47. data/vagrant-xenserver.gemspec +27 -0
  48. metadata +173 -0
@@ -0,0 +1,215 @@
1
+ require "uri"
2
+
3
+ require "log4r"
4
+
5
+ require "vagrant/util/busy"
6
+ require "vagrant/util/platform"
7
+ require "vagrant/util/subprocess"
8
+
9
+ module VagrantPlugins
10
+ module XenServer
11
+ module MyUtil
12
+ # This class uploads files using various protocols by subprocessing
13
+ # to cURL. cURL is a much more capable and complete upload tool than
14
+ # a hand-rolled Ruby library, so we defer to its expertise.
15
+ class Uploader
16
+ # Custom user agent provided to cURL so that requests to URL shorteners
17
+ # are properly tracked.
18
+ USER_AGENT = "VagrantXenserver/1.0"
19
+
20
+ attr_reader :source
21
+ attr_reader :destination
22
+
23
+ def initialize(source, destination, options=nil)
24
+ options ||= {}
25
+
26
+ @logger = Log4r::Logger.new("vagrant::xenserver::util::uploader")
27
+ @source = source.to_s
28
+ @destination = destination.to_s
29
+
30
+ begin
31
+ url = URI.parse(@destination)
32
+ if url.scheme && url.scheme.start_with?("http") && url.user
33
+ auth = "#{url.user}"
34
+ auth += ":#{url.password}" if url.password
35
+ url.user = nil
36
+ url.password = nil
37
+ options[:auth] ||= auth
38
+ @destination = url.to_s
39
+ end
40
+ rescue URI::InvalidURIError
41
+ # Ignore, since its clearly not HTTP
42
+ end
43
+
44
+ # Get the various optional values
45
+ @auth = options[:auth]
46
+ @ca_cert = options[:ca_cert]
47
+ @ca_path = options[:ca_path]
48
+ @continue = options[:continue]
49
+ @headers = options[:headers]
50
+ @insecure = options[:insecure]
51
+ @ui = options[:ui]
52
+ @client_cert = options[:client_cert]
53
+ end
54
+
55
+ # This executes the actual upload, uploading the source file
56
+ # to the destination with the given options used to initialize this
57
+ # class.
58
+ #
59
+ # If this method returns without an exception, the upload
60
+ # succeeded. An exception will be raised if the upload failed.
61
+ def upload!
62
+ options, subprocess_options = self.options
63
+ options += ["--output", "dummy"]
64
+ options << @destination
65
+ options += ["-T", @source]
66
+
67
+ # This variable can contain the proc that'll be sent to
68
+ # the subprocess execute.
69
+ data_proc = nil
70
+
71
+ if @ui
72
+ # If we're outputting progress, then setup the subprocess to
73
+ # tell us output so we can parse it out.
74
+ subprocess_options[:notify] = :stderr
75
+
76
+ progress_data = ""
77
+ progress_regexp = /(\r(.+?))\r/
78
+
79
+ # Setup the proc that'll receive the real-time data from
80
+ # the uploader.
81
+ data_proc = Proc.new do |type, data|
82
+ # Type will always be "stderr" because that is the only
83
+ # type of data we're subscribed for notifications.
84
+
85
+ # Accumulate progress_data
86
+ progress_data << data
87
+
88
+ while true
89
+ # If we have a full amount of column data (two "\r") then
90
+ # we report new progress reports. Otherwise, just keep
91
+ # accumulating.
92
+ match = progress_regexp.match(progress_data)
93
+ break if !match
94
+ data = match[2]
95
+ progress_data.gsub!(match[1], "")
96
+
97
+ # Ignore the first \r and split by whitespace to grab the columns
98
+ columns = data.strip.split(/\s+/)
99
+
100
+ # COLUMN DATA:
101
+ #
102
+ # 0 - % total
103
+ # 1 - Total size
104
+ # 2 - % received
105
+ # 3 - Received size
106
+ # 4 - % transferred
107
+ # 5 - Transferred size
108
+ # 6 - Average download speed
109
+ # 7 - Average upload speed
110
+ # 9 - Total time
111
+ # 9 - Time spent
112
+ # 10 - Time left
113
+ # 11 - Current speed
114
+
115
+ output = "Progress: #{columns[0]}% (Rate: #{columns[11]}/s, Estimated time remaining: #{columns[10]})"
116
+ @ui.clear_line
117
+ @ui.detail(output, new_line: false)
118
+ end
119
+ end
120
+ end
121
+
122
+ @logger.info("Uploader starting upload: ")
123
+ @logger.info(" -- Source: #{@source}")
124
+ @logger.info(" -- Destination: #{@destination}")
125
+
126
+ begin
127
+ execute_curl(options, subprocess_options, &data_proc)
128
+ ensure
129
+ # If we're outputting to the UI, clear the output to
130
+ # avoid lingering progress meters.
131
+ if @ui
132
+ @ui.clear_line
133
+
134
+ # Windows doesn't clear properly for some reason, so we just
135
+ # output one more newline.
136
+ # @ui.detail("") if Platform.windows?
137
+ end
138
+ end
139
+
140
+ # Everything succeeded
141
+ true
142
+ end
143
+
144
+ def execute_curl(options, subprocess_options, &data_proc)
145
+ options = options.dup
146
+ options << subprocess_options
147
+
148
+ # Create the callback that is called if we are interrupted
149
+ interrupted = false
150
+ int_callback = Proc.new do
151
+ @logger.info("Uploader interrupted!")
152
+ interrupted = true
153
+ end
154
+
155
+ # Execute!
156
+ result = Vagrant::Util::Busy.busy(int_callback) do
157
+ Vagrant::Util::Subprocess.execute("curl", *options, &data_proc)
158
+ end
159
+
160
+ # If the upload was interrupted, then raise a specific error
161
+ raise Errors::UploaderInterrupted if interrupted
162
+
163
+ # If it didn't exit successfully, we need to parse the data and
164
+ # show an error message.
165
+ if result.exit_code != 0
166
+ @logger.warn("Uploader exit code: #{result.exit_code}")
167
+ parts = result.stderr.split(/\n*curl:\s+\(\d+\)\s*/, 2)
168
+ parts[1] ||= ""
169
+ raise Errors::UploaderError, message: parts[1].chomp
170
+ end
171
+
172
+ result
173
+ end
174
+
175
+ # Returns the varoius cURL and subprocess options.
176
+ #
177
+ # @return [Array<Array, Hash>]
178
+ def options
179
+ # Build the list of parameters to execute with cURL
180
+ options = [
181
+ "--fail",
182
+ "--location",
183
+ "--max-redirs", "10",
184
+ "--user-agent", USER_AGENT,
185
+ ]
186
+
187
+ options += ["--cacert", @ca_cert] if @ca_cert
188
+ options += ["--capath", @ca_path] if @ca_path
189
+ options += ["--continue-at", "-"] if @continue
190
+ options << "--insecure" if @insecure
191
+ options << "--cert" << @client_cert if @client_cert
192
+ options << "-u" << @auth if @auth
193
+
194
+ if @headers
195
+ Array(@headers).each do |header|
196
+ options << "-H" << header
197
+ end
198
+ end
199
+
200
+ # Specify some options for the subprocess
201
+ subprocess_options = {}
202
+
203
+ # If we're in Vagrant, then we use the packaged CA bundle
204
+ if Vagrant.in_installer?
205
+ subprocess_options[:env] ||= {}
206
+ subprocess_options[:env]["CURL_CA_BUNDLE"] =
207
+ File.expand_path("cacert.pem", ENV["VAGRANT_INSTALLER_EMBEDDED_DIR"])
208
+ end
209
+
210
+ return [options, subprocess_options]
211
+ end
212
+ end
213
+ end
214
+ end
215
+ end
@@ -0,0 +1,6 @@
1
+ module VagrantPlugins
2
+ module XenServer
3
+ VERSION = "0.0.13"
4
+ end
5
+ end
6
+
@@ -0,0 +1,17 @@
1
+ require "pathname"
2
+
3
+ require "vagrant-xenserver/plugin"
4
+
5
+ module VagrantPlugins
6
+ module XenServer
7
+ lib_path = Pathname.new(File.expand_path("../vagrant-xenserver", __FILE__))
8
+ autoload :Action, lib_path.join("action")
9
+ autoload :Errors, lib_path.join("errors")
10
+ autoload :Util, lib_path.join("util")
11
+
12
+ def self.source_root
13
+ @source_root ||= Pathname.new(File.expand_path("../../", __FILE__))
14
+ end
15
+ end
16
+ end
17
+
data/locales/en.yml ADDED
@@ -0,0 +1,38 @@
1
+ en:
2
+ vagrant_xenserver:
3
+ config:
4
+ host_required: |-
5
+ A XenServer host must be defined via "xs_host"
6
+ username_required: |-
7
+ The XenServer username must be defined via "xs_username"
8
+ password_required: |-
9
+ The password for the XenServer username must be defined via "xs_password"
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}'.
30
+ connection_error: |-
31
+ Failed to connect to the XenServer. Please verify "xs_host" setting is correct.
32
+ himn_communicator_error: |-
33
+ Failed to connect to the VM via HIMN. Please make sure the first eth (eth0) is configured as DHCP.
34
+ invalid_network: |-
35
+ Invalid network %{network} in machine %{vm}. Available networks: %{allnetwork}
36
+ invalid_interface: |-
37
+ Configuration Error: Interface %{eth} on network %{net} is %{opt}. %{message} !
38
+
@@ -0,0 +1,27 @@
1
+ $:.unshift File.expand_path("../lib", __FILE__)
2
+ require "vagrant-xenserver/version"
3
+
4
+ Gem::Specification.new do |s|
5
+ s.name = "vagrant-xenserver-jc"
6
+ s.version = VagrantPlugins::XenServer::VERSION
7
+ s.platform = Gem::Platform::RUBY
8
+ s.license = "MIT"
9
+ s.authors = "Sayid Munawar"
10
+ s.email = "sayid.munawar@gmail.com"
11
+ s.homepage = "http://github.com/jogjacamp/vagrant-xenserver-jc"
12
+ s.summary = "Enables Vagrant to manage XenServers. Forked from vagrant-xenserver"
13
+ s.description = "Enables Vagrant to manage XenServers. Forked from vagrant-xenserver"
14
+
15
+ s.add_development_dependency "rake"
16
+ s.add_runtime_dependency "nokogiri", "~> 1.6.3"
17
+ s.add_runtime_dependency "json"
18
+ s.add_runtime_dependency "xenapi"
19
+ s.add_runtime_dependency "pry"
20
+ s.add_runtime_dependency "pry-byebug"
21
+
22
+ s.files = `git ls-files`.split($\)
23
+ s.executables = [] # gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
24
+ s.test_files = [] #gem.files.grep(%r{^(test|spec|features)/})
25
+ s.require_paths = ['lib']
26
+
27
+ end
metadata ADDED
@@ -0,0 +1,173 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: vagrant-xenserver-jc
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.13
5
+ platform: ruby
6
+ authors:
7
+ - Sayid Munawar
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2017-08-02 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rake
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: nokogiri
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: 1.6.3
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: 1.6.3
41
+ - !ruby/object:Gem::Dependency
42
+ name: json
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
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'
69
+ - !ruby/object:Gem::Dependency
70
+ name: pry
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: pry-byebug
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :runtime
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ description: Enables Vagrant to manage XenServers. Forked from vagrant-xenserver
98
+ email: sayid.munawar@gmail.com
99
+ executables: []
100
+ extensions: []
101
+ extra_rdoc_files: []
102
+ files:
103
+ - ".gitignore"
104
+ - CHANGELOG.md
105
+ - Gemfile
106
+ - LICENSE
107
+ - README.md
108
+ - Rakefile
109
+ - example_box/install_wheezy.sh
110
+ - example_box/metadata.json
111
+ - example_box/mkbox.sh
112
+ - lib/vagrant-xenserver.rb
113
+ - lib/vagrant-xenserver/action.rb
114
+ - lib/vagrant-xenserver/action/clone_disk.rb
115
+ - lib/vagrant-xenserver/action/clone_vm.rb
116
+ - lib/vagrant-xenserver/action/configure_network.rb
117
+ - lib/vagrant-xenserver/action/connect_xs.rb
118
+ - lib/vagrant-xenserver/action/create_template.rb
119
+ - lib/vagrant-xenserver/action/create_vifs.rb
120
+ - lib/vagrant-xenserver/action/create_vm.rb
121
+ - lib/vagrant-xenserver/action/destroy_vm.rb
122
+ - lib/vagrant-xenserver/action/download_xva.rb
123
+ - lib/vagrant-xenserver/action/dummy.rb
124
+ - lib/vagrant-xenserver/action/halt_vm.rb
125
+ - lib/vagrant-xenserver/action/is_created.rb
126
+ - lib/vagrant-xenserver/action/is_running.rb
127
+ - lib/vagrant-xenserver/action/is_suspended.rb
128
+ - lib/vagrant-xenserver/action/prepare_nfs_settings.rb
129
+ - lib/vagrant-xenserver/action/prepare_nfs_valid_ids.rb
130
+ - lib/vagrant-xenserver/action/read_ssh_info.rb
131
+ - lib/vagrant-xenserver/action/read_state.rb
132
+ - lib/vagrant-xenserver/action/resume_vm.rb
133
+ - lib/vagrant-xenserver/action/set_vm_params.rb
134
+ - lib/vagrant-xenserver/action/start_vm.rb
135
+ - lib/vagrant-xenserver/action/suspend_vm.rb
136
+ - lib/vagrant-xenserver/action/upload_vhd.rb
137
+ - lib/vagrant-xenserver/action/upload_xva.rb
138
+ - lib/vagrant-xenserver/action/validate_network.rb
139
+ - lib/vagrant-xenserver/action/wait_himn.rb
140
+ - lib/vagrant-xenserver/config.rb
141
+ - lib/vagrant-xenserver/errors.rb
142
+ - lib/vagrant-xenserver/plugin.rb
143
+ - lib/vagrant-xenserver/provider.rb
144
+ - lib/vagrant-xenserver/util/exnhandler.rb
145
+ - lib/vagrant-xenserver/util/uploader.rb
146
+ - lib/vagrant-xenserver/version.rb
147
+ - locales/en.yml
148
+ - vagrant-xenserver.gemspec
149
+ homepage: http://github.com/jogjacamp/vagrant-xenserver-jc
150
+ licenses:
151
+ - MIT
152
+ metadata: {}
153
+ post_install_message:
154
+ rdoc_options: []
155
+ require_paths:
156
+ - lib
157
+ required_ruby_version: !ruby/object:Gem::Requirement
158
+ requirements:
159
+ - - ">="
160
+ - !ruby/object:Gem::Version
161
+ version: '0'
162
+ required_rubygems_version: !ruby/object:Gem::Requirement
163
+ requirements:
164
+ - - ">="
165
+ - !ruby/object:Gem::Version
166
+ version: '0'
167
+ requirements: []
168
+ rubyforge_project:
169
+ rubygems_version: 2.5.2
170
+ signing_key:
171
+ specification_version: 4
172
+ summary: Enables Vagrant to manage XenServers. Forked from vagrant-xenserver
173
+ test_files: []