vagrant-skytap 0.3.1 → 0.3.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: dae76ca9f326fc61d315aed14516cb4d62a03276
4
- data.tar.gz: c26500f1f04d28b9325f3487369ea89106788437
3
+ metadata.gz: 3ad66d0732292fb4e3eade24cdcc614b00b18869
4
+ data.tar.gz: 193d5678f30a527277f1bd04816c41d6857a2e2f
5
5
  SHA512:
6
- metadata.gz: 1fc8c6e878f55c34c81e6475ad67dbd3a3c759c28eeb9ca678b1db2e8599061d79263787837fdc9217c2eff6bf738c2dd5d26d8c03a6b0c0d7ff3555110030ae
7
- data.tar.gz: afa804091a15ffda3cf6478ef6def6d5527fb958dc7daf908109265f347f4c707792aa9a2cea147e046d3630cb3cfe7a537d2f7f27d8bd846ddaa7f7beb15459
6
+ metadata.gz: 27195d6fe141492a6979a4995ea2ba7aa20f0245a4e3409786f9bb65a58b3e1620cf9ef085221a2d00d13af7bf327d1f65bcdda13e831a15440adf45e07b39d2
7
+ data.tar.gz: d05d051aaf236112118c65d4ffeef8193ce29ec2fc2e2508622a0f8014ded4718d4be620abb5bf1224a01b2ae2f71641866bec76ecb72544b4c73a1aaa436b70
data/CHANGELOG.md CHANGED
@@ -1,6 +1,11 @@
1
+ # 0.3.2 (April 19, 2016)
2
+
3
+ * Retry all operations on 423 response (previously this was not happening when attaching to a VPN).
4
+
1
5
  # 0.3.1 (April 15, 2016)
2
6
 
3
7
  * Add support for running in a Skytap VM when the VM's network is using a custom DNS.
8
+ * Clean up SSH tunnels on `vagrant destroy` (port forwarding bug).
4
9
 
5
10
  # 0.3.0 (April 13, 2016)
6
11
 
@@ -97,6 +97,7 @@ module VagrantPlugins
97
97
  end
98
98
  b1.use Call, DestroyConfirm do |env2, b2|
99
99
  if env2[:result]
100
+ b2.use ClearForwardedPorts
100
101
  case existence_state
101
102
  when :one_of_many_vms
102
103
  b2.use DeleteVm
@@ -109,7 +110,6 @@ module VagrantPlugins
109
110
  end
110
111
  end
111
112
  end
112
- b.use ClearForwardedPorts
113
113
  b.use PrepareNFSValidIds
114
114
  b.use SyncedFolderCleanup
115
115
  end
@@ -42,7 +42,7 @@ module VagrantPlugins
42
42
  if nic = vm.interfaces.first
43
43
  if hostname != nic.get_api_attribute('hostname')
44
44
  @logger.info("Updating hostname: #{hostname}")
45
- nic.update_with_retry(hostname: hostname)
45
+ nic.update(hostname: hostname)
46
46
  end
47
47
  end
48
48
  end
@@ -50,7 +50,7 @@ module VagrantPlugins
50
50
 
51
51
  if hardware_info.present?
52
52
  @logger.info("Updating hardware properties: #{hardware_info}")
53
- vm.update_with_retry(hardware: hardware_info)
53
+ vm.update(hardware: hardware_info)
54
54
  end
55
55
  end
56
56
 
@@ -22,6 +22,7 @@
22
22
 
23
23
  require 'base64'
24
24
  require "vagrant-skytap/version"
25
+ require 'timeout'
25
26
 
26
27
  module VagrantPlugins
27
28
  module Skytap
@@ -29,8 +30,9 @@ module VagrantPlugins
29
30
  class Client
30
31
  attr_reader :config, :http
31
32
 
33
+ DEFAULT_TIMEOUT = 120
32
34
  MAX_RATE_LIMIT_RETRIES = 3
33
- DEFAULT_RETRY_AFTER_SECONDS = 10
35
+ DEFAULT_RETRY_AFTER_SECONDS = 5
34
36
 
35
37
  def initialize(config)
36
38
  @logger = Log4r::Logger.new("vagrant_skytap::api_client")
