Class: Vagrant::Smartos::Zones::Command::Zones

Inherits:
Object
  • Object
show all
Includes:
MultiCommand
Defined in:
lib/vagrant/smartos/zones/commands/zones.rb

Constant Summary collapse

COMMANDS =
%w(config create destroy list show snapshot start stop).freeze

Class Method Summary collapse

Instance Method Summary collapse

Methods included from MultiCommand

#execute, #fail_options!, #process_subcommand, #subcommands

Class Method Details

.synopsisObject

rubocop:enable Metrics/MethodLength



43
44
45
# File 'lib/vagrant/smartos/zones/commands/zones.rb', line 43

def self.synopsis
  'View and interact with SmartOS zones'
end

Instance Method Details

#config(*args) ⇒ Object



47
48
49
# File 'lib/vagrant/smartos/zones/commands/zones.rb', line 47

def config(*args)
  Models::Config.parse_cli(@env, *args)
end

#create(name) ⇒ Object



51
52
53
54
55
56
57
58
59
60
# File 'lib/vagrant/smartos/zones/commands/zones.rb', line 51

def create(name)
  with_target_vms('default') do |machine|
    Models::Zone.create(name, machine).tap do |zone|
      @env.ui.info(I18n.t('vagrant.smartos.zones.commands.zones.create',
                          name: zone.name, state: zone.state, uuid: zone.uuid,
                          brand: zone.brand, image: zone.image),
                   prefix: false)
    end
  end
end

#destroy(name) ⇒ Object



62
63
64
65
66
67
68
69
# File 'lib/vagrant/smartos/zones/commands/zones.rb', line 62

def destroy(name)
  with_zone(name) do |zone|
    zone.destroy
    @env.ui.info(I18n.t('vagrant.smartos.zones.commands.zones.destroyed',
                        name: zone.name, state: zone.state, uuid: zone.uuid,
                        brand: zone.brand, image: zone.image))
  end
end

#list(*_args) ⇒ Object



71
72
73
74
75
76
77
78
79
# File 'lib/vagrant/smartos/zones/commands/zones.rb', line 71

def list(*_args)
  with_target_vms('default') do |machine|
    zones = Models::Zone.all(machine).map do |zone|
      [zone.name.to_s.ljust(25), zone.state.to_s.ljust(10), zone.uuid].join(' ')
    end
    @env.ui.info(I18n.t('vagrant.smartos.zones.commands.zones.list',
                        zones: zones.join("\n")), prefix: false)
  end
end

#option_parserObject

rubocop:disable Metrics/MethodLength



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/vagrant/smartos/zones/commands/zones.rb', line 19

def option_parser
  OptionParser.new do |o|
    o.banner = 'Usage: vagrant zones [command] [name]'
    o.separator ''
    o.separator 'Commands:'
    o.separator '  list                                 show status of zones'
    o.separator '  config [action] [options]            interact with global plugin configuration'
    o.separator '  create [name]                        create or update zone with alias [name]'
    o.separator '  destroy [name]                       delete zone with alias [name]'
    o.separator '  show [name]                          show info on zone with alias [name]'
    o.separator '  snapshot [action] [name] [snapshot]  snapshot the ZFS filesystem for [name]'
    o.separator '                                         actions: list, create, delete, rollback'
    o.separator '  start [name]                         start zone with alias [name]'
    o.separator '  stop [name]                          stop zone with alias [name]'
    o.separator ''
    o.separator 'Options:'
    o.separator ''
    o.on('--delete', 'delete configuration key') do |d|
      @options[:delete] = d
    end
  end
end

#show(name) ⇒ Object



81
82
83
84
85
86
87
88
# File 'lib/vagrant/smartos/zones/commands/zones.rb', line 81

def show(name)
  with_zone(name) do |zone|
    @env.ui.info(I18n.t('vagrant.smartos.zones.commands.zones.show',
                        name: zone.name, state: zone.state, uuid: zone.uuid,
                        brand: zone.brand, image: zone.image),
                 prefix: false)
  end
end

#snapshot(action = nil, name = nil, snapshot = nil) ⇒ Object



90
91
92
93
94
95
# File 'lib/vagrant/smartos/zones/commands/zones.rb', line 90

def snapshot(action = nil, name = nil, snapshot = nil)
  fail_options! unless action && name
  with_target_vms('default') do |machine|
    Util::Snapshots.new(machine, name).run(action, snapshot)
  end
end

#start(name) ⇒ Object



97
98
99
100
101
102
103
104
# File 'lib/vagrant/smartos/zones/commands/zones.rb', line 97

def start(name)
  with_zone(name) do |zone|
    zone.start
    @env.ui.info(I18n.t('vagrant.smartos.zones.commands.zones.start',
                        name: zone.name, state: zone.state, uuid: zone.uuid,
                        brand: zone.brand, image: zone.image))
  end
end

#stop(name) ⇒ Object



106
107
108
109
110
111
112
113
114
# File 'lib/vagrant/smartos/zones/commands/zones.rb', line 106

def stop(name)
  with_zone(name) do |zone|
    zone.stop
    @env.ui.info(I18n.t('vagrant.smartos.zones.commands.zones.stop',
                        name: zone.name, state: zone.state,
                        uuid: zone.uuid, brand: zone.brand,
                        image: zone.image))
  end
end