Class: Wire::VerifyCommand
- Inherits:
-
BaseCommand
- Object
- BaseCommand
- Wire::VerifyCommand
- Defined in:
- lib/wire/commands/verify_command.rb
Overview
Verify Command reads yaml, parses model elements and checks if given elements are present on the system rubocop:disable ClassLength
Instance Attribute Summary collapse
-
#findings ⇒ Object
project- to operate upon
findings -
is an array of potential errors that occured during verification run.
- to operate upon
-
#handler ⇒ Object
readonly
allow to get access to handler object.
-
#project ⇒ Object
project- to operate upon
findings -
is an array of potential errors that occured during verification run.
- to operate upon
Attributes inherited from BaseCommand
Instance Method Summary collapse
-
#initialize ⇒ VerifyCommand
constructor
set up with empty findings arraay.
-
#mark(msg, type, element_name, element_data) ⇒ Object
- add a finding to the findings array params:
msg - what went wrong
type -
element type, i.e.
- what went wrong
- add a finding to the findings array params:
-
#run_on_project ⇒ Object
run verification on whole project iterates all zones, descend into zone verification returns: - [bool] true = verification ok.
-
#run_on_project_zones(zones) ⇒ Object
run verification on given
zones. -
#run_on_zone(zone_name) ⇒ Object
run verification for given
zone_name: - check if bridges exist for all networks in this zone. -
#verify_appgroups(appgroups, zone_name) ⇒ Object
Given a
zone_nameand an array ofappgroupsentries this methods verifies if these appgroups are up and running It also checks container’s network attachments. -
#verify_networks(networks_in_zone, zone_name) ⇒ Object
given an array of network elements (
networks_in_zone), this method runs the verification on each network.
Methods inherited from BaseCommand
#check_user, #default_handle_resource, #dump_state, #ensure_hostip_netmask, #objects_in_zone, #outputs, #run, #state
Constructor Details
#initialize ⇒ VerifyCommand
set up with empty findings arraay
21 22 23 24 |
# File 'lib/wire/commands/verify_command.rb', line 21 def initialize @findings = [] @handler = VerifyCommandHandler.new end |
Instance Attribute Details
#findings ⇒ Object
project-
to operate upon
findings-
is an array of potential errors that occured
during verification run
16 17 18 |
# File 'lib/wire/commands/verify_command.rb', line 16 def findings @findings end |
#handler ⇒ Object (readonly)
allow to get access to handler object
18 19 20 |
# File 'lib/wire/commands/verify_command.rb', line 18 def handler @handler end |
#project ⇒ Object
project-
to operate upon
findings-
is an array of potential errors that occured
during verification run
16 17 18 |
# File 'lib/wire/commands/verify_command.rb', line 16 def project @project end |
Instance Method Details
#mark(msg, type, element_name, element_data) ⇒ Object
add a finding to the findings array params:
msg-
what went wrong
type-
element type, i.e. Network
element_name-
element_name
element_data-
map of details, from model
32 33 34 35 36 |
# File 'lib/wire/commands/verify_command.rb', line 32 def mark(msg, type, element_name, element_data) @findings << VerificationError.new(msg, type, element_name, element_data) end |
#run_on_project ⇒ Object
run verification on whole project iterates all zones, descend into zone verification returns:
- bool
-
true = verification ok
43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/wire/commands/verify_command.rb', line 43 def run_on_project zones = @project.get_element('zones') # iterates all zones, descend into zone # for further checks, mark all those bad # zones, decide upon boolean return flag (run_on_project_zones(zones) .each do |zone_name, zone_data| # error occured in run_on_zone call. Lets mark this zone_data.store :status, :failed mark("Not all elements of zone \'#{zone_name}\' are valid.", :zone, zone_name, zone_data) end.size > 0) end |
#run_on_project_zones(zones) ⇒ Object
run verification on given zones
59 60 61 62 63 64 65 66 67 68 69 70 71 72 |
# File 'lib/wire/commands/verify_command.rb', line 59 def run_on_project_zones(zones) zones.select do |zone_name, _| $log.debug("Verifying zone #{zone_name} ...") b_zone_res = run_on_zone(zone_name) if b_zone_res outputs 'VERIFY', "Zone \'#{zone_name}\' verified successfully", :ok else outputs 'VERIFY', "Zone \'#{zone_name}\' NOT verified successfully", :err end b_zone_res == false end end |
#run_on_zone(zone_name) ⇒ Object
run verification for given zone_name:
-
check if bridges exist for all networks in this zone
77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 |
# File 'lib/wire/commands/verify_command.rb', line 77 def run_on_zone(zone_name) networks = @project.get_element('networks') b_verify_ok = true # select networks in current zone only networks_in_zone = networks.select do |_, network_data| network_data[:zone] == zone_name end # verify these networks b_verify_ok = false unless verify_networks(networks_in_zone, zone_name) # select appgroups in this zone and verify them appgroups_in_zone = objects_in_zone('appgroups', zone_name) b_verify_ok = false unless verify_appgroups(appgroups_in_zone, zone_name) b_verify_ok end |
#verify_appgroups(appgroups, zone_name) ⇒ Object
Given a zone_name and an array of appgroups entries this methods verifies if these appgroups are up and running It also checks container’s network attachments
163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 |
# File 'lib/wire/commands/verify_command.rb', line 163 def verify_appgroups(appgroups, zone_name) b_verify_ok = true appgroups.each do |appgroup_name, appgroup_data| $log.debug("Verifying appgroup \'#{appgroup_name}\'") if @handler.handle_appgroup(zone_name, appgroup_name, appgroup_data, @project.target_dir) == false appgroup_data.store :status, :failed b_verify_ok = false mark("Appgroup \'#{appgroup_name}\' does not run correctly.", :appgroup, appgroup_name, appgroup_data) else appgroup_data.store :status, :ok end next unless b_verify_ok zone_networks = objects_in_zone('networks', zone_name) if @handler.(zone_name, zone_networks, appgroup_name, appgroup_data, @project.target_dir) == false appgroup_data.store :status, :failed b_verify_ok = false mark("Appgroup \'#{appgroup_name}\' has missing network attachments", :appgroup, appgroup_name, appgroup_data) else appgroup_data.store :status, :ok end end b_verify_ok end |
#verify_networks(networks_in_zone, zone_name) ⇒ Object
given an array of network elements (networks_in_zone), this method runs the verification on each network. It checks the availability of a bridge and the optional host ip on that bridge. Params:
networks_in_zone-
Array of network data elements in desired zone
zone_name-
Name of zone
103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 |
# File 'lib/wire/commands/verify_command.rb', line 103 def verify_networks(networks_in_zone, zone_name) b_verify_ok = true networks_in_zone.each do |network_name, network_data| $log.debug("Verifying network \'#{network_name}\'") bridge_name = network_name $log.debug 'checking bridge ...' # we should have a bridge with that name. if @handler.handle_bridge(bridge_name) == false network_data.store :status, :failed b_verify_ok = false mark("Bridge \'#{bridge_name}\' does not exist.", :network, network_name, network_data) else network_data.store :status, :ok hostip = network_data[:hostip] # if we have a host ip, then that bridge should have # this ip if hostip $log.debug 'checking host-ip ...' # if the hostip is not in cidr, take netmask # from network entry, add to hostip hostip = ensure_hostip_netmask(hostip, network_data) if @handler.handle_hostip(bridge_name, hostip) == false network_data.store :status, :failed b_verify_ok = false mark("Host ip \'#{hostip}\' not up on bridge \'#{bridge_name}\'.", :network, network_name, network_data) else network_data.store :status, :ok end end # if we have dhcp, check this dhcp_data = network_data[:dhcp] if dhcp_data $log.debug 'checking dhcp ...' if @handler.handle_dhcp(zone_name, network_name, network_data, dhcp_data[:start], dhcp_data[:end]) == false network_data.store :status, :failed b_verify_ok = false mark("dnsmasq/dhcp not configured on network \'#{bridge_name}\'.", :network, network_name, network_data) else network_data.store :status, :ok end end end end b_verify_ok end |