Class: OsCtl::Cli::Pool

Inherits:
Command show all
Includes:
Assets, Attributes
Defined in:
lib/osctl/cli/pool.rb

Constant Summary collapse

FIELDS =
%i(
  name
  dataset
  state
  users
  groups
  containers
  parallel_start
  parallel_stop
)
DEFAULT_FIELDS =
%i(
  name
  dataset
  state
  users
  groups
  containers
)
AUTOSTART_FIELDS =
%i(
  id
  priority
)

Instance Attribute Summary

Attributes inherited from Command

#args, #gopts, #opts

Instance Method Summary collapse

Methods included from Attributes

#do_set_attr, #do_unset_attr

Methods included from Assets

#print_assets

Methods inherited from Command

#cli_opt, #format_output, #initialize, #osctld_call, #osctld_fmt, #osctld_open, #osctld_resp, #require_args!, run

Methods included from Utils::Humanize

#break_interval, #format_long_duration, #format_percent, #format_short_duration, #humanize_data, #humanize_time_ns, #parse_data

Constructor Details

This class inherits a constructor from OsCtl::Cli::Command

Instance Method Details

#assetsObject



114
115
116
117
118
# File 'lib/osctl/cli/pool.rb', line 114

def assets
  require_args!('name')

  print_assets(:pool_assets, name: args[0])
end

#autostart_cancelObject



144
145
146
147
# File 'lib/osctl/cli/pool.rb', line 144

def autostart_cancel
  require_args!('name')
  osctld_fmt(:pool_autostart_cancel, name: args[0])
end

#autostart_queueObject



120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
# File 'lib/osctl/cli/pool.rb', line 120

def autostart_queue
  if opts[:list]
    puts AUTOSTART_FIELDS.join("\n")
    return
  end

  require_args!('name')

  fmt_opts = {layout: :columns}
  fmt_opts[:header] = false if opts['hide-header']

  osctld_fmt(
    :pool_autostart_queue,
    {name: args[0]},
    opts[:output] ? opts[:output].split(',').map(&:to_sym) : nil,
    fmt_opts
  )
end

#autostart_triggerObject



139
140
141
142
# File 'lib/osctl/cli/pool.rb', line 139

def autostart_trigger
  require_args!('name')
  osctld_fmt(:pool_autostart_trigger, name: args[0])
end

#exportObject



89
90
91
92
93
94
95
96
97
98
# File 'lib/osctl/cli/pool.rb', line 89

def export
  require_args!('name')
  osctld_fmt(
    :pool_export,
    name: args[0],
    force: opts[:force],
    stop_containers: opts['stop-containers'],
    unregister_users: opts['unregister-users'],
  )
end

#importObject



76
77
78
79
80
81
82
83
84
85
86
87
# File 'lib/osctl/cli/pool.rb', line 76

def import
  if !args[0] && !opts[:all]
    raise GLI::BadCommandLine, 'specify pool name or --all'
  end

  osctld_fmt(
    :pool_import,
    name: args[0],
    all: opts[:all],
    autostart: opts[:autostart]
  )
end

#installObject



100
101
102
103
104
105
106
107
# File 'lib/osctl/cli/pool.rb', line 100

def install
  require_args!('name')

  cmd_opts = {name: args[0]}
  cmd_opts[:dataset] = opts[:dataset] if opts[:dataset]

  osctld_fmt(:pool_install, cmd_opts)
end

#listObject



33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/osctl/cli/pool.rb', line 33

def list
  if opts[:list]
    puts FIELDS.join("\n")
    return
  end

  cmd_opts = {}
  fmt_opts = {
    layout: :columns,
    sort: opts[:sort] && opts[:sort].split(',').map(&:to_sym),
  }

  cmd_opts[:names] = args if args.count > 0
  fmt_opts[:header] = false if opts['hide-header']

  osctld_fmt(
    :pool_list,
    cmd_opts,
    opts[:output] ? opts[:output].split(',').map(&:to_sym) : DEFAULT_FIELDS,
    fmt_opts
  )
end

#set(key) ⇒ Object



149
150
151
152
153
# File 'lib/osctl/cli/pool.rb', line 149

def set(key)
  require_args!('name', 'n')

  osctld_fmt(:pool_set, name: args[0], key => args[1])
end

#set_attrObject



161
162
163
164
165
166
167
168
169
# File 'lib/osctl/cli/pool.rb', line 161

def set_attr
  require_args!('name', 'attribute', 'value')
  do_set_attr(
    :pool_set,
    {name: args[0]},
    args[1],
    args[2],
  )
end

#showObject



56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
# File 'lib/osctl/cli/pool.rb', line 56

def show
  if opts[:list]
    puts FIELDS.join("\n")
    return
  end

  require_args!('name')

  cmd_opts = {name: args[0]}
  fmt_opts = {layout: :rows}
  fmt_opts[:header] = false if opts['hide-header']

  osctld_fmt(
    :pool_show,
    cmd_opts,
    opts[:output] ? opts[:output].split(',').map(&:to_sym) : DEFAULT_FIELDS,
    fmt_opts
  )
end

#uninstallObject



109
110
111
112
# File 'lib/osctl/cli/pool.rb', line 109

def uninstall
  require_args!('name')
  osctld_fmt(:pool_uninstall, name: args[0])
end

#unset(key) ⇒ Object



155
156
157
158
159
# File 'lib/osctl/cli/pool.rb', line 155

def unset(key)
  require_args!('name')

  osctld_fmt(:pool_unset, name: args[0], options: [key])
end

#unset_attrObject



171
172
173
174
175
176
177
178
# File 'lib/osctl/cli/pool.rb', line 171

def unset_attr
  require_args!('name', 'attribute')
  do_unset_attr(
    :pool_unset,
    {name: args[0]},
    args[1],
  )
end