vagrant-vmware-esxi 1.0.1 → 1.1.2

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: f46516e196812b3fbbf49dd8ed7a46495e2fc218
4
- data.tar.gz: 67954083f84d6379592369129bb39d38630d06cb
3
+ metadata.gz: 3301495dc2f6eedc70da07b146b713b93e27bd0f
4
+ data.tar.gz: 8f97dd15927c34cb105cfa28c59b9f7d49e8e218
5
5
  SHA512:
6
- metadata.gz: 15957a2906621db58b7e98e335527728e8c10b5a1c173a3612119a9a45d1440df19443ebbef528c48fb6fb86b1ca114110da0d0e642997a45212cd35824e4b4f
7
- data.tar.gz: afa0bbd2b7ef8a49126ccb261083e7cea70341a029b6ecfb5d75e91db99c2f38257dea094b87549e5b2a01e233626893cf4064d17ec7140bc97a8905cad01700
6
+ metadata.gz: af1a8de6400d7f4ef38bc8a6b80e8561ac6fb5fbf228cf858d3c5894ee320c7e017045734e041911fcde0490e29276f91986fbfeb2276dcbfbf27bc0715443fa
7
+ data.tar.gz: 27319e322ee0600a762e5c49591b9db54c6d22b7926ce751d6ecfa323cc28e0ee0a0108eeaa38a8f36ded661704cda9b0c4bfff7f0f44a8c97b829a386895b39
data/README.md CHANGED
@@ -1,21 +1,22 @@
1
1
  vagrant-vmware-esxi plugin
2
2
  ==========================
3
- This is a Vagrant plugin that adds a VMware ESXi provider support. This allows Vagrant to control and provision VMs directly on an ESXi hypervisor without a need for vCenter or VShpere. ESXi hypervisor is a free download from VMware!
3
+ This is a Vagrant plugin that adds a VMware ESXi provider support. This allows Vagrant to control and provision VMs directly on an ESXi hypervisor without a need for vCenter or VShpere. ESXi hypervisor is a free download from VMware!
4
4
  >https://www.vmware.com/go/get-free-esxi
5
5
 
6
6
 
7
- Features
8
- --------
7
+ Features and Compatibility
8
+ --------------------------
9
9
  * Any of the vmware Box formats should be compatible.
10
- * vmware_destop, vmware_fusion, vmware_workstation...
10
+ * vmware_desktop, vmware_fusion, vmware_workstation...
11
11
  * Will automatically download boxes from the web.
12
12
  * Will automatically upload the box to your ESXi host.
13
13
  * Automatic or manual VM names.
14
14
  * Automatic VM names are "PREFIX-HOSTNAME-USERNAME-DIR".
15
15
  * Multi machine capable.
16
- * Supports adding your VM to a Resource Pools to partition CPU and memory usage from other VMs on your ESXi host.
17
- * suspend / resume
18
- * rsync, using built-in Vagrant synced folders.
16
+ * Supports adding your VM to Resource Pools to partition CPU and memory usage from other VMs on your ESXi host.
17
+ * suspend / resume.
18
+ * snapshots.
19
+ * rsync & NFS using built-in Vagrant synced folders.
19
20
  * Provision using built-in Vagrant provisioner.
20
21
 
21
22
  Requirements
@@ -60,13 +61,13 @@ Vagrant.configure("2") do |config|
60
61
  #config.vm.box = 'centos/7'
61
62
  #config.vm.box = 'bento/ubuntu-14.04'
62
63
 
63
- # Currently this tool supports rsync ONLY. NFS is not working yet
64
+ # Supports type rsync and NFS.
64
65
  config.vm.synced_folder('.', '/Vagrantfiles', type: 'rsync')
65
66
 
66
67
  #
67
68
  # Provider (esxi) settings
68
69
  #
69
- config.vm.provider :esxi do |esxi|
70
+ config.vm.provider :vmware_esxi do |esxi|
70
71
 
71
72
  # REQUIRED! ESXi hostname/IP
72
73
  # You MUST specify a esxi_hostname or IP, uless you
@@ -81,10 +82,10 @@ Vagrant.configure("2") do |config|
81
82
  # A NOTE about esxi_password / ssh keys!!
82
83
  #
83
84
  # If you don't specify a password and do not use ssh
84
- # keys, you wil; be entering your esxi password A LOT!
85
+ # keys, you will be entering your esxi password A LOT!
85
86
  #
86
87
  # From your command line, you should be able to run
87
- # following command without erros and be able to get to
88
+ # following command without an error and be able to get to
88
89
  # the esxi command prompt.
89
90
  #
90
91
  # $ ssh root@ESXi_IP_ADDRESS
@@ -111,14 +112,14 @@ Vagrant.configure("2") do |config|
111
112
  esxi.virtual_network = "vmnet_example"
112
113
 
113
114
  # OPTIONAL. Specify a Disk Store
114
- # Default is to use the least used Disk Store.
115
+ # The Default is to use the least used Disk Store.
115
116
  #esxi.vm_disk_store = "DS_001"
116
117
 
