vagrant-save 0.2.9 → 0.2.10
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +20 -20
- data/Gemfile +12 -11
- data/README.md +73 -73
- data/lib/vagrant-save/command.rb +109 -109
- data/lib/vagrant-save/uploader.rb +137 -130
- data/lib/vagrant-save/version.rb +10 -10
- data/vagrant-save.gemspec +1 -0
- metadata +17 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8d12fce680eb7b11dda3896b21a1cc5ba81dffac
|
4
|
+
data.tar.gz: 746385237c987123812fbd4bd4482e5f5bcc8939
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a28ab6622188fc8cdf8f96f042dbe29db3bfeafbef6e06e4932837650d50a8c397dc088ca85869365f5d8816b84a62192885d35cd980f1694d25a754400668bc
|
7
|
+
data.tar.gz: c088bdbb47eca3e0e42a27a45f0812195fdcba92fecb9d983c5308f184661c8ed9a028dd1053acdd4aa3ffcc5b11b92c6f785246438fae8086993efd01749e7a
|
data/.gitignore
CHANGED
@@ -1,20 +1,20 @@
|
|
1
|
-
/.bundle/
|
2
|
-
/.yardoc
|
3
|
-
/Gemfile.lock
|
4
|
-
/_yardoc/
|
5
|
-
/coverage/
|
6
|
-
/doc/
|
7
|
-
/pkg/
|
8
|
-
/spec/reports/
|
9
|
-
/tmp/
|
10
|
-
*.bundle
|
11
|
-
*.so
|
12
|
-
*.o
|
13
|
-
*.a
|
14
|
-
mkmf.log
|
15
|
-
Gemfile.lock
|
16
|
-
/.idea
|
17
|
-
/.vagrant
|
18
|
-
*.gem
|
19
|
-
*.box
|
20
|
-
Vagrantfile
|
1
|
+
/.bundle/
|
2
|
+
/.yardoc
|
3
|
+
/Gemfile.lock
|
4
|
+
/_yardoc/
|
5
|
+
/coverage/
|
6
|
+
/doc/
|
7
|
+
/pkg/
|
8
|
+
/spec/reports/
|
9
|
+
/tmp/
|
10
|
+
*.bundle
|
11
|
+
*.so
|
12
|
+
*.o
|
13
|
+
*.a
|
14
|
+
mkmf.log
|
15
|
+
Gemfile.lock
|
16
|
+
/.idea
|
17
|
+
/.vagrant
|
18
|
+
*.gem
|
19
|
+
*.box
|
20
|
+
Vagrantfile
|
data/Gemfile
CHANGED
@@ -1,11 +1,12 @@
|
|
1
|
-
source 'https://rubygems.org'
|
2
|
-
|
3
|
-
group :development do
|
4
|
-
gem 'vagrant', git: 'https://github.com/mitchellh/vagrant.git'
|
5
|
-
end
|
6
|
-
|
7
|
-
gem 'vagrant-export', '>= 0.3.4', git: 'https://github.com/trenker/vagrant-export.git'
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
1
|
+
source 'https://rubygems.org'
|
2
|
+
|
3
|
+
group :development do
|
4
|
+
gem 'vagrant', git: 'https://github.com/mitchellh/vagrant.git'
|
5
|
+
end
|
6
|
+
|
7
|
+
gem 'vagrant-export', '>= 0.3.4', git: 'https://github.com/trenker/vagrant-export.git'
|
8
|
+
gem 'net-http-uploadprogress', '>= 2.0.0'
|
9
|
+
|
10
|
+
group :plugins do
|
11
|
+
gem 'vagrant-save', path: '.'
|
12
|
+
end
|
data/README.md
CHANGED
@@ -1,73 +1,73 @@
|
|
1
|
-
# vagrant-save
|
2
|
-
|
3
|
-
This is a simple plugin to export boxes into .box files using [vagrant-export](https://github.com/trenker/vagrant-export) and pushes that file to a [boxserver](https://github.com/trenker/boxserver) instance.
|
4
|
-
|
5
|
-
## Installation
|
6
|
-
|
7
|
-
Like with any other vagrant plugin:
|
8
|
-
|
9
|
-
```bash
|
10
|
-
vagrant plugin install vagrant-save
|
11
|
-
```
|
12
|
-
|
13
|
-
## Usage
|
14
|
-
|
15
|
-
Have a [boxserver](https://github.com/trenker/boxserver) instance running and set the property `config.vm.box_server_url` to its address in your vagrant file. So your `Vagrantfile` contains the following statements:
|
16
|
-
|
17
|
-
```ruby
|
18
|
-
Vagrant.configure("2") do |config|
|
19
|
-
# This must be set
|
20
|
-
config.vm.box_server_url = "http://localhost:8001"
|
21
|
-
end
|
22
|
-
```
|
23
|
-
|
24
|
-
Then just run
|
25
|
-
|
26
|
-
```bash
|
27
|
-
vagrant save
|
28
|
-
```
|
29
|
-
|
30
|
-
to release a new version of your box.
|
31
|
-
|
32
|
-
By default, it increases the bugfix version number by one. So an installed 1.0.0 becomes 1.0.1. You can specify the version yourself using the parameter `-v|--version`, like this:
|
33
|
-
|
34
|
-
```bash
|
35
|
-
vagrant save -v 1.2.0
|
36
|
-
```
|
37
|
-
|
38
|
-
The parameter must always have all three digits and must be greater than the installed version.
|
39
|
-
|
40
|
-
You may want to clean up the boxserver by deleting old versions. The `-k|--keep` parameter sets how many versions to keep. The versions are sorted in descending order, older than the newest X will be deleted:
|
41
|
-
|
42
|
-
```bash
|
43
|
-
# Keeping the last six versions
|
44
|
-
vagrant save -k 6
|
45
|
-
|
46
|
-
# Keeping all versions
|
47
|
-
# Does not need to be written, as it is the default setting
|
48
|
-
vagrant save -k 0
|
49
|
-
```
|
50
|
-
|
51
|
-
## License
|
52
|
-
|
53
|
-
The MIT License (MIT)
|
54
|
-
|
55
|
-
Copyright (c) 2014 Georg Großberger
|
56
|
-
|
57
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
58
|
-
of this software and associated documentation files (the "Software"), to deal
|
59
|
-
in the Software without restriction, including without limitation the rights
|
60
|
-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
61
|
-
copies of the Software, and to permit persons to whom the Software is
|
62
|
-
furnished to do so, subject to the following conditions:
|
63
|
-
|
64
|
-
The above copyright notice and this permission notice shall be included in
|
65
|
-
all copies or substantial portions of the Software.
|
66
|
-
|
67
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
68
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
69
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
70
|
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
71
|
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
72
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
73
|
-
THE SOFTWARE.
|
1
|
+
# vagrant-save
|
2
|
+
|
3
|
+
This is a simple plugin to export boxes into .box files using [vagrant-export](https://github.com/trenker/vagrant-export) and pushes that file to a [boxserver](https://github.com/trenker/boxserver) instance.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Like with any other vagrant plugin:
|
8
|
+
|
9
|
+
```bash
|
10
|
+
vagrant plugin install vagrant-save
|
11
|
+
```
|
12
|
+
|
13
|
+
## Usage
|
14
|
+
|
15
|
+
Have a [boxserver](https://github.com/trenker/boxserver) instance running and set the property `config.vm.box_server_url` to its address in your vagrant file. So your `Vagrantfile` contains the following statements:
|
16
|
+
|
17
|
+
```ruby
|
18
|
+
Vagrant.configure("2") do |config|
|
19
|
+
# This must be set
|
20
|
+
config.vm.box_server_url = "http://localhost:8001"
|
21
|
+
end
|
22
|
+
```
|
23
|
+
|
24
|
+
Then just run
|
25
|
+
|
26
|
+
```bash
|
27
|
+
vagrant save
|
28
|
+
```
|
29
|
+
|
30
|
+
to release a new version of your box.
|
31
|
+
|
32
|
+
By default, it increases the bugfix version number by one. So an installed 1.0.0 becomes 1.0.1. You can specify the version yourself using the parameter `-v|--version`, like this:
|
33
|
+
|
34
|
+
```bash
|
35
|
+
vagrant save -v 1.2.0
|
36
|
+
```
|
37
|
+
|
38
|
+
The parameter must always have all three digits and must be greater than the installed version.
|
39
|
+
|
40
|
+
You may want to clean up the boxserver by deleting old versions. The `-k|--keep` parameter sets how many versions to keep. The versions are sorted in descending order, older than the newest X will be deleted:
|
41
|
+
|
42
|
+
```bash
|
43
|
+
# Keeping the last six versions
|
44
|
+
vagrant save -k 6
|
45
|
+
|
46
|
+
# Keeping all versions
|
47
|
+
# Does not need to be written, as it is the default setting
|
48
|
+
vagrant save -k 0
|
49
|
+
```
|
50
|
+
|
51
|
+
## License
|
52
|
+
|
53
|
+
The MIT License (MIT)
|
54
|
+
|
55
|
+
Copyright (c) 2014 Georg Großberger
|
56
|
+
|
57
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
58
|
+
of this software and associated documentation files (the "Software"), to deal
|
59
|
+
in the Software without restriction, including without limitation the rights
|
60
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
61
|
+
copies of the Software, and to permit persons to whom the Software is
|
62
|
+
furnished to do so, subject to the following conditions:
|
63
|
+
|
64
|
+
The above copyright notice and this permission notice shall be included in
|
65
|
+
all copies or substantial portions of the Software.
|
66
|
+
|
67
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
68
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
69
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
70
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
71
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
72
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
73
|
+
THE SOFTWARE.
|
data/lib/vagrant-save/command.rb
CHANGED
@@ -1,109 +1,109 @@
|
|
1
|
-
# #
|
2
|
-
# This is free software; you can redistribute it and/or modify it under #
|
3
|
-
# the terms of the MIT- / X11 - License #
|
4
|
-
# #
|
5
|
-
|
6
|
-
require_relative 'errors'
|
7
|
-
|
8
|
-
module VagrantPlugins
|
9
|
-
module Save
|
10
|
-
class Command < Vagrant.plugin('2', :command)
|
11
|
-
|
12
|
-
def self.synopsis
|
13
|
-
'exports a box file with additional actions taken'
|
14
|
-
end
|
15
|
-
|
16
|
-
def execute
|
17
|
-
options = {}
|
18
|
-
options[:version] = nil
|
19
|
-
options[:keep] = 0
|
20
|
-
|
21
|
-
opts = OptionParser.new do |o|
|
22
|
-
o.banner = 'Usage: vagrant save [-v|--version VERSION] [-k|--keep COUNT]'
|
23
|
-
o.separator ''
|
24
|
-
|
25
|
-
o.on('-v', '--version', 'Set the version of the uploaded box. Defaults to next bugfix version') do |v|
|
26
|
-
options[:version] = v.to_s
|
27
|
-
end
|
28
|
-
|
29
|
-
o.on('-k', '--keep', 'Number of versions to keep, older will be removed. Must be >= 1. Defaults to 0.') do |v|
|
30
|
-
options[:keep] = v.to_i
|
31
|
-
end
|
32
|
-
end
|
33
|
-
|
34
|
-
argv = parse_options(opts)
|
35
|
-
return 1 unless argv
|
36
|
-
|
37
|
-
target_version = options[:version]
|
38
|
-
|
39
|
-
unless target_version == nil
|
40
|
-
unless /^[0-9]+\.[0-9]+\.[0-9]+$/ =~ target_version
|
41
|
-
raise VagrantPlugins::Save::Errors::NoValidVersion
|
42
|
-
end
|
43
|
-
end
|
44
|
-
|
45
|
-
require 'vagrant-export/exporter'
|
46
|
-
require_relative 'uploader'
|
47
|
-
|
48
|
-
up = Uploader.new(@env, @logger)
|
49
|
-
|
50
|
-
with_target_vms argv, reverse: true do |machine|
|
51
|
-
|
52
|
-
if machine.state.short_description == 'not created'
|
53
|
-
raise MachineNotCreated
|
54
|
-
end
|
55
|
-
|
56
|
-
if target_version
|
57
|
-
version = target_version
|
58
|
-
|
59
|
-
if Gem::Version.new(machine.box.version.to_s) <= Gem::Version.new(version)
|
60
|
-
raise VagrantPlugins::Save::Errors::InvalidVersion
|
61
|
-
end
|
62
|
-
|
63
|
-
else
|
64
|
-
version_parts = machine.box.version.to_s
|
65
|
-
if /^[0-9]+\.[0-9]+\.[0-9]+$/ =~ version_parts
|
66
|
-
version_parts = version_parts.split('.')
|
67
|
-
version = version_parts[0] + '.' + version_parts[1] + '.' + (version_parts[2].to_i + 1).to_s
|
68
|
-
else
|
69
|
-
version = '1.0.0'
|
70
|
-
end
|
71
|
-
end
|
72
|
-
|
73
|
-
ex = VagrantPlugins::Export::Exporter.new(@env, @logger, machine)
|
74
|
-
file = ex.target_box
|
75
|
-
box_created = false
|
76
|
-
|
77
|
-
unless File.file?(file)
|
78
|
-
box_created = true
|
79
|
-
ex.handle(false, false)
|
80
|
-
end
|
81
|
-
|
82
|
-
provider_name = up.send(machine, file, version)
|
83
|
-
|
84
|
-
data = @env.machine_index.get(machine.index_uuid)
|
85
|
-
data.extra_data['box']['version'] = version
|
86
|
-
@env.machine_index.set(data)
|
87
|
-
@env.machine_index.release(data)
|
88
|
-
|
89
|
-
@env.boxes.add(
|
90
|
-
file,
|
91
|
-
machine.box.name,
|
92
|
-
version,
|
93
|
-
force: true,
|
94
|
-
metadata_url: up.make_url(machine),
|
95
|
-
providers: provider_name
|
96
|
-
)
|
97
|
-
|
98
|
-
FileUtils.remove(file) if box_created
|
99
|
-
|
100
|
-
if options[:keep] && options[:keep] > 1
|
101
|
-
up.clean(machine, options[:keep])
|
102
|
-
end
|
103
|
-
|
104
|
-
end
|
105
|
-
0
|
106
|
-
end
|
107
|
-
end
|
108
|
-
end
|
109
|
-
end
|
1
|
+
# #
|
2
|
+
# This is free software; you can redistribute it and/or modify it under #
|
3
|
+
# the terms of the MIT- / X11 - License #
|
4
|
+
# #
|
5
|
+
|
6
|
+
require_relative 'errors'
|
7
|
+
|
8
|
+
module VagrantPlugins
|
9
|
+
module Save
|
10
|
+
class Command < Vagrant.plugin('2', :command)
|
11
|
+
|
12
|
+
def self.synopsis
|
13
|
+
'exports a box file with additional actions taken'
|
14
|
+
end
|
15
|
+
|
16
|
+
def execute
|
17
|
+
options = {}
|
18
|
+
options[:version] = nil
|
19
|
+
options[:keep] = 0
|
20
|
+
|
21
|
+
opts = OptionParser.new do |o|
|
22
|
+
o.banner = 'Usage: vagrant save [-v|--version VERSION] [-k|--keep COUNT]'
|
23
|
+
o.separator ''
|
24
|
+
|
25
|
+
o.on('-v', '--version', 'Set the version of the uploaded box. Defaults to next bugfix version') do |v|
|
26
|
+
options[:version] = v.to_s
|
27
|
+
end
|
28
|
+
|
29
|
+
o.on('-k', '--keep', 'Number of versions to keep, older will be removed. Must be >= 1. Defaults to 0.') do |v|
|
30
|
+
options[:keep] = v.to_i
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
argv = parse_options(opts)
|
35
|
+
return 1 unless argv
|
36
|
+
|
37
|
+
target_version = options[:version]
|
38
|
+
|
39
|
+
unless target_version == nil
|
40
|
+
unless /^[0-9]+\.[0-9]+\.[0-9]+$/ =~ target_version
|
41
|
+
raise VagrantPlugins::Save::Errors::NoValidVersion
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
require 'vagrant-export/exporter'
|
46
|
+
require_relative 'uploader'
|
47
|
+
|
48
|
+
up = Uploader.new(@env, @logger)
|
49
|
+
|
50
|
+
with_target_vms argv, reverse: true do |machine|
|
51
|
+
|
52
|
+
if machine.state.short_description == 'not created'
|
53
|
+
raise VagrantPlugins::Save::Errors::MachineNotCreated
|
54
|
+
end
|
55
|
+
|
56
|
+
if target_version
|
57
|
+
version = target_version
|
58
|
+
|
59
|
+
if Gem::Version.new(machine.box.version.to_s) <= Gem::Version.new(version)
|
60
|
+
raise VagrantPlugins::Save::Errors::InvalidVersion
|
61
|
+
end
|
62
|
+
|
63
|
+
else
|
64
|
+
version_parts = machine.box.version.to_s
|
65
|
+
if /^[0-9]+\.[0-9]+\.[0-9]+$/ =~ version_parts
|
66
|
+
version_parts = version_parts.split('.')
|
67
|
+
version = version_parts[0] + '.' + version_parts[1] + '.' + (version_parts[2].to_i + 1).to_s
|
68
|
+
else
|
69
|
+
version = '1.0.0'
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
ex = VagrantPlugins::Export::Exporter.new(@env, @logger, machine)
|
74
|
+
file = ex.target_box
|
75
|
+
box_created = false
|
76
|
+
|
77
|
+
unless File.file?(file)
|
78
|
+
box_created = true
|
79
|
+
ex.handle(false, false)
|
80
|
+
end
|
81
|
+
|
82
|
+
provider_name = up.send(machine, file, version)
|
83
|
+
|
84
|
+
data = @env.machine_index.get(machine.index_uuid)
|
85
|
+
data.extra_data['box']['version'] = version
|
86
|
+
@env.machine_index.set(data)
|
87
|
+
@env.machine_index.release(data)
|
88
|
+
|
89
|
+
@env.boxes.add(
|
90
|
+
file,
|
91
|
+
machine.box.name,
|
92
|
+
version,
|
93
|
+
force: true,
|
94
|
+
metadata_url: up.make_url(machine),
|
95
|
+
providers: provider_name
|
96
|
+
)
|
97
|
+
|
98
|
+
FileUtils.remove(file) if box_created
|
99
|
+
|
100
|
+
if options[:keep] && options[:keep] > 1
|
101
|
+
up.clean(machine, options[:keep])
|
102
|
+
end
|
103
|
+
|
104
|
+
end
|
105
|
+
0
|
106
|
+
end
|
107
|
+
end
|
108
|
+
end
|
109
|
+
end
|
@@ -1,130 +1,137 @@
|
|
1
|
-
# #
|
2
|
-
# This is free software; you can redistribute it and/or modify it under #
|
3
|
-
# the terms of the MIT- / X11 - License #
|
4
|
-
# #
|
5
|
-
|
6
|
-
require 'httpclient'
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
# @param [
|
22
|
-
# @
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
client
|
43
|
-
|
44
|
-
client.
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
1
|
+
# #
|
2
|
+
# This is free software; you can redistribute it and/or modify it under #
|
3
|
+
# the terms of the MIT- / X11 - License #
|
4
|
+
# #
|
5
|
+
|
6
|
+
require 'httpclient'
|
7
|
+
require 'net/http/uploadprogress'
|
8
|
+
require 'uri'
|
9
|
+
|
10
|
+
module VagrantPlugins
|
11
|
+
module Save
|
12
|
+
class Uploader
|
13
|
+
|
14
|
+
# @param [Vagrant::Environment] env
|
15
|
+
# @param [Log4r::Logger] logger
|
16
|
+
def initialize(env, logger)
|
17
|
+
@env = env
|
18
|
+
@logger = logger
|
19
|
+
end
|
20
|
+
|
21
|
+
# @param [Vagrant::Machine] machine
|
22
|
+
# @param [string] file
|
23
|
+
# @param [string] version
|
24
|
+
# @return int
|
25
|
+
def send(machine, file, version)
|
26
|
+
|
27
|
+
machine.ui.info('Uploading now')
|
28
|
+
|
29
|
+
@logger.debug("Preparing to send file #{file}")
|
30
|
+
|
31
|
+
provider = machine.provider_name.to_s
|
32
|
+
|
33
|
+
if provider =~ /vmware/
|
34
|
+
provider = 'vmware_desktop'
|
35
|
+
end
|
36
|
+
|
37
|
+
ping_url = make_url(machine)
|
38
|
+
post_url = ping_url + '/' + version + '/' + provider
|
39
|
+
|
40
|
+
@logger.debug("Pinging #{ping_url}")
|
41
|
+
|
42
|
+
client = HTTPClient.new
|
43
|
+
|
44
|
+
client.connect_timeout = 10000
|
45
|
+
client.send_timeout = 10000
|
46
|
+
client.receive_timeout = 10000
|
47
|
+
|
48
|
+
res = client.options(ping_url)
|
49
|
+
|
50
|
+
raise VagrantPlugins::Save::Errors::CannotContactBoxServer unless res.http_header.status_code == 200
|
51
|
+
|
52
|
+
@logger.debug("Sending file to #{post_url}")
|
53
|
+
|
54
|
+
@env.ui.info('Uploading', new_line: false)
|
55
|
+
|
56
|
+
File.open(file) do |f|
|
57
|
+
|
58
|
+
uri = URI.parse(post_url)
|
59
|
+
full_size = f.size
|
60
|
+
|
61
|
+
http = Net::HTTP.new(uri.host, uri.port)
|
62
|
+
http.open_timeout = 10000
|
63
|
+
http.read_timeout = 10000
|
64
|
+
|
65
|
+
req = Net::HTTP::Post.new(uri.path)
|
66
|
+
req.set_form({"box" => f}, 'multipart/form-data')
|
67
|
+
|
68
|
+
previous_percent = ""
|
69
|
+
|
70
|
+
Net::HTTP::UploadProgress.new(req) do |progress|
|
71
|
+
frac = progress.upload_size.to_f / full_size.to_f
|
72
|
+
percent = (frac * 100).round.to_s + "%"
|
73
|
+
|
74
|
+
if percent != previous_percent
|
75
|
+
previous_percent = percent
|
76
|
+
@env.ui.clear_line
|
77
|
+
@env.ui.info(percent, new_line: false)
|
78
|
+
end
|
79
|
+
end
|
80
|
+
res = http.request(req)
|
81
|
+
end
|
82
|
+
|
83
|
+
@env.ui.clear_line
|
84
|
+
|
85
|
+
raise VagrantPlugins::Save::Errors::UploadFailed unless res.code == '200'
|
86
|
+
|
87
|
+
machine.ui.info('Upload successful')
|
88
|
+
|
89
|
+
provider
|
90
|
+
end
|
91
|
+
|
92
|
+
# @param [Vagrant::Machine] machine
|
93
|
+
# @param [int] keep
|
94
|
+
# @return int
|
95
|
+
def clean(machine, keep)
|
96
|
+
machine.ui.info('Cleaning up old versions')
|
97
|
+
|
98
|
+
data_url = make_url(machine)
|
99
|
+
|
100
|
+
@logger.debug("Load versions from #{data_url}")
|
101
|
+
|
102
|
+
res = client.get(data_url)
|
103
|
+
data = JSON.parse(res.http_body)
|
104
|
+
|
105
|
+
client = HTTPClient.new
|
106
|
+
saved_versions = data['versions'].map{ |v| v.version}
|
107
|
+
|
108
|
+
@logger.debug("Received #{saved_versions.length} versions")
|
109
|
+
|
110
|
+
if saved_versions.length > keep
|
111
|
+
saved_versions = saved_versions.sort.reverse
|
112
|
+
saved_versions.slice(keep, saved_versions.length).each { |v|
|
113
|
+
delete_url = data_url + '/' + v
|
114
|
+
|
115
|
+
@logger.debug("Sending delete #{delete_url}")
|
116
|
+
|
117
|
+
client.delete(delete_url)
|
118
|
+
}
|
119
|
+
end
|
120
|
+
|
121
|
+
0
|
122
|
+
end
|
123
|
+
|
124
|
+
# @param [Vagrant::Machine] machine
|
125
|
+
# @return string
|
126
|
+
def make_url(machine)
|
127
|
+
name = machine.box.name.gsub(/_+/, '/')
|
128
|
+
base_url = Vagrant.server_url(machine.config.vm.box_server_url).to_s
|
129
|
+
|
130
|
+
raise Vagrant::Errors::BoxServerNotSet unless base_url
|
131
|
+
|
132
|
+
base_url + '/' + name
|
133
|
+
end
|
134
|
+
|
135
|
+
end
|
136
|
+
end
|
137
|
+
end
|
data/lib/vagrant-save/version.rb
CHANGED
@@ -1,10 +1,10 @@
|
|
1
|
-
# #
|
2
|
-
# This is free software; you can redistribute it and/or modify it under #
|
3
|
-
# the terms of the MIT- / X11 - License #
|
4
|
-
# #
|
5
|
-
|
6
|
-
module VagrantPlugins
|
7
|
-
module Save
|
8
|
-
VERSION = '0.2.
|
9
|
-
end
|
10
|
-
end
|
1
|
+
# #
|
2
|
+
# This is free software; you can redistribute it and/or modify it under #
|
3
|
+
# the terms of the MIT- / X11 - License #
|
4
|
+
# #
|
5
|
+
|
6
|
+
module VagrantPlugins
|
7
|
+
module Save
|
8
|
+
VERSION = '0.2.10'
|
9
|
+
end
|
10
|
+
end
|
data/vagrant-save.gemspec
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: vagrant-save
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.10
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Georg Grossberger
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-07-28 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: vagrant-export
|
@@ -24,6 +24,20 @@ dependencies:
|
|
24
24
|
- - ">="
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: 0.3.4
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: net-http-uploadprogress
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 2.0.0
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: 2.0.0
|
27
41
|
description: Export boxes to a boxserver on a remote machine using HTTP/PUT
|
28
42
|
email: contact@grossberger-ge.org
|
29
43
|
executables: []
|
@@ -60,7 +74,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
60
74
|
version: '0'
|
61
75
|
requirements: []
|
62
76
|
rubyforge_project:
|
63
|
-
rubygems_version: 2.
|
77
|
+
rubygems_version: 2.4.6
|
64
78
|
signing_key:
|
65
79
|
specification_version: 4
|
66
80
|
summary: Export boxes to a boxserver
|