vagrant-smartos-zones 0.0.1.pre.21

Sign up to get free protection for your applications and to get access to all the features.
Files changed (78) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +19 -0
  3. data/.rubocop.yml +12 -0
  4. data/Gemfile +12 -0
  5. data/LICENSE.txt +22 -0
  6. data/README.md +268 -0
  7. data/Rakefile +6 -0
  8. data/Vagrantfile +29 -0
  9. data/examples/Vagrantfile +18 -0
  10. data/examples/Vagrantfile.chef_server +33 -0
  11. data/examples/Vagrantfile.lx +22 -0
  12. data/examples/Vagrantfile.rsync +23 -0
  13. data/files/gz_vnic/create_gz_vnic +15 -0
  14. data/files/smf/create-gz-vnic.xml +31 -0
  15. data/files/smf/zonegate.xml +34 -0
  16. data/files/zonegate/zonegate +60 -0
  17. data/files/zonegate/zonemon +15 -0
  18. data/files/zonegate/zonenat +153 -0
  19. data/lib/vagrant/smartos/locales/en.yml +41 -0
  20. data/lib/vagrant/smartos/zones/action/configure_zone_synced_folders.rb +53 -0
  21. data/lib/vagrant/smartos/zones/action/create_gz_vnic.rb +28 -0
  22. data/lib/vagrant/smartos/zones/action/forward_gz_ports.rb +46 -0
  23. data/lib/vagrant/smartos/zones/action/helper.rb +33 -0
  24. data/lib/vagrant/smartos/zones/action/imgadm_import.rb +24 -0
  25. data/lib/vagrant/smartos/zones/action/virtualbox/platform_iso.rb +57 -0
  26. data/lib/vagrant/smartos/zones/action/zone/create.rb +25 -0
  27. data/lib/vagrant/smartos/zones/action/zone/start.rb +25 -0
  28. data/lib/vagrant/smartos/zones/action/zone/stop.rb +25 -0
  29. data/lib/vagrant/smartos/zones/action/zone_gate/enable.rb +26 -0
  30. data/lib/vagrant/smartos/zones/action/zone_gate/install.rb +26 -0
  31. data/lib/vagrant/smartos/zones/action.rb +75 -0
  32. data/lib/vagrant/smartos/zones/cap/base.rb +29 -0
  33. data/lib/vagrant/smartos/zones/cap/create_gz_vnic.rb +45 -0
  34. data/lib/vagrant/smartos/zones/cap/imgadm_import.rb +30 -0
  35. data/lib/vagrant/smartos/zones/cap/platform_image/install.rb +17 -0
  36. data/lib/vagrant/smartos/zones/cap/platform_image/latest.rb +19 -0
  37. data/lib/vagrant/smartos/zones/cap/platform_image/list.rb +17 -0
  38. data/lib/vagrant/smartos/zones/cap/zone/base.rb +32 -0
  39. data/lib/vagrant/smartos/zones/cap/zone/create.rb +45 -0
  40. data/lib/vagrant/smartos/zones/cap/zone/start.rb +29 -0
  41. data/lib/vagrant/smartos/zones/cap/zone/stop.rb +29 -0
  42. data/lib/vagrant/smartos/zones/cap/zone_gate/enable.rb +20 -0
  43. data/lib/vagrant/smartos/zones/cap/zone_gate/install.rb +46 -0
  44. data/lib/vagrant/smartos/zones/commands/dataset.rb +91 -0
  45. data/lib/vagrant/smartos/zones/commands/global_zone.rb +43 -0
  46. data/lib/vagrant/smartos/zones/commands/multi_command.rb +46 -0
  47. data/lib/vagrant/smartos/zones/commands/smartos.rb +70 -0
  48. data/lib/vagrant/smartos/zones/commands/zlogin.rb +35 -0
  49. data/lib/vagrant/smartos/zones/commands/zones.rb +136 -0
  50. data/lib/vagrant/smartos/zones/communicator/smartos.rb +87 -0
  51. data/lib/vagrant/smartos/zones/config/global_zone.rb +26 -0
  52. data/lib/vagrant/smartos/zones/config/zone.rb +33 -0
  53. data/lib/vagrant/smartos/zones/errors.rb +9 -0
  54. data/lib/vagrant/smartos/zones/guest.rb +25 -0
  55. data/lib/vagrant/smartos/zones/hooks.rb +41 -0
  56. data/lib/vagrant/smartos/zones/models/dataset.rb +27 -0
  57. data/lib/vagrant/smartos/zones/models/snapshot.rb +71 -0
  58. data/lib/vagrant/smartos/zones/models/zone.rb +80 -0
  59. data/lib/vagrant/smartos/zones/models/zone_group.rb +11 -0
  60. data/lib/vagrant/smartos/zones/models/zone_user.rb +11 -0
  61. data/lib/vagrant/smartos/zones/plugin.rb +118 -0
  62. data/lib/vagrant/smartos/zones/util/checksum.rb +22 -0
  63. data/lib/vagrant/smartos/zones/util/downloader.rb +48 -0
  64. data/lib/vagrant/smartos/zones/util/global_zone/connection.rb +192 -0
  65. data/lib/vagrant/smartos/zones/util/global_zone/helper.rb +33 -0
  66. data/lib/vagrant/smartos/zones/util/global_zone/ssh_info.rb +85 -0
  67. data/lib/vagrant/smartos/zones/util/platform_images.rb +132 -0
  68. data/lib/vagrant/smartos/zones/util/public_key.rb +14 -0
  69. data/lib/vagrant/smartos/zones/util/snapshots.rb +63 -0
  70. data/lib/vagrant/smartos/zones/util/zone_group.rb +34 -0
  71. data/lib/vagrant/smartos/zones/util/zone_info.rb +72 -0
  72. data/lib/vagrant/smartos/zones/util/zone_json.rb +77 -0
  73. data/lib/vagrant/smartos/zones/util/zone_project.rb +25 -0
  74. data/lib/vagrant/smartos/zones/util/zone_user.rb +63 -0
  75. data/lib/vagrant/smartos/zones/version.rb +7 -0
  76. data/lib/vagrant/smartos/zones.rb +10 -0
  77. data/vagrant-smartos-zones.gemspec +24 -0
  78. metadata +163 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: c7231d953d2c1a01f6e9a8255ca6d60684dd0f47