117
118
  # OPTIONAL. Guest VM name to be created/used.
118
119
  # The Default will be automatically generated
119
120
  # and will be based on the vmname_prefix,
120
121
  # hostname, username, path...
121
- #esxi.vmname = "Custome_Guest_VM_Name"
122
+ #esxi.vmname = "Custom-Guest-VM_Name"
122
123
 
123
124
  # OPTIONAL. When automatically naming VMs, use
124
125
  # this prifix.
@@ -146,7 +147,7 @@ Vagrant.configure("2") do |config|
146
147
  # Set this to 'True' will overwrite existing VMs (with the same name)
147
148
  # when you run vagrant up. ie, if the vmname already exists,
148
149
  # it will be destroyed, then over written... This is helpful
149
- # if you have a VM that vagrant lost control (lost association).
150
+ # if you have a VM that became an orphan (vagrant lost association).
150
151
  #esxi.allow_overwrite = 'True'
151
152
 
152
153
  end
@@ -155,21 +156,25 @@ end
155
156
 
156
157
  Basic usage
157
158
  -----------
158
- 1. `vagrant up --provider=esxi`
159
+ 1. `vagrant up --provider=vmware_esxi`
159
160
  1. To access the VM, use `vagrant ssh`
160
161
  1. To destroy the VM, use `vagrant destroy`
161
162
  1. Some other fun stuff you can do.
162
163
  * `vagrant status`
163
164
  * `vagrant suspend`
164
165
  * `vagrant resume`
166
+ * `vagrant snapshot push`
167
+ * `vagrant snapshot list`
168
+ * `vagrant snapshot pop`
165
169
  * `vagrant halt`
166
170
  * `vagrant provision`
167
171
 
168
172
 
169
- Known issues
170
- ------------
171
- * NFS using built-in Vagrant synced folders is not yet supported.
172
- * Multi machines may not provision one VM if the boxes are different.
173
- * I found this seems to be a problem with libvirt also, so I'm assuming it's a vagrant problem...
173
+ Known issues with vmware_esxi
174
+ -----------------------------
174
175
  * 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.