@@ -83,35 +85,47 @@ module VagrantPlugins
83
85
  end
84
86
 
85
87
  headers = default_headers.merge(options[:extra_headers] || {})
86
- tries = 0
87
88
  retry_after = DEFAULT_RETRY_AFTER_SECONDS
89
+ most_recent_exception = nil
90
+
88
91
  begin
89
- tries += 1
90
- http.send_request(method, URI.encode(path), body, headers).tap do |ret|
91
- @logger.debug("REST API response: #{ret.body}")
92
- unless ret.code =~ /^2\d\d/
93
- raise Errors::DoesNotExist, object_name: "Object '#{path}'" if ret.code == '404'
94
- error_class = case ret.code
95
- when '403'
96
- Errors::Unauthorized
97
- when '422'
98
- Errors::UnprocessableEntity
99
- when '423'
100
- Errors::ResourceBusy
101
- when '429'
102
- retry_after = ret['Retry-After'] || DEFAULT_RETRY_AFTER_SECONDS
103
- Errors::RateLimited
104
- else
105
- Errors::OperationFailed
92
+ Timeout.timeout(options[:timeout] || DEFAULT_TIMEOUT) do
93
+ begin
94
+ http.send_request(method, URI.encode(path), body, headers).tap do |ret|
95
+ @logger.debug("REST API response: #{ret.body}")
96
+ unless ret.code =~ /^2\d\d/
97
+ raise Errors::DoesNotExist, object_name: "Object '#{path}'" if ret.code == '404'
98
+ error_class = case ret.code
99
+ when '403'
100
+ Errors::Unauthorized
101
+ when '422'
102
+ Errors::UnprocessableEntity
103
+ when '423'
104
+ Errors::ResourceBusy
105
+ when '429'
106
+ retry_after = ret['Retry-After'] || DEFAULT_RETRY_AFTER_SECONDS
107
+ Errors::RateLimited
108
+ else
109
+ Errors::OperationFailed
110
+ end
111
+ raise error_class, err: error_string_from_body(ret)
112
+ end
106
113
  end
107
- raise error_class, err: error_string_from_body(ret)
114
+ rescue Errors::RateLimited => ex
115
+ most_recent_exception = ex
116
+ @logger.info("Rate limited, wil retry in #{retry_after} seconds")
117
+ sleep retry_after.to_f + 0.1
118
+ retry
119
+ rescue Errors::ResourceBusy => ex
120
+ most_recent_exception = ex
121
+ @logger.debug("Resource busy, retrying")
122
+ sleep DEFAULT_RETRY_AFTER_SECONDS
123
+ retry
108
124
  end
109
125
  end
110
- rescue Errors::RateLimited => ex
111
- raise if tries > MAX_RATE_LIMIT_RETRIES
112
- @logger.info("Rate limited, wil retry in #{retry_after} seconds")
113
- sleep retry_after.to_f + 0.1
114
- retry
126
+ rescue Timeout::Error => ex
127
+ raise most_recent_exception if most_recent_exception
128
+ raise Errors::OperationFailed, "Timeout exceeded"
115
129
  end
116
130
  end
117
131
 
@@ -144,13 +144,6 @@ module VagrantPlugins
144
144
  set_runstate :running, vm_ids: vm_ids
145
145
  end
146
146
 
147
- def delete
148
- retry_while_resource_busy do
149
- api_client.delete(url)
150
- break
151
- end
152
- end
153
-
154
147
  # Makes the REST call to add VMs to this environment, using
155
148
  # the provided VMs as sources.
156
149
  #
@@ -169,7 +162,7 @@ module VagrantPlugins
169
162
  end
170
163
 
171
164
  existing_vm_ids = self.vms.collect(&:id)
172
- update_with_retry(args)
165
+ update(args)
173
166
  get_vms_by_id(self.vms.collect(&:id) - existing_vm_ids)
174
167
  end
175
168
 
@@ -23,14 +23,11 @@
23
23
  require 'vagrant-skytap/api/resource'
24
24
  require 'vagrant-skytap/api/public_ip'
25
25
  require 'vagrant-skytap/api/published_service'
26
- require_relative 'busyable'
27
26
 
28
27
  module VagrantPlugins
29
28
  module Skytap
