Class: OsCtl::Cli::Pool

Inherits:
Command
  • Object
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
].freeze
DEFAULT_FIELDS =
%i[
  name
  dataset
  state
  users
  groups
  containers
].freeze
AUTOSTART_FIELDS =
%i[
  id
  priority
].freeze

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, #osctld_call, #osctld_fmt, #osctld_open, #osctld_resp, run

Instance Method Details

#assetsObject



120
121
122
123
124
# File 'lib/osctl/cli/pool.rb', line 120

def assets
  require_args!('name')

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

#autostart_cancelObject



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

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

#autostart_queueObject



126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
# File 'lib/osctl/cli/pool.rb', line 126

def autostart_queue
  param_selector = OsCtl::Lib::Cli::ParameterSelector.new(
    all_params: AUTOSTART_FIELDS
  )

  if opts[:list]
    puts param_selector
    return
  end

  require_args!('name')

  fmt_opts = {
    layout: :columns,
    cols: param_selector.parse_option(opts[:output])
  }
  fmt_opts[:header] = false if opts['hide-header']

  osctld_fmt(
    :pool_autostart_queue,
    cmd_opts: { name: args[0] },
    fmt_opts:
  )
end

#autostart_triggerObject



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

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

#exportObject



89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
# File 'lib/osctl/cli/pool.rb', line 89

def export
  require_args!('name')

  if opts[:abort]
    osctld_fmt(:pool_abort_export, cmd_opts: { name: args[0] })
  else
    osctld_fmt(:pool_export, cmd_opts: {
      name: args[0],
      force: opts[:force],
      stop_containers: opts['stop-containers'],
      unregister_users: opts['unregister-users'],
      message: opts['message'],
      if_imported: opts['if-imported']
    })
  end
end

#importObject



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

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

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

#installObject



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

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
55
# File 'lib/osctl/cli/pool.rb', line 33

def list
  param_selector = OsCtl::Lib::Cli::ParameterSelector.new(
    all_params: FIELDS,
    default_params: DEFAULT_FIELDS
  )

  if opts[:list]
    puts param_selector
    return
  end

  cmd_opts = {}
  fmt_opts = {
    layout: :columns,
    sort: opts[:sort] && param_selector.parse_option(opts[:sort])
  }

  cmd_opts[:names] = args if args.count > 0
  fmt_opts[:header] = false if opts['hide-header']
  fmt_opts[:cols] = param_selector.parse_option(opts[:output])

  osctld_fmt(:pool_list, cmd_opts:, fmt_opts:)
end

#set(key) ⇒ Object



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

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

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

#set_attrObject



173
174
175
176
177
178
179
180
181
# File 'lib/osctl/cli/pool.rb', line 173

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

#showObject



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

def show
  param_selector = OsCtl::Lib::Cli::ParameterSelector.new(
    all_params: FIELDS
  )

  if opts[:list]
    puts param_selector
    return
  end

  require_args!('name')

  cmd_opts = { name: args[0] }
  fmt_opts = { layout: :rows }
  fmt_opts[:header] = false if opts['hide-header']
  fmt_opts[:cols] = param_selector.parse_option(opts[:output])

  osctld_fmt(:pool_show, cmd_opts:, fmt_opts:)
end

#uninstallObject



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

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

#unset(key) ⇒ Object



167
168
169
170
171
# File 'lib/osctl/cli/pool.rb', line 167

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

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

#unset_attrObject



183
184
185
186
187
188
189
190
# File 'lib/osctl/cli/pool.rb', line 183

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