175
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.
177
+ * Built-in Vagrant synced folders using NFS fails if you try to re-provision.
178
+ * In general I find NFS synced folders pretty "flakey" anyways...
179
+ * Multi machines may not provision one VM if the boxes are different.
180
+ * I found this problem with libvirt also, so I'm assuming it's a vagrant problem...
@@ -0,0 +1,109 @@
1
+ Vagrant.configure("2") do |config|
2
+
3
+ # Box, Select any box created for VMware that is compatible with
4
+ # the ovftool. To get maximum compatiblity You should download
5
+ # and install the latest version for your OS.
6
+ # https://www.vmware.com/support/developer/ovf/
7
+ #
8
+ # If your box is stuck at "Powered On", then most likely
9
+ # the system didn't have the vmware tools installed.
10
+ #
11
+ # Here are some of the MANY examples....
12
+ config.vm.box = 'hashicorp/precise64'
13
+ #config.vm.box = 'steveant/CentOS-7.0-1406-Minimal-x64'
14
+ #config.vm.box = 'geerlingguy/ubuntu1604'
15
+ #config.vm.box = 'laravel/homestead'
16
+ #config.vm.box = 'centos/7'
17
+ #config.vm.box = 'bento/ubuntu-14.04'
18
+
19
+ # Supports type rsync and NFS.
20
+ config.vm.synced_folder('.', '/Vagrantfiles', type: 'rsync')
21
+
22
+ #
23
+ # Provider (esxi) settings
24
+ #
25
+ config.vm.provider :vmware_esxi do |esxi|
26
+
27
+ # REQUIRED! ESXi hostname/IP
28
+ # You MUST specify a esxi_hostname or IP, uless you
29
+ # were lucky enough to name your esxi host "esxi". :-)
30
+ esxi.esxi_hostname = "esxi"
31
+
32
+ # ESXi username
33
+ # Default is "root".
34
+ esxi.esxi_username = "root"
35
+
36
+ #
37
+ # A NOTE about esxi_password / ssh keys!!
38
+ #
39
+ # If you don't specify a password and do not use ssh
40
+ # keys, you will be entering your esxi password A LOT!
41
+ #
42
+ # From your command line, you should be able to run
43
+ # following command without an error and be able to get to
44
+ # the esxi command prompt.
45
+ #
46
+ # $ ssh root@ESXi_IP_ADDRESS
47
+
48
+ # IMPORTANT! ESXi password.
49
+ # The ssh connections to esxi will try your ssh
50
+ # keys first. However the ovftool does NOT! To make
51
+ # vagrant up fully password-less, you will need to
52
+ # enter your password here....
53
+ esxi.esxi_password = nil
54
+
55
+ # ESXi ssh keys
56
+ # The Default is to use system defaults, However
57
+ # you can specify an array of keys here...
58
+ #esxi.esxi_private_keys = []
59
+
60
+ # SSH port.
61
+ # Default port 22
62
+ #esxi.esxi_hostport = 22
63
+
64
+ # REQUIRED! Virtual Network
65
+ # You MUST specify a Virtual Network!
66
+ # The default is fail if no Virtual Network is set!
67
+ esxi.virtual_network = "vmnet_example"
68
+
69
+ # OPTIONAL. Specify a Disk Store
70
+ # The Default is to use the least used Disk Store.
71
+ #esxi.vm_disk_store = "DS_001"
72
+
73
+ # OPTIONAL. Guest VM name to be created/used.
74
+ # The Default will be automatically generated
75
+ # and will be based on the vmname_prefix,
76
+ # hostname, username, path...
77
+ #esxi.vmname = "Custom-Guest-VM_Name"
78
+
79
+ # OPTIONAL. When automatically naming VMs, use
80
+ # this prifix.
81
+ #esxi.vmname_prefix = "V-"
82
+
83
+ # OPTIONAL. Memory size override
84
+ # The default is to use the memory size specified in the
85
+ # vmx file, however you can specify a new value here.
86
+ #esxi.memsize = "2048"
87
+
88
+ # OPTIONAL. Virtual CPUs override
89
+ # The default is to use the number of virt cpus specified
90
+ # in the vmx file, however you can specify a new value here.
91
+ #esxi.numvcpus = "2"
92
+
93
+ # OPTIONAL. Resource Pool
94
+ # The default is to create VMs in the "root". You can
95
+ # specify a resource pool here to partition memory and
96
+ # cpu usage away from other systems on your esxi host.
97
+ # The resource pool must already exist and be configured.
98
+ # Vagrant will NOT create it for you.
99
+ #esxi.resource_pool = "/Vagrant"
100
+
101
+ # DANGEROUS! Allow Overwrite
102
+ # Set this to 'True' will overwrite existing VMs (with the same name)
103
+ # when you run vagrant up. ie, if the vmname already exists,
104
+ # it will be destroyed, then over written... This is helpful
105
+ # if you have a VM that became an orphan (vagrant lost association).
106
+ #esxi.allow_overwrite = 'True'
107
+
108
+ end
109
+ end
@@ -0,0 +1,36 @@
1
+ #
2
+ # This is a Vagrantfile multi machine example.
3
+ #
4
+
5
+ nodes = [
6
+ { hostname: 'VM-multi1', box: 'hashicorp/precise64' },
7
+ { hostname: 'VM-multi2', box: 'hashicorp/precise64' }
8
+ ]
9
+
10
+ Vagrant.configure("2") do |config|
11
+ nodes.each do |node|
12
+ config.vm.define node[:hostname] do |node_config|
13
+ node_config.vm.hostname = node[:hostname]
14
+ node_config.vm.box = node[:box]
15
+ node_config.vm.synced_folder('.', '/Vagrantfiles', type: 'rsync')
16
+ end
17
+ end
18
+
19
+ config.vm.provider :vmware_esxi do |esxi|
20
+ #
21
+ # Provider settings
22
+ #
23
+ esxi.esxi_hostname = "esxi"
24
+ esxi.esxi_username = "root"
25
+ esxi.esxi_password = nil
26
+ #esxi.esxi_private_keys = []
27
+ #esxi.esxi_hostport = 22
28
+ esxi.virtual_network = "vmnet_example"
29
+ #esxi.vm_disk_store = "DS_001"
30
+ #esxi.vmname_prefix = "V-"
31
+ #esxi.memsize = "2048"
32
+ #esxi.numvcpus = "2"
33
+ #esxi.resource_pool = "/Vagrant"
34
+ #esxi.allow_overwrite = 'True'
35
+ end
36
+ end
@@ -1,4 +1,4 @@
1
1
 
2
2
  {
3
- "provider": "vmware-esxi"
3
+ "provider": "vmware_esxi"
4
4
  }
@@ -11,6 +11,19 @@ module VagrantPlugins
11
11
  end
12
12
  end
13
13
 
14
+ def self.action_read_state
15
+ Vagrant::Action::Builder.new.tap do |b|
16
+ b.use ReadSSHInfo
17
+ b.use ReadState
18
+ end
19
+ end
20
+
21
+ def self.action_read_ssh_info
22
+ Vagrant::Action::Builder.new.tap do |b|
23
+ b.use ReadSSHInfo
24
+ end
25
+ end
26
+
14
27
  def self.action_halt
15
28
  Vagrant::Action::Builder.new.tap do |b|
16
29
  b.use ReadState
@@ -32,66 +45,97 @@ module VagrantPlugins
32
45
  end
33
46
  end
34
47
 
35
- def self.action_destroy
48
+ def self.action_ssh
36
49
  Vagrant::Action::Builder.new.tap do |b|
37
- b.use action_halt
38
50
  b.use ReadState
39
- b.use Destroy
51
+ b.use ReadSSHInfo
52
+ b.use SSHExec
53
+ b.use SSHRun
40
54
  end
41
55
  end
42
56
 
43
- def self.action_up
57
+ def self.action_snapshot_list
44
58
  Vagrant::Action::Builder.new.tap do |b|
