Class: Bim::Action::Meta

Inherits:
Object
  • Object
show all
Extended by:
Util
Defined in:
lib/bim/action/meta.rb

Overview

Meta class uses by Bim::Subcommands::Meta

Constant Summary collapse

DEVICE_PATH =
'/mgmt/tm/cm/device'.freeze
DEVICE_GROUP_PATH =
'/mgmt/tm/cm/deviceGroup'.freeze

Constants included from Util

Util::VS_PATH

Class Method Summary collapse

Class Method Details

.activesObject



11
12
13
14
15
16
17
18
19
# File 'lib/bim/action/meta.rb', line 11

def actives
  uri = URI.join(Bim::BASE_URL, Bim::Action::Meta::DEVICE_PATH)
  JSON
    .parse(get_body(uri))['items']
    .select { |item| item['failoverState'] == 'active' }
    .inject([]) do |infos, item|
      infos.push(hostname: item['hostname'], ip: item['managementIp'])
    end.to_json
end

.device_groupsObject



21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/bim/action/meta.rb', line 21

def device_groups
  uri = URI.join(Bim::BASE_URL, Bim::Action::Meta::DEVICE_GROUP_PATH)
  JSON
    .parse(get_body(uri))['items']
    .select { |item| item['type'] == 'sync-failover' }
    .inject([]) do |infos, item|
      m = if item&.dig('devicesReference')&.dig('link')
            uri_r = URI.parse(item['devicesReference']['link'].sub('localhost', BIGIP_HOST))
            JSON.parse(get_body(uri_r))['items'].map { |item_in| item_in['name'] }
          end
      infos.push(name: item['name'], members: m)
    end.to_json
end