4
+ data.tar.gz: 5adb6ac03013fa4a5e9b3455be9ef500a85cf568
5
+ SHA512:
6
+ metadata.gz: 20d000f49065dedd3c83f338fb59c3ddc07f0def75f35d19d31a9f74e83dcd5eb598481b498808aafd54a4c33a2dd8321cd74b2d4d54d0130ac0acadb8ba60c3
7
+ data.tar.gz: ea6343b9d7a8de20201bc5be827f0ab2a9c2132f18553fbf1cb44468b396327876c3800e3ae353ee8a884fb146f4eb41922706dbec26238be13c36531e8c21c8
data/.gitignore ADDED
@@ -0,0 +1,19 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ .vagrant
7
+ examples/.vagrant
8
+ Gemfile.lock
9
+ InstalledFiles
10
+ _yardoc
11
+ coverage
12
+ doc/
13
+ lib/bundler/man
14
+ pkg
15
+ rdoc
16
+ spec/reports
17
+ test/tmp
18
+ test/version_tmp
19
+ tmp
data/.rubocop.yml ADDED
@@ -0,0 +1,12 @@
1
+ Metrics/LineLength:
2
+ Max: 120
3
+ Style/Documentation:
4
+ Enabled: false
5
+ Style/DoubleNegation:
6
+ Enabled: false
7
+ Style/SignalException:
8
+ Enabled: false
9
+ Style/FormatString:
10
+ Enabled: false
11
+ Style/MultilineBlockChain:
12
+ Enabled: false
data/Gemfile ADDED
@@ -0,0 +1,12 @@
1
+ source 'https://rubygems.org'
2
+
3
+ group :development do
4
+ gem 'rubocop'
5
+ gem 'vagrant', git: 'https://github.com/mitchellh/vagrant.git'
6
+ gem 'rake'
7
+ gem 'pry-nav'
8
+ end
9
+
10
+ group :plugins do
11
+ gem 'vagrant-smartos-zones', path: '.'
12
+ end
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 Eric Saxby
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,268 @@
1
+ vagrant-smartos-zones
2
+ =====================
3
+
4
+ Manage SmartOS zones using Vagrant.
5
+
6
+ ## Dependencies
7
+
8
+ This plugin depends on using a SmartOS global zone built to be vagrant
9
+ compatible.
10
+
11
+ ```ruby
12
+ config.vm.box = "livinginthepast/smartos"
13
+ ```
14
+
15
+ See [Vagrant Cloud](https://vagrantcloud.com/livinginthepast) for some boxes.
16
+
17
+ This plugin also depends on Vagrant recognizing the SmartOS guest. This
18
+ is available in Vagrant 1.5.3 or newer.
19
+
20
+ Any outstanding issues with SmartOS integration in the current released
21
+ version of Vagrant can be hacked into shape with the
22
+ [vagrant-smartos/vagrant-smartos-guest](https://github.com/vagrant-smartos/vagrant-smartos-guest)
23
+ plugin. This tracks fixes that have been submitted as pull requests to
24
+ Vagrant but may have not been yet released.
25
+
26
+ ## Quick Start Installation
27
+
28
+ ```bash
29
+ vagrant plugin install vagrant-smartos-zones
30
+ mkdir <directory_name>
31
+ cd <directory_name>
32
+ curl -sO https://raw.githubusercontent.com/vagrant-smartos/vagrant-smartos-zones/master/examples/Vagrantfile
33
+ vagrant up
34
+ vagrant ssh
35
+ ```
36
+
37
+
38
+ ## Slow Start Installation
39
+
40
+ ```bash
41
+ vagrant plugin install vagrant-smartos-zones
42
+ ```
43
+
44
+ If you are using a development version of vagrant, or would like to use
45
+ an unreleased version of this plugin, add the following to your Gemfile.
46
+
47
+ ```ruby
48
+ group :plugins do
49
+ gem 'vagrant-smartos-zones', github: 'vagrant-smartos/vagrant-smartos-zones'
50
+ end
51
+ ```
52
+
53
+ In a local checkout of this repository, the following will work:
54
+
55
+ ```bash
56
+ gem install bundler
57
+ bundle
58
+ bundle exec vagrant up
59
+ bundle exec vagrant ssh
60
+ ```
61
+
62
+ Please note that this will install vagrant into your local ruby
63
+ environment, which may overwrite or conflict with the normal vagrant
64
+ version installed in your system.
65
+
66
+
67
+ ## Usage
68
+
69
+ ```ruby
70
+ Vagrant.configure('2') do |config|
71
+ config.vm.provider "virtualbox" do |v|
72
+ v.memory = 3072
73
+ end
74
+
75
+ # See https://vagrantcloud.com/livinginthepast for SmartOS boxes
76
+ config.vm.box = "livinginthepast/smartos"
77
+ config.vm.synced_folder ".", "/vagrant", disabled: true
78
+
79
+ # This is required for the commands that talk to the global zone
80
+ config.vm.communicator = 'smartos'
81
+
82
+ # livinginthepast boxes include a default platform_image. Set
83
+ # here to download/use a different image.
84
+ # config.global_zone.platform_image = 'latest'
85
+ # config.global_zone.platform_image = '20140312T071408Z'
86
+
87
+ config.zone.name = 'base64'
88
+ config.zone.brand = 'joyent'
89
+ config.zone.image = 'c353c568-69ad-11e3-a248-db288786ea63'
90
+ config.zone.memory = 2048
91
+ config.zone.disk_size = 5
92
+
93
+ config.zone.synced_folder ".", "/vagrant", type: 'rsync'
94
+ end
95
+ ```
96
+
97
+ Download or interact with SmartOS platform images:
98
+
99
+ ```bash
100
+ vagrant smartos latest
101
+ vagrant smartos list
102
+ vagrant smartos install [platform_image]
103
+ ```
104
+
105
+ Interact with zones running in a box:
106
+
107
+ ```bash
108
+ vagrant zones list
109
+ vagrant zones show [name]
110
+ vagrant zones start [name]
111
+ vagrant zones stop [name]
112
+ ```
113
+
114
+ ## Single zone usage
115
+
116
+ When a single zone is configured (currently the only configuration
117
+ possible), a `zonegate` service is enabled in the global zone. This
118
+ makes it so that inbound packets in the global zone are forwarded to the
119
+ zone.
120
+
121
+ #### vagrant ssh
122
+
123
+ When `zonegate` is disabled or when a zone is not running, then `vagrant
124
+ ssh` will access the global zone. When a zone is running while
125
+ `zonegate` is enabled, then `vagrant ssh` will access the zone.
126
+
127
+ ```bash
128
+ vagrant ssh
129
+ ```
130
+
131
+ #### vagrant global-zone ssh
132
+
133
+ A secondary port forward is installed in VirtualBox, which allows us to
134
+ access the global zone even when `zonegate` forwards normal ssh to the
135
+ zone.
136
+
137
+ ```bash
138
+ vagrant global-zone ssh
139
+ ```
140
+
141
+ #### vagrant zlogin [name]
142
+
143
+ This command accesses the zone, but through the global zone. It uses the
144
+ global zone ssh port to connect to the global zone, then runs `zlogin`
145
+ to access the zone.
146
+
147
+ This can by handy when, for instance, SSH becomes broken in the zone.
148
+
149
+ ```bash
150
+ vagrant zlogin [name]
151
+ ```
152
+
153
+ ## Platform images
154
+
155
+ This plugin expects the Vagrant box to boot SmartOS from a mounted ISO
156
+ file, known as a platform image. To facilitate updates to the platform
157
+ image without having to continually create new boxes, the plugin
158
+ downloads platform image into a user's `.vagrant.d` directory, and then
159
+ swaps out the ISO mounted in the Vagrant box with the one configured in
160
+ the Vagrantfile.
161
+
162
+ To help with this, `vagrant-smartos-zones` provides the `vagrant
163
+ smartos` subcommand.
164
+
165
+ Show the name of the most up-to-date platform version hosted by Joyent:
166
+
167
+ ```bash
168
+ vagrant smartos latest
169
+ ```
170
+
171
+ List all locally-installed platform images:
172
+
173
+ ```bash
174
+ vagrant smartos list
175
+ ```
176
+
177
+ Download a new platform image:
178
+
179
+ ```bash
180
+ vagrant smartos install [platform-image]
181
+ ```
182
+
183
+ #### Using an arbitrary platform image url
184
+
185
+ An arbitrary URL can be used to download SmartOS platform images.
186
+ When doing so, no checksum validation is performed (so if the image
187
+ is interrupted when downloading, you may end up with a corrupt ISO
188
+ file).
189
+
190
+ When using an arbitrary URL for the platform image, make sure you set
191
+ both `platform_image` and `platform_image_url` and include the full
192
+ URL to the ISO file. In this case, `platform_image` will be used to name
193
+ (and find) the file in the local file system.
194
+
195
+ ```ruby
196
+ config.global_zone.platform_image = 'omglol-2131234'
197
+ config.global_zone.platform_image_url = 'http://example.com/path/to/smartos-2131234.iso'
198
+ ```
199
+
200
+ ## Synced Folders
201
+
202
+ Vagrant allows synced folders into any SmartOS guest. When the guest is
203
+ a global zone, be aware that the root partition is a RAM disk of a
204
+ little more than 256M.
205
+
206
+ #### VirtualBox guest additions
207
+
208
+ Shared folders using VirtualBox guest additions currently do not work.
209
+
210
+ #### Rsync
211
+
212
+ In single-zone environments, synced folders of type `rsync` work as
213
+ normal. `zonegate` forwards all packets into the zone, and the built-in
214
+ synced folders code in Vagrant runs after the zone is configured.
215
+
216
+ ```ruby
217
+ # Vagrantfile
218
+ config.vm.synced_folder ".", "/vagrant", type: "rsync"
219
+ ```
220
+
221
+ #### NFS
222
+
223
+ Pending.
224
+
225
+ ## User management
226
+
227
+ The vagrant box with the global zone requires a `vagrant` user and
228
+ group with which to connect. This user should have `Primary
229
+ Administrator` privileges. When creating a local zone, a `vagrant`
230
+ user and group are also created in the zone.
231
+
232
+ ## References / Alternatives
233
+
234
+ Any success of this project depends heavily on the work of others,
235
+ which I've either learned from or pulled in directly.
236
+
237
+ * https://github.com/joshado/vagrant-smartos - Vagrant plugin for
238
+ managing zones on a global zone running on an arbitary IP.
239
+ * https://github.com/groundwater/vagrant-smartos - Scripts for
240
+ creating stand-alone boxes where GZ networking is twerked to pretend
241
+ that the local zone is the only thing in the box.
242
+ * http://dlc-int.openindiana.org/aszeszo/vagrant - aszeszo's work,
243
+ which led to the above repo.
244
+ * http://cuddletech.com/blog/?p=821 - [@benr](https://github.com/benr)'s
245
+ writeup of the above work.
246
+ * http://vagrantup.com - Thank you so much to Michell Hashimoto for
247
+ making Vagrant in the first place.
248
+
249
+ Please forgive any lapses of acknowledgment. I've read so many blog
250
+ posts and so much source code in the course of working on this, many
251
+ references have fallen by the wayside.
252
+
253
+ ## Caveats
254
+
255
+ * Only one local zone per box. Working on it.
256
+ * Usage may change with each prerelease version until I get it
257
+ right. Until a non .pre version is released, check commit logs.
258
+
259
+ ## Contributing
260
+
261
+ 1. Fork it ( https://github.com/vagrant-smartos/vagrant-smartos-zones/fork )
262
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
263
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
264
+ 4. Push to the branch (`git push origin my-new-feature`)
265
+ 5. Create new Pull Request
266
+
267
+ When creating a new Pull Request, `/cc @sax` in the notes to make sure
268
+ I get an email about it.
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require 'bundler/gem_tasks'
2
+ require 'rubocop/rake_task'
3
+
4
+ RuboCop::RakeTask.new
5
+
6
+ task default: [:rubocop]
data/Vagrantfile ADDED
@@ -0,0 +1,29 @@
1
+ # This Vagrantfile exists for the purposes of development on
2
+ # this plugin.
3
+ Vagrant.configure('2') do |config|
4
+ config.vm.provider 'virtualbox' do |v|
5
+ v.memory = 2048
6
+ end
7
+
8
+ config.ssh.insert_key = false
9
+
10
+ # See https://vagrantcloud.com/livinginthepast for SmartOS boxes
11
+ config.vm.box = 'livinginthepast/smartos-base64'
12
+ config.vm.communicator = 'smartos'
13
+
14
+ # livinginthepast boxes include a default platform_image. Set
15
+ # here to download/use a different image.
16
+ config.global_zone.platform_image = 'latest'
17
+
18
+ config.zone.name = 'base64'
19
+ config.zone.brand = 'joyent'
20
+ config.zone.image = 'd34c301e-10c3-11e4-9b79-5f67ca448df0'
21
+ config.zone.memory = 1536
22
+ config.zone.disk_size = 5
23
+
24
+ # config.zone.name = 'lx'
25
+ # config.zone.brand = 'lx'
26
+ # config.zone.image = 'b7493690-f019-4612-958b-bab5f844283e'
27
+ # config.zone.memory = 1536
28
+ # config.zone.disk_size = 5
29
+ end
@@ -0,0 +1,18 @@
1
+ Vagrant.configure('2') do |config|
2
+ config.vm.provider 'virtualbox' do |v|
3
+ v.memory = 2048
4
+ end
5
+
6
+ # See https://vagrantcloud.com/livinginthepast for SmartOS boxes
7
+ config.vm.box = 'livinginthepast/smartos-base64'
8
+ config.vm.synced_folder '.', '/vagrant', disabled: true
9
+ config.vm.communicator = 'smartos'
10
+
11
+ config.global_zone.platform_image = 'latest'
12
+
13
+ config.zone.name = 'base64'
14
+ config.zone.brand = 'joyent'
15
+ config.zone.image = 'd34c301e-10c3-11e4-9b79-5f67ca448df0'
16
+ config.zone.memory = 1536
17
+ config.zone.disk_size = 5
18
+ end
@@ -0,0 +1,33 @@
1
+ #!/usr/bin/ruby
2
+ #^ syntax highlighting
3
+
4
+ Vagrant.configure('2') do |config|
5
+ config.vm.provider 'virtualbox' do |v|
6
+ v.memory = 2048
7
+ end
8
+
9
+ # See https://vagrantcloud.com/livinginthepast for SmartOS boxes
10
+ config.vm.box = 'livinginthepast/smartos-base64'
11
+ config.vm.synced_folder '.', '/vagrant', disabled: true
12
+ config.vm.communicator = 'smartos'
13
+
14
+ config.global_zone.platform_image = 'latest'
15
+
16
+ config.zone.name = 'base64'
17
+ config.zone.brand = 'joyent'
18
+ config.zone.image = 'd34c301e-10c3-11e4-9b79-5f67ca448df0'
19
+ config.zone.memory = 1536
20
+ config.zone.disk_size = 5
21
+
22
+ config.vm.provision "shell",
23
+ inline: "sudo pkgin -y install ruby212 build-essential && gem install chef --no-ri --no-rdoc"
24
+
25
+ config.vm.provision :chef_client do |chef|
26
+ chef.chef_server_url = "#{ENV['CHEF_SERVER_URL']}"
27
+ chef.validation_key_path = "#{ENV['HOME']}/.ssh/#{ENV['VALIDATION_CLIENT_NAME']}.pem"
28
+ chef.validation_client_name = "#{ENV['VALIDATION_CLIENT_NAME']}"
29
+ chef.node_name = "#{config.zone.name}-vagrant"
30
+ chef.provisioning_path = "/etc/chef"
31
+ chef.add_role("base")
32
+ end
33
+ end
@@ -0,0 +1,22 @@
1
+ #!/usr/bin/ruby
2
+ #^ syntax highlighting
3
+
4
+ Vagrant.configure('2') do |config|
5
+ config.vm.provider 'virtualbox' do |v|
6
+ v.memory = 2048
7
+ end
8
+
9
+ # See https://vagrantcloud.com/livinginthepast for SmartOS boxes
10
+ config.vm.box = 'livinginthepast/smartos-base64'
11
+ config.vm.synced_folder '.', '/vagrant', disabled: true
12
+ config.vm.communicator = 'smartos'
13
+
14
+ config.global_zone.platform_image = 'hourly-20141121'
15
+ config.global_zone.platform_image_url = 'https://us-east.manta.joyent.com/nahamu/public/smartos/platform-hourly.iso'
16
+
17
+ config.zone.name = 'lx'
18
+ config.zone.brand = 'lx'
19
+ config.zone.image = 'b7493690-f019-4612-958b-bab5f844283e'
20
+ config.zone.memory = 1536
21
+ config.zone.disk_size = 5
22
+ end
@@ -0,0 +1,23 @@
1
+ #!/usr/bin/ruby
2
+ #^ syntax highlighting
3
+
4
+ Vagrant.configure('2') do |config|
5
+ config.vm.provider "virtualbox" do |v|
6
+ v.memory = 2048
7
+ end
8
+
9
+ # See https://vagrantcloud.com/livinginthepast for SmartOS boxes
10
+ config.vm.box = "livinginthepast/smartos-base64"
11
+ config.vm.synced_folder ".", "/vagrant", disabled: true
12
+ config.vm.communicator = 'smartos'
13
+
14
+ config.vm.synced_folder ".", "/vagrant", type: "rsync"
15
+
16
+ config.global_zone.platform_image = 'latest'
17
+
18
+ config.zone.name = 'base64'
19
+ config.zone.brand = 'joyent'
20
+ config.zone.image = 'd34c301e-10c3-11e4-9b79-5f67ca448df0'
21
+ config.zone.memory = 1536
22
+ config.zone.disk_size = 5
23
+ end
@@ -0,0 +1,15 @@
1
+ #!/usr/bin/bash
2
+
3
+ dladm create-etherstub stub0
4
+ dladm create-vnic -l stub0 vnic0
5
+ ipadm create-if vnic0
6
+ ipadm create-addr -T static -a 10.0.0.1/24 vnic0/static
7
+
8
+ echo 'map e1000g0 10.0.0.0/24 -> 0.0.0.0/32' | ipnat -f -
9
+
10
+ # When we SSH into port 2222, ensure that that goes to 22 in the GZ
11
+ # and is never forwarded to the zone.
12
+ echo 'rdr e1000g0 0.0.0.0/0 port 2222 -> 10.0.0.1 port 22' | ipnat -f -
13
+
14
+ routeadm -u -e ipv4-forwarding
15
+ routeadm -u -e ipv4-routing
@@ -0,0 +1,31 @@
1
+ <?xml version='1.0'?>
2
+ <!DOCTYPE service_bundle SYSTEM '/usr/share/lib/xml/dtd/service_bundle.dtd.1'>
3
+ <service_bundle type='manifest' name='export'>
4
+ <service name='vagrant/create-gz-vnic' type='service' version='0'>
5
+ <create_default_instance enabled='true'/>
6
+ <single_instance/>
7
+ <dependency name='fs-local' grouping='require_all' restart_on='error' type='service'>
8
+ <service_fmri value='svc:/system/filesystem/local'/>
9
+ </dependency>
10
+ <dependency name='fs-root' grouping='require_all' restart_on='error' type='service'>
11
+ <service_fmri value='svc:/system/filesystem/root'/>
12
+ </dependency>
13
+ <dependent name='zones' restart_on='none' grouping='optional_all'>
14
+ <service_fmri value='svc:/system/zones'/>
15
+ </dependent>
16
+ <method_context/>
17
+ <exec_method name='start' type='method' exec='/opt/custom/method/create_gz_vnic' timeout_seconds='60'/>
18
+ <exec_method name='stop' type='method' exec=':true' timeout_seconds='60'/>
19
+ <property_group name='startd' type='framework'>
20
+ <propval name='duration' type='astring' value='transient'/>
21
+ <propval name='ignore_error' type='astring' value='signal'/>
22
+ </property_group>
23
+ <property_group name='application' type='application'/>
24
+ <stability value='Evolving'/>
25
+ <template>
26
+ <common_name>
27
+ <loctext xml:lang='C'>Ensure </loctext>
28
+ </common_name>
29
+ </template>
30
+ </service>
31
+ </service_bundle>
@@ -0,0 +1,34 @@
1
+ <?xml version='1.0'?>
2
+ <!DOCTYPE service_bundle SYSTEM '/usr/share/lib/xml/dtd/service_bundle.dtd.1'>
3
+ <service_bundle type='manifest' name='export'>
4
+ <service name='site/zonegate' type='service' version='0'>
5
+ <create_default_instance enabled='false'/>
6
+ <single_instance/>
7
+ <dependency name='fs-local' grouping='require_all' restart_on='error' type='service'>
8
+ <service_fmri value='svc:/system/filesystem/local'/>
9
+ </dependency>
10
+ <dependency name='fs-root' grouping='require_all' restart_on='error' type='service'>
11
+ <service_fmri value='svc:/system/filesystem/root'/>
12
+ </dependency>
13
+ <dependency name='ipfilter' grouping='require_all' restart_on='error' type='service'>
14
+ <service_fmri value='svc:/network/ipfilter'/>
15
+ </dependency>
16
+ <method_context>
17
+ <method_environment>
18
+ <envvar name="PATH" value="/opt/custom/method/zonegate:/usr/bin:/usr/sbin"/>
19
+ </method_environment>
20
+ </method_context>
21
+ <exec_method name='start' type='method' exec='/opt/custom/method/zonegate/zonegate start' timeout_seconds='60'/>
22
+ <exec_method name='stop' type='method' exec='/opt/custom/method/zonegate/zonegate stop' timeout_seconds='60'/>
23
+ <property_group name='startd' type='framework'>
24
+ <propval name='ignore_error' type='astring' value='signal'/>
25
+ </property_group>
26
+ <property_group name='application' type='application'/>
27
+ <stability value='Evolving'/>
28
+ <template>
29
+ <common_name>
30
+ <loctext xml:lang='C'>Ensure </loctext>
31
+ </common_name>
32
+ </template>
33
+ </service>
34
+ </service_bundle>
@@ -0,0 +1,60 @@
1
+ #!/usr/bin/bash
2
+
3
+ . /lib/svc/share/smf_include.sh
4
+
5
+ contract() {
6
+ echo $(svcprop -p restarter/contract $SMF_FMRI)
7
+ }
8
+
9
+ disable_nat_rules() {
10
+ IFS=$'\n\t'
11
+ # disable any running nat rules
12
+ for zone in $(/usr/sbin/zoneadm list -ip | grep running | tail -n +2 | awk -F":" '{ print $2 }');
13
+ do
14
+ zonenat "${zone}:down"
15
+ done
16
+ }
17
+
18
+ start_zonenat() {
19
+ # then we run a dtrace monitor and pipe the output as we receive it
20
+ zonemon |
21
+ while IFS= read -r line
22
+ do
23
+ zonenat "$line"
24
+ done
25
+ }
26
+
27
+ stop_zonenat() {
28
+ local contract_id=$(contract)
29
+ smf_kill_contract ${contract_id} TERM
30
+ }
31
+
32
+ nat_existing_zone() {
33
+ IFS=$'\n\t'
34
+ # first, we need to nat the zone if it's already running
35
+ for zone in $(/usr/sbin/zoneadm list -ip | grep running | tail -n +2 | awk -F":" '{ print $2 }');
36
+ do
37
+ zonenat "${zone}:up"
38
+ done
39
+ }
40
+
41
+ start() {
42
+ echo 'enabling zonegate'
43
+ nat_existing_zone
44
+ start_zonenat &
45
+ }
46
+
47
+ stop() {
48
+ echo 'disabling zonegate'
49
+ disable_nat_rules
50
+ stop_zonenat
51
+ }
52
+
53
+ case $SMF_METHOD in
54
+ start)
55
+ start
56
+ ;;
57
+ stop)
58
+ stop
59
+ ;;
60
+ esac
@@ -0,0 +1,15 @@
1
+ #!/usr/sbin/dtrace -qs
2
+
3
+ /* up */
4
+ zone_status_set:entry
5
+ / (args[0]->zone_id) != 0 && args[1] == 4 /
6
+ {
7
+ printf("%s:up\n", stringof(args[0]->zone_name));
8
+ }
9
+
10
+ /* down */
11
+ zone_status_set:entry
12
+ / (args[0]->zone_id) != 0 && args[1] == 7 /
13
+ {
14
+ printf("%s:down\n", stringof(args[0]->zone_name));
15
+ }