Class: Wire::DownCommandHandler
- Inherits:
-
BaseCommand
- Object
- BaseCommand
- Wire::DownCommandHandler
- Defined in:
- lib/wire/commands/down_command_handler.rb
Overview
implements handle_xxx methods for DownCommand delegates to BaseCommand.default_handle_resource for most parts rubocop:disable ClassLength
Instance Attribute Summary
Attributes inherited from BaseCommand
Instance Method Summary collapse
-
#handle_appgroup(zone_name, appgroup_name, appgroup_entry, target_dir) ⇒ Object
take the appgroups’ controller and directs methods to it.
-
#handle_appgroup__fig(zone_name, appgroup_name, appgroup_entry, target_dir) ⇒ Object
- implement appgroup handling for fig controller Params:
zone_name - Name of zone
appgroup_name - Name of Appgroup
appgroup_entry - Appgroup data from model
target_dir -
Target directory (where fig file is located).
- Appgroup data from model
- Name of Appgroup
- Name of zone
- implement appgroup handling for fig controller Params:
-
#handle_bridge(bridge_name) ⇒ Object
take bridge down.
-
#handle_dhcp(zone_name, network_name, network_entry, address_start, address_end) ⇒ Object
unconfigures dnsmasq for dhcp params:
zone_namename of zonenetwork_namename of network (and bridge)networknetwork entryaddress_startstart of address range (i.e.192.168.10.10)address_endend of dhcp address range (i.e.192.168.10.100) Returns - [Bool] true if dhcp setup is valid. -
#handle_hostip(bridge_name, hostip) ⇒ Object
remove ip from bridge interface.
-
#handle_network_attachments(_zone_name, networks, appgroup_name, appgroup_entry, target_dir) ⇒ Object
detaches networks to containers of appgroup Params:
_zone_name: Name of zonenetworks: Array of networks names, what to attachappgroup_name: Name of appgroupappgroup_entry: appgroup hashtarget_dir: project target dir Returns - [Bool] true if appgroup setup is ok.
Methods inherited from BaseCommand
#check_user, #default_handle_resource, #dump_state, #ensure_hostip_netmask, #objects_in_zone, #outputs, #run, #state
Instance Method Details
#handle_appgroup(zone_name, appgroup_name, appgroup_entry, target_dir) ⇒ Object
take the appgroups’ controller and directs methods to it. First checks if appgroup is down. If so, ok. If not, take it down and ensure that it’s down Params:
zone_name-
Name of zone
appgroup_name-
Name of Appgroup
appgroup_entry-
Appgroup data from model
target_dir-
Target directory (where fig file is located)
65 66 67 68 69 70 71 72 73 74 75 76 77 78 |
# File 'lib/wire/commands/down_command_handler.rb', line 65 def handle_appgroup(zone_name, appgroup_name, appgroup_entry, target_dir) # get path controller_entry = appgroup_entry[:controller] if controller_entry[:type] == 'fig' return handle_appgroup__fig(zone_name, appgroup_name, appgroup_entry, target_dir) end $log.error "Appgroup not handled for zone #{zone_name}, " \ "unknown controller type #{controller_entry[:type]}" false rescue => e $log.error "processing appgroup: #{e}" end |
#handle_appgroup__fig(zone_name, appgroup_name, appgroup_entry, target_dir) ⇒ Object
implement appgroup handling for fig controller Params:
zone_name-
Name of zone
appgroup_name-
Name of Appgroup
appgroup_entry-
Appgroup data from model
target_dir-
Target directory (where fig file is located)
86 87 88 89 90 91 92 93 94 95 96 97 98 99 |
# File 'lib/wire/commands/down_command_handler.rb', line 86 def handle_appgroup__fig(zone_name, appgroup_name, appgroup_entry, target_dir) # get path controller_entry = appgroup_entry[:controller] fig_path = File.join(File.(target_dir), controller_entry[:file]) resource_fig = Wire::Resource::ResourceFactory .instance.create(:figadapter, "#{appgroup_name}", fig_path) default_handle_resource(resource_fig, :appgroup, "appgroup \'#{appgroup_name}\' for zone \'#{zone_name}\'", :down) rescue => e $log.error "processing appgroup/fig: #{e}" end |
#handle_bridge(bridge_name) ⇒ Object
take bridge down
14 15 16 17 18 19 |
# File 'lib/wire/commands/down_command_handler.rb', line 14 def handle_bridge(bridge_name) bridge_resource = Wire::Resource::ResourceFactory.instance.create(:ovsbridge, bridge_name) default_handle_resource(bridge_resource, :bridge, "Bridge \'#{bridge_name}\'", :down) rescue => e $log.error "processing bridge: #{e}" end |
#handle_dhcp(zone_name, network_name, network_entry, address_start, address_end) ⇒ Object
unconfigures dnsmasq for dhcp params: zone_name name of zone network_name name of network (and bridge) network network entry address_start start of address range (i.e.192.168.10.10) address_end end of dhcp address range (i.e.192.168.10.100) Returns
- Bool
-
true if dhcp setup is valid
47 48 49 50 51 52 53 54 55 |
# File 'lib/wire/commands/down_command_handler.rb', line 47 def handle_dhcp(zone_name, network_name, network_entry, address_start, address_end) resource_dhcp = Wire::Resource::ResourceFactory .instance.create(:dhcpconfig, "wire__#{zone_name}", network_name, network_entry, address_start, address_end) default_handle_resource(resource_dhcp, :dnsmasq, "dnsmasq/dhcp config on network \'#{network_name}\'", :down) rescue => e $log.error "processing dhcp configuration: #{e}" end |
#handle_hostip(bridge_name, hostip) ⇒ Object
remove ip from bridge interface
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/wire/commands/down_command_handler.rb', line 22 def handle_hostip(bridge_name, hostip) bridge_resource = Wire::Resource::ResourceFactory.instance.create(:ovsbridge, bridge_name) if bridge_resource.down? outputs 'DOWN', "Bridge #{bridge_name} already down, will not care about ip", :ok2 return true end # we should have a bridge with that name. hostip_resource = Wire::Resource::ResourceFactory .instance.create(:bridgeip, hostip, bridge_name) default_handle_resource(hostip_resource, :hostip, "IP \'#{hostip}\' on bridge \'#{bridge_name}\'", :down) rescue => e $log.error "processing host ip: #{e}" end |
#handle_network_attachments(_zone_name, networks, appgroup_name, appgroup_entry, target_dir) ⇒ Object
detaches networks to containers of appgroup Params: _zone_name: Name of zone networks: Array of networks names, what to attach appgroup_name: Name of appgroup appgroup_entry: appgroup hash target_dir: project target dir Returns
- Bool
-
true if appgroup setup is ok
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 |
# File 'lib/wire/commands/down_command_handler.rb', line 110 def (_zone_name, networks, appgroup_name, appgroup_entry, target_dir) # query container ids of containers running here # get path controller_entry = appgroup_entry[:controller] container_ids = [] if controller_entry[:type] == 'fig' fig_path = File.join(File.(target_dir), controller_entry[:file]) resource_fig = Wire::Resource::ResourceFactory .instance.create(:figadapter, "#{appgroup_name}", fig_path) container_ids = resource_fig.up_ids || [] $log.debug "Got #{container_ids.size} container id(s) from adapter" end # resource_nw = Wire::Resource::ResourceFactory .instance.create(:networkinjection, appgroup_name, networks, container_ids) default_handle_resource(resource_nw, :network_injection, "Network(s) \'#{networks.keys.join(',')}\' in "\ "appgroup \'#{appgroup_name}\'", :down) rescue => e $log.error "processing network attachments: #{e}" end |