Class: OsCtl::Cli::IdRange
Constant Summary
collapse
- FIELDS =
%i(pool name start_id last_id block_size block_count allocated free)
- TABLE_FIELDS =
%i(type block_index block_count owner first_id last_id id_count)
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
#break_interval, #format_long_duration, #format_percent, #format_short_duration, #humanize_data, #humanize_time_ns, #parse_data
Instance Method Details
#allocate ⇒ Object
127
128
129
130
131
132
133
134
135
136
137
138
|
# File 'lib/osctl/cli/id_range.rb', line 127
def allocate
require_args!('id-range')
osctld_fmt(
:id_range_allocate,
pool: gopts[:pool],
name: args[0],
block_count: opts['block-count'],
block_index: opts['block-index'],
owner: opts[:owner],
)
end
|
#assets ⇒ Object
175
176
177
178
|
# File 'lib/osctl/cli/id_range.rb', line 175
def assets
require_args!('name')
print_assets(:id_range_assets, name: args[0], pool: gopts[:pool])
end
|
#create ⇒ Object
49
50
51
52
53
54
55
56
57
58
59
60
|
# File 'lib/osctl/cli/id_range.rb', line 49
def create
require_args!('id-range')
osctld_fmt(
:id_range_create,
pool: gopts[:pool],
name: args[0],
start_id: opts['start-id'],
block_size: opts['block-size'],
block_count: opts['block-count'],
)
end
|
#delete ⇒ Object
62
63
64
65
66
67
68
69
70
|
# File 'lib/osctl/cli/id_range.rb', line 62
def delete
require_args!('id-range')
osctld_fmt(
:id_range_delete,
pool: gopts[:pool],
name: args[0],
)
end
|
#free ⇒ Object
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
|
# File 'lib/osctl/cli/id_range.rb', line 140
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,
pool: gopts[:pool],
name: args[0],
block_index: opts['block-index'],
owner: opts['owner'],
)
end
|
#list ⇒ Object
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
|
# File 'lib/osctl/cli/id_range.rb', line 12
def list
if opts[:list]
puts FIELDS.join("\n")
return
end
cmd_opts = {pool: gopts[:pool]}
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']
cols = opts[:output] ? opts[:output].split(',').map(&:to_sym) : FIELDS
osctld_fmt(:id_range_list, cmd_opts, cols, fmt_opts)
end
|
#set_attr ⇒ Object
156
157
158
159
160
161
162
163
164
|
# File 'lib/osctl/cli/id_range.rb', line 156
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
|
#show ⇒ Object
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
|
# File 'lib/osctl/cli/id_range.rb', line 32
def show
if opts[:list]
puts FIELDS.join("\n")
return
end
require_args!('id-range')
cmd_opts = {name: args[0], pool: gopts[:pool]}
fmt_opts = {layout: :rows}
fmt_opts[:header] = false if opts['hide-header']
cols = opts[:output] ? opts[:output].split(',').map(&:to_sym) : FIELDS
osctld_fmt(:id_range_show, cmd_opts, cols, fmt_opts)
end
|
#table_list ⇒ Object
72
73
74
75
76
77
78
79
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
|
# File 'lib/osctl/cli/id_range.rb', line 72
def table_list
if opts[:list]
puts TABLE_FIELDS.join("\n")
return
end
require_args!('id-range')
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']
cols =
if opts[:output]
opts[:output].split(',').map(&:to_sym)
elsif args[1].nil? || args[1] == 'all'
TABLE_FIELDS
else
TABLE_FIELDS[1..-1] end
osctld_fmt(:id_range_table_list, cmd_opts, cols, fmt_opts)
end
|
#table_show ⇒ Object
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
|
# File 'lib/osctl/cli/id_range.rb', line 110
def table_show
if opts[:list]
puts FIELDS.join("\n")
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}
fmt_opts[:header] = false if opts['hide-header']
cols = opts[:output] ? opts[:output].split(',').map(&:to_sym) : TABLE_FIELDS
osctld_fmt(:id_range_table_show, cmd_opts, cols, fmt_opts)
end
|
#unset_attr ⇒ Object
166
167
168
169
170
171
172
173
|
# File 'lib/osctl/cli/id_range.rb', line 166
def unset_attr
require_args!('id-range', 'attribute')
do_unset_attr(
:id_range_unset,
{name: args[0], pool: gopts[:pool]},
args[1],
)
end
|