Class: Yast::DnsClient

Inherits:
Client
  • Object
show all
Defined in:
src/clients/dns.rb

Instance Method Summary collapse

Instance Method Details

#DNSGUIObject

Main DNS GUI


131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
# File 'src/clients/dns.rb', line 131

def DNSGUI
  Wizard.CreateDialog
  Wizard.SetDesktopTitleAndIcon("dns")
  DNS.Read
  Lan.Read(:cache)

  Wizard.SetNextButton(:next, Label.FinishButton)

  # main ui function
  ret = DNSMainDialog(true)
  Builtins.y2debug("ret == %1", ret)

  if ret == :next && DNS.modified
    DNS.Write
    # no more workarounds with dhcp-clients
    # do a full network restart (bnc#528937)
    NetworkService.StartStop
  end

  UI.CloseDialog
  deep_copy(ret)
end

#EditHandler(options) ⇒ Boolean

Handler for action "edit"


174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
# File 'src/clients/dns.rb', line 174

def EditHandler(options)
  options = deep_copy(options)
  Builtins.y2milestone("Edit handler, options: %1", options)

  # validator: a reference to boolean( string) is expected
  # setter: a reference to void( any) is expected
  # fail message: a string is expected
  option_handlers = {
    @HOSTNAME     => {
      "validator"    => fun_ref(Hostname.method(:Check), "boolean (string)"),
      "setter"       => fun_ref(method(:SetHostname), "void (any)"),
      "fail_message" => Ops.add(_("InvalidHostname. "), Hostname.ValidHost)
    },
    @NAMESERVER_1 => {
      "validator"    => fun_ref(IP.method(:Check), "boolean (string)"),
      "setter"       => fun_ref(method(:SetNameserver1), "void (any)"),
      "fail_message" => Ops.add(
        Ops.add(Ops.add(_("Invalid IP. "), IP.Valid4), "\n"),
        IP.Valid6
      )
    },
    @NAMESERVER_2 => {
      "validator"    => fun_ref(IP.method(:Check), "boolean (string)"),
      "setter"       => fun_ref(method(:SetNameserver2), "void (any)"),
      "fail_message" => Ops.add(
        Ops.add(Ops.add(_("Invalid IP. "), IP.Valid4), "\n"),
        IP.Valid6
      )
    },
    @NAMESERVER_3 => {
      "validator"    => fun_ref(IP.method(:Check), "boolean (string)"),
      "setter"       => fun_ref(method(:SetNameserver3), "void (any)"),
      "fail_message" => Ops.add(
        Ops.add(Ops.add(_("Invalid IP. "), IP.Valid4), "\n"),
        IP.Valid6
      )
    }
  }

  unmanaged_only_options = [@NAMESERVER_1, @NAMESERVER_2, @NAMESERVER_3]

  ret = true

  Builtins.foreach(options) do |option, value|
    if Builtins.contains(unmanaged_only_options, option) &&
        NetworkService.is_network_manager
      CommandLine.Print(
        Ops.add(
          Ops.add(_("Cannot set "), option),
          _(". Network is managed by NetworkManager.")
        )
      )

      ret = false
    end
    option_validator = Convert.convert(
      Ops.get(option_handlers, [option, "validator"]),
      from: "any",
      to:   "boolean (string)"
    )
    option_setter = Convert.convert(
      Ops.get(option_handlers, [option, "setter"]),
      from: "any",
      to:   "void (any)"
    )
    fail_message = Ops.get_locale(
      option_handlers,
      [option, "fail_message"],
      _("Invalid option value.")
    )
    if option_validator.nil? || option_setter.nil?
      Builtins.y2internal(
        "Edit handler: unknown option (%1=%2) or unknown option handlers",
        option,
        value
      )

      CommandLine.Print(_("Internal error"))

      ret = false
    end
    if option_validator.call(value)
      option_setter.call(value)
    else
      CommandLine.Print(fail_message)
      ret = false
    end
  end

  ret
