vagrant-vmware-esxi 1.1.2 → 1.1.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 3301495dc2f6eedc70da07b146b713b93e27bd0f
4
- data.tar.gz: 8f97dd15927c34cb105cfa28c59b9f7d49e8e218
3
+ metadata.gz: 8a4b0a4a1d1fb0d75a31e089a5768c08f39e4a97
4
+ data.tar.gz: f05e33dc43287a63abe340df0129a6fe1bcaf4b3
5
5
  SHA512:
6
- metadata.gz: af1a8de6400d7f4ef38bc8a6b80e8561ac6fb5fbf228cf858d3c5894ee320c7e017045734e041911fcde0490e29276f91986fbfeb2276dcbfbf27bc0715443fa
7
- data.tar.gz: 27319e322ee0600a762e5c49591b9db54c6d22b7926ce751d6ecfa323cc28e0ee0a0108eeaa38a8f36ded661704cda9b0c4bfff7f0f44a8c97b829a386895b39
6
+ metadata.gz: d7cc652733e6811873f6fa2d1abc282120adc43fefee116f271ab96890d236d014b2ce9bf89a3b6b886ab69000d4b4f9b38e522f00bf644f9ff5c8659d641efb
7
+ data.tar.gz: 2c5590cb4815ef1a793f8f1c2e74dbda26d13d635a92f2c96d1b193f84b1a6ca69c71e5043c30fd5334eb772d7ffee1712bba54a33db0ae508364504793f6195
data/README.md CHANGED
@@ -18,6 +18,7 @@ Features and Compatibility
18
18
  * snapshots.
19
19
  * rsync & NFS using built-in Vagrant synced folders.
20
20
  * Provision using built-in Vagrant provisioner.
21
+ * package
21
22
 
22
23
  Requirements
23
24
  ------------
@@ -51,7 +52,7 @@ Vagrant.configure("2") do |config|
51
52
  # https://www.vmware.com/support/developer/ovf/
52
53
  #
53
54
  # If your box is stuck at "Powered On", then most likely
54
- # the system didn't have the vmware tools installed.
55
+ # the system doesn't have the vmware tools installed.
55
56
  #
56
57
  # Here are some of the MANY examples....
57
58
  config.vm.box = 'hashicorp/precise64'
@@ -60,6 +61,9 @@ Vagrant.configure("2") do |config|
60
61
  #config.vm.box = 'laravel/homestead'
61
62
  #config.vm.box = 'centos/7'
62
63
  #config.vm.box = 'bento/ubuntu-14.04'
64
+ #config.vm.box = 'generic/fedora26'
65
+ #config.vm.box = 'generic/alpine36'
66
+
63
67
 
64
68
  # Supports type rsync and NFS.
65
69
  config.vm.synced_folder('.', '/Vagrantfiles', type: 'rsync')
@@ -148,6 +152,7 @@ Vagrant.configure("2") do |config|
148
152
  # when you run vagrant up. ie, if the vmname already exists,
149
153
  # it will be destroyed, then over written... This is helpful
150
154
  # if you have a VM that became an orphan (vagrant lost association).
155
+ # This will also overwrite your box when using vagrant package.
151
156
  #esxi.allow_overwrite = 'True'
152
157
 
153
158
  end
@@ -173,7 +178,7 @@ Basic usage
173
178
  Known issues with vmware_esxi
174
179
  -----------------------------
175
180
  * Cleanup doesn't always destroy a VM that has been partially built. Use the allow_overwrite = 'True' option if you need to force a rebuild.
176
- * ovftool for windows doesn't put ovftool.exe in your path. You can manually set your path, or install ovftool in the \HashiCorp\Vagrant\bin directory.
181
+ * ovftool installer for windows doesn't put ovftool.exe in your path. You can manually set your path, or install ovftool in the \HashiCorp\Vagrant\bin directory.
177
182
  * Built-in Vagrant synced folders using NFS fails if you try to re-provision.
