Module: Morpheus::Cli::NetworksHelper
- Included in:
- NetworkDhcpRelaysCommand, NetworkDhcpServersCommand, NetworkEdgeClustersCommand, NetworkFirewallsCommand, NetworkTransportZonesCommand
- Defined in:
- lib/morpheus/cli/mixins/networks_helper.rb
Overview
Provides common methods for networking commands
Class Method Summary collapse
Instance Method Summary collapse
- #find_network_server(val) ⇒ Object
- #find_network_server_by_id(id) ⇒ Object
- #find_network_server_by_name(name) ⇒ Object
- #network_servers_interface ⇒ Object
Class Method Details
.included(klass) ⇒ Object
8 9 10 |
# File 'lib/morpheus/cli/mixins/networks_helper.rb', line 8 def self.included(klass) klass.send :include, Morpheus::Cli::PrintHelper end |
Instance Method Details
#find_network_server(val) ⇒ Object
18 19 20 21 22 23 24 25 26 |
# File 'lib/morpheus/cli/mixins/networks_helper.rb', line 18 def find_network_server(val) if val.to_s =~ /\A\d{1,}\Z/ return find_network_server_by_id(val) else if server = find_network_server_by_name(val) return find_network_server_by_id(server['id']) end end end |
#find_network_server_by_id(id) ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/morpheus/cli/mixins/networks_helper.rb', line 28 def find_network_server_by_id(id) begin # Use query parameter `details=true` to get the full type object with all its configuration settings and optionTypes json_response = @network_servers_interface.get(id.to_i, {details:true}) return json_response['networkServer'] rescue RestClient::Exception => e if e.response && e.response.code == 404 print_red_alert "Network Server not found by id #{id}" return nil else raise e end end end |
#find_network_server_by_name(name) ⇒ Object
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/morpheus/cli/mixins/networks_helper.rb', line 43 def find_network_server_by_name(name) # Use query parameter `details=true` to get the full type object with all its configuration settings and optionTypes json_response = @network_servers_interface.list({phrase: name.to_s, details:true}) servers = json_response['networkServers'] if servers.empty? print_red_alert "Network Server not found by name #{name}" return nil elsif servers.size > 1 print_red_alert "#{servers.size} network servers found by name #{name}" rows = servers.collect do |it| {id: it['id'], name: it['name']} end puts as_pretty_table(rows, [:id, :name], {color:red}) return nil else return servers[0] end end |
#network_servers_interface ⇒ Object
12 13 14 15 16 |
# File 'lib/morpheus/cli/mixins/networks_helper.rb', line 12 def network_servers_interface # @api_client.network_servers raise "#{self.class} has not defined @network_servers_interface" if @network_servers_interface.nil? @network_servers_interface end |