Class: OsCtl::Cli::IdRange

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

Constant Summary collapse

FIELDS =
%i[pool name start_id last_id block_size block_count allocated free].freeze
TABLE_FIELDS =
%i[type block_index block_count owner first_id last_id id_count].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

#allocateObject



137
138
139
140
141
142
143
144
145
146
147
# File 'lib/osctl/cli/id_range.rb', line 137

def allocate
  require_args!('id-range')

  osctld_fmt(:id_range_allocate, cmd_opts: {
    pool: gopts[:pool],
    name: args[0],
    block_count: opts['block-count'],
    block_index: opts['block-index'],
    owner: opts[:owner]
  })
end

#assetsObject



183
184
185
186
# File 'lib/osctl/cli/id_range.rb', line 183

def assets
  require_args!('name')
  print_assets(:id_range_assets, name: args[0], pool: gopts[:pool])
end

#createObject



59
60
61
62
63
64
65
66
67
68
69
# File 'lib/osctl/cli/id_range.rb', line 59

def create
  require_args!('id-range')

  osctld_fmt(:id_range_create, cmd_opts: {
    pool: gopts[:pool],
    name: args[0],
    start_id: opts['start-id'],
    block_size: opts['block-size'],
    block_count: opts['block-count']
  })
end

#deleteObject



71
72
73
74
75
76
77
78
# File 'lib/osctl/cli/id_range.rb', line 71

def delete
  require_args!('id-range')

  osctld_fmt(:id_range_delete, cmd_opts: {
    pool: gopts[:pool],
    name: args[0]
  })
end

#freeObject



149
150
151
152
153
154
155
156
157
158
159
160
161
162
# File 'lib/osctl/cli/id_range.rb', line 149

def free
  require_args!('id-range')

  if !opts['block-index'] === !opts['owner']
    raise GLI::BadCommandLine, 'use --block-index or --owner'
  end

  osctld_fmt(:id_range_free, cmd_opts: {
    pool: gopts[:pool],
    name: args[0],
    block_index: opts['block-index'],
    owner: opts['owner']
  })
end

#listObject



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/osctl/cli/id_range.rb', line 12

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

  if opts[:list]
    puts param_selector
    return
  end

  cmd_opts = { pool: gopts[:pool] }
  fmt_opts = {
    layout: :columns,
    cols: param_selector.parse_option(opts[:output]),
    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']

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

#set_attrObject



164
165
166
167
168
169
170
171
172
# File 'lib/osctl/cli/id_range.rb', line 164

def set_attr
  require_args!('id-range', 'attribute', 'value')
  do_set_attr(
    :id_range_set,
    { name: args[0], pool: gopts[:pool] },
    args[1],
    args[2]
  )
end

#showObject



36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/osctl/cli/id_range.rb', line 36

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

  if opts[:list]
    puts param_selector
    return
  end

  require_args!('id-range')

  cmd_opts = { name: args[0], pool: gopts[:pool] }
  fmt_opts = {
    layout: :rows,
    cols: param_selector.parse_option(opts[:output])
  }

  fmt_opts[:header] = false if opts['hide-header']

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

#table_listObject



80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
# File 'lib/osctl/cli/id_range.rb', line 80

def table_list
  param_selector = OsCtl::Lib::Cli::ParameterSelector.new(
    all_params: TABLE_FIELDS
  )

  if opts[:list]
    puts param_selector
    return
  end

  require_args!('id-range', optional: %w[type])

  types = %w[all allocated free]

  if args[1] && !types.include?(args[1])
    raise GLI::BadCommandLine, "type can be one of: #{types.join(', ')}"
  end

  cmd_opts = {
    pool: gopts[:pool],
    name: args[0],
    type: args[1] || 'all'
  }
  fmt_opts = {
    layout: :columns,
    sort: opts[:sort] && opts[:sort].split(',').map(&:to_sym)
  }

  fmt_opts[:header] = false if opts['hide-header']
  fmt_opts[:cols] = param_selector.parse_option(opts[:output])

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

#table_showObject



114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
# File 'lib/osctl/cli/id_range.rb', line 114

def table_show
  param_selector = OsCtl::Lib::Cli::ParameterSelector.new(
    all_params: TABLE_FIELDS
  )

  if opts[:list]
    puts param_selector
    return
  end

  require_args!('id-range', 'block-index')

  cmd_opts = { name: args[0], pool: gopts[:pool], block_index: args[1].to_i }
  fmt_opts = {
    layout: :rows,
    cols: param_selector.parse_option(opts[:output])
  }

  fmt_opts[:header] = false if opts['hide-header']

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

#unset_attrObject



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

def unset_attr
  require_args!('id-range', 'attribute')
  do_unset_attr(
    :id_range_unset,
    { name: args[0], pool: gopts[:pool] },
    args[1]
  )
end