178
183
  * In general I find NFS synced folders pretty "flakey" anyways...
179
184
  * Multi machines may not provision one VM if the boxes are different.
@@ -1,20 +1,23 @@
1
1
  Vagrant.configure("2") do |config|
2
2
 
3
- # Box, Select any box created for VMware that is compatible with
3
+ # Select any box created for VMware that is compatible with
4
4
  # the ovftool. To get maximum compatiblity You should download
5
5
  # and install the latest version for your OS.
6
6
  # https://www.vmware.com/support/developer/ovf/
7
7
  #
8
8
  # If your box is stuck at "Powered On", then most likely
9
- # the system didn't have the vmware tools installed.
9
+ # the system doesn't have the vmware tools installed.
10
10
  #
11
- # Here are some of the MANY examples....
11
+ # Here are some of the MANY box examples....
12
12
  config.vm.box = 'hashicorp/precise64'
13
13
  #config.vm.box = 'steveant/CentOS-7.0-1406-Minimal-x64'
14
14
  #config.vm.box = 'geerlingguy/ubuntu1604'
15
15
  #config.vm.box = 'laravel/homestead'
16
16
  #config.vm.box = 'centos/7'
17
17
  #config.vm.box = 'bento/ubuntu-14.04'
18
+ #config.vm.box = 'generic/fedora26'
19
+ #config.vm.box = 'generic/alpine36'
20
+
18
21
 
19
22
  # Supports type rsync and NFS.
20
23
  config.vm.synced_folder('.', '/Vagrantfiles', type: 'rsync')
@@ -103,6 +106,7 @@ Vagrant.configure("2") do |config|
103
106
  # when you run vagrant up. ie, if the vmname already exists,
104
107
  # it will be destroyed, then over written... This is helpful
105
108
  # if you have a VM that became an orphan (vagrant lost association).
109
+ # This will also overwrite your box when using vagrant package.
106
110
  #esxi.allow_overwrite = 'True'
107
111
 
108
112
  end
@@ -147,6 +147,13 @@ module VagrantPlugins
147
147
  end
148
148
  end
149
149
 
150
+ def self.action_package
151
+ Vagrant::Action::Builder.new.tap do |b|
152
+ b.use ReadState
153
+ b.use Package
154
+ end
155
+ end
156
+
150
157
  action_root = Pathname.new(File.expand_path('../action', __FILE__))
151
158
  autoload :ConnectESXi, action_root.join('connect_esxi')
152
159
  autoload :CreateVM, action_root.join('createvm')
@@ -157,6 +164,7 @@ module VagrantPlugins
157
164
  autoload :Destroy, action_root.join('destroy')
158
165
  autoload :Suspend, action_root.join('suspend')
159
166
  autoload :Resume, action_root.join('resume')
167
+ autoload :Package, action_root.join('package')
160
168
  autoload :SnapshotInfo, action_root.join('snapshot_info')
161
169
  autoload :SnapshotList, action_root.join('snapshot_list')
162
170
  autoload :SnapshotSave, action_root.join('snapshot_save')
@@ -261,7 +261,7 @@ module VagrantPlugins
261
261
  # Using ovftool, import vmx in box folder, export to ESXi server
262
262
  #
263
263
  unless system 'ovftool --version'
264
- raise Errors::ESXiConfigError,
264
+ raise Errors::OVFToolError,
265
265
  message: 'ovftool not found or not in your path.'\
266
266
  " Please download and "\
267
267
  ' install from http://www.vmware.com.'
@@ -276,7 +276,7 @@ module VagrantPlugins
276
276
  # Security bug if unremarked! Password will be exposed in log file.
277
277
  # @logger.info("vagrant-vmware-esxi, createvm: ovf_cmd #{ovf_cmd}")
278
278
  unless system "#{ovf_cmd}"
279
- raise Errors::ESXiConfigError, message: 'Error with ovftool...'
279
+ raise Errors::OVFToolError, message: ''
280
280
  end
281
281
 