45
- b.use ConfigValidate
46
- b.use ConnectESXi
47
- b.use HandleBox
48
- b.use ReadState
49
- b.use CreateVM
50
- b.use ReadState
51
- b.use Boot
52
- b.use Call, WaitForState, :running, 240 do |env1, b1|
59
+ b.use SnapshotList
60
+ end
61
+ end
62
+
63
+ def self.action_snapshot_info
64
+ Vagrant::Action::Builder.new.tap do |b|
65
+ b.use SnapshotInfo
66
+ end
67
+ end
68
+
69
+ def self.action_snapshot_save
70
+ Vagrant::Action::Builder.new.tap do |b|
71
+ b.use SnapshotSave
72
+ end
73
+ end
74
+
75
+ def self.action_snapshot_restore
76
+ Vagrant::Action::Builder.new.tap do |b|
77
+ b.use action_halt
78
+ b.use Call, WaitForState, :powered_off, 240 do |env1, b1|
53
79
  if env1[:result] == 'True'
54
- b1.use action_provision
80
+ b1.use SnapshotRestore
81
+ b1.use action_up
55
82
  end
56
83
  end
57
84
  end
58
85
  end
59
86
 
60
- def self.action_reload
87
+ def self.action_snapshot_delete
61
88
  Vagrant::Action::Builder.new.tap do |b|
62
- b.use Call, ReadState do |env1, b1|
63
- if env1[:machine_state].to_s == 'powered_on'
64
- b1.use action_halt
65
- end
66
- b1.use action_up
67
- end
89
+ b.use SnapshotDelete
68
90
  end
69
91
  end
70
92
 
71
- def self.action_read_state
93
+
94
+ def self.action_destroy
72
95
  Vagrant::Action::Builder.new.tap do |b|
73
- b.use ReadSSHInfo
74
- b.use ReadState
96
+ b.use Call, ReadState do |env1, b1|
97
+ unless env1[:machine_state] == 'powered_off'
98
+ b1.use action_halt
99
+ end
100
+ b1.use ReadState
101
+ b1.use Destroy
102
+ end
75
103
  end
76
104
  end
77
105
 
78
- def self.action_read_ssh_info
106
+ def self.action_reload
79
107
  Vagrant::Action::Builder.new.tap do |b|
80
- b.use ReadSSHInfo
108
+ b.use Call, ReadState do |env1, b1|
109
+ if (env1[:machine_state].to_s == 'powered_on') ||
110
+ (env1[:machine_state].to_s == 'running') ||
111
+ (env1[:machine_state].to_s == 'suspended')
112
+ b1.use action_halt
113
+ end
114
+ b1.use action_up
115
+ end
81
116
  end
82
117
  end
83
118
 
84
- def self.action_ssh
119
+ def self.action_up
85
120
  Vagrant::Action::Builder.new.tap do |b|
121
+ b.use ConfigValidate
122
+ b.use ConnectESXi
123
+ b.use HandleBox
86
124
  b.use ReadState
87
- b.use ReadSSHInfo
88
- b.use SSHExec
89
- b.use SSHRun
125
+ b.use CreateVM
126
+ b.use ReadState
127
+ b.use Boot
128
+ b.use Call, WaitForState, :running, 240 do |env1, b1|
129
+ if env1[:result] == 'True'
130
+ b1.use action_provision
131
+ end
132
+ end
90
133
  end
91
134
  end
92
135
 
93
136
  def self.action_provision
94
137
  Vagrant::Action::Builder.new.tap do |b|
138
+ b.use ReadState
95
139
  b.use Call, WaitForState, :running, 240 do |env1, b1|
96
140
  if env1[:result] == 'True'
97
141
  b1.use ReadState
@@ -113,6 +157,11 @@ module VagrantPlugins
113
157
  autoload :Destroy, action_root.join('destroy')
114
158
  autoload :Suspend, action_root.join('suspend')
115
159
  autoload :Resume, action_root.join('resume')
160
+ autoload :SnapshotInfo, action_root.join('snapshot_info')
161
+ autoload :SnapshotList, action_root.join('snapshot_list')
162
+ autoload :SnapshotSave, action_root.join('snapshot_save')
163
+ autoload :SnapshotDelete, action_root.join('snapshot_delete')
164
+ autoload :SnapshotRestore, action_root.join('snapshot_restore')
116
165
  autoload :WaitForState, action_root.join('wait_for_state')
117
166
  end
118
167
  end
@@ -33,12 +33,12 @@ module VagrantPlugins
33
33
 
34
34
  # Set guestvm_vmname
35
35
  if !env[:machine].config.vm.hostname.nil?
36
- # A hostname has been set, so use it. (multi node)
36
+ # A hostname has been set, so use it.
37
37
  guestvm_vmname = env[:machine].config.vm.hostname
38
38
  elsif config.vmname.nil?
39
39
  # Nothing set, so generate our own
40
- guestvm_vmname = config.vmname_prefix
41
- guestvm_vmname << `hostname`.strip
40
+ guestvm_vmname = config.vmname_prefix.strip
41
+ guestvm_vmname << `hostname`.partition('.').first.strip
42
42
  guestvm_vmname << '-'