end

#FinishHandlerBoolean

CLI mode finish handler


278
279
280
281
282
# File 'src/clients/dns.rb', line 278

def FinishHandler
  StoreHnSettings()

  DNS.Write
end

#InitHandlerBoolean

CLI mode initialization handler


268
269
270
271
272
273
274
# File 'src/clients/dns.rb', line 268

def InitHandler
  return false if !DNS.Read || !Lan.Read(:cache)

  InitHnSettings()

  true
end

#ListHandler(_options) ⇒ Object

Handler for action "list"


156
157
158
159
160
161
162
163
164
165
166
167
168
169
# File 'src/clients/dns.rb', line 156

def ListHandler(_options)
  # Command line output Headline
  summary = Ops.add(
    Ops.add(
      "\n" + _("DNS Configuration Summary:") + "\n\n",
      RichText.Rich2Plain(DNS.Summary)
    ),
    "\n"
  )

  Builtins.y2debug("%1", summary)
  CommandLine.Print(summary)
  true
end

#mainObject


34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
# File 'src/clients/dns.rb', line 34

def main
  Yast.import "UI"

  textdomain "network"

  # The main ()
  Builtins.y2milestone("----------------------------------------")
  Builtins.y2milestone("DNS module started")

  Yast.import "DNS"
  Yast.import "Label"
  Yast.import "Lan"
  Yast.import "NetworkService"
  Yast.import "Wizard"

  Yast.import "CommandLine"
  Yast.import "RichText"

  Yast.include self, "network/services/dns.rb"

  @HOSTNAME = "hostname"
  @NAMESERVER_1 = "nameserver1"
  @NAMESERVER_2 = "nameserver2"
  @NAMESERVER_3 = "nameserver3"

  # Command line definition
  @cmdline = {
    # Commandline help title
    "help"       => _("DNS Configuration"),
    "id"         => "dns",
    "guihandler" => fun_ref(method(:DNSGUI), "any ()"),
    "initialize" => fun_ref(method(:InitHandler), "boolean ()"),
    "finish"     => fun_ref(method(:FinishHandler), "boolean ()"),
    "actions"    => {
      "list" => {
        # Commandline command help
        "help"    => _(
          "Display configuration summary"
        ),
        "handler" => fun_ref(
          method(:ListHandler),
          "boolean (map <string, string>)"
        )
      },
      "edit" => {
        "help"    => _("Edit current settings"),
        "handler" => fun_ref(
          method(:EditHandler),
          "boolean (map <string, string>)"
        )
      }
    },
    "options"    => {
      @HOSTNAME     => {
        "help"    => _("Used machine hostname"),
        "type"    => "string",
        "example" => "dns edit hostname=SUSE-host"
      },
      @NAMESERVER_1 => {
        "help"    => _("IP address of first nameserver."),
        "type"    => "string",
        "example" => "dns edit nameserver1=192.168.0.1"
      },
      @NAMESERVER_2 => {
        "help"    => _("IP address of second nameserver."),
        "type"    => "string",
        "example" => "dns edit nameserver2=192.168.0.1"
      },
      @NAMESERVER_3 => {
        "help"    => _("IP address of third nameserver."),
        "type"    => "string",
        "example" => "dns edit nameserver3=192.168.0.1"
      }
    },
    "mappings"   => {
      "edit" => [@HOSTNAME, @NAMESERVER_1, @NAMESERVER_2, @NAMESERVER_3]
    }
  }

  @ret = CommandLine.Run(@cmdline)
  Builtins.y2debug("ret=%1", @ret)

  # Finish
  Builtins.y2milestone("DNS module finished")
  Builtins.y2milestone("----------------------------------------")
  deep_copy(@ret)

  # EOF
end

#ModifiedObject

Return a modification status


126
127
128
# File 'src/clients/dns.rb', line 126

def Modified
  DNS.modified
end