Class: Bim::Action::Sync

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

Overview

Sync class used by Bim::Subcommands::Sync

Constant Summary collapse

SYNC_PATH =
'/mgmt/tm/cm'.freeze
SYNC_STATE_PATH =
'/mgmt/tm/cm/syncStatus'.freeze
FAILOVER_STATE_PATH =
'/mgmt/tm/cm/failoverStatus'.freeze

Constants included from Util

Util::VS_PATH

Class Method Summary collapse

Class Method Details

.failover_stateObject



32
33
34
35
36
37
38
39
40
41
42
# File 'lib/bim/action/sync.rb', line 32

def failover_state
  uri = URI.join(Bim::BASE_URL, Bim::Action::Sync::FAILOVER_STATE_PATH)
  req = request(uri, Bim::AUTH, 'application/json')
  body = JSON.parse(http(uri).request(req).body)
  body['entries'].each_with_object({}) do |(_key, value), info|
    entries = value['nestedStats']['entries']
    info['color']   = entries['color']['description']
    info['summary'] = entries['summary']['description']
    info['status']  = entries['status']['description']
  end.to_json
end

.stateObject



20
21
22
23
24
25
26
27
28
29
30
# File 'lib/bim/action/sync.rb', line 20

def state
  uri = URI.join(Bim::BASE_URL, Bim::Action::Sync::SYNC_STATE_PATH)
  req = request(uri, Bim::AUTH, 'application/json')
  res = http(uri).request(req)
  body = JSON.parse(res.body)
  body['entries'].each_with_object({}) do |(_key, value), info|
    entries = value['nestedStats']['entries']
    info['color']   = entries['color']['description']
    info['summary'] = entries['summary']['description']
  end.to_json
end

.sync!(dest, overwrite: false) ⇒ Object



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

def sync!(dest, overwrite: false)
  msg = "you want to sync #{BIGIP_HOST} configuration to #{dest}? [y|n]"
  return { 'message' => "cancel sync #{BIGIP_HOST} to #{dest}" } unless yes_or_no?(msg)
  uri = URI.join(Bim::BASE_URL, Bim::Action::Sync::SYNC_PATH)
  j = { "command": 'run', "utilCmdArgs": "config-sync #{'force-full-load-push ' if overwrite}to-group #{dest}" }
  post(uri, j.to_json)
end