Module: NovaDsl::NovaStdoutParser
- Included in:
- NovaConsoleWrapper
- Defined in:
- lib/nova/wrapper/nova_stdout_parser.rb
Constant Summary collapse
- IP_SEARCHER =
Searches ip in the word, that ENDS by ip. Ex: s=“fo_my_vm_bar_435.as.341 = 10.3.4.5” The result: s[IP_SEARCHER=~s, s.length] results in ‘10.3.4.5` TODO: It should supports multiple ips such as: ’private=10.35.9.40, 50.56.54.87’
/[a-zA-Z0-9]*(([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\.){3}([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])$/
Instance Method Summary collapse
Instance Method Details
#parse_nova_list_stdout(stdout) ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/nova/wrapper/nova_stdout_parser.rb', line 17 def parse_nova_list_stdout(stdout) LOGGER.debug("Parsing stdout, size: #{stdout.size}") Common::type_checker stdout, String initial_strings = stdout.split("\n") LOGGER.debug("Parsing #{initial_strings.size} lines, assuming first three should be a headers and other stuff") vms = NovaDsl::NovaVmsContainer.new initial_strings.each_with_index do |line, index| columns = line.split("|").map { |s| s.strip } if index >=3 && columns.size.eql?(5) id = columns[1].to_i name = columns[2].to_s status = columns[3].capitalize ip = columns[4][IP_SEARCHER=~columns[4], columns[4].size] vms << NovaDsl::NovaVm.new(id, name, ip, status) end end vms end |
#parse_nova_show_stdout(stdout) ⇒ Object
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/nova/wrapper/nova_stdout_parser.rb', line 40 def parse_nova_show_stdout(stdout) LOGGER.debug("Parsing nova stdout") Common::type_checker stdout, String initial_strings = stdout.split("\n") LOGGER.debug("Creating key-value info instance") initial_strings.each_with_index do |line, index| columns = line.split('|').map { |s| s.strip } if index >= 3 && columns.size.eql?(5) end end end |