43
43
  guestvm_vmname << `whoami`.gsub!(/[^0-9A-Za-z]/, '').strip
44
44
  guestvm_vmname << '-'
@@ -1,4 +1,5 @@
1
1
  require 'log4r'
2
+ require 'net/ssh/simple'
2
3
 
3
4
  module VagrantPlugins
4
5
  module ESXi
@@ -1,4 +1,6 @@
1
1
  require 'log4r'
2
+ require 'net/ssh/simple'
3
+ require 'socket'
2
4
 
3
5
  module VagrantPlugins
4
6
  module ESXi
@@ -13,6 +15,17 @@ module VagrantPlugins
13
15
 
14
16
  def call(env)
15
17
  env[:machine_state] = read_state(env)
18
+
19
+ # Do NFS stuff
20
+ if env[:machine_state].to_s.include? "running"
21
+ ssh_info = env[:machine].ssh_info
22
+ if defined?(ssh_info[:host])
23
+ env[:nfs_machine_ip] = [ssh_info[:host]]
24
+ env[:nfs_host_ip] = Socket::getaddrinfo(Socket.gethostname,"echo",Socket::AF_INET)[0][3]
25
+ env[:nfs_valid_ids] = [env[:machine].id]
26
+ end
27
+ end
28
+
16
29
  @app.call(env)
17
30
  end
18
31
 
@@ -23,6 +36,7 @@ module VagrantPlugins
23
36
  machine = env[:machine]
24
37
  config = env[:machine].provider_config
25
38
 
39
+
26
40
  return :not_created if machine.id.to_i < 1
27
41
 
28
42
  @logger.info("vagrant-vmware-esxi, read_state: machine id: #{machine.id}")
