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
@@ -0,0 +1,136 @@
1
+ require 'vagrant'
2
+ require 'vagrant/smartos/zones/errors'
3
+ require 'vagrant/smartos/zones/models/zone'
4
+ require 'vagrant/smartos/zones/util/snapshots'
5
+ require 'vagrant/smartos/zones/util/zone_info'
6
+ require_relative 'multi_command'
7
+
8
+ module Vagrant
9
+ module Smartos
10
+ module Zones
11
+ module Command
12
+ class Zones < Vagrant.plugin('2', :command)
13
+ include MultiCommand
14
+
15
+ COMMANDS = %w(create destroy list show snapshot start stop).freeze
16
+
17
+ OPTION_PARSER = OptionParser.new do |o|
18
+ o.banner = 'Usage: vagrant zones [command] [name]'
19
+ o.separator ''
20
+ o.separator 'Commands:'
21
+ o.separator ' list show status of zones'
22
+ o.separator ' create [name] create or update zone with alias [name]'
23
+ o.separator ' destroy [name] delete zone with alias [name]'
24
+ o.separator ' show [name] show info on zone with alias [name]'
25
+ o.separator ' snapshot [action] [name] [snapshot] snapshot the ZFS filesystem for [name]'
26
+ o.separator ' actions: list, create, delete, rollback'
27
+ o.separator ' start [name] start zone with alias [name]'
28
+ o.separator ' stop [name] stop zone with alias [name]'
29
+ o.separator ''
30
+ o.separator 'Options:'
31
+ o.separator ''
32
+ end
33
+
34
+ def self.synopsis
35
+ 'View and interact with SmartOS zones'
36
+ end
37
+
38
+ def execute
39
+ process_subcommand
40
+ end
41
+
42
+ def create(name)
43
+ zones.create(name).tap do |zone|
44
+ return unless zone
45
+ @env.ui.info(I18n.t('vagrant.smartos.zones.commands.zones.create',
46
+ name: zone.name, state: zone.state,
47
+ uuid: zone.uuid, brand: zone.brand,
48
+ image: zone.image),
49
+ prefix: false)
50
+ end
51
+ end
52
+
53
+ def destroy(name)
54
+ with_zone(name) do |zone|
55
+ zone.destroy
56
+ @env.ui.info(I18n.t('vagrant.smartos.zones.commands.zones.destroyed',
57
+ name: zone.name, state: zone.state,
58
+ uuid: zone.uuid, brand: zone.brand,
59
+ image: zone.image))
60
+ end
61
+ end
62
+
63
+ def list(*_args)
64
+ with_target_vms('default') do |machine|
65
+ zones = Models::Zone.all(machine).map do |zone|
66
+ [zone.name.to_s.ljust(25), zone.state.to_s.ljust(10), zone.uuid].join(' ')
67
+ end
68
+ @env.ui.info(I18n.t('vagrant.smartos.zones.commands.zones.list',
69
+ zones: zones.join("\n")), prefix: false)
70
+ end
71
+ end
72
+
73
+ def show(name)
74
+ with_zone(name) do |zone|
75
+ @env.ui.info(I18n.t('vagrant.smartos.zones.commands.zones.show',
76
+ name: zone.name, state: zone.state,
77
+ uuid: zone.uuid, brand: zone.brand,
78
+ image: zone.image),
79
+ prefix: false)
80
+ end
81
+ end
82
+
83
+ def snapshot(action = nil, name = nil, snapshot = nil)
84
+ fail_options! unless action && name
85
+ with_target_vms('default') do |machine|
86
+ Util::Snapshots.new(machine, name).run(action, snapshot)
87
+ end
88
+ end
89
+
90
+ def start(name)
91
+ with_zone(name) do |zone|
92
+ zone.start
93
+ @env.ui.info(I18n.t('vagrant.smartos.zones.commands.zones.start',
94
+ name: zone.name, state: zone.state,
95
+ uuid: zone.uuid, brand: zone.brand,
96
+ image: zone.image))
97
+ end
98
+ end
99
+
100
+ def stop(name)
101
+ with_zone(name) do |zone|
102
+ zone.stop
103
+ @env.ui.info(I18n.t('vagrant.smartos.zones.commands.zones.stop',
104
+ name: zone.name, state: zone.state,
105
+ uuid: zone.uuid, brand: zone.brand,
106
+ image: zone.image))
107
+ end
108
+ end
109
+
110
+ private
111
+
112
+ def zones
113
+ zones = nil
114
+ with_target_vms('default') { |machine| zones = Util::ZoneInfo.new(machine) }
115
+ zones
116
+ end
117
+
118
+ def ui
119
+ @env.ui
120
+ end
121
+
122
+ def with_zone(name)
123
+ with_target_vms('default', single_target: true) do |machine|
124
+ Models::Zone.find(machine, name).tap do |zone|
125
+ yield zone
126
+ end
127
+ end
128
+ rescue ZoneNotFound
129
+ ui.warn(I18n.t('vagrant.smartos.zones.warning.zone_not_found',
130
+ name: name), prefix: false)
131
+ end
132
+ end
133
+ end
134
+ end
135
+ end
136
+ end
@@ -0,0 +1,87 @@
1
+ require 'vagrant/smartos/zones/util/global_zone/connection'
2
+
3
+ module Vagrant
4
+ module Smartos
5
+ module Zones
6
+ module Communicator
7
+ class Smartos < Vagrant.plugin('2').manager.communicators[:ssh]
8
+ def initialize(machine)
9
+ @machine = machine
10
+ super
11
+ end
12
+
13
+ # rubocop:disable Metrics/MethodLength
14
+ def gz_execute(command, opts = {}, &block)
15
+ opts = {
16
+ error_check: true,
17
+ error_class: Vagrant::Errors::VagrantError,
18
+ error_key: :ssh_bad_exit_status,
19
+ good_exit: 0,
20
+ command: command,
21
+ shell: nil,
22
+ sudo: false
23
+ }.merge(opts)
24
+
25
+ opts[:good_exit] = Array(opts[:good_exit])
26
+
27
+ # Connect via SSH and execute the command in the shell.
28
+ stdout = ''
29
+ stderr = ''
30
+ global_zone_connector.connect
31
+
32
+ begin
33
+ generic_ssh_info = @connection_ssh_info
34
+ @connection_ssh_info = global_zone_connector.ssh_info
35
+
36
+ exit_status = global_zone_connector.with_connection do |connection|
37
+ shell_opts = {
38
+ sudo: opts[:sudo],
39
+ shell: opts[:shell]
40
+ }
41
+
42
+ shell_execute(connection, command, **shell_opts) do |type, data|
43
+ if type == :stdout
44
+ stdout += data
45
+ elsif type == :stderr
46
+ stderr += data
47
+ end
48
+
49
+ block.call(type, data) if block
50
+ end
51
+ end
52
+ ensure
53
+ @connection_ssh_info = generic_ssh_info
54
+ end
55
+
56
+ # Check for any errors
57
+ if opts[:error_check] && !opts[:good_exit].include?(exit_status)
58
+ # The error classes expect the translation key to be _key,
59
+ # but that makes for an ugly configuration parameter, so we
60
+ # set it here from `error_key`
61
+ error_opts = opts.merge(
62
+ _key: opts[:error_key],
63
+ stdout: stdout,
64
+ stderr: stderr
65
+ )
66
+ raise opts[:error_class], error_opts
67
+ end
68
+
69
+ # Return the exit status
70
+ exit_status
71
+ end
72
+
73
+ def gz_test(command, opts = nil)
74
+ opts = { error_check: false }.merge(opts || {})
75
+ gz_execute(command, opts) == 0
76
+ end
77
+
78
+ private
79
+
80
+ def global_zone_connector
81
+ @global_zone_connector ||= Vagrant::Smartos::Zones::Util::GlobalZone::Connection.new(@machine, @logger)
82
+ end
83
+ end
84
+ end
85
+ end
86
+ end
87
+ end
@@ -0,0 +1,26 @@
1
+ require 'vagrant'
2
+
3
+ module Vagrant
4
+ module Smartos
5
+ module Zones
6
+ module Config
7
+ class GlobalZone < Vagrant.plugin('2', :config)
8
+ attr_accessor :platform_image, :platform_image_url, :ssh_port, :forwarded_ssh_port
9
+
10
+ def initialize
11
+ @platform_image = UNSET_VALUE
12
+ @platform_image_url = UNSET_VALUE
13
+ @ssh_port = UNSET_VALUE
14
+ @forwarded_ssh_port = UNSET_VALUE
15
+ end
16
+
17
+ def finalize!
18
+ @platform_image = 'latest' if @platform_image == UNSET_VALUE
19
+ @ssh_port = 2222 if @ssh_port == UNSET_VALUE
20
+ @forwarded_ssh_port = 22_022 if @forwarded_ssh_port == UNSET_VALUE
21
+ end
22
+ end
23
+ end
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,33 @@
1
+ require 'vagrant'
2
+
3
+ module Vagrant
4
+ module Smartos
5
+ module Zones
6
+ module Config
7
+ class Zone < Vagrant.plugin('2', :config)
8
+ attr_accessor :brand, :disk_size, :image, :kernel_version, :memory, :name
9
+ attr_reader :synced_folders
10
+
11
+ def initialize
12
+ @brand = UNSET_VALUE
13
+ @disk_size = UNSET_VALUE
14
+ @image = UNSET_VALUE
15
+ @kernel_version = UNSET_VALUE
16
+ @memory = UNSET_VALUE
17
+ @name = UNSET_VALUE
18
+ @synced_folders = []
19
+ end
20
+
21
+ def synced_folder(*args)
22
+ @synced_folders << args
23
+ end
24
+
25
+ def finalize!
26
+ @brand = 'joyent' if @brand == UNSET_VALUE
27
+ @kernel_version = '3.16' if @kernel_version == UNSET_VALUE
28
+ end
29
+ end
30
+ end
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,9 @@
1
+ module Vagrant
2
+ module Smartos
3
+ module Zones
4
+ class Error < StandardError; end
5
+ class SnapshotNotFound < Error; end
6
+ class ZoneNotFound < Error; end
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,25 @@
1
+ require 'vagrant'
2
+
3
+ module Vagrant
4
+ module Smartos
5
+ module Zones
6
+ class Guest < Vagrant.plugin('2', :guest)
7
+ TEST_COMMAND = "grep 'SmartOS [0-9]\\{8\\}T[0-9]\\{6\\}Z' /etc/release"
8
+
9
+ def detect?(machine)
10
+ @machine = machine
11
+ ssh_test || gz_test
12
+ end
13
+
14
+ def ssh_test
15
+ @machine.communicate.test(TEST_COMMAND)
16
+ end
17
+
18
+ def gz_test
19
+ return false unless @machine.communicate.respond_to?(:gz_test)
20
+ @machine.communicate.gz_test(TEST_COMMAND)
21
+ end
22
+ end
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,41 @@
1
+ # rubocop:disable all
2
+ module Vagrant
3
+ module Smartos
4
+ module Zones
5
+ class Plugin < Vagrant.plugin("2")
6
+ manage_zones = lambda do |hook|
7
+ require_relative 'action'
8
+ hook.before(::VagrantPlugins::ProviderVirtualBox::Action::PrepareForwardedPortCollisionParams, Vagrant::Smartos::Zones::Action.forward_gz_ports)
9
+ hook.after(::VagrantPlugins::ProviderVirtualBox::Action::SaneDefaults, Vagrant::Smartos::Zones::Action.virtualbox_platform_iso)
10
+ hook.before(::VagrantPlugins::ProviderVirtualBox::Action::Network, Vagrant::Smartos::Zones::Action.create_gz_vnic)
11
+
12
+ hook.before(Vagrant::Smartos::Zones::Action::CreateGZVnic, Vagrant::Smartos::Zones::Action.install_zone_gate)
13
+ hook.before(Vagrant::Smartos::Zones::Action::ZoneGate::Install, Vagrant::Smartos::Zones::Action.zone_create)
14
+ hook.before(Vagrant::Smartos::Zones::Action::Zone::Create, Vagrant::Smartos::Zones::Action.configure_zone_synced_folders)
15
+ hook.before(Vagrant::Smartos::Zones::Action::Zone::Create, Vagrant::Smartos::Zones::Action.zone_start)
16
+
17
+ # Currently if this runs before a zone is created, other capabilities (such as creating zone users)
18
+ # fail with the error that the machine is not ready for guest communication.
19
+ hook.before(Vagrant::Smartos::Zones::Action::Zone::Create, Vagrant::Smartos::Zones::Action.enable_zone_gate)
20
+ hook.after(Vagrant::Smartos::Zones::Action::ConfigureZoneSyncedFolders, Vagrant::Action::Builtin::SyncedFolders)
21
+ end
22
+
23
+ zone_start = lambda do |hook|
24
+ require_relative 'action'
25
+ hook.before(::Vagrant::Action::Builtin::WaitForCommunicator, Vagrant::Smartos::Zones::Action.zone_start)
26
+ end
27
+
28
+ zone_stop = lambda do |hook|
29
+ require_relative 'action'
30
+ hook.before(::Vagrant::Action::Builtin::GracefulHalt, Vagrant::Smartos::Zones::Action.zone_stop)
31
+ end
32
+
33
+ action_hook('smartos-zones-up', :machine_action_up, &manage_zones)
34
+ action_hook('smartos-zones-reload', :machine_action_reload, &manage_zones)
35
+ action_hook('smartos-zones-provision', :machine_action_provision, &manage_zones)
36
+ action_hook('smartos-zones-halt', :machine_action_halt, &zone_stop)
37
+ action_hook('smartos-zones-resume', :machine_action_resume, &zone_start)
38
+ end
39
+ end
40
+ end
41
+ end
@@ -0,0 +1,27 @@
1
+ require 'vagrant/smartos/zones/models/snapshot'
2
+ require 'vagrant/smartos/zones/util/global_zone/helper'
3
+
4
+ module Vagrant
5
+ module Smartos
6
+ module Zones
7
+ module Models
8
+ class Dataset
9
+ include Util::GlobalZone::Helper
10
+
11
+ def self.create(name, zone)
12
+ Models::Snapshot.around(zone) do
13
+ zone.zlogin('\'find /var/log -type f -exec truncate --size 0 {} \;\'')
14
+ zone.zlogin('sm-prepare-image -y')
15
+ zone.stop
16
+ Models::Snapshot.around(zone) do |snapshot|
17
+ cmd = 'pfexec /usr/bin/bash -l -c "/usr/sbin/zfs send %s | /usr/bin/bzip2 > /zones/%s.zfs.bz2"'
18
+ with_gz(zone.machine, cmd % [snapshot.path, name])
19
+ end
20
+ end
21
+ zone.start
22
+ end
23
+ end
24
+ end
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,71 @@
1
+ require 'vagrant/smartos/zones/errors'
2
+ require 'vagrant/smartos/zones/util/global_zone/helper'
3
+
4
+ module Vagrant
5
+ module Smartos
6
+ module Zones
7
+ module Models
8
+ class Snapshot
9
+ include Util::GlobalZone::Helper
10
+
11
+ attr_accessor :machine, :zone, :name, :created_at, :space_used
12
+
13
+ def self.around(zone, &block)
14
+ snapshot_name = "before_#{Time.now.to_i}"
15
+ snapshot = create(snapshot_name, zone)
16
+ if block.arity.eql?(1)
17
+ block.call snapshot
18
+ else
19
+ block.call
20
+ end
21
+ snapshot.rollback
22
+ snapshot.destroy
23
+ end
24
+
25
+ def self.all(zone)
26
+ snapshots = []
27
+ cmd = "pfexec zfs list -t snapshot -H -r -o name,creation,used zones/#{zone.uuid}"
28
+ with_gz(zone.machine, cmd) do |output|
29
+ break if output.include?('no datasets available')
30
+ snapshots += output.split("\n").map { |l| from_line(l, zone) }
31
+ end
32
+ snapshots
33
+ end
34
+
35
+ def self.create(name, zone)
36
+ cmd = "pfexec zfs snapshot zones/#{zone.uuid}@#{name}"
37
+ with_gz(zone.machine, cmd)
38
+ find(name, zone)
39
+ end
40
+
41
+ def self.find(name, zone)
42
+ all(zone).find { |snapshot| snapshot.name == name } || raise(SnapshotNotFound)
43
+ end
44
+
45
+ def self.from_line(l, zone)
46
+ name, created_at, used = l.split("\t")
47
+ new.tap do |s|
48
+ s.machine = zone.machine
49
+ s.zone = zone
50
+ s.name = name.split('@').last
51
+ s.created_at = created_at
52
+ s.space_used = used
53
+ end
54
+ end
55
+
56
+ def path
57
+ "zones/#{zone.uuid}@#{name}"
58
+ end
59
+
60
+ def destroy
61
+ with_gz("pfexec zfs destroy #{path}")
62
+ end
63
+
64
+ def rollback
65
+ with_gz("pfexec zfs rollback -r #{path}")
66
+ end
67
+ end
68
+ end
69
+ end
70
+ end
71
+ end
@@ -0,0 +1,80 @@
1
+ require 'vagrant/smartos/zones/errors'
2
+ require 'vagrant/smartos/zones/util/global_zone/helper'
3
+
4
+ module Vagrant
5
+ module Smartos
6
+ module Zones
7
+ module Models
8
+ class Zone
9
+ include Util::GlobalZone::Helper
10
+
11
+ attr_accessor :machine, :name, :state, :uuid, :brand, :image
12
+
13
+ def self.all(machine)
14
+ zones = []
15
+ with_gz(machine, 'pfexec vmadm lookup -j') do |output|
16
+ hashes = JSON.parse(output)
17
+ zones += hashes.map { |h| from_hash(h, machine) }
18
+ end
19
+ zones
20
+ end
21
+
22
+ def self.find(machine, name)
23
+ zone_hash = {}
24
+ finder = "pfexec vmadm lookup -j -o uuid,alias,state,image_uuid,brand alias=#{name}"
25
+ with_gz(machine, finder) do |output|
26
+ hash = JSON.parse(output).first
27
+ raise ZoneNotFound unless hash
28
+ zone_hash.merge!(hash)
29
+ end
30
+ from_hash(zone_hash, machine)
31
+ end
32
+
33
+ def self.from_hash(zone, machine = nil)
34
+ new.tap do |z|
35
+ z.machine = machine
36
+ z.name = zone['alias']
37
+ z.uuid = zone['uuid']
38
+ z.brand = zone['brand']
39
+ z.state = zone['state']
40
+ z.image = zone['image_uuid']
41
+ end
42
+ end
43
+
44
+ def running?
45
+ state == 'running'
46
+ end
47
+
48
+ def lx_brand?
49
+ brand == 'lx'
50
+ end
51
+
52
+ def test(cmd)
53
+ command = "pfexec zlogin #{uuid} #{cmd}"
54
+ machine.communicate.gz_test(command)
55
+ end
56
+
57
+ def zlogin(cmd, options = {})
58
+ command = "pfexec zlogin #{uuid} #{cmd}"
59
+ with_gz(command, options) do |output|
60
+ yield output if block_given?
61
+ end
62
+ end
63
+
64
+ def destroy
65
+ with_gz("pfexec vmadm delete #{uuid}")
66
+ self.state = 'deleted'
67
+ end
68
+
69
+ def start
70
+ with_gz("pfexec vmadm start #{uuid}")
71
+ end
72
+
73
+ def stop
74
+ with_gz("pfexec vmadm stop #{uuid}")
75
+ end
76
+ end
77
+ end
78
+ end
79
+ end
80
+ end
@@ -0,0 +1,11 @@
1
+ module Vagrant
2
+ module Smartos
3
+ module Zones
4
+ module Models
5
+ class ZoneGroup
6
+ attr_accessor :name, :gid
7
+ end
8
+ end
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,11 @@
1
+ module Vagrant
2
+ module Smartos
3
+ module Zones
4
+ module Models
5
+ class ZoneUser
6
+ attr_accessor :name, :uid
7
+ end
8
+ end
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,118 @@
1
+ require 'vagrant'
2
+
3
+ module Vagrant
4
+ module Smartos
5
+ module Zones
6
+ class Plugin < Vagrant.plugin('2')
7
+ name 'smartos-zones'
8
+
9
+ description 'SmartOS zone support'
10
+
11
+ communicator('smartos') do
12
+ require_relative 'communicator/smartos'
13
+ Communicator::Smartos
14
+ end
15
+
16
+ config 'global_zone' do
17
+ load_il8n
18
+ require_relative 'config/global_zone'
19
+ Config::GlobalZone
20
+ end
21
+
22
+ config 'zone' do
23
+ require_relative 'config/zone'
24
+ Config::Zone
25
+ end
26
+
27
+ command 'dataset' do
28
+ require_relative 'commands/dataset'
29
+ Command::Dataset
30
+ end
31
+
32
+ command 'global-zone' do
33
+ require_relative 'commands/global_zone'
34
+ Command::GlobalZone
35
+ end
36
+
37
+ command 'smartos' do
38
+ require_relative 'commands/smartos'
39
+ Command::Smartos
40
+ end
41
+
42
+ command 'zones' do
43
+ require_relative 'commands/zones'
44
+ Command::Zones
45
+ end
46
+
47
+ command 'zlogin' do
48
+ require_relative 'commands/zlogin'
49
+ Command::Zlogin
50
+ end
51
+
52
+ guest 'global_zone', 'smartos' do
53
+ require_relative 'guest'
54
+ Guest
55
+ end
56
+
57
+ guest_capability 'global_zone', 'create_gz_vnic' do
58
+ require_relative 'cap/create_gz_vnic'
59
+ Cap::CreateGZVnic
60
+ end
61
+
62
+ guest_capability 'global_zone', 'imgadm_import' do
63
+ require_relative 'cap/imgadm_import'
64
+ Cap::ImgadmImport
65
+ end
66
+
67
+ guest_capability 'global_zone', 'zone_gate_enable' do
68
+ require_relative 'cap/zone_gate/enable'
69
+ Cap::ZoneGate::Enable
70
+ end
71
+
72
+ guest_capability 'global_zone', 'zone_gate_install' do
73
+ require_relative 'cap/zone_gate/install'
74
+ Cap::ZoneGate::Install
75
+ end
76
+
77
+ guest_capability 'global_zone', 'zone__create' do
78
+ require_relative 'cap/zone/create'
79
+ Cap::Zone::Create
80
+ end
81
+
82
+ guest_capability 'global_zone', 'zone__start' do
83
+ require_relative 'cap/zone/start'
84
+ Cap::Zone::Start
85
+ end
86
+
87
+ guest_capability 'global_zone', 'zone__stop' do
88
+ require_relative 'cap/zone/stop'
89
+ Cap::Zone::Stop
90
+ end
91
+
92
+ host_capability 'bsd', 'platform_image_install' do
93
+ require_relative 'cap/platform_image/install'
94
+ Cap::PlatformImage::Install
95
+ end
96
+
97
+ host_capability 'bsd', 'platform_image_latest' do
98
+ require_relative 'cap/platform_image/latest'
99
+ Cap::PlatformImage::Latest
100
+ end
101
+
102
+ host_capability 'bsd', 'platform_image_list' do
103
+ require_relative 'cap/platform_image/list'
104
+ Cap::PlatformImage::List
105
+ end
106
+
107
+ class << self
108
+ def load_il8n
109
+ I18n.load_path << File.expand_path('../../locales/en.yml', __FILE__)
110
+ I18n.reload!
111
+ end
112
+ end
113
+ end
114
+ end
115
+ end
116
+ end
117
+
118
+ require_relative 'hooks'