30
29
  module API
31
30
  class Interface < Resource
32
- include Busyable
33
-
34
31
  attr_reader :vm
35
32
 
36
33
  reads :id, :ip, :nat_addresses, :network_id, :public_ips, :services
@@ -52,10 +52,6 @@ module VagrantPlugins
52
52
  def vms
53
53
  environment.get_vms_by_id(vm_ids)
54
54
  end
55
-
56
- def delete
57
- api_client.delete(url)
58
- end
59
55
  end
60
56
  end
61
57
  end
@@ -33,12 +33,19 @@ module VagrantPlugins
33
33
  attr_reader :attrs, :env
34
34
 
35
35
  class << self
36
+ # Last segment of the class name (without the namespace).
37
+ #
38
+ # @return [String]
39
+ def short_name
40
+ name.split("::").last
41
+ end
42
+
36
43
  # Resource name suitable for use in URLs. This should be overridden
37
44
  # for classes with camel-cased names (e.g., VpnAttachment).
38
45
  #
39
46
  # @return [String]
40
47
  def rest_name
41
- name.split("::").last.downcase
48
+ short_name.downcase
42
49
  end
43
50
  end
44
51
 
@@ -73,6 +80,25 @@ module VagrantPlugins
73
80
  self
74
81
  end
75
82
 
83
+ # Sets attributes on the Skytap model, then refreshes this resource
84
+ # from the response.
85
+ #
86
+ # @param [Hash] attrs The attributes to update on the resource.
87
+ # @param [String] path The path to this resource, if different from
88
+ # the default.
89
+ # @return [API::Resource]
90
+ def update(attrs, path=nil)
91
+ resp = api_client.put(path || url, JSON.dump(attrs))
92
+ refresh(JSON.load(resp.body))
93
+ end
94
+
95
+ # Remove this resource from Skytap.
96
+ #
97
+ # @return [NilClass]
98
+ def delete
99
+ api_client.delete(url)
100
+ end
101
+
76
102
  private
77
103
 
78
104
  # Return a reference to the API client which was passed in when
@@ -21,13 +21,12 @@
21
21
  # DEALINGS IN THE SOFTWARE.
22
22
 
23
23
  require 'timeout'
24
- require_relative 'busyable'
25
24
 
26
25
  module VagrantPlugins
27
26
  module Skytap
28
27
  module API
29
28
  module RunstateOperations
30
- include Busyable
29
+ RUNSTATE_RETRY = 5
31
30
 
32
31
  def run!
33
32
  set_runstate :running
@@ -51,7 +50,7 @@ module VagrantPlugins
51
50
  params = {runstate: new_runstate}.tap do |ret|
52
51
  ret[:multiselect] = opts[:vm_ids] if opts[:vm_ids]
53
52
  end
54
- update_with_retry(params)
53
+ update(params)
55
54
 
56
55
  wait_for_runstate(completed_runstate) unless runstate == completed_runstate
57
56
  end
@@ -62,10 +61,17 @@ module VagrantPlugins
62
61
 
63
62
  def wait_for_runstate(expected_runstate)
64
63
  expected_runstate = expected_runstate.to_s
65
- retry_while_resource_busy do
66
- unless reload.busy?
67
- break if runstate == expected_runstate || expected_runstate == 'ready'
64
+ begin
65
+ Timeout.timeout(provider_config.instance_ready_timeout) do
66
+ loop do
67
+ unless reload.busy?
68
+ break if runstate == expected_runstate || expected_runstate == 'ready'
69
+ end
70
+ sleep RUNSTATE_RETRY
71
+ end
68
72
  end
73
+ rescue Timeout::Error => ex
74
+ raise Errors::InstanceReadyTimeout, timeout: provider_config.instance_ready_timeout
69
75
  end
70
76
  end
71
77
 
@@ -105,17 +105,6 @@ module VagrantPlugins
105
105
  def region
106
106
  @region ||= parent.region
107
107
  end
108
-
109
- def delete
110
- begin
111
- retry_while_resource_busy do
112
- api_client.delete(url)
113
- break
114
- end
115
- rescue Errors::OperationFailed => ex
116
- raise Errors::OperationFailed, err: 'Failed to delete VM'
117
- end
118
- end
119
108
  end