@@ -0,0 +1,63 @@
1
+ require 'log4r'
2
+ require 'net/ssh/simple'
3
+
4
+ module VagrantPlugins
5
+ module ESXi
6
+ module Action
7
+ # This action will delete the snapshot
8
+ class SnapshotDelete
9
+ def initialize(app, _env)
10
+ @app = app
11
+ @logger = Log4r::Logger.new('vagrant_vmware_esxi::action::snapshot_delete')
12
+ end
13
+
14
+ def call(env)
15
+ suspend(env)
16
+ @app.call(env)
17
+ end
18
+
19
+ def suspend(env)
20
+ @logger.info('vagrant-vmware-esxi, snapshot_delete: start...')
21
+
22
+ # Get config.
23
+ machine = env[:machine]
24
+ config = env[:machine].provider_config
25
+
26
+ @logger.info("vagrant-vmware-esxi, snapshot_delete: machine id: #{machine.id}")
27
+ @logger.info("vagrant-vmware-esxi, snapshot_delete: current state: #{env[:machine_state]}")
28
+
29
+ if env[:machine_state].to_s == 'not_created'
30
+ env[:ui].info I18n.t('vagrant_vmware_esxi.vagrant_vmware_esxi_message',
31
+ message: 'Cannot snapshot_delete in this state')
32
+ else
33
+ env[:ui].info I18n.t('vagrant_vmware_esxi.vagrant_vmware_esxi_message',
34
+ message: 'Attempting to snapshot_delete')
35
+
36
+ Net::SSH::Simple.sync(
37
+ user: config.esxi_username,
38
+ password: config.esxi_password,
39
+ port: config.esxi_hostport,
40
+ keys: config.esxi_private_keys,
41
+ timeout: 300
42
+ ) do
43
+
44
+ r = ssh config.esxi_hostname,
45
+ "vim-cmd vmsvc/snapshot.remove #{machine.id} "\
46
+ "`vim-cmd vmsvc/snapshot.get #{machine.id} | "\
47
+ "grep -A1 '.*Snapshot Name : #{env[:snapshot_name]}$' | "\
48
+ "grep 'Snapshot Id'|awk '{print $NF}'`"
49
+
50
+ if r.exit_code != 0
51
+ raise Errors::ESXiError,
52
+ message: "Unable to remove snapshots of the VM:\n"\
53
+ " #{r.stdout}\n#{r.stderr}"
54
+ end
55
+
56
+ env[:ui].info I18n.t('vagrant_vmware_esxi.snapshot_deleted')
57
+ end
58
+ end
59
+ end
60
+ end
61
+ end
62
+ end
63
+ end
@@ -0,0 +1,64 @@
1
+ require 'log4r'
2
+ require 'net/ssh/simple'
3
+
4
+ module VagrantPlugins
5
+ module ESXi
6
+ module Action
7
+ # This action will list all the snapshots
8
+ class SnapshotInfo
9
+ def initialize(app, _env)
10
+ @app = app
11
+ @logger = Log4r::Logger.new('vagrant_vmware_esxi::action::snapshot_info')
12
+ end
13
+
14
+ def call(env)
15
+ suspend(env)
16
+ @app.call(env)
17
+ end
18
+
19
+ def suspend(env)
20
+ @logger.info('vagrant-vmware-esxi, snapshot_info: start...')
21
+
22
+ # Get config.
23
+ machine = env[:machine]
24
+ config = env[:machine].provider_config
25
+
26
+ @logger.info("vagrant-vmware-esxi, snapshot_info: machine id: #{machine.id}")
27
+ @logger.info("vagrant-vmware-esxi, snapshot_info: current state: #{env[:machine_state]}")
28
+
29
+ if env[:machine_state].to_s == 'not_created'
30
+ env[:ui].info I18n.t('vagrant_vmware_esxi.vagrant_vmware_esxi_message',
31
+ message: 'Cannot snapshot_info in this state')
32
+ else
33
+
34
+ Net::SSH::Simple.sync(
35
+ user: config.esxi_username,
36
+ password: config.esxi_password,
37
+ port: config.esxi_hostport,
38
+ keys: config.esxi_private_keys,
39
+ ) do
40
+
41
+ r = ssh config.esxi_hostname,
42
+ "vim-cmd vmsvc/snapshot.get #{machine.id} 2>&1 | "\
43
+ "sed 's/Get Snapshot:/ /g' | "\
44
+ "grep -v "\
45
+ "-e 'Snapshot Id ' "\
46
+ "-e 'Snapshot Desciption ' "\
47
+ "-e 'Snapshot State '"
48
+
49
+ snapshotinfo = r.stdout
50
+ if r.exit_code != 0
51
+ raise Errors::ESXiError,
52
+ message: "Unable to list snapshots:\n"\
53
+ " #{allsnapshots}\n#{r.stderr}"
54
+ end
55
+
56
+ env[:ui].info I18n.t('vagrant_vmware_esxi.vagrant_vmware_esxi_message',
57
+ message: "#{snapshotinfo}")
58
+ end
59
+ end
60
+ end
61
+ end
62
+ end
63
+ end
64
+ end
@@ -0,0 +1,59 @@
1
+ require 'log4r'
2
+ require 'net/ssh/simple'
3
+
4
+ module VagrantPlugins
5
+ module ESXi
6
+ module Action
7
+ # This action will list all the snapshots
8
+ class SnapshotList
9
+ def initialize(app, _env)
10
+ @app = app
11
+ @logger = Log4r::Logger.new('vagrant_vmware_esxi::action::snapshot_list')
12
+ end
13
+
14
+ def call(env)
15
+ suspend(env)
16
+ @app.call(env)
17
+ end
18
+
19
+ def suspend(env)
20
+ @logger.info('vagrant-vmware-esxi, snapshot_list: start...')
21
+
22
+ # Get config.
23
+ machine = env[:machine]
24
+ config = env[:machine].provider_config
25
+
26
+ @logger.info("vagrant-vmware-esxi, snapshot_list: machine id: #{machine.id}")
27
+ @logger.info("vagrant-vmware-esxi, snapshot_list: current state: #{env[:machine_state]}")
28
+
29
+ if env[:machine_state].to_s == 'not_created'
30
+ env[:ui].info I18n.t('vagrant_vmware_esxi.vagrant_vmware_esxi_message',
31
+ message: 'Cannot snapshot_list in this state')
32
+ else
33
+
34
+ Net::SSH::Simple.sync(
35
+ user: config.esxi_username,
36
+ password: config.esxi_password,
37
+ port: config.esxi_hostport,
38
+ keys: config.esxi_private_keys,
39
+ ) do
40
+
41
+ r = ssh config.esxi_hostname,
42
+ "vim-cmd vmsvc/snapshot.get #{machine.id} 2>&1 | "\
43
+ "grep 'Snapshot Name'|sed 's/.*Snapshot Name : //g'"
44
+
45
+ allsnapshots = r.stdout
46
+ if r.exit_code != 0
47
+ raise Errors::ESXiError,
48
+ message: "Unable to list snapshots:\n"\
49
+ " #{allsnapshots}\n#{r.stderr}"
50
+ end
51
+
52
+ env[:machine_snapshot_list] = allsnapshots.split("\n")
53
+ end
54
+ end
55
+ end
56
+ end
57
+ end
58
+ end
59
+ end
@@ -0,0 +1,63 @@
1
+ require 'log4r'
2
+ require 'net/ssh/simple'
3
+
4
+ module VagrantPlugins
5
+ module ESXi
6
+ module Action
7
+ # This action will Restore (revert) the snapshot
8
+ class SnapshotRestore
9
+ def initialize(app, _env)
10
+ @app = app
11
+ @logger = Log4r::Logger.new('vagrant_vmware_esxi::action::snapshot_restore')
12
+ end
13
+
14
+ def call(env)
15
+ suspend(env)
16
+ @app.call(env)
17
+ end
18
+
19
+ def suspend(env)
20
+ @logger.info('vagrant-vmware-esxi, snapshot_restore: start...')
21
+
22
+ # Get config.
23
+ machine = env[:machine]
24
+ config = env[:machine].provider_config
25
+
26
+ @logger.info("vagrant-vmware-esxi, snapshot_restore: machine id: #{machine.id}")
27
+ @logger.info("vagrant-vmware-esxi, snapshot_restore: current state: #{env[:machine_state]}")
28
+
29
+ if env[:machine_state].to_s == 'not_created'
30
+ env[:ui].info I18n.t('vagrant_vmware_esxi.vagrant_vmware_esxi_message',
31
+ message: 'Cannot snapshot_restore in this state')
32
+ else
33
+ env[:ui].info I18n.t('vagrant_vmware_esxi.vagrant_vmware_esxi_message',
34
+ message: 'Attempting to snapshot_restore')
35
+
36
+ Net::SSH::Simple.sync(
37
+ user: config.esxi_username,
38
+ password: config.esxi_password,
39
+ port: config.esxi_hostport,
40
+ keys: config.esxi_private_keys,
41
+ timeout: 300
42
+ ) do
43
+
44
+ r = ssh config.esxi_hostname,
45
+ "vim-cmd vmsvc/snapshot.revert #{machine.id} "\
46
+ "`vim-cmd vmsvc/snapshot.get #{machine.id} | "\
47
+ "grep -A1 '.*Snapshot Name : #{env[:snapshot_name]}$' | "\
48
+ "grep 'Snapshot Id'|awk '{print $NF}'` suppressPowerOn"
49
+
50
+ if r.exit_code != 0
51
+ raise Errors::ESXiError,
52
+ message: "Unable to restore snapshots of the VM:\n"\
53
+ " #{r.stdout}\n#{r.stderr}"
54
+ end
55
+
56
+ env[:ui].info I18n.t('vagrant_vmware_esxi.snapshot_restored')
57
+ end
58
+ end
59
+ end
60
+ end
61
+ end
62
+ end
63
+ end
@@ -0,0 +1,61 @@
1
+ require 'log4r'
2
+ require 'net/ssh/simple'
3
+
4
+ module VagrantPlugins
5
+ module ESXi
6
+ module Action
7
+ # This action will save (create) a new snapshot
8
+ class SnapshotSave
9
+ def initialize(app, _env)
10
+ @app = app
11
+ @logger = Log4r::Logger.new('vagrant_vmware_esxi::action::snapshot_save')
12
+ end
13
+
14
+ def call(env)
15
+ suspend(env)
16
+ @app.call(env)
17
+ end
18
+
19
+ def suspend(env)
20
+ @logger.info('vagrant-vmware-esxi, snapshot_save: start...')
21
+
22
+ # Get config.
23
+ machine = env[:machine]
24
+ config = env[:machine].provider_config
25
+
26
+ @logger.info("vagrant-vmware-esxi, snapshot_save: machine id: #{machine.id}")
27
+ @logger.info("vagrant-vmware-esxi, snapshot_save: current state: #{env[:machine_state]}")
28
+
29
+ if env[:machine_state].to_s == 'not_created'
30
+ env[:ui].info I18n.t('vagrant_vmware_esxi.vagrant_vmware_esxi_message',
31
+ message: 'Cannot snapshot_save in this state')
32
+ else
33
+ env[:ui].info I18n.t('vagrant_vmware_esxi.vagrant_vmware_esxi_message',
34
+ message: 'Attempting to snapshot_save')
35
+
36
+ Net::SSH::Simple.sync(
37
+ user: config.esxi_username,
38
+ password: config.esxi_password,
39
+ port: config.esxi_hostport,
40
+ keys: config.esxi_private_keys,
41
+ timeout: 300
42
+ ) do
43
+
44
+ r = ssh config.esxi_hostname,
45
+ "vim-cmd vmsvc/snapshot.create #{machine.id} \"#{env[:snapshot_name]}\""
46
+
47
+ if r.exit_code != 0
48
+ raise Errors::ESXiError,
49
+ message: "Unable to save snapshots of the VM:\n"\
50
+ " #{r.stdout}\n#{r.stderr}"
51
+ end
52
+ env[:ui].info I18n.t('vagrant_vmware_esxi.support')
53
+
54
+ env[:ui].info I18n.t('vagrant_vmware_esxi.snapshot_saved')
55
+ end
56
+ end
57
+ end
58
+ end
59
+ end
60
+ end
61
+ end
@@ -1,5 +1,6 @@
1
1
  require 'log4r'
