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"
110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 |
# File 'src/include/network/lan/cmdline.rb', line 110 def AddHandler() 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, ) LanItems.Commit(builder) ListHandler({}) true rescue InvalidOption => e Report.Error(e.) false end |
#DeleteHandler(options) ⇒ Object
Handler for action "delete"
155 156 157 158 159 160 161 162 163 164 |
# File 'src/include/network/lan/cmdline.rb', line 155 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"
132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 |
# File 'src/include/network/lan/cmdline.rb', line 132 def EditHandler() log.info "calling edit handler with #{options}" 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, ) LanItems.Commit(builder) ShowHandler() true rescue InvalidOption => e Report.Error(e.) false end |
#initialize_network_lan_cmdline(_include_target) ⇒ Object
39 40 41 42 43 44 45 46 |
# File 'src/include/network/lan/cmdline.rb', line 39 def initialize_network_lan_cmdline(_include_target) textdomain "network" Yast.import "CommandLine" Yast.import "Lan" Yast.import "Report" Yast.import "LanItems" end |
#ListHandler(options) ⇒ Object
86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 |
# File 'src/include/network/lan/cmdline.rb', line 86 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"
72 73 74 75 76 77 78 79 80 81 82 83 84 |
# File 'src/include/network/lan/cmdline.rb', line 72 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
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 |
# File 'src/include/network/lan/cmdline.rb', line 48 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 |