Class: Wire::UpDownCommand
- Inherits:
-
BaseCommand
- Object
- BaseCommand
- Wire::UpDownCommand
- Defined in:
- lib/wire/commands/updown_command_base.rb
Overview
Base class for up/down commands
Direct Known Subclasses
Instance Attribute Summary
Attributes inherited from BaseCommand
Class Method Summary collapse
-
.get_networks_for_zone(networks, zone_name) ⇒ Object
returns networks from given
networksarray that belong tozone_nameparams:networks: array of all networkszone_name: name of desired zone returns: # => [Array] of networks for given zone.
Instance Method Summary collapse
-
#default_handle_dhcp(zone_name, network_name, network_data, handler) ⇒ Object
if dhcp is part of given
network_data, usehandlerto process it. -
#default_handle_hostip(network_name, network_data, handler) ⇒ Object
if host ip is enabled for given network (
network_name,network_data) usehandlerto process it. -
#run_on_project ⇒ Object
generic method, calls run_on_project_zones for all zones in model.
-
#run_on_project_zones(zones) ⇒ Object
run on all given
zonesReturns [Hash] of zones that failed.
Methods inherited from BaseCommand
#check_user, #default_handle_resource, #dump_state, #ensure_hostip_netmask, #objects_in_zone, #outputs, #run, #state
Class Method Details
.get_networks_for_zone(networks, zone_name) ⇒ Object
returns networks from given networks array that belong to zone_name params: networks: array of all networks zone_name: name of desired zone returns: # => [Array] of networks for given zone
73 74 75 76 77 78 |
# File 'lib/wire/commands/updown_command_base.rb', line 73 def self.get_networks_for_zone(networks, zone_name) # select networks in given zone only networks.select do |_, network_data| network_data[:zone] == zone_name end end |
Instance Method Details
#default_handle_dhcp(zone_name, network_name, network_data, handler) ⇒ Object
if dhcp is part of given network_data, use handler to process it.
zone_name-
Name of zone
network_name-
Name of network
40 41 42 43 44 45 46 47 48 |
# File 'lib/wire/commands/updown_command_base.rb', line 40 def default_handle_dhcp(zone_name, network_name, network_data, handler) dhcp_data = network_data[:dhcp] return true unless dhcp_data $log.debug 'Processing dhcp/dnsmasq ...' handler.handle_dhcp(zone_name, network_name, network_data, dhcp_data[:start], dhcp_data[:end]) end |
#default_handle_hostip(network_name, network_data, handler) ⇒ Object
if host ip is enabled for given network (network_name, network_data) use handler to process it
52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/wire/commands/updown_command_base.rb', line 52 def default_handle_hostip(network_name, network_data, handler) hostip = network_data[:hostip] return true unless hostip $log.debug "Processing host ip on network #{network_name} ..." # if the hostip is not in cidr, take netmask # from network entry, add to hostip hostip = ensure_hostip_netmask(hostip, network_data) # forward to handler handler.handle_hostip(network_name, hostip) end |
#run_on_project ⇒ Object
generic method, calls run_on_project_zones for all zones in model
13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/wire/commands/updown_command_base.rb', line 13 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 end.size > 0) end |
#run_on_project_zones(zones) ⇒ Object
run on all given zones Returns [Hash] of zones that failed.
29 30 31 32 33 34 |
# File 'lib/wire/commands/updown_command_base.rb', line 29 def run_on_project_zones(zones) zones.select do |zone_name, _| $log.debug("Processing zone #{zone_name} ...") run_on_zone(zone_name) == false end end |