2
2
  require 'timeout'
3
+ require 'net/ssh/simple'
3
4
 
4
5
  module VagrantPlugins
5
6
  module ESXi
@@ -0,0 +1,16 @@
1
+
2
+ module VagrantPlugins
3
+ module ESXi
4
+ module Cap
5
+ module SnapshotList
6
+ # Returns a list of the snapshots that are taken on this machine.
7
+ #
8
+ # @return [Array<String>] Snapshot Name
9
+ def self.snapshot_list(machine)
10
+ env = machine.action(:snapshot_list, lock: false)
11
+ env[:machine_snapshot_list]
12
+ end
13
+ end
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,14 @@
1
+ module VagrantPlugins
2
+ module ESXi
3
+ class SnapshotInfo < Vagrant.plugin(2, :command)
4
+ def self.synopsis
5
+ "Snapshot additional information."
6
+ end
7
+ def execute
8
+ with_target_vms(nil, :provider => "vmware_esxi") do |vm|
9
+ vm.action(:snapshot_info)
10
+ end
11
+ end
12
+ end
13
+ end
14
+ end
@@ -18,10 +18,20 @@ module VagrantPlugins
18
18
  setup_logging
19
19
  setup_i18n
20
20
 
21
- require_relative 'provider'
21
+ require_relative 'provider'
22
22
  Provider
