vagrant-smartos-zones 0.1.0 → 0.2.0
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.
- checksums.yaml +4 -4
- data/README.md +51 -13
- data/examples/Vagrantfile.lx +3 -4
- data/lib/vagrant/smartos/locales/en.yml +11 -0
- data/lib/vagrant/smartos/zones/cap/dataset/list.rb +17 -0
- data/lib/vagrant/smartos/zones/cap/imgadm_import.rb +37 -6
- data/lib/vagrant/smartos/zones/commands/dataset.rb +2 -1
- data/lib/vagrant/smartos/zones/communicator/smartos.rb +46 -0
- data/lib/vagrant/smartos/zones/models/dataset.rb +80 -2
- data/lib/vagrant/smartos/zones/plugin.rb +5 -0
- data/lib/vagrant/smartos/zones/util/datasets/manifest.rb +95 -0
- data/lib/vagrant/smartos/zones/util/datasets.rb +56 -0
- data/lib/vagrant/smartos/zones/util/rsync.rb +51 -0
- data/lib/vagrant/smartos/zones/util/zone_group.rb +7 -2
- data/lib/vagrant/smartos/zones/util/zone_image.rb +43 -0
- data/lib/vagrant/smartos/zones/util/zone_json.rb +10 -1
- data/lib/vagrant/smartos/zones/util/zone_project.rb +5 -0
- data/lib/vagrant/smartos/zones/util/zone_user.rb +7 -2
- data/lib/vagrant/smartos/zones/util/zones.rb +4 -4
- data/lib/vagrant/smartos/zones/version.rb +1 -1
- metadata +8 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b23f15194df8189c39b2ed6a4d757e9948497185
|
4
|
+
data.tar.gz: 0fb7e83e3bb27d84cf743ce303ef2a9401f864e6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 19c63f89d059f8aca3098414f774e86e3eb83d1fc7986cf63e22b6e11117817696a6138e3091a09dd6b27c95b78e69f17f394bafe2293b80139b711e1d302ed9
|
7
|
+
data.tar.gz: 54489755d0f804f002127bfeccf1b971b13c9d993746b8d348b87d3ba5630a43eaa71215e852498685e5b784d899f615958b00bdfba72a24fba7f07372d8466d
|
data/README.md
CHANGED
@@ -114,6 +114,14 @@ vagrant zones start [name]
|
|
114
114
|
vagrant zones stop [name]
|
115
115
|
```
|
116
116
|
|
117
|
+
Export a running zone as a dataset (image) in the local file system:
|
118
|
+
|
119
|
+
```bash
|
120
|
+
vagrant dataset create [zone] [identifier]
|
121
|
+
vagrant dataset delete [identifier]
|
122
|
+
vagrant dataset list
|
123
|
+
```
|
124
|
+
|
117
125
|
## Single zone usage
|
118
126
|
|
119
127
|
When a single zone is configured (currently the only configuration
|
@@ -232,19 +240,6 @@ group with which to connect. This user should have `Primary
|
|
232
240
|
Administrator` privileges. When creating a local zone, a `vagrant`
|
233
241
|
user and group are also created in the zone.
|
234
242
|
|
235
|
-
## Tests
|
236
|
-
|
237
|
-
There is a basic test suite that uses `test-kitchen` to converge
|
238
|
-
different brands of zones. Although it might not be comprehensive, it
|
239
|
-
should be ran after new features or after any significant refactoring to
|
240
|
-
ensure that nothing breaks the ability to stand up a zone.
|
241
|
-
|
242
|
-
```bash
|
243
|
-
bundle exec kitchen test
|
244
|
-
```
|
245
|
-
|
246
|
-
This may take a while...
|
247
|
-
|
248
243
|
## Plugin configuration
|
249
244
|
|
250
245
|
The plugin allows for local configuration through the `vagrant zones
|
@@ -264,6 +259,9 @@ networks. For this reason, the network chosen by the plugin when
|
|
264
259
|
configuring the Global Zone and its local zone can be globally
|
265
260
|
overridden.
|
266
261
|
|
262
|
+
Since this is a facet of your current location and not of the box
|
263
|
+
itself, this is configured in the plugin rather than in the Vagrantfile.
|
264
|
+
|
267
265
|
```bash
|
268
266
|
vagrant zones config network 10.0.0.0/24
|
269
267
|
```
|
@@ -274,6 +272,33 @@ create zones. It should be pretty obvious when this is the case.
|
|
274
272
|
|
275
273
|
* Does your network overlap with VirtualBox's local network space?
|
276
274
|
|
275
|
+
### Using local zone images
|
276
|
+
|
277
|
+
When running vagrant from a location far away from where SmartOS images
|
278
|
+
are hosted (anywhere other than the east coast of the USA, basically),
|
279
|
+
setting up a zone can be very slow.
|
280
|
+
|
281
|
+
Zones can be modified in Vagrant, then exported locally to save time on
|
282
|
+
repeated tasks. After modifying a zone, for instance by installing build
|
283
|
+
tools, you can export the zone as follows (warning: this will take a
|
284
|
+
while):
|
285
|
+
|
286
|
+
```bash
|
287
|
+
# vagrant dataset create [zone] [identifier]
|
288
|
+
vagrant dataset create base64 base64-15.1.1-build-essential
|
289
|
+
```
|
290
|
+
|
291
|
+
The vagrant-smartos-zones plugin can be configured to use a local zone
|
292
|
+
image in place of a remote one as follows:
|
293
|
+
|
294
|
+
```bash
|
295
|
+
vagrant zones config dataset.0edf00aa-0562-11e5-b92f-879647d45790 base64-15.1.1-build-essential
|
296
|
+
```
|
297
|
+
|
298
|
+
Now any Vagrantfile configured to use a local zone with the image
|
299
|
+
0edf00aa-0562-11e5-b92f-879647d45790 will instead install and use the
|
300
|
+
local image.
|
301
|
+
|
277
302
|
### Pkgsrc mirror
|
278
303
|
|
279
304
|
```bash
|
@@ -283,6 +308,19 @@ vagrant zones config local.pkgsrc http://mirror.domain.com
|
|
283
308
|
This will replace the protocol and domain of the pkgsrc mirror used by
|
284
309
|
pkgin in a SmartOS zone.
|
285
310
|
|
311
|
+
## Tests
|
312
|
+
|
313
|
+
There is a basic test suite that uses `test-kitchen` to converge
|
314
|
+
different brands of zones. Although it might not be comprehensive, it
|
315
|
+
should be ran after new features or after any significant refactoring to
|
316
|
+
ensure that nothing breaks the ability to stand up a zone.
|
317
|
+
|
318
|
+
```bash
|
319
|
+
bundle exec kitchen test
|
320
|
+
```
|
321
|
+
|
322
|
+
This may take a while...
|
323
|
+
|
286
324
|
## References / Alternatives
|
287
325
|
|
288
326
|
Any success of this project depends heavily on the work of others,
|
data/examples/Vagrantfile.lx
CHANGED
@@ -13,12 +13,11 @@ Vagrant.configure('2') do |config|
|
|
13
13
|
|
14
14
|
config.ssh.insert_key = false
|
15
15
|
|
16
|
-
config.global_zone.platform_image = '
|
17
|
-
config.global_zone.platform_image_url = 'https://us-east.manta.joyent.com/nahamu/public/smartos/platform-hourly.iso'
|
16
|
+
config.global_zone.platform_image = 'latest'
|
18
17
|
|
19
|
-
config.zone.name = 'lx'
|
18
|
+
config.zone.name = 'lx-ubuntu-14.04_20150415' # images are available through https://images.joyent.com/images
|
20
19
|
config.zone.brand = 'lx'
|
21
|
-
config.zone.image = '
|
20
|
+
config.zone.image = '430da066-e3a7-11e4-9657-332a2dbdf565'
|
22
21
|
config.zone.memory = 1536
|
23
22
|
config.zone.disk_size = 5
|
24
23
|
end
|
@@ -3,6 +3,17 @@ en:
|
|
3
3
|
smartos:
|
4
4
|
zones:
|
5
5
|
commands:
|
6
|
+
dataset:
|
7
|
+
create: |-
|
8
|
+
Creating a new dataset %{dataset} from zone: %{uuid}
|
9
|
+
prepare_image: |-
|
10
|
+
Preparing zone for dataset
|
11
|
+
save: |-
|
12
|
+
Saving zone file system
|
13
|
+
start_zone: |-
|
14
|
+
Restarting zone
|
15
|
+
stop_zone: |-
|
16
|
+
Stopping zone
|
6
17
|
zones:
|
7
18
|
list: |-
|
8
19
|
name state uuid
|
@@ -0,0 +1,17 @@
|
|
1
|
+
require 'vagrant/smartos/zones/util/datasets'
|
2
|
+
|
3
|
+
module Vagrant
|
4
|
+
module Smartos
|
5
|
+
module Zones
|
6
|
+
module Cap
|
7
|
+
module Dataset
|
8
|
+
class List
|
9
|
+
def self.dataset_list(env)
|
10
|
+
Zones::Util::Datasets.new(env).list
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -1,4 +1,7 @@
|
|
1
1
|
require 'vagrant/smartos/zones/cap/base'
|
2
|
+
require 'vagrant/smartos/zones/models/dataset'
|
3
|
+
require 'vagrant/smartos/zones/util/datasets/manifest'
|
4
|
+
require 'vagrant/smartos/zones/util/zone_image'
|
2
5
|
|
3
6
|
module Vagrant
|
4
7
|
module Smartos
|
@@ -10,18 +13,46 @@ module Vagrant
|
|
10
13
|
def execute
|
11
14
|
return ui.info 'No zone image set, skipping import' unless image
|
12
15
|
|
13
|
-
|
16
|
+
if zone_image.install_override?
|
17
|
+
install
|
18
|
+
else
|
19
|
+
import
|
20
|
+
end
|
21
|
+
end
|
14
22
|
|
15
|
-
|
16
|
-
return if installed
|
23
|
+
private
|
17
24
|
|
18
|
-
|
25
|
+
def image
|
26
|
+
machine.config.zone.image
|
27
|
+
end
|
28
|
+
|
29
|
+
def import
|
30
|
+
ui.info "Zone image #{image}: installed" && return if installed?(image)
|
31
|
+
ui.info " Importing zone image #{image}..."
|
19
32
|
machine.communicate.gz_execute("#{sudo} imgadm sources -a https://updates.joyent.com")
|
20
33
|
machine.communicate.gz_execute("#{sudo} imgadm import #{image}")
|
21
34
|
end
|
22
35
|
|
23
|
-
def
|
24
|
-
machine.
|
36
|
+
def installed?(uuid)
|
37
|
+
machine.communicate.gz_test("#{sudo} imgadm get #{uuid}")
|
38
|
+
end
|
39
|
+
|
40
|
+
def install
|
41
|
+
uuid = zone_image.override_uuid
|
42
|
+
ui.info "Swapping out image #{uuid} for #{image}"
|
43
|
+
ui.info "Zone image #{uuid}: installed" && return if installed?(uuid)
|
44
|
+
dataset = Models::Dataset.install(zone_image.override, machine)
|
45
|
+
machine.communicate.gz_upload(manifest.local_filename, manifest.remote_filename)
|
46
|
+
ui.info " Unpacking #{uuid}..."
|
47
|
+
machine.communicate.gz_execute("#{sudo} imgadm install -m #{manifest.remote_filename} -f #{dataset.remote_filename}")
|
48
|
+
end
|
49
|
+
|
50
|
+
def manifest
|
51
|
+
@manifest ||= Util::Datasets::Manifest.new(zone_image.override, machine.env).load!
|
52
|
+
end
|
53
|
+
|
54
|
+
def zone_image
|
55
|
+
@zone_image ||= Util::ZoneImage.new(machine)
|
25
56
|
end
|
26
57
|
end
|
27
58
|
end
|
@@ -40,7 +40,8 @@ module Vagrant
|
|
40
40
|
|
41
41
|
def create(zonename, dataset)
|
42
42
|
with_zone(zonename) do |zone|
|
43
|
-
|
43
|
+
ui.info(I18n.t('vagrant.smartos.zones.commands.dataset.create', uuid: zone.uuid, dataset: dataset))
|
44
|
+
Models::Dataset.create(dataset, zone, zone.machine)
|
44
45
|
end
|
45
46
|
end
|
46
47
|
|
@@ -1,4 +1,5 @@
|
|
1
1
|
require 'vagrant/smartos/zones/util/global_zone/connection'
|
2
|
+
require 'vagrant/smartos/zones/util/rsync'
|
2
3
|
|
3
4
|
module Vagrant
|
4
5
|
module Smartos
|
@@ -10,6 +11,38 @@ module Vagrant
|
|
10
11
|
super
|
11
12
|
end
|
12
13
|
|
14
|
+
def gz_download(from, to = nil)
|
15
|
+
@logger.debug("Downloading from global zone: #{from} to #{to}")
|
16
|
+
|
17
|
+
if gz_rsync_connector.available?
|
18
|
+
gz_rsync_connector.download(from, to)
|
19
|
+
else
|
20
|
+
gz_scp_connect do |scp|
|
21
|
+
scp.download!(from, to) do |_ch, name, sent, total|
|
22
|
+
percent = (sent.to_f / total) * 100
|
23
|
+
print "#{name}: #{sent}/#{total} : #{percent.to_i}%\r"
|
24
|
+
$stdout.flush
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
def gz_upload(from, to)
|
31
|
+
@logger.debug("Uploading to global zone: #{from} to #{to}")
|
32
|
+
|
33
|
+
if gz_rsync_connector.available?
|
34
|
+
gz_rsync_connector.upload(from, to)
|
35
|
+
else
|
36
|
+
gz_scp_connect do |scp|
|
37
|
+
scp.upload!(from, to) do |_ch, name, sent, total|
|
38
|
+
percent = (sent.to_f / total) * 100
|
39
|
+
print "#{name}: #{sent}/#{total} : #{percent.to_i}%\r"
|
40
|
+
$stdout.flush
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
13
46
|
# rubocop:disable Metrics/MethodLength
|
14
47
|
def gz_execute(command, opts = {}, &block)
|
15
48
|
opts = {
|
@@ -70,6 +103,15 @@ module Vagrant
|
|
70
103
|
exit_status
|
71
104
|
end
|
72
105
|
|
106
|
+
def gz_scp_connect
|
107
|
+
global_zone_connector.with_connection do |connection|
|
108
|
+
yield connection.scp
|
109
|
+
end
|
110
|
+
rescue Net::SCP::Error => e
|
111
|
+
raise Vagrant::Errors::SCPUnavailable if e.message =~ /\(127\)/
|
112
|
+
raise
|
113
|
+
end
|
114
|
+
|
73
115
|
def gz_test(command, opts = nil)
|
74
116
|
opts = { error_check: false }.merge(opts || {})
|
75
117
|
gz_execute(command, opts) == 0
|
@@ -80,6 +122,10 @@ module Vagrant
|
|
80
122
|
def global_zone_connector
|
81
123
|
@global_zone_connector ||= Vagrant::Smartos::Zones::Util::GlobalZone::Connection.new(@machine, @logger)
|
82
124
|
end
|
125
|
+
|
126
|
+
def gz_rsync_connector
|
127
|
+
@gz_rsync_connector ||= Vagrant::Smartos::Zones::Util::Rsync.new(global_zone_connector.connect)
|
128
|
+
end
|
83
129
|
end
|
84
130
|
end
|
85
131
|
end
|
@@ -1,4 +1,6 @@
|
|
1
1
|
require 'vagrant/smartos/zones/models/snapshot'
|
2
|
+
require 'vagrant/smartos/zones/util/datasets'
|
3
|
+
require 'vagrant/smartos/zones/util/datasets/manifest'
|
2
4
|
require 'vagrant/smartos/zones/util/global_zone/helper'
|
3
5
|
|
4
6
|
module Vagrant
|
@@ -8,18 +10,94 @@ module Vagrant
|
|
8
10
|
class Dataset
|
9
11
|
include Util::GlobalZone::Helper
|
10
12
|
|
13
|
+
attr_reader :name, :zone, :machine
|
14
|
+
|
15
|
+
def initialize(name, zone, machine)
|
16
|
+
@name = name
|
17
|
+
@zone = zone
|
18
|
+
@machine = machine
|
19
|
+
end
|
20
|
+
|
11
21
|
def self.create(name, zone)
|
22
|
+
new(name, zone).create
|
23
|
+
end
|
24
|
+
|
25
|
+
def self.install(name, machine)
|
26
|
+
new(name, nil, machine).install
|
27
|
+
end
|
28
|
+
|
29
|
+
def create
|
30
|
+
Zones::Util::Datasets.new(machine.env).setup_smartos_directories
|
31
|
+
prepare_gz
|
32
|
+
# create_dataset
|
33
|
+
# download
|
34
|
+
write_manifest
|
35
|
+
end
|
36
|
+
|
37
|
+
def exists?
|
38
|
+
cmd = 'ls %s 2>/dev/null' % remote_filename
|
39
|
+
with_gz(cmd) do |output|
|
40
|
+
return true if output.strip == remote_filename
|
41
|
+
end
|
42
|
+
false
|
43
|
+
end
|
44
|
+
|
45
|
+
def install
|
46
|
+
prepare_gz
|
47
|
+
upload
|
48
|
+
self
|
49
|
+
end
|
50
|
+
|
51
|
+
def remote_filename
|
52
|
+
'/zones/vagrant/%s' % filename
|
53
|
+
end
|
54
|
+
|
55
|
+
private
|
56
|
+
|
57
|
+
def prepare_gz
|
58
|
+
with_gz('pfexec mkdir /zones/vagrant')
|
59
|
+
with_gz('pfexec chown vagrant:vagrant /zones/vagrant')
|
60
|
+
end
|
61
|
+
|
62
|
+
def create_dataset
|
63
|
+
return machine.ui.info('Dataset already exists in global zone') if exists?
|
12
64
|
Models::Snapshot.around(zone) do
|
65
|
+
machine.ui.info(I18n.t('vagrant.smartos.zones.commands.dataset.prepare_image'))
|
13
66
|
zone.zlogin('\'find /var/log -type f -exec truncate --size 0 {} \;\'')
|
14
67
|
zone.zlogin('sm-prepare-image -y')
|
68
|
+
machine.ui.info(I18n.t('vagrant.smartos.zones.commands.dataset.stop_zone'))
|
15
69
|
zone.stop
|
16
70
|
Models::Snapshot.around(zone) do |snapshot|
|
17
|
-
|
18
|
-
|
71
|
+
machine.ui.info(I18n.t('vagrant.smartos.zones.commands.dataset.save'))
|
72
|
+
cmd = 'pfexec /usr/bin/bash -l -c "/usr/sbin/zfs send %s | /usr/bin/bzip2 > %s"'
|
73
|
+
with_gz(cmd % [snapshot.path, remote_filename])
|
19
74
|
end
|
20
75
|
end
|
76
|
+
machine.ui.info(I18n.t('vagrant.smartos.zones.commands.dataset.start_zone'))
|
21
77
|
zone.start
|
22
78
|
end
|
79
|
+
|
80
|
+
def download
|
81
|
+
machine.ui.info 'Downloading %s' % filename
|
82
|
+
machine.communicate.gz_download(remote_filename, local_filename)
|
83
|
+
end
|
84
|
+
|
85
|
+
def upload
|
86
|
+
machine.ui.info 'Installing %s in global zone' % filename
|
87
|
+
machine.communicate.gz_upload(local_filename, remote_filename)
|
88
|
+
end
|
89
|
+
|
90
|
+
def write_manifest
|
91
|
+
Zones::Util::Datasets::Manifest.new(name, machine.env).write!
|
92
|
+
end
|
93
|
+
|
94
|
+
def filename
|
95
|
+
'%s.zfs.bz2' % name
|
96
|
+
end
|
97
|
+
|
98
|
+
def local_filename
|
99
|
+
machine.env.home_path.join('smartos', 'datasets', filename).to_s
|
100
|
+
end
|
23
101
|
end
|
24
102
|
end
|
25
103
|
end
|
@@ -90,6 +90,11 @@ module Vagrant
|
|
90
90
|
Cap::Zone::Stop
|
91
91
|
end
|
92
92
|
|
93
|
+
host_capability 'bsd', 'dataset_list' do
|
94
|
+
require_relative 'cap/dataset/list'
|
95
|
+
Cap::Dataset::List
|
96
|
+
end
|
97
|
+
|
93
98
|
host_capability 'bsd', 'platform_image_install' do
|
94
99
|
require_relative 'cap/platform_image/install'
|
95
100
|
Cap::PlatformImage::Install
|
@@ -0,0 +1,95 @@
|
|
1
|
+
require 'securerandom'
|
2
|
+
require 'vagrant/smartos/zones/util/datasets'
|
3
|
+
|
4
|
+
module Vagrant
|
5
|
+
module Smartos
|
6
|
+
module Zones
|
7
|
+
module Util
|
8
|
+
class Datasets
|
9
|
+
class Manifest
|
10
|
+
attr_reader :name, :env
|
11
|
+
|
12
|
+
def initialize(name, env)
|
13
|
+
@name = name
|
14
|
+
@env = env
|
15
|
+
end
|
16
|
+
|
17
|
+
def write!
|
18
|
+
File.open(local_filename, 'w') do |f|
|
19
|
+
f.write to_json
|
20
|
+
end
|
21
|
+
self
|
22
|
+
end
|
23
|
+
|
24
|
+
def load!
|
25
|
+
json = JSON.load(File.read(local_filename))
|
26
|
+
@creator = json['creator_uuid']
|
27
|
+
@uuid = json['uuid']
|
28
|
+
self
|
29
|
+
end
|
30
|
+
|
31
|
+
def to_json
|
32
|
+
{
|
33
|
+
'creator_name' => 'vagrant-smartos-zones',
|
34
|
+
'creator_uuid' => creator_uuid,
|
35
|
+
'description' => name,
|
36
|
+
'files' => files,
|
37
|
+
'name' => name,
|
38
|
+
'os' => 'smartos',
|
39
|
+
'published_at' => '2015-06-15T15:13:08.425Z',
|
40
|
+
'type' => 'zone-dataset',
|
41
|
+
'urn' => urn,
|
42
|
+
'uuid' => uuid,
|
43
|
+
'version' => '1.0.0'
|
44
|
+
}.to_json
|
45
|
+
end
|
46
|
+
|
47
|
+
def local_filename
|
48
|
+
env.home_path.join('smartos', 'datasets', manifest_filename).to_s
|
49
|
+
end
|
50
|
+
|
51
|
+
def remote_filename
|
52
|
+
'/zones/vagrant/%s' % manifest_filename
|
53
|
+
end
|
54
|
+
|
55
|
+
def uuid
|
56
|
+
@uuid ||= SecureRandom.uuid
|
57
|
+
end
|
58
|
+
|
59
|
+
private
|
60
|
+
|
61
|
+
def files
|
62
|
+
[
|
63
|
+
{
|
64
|
+
'path' => "#{name}.zfs.bz2",
|
65
|
+
'sha1' => sha1,
|
66
|
+
'size' => size
|
67
|
+
}
|
68
|
+
]
|
69
|
+
end
|
70
|
+
|
71
|
+
def creator_uuid
|
72
|
+
@creator ||= SecureRandom.uuid
|
73
|
+
end
|
74
|
+
|
75
|
+
def sha1
|
76
|
+
Datasets.new(env).sha1(name)
|
77
|
+
end
|
78
|
+
|
79
|
+
def size
|
80
|
+
Datasets.new(env).size(name)
|
81
|
+
end
|
82
|
+
|
83
|
+
def urn
|
84
|
+
"smartos:vagrant-smartos-zones:#{name}:1.0.0"
|
85
|
+
end
|
86
|
+
|
87
|
+
def manifest_filename
|
88
|
+
'%s.dsmanifest' % name
|
89
|
+
end
|
90
|
+
end
|
91
|
+
end
|
92
|
+
end
|
93
|
+
end
|
94
|
+
end
|
95
|
+
end
|
@@ -0,0 +1,56 @@
|
|
1
|
+
require 'digest/sha1'
|
2
|
+
|
3
|
+
module Vagrant
|
4
|
+
module Smartos
|
5
|
+
module Zones
|
6
|
+
module Util
|
7
|
+
class Datasets
|
8
|
+
attr_reader :env, :machine
|
9
|
+
|
10
|
+
def initialize(env, machine = nil)
|
11
|
+
@env = env
|
12
|
+
@machine = machine
|
13
|
+
end
|
14
|
+
|
15
|
+
def list
|
16
|
+
setup_smartos_directories
|
17
|
+
ui.info(datasets.join("\n"), prefix: false)
|
18
|
+
end
|
19
|
+
|
20
|
+
def setup_smartos_directories
|
21
|
+
env.setup_home_path if env.respond_to?(:setup_home_path)
|
22
|
+
FileUtils.mkdir_p(dataset_dir)
|
23
|
+
end
|
24
|
+
|
25
|
+
def sha1(name)
|
26
|
+
Digest::SHA1.file(dataset_dir.join("#{name}.zfs.bz2")).hexdigest
|
27
|
+
end
|
28
|
+
|
29
|
+
def size(name)
|
30
|
+
::File.size(dataset_dir.join("#{name}.zfs.bz2"))
|
31
|
+
end
|
32
|
+
|
33
|
+
private
|
34
|
+
|
35
|
+
def ui
|
36
|
+
env.respond_to?(:ui) ? env.ui : env[:ui]
|
37
|
+
end
|
38
|
+
|
39
|
+
def home_path
|
40
|
+
env.respond_to?(:home_path) ? env.home_path : env[:home_path]
|
41
|
+
end
|
42
|
+
|
43
|
+
def datasets
|
44
|
+
Dir[dataset_dir.join('*.zfs.bz2')].map do |f|
|
45
|
+
File.basename(f, '.zfs.bz2')
|
46
|
+
end.sort
|
47
|
+
end
|
48
|
+
|
49
|
+
def dataset_dir
|
50
|
+
home_path.join('smartos', 'datasets')
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
@@ -0,0 +1,51 @@
|
|
1
|
+
module Vagrant
|
2
|
+
module Smartos
|
3
|
+
module Zones
|
4
|
+
module Util
|
5
|
+
class Rsync
|
6
|
+
attr_reader :connection
|
7
|
+
|
8
|
+
def initialize(connection)
|
9
|
+
@connection = connection
|
10
|
+
end
|
11
|
+
|
12
|
+
def available?
|
13
|
+
Vagrant::Util::Subprocess.execute(*%w(which rsync)).exit_code == 0
|
14
|
+
end
|
15
|
+
|
16
|
+
def download(from, to)
|
17
|
+
Vagrant::Util::Subprocess.execute(*rsync_command, '-e', ssh_command, remote(from), to, notify: [:stdout])
|
18
|
+
end
|
19
|
+
|
20
|
+
def upload(from, to)
|
21
|
+
Vagrant::Util::Subprocess.execute(*rsync_command, '-e', ssh_command, from, remote(to), notify: [:stdout])
|
22
|
+
end
|
23
|
+
|
24
|
+
def rsync_command
|
25
|
+
%w(rsync -avz --progress)
|
26
|
+
end
|
27
|
+
|
28
|
+
def ssh_command
|
29
|
+
"ssh -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null -i #{identity_file} -p #{remote_port}"
|
30
|
+
end
|
31
|
+
|
32
|
+
def identity_file
|
33
|
+
connection.options[:keys].first
|
34
|
+
end
|
35
|
+
|
36
|
+
def remote(file)
|
37
|
+
"#{remote_user}@#{connection.host}:#{file}"
|
38
|
+
end
|
39
|
+
|
40
|
+
def remote_port
|
41
|
+
connection.options[:port]
|
42
|
+
end
|
43
|
+
|
44
|
+
def remote_user
|
45
|
+
connection.options[:user]
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
@@ -18,13 +18,18 @@ module Vagrant
|
|
18
18
|
def find(group)
|
19
19
|
Models::ZoneGroup.new.tap do |g|
|
20
20
|
g.name = group
|
21
|
-
with_gz("#{sudo} zlogin #{zone.uuid} gid -g #{group}") do |
|
22
|
-
g.gid = output.chomp
|
21
|
+
with_gz("#{sudo} zlogin #{zone.uuid} gid -g #{group}") do |output|
|
22
|
+
g.gid = output.chomp if output
|
23
23
|
end
|
24
24
|
end
|
25
25
|
end
|
26
26
|
|
27
|
+
def exists?(group)
|
28
|
+
machine.communicate.gz_test("#{sudo} zlogin #{zone.uuid} gid -g #{group}")
|
29
|
+
end
|
30
|
+
|
27
31
|
def create(group)
|
32
|
+
return if exists?(group)
|
28
33
|
zone.zlogin("groupadd #{group}")
|
29
34
|
end
|
30
35
|
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
require 'vagrant/smartos/zones/models/config'
|
2
|
+
|
3
|
+
module Vagrant
|
4
|
+
module Smartos
|
5
|
+
module Zones
|
6
|
+
module Util
|
7
|
+
class ZoneImage
|
8
|
+
attr_reader :machine
|
9
|
+
|
10
|
+
def initialize(machine)
|
11
|
+
@machine = machine
|
12
|
+
end
|
13
|
+
|
14
|
+
def image
|
15
|
+
machine.config.zone.image
|
16
|
+
end
|
17
|
+
|
18
|
+
def install_override?
|
19
|
+
!!override
|
20
|
+
end
|
21
|
+
|
22
|
+
def override
|
23
|
+
plugin_config["dataset.#{image}"]
|
24
|
+
end
|
25
|
+
|
26
|
+
def override_uuid
|
27
|
+
@override_uuid ||= manifest.uuid
|
28
|
+
end
|
29
|
+
|
30
|
+
private
|
31
|
+
|
32
|
+
def plugin_config
|
33
|
+
@plugin_config ||= Models::Config.config(machine.env).hash
|
34
|
+
end
|
35
|
+
|
36
|
+
def manifest
|
37
|
+
@manifest ||= Util::Datasets::Manifest.new(override, machine.env).load!
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
@@ -1,4 +1,5 @@
|
|
1
1
|
require 'vagrant/smartos/zones/models/network'
|
2
|
+
require 'vagrant/smartos/zones/util/zone_image'
|
2
3
|
|
3
4
|
module Vagrant
|
4
5
|
module Smartos
|
@@ -23,7 +24,7 @@ module Vagrant
|
|
23
24
|
{
|
24
25
|
'brand' => machine.config.zone.brand,
|
25
26
|
'alias' => machine.config.zone.name,
|
26
|
-
'dataset_uuid' =>
|
27
|
+
'dataset_uuid' => image,
|
27
28
|
'quota' => machine.config.zone.disk_size || 1,
|
28
29
|
'max_physical_memory' => machine.config.zone.memory || 64
|
29
30
|
}
|
@@ -67,6 +68,10 @@ module Vagrant
|
|
67
68
|
}
|
68
69
|
end
|
69
70
|
|
71
|
+
def image
|
72
|
+
zone_image.install_override? ? zone_image.override_uuid : machine.config.zone.image
|
73
|
+
end
|
74
|
+
|
70
75
|
private
|
71
76
|
|
72
77
|
def lx_brand?
|
@@ -76,6 +81,10 @@ module Vagrant
|
|
76
81
|
def network
|
77
82
|
@network ||= Models::Network.new(machine.env)
|
78
83
|
end
|
84
|
+
|
85
|
+
def zone_image
|
86
|
+
@zone_image ||= Util::ZoneImage.new(machine)
|
87
|
+
end
|
79
88
|
end
|
80
89
|
end
|
81
90
|
end
|
@@ -15,8 +15,13 @@ module Vagrant
|
|
15
15
|
@zone = zone
|
16
16
|
end
|
17
17
|
|
18
|
+
def exists?(project)
|
19
|
+
machine.communicate.gz_test("#{sudo} zlogin #{zone.uuid} projects -l #{project}")
|
20
|
+
end
|
21
|
+
|
18
22
|
def create(project, users, comment)
|
19
23
|
return if zone.lx_brand?
|
24
|
+
return if exists?(project)
|
20
25
|
zone.zlogin("projadd -c \"#{comment}\" -U #{users.join(',')} #{project}")
|
21
26
|
end
|
22
27
|
end
|
@@ -19,13 +19,18 @@ module Vagrant
|
|
19
19
|
def find(username)
|
20
20
|
Models::ZoneUser.new.tap do |u|
|
21
21
|
u.name = username
|
22
|
-
|
23
|
-
u.uid = output.chomp
|
22
|
+
with_gz("#{sudo} zlogin #{zone.uuid} id -u #{username}") do |output|
|
23
|
+
u.uid = output.chomp if output
|
24
24
|
end
|
25
25
|
end
|
26
26
|
end
|
27
27
|
|
28
|
+
def exists?(username)
|
29
|
+
machine.communicate.gz_test("#{sudo} zlogin #{zone.uuid} id -u #{username}")
|
30
|
+
end
|
31
|
+
|
28
32
|
def create(username, group, role = nil)
|
33
|
+
return if exists?(username)
|
29
34
|
zone.zlogin("useradd #{flags(group)} #{username}")
|
30
35
|
grant_role(username, role)
|
31
36
|
install_public_key(group)
|
@@ -27,8 +27,8 @@ module Vagrant
|
|
27
27
|
end
|
28
28
|
|
29
29
|
def create(name)
|
30
|
-
machine.ui.info "Creating zone #{machine.config.zone.name} with image #{
|
31
|
-
with_gz("echo '#{zone_json}' | #{sudo} vmadm create")
|
30
|
+
machine.ui.info "Creating zone #{machine.config.zone.name} with image #{zone_json.image}"
|
31
|
+
with_gz("echo '#{zone_json.to_json}' | #{sudo} vmadm create")
|
32
32
|
with_zone(name) do |zone|
|
33
33
|
create_zone_users(zone)
|
34
34
|
configure_pkgsrc_mirror(zone)
|
@@ -38,7 +38,7 @@ module Vagrant
|
|
38
38
|
def update(name)
|
39
39
|
with_zone(name) do |zone|
|
40
40
|
machine.ui.info "Updating zone #{name}..."
|
41
|
-
with_gz("echo '#{zone_json}' | #{sudo} vmadm update #{zone.uuid}")
|
41
|
+
with_gz("echo '#{zone_json.to_json}' | #{sudo} vmadm update #{zone.uuid}")
|
42
42
|
end
|
43
43
|
end
|
44
44
|
|
@@ -81,7 +81,7 @@ module Vagrant
|
|
81
81
|
end
|
82
82
|
|
83
83
|
def zone_json
|
84
|
-
Util::ZoneJson.new(machine)
|
84
|
+
Util::ZoneJson.new(machine)
|
85
85
|
end
|
86
86
|
|
87
87
|
def with_zone(name)
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: vagrant-smartos-zones
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Eric Saxby
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-06-21 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: netaddr
|
@@ -107,6 +107,7 @@ files:
|
|
107
107
|
- lib/vagrant/smartos/zones/action/zone_gate/install.rb
|
108
108
|
- lib/vagrant/smartos/zones/cap/base.rb
|
109
109
|
- lib/vagrant/smartos/zones/cap/create_gz_vnic.rb
|
110
|
+
- lib/vagrant/smartos/zones/cap/dataset/list.rb
|
110
111
|
- lib/vagrant/smartos/zones/cap/imgadm_import.rb
|
111
112
|
- lib/vagrant/smartos/zones/cap/platform_image/install.rb
|
112
113
|
- lib/vagrant/smartos/zones/cap/platform_image/latest.rb
|
@@ -138,14 +139,18 @@ files:
|
|
138
139
|
- lib/vagrant/smartos/zones/models/zone_user.rb
|
139
140
|
- lib/vagrant/smartos/zones/plugin.rb
|
140
141
|
- lib/vagrant/smartos/zones/util/checksum.rb
|
142
|
+
- lib/vagrant/smartos/zones/util/datasets.rb
|
143
|
+
- lib/vagrant/smartos/zones/util/datasets/manifest.rb
|
141
144
|
- lib/vagrant/smartos/zones/util/downloader.rb
|
142
145
|
- lib/vagrant/smartos/zones/util/global_zone/connection.rb
|
143
146
|
- lib/vagrant/smartos/zones/util/global_zone/helper.rb
|
144
147
|
- lib/vagrant/smartos/zones/util/global_zone/ssh_info.rb
|
145
148
|
- lib/vagrant/smartos/zones/util/platform_images.rb
|
146
149
|
- lib/vagrant/smartos/zones/util/public_key.rb
|
150
|
+
- lib/vagrant/smartos/zones/util/rsync.rb
|
147
151
|
- lib/vagrant/smartos/zones/util/snapshots.rb
|
148
152
|
- lib/vagrant/smartos/zones/util/zone_group.rb
|
153
|
+
- lib/vagrant/smartos/zones/util/zone_image.rb
|
149
154
|
- lib/vagrant/smartos/zones/util/zone_json.rb
|
150
155
|
- lib/vagrant/smartos/zones/util/zone_project.rb
|
151
156
|
- lib/vagrant/smartos/zones/util/zone_user.rb
|
@@ -177,7 +182,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
177
182
|
version: '0'
|
178
183
|
requirements: []
|
179
184
|
rubyforge_project:
|
180
|
-
rubygems_version: 2.
|
185
|
+
rubygems_version: 2.2.3
|
181
186
|
signing_key:
|
182
187
|
specification_version: 4
|
183
188
|
summary: Manage SmartOS zones in Vagrant
|
@@ -187,4 +192,3 @@ test_files:
|
|
187
192
|
- test/integration/default/serverspec/user_spec.rb
|
188
193
|
- test/templates/Vagrantfile.smartos.erb
|
189
194
|
- test/templates/bootstrap.sh
|
190
|
-
has_rdoc:
|