Module: Yast::NetworkLanCmdlineInclude
- Includes:
- Logger
- Defined in:
- src/include/network/lan/cmdline.rb
Defined Under Namespace
Classes: InvalidOption
Instance Method Summary collapse
-
#AddHandler(options) ⇒ Object
Handler for action "add".
-
#DeleteHandler(options) ⇒ Object
Handler for action "delete".
-
#EditHandler(options) ⇒ Object
Handler for action "edit".
- #initialize_network_lan_cmdline(_include_target) ⇒ Object
- #ListHandler(options) ⇒ Object
-
#ShowHandler(options) ⇒ Object
Handler for action "show".
- #validateId(options, config) ⇒ Object
Instance Method Details
#AddHandler(options) ⇒ Object
Handler for action "add"
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 |
# File 'src/include/network/lan/cmdline.rb', line 109 def AddHandler() # slaves option is marked as obsolete, bond_ports should be used instead. # If both options are present, new one (bond_ports) wins. if !.key?("bond_ports") && .key?("slaves") ["bond_ports"] = .delete("slaves") end type = .fetch("type", infered_type()) if type.empty? Report.Error(_("The device type is mandatory.")) return false end builder = Y2Network::InterfaceConfigBuilder.for( Y2Network::InterfaceType.from_short_name(type) ) builder.name = .fetch("name") (builder, ) builder.save ListHandler({}) true rescue InvalidOption => e Report.Error(e.) false end |
#DeleteHandler(options) ⇒ Object
Handler for action "delete"
162 163 164 165 166 167 168 169 170 171 |
# File 'src/include/network/lan/cmdline.rb', line 162 def DeleteHandler() config = Yast::Lan.yast_config return false unless validateId(, config.interfaces) interface = config.interfaces.to_a[["id"].to_i] config.delete_interface(interface.name) true end |
#EditHandler(options) ⇒ Object
Handler for action "edit"
139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 |
# File 'src/include/network/lan/cmdline.rb', line 139 def EditHandler() log.info "calling edit handler with #{}" config = Lan.yast_config.copy return false unless validateId(, config.interfaces) interface = config.interfaces.to_a[["id"].to_i] connection_config = config.connections.by_name(interface.name) builder = Y2Network::InterfaceConfigBuilder.for(interface.type, config: connection_config) builder.name = interface.name (builder, ) builder.save ShowHandler() true rescue InvalidOption => e Report.Error(e.) false end |
#initialize_network_lan_cmdline(_include_target) ⇒ Object
37 38 39 40 41 42 43 |
# File 'src/include/network/lan/cmdline.rb', line 37 def initialize_network_lan_cmdline(_include_target) textdomain "network" Yast.import "CommandLine" Yast.import "Lan" Yast.import "Report" end |
#ListHandler(options) ⇒ Object
85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 |
# File 'src/include/network/lan/cmdline.rb', line 85 def ListHandler() config = Yast::Lan.yast_config CommandLine.Print("id\tname\tbootproto") config.interfaces.to_a.each_with_index do |interface, index| connection = config.connections.by_name(interface.name) next if connection && .include?("unconfigured") next if !connection && .include?("configured") status = if !connection "Not configured" elsif connection.bootproto == Y2Network::BootProtocol::STATIC connection.ip.address.to_s else connection.bootproto.name end CommandLine.Print( "#{index}\t#{interface.name}\t#{status}" ) end true end |
#ShowHandler(options) ⇒ Object
Handler for action "show"
69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 |
# File 'src/include/network/lan/cmdline.rb', line 69 def ShowHandler() config = Yast::Lan.yast_config return false unless validateId(, config.interfaces) presenter = Y2Network::Presenters::InterfaceSummary.new( config.interfaces.to_a[["id"].to_i].name, config ) text = presenter.text # create plain text from formated HTML text.gsub!(/(<br>)|(<\/li>)/, "\n") text.gsub!(/<[^>]+>/, "") CommandLine.Print(text) true end |
#validateId(options, config) ⇒ Object
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'src/include/network/lan/cmdline.rb', line 45 def validateId(, config) if !["id"] Report.Error(_("Use \"id\" option to determine device.")) return false end begin id = Integer(["id"]) rescue ArgumentError Report.Error(_("Invalid value '%s' for \"id\" option.") % ["id"]) return false end if id >= config.size Report.Error( _("Value of \"id\" is out of range. Use \"list\" option to check max. value of \"id\".") ) return false end true end |