23
23
  end
24
24
 
25
+ provider_capability('vmware_esxi', 'snapshot_list') do
26
+ require_relative 'cap/snapshot_list'
27
+ Cap::SnapshotList
28
+ end
29
+
30
+ command('snapshot-info') do
31
+ require_relative "command"
32
+ SnapshotInfo
33
+ end
34
+
25
35
  # This initializes the internationalization strings.
26
36
  def self.setup_i18n
27
37
  require 'pathname'
@@ -21,7 +21,7 @@ module VagrantPlugins
21
21
  end
22
22
 
23
23
  def state
24
- @machine.action('connect_esxi')
24
+ #@machine.action('connect_esxi')
25
25
  env = @machine.action('read_state')
26
26
  state_id = env[:machine_state]
27
27
 
@@ -1,6 +1,6 @@
1
1
  # VERSION
2
2
  module VagrantPlugins
3
3
  module ESXi
4
- VERSION = '1.0.1'
4
+ VERSION = '1.1.2'
5
5
  end
6
6
  end
data/locales/en.yml CHANGED
@@ -32,6 +32,12 @@ en:
32
32
  The VM is already suspended.
33
33
  already_destroyed: |-
34
34
  The VM is destroyed.
35
+ snapshot_saved: |-
36
+ The snapshot has been saved.
37
+ snapshot_deleted: |-
38
+ The snapshot has been deleted.
39
+ snapshot_restored: |-
40
+ The snapshot has been restored.
35
41
  config:
36
42
  esxi_hostname_is_required: |-
37
43
  hostname is required
@@ -19,6 +19,7 @@ Gem::Specification.new do |s|
19
19
  s.add_runtime_dependency 'i18n', '~> 0.6'
20
20
  s.add_runtime_dependency 'log4r', '~> 1.1'
21
21
  s.add_runtime_dependency "iniparse", '> 1.0'
22
+ s.add_runtime_dependency "nokogiri", '> 1.5'
22
23
  s.add_runtime_dependency "net-ssh-simple", '> 1.5'
23
24
 
24
25
  s.add_development_dependency "bundler"
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.0.1
4
+ version: 1.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jonathan Senkerik
@@ -52,6 +52,20 @@ dependencies:
52
52
  - - ">"
53
53
  - !ruby/object:Gem::Version
54
54
  version: '1.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: nokogiri
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">"
60
+ - !ruby/object:Gem::Version
61
+ version: '1.5'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">"
67
+ - !ruby/object:Gem::Version
68
+ version: '1.5'
55
69
  - !ruby/object:Gem::Dependency
56
70
  name: net-ssh-simple
57
71
  requirement: !ruby/object:Gem::Requirement
@@ -104,6 +118,8 @@ files:
104
118
  - LICENSE
105
119
  - README.md
106
120
  - Rakefile
121
+ - example_box/Vagrantfile
122
+ - example_box/Vagrantfile-multimachine
107
123
  - example_box/metadata.json
108
124
  - lib/vagrant-vmware-esxi.rb
109
125
  - lib/vagrant-vmware-esxi/action.rb
@@ -115,8 +131,15 @@ files:
115
131
  - lib/vagrant-vmware-esxi/action/read_ssh_info.rb
116
132
  - lib/vagrant-vmware-esxi/action/read_state.rb
117
133
  - lib/vagrant-vmware-esxi/action/resume.rb
134
+ - lib/vagrant-vmware-esxi/action/snapshot_delete.rb
135
+ - lib/vagrant-vmware-esxi/action/snapshot_info.rb
136
+ - lib/vagrant-vmware-esxi/action/snapshot_list.rb
137
+ - lib/vagrant-vmware-esxi/action/snapshot_restore.rb
138
+ - lib/vagrant-vmware-esxi/action/snapshot_save.rb
118
139
  - lib/vagrant-vmware-esxi/action/suspend.rb
119
140
  - lib/vagrant-vmware-esxi/action/wait_for_state.rb
141
+ - lib/vagrant-vmware-esxi/cap/snapshot_list.rb
142
+ - lib/vagrant-vmware-esxi/command.rb
120
143
  - lib/vagrant-vmware-esxi/config.rb
121
144
  - lib/vagrant-vmware-esxi/errors.rb
122
145
  - lib/vagrant-vmware-esxi/plugin.rb
@@ -144,7 +167,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
144
167
  version: '0'
145
168
  requirements: []
146
169
  rubyforge_project:
147
- rubygems_version: 2.6.12
170
+ rubygems_version: 2.6.13
148
171
  signing_key:
149
172
  specification_version: 4
150
173
  summary: Vagrant ESXi provider plugin