Module: Morpheus::Cli::InfrastructureHelper
- Included in:
- AccountGroupsCommand, CloudDatastoresCommand, CloudFoldersCommand, CloudResourcePoolsCommand, CloudTypes, Clouds, Groups, NetworkDomainsCommand, NetworkGroupsCommand, NetworkPoolServerTypes, NetworkPoolServersCommand, NetworkPoolsCommand, NetworkProxiesCommand, NetworkRoutersCommand, NetworkSecurityServerTypes, NetworkServerTypes, NetworkServersCommand, NetworkServicesCommand, NetworksCommand, PoliciesCommand, Processes, ResourcePoolGroupsCommand, SecurityGroups, StorageProvidersCommand, SubnetsCommand, Whoami
- Defined in:
- lib/morpheus/cli/mixins/infrastructure_helper.rb
Overview
Provides common methods for infrastructure management
Class Method Summary collapse
Instance Method Summary collapse
- #cloud_type_for_id(id) ⇒ Object
- #cloud_type_for_name(name) ⇒ Object
- #cloud_type_for_name_or_id(val) ⇒ Object
- #clouds_interface ⇒ Object
- #find_cloud_by_id(id) ⇒ Object
- #find_cloud_by_name(name) ⇒ Object
- #find_cloud_by_name_or_id(val) ⇒ Object
- #find_group_by_id(id) ⇒ Object
- #find_group_by_name(name) ⇒ Object
- #find_group_by_name_or_id(val) ⇒ Object
- #find_network_by_id(id) ⇒ Object
- #find_network_by_name(name) ⇒ Object
-
#find_network_by_name_or_id(val) ⇒ Object
Networks.
- #find_network_group_by_id(id) ⇒ Object
- #find_network_group_by_name(name) ⇒ Object
- #find_network_group_by_name_or_id(val) ⇒ Object
- #find_network_server_type_by_id(id) ⇒ Object
- #find_network_server_type_by_name(name) ⇒ Object
- #find_network_server_type_by_name_or_code(name) ⇒ Object
- #find_network_server_type_by_name_or_id(val) ⇒ Object
- #find_network_type_by_id(id) ⇒ Object
- #find_network_type_by_name(name) ⇒ Object
- #find_network_type_by_name_or_id(val) ⇒ Object
- #find_resource_pool_by_id(id) ⇒ Object
- #find_resource_pool_by_name(name) ⇒ Object
- #find_resource_pool_by_name_or_id(val) ⇒ Object
- #find_resource_pool_group_by_id(id) ⇒ Object
- #find_resource_pool_group_by_name(name) ⇒ Object
- #find_resource_pool_group_by_name_or_id(val) ⇒ Object
- #find_subnet_by_id(id) ⇒ Object
- #find_subnet_by_name(name) ⇒ Object
- #find_subnet_by_name_or_id(val) ⇒ Object
- #find_subnet_type_by_id(id) ⇒ Object
- #find_subnet_type_by_name(name) ⇒ Object
- #find_subnet_type_by_name_or_id(val) ⇒ Object
- #format_network_pool_server_status(network_pool_server, return_color = cyan) ⇒ Object
- #get_available_cloud_types(refresh = false, params = {}) ⇒ Object
- #groups_interface ⇒ Object
- #network_groups_interface ⇒ Object
- #network_pool_server_column_definitions(options) ⇒ Object
- #network_pool_server_list_column_definitions(options) ⇒ Object
- #network_pool_server_type_column_definitions(options) ⇒ Object
- #network_pool_server_type_list_column_definitions(options) ⇒ Object
- #network_server_type_column_definitions(options) ⇒ Object
- #network_server_type_list_column_definitions(options) ⇒ Object
- #network_types_interface ⇒ Object
- #networks_interface ⇒ Object
- #prompt_for_network(network_id, options = {}, required = true, field_name = 'network', field_label = 'Network') ⇒ Object
- #prompt_for_networks(params, options = {}, api_client = nil, api_params = {}) ⇒ Object
- #prompt_for_pools(params, options = {}, api_client = nil, api_params = {}) ⇒ Object
- #prompt_for_subnets(params, options = {}, api_client = nil, api_params = {}) ⇒ Object
- #resource_pool_groups_interface ⇒ Object
- #resource_pools_interface ⇒ Object
- #subnet_types_interface ⇒ Object
- #subnets_interface ⇒ Object
Class Method Details
.included(klass) ⇒ Object
8 9 10 |
# File 'lib/morpheus/cli/mixins/infrastructure_helper.rb', line 8 def self.included(klass) klass.send :include, Morpheus::Cli::PrintHelper end |
Instance Method Details
#cloud_type_for_id(id) ⇒ Object
141 142 143 |
# File 'lib/morpheus/cli/mixins/infrastructure_helper.rb', line 141 def cloud_type_for_id(id) return get_available_cloud_types().find { |z| z['id'].to_i == id.to_i} end |
#cloud_type_for_name(name) ⇒ Object
145 146 147 148 |
# File 'lib/morpheus/cli/mixins/infrastructure_helper.rb', line 145 def cloud_type_for_name(name) types = get_available_cloud_types(true, {'name' => name}) return types.find { |z| z['code'].downcase == name.downcase} || types.find { |z| z['name'].downcase == name.downcase} end |
#cloud_type_for_name_or_id(val) ⇒ Object
133 134 135 136 137 138 139 |
# File 'lib/morpheus/cli/mixins/infrastructure_helper.rb', line 133 def cloud_type_for_name_or_id(val) if val.to_s =~ /\A\d{1,}\Z/ return cloud_type_for_id(val) else return cloud_type_for_name(val) end end |
#clouds_interface ⇒ Object
18 19 20 21 22 |
# File 'lib/morpheus/cli/mixins/infrastructure_helper.rb', line 18 def clouds_interface # @api_client.clouds raise "#{self.class} has not defined @clouds_interface" if @clouds_interface.nil? @clouds_interface end |
#find_cloud_by_id(id) ⇒ Object
106 107 108 109 110 111 112 113 114 |
# File 'lib/morpheus/cli/mixins/infrastructure_helper.rb', line 106 def find_cloud_by_id(id) json_results = clouds_interface.get(id.to_i) if json_results['zone'].empty? print_red_alert "Cloud not found by id #{id}" exit 1 end cloud = json_results['zone'] return cloud end |
#find_cloud_by_name(name) ⇒ Object
116 117 118 119 120 121 122 123 124 |
# File 'lib/morpheus/cli/mixins/infrastructure_helper.rb', line 116 def find_cloud_by_name(name) json_results = clouds_interface.list({name: name}) if json_results['zones'].empty? print_red_alert "Cloud not found by name #{name}" exit 1 end cloud = json_results['zones'][0] return cloud end |
#find_cloud_by_name_or_id(val) ⇒ Object
98 99 100 101 102 103 104 |
# File 'lib/morpheus/cli/mixins/infrastructure_helper.rb', line 98 def find_cloud_by_name_or_id(val) if val.to_s =~ /\A\d{1,}\Z/ return find_cloud_by_id(val) else return find_cloud_by_name(val) end end |
#find_group_by_id(id) ⇒ Object
74 75 76 77 78 79 80 81 82 83 84 85 86 |
# File 'lib/morpheus/cli/mixins/infrastructure_helper.rb', line 74 def find_group_by_id(id) begin json_response = groups_interface.get(id.to_i) return json_response['group'] rescue RestClient::Exception => e if e.response && e.response.code == 404 print_red_alert "Group not found by id #{id}" exit 1 else raise e end end end |
#find_group_by_name(name) ⇒ Object
88 89 90 91 92 93 94 95 96 |
# File 'lib/morpheus/cli/mixins/infrastructure_helper.rb', line 88 def find_group_by_name(name) json_results = groups_interface.list({name: name}) if json_results['groups'].empty? print_red_alert "Group not found by name #{name}" exit 1 end group = json_results['groups'][0] return group end |
#find_group_by_name_or_id(val) ⇒ Object
66 67 68 69 70 71 72 |
# File 'lib/morpheus/cli/mixins/infrastructure_helper.rb', line 66 def find_group_by_name_or_id(val) if val.to_s =~ /\A\d{1,}\Z/ return find_group_by_id(val) else return find_group_by_name(val) end end |
#find_network_by_id(id) ⇒ Object
161 162 163 164 165 166 167 168 169 170 171 172 173 |
# File 'lib/morpheus/cli/mixins/infrastructure_helper.rb', line 161 def find_network_by_id(id) begin json_response = networks_interface.get(id.to_i) return json_response['network'] rescue RestClient::Exception => e if e.response && e.response.code == 404 print_red_alert "Network not found by id #{id}" return nil else raise e end end end |
#find_network_by_name(name) ⇒ Object
175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 |
# File 'lib/morpheus/cli/mixins/infrastructure_helper.rb', line 175 def find_network_by_name(name) json_response = networks_interface.list({name: name.to_s}) networks = json_response['networks'] if networks.empty? print_red_alert "Network not found by name #{name}" return nil elsif networks.size > 1 print_red_alert "#{networks.size} networks found by name #{name}" rows = networks.collect do |it| {id: it['id'], name: it['name']} end puts as_pretty_table(rows, [:id, :name], {color:red}) return nil else network = networks[0] # merge in tenants map if json_response['tenants'] && json_response['tenants'][network['id']] network['tenants'] = json_response['tenants'][network['id']] end return network end end |
#find_network_by_name_or_id(val) ⇒ Object
Networks
153 154 155 156 157 158 159 |
# File 'lib/morpheus/cli/mixins/infrastructure_helper.rb', line 153 def find_network_by_name_or_id(val) if val.to_s =~ /\A\d{1,}\Z/ return find_network_by_id(val) else return find_network_by_name(val) end end |
#find_network_group_by_id(id) ⇒ Object
326 327 328 329 330 331 332 333 334 335 336 337 338 |
# File 'lib/morpheus/cli/mixins/infrastructure_helper.rb', line 326 def find_network_group_by_id(id) begin json_response = network_groups_interface.get(id.to_i) return json_response['networkGroup'] rescue RestClient::Exception => e if e.response && e.response.code == 404 print_red_alert "Network Group not found by id #{id}" return nil else raise e end end end |
#find_network_group_by_name(name) ⇒ Object
340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 |
# File 'lib/morpheus/cli/mixins/infrastructure_helper.rb', line 340 def find_network_group_by_name(name) json_response = network_groups_interface.list({name: name.to_s}) network_groups = json_response['networkGroups'] if network_groups.empty? print_red_alert "Network Group not found by name #{name}" return nil elsif network_groups.size > 1 print_red_alert "#{network_groups.size} network groups found by name #{name}" # print_networks_table(networks, {color: red}) rows = network_groups.collect do |it| {id: it['id'], name: it['name']} end puts as_pretty_table(rows, [:id, :name], {color:red}) return nil else return network_groups[0] end end |
#find_network_group_by_name_or_id(val) ⇒ Object
318 319 320 321 322 323 324 |
# File 'lib/morpheus/cli/mixins/infrastructure_helper.rb', line 318 def find_network_group_by_name_or_id(val) if val.to_s =~ /\A\d{1,}\Z/ return find_network_group_by_id(val) else return find_network_group_by_name(val) end end |
#find_network_server_type_by_id(id) ⇒ Object
718 719 720 721 722 723 724 725 726 727 728 729 730 |
# File 'lib/morpheus/cli/mixins/infrastructure_helper.rb', line 718 def find_network_server_type_by_id(id) begin json_response = @network_server_types_interface.get(id.to_i) return json_response['networkServerType'] rescue RestClient::Exception => e if e.response && e.response.code == 404 print_red_alert "Network Server Type not found by id #{id}" return nil else raise e end end end |
#find_network_server_type_by_name(name) ⇒ Object
732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 |
# File 'lib/morpheus/cli/mixins/infrastructure_helper.rb', line 732 def find_network_server_type_by_name(name) json_response = @network_server_types_interface.list({name: name.to_s}) network_server_types = json_response['networkServerTypes'] if network_server_types.empty? print_red_alert "Network Server Type not found by name #{name}" return nil elsif network_server_types.size > 1 print_red_alert "#{network_server_types.size} network server types found by name #{name}" # print_networks_table(networks, {color: red}) rows = network_server_types.collect do |it| {id: it['id'], name: it['name']} end puts as_pretty_table(rows, [:id, :code, :name], {color:red}) return nil else return network_server_types[0] end end |
#find_network_server_type_by_name_or_code(name) ⇒ Object
751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 |
# File 'lib/morpheus/cli/mixins/infrastructure_helper.rb', line 751 def find_network_server_type_by_name_or_code(name) json_response = @network_server_types_interface.list({phrase: name.to_s, max: 100}) downcase_name = name.to_s.downcase network_server_types = json_response['networkServerTypes'].select { |it| it['code'].to_s.downcase == downcase_name || it['name'].to_s.downcase == downcase_name } if network_server_types.empty? print_red_alert "Network Server Type not found by name or code '#{name}'" return nil elsif network_server_types.size > 1 print_red_alert "#{network_server_types.size} network server types found with name or code '#{name}'" # print_networks_table(networks, {color: red}) rows = network_server_types.collect do |it| {id: it['id'], name: it['name']} end puts as_pretty_table(rows, [:id, :code, :name], {color:red}) return nil else return network_server_types[0] end end |
#find_network_server_type_by_name_or_id(val) ⇒ Object
708 709 710 711 712 713 714 715 716 |
# File 'lib/morpheus/cli/mixins/infrastructure_helper.rb', line 708 def find_network_server_type_by_name_or_id(val) if val.to_s =~ /\A\d{1,}\Z/ return find_network_server_type_by_id(val) else # always find by code too #return find_network_server_type_by_name(val) return find_network_server_type_by_name_or_code(val) end end |
#find_network_type_by_id(id) ⇒ Object
206 207 208 209 210 211 212 213 214 215 216 217 218 |
# File 'lib/morpheus/cli/mixins/infrastructure_helper.rb', line 206 def find_network_type_by_id(id) begin json_response = network_types_interface.get(id.to_i) return json_response['networkType'] rescue RestClient::Exception => e if e.response && e.response.code == 404 print_red_alert "Network Type not found by id #{id}" return nil else raise e end end end |
#find_network_type_by_name(name) ⇒ Object
220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 |
# File 'lib/morpheus/cli/mixins/infrastructure_helper.rb', line 220 def find_network_type_by_name(name) json_response = network_types_interface.list({name: name.to_s}) network_types = json_response['networkTypes'] if network_types.empty? print_red_alert "Network Type not found by name #{name}" return network_types elsif network_types.size > 1 print_red_alert "#{network_types.size} network types found by name #{name}" rows = network_types.collect do |it| {id: it['id'], name: it['name']} end puts as_pretty_table(rows, [:id, :name], {color:red}) return nil else return network_types[0] end end |
#find_network_type_by_name_or_id(val) ⇒ Object
198 199 200 201 202 203 204 |
# File 'lib/morpheus/cli/mixins/infrastructure_helper.rb', line 198 def find_network_type_by_name_or_id(val) if val.to_s =~ /\A\d{1,}\Z/ return find_network_type_by_id(val) else return find_network_type_by_name(val) end end |
#find_resource_pool_by_id(id) ⇒ Object
367 368 369 370 371 372 373 374 375 376 377 378 379 |
# File 'lib/morpheus/cli/mixins/infrastructure_helper.rb', line 367 def find_resource_pool_by_id(id) begin json_response = resource_pools_interface.get_without_cloud(id.to_i) return json_response['resourcePool'] rescue RestClient::Exception => e if e.response && e.response.code == 404 print_red_alert "Resource Pool not found by id #{id}" return nil else raise e end end end |
#find_resource_pool_by_name(name) ⇒ Object
381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 |
# File 'lib/morpheus/cli/mixins/infrastructure_helper.rb', line 381 def find_resource_pool_by_name(name) json_response = resource_pools_interface.list_without_cloud({name: name.to_s}) resource_pools = json_response['resourcePools'] if resource_pools.empty? print_red_alert "Resource Pool not found by name #{name}" return nil elsif resource_pools.size > 1 print_red_alert "#{resource_pools.size} resource pools found by name #{name}" rows = resource_pools.collect do |it| {id: it['id'], name: it['name']} end puts as_pretty_table(rows, [:id, :name], {color:red}) return nil else return resource_pools[0] end end |
#find_resource_pool_by_name_or_id(val) ⇒ Object
359 360 361 362 363 364 365 |
# File 'lib/morpheus/cli/mixins/infrastructure_helper.rb', line 359 def find_resource_pool_by_name_or_id(val) if val.to_s =~ /\A\d{1,}\Z/ return find_resource_pool_by_id(val) else return find_resource_pool_by_name(val) end end |
#find_resource_pool_group_by_id(id) ⇒ Object
407 408 409 410 411 412 413 414 415 416 417 418 419 |
# File 'lib/morpheus/cli/mixins/infrastructure_helper.rb', line 407 def find_resource_pool_group_by_id(id) begin json_response = resource_pool_groups_interface.get(id.to_i) return json_response['resourcePoolGroup'] rescue RestClient::Exception => e if e.response && e.response.code == 404 print_red_alert "Resource Pool Group not found by id #{id}" return nil else raise e end end end |
#find_resource_pool_group_by_name(name) ⇒ Object
421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 |
# File 'lib/morpheus/cli/mixins/infrastructure_helper.rb', line 421 def find_resource_pool_group_by_name(name) json_response = resource_pool_groups_interface.list({name: name.to_s}) resource_pool_groups = json_response['resourcePoolGroups'] if resource_pool_groups.empty? print_red_alert "Resource Pool Group not found by name #{name}" return nil elsif resource_pool_groups.size > 1 print_red_alert "#{resource_pool_groups.size} resource pool groups found by name #{name}" rows = resource_pool_groups.collect do |it| {id: it['id'], name: it['name']} end puts as_pretty_table(rows, [:id, :name], {color:red}) return nil else return resource_pool_groups[0] end end |
#find_resource_pool_group_by_name_or_id(val) ⇒ Object
399 400 401 402 403 404 405 |
# File 'lib/morpheus/cli/mixins/infrastructure_helper.rb', line 399 def find_resource_pool_group_by_name_or_id(val) if val.to_s =~ /\A\d{1,}\Z/ return find_resource_pool_group_by_id(val) else return find_resource_pool_group_by_name(val) end end |
#find_subnet_by_id(id) ⇒ Object
246 247 248 249 250 251 252 253 254 255 256 257 258 |
# File 'lib/morpheus/cli/mixins/infrastructure_helper.rb', line 246 def find_subnet_by_id(id) begin json_response = subnets_interface.get(id.to_i) return json_response['subnet'] rescue RestClient::Exception => e if e.response && e.response.code == 404 print_red_alert "Subnet not found by id #{id}" return nil else raise e end end end |
#find_subnet_by_name(name) ⇒ Object
260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 |
# File 'lib/morpheus/cli/mixins/infrastructure_helper.rb', line 260 def find_subnet_by_name(name) json_response = subnets_interface.list({name: name.to_s}) subnets = json_response['subnets'] if subnets.empty? print_red_alert "Subnet not found by name #{name}" return nil elsif subnets.size > 1 print_red_alert "#{subnets.size} subnets found by name #{name}" rows = subnets.collect do |it| {id: it['id'], name: it['name']} end puts as_pretty_table(rows, [:id, :name], {color:red}) return nil else return subnets[0] end end |
#find_subnet_by_name_or_id(val) ⇒ Object
238 239 240 241 242 243 244 |
# File 'lib/morpheus/cli/mixins/infrastructure_helper.rb', line 238 def find_subnet_by_name_or_id(val) if val.to_s =~ /\A\d{1,}\Z/ return find_subnet_by_id(val) else return find_subnet_by_name(val) end end |
#find_subnet_type_by_id(id) ⇒ Object
286 287 288 289 290 291 292 293 294 295 296 297 298 |
# File 'lib/morpheus/cli/mixins/infrastructure_helper.rb', line 286 def find_subnet_type_by_id(id) begin json_response = subnet_types_interface.get(id.to_i) return json_response['subnetType'] rescue RestClient::Exception => e if e.response && e.response.code == 404 print_red_alert "Subnet Type not found by id #{id}" return nil else raise e end end end |
#find_subnet_type_by_name(name) ⇒ Object
300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 |
# File 'lib/morpheus/cli/mixins/infrastructure_helper.rb', line 300 def find_subnet_type_by_name(name) json_response = subnet_types_interface.list({name: name.to_s}) subnet_types = json_response['subnetTypes'] if subnet_types.empty? print_red_alert "Subnet Type not found by name #{name}" return subnet_types elsif subnet_types.size > 1 print_red_alert "#{subnet_types.size} subnet types found by name #{name}" rows = subnet_types.collect do |it| {id: it['id'], name: it['name']} end puts as_pretty_table(rows, [:id, :name], {color:red}) return nil else return subnet_types[0] end end |
#find_subnet_type_by_name_or_id(val) ⇒ Object
278 279 280 281 282 283 284 |
# File 'lib/morpheus/cli/mixins/infrastructure_helper.rb', line 278 def find_subnet_type_by_name_or_id(val) if val.to_s =~ /\A\d{1,}\Z/ return find_subnet_type_by_id(val) else return find_subnet_type_by_name(val) end end |
#format_network_pool_server_status(network_pool_server, return_color = cyan) ⇒ Object
669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 |
# File 'lib/morpheus/cli/mixins/infrastructure_helper.rb', line 669 def format_network_pool_server_status(network_pool_server, return_color=cyan) out = "" status_string = network_pool_server['status'] if status_string.nil? || status_string.empty? || status_string == "unknown" out << "#{white}UNKNOWN#{network_pool_server['statusMessage'] ? "#{return_color} - #{network_pool_server['statusMessage']}" : ''}#{return_color}" # elsif network_pool_server['enabled'] == false # out << "#{red}DISABLED#{network_pool_server['statusMessage'] ? "#{return_color} - #{network_pool_server['statusMessage']}" : ''}#{return_color}" elsif status_string == 'ok' out << "#{green}#{status_string.upcase}#{return_color}" elsif status_string == 'error' || status_string == 'offline' out << "#{red}#{status_string ? status_string.upcase : 'N/A'}#{network_pool_server['statusMessage'] ? "#{return_color} - #{network_pool_server['statusMessage']}" : ''}#{return_color}" else out << "#{yellow}#{status_string.upcase}#{return_color}" end out end |
#get_available_cloud_types(refresh = false, params = {}) ⇒ Object
126 127 128 129 130 131 |
# File 'lib/morpheus/cli/mixins/infrastructure_helper.rb', line 126 def get_available_cloud_types(refresh=false, params = {}) if !@available_cloud_types || refresh @available_cloud_types = clouds_interface.cloud_types({max:1000}.deep_merge(params))['zoneTypes'] end return @available_cloud_types end |
#groups_interface ⇒ Object
12 13 14 15 16 |
# File 'lib/morpheus/cli/mixins/infrastructure_helper.rb', line 12 def groups_interface # @api_client.groups raise "#{self.class} has not defined @groups_interface" if @groups_interface.nil? @groups_interface end |
#network_groups_interface ⇒ Object
36 37 38 39 40 |
# File 'lib/morpheus/cli/mixins/infrastructure_helper.rb', line 36 def network_groups_interface # @api_client.network_groups raise "#{self.class} has not defined @network_groups_interface" if @network_groups_interface.nil? @network_groups_interface end |
#network_pool_server_column_definitions(options) ⇒ Object
644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 |
# File 'lib/morpheus/cli/mixins/infrastructure_helper.rb', line 644 def network_pool_server_column_definitions() { "ID" => 'id', "Name" => lambda {|it| it['name'] }, "Type" => lambda {|it| it['type'] ? it['type']['name'] : '' }, "URL" => lambda {|it| it['serviceUrl'] }, "App ID" => lambda {|it| it['config'] ? it['config']['appId'] : nil }, "Credentials" => lambda {|it| it['credential'] ? (it['credential']['type'] == 'local' ? '(Local)' : it['credential']['name']) : nil }, "Username" => lambda {|it| it['serviceUsername'] }, "Password" => lambda {|it| it['servicePassword'] }, "Throttle Rate" => lambda {|it| it['serviceThrottleRate'] }, "Disable SSL SNI" => lambda {|it| format_boolean it['ignoreSsl'] }, "Inventory Existing" => lambda {|it| format_boolean(it['config'] ? it['config']['inventoryExisting'] : nil) }, "IP Mode" => lambda {|it| it['serviceMode'] }, "Network Filter" => lambda {|it| it['networkFilter'] }, "Zone Filter" => lambda {|it| it['zoneFilter'] }, "Tenant Match" => lambda {|it| it['tenantMatch'] }, "Extra Attributes" => lambda {|it| it['config'] ? it['config']['extraAttributes'] : nil }, "Enabled" => lambda {|it| format_boolean(it['enabled']) }, "Status" => lambda {|it| format_network_pool_server_status(it) }, "Date Created" => lambda {|it| format_local_dt(it['dateCreated']) }, "Last Updated" => lambda {|it| format_local_dt(it['lastUpdated']) }, } end |
#network_pool_server_list_column_definitions(options) ⇒ Object
631 632 633 634 635 636 637 638 639 640 641 642 |
# File 'lib/morpheus/cli/mixins/infrastructure_helper.rb', line 631 def network_pool_server_list_column_definitions() { "ID" => 'id', "Name" => lambda {|it| it['name'] }, "Type" => lambda {|it| it['type'] ? it['type']['name'] : '' }, "URL" => lambda {|it| it['serviceUrl'] }, "Enabled" => lambda {|it| format_boolean(it['enabled']) }, "Status" => lambda {|it| format_network_pool_server_status(it) }, "Date Created" => lambda {|it| format_local_dt(it['dateCreated']) }, "Last Updated" => lambda {|it| format_local_dt(it['lastUpdated']) }, } end |
#network_pool_server_type_column_definitions(options) ⇒ Object
694 695 696 697 698 699 700 701 702 703 704 705 706 |
# File 'lib/morpheus/cli/mixins/infrastructure_helper.rb', line 694 def network_pool_server_type_column_definitions() { "ID" => 'id', "Name" => 'name', "Code" => 'code', # "Integration Code" => 'integrationCode', "Description" => 'description', "Enabled" => lambda {|it| format_boolean(it['enabled']) }, "Selectable" => lambda {|it| format_boolean(it['selectable']) }, "Plugin" => lambda {|it| format_boolean(it['isPlugin']) }, "Embedded" => lambda {|it| format_boolean(it['isEmbedded']) }, } end |
#network_pool_server_type_list_column_definitions(options) ⇒ Object
686 687 688 689 690 691 692 |
# File 'lib/morpheus/cli/mixins/infrastructure_helper.rb', line 686 def network_pool_server_type_list_column_definitions() { "ID" => 'id', "Name" => 'name', "Code" => 'code', } end |
#network_server_type_column_definitions(options) ⇒ Object
783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 |
# File 'lib/morpheus/cli/mixins/infrastructure_helper.rb', line 783 def network_server_type_column_definitions() { "ID" => 'id', "Name" => 'name', "Code" => 'code', "Description" => 'description', "Enabled" => lambda {|it| format_boolean(it['enabled']) }, "Selectable" => lambda {|it| format_boolean(it['selectable']) }, "Creatable" => lambda {|it| format_boolean(it['creatable']) }, "Plugin" => lambda {|it| format_boolean(it['isPlugin']) }, "Embedded" => lambda {|it| format_boolean(it['isEmbedded']) }, #"Integration Code" => lambda {|it| it['integrationCode'] }, "Networks" => lambda {|it| format_boolean(it['hasNetworks']) }, "Gateways" => lambda {|it| format_boolean(it['hasGateways']) }, "DHCP Servers" => lambda {|it| format_boolean(it['hasDhcpServers']) }, "DHCP Relays" => lambda {|it| format_boolean(it['hasDhcpRelays']) }, # "Route Tables" => lambda {|it| format_boolean(it['hasRouteTables']) }, "Routers" => lambda {|it| format_boolean(it['hasRouters']) }, "Switches" => lambda {|it| format_boolean(it['hasSwitches']) }, "Firewall" => lambda {|it| format_boolean(it['hasFirewall']) }, "Security Groups" => lambda {|it| format_boolean(it['hasSecurityGroups']) }, "Load Balancers" => lambda {|it| format_boolean(it['hasLoadBalancers']) }, # "Security Code" => lambda {|it| it['securityCode'] }, # "User Visible" => lambda {|it| format_boolean(it['userVisible']) }, } end |
#network_server_type_list_column_definitions(options) ⇒ Object
773 774 775 776 777 778 779 780 781 |
# File 'lib/morpheus/cli/mixins/infrastructure_helper.rb', line 773 def network_server_type_list_column_definitions() { "ID" => 'id', "Name" => 'name', "Code" => 'code', "Description" => 'description', "Enabled" => lambda {|it| format_boolean(it['enabled']) } } end |
#network_types_interface ⇒ Object
54 55 56 57 58 |
# File 'lib/morpheus/cli/mixins/infrastructure_helper.rb', line 54 def network_types_interface # @api_client.network_types raise "#{self.class} has not defined @network_types_interface" if @network_types_interface.nil? @network_types_interface end |
#networks_interface ⇒ Object
24 25 26 27 28 |
# File 'lib/morpheus/cli/mixins/infrastructure_helper.rb', line 24 def networks_interface # @api_client.networks raise "#{self.class} has not defined @networks_interface" if @networks_interface.nil? @networks_interface end |
#prompt_for_network(network_id, options = {}, required = true, field_name = 'network', field_label = 'Network') ⇒ Object
439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 |
# File 'lib/morpheus/cli/mixins/infrastructure_helper.rb', line 439 def prompt_for_network(network_id, ={}, required=true, field_name='network', field_label='Network') # Prompt for a Network, text input that searches by name or id network = nil still_prompting = true while still_prompting do v_prompt = Morpheus::Cli::OptionTypes.prompt([{'fieldName' => field_name, 'type' => 'text', 'fieldLabel' => field_label, 'required' => required, 'description' => 'Network name or ID.'}], network_id ? {(field_name) => network_id} : {}) network_id = v_prompt['network'] begin network = find_network_by_name_or_id(network_id) rescue SystemExit => cmdexit end if [:no_prompt] still_prompting = false else still_prompting = network ? false : true end if still_prompting network_id = nil end end return {success:!!network, network: network} end |
#prompt_for_networks(params, options = {}, api_client = nil, api_params = {}) ⇒ Object
462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 |
# File 'lib/morpheus/cli/mixins/infrastructure_helper.rb', line 462 def prompt_for_networks(params, ={}, api_client=nil, api_params={}) # Networks network_list = nil network_ids = nil still_prompting = true if params['networks'].nil? still_prompting = true while still_prompting do v_prompt = Morpheus::Cli::OptionTypes.prompt([{'fieldName' => 'networks', 'type' => 'text', 'fieldLabel' => 'Networks', 'required' => false, 'description' => 'Networks to include, comma separated list of names or IDs.'}], [:options]) unless v_prompt['networks'].to_s.empty? network_list = v_prompt['networks'].split(",").collect {|it| it.to_s.strip.empty? ? nil : it.to_s.strip }.compact.uniq end network_ids = [] bad_ids = [] if network_list && network_list.size > 0 network_list.each do |it| found_network = nil begin found_network = find_network_by_name_or_id(it) rescue SystemExit => cmdexit end if found_network network_ids << found_network['id'] else bad_ids << it end end end still_prompting = bad_ids.empty? ? false : true end else network_list = params['networks'] still_prompting = false network_ids = [] bad_ids = [] if network_list && network_list.size > 0 network_list.each do |it| found_network = nil begin found_network = find_network_by_name_or_id(it) rescue SystemExit => cmdexit end if found_network network_ids << found_network['id'] else bad_ids << it end end end if !bad_ids.empty? return {success:false, msg:"Networks not found: #{bad_ids}"} end end return {success:true, data: network_ids} end |
#prompt_for_pools(params, options = {}, api_client = nil, api_params = {}) ⇒ Object
575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 |
# File 'lib/morpheus/cli/mixins/infrastructure_helper.rb', line 575 def prompt_for_pools(params, ={}, api_client=nil, api_params={}) # Pools pool_list = nil pool_ids = nil still_prompting = true if params['pools'].nil? still_prompting = true while still_prompting do v_prompt = Morpheus::Cli::OptionTypes.prompt([{'fieldName' => 'pools', 'type' => 'text', 'fieldLabel' => 'Pools', 'required' => false, 'description' => 'Pools to include, comma separated list of names or IDs.'}], [:options]) unless v_prompt['pools'].to_s.empty? pool_list = v_prompt['pools'].split(",").collect {|it| it.to_s.strip.empty? ? nil : it.to_s.strip }.compact.uniq end pool_ids = [] bad_ids = [] if pool_list && pool_list.size > 0 pool_list.each do |it| found_pool = nil begin found_pool = find_resource_pool_by_name_or_id(it) rescue SystemExit => cmdexit end if found_pool pool_ids << found_pool['id'] else bad_ids << it end end end still_prompting = bad_ids.empty? ? false : true end else pool_list = params['pools'] still_prompting = false pool_ids = [] bad_ids = [] if pool_list && pool_list.size > 0 pool_list.each do |it| found_pool = nil begin found_pool = find_resource_pool_by_name_or_id(it) rescue SystemExit => cmdexit end if found_pool pool_ids << found_pool['id'] else bad_ids << it end end end if !bad_ids.empty? return {success:false, msg:"Pools not found: #{bad_ids}"} end end return {success:true, data: pool_ids} end |
#prompt_for_subnets(params, options = {}, api_client = nil, api_params = {}) ⇒ Object
518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 |
# File 'lib/morpheus/cli/mixins/infrastructure_helper.rb', line 518 def prompt_for_subnets(params, ={}, api_client=nil, api_params={}) # todo: make this a generic method now please. # Subnets record_list = nil record_ids = nil still_prompting = true if params['subnets'].nil? still_prompting = true while still_prompting do v_prompt = Morpheus::Cli::OptionTypes.prompt([{'fieldName' => 'subnets', 'type' => 'text', 'fieldLabel' => 'Subnets', 'required' => false, 'description' => 'Subnets to include, comma separated list of names or IDs.'}], [:options]) unless v_prompt['subnets'].to_s.empty? record_list = v_prompt['subnets'].split(",").collect {|it| it.to_s.strip.empty? ? nil : it.to_s.strip }.compact.uniq end record_ids = [] bad_ids = [] if record_list && record_list.size > 0 record_list.each do |it| found_record = nil begin found_record = find_subnet_by_name_or_id(it) rescue SystemExit => cmdexit end if found_record record_ids << found_record['id'] else bad_ids << it end end end still_prompting = bad_ids.empty? ? false : true end else record_list = params['subnets'] still_prompting = false record_ids = [] bad_ids = [] if record_list && record_list.size > 0 record_list.each do |it| found_subnet = nil begin found_subnet = find_subnet_by_name_or_id(it) rescue SystemExit => cmdexit end if found_subnet record_ids << found_subnet['id'] else bad_ids << it end end end if !bad_ids.empty? return {success:false, msg:"Subnets not found: #{bad_ids}"} end end return {success:true, data: record_ids} end |
#resource_pool_groups_interface ⇒ Object
42 43 44 45 46 |
# File 'lib/morpheus/cli/mixins/infrastructure_helper.rb', line 42 def resource_pool_groups_interface # @api_client.resource_pool_groups raise "#{self.class} has not defined @resource_pool_groups_interface" if @resource_pool_groups_interface.nil? @resource_pool_groups_interface end |
#resource_pools_interface ⇒ Object
48 49 50 51 52 |
# File 'lib/morpheus/cli/mixins/infrastructure_helper.rb', line 48 def resource_pools_interface # @api_client.resource_pool_groups raise "#{self.class} has not defined @cloud_resource_pools_interface" if @cloud_resource_pools_interface.nil? @cloud_resource_pools_interface end |
#subnet_types_interface ⇒ Object
60 61 62 63 64 |
# File 'lib/morpheus/cli/mixins/infrastructure_helper.rb', line 60 def subnet_types_interface # @api_client.subnet_types raise "#{self.class} has not defined @subnet_types_interface" if @subnet_types_interface.nil? @subnet_types_interface end |
#subnets_interface ⇒ Object
30 31 32 33 34 |
# File 'lib/morpheus/cli/mixins/infrastructure_helper.rb', line 30 def subnets_interface # @api_client.subnets raise "#{self.class} has not defined @subnets_interface" if @subnets_interface.nil? @subnets_interface end |