282
282
  # VMX file is not needed any longer
@@ -0,0 +1,139 @@
1
+ require 'log4r'
2
+ require 'net/ssh/simple'
3
+ require 'fileutils'
4
+
5
+ module VagrantPlugins
6
+ module ESXi
7
+ module Action
8
+ # This action will save (create) a new snapshot
9
+ class Package
10
+ def initialize(app, env)
11
+ @app = app
12
+ @logger = Log4r::Logger.new('vagrant_vmware_esxi::action::package')
13
+ env['package.files'] ||= {}
14
+ env['package.output'] ||= 'package'
15
+ end
16
+
17
+ def call(env)
18
+ suspend(env)
19
+ @app.call(env)
20
+ end
21
+
22
+ def suspend(env)
23
+ @logger.info('vagrant-vmware-esxi, package: start...')
24
+
25
+ # Get config.
26
+ machine = env[:machine]
27
+ config = env[:machine].provider_config
28
+
29
+ @logger.info("vagrant-vmware-esxi, package: machine id: #{machine.id}")
30
+ @logger.info("vagrant-vmware-esxi, package: current state: #{env[:machine_state]}")
31
+
32
+ if env[:machine_state].to_s != 'powered_off'
33
+ env[:ui].info I18n.t('vagrant_vmware_esxi.vagrant_vmware_esxi_message',
34
+ message: 'Cannot package in this state, must '\
35
+ 'be powered off.')
36
+ else
37
+ env[:ui].info I18n.t('vagrant_vmware_esxi.vagrant_vmware_esxi_message',
38
+ message: 'Attempting to package')
39
+
40
+ if (config.allow_overwrite =~ %r{true}i) ||
41
+ (config.allow_overwrite =~ %r{yes}i)
42
+ overwrite_opts = '--overwrite'
43
+ else
44
+ overwrite_opts = nil
45
+ end
46
+
47
+ boxname = env['package.output'].gsub('/', '-VAGRANTSLASH-')
48
+ tmpdir = "ZZZZ_tmpdir"
49
+ Dir.mkdir(tmpdir) unless File.exists?(tmpdir)
50
+
51
+ env[:ui].info I18n.t('vagrant_vmware_esxi.vagrant_vmware_esxi_message',
52
+ message: "boxname: #{boxname}.box")
53
+
54
+ if File.exists?("#{boxname}.box") && overwrite_opts.nil?
55
+ raise Errors::GeneralError,
56
+ message: "#{boxname}.box already exists. Set \n"\
57
+ " allow_overwrite='True' in Vagrantfile for force."
58
+ end
59
+
60
+ # Find a tar/bsdtar
61
+ if system 'tar --version >/dev/null 2>&1'
62
+ tar_cmd = 'tar'
63
+ elsif system 'bsdtar --version >/dev/null 2>&1'
64
+ tar_cmd = 'bsdtar'
65
+ else
66
+ raise Errors::ESXiConfigError,
67
+ message: 'unable to find tar in your path.'
68
+ end
69
+
70
+ # Check if user files and Vagrantfile exists
71
+ if env['package.include']
72
+ env['package.include'].each do |f|
73
+ unless File.exists?(f)
74
+ raise Errors::GeneralError,
75
+ message: "file not found #{f}"
76
+ end
77
+ end
78
+ end
79
+ if env['package.vagrantfile']
80
+ unless File.exists?(env['package.vagrantfile'])
81
+ raise Errors::GeneralError,
82
+ message: "file not found #{env['package.vagrantfile']}"
83
+ end
84
+ end
85
+
86
+ #
87
+ # Using ovftool, import vmx in box folder, export to ESXi server
88
+ #
89
+ unless system 'ovftool --version'
90
+ raise Errors::OVFToolError,
91
+ message: 'ovftool not found or not in your path.'\
92
+ " Please download and "\
93
+ ' install from http://www.vmware.com.'
94
+ end
95
+
96
+ ovf_cmd = "ovftool --noSSLVerify -tt=VMX --name=\"#{boxname}\" "\
97
+ "#{overwrite_opts} vi://#{config.esxi_username}:"\
98
+ "#{config.esxi_password}@#{config.esxi_hostname}"\
99
+ "?moref=vim.VirtualMachine:#{machine.id} #{tmpdir}"
100
+
101
+ unless system "#{ovf_cmd}"
102
+ raise Errors::OVFToolError, message: ''
103
+ end
104
+
105
+ # Add user files, Vagrantfile & metadata
106
+ if env['package.include']
107
+ env['package.include'].each do |f|
108
+ env[:ui].info("Including user file: #{f}")
109
+ FileUtils.cp(f, "#{tmpdir}/#{boxname}/")
110
+ end
111
+ end
112
+ if env['package.vagrantfile']
113
+ env[:ui].info('Including user Vagrantfile')
114
+ FileUtils.cp(env['package.vagrantfile'], "#{tmpdir}/#{boxname}/")
115
+ end
116
+ # Add metadata.json
117
+ File.open("#{tmpdir}/#{boxname}/metadata.json", "w") do |f|
118
+ unless f.write('{"provider":"vmware"}')
119
+ raise Errors::GeneralError, message: 'cannot create metadata.json'
120
+ end
121
+ end
122
+
123
+ env[:ui].info("tarring #{boxname}.box")
124
+ unless system "cd #{tmpdir}/#{boxname} ; #{tar_cmd} cvf ../../#{boxname}.box *"
125
+ raise Errors::GeneralError,
126
+ message: 'tar command failed.'
127
+ end
128
+
129
+ env[:ui].info("Doing cleanup.")
130
+ unless FileUtils.rm_r tmpdir
131
+ raise Errors::GeneralError,
132
+ message: "unable to remove tmpdir. (#{tmpdir})"
133
+ end
134
+ end
135
+ end
136
+ end
137
+ end
138
+ end
139
+ end
@@ -17,6 +17,15 @@ module VagrantPlugins
17
17
  class ESXiConfigError < VagrantESXiErrors