120
109
  end
121
110
  end
@@ -21,14 +21,11 @@
21
21
  # DEALINGS IN THE SOFTWARE.
22
22
 
23
23
  require 'vagrant-skytap/api/resource'
24
- require_relative 'busyable'
25
24
 
26
25
  module VagrantPlugins
27
26
  module Skytap
28
27
  module API
29
28
  class VpnAttachment < Resource
30
- include Busyable
31
-
32
29
  attr_reader :network
33
30
 
34
31
  reads :connected, :network, :vpn
@@ -65,7 +62,7 @@ module VagrantPlugins
65
62
  end
66
63
 
67
64
  def connect!
68
- update_with_retry(connected: true)
65
+ update(connected: true)
69
66
  raise Errors::VpnConnectionFailed unless connected?
70
67
  end
71
68
 
@@ -22,6 +22,6 @@
22
22
 
23
23
  module VagrantPlugins
24
24
  module Skytap
25
- VERSION = "0.3.1"
25
+ VERSION = "0.3.2"
26
26
  end
27
27
  end
@@ -39,7 +39,7 @@ describe VagrantPlugins::Skytap::Action::UpdateHardware do
39
39
  describe "#call" do
40
40
  it "filters out unchanged hardware properties" do
41
41
  allow(subject).to receive(:current_vm).and_return(vm)
42
- expect(vm).to receive(:update_with_retry).with(hardware: {cpus: 4, cpus_per_socket: 2, guestOS: "linux"})
42
+ expect(vm).to receive(:update).with(hardware: {cpus: 4, cpus_per_socket: 2, guestOS: "linux"})
43
43
  subject.call(env)
44
44
  end
45
45
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: vagrant-skytap
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.1
4
+ version: 0.3.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Eric True
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2016-04-15 00:00:00.000000000 Z
12
+ date: 2016-04-20 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: json_pure
@@ -167,7 +167,6 @@ files:
167
167
  - lib/vagrant-skytap/action/update_hardware.rb
168
168
  - lib/vagrant-skytap/action/wait_for_communicator.rb
169
169
  - lib/vagrant-skytap/action.rb
170
- - lib/vagrant-skytap/api/busyable.rb
171
170
  - lib/vagrant-skytap/api/client.rb
172
171
  - lib/vagrant-skytap/api/connectable.rb
173
172
  - lib/vagrant-skytap/api/credentials.rb
@@ -1,59 +0,0 @@
1
- # Copyright (c) 2014-2016 Skytap, Inc.
2
- #
3
- # The MIT License (MIT)
4
- #
5
- # Permission is hereby granted, free of charge, to any person obtaining a copy
6
- # of this software and associated documentation files (the "Software"), to deal
7
- # in the Software without restriction, including without limitation the rights
8
- # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- # copies of the Software, and to permit persons to whom the Software is
10
- # furnished to do so, subject to the following conditions:
11
- #
12
- # The above copyright notice and this permission notice shall be included in
13
- # all copies or substantial portions of the Software.
14
- #
15
- # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20
- # FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
21
- # DEALINGS IN THE SOFTWARE.
22
-
23
- require 'timeout'
24
-
25
- module VagrantPlugins
26
- module Skytap
27
- module API
28
- module Busyable
29
- WAIT_TIMEOUT = 300
30
- WAIT_ITERATION_PERIOD = 2
31
-
32
- def update_with_retry(attrs, path=nil)
33
- retry_while_resource_busy do
34
- resp = api_client.put(path || url, JSON.dump(attrs))
35
- refresh(JSON.load(resp.body))
36
- break
37
- end
38
- end
39
-
40
- def retry_while_resource_busy(timeout=WAIT_TIMEOUT, &block)
41
- begin
42
- Timeout.timeout(timeout) do
43
- loop do
44
- break if env[:interrupted]
45
- begin
46
- yield
47
- rescue Errors::ResourceBusy
48
- end
49
- sleep WAIT_ITERATION_PERIOD
50
- end
51
- end
52
- rescue Timeout::Error => ex
53
- raise Errors::InstanceReadyTimeout, timeout: timeout
54
- end
55
- end
56
- end
57
- end
58
- end
59
- end