Class: CollinsShell::IpAddress
- Inherits:
-
Thor
- Object
- Thor
- CollinsShell::IpAddress
show all
- Includes:
- ThorHelper, Util
- Defined in:
- lib/collins_shell/ip_address.rb
Constant Summary
Constants included
from Util
Util::SIZABLE_ATTRIBUTES
Constants included
from ThorHelper
ThorHelper::COLLINS_OPTIONS, ThorHelper::PAGE_OPTIONS
Class Method Summary
collapse
Instance Method Summary
collapse
Methods included from Util
#asset_exec, #asset_get, #call_collins, #finalize_exec, #format_asset_tags, #format_asset_value, #get_selector, #is_array?, #print_find_results, #run_command_in_thread, #say_status, #thread_mgr
Methods included from ThorHelper
#appropriate_answer?, #batch_selector_operation, #collins_config_from_file, #ensure_password, #get_collins_client, #get_collins_config, #get_password, included, #require_valid_collins_config, #require_yes, #say_error, #say_success, #selector_or_tag, #try_config_merge, #use_collins_options, #use_nuke_option, #use_page_options, #use_selector_option, #use_tag_option
Class Method Details
.banner(task, namespace = true, subcommand = false) ⇒ Object
13
14
15
|
# File 'lib/collins_shell/ip_address.rb', line 13
def self.banner task, namespace = true, subcommand = false
"#{basename} #{task.formatted_usage(self, true, subcommand).gsub(':',' ')}"
end
|
Instance Method Details
#allocate(pool) ⇒ Object
21
22
23
24
25
26
27
28
29
30
|
# File 'lib/collins_shell/ip_address.rb', line 21
def allocate pool
call_collins get_collins_client, "ip_address allocate" do |client|
addresses = client.ipaddress_allocate! options.tag, pool, options["count"]
= [["Gateway","Netmask","Address","Pool"]]
tags = + addresses.map do |address|
[address.gateway, address.netmask, address.address, address.pool]
end
print_table tags
end
end
|
#assets(pool) ⇒ Object
68
69
70
71
72
73
74
75
76
77
78
79
80
81
|
# File 'lib/collins_shell/ip_address.rb', line 68
def assets pool
call_collins get_collins_client, "ip_address assets" do |client|
= true
client.assets_in_pool(pool).each do |asset|
if options.details then
asset = client.get asset
print_find_results asset, [:tag,:status,:type,:hostname,:addresses], :header =>
= false
else
puts(asset.tag)
end
end
end
end
|
#create ⇒ Object
105
106
107
108
109
110
111
112
113
114
115
116
117
118
|
# File 'lib/collins_shell/ip_address.rb', line 105
def create
call_collins get_collins_client, "create address" do |client|
address = client.ipaddress_update! options.tag, nil,
:address => options.address,
:gateway => options.gateway,
:netmask => options.netmask,
:pool => options.pool
if address then
say_success "Address for #{options.tag} created"
else
say_error "Address for #{options.tag} not created"
end
end
end
|
#delete(pool) ⇒ Object
35
36
37
38
39
40
|
# File 'lib/collins_shell/ip_address.rb', line 35
def delete pool
call_collins get_collins_client, "ip_address delete" do |client|
delete_count = client.ipaddress_delete! options.tag, pool
say_success "Deleted #{delete_count} addresses"
end
end
|
#delete_all ⇒ Object
45
46
47
48
49
50
|
# File 'lib/collins_shell/ip_address.rb', line 45
def delete_all
call_collins get_collins_client, "ip_address delete_all" do |client|
delete_count = client.ipaddress_delete! options.tag
say_success "Deleted #{delete_count} addresses"
end
end
|
#find(address) ⇒ Object
54
55
56
57
58
59
60
61
62
63
|
# File 'lib/collins_shell/ip_address.rb', line 54
def find address
call_collins get_collins_client, "ip_address find" do |client|
asset = client.asset_at_address address
if asset then
say_success "Asset #{asset.tag} is using address #{address}"
else
say_error "No asset using address #{address}"
end
end
end
|
#pools ⇒ Object
86
87
88
89
90
91
92
93
94
95
96
|
# File 'lib/collins_shell/ip_address.rb', line 86
def pools
call_collins get_collins_client, "ip_address pools" do |client|
= [["Pool","Network","Gateway","Broadcast","Possible Addresses","Start Address","Specified Gateway"]]
rows = client.ipaddress_pools(!options.used).map do |pool|
[pool["NAME"], pool["NETWORK"], pool["GATEWAY"], pool["BROADCAST"], pool["POSSIBLE_ADDRESSES"],
pool["START_ADDRESS"], pool["SPECIFIED_GATEWAY"]]
end
print_table + rows
end
end
|
#update(old_address) ⇒ Object
127
128
129
130
131
132
133
134
135
136
137
138
139
140
|
# File 'lib/collins_shell/ip_address.rb', line 127
def update old_address
call_collins get_collins_client, "update address" do |client|
address = client.ipaddress_update! options.tag, old_address,
:address => options.address,
:gateway => options.gateway,
:netmask => options.netmask,
:pool => options.pool
if address then
say_success "Address for #{options.tag} updated"
else
say_error "Address for #{options.tag} not updated"
end
end
end
|