18
18
  error_key(:esxi_config_error)
19
19
  end
20
+
21
+ # Error class
22
+ class OVFToolError < VagrantESXiErrors
23
+ error_key(:esxi_ovftool_error)
24
+ end
25
+ # Error class
26
+ class GeneralError < VagrantESXiErrors
27
+ error_key(:general_error)
28
+ end
20
29
  end
21
30
  end
22
31
  end
@@ -1,6 +1,6 @@
1
1
  # VERSION
2
2
  module VagrantPlugins
3
3
  module ESXi
4
- VERSION = '1.1.2'
4
+ VERSION = '1.1.3'
5
5
  end
6
6
  end
data/locales/en.yml CHANGED
@@ -18,6 +18,12 @@ en:
18
18
  esxi_config_error: |-
19
19
  There was an ESXi configuration error.
20
20
  %{message}
21
+ esxi_ovftool_error: |-
22
+ There was an OVF Tool error.
23
+ %{message}
24
+ general_error: |-
25
+ There was an error.
26
+ %{message}
21
27
  vagrant_vmware_esxi_message: |-
22
28
  --- %{message}
23
29
  vmbuild_not_done: |-
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: vagrant-vmware-esxi
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.2
4
+ version: 1.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jonathan Senkerik
@@ -128,6 +128,7 @@ files:
128
128
  - lib/vagrant-vmware-esxi/action/createvm.rb
129
129
  - lib/vagrant-vmware-esxi/action/destroy.rb
130
130
  - lib/vagrant-vmware-esxi/action/halt.rb
131
+ - lib/vagrant-vmware-esxi/action/package.rb
131
132
  - lib/vagrant-vmware-esxi/action/read_ssh_info.rb
132
133
  - lib/vagrant-vmware-esxi/action/read_state.rb
133
134
  - lib/vagrant-vmware-esxi/action/resume.rb