Class List Method List File List

# Module: Yast::NtpClientCommandlineInclude

Defined in:
  ../../src/include/ntp-client/commandline.rb

## Instance Method Summary (collapse)

- - (Object) findSyncRecord(options)

  Find the synchronization record the map is about.

- - (String) getSyncRecordType(options)

  Get the type of the synchronization record.

- - (Object) initialize_ntp_client_commandline(include_target)
- - (Boolean) NtpAddHandler(options)

  Handler for command line interface.

- - (Boolean) NtpDeleteHandler(options)

  Handler for command line interface.

- - (Boolean) NtpDisableHandler(options)

  Handler for command line interface.

- - (Boolean) NtpEditHandler(options)

  Handler for command line interface.

- - (Boolean) NtpEnableHandler(options)

  Handler for command line interface.

- - (Boolean) NtpListHandler(options)

  Handler for command line interface.

- - (Boolean) NtpStatusHandler(options)

  Handler for command line interface.

- - (Boolean) updateSyncRecord(options)

  Update the synchronization record.

## Instance Method Details

### - (`Object`) findSyncRecord(options)

Find the synchronization record the map is about

Parameters:

- options (`Hash`) —

  map of command line options

Returns:

- index of the found record, -1 in case of an error

    186
    187
    188
    189
    190
    191
    192
    193
    194
    195
    196
    197
    198
    199
    200
    201
    202
    # File '../../src/include/ntp-client/commandline.rb', line 186

    def findSyncRecord(options)
      options = deep_copy(options)
      type = getSyncRecordType(options)
      if type == ""
        # error report for command line
        CommandLine.Print(_("The synchronization peer not specified."))
        return -1
      end
      address = Ops.get_string(options, type, "")
      index = NtpClient.findSyncRecord(type, address)
      if index == -1
        # error report for command line
        CommandLine.Print(_("Specified synchronization peer not found."))
        return -1
      end
      index
    end

### - (`String`) getSyncRecordType(options)

Get the type of the synchronization record

Parameters:

- options (`Hash`) —

  a map of the command line options

Returns:

- (`String`) —

  the sync record type

    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    # File '../../src/include/ntp-client/commandline.rb', line 168

    def getSyncRecordType(options)
      options = deep_copy(options)
      type = ""
      if Builtins.haskey(options, "server")
        type = "server"
      elsif Builtins.haskey(options, "peer")
        type = "peer"
      elsif Builtins.haskey(options, "broadcast")
        type = "broadcast"
      elsif Builtins.haskey(options, "broadcastclient")
        type = "broadcastclient"
      end
      type
    end

### - (`Object`) initialize_ntp_client_commandline(include_target)

    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    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
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    # File '../../src/include/ntp-client/commandline.rb', line 13

    def initialize_ntp_client_commandline(include_target)
      Yast.import "CommandLine"
      Yast.import "NtpClient"

      textdomain "ntp-client"

      @cmdline = {
        "id"         => "ntp-client",
        # command line help text for NTP client module
        "help"       => _(
          "NTP client configuration module."
        ),
        "guihandler" => fun_ref(method(:GuiHandler), "boolean ()"),
        "initialize" => fun_ref(NtpClient.method(:Read), "boolean ()"),
        "finish"     => fun_ref(NtpClient.method(:Write), "boolean ()"),
        "actions"    => {
          "status"  => {
            "handler" => fun_ref(method(:NtpStatusHandler), "boolean (map)"),
            # command line help text for an action
            "help"    => _(
              "Print the status of the NTP daemon"
            )
          },
          "list"    => {
            "handler" => fun_ref(method(:NtpListHandler), "boolean (map)"),
            # command line help text for an action
            "help"    => _(
              "Print all configured synchronization relationships"
            )
          },
          "enable"  => {
            "handler" => fun_ref(method(:NtpEnableHandler), "boolean (map)"),
            # command line help text for an action
            "help"    => _(
              "Enable the NTP daemon"
            )
          },
          "disable" => {
            "handler" => fun_ref(method(:NtpDisableHandler), "boolean (map)"),
            # command line help text for an action
            "help"    => _(
              "Disable the NTP daemon"
            )
          },
          "add"     => {
            "handler" => fun_ref(method(:NtpAddHandler), "boolean (map)"),
            # command line help text for an action
            "help"    => _(
              "Add new synchronization relationship"
            )
          },
          "edit"    => {
            "handler" => fun_ref(method(:NtpEditHandler), "boolean (map)"),
            # command line help text for an action
            "help"    => _(
              "Edit existing synchronization relationship"
            )
          },
          "delete"  => {
            "handler" => fun_ref(method(:NtpDeleteHandler), "boolean (map)"),
            # command line help text for an action
            "help"    => _(
              "Delete a synchronization relationship"
            )
          }
        },
        "options"    => {
          "server"          => {
            # command line help text for an option
            "help" => _(
              "The address of the server"
            ),
            "type" => "string"
          },
          "peer"            => {
            # command line help text for an option
            "help" => _(
              "The address of the peer"
            ),
            "type" => "string"
          },
          "broadcast"       => {
            # command line help text for an option
            "help" => _(
              "The address to which to broadcast"
            ),
            "type" => "string"
          },
          "broadcastclient" => {
            # command line help text for an option
            "help" => _(
              "The address from which to accept broadcasts"
            ),
            "type" => "string"
          },
          "options"         => {
            # command line help text for an option
            "help" => _(
              "The options of the relationship"
            ),
            "type" => "string"
          },
          "fudge"           => {
            # command line help text for an option
            "help" => _(
              "Options for clock driver calibration"
            ),
            "type" => "string"
          },
          "initial"         => {
            # command line help text for an option
            "help" => _(
              "Use the server for initial synchronization"
            )
          },
          "no-initial"      => {
            # command line help text for an option
            "help" => _(
              "Do not use the server for initial synchronization"
            )
          }
        },
        "mappings"   => {
          "status"  => [],
          "list"    => [],
          "enable"  => [],
          "disable" => [],
          "add"     => [
            "server",
            "peer",
            "broadcast",
            "broadcastclient",
            "options",
            "fudge",
            "initial"
          ],
          "edit"    => [
            "server",
            "peer",
            "broadcast",
            "broadcastclient",
            "options",
            "fudge",
            "initial",
            "no-initial"
          ],
          "delete"  => ["server", "peer", "broadcast", "broadcastclient"]
        }
      }
    end

### - (`Boolean`) NtpAddHandler(options)

Handler for command line interface

Parameters:

- options (`Hash`) —

  map options from the command line

Returns:

- (`Boolean`) —

  true if settings have been changed

    329
    330
    331
    332
    333
    # File '../../src/include/ntp-client/commandline.rb', line 329

    def NtpAddHandler(options)
      options = deep_copy(options)
      NtpClient.selectSyncRecord(-1)
      updateSyncRecord(options)
    end

### - (`Boolean`) NtpDeleteHandler(options)

Handler for command line interface

Parameters:

- options (`Hash`) —

  map options from the command line

Returns:

- (`Boolean`) —

  true if settings have been changed

    353
    354
    355
    356
    357
    358
    359
    # File '../../src/include/ntp-client/commandline.rb', line 353

    def NtpDeleteHandler(options)
      options = deep_copy(options)
      index = findSyncRecord(options)
      return false if Ops.less_than(index, 0)
      NtpClient.deleteSyncRecord(index)
      true
    end

### - (`Boolean`) NtpDisableHandler(options)

Handler for command line interface

Parameters:

- options (`Hash`) —

  map options from the command line

Returns:

- (`Boolean`) —

  true if settings have been changed

    319
    320
    321
    322
    323
    324
    # File '../../src/include/ntp-client/commandline.rb', line 319

    def NtpDisableHandler(options)
      options = deep_copy(options)
      NtpClient.modified = NtpClient.run_service
      NtpClient.run_service = false
      true
    end

### - (`Boolean`) NtpEditHandler(options)

Handler for command line interface

Parameters:

- options (`Hash`) —

  map options from the command line

Returns:

- (`Boolean`) —

  true if settings have been changed

    338
    339
    340
    341
    342
    343
    344
    345
    346
    347
    348
    # File '../../src/include/ntp-client/commandline.rb', line 338

    def NtpEditHandler(options)
      options = deep_copy(options)
      index = findSyncRecord(options)
      return false if Ops.less_than(index, 0)
      if !NtpClient.selectSyncRecord(index)
        # command line error message
        CommandLine.Print(_("Reading the settings failed."))
        return false
      end
      updateSyncRecord(options)
    end

### - (`Boolean`) NtpEnableHandler(options)

Handler for command line interface

Parameters:

- options (`Hash`) —

  map options from the command line

Returns:

- (`Boolean`) —

  true if settings have been changed

    309
    310
    311
    312
    313
    314
    # File '../../src/include/ntp-client/commandline.rb', line 309

    def NtpEnableHandler(options)
      options = deep_copy(options)
      NtpClient.modified = !NtpClient.run_service
      NtpClient.run_service = true
      true
    end

### - (`Boolean`) NtpListHandler(options)

Handler for command line interface

Parameters:

- options (`Hash`) —

  map options from the command line

Returns:

- (`Boolean`) —

  true if settings have been changed

    262
    263
    264
    265
    266
    267
    268
    269
    270
    271
    272
    273
    274
    275
    276
    277
    278
    279
    280
    281
    282
    283
    284
    285
    286
    287
    288
    289
    290
    291
    292
    293
    294
    295
    296
    297
    298
    299
    300
    301
    302
    303
    304
    # File '../../src/include/ntp-client/commandline.rb', line 262

    def NtpListHandler(options)
      options = deep_copy(options)
      # FIXME there is some code duplication with the initialization handler of the
      # overview widget
      types = {
        # table cell, NTP relationship type
        "server"          => _("Server"),
        # table cell, NTP relationship type
        "peer"            => _("Peer"),
        # table cell, NTP relationship type
        "broadcast"       => _("Broadcast"),
        # table cell, NTP relationship type
        "broadcastclient" => _(
          "Accepting Broadcasts"
        )
      }
      Builtins.foreach(NtpClient.getSyncRecords) do |i|
        type = Ops.get_string(i, "type", "")
        address = Ops.get_string(i, "address", "")
        index = Ops.get_integer(i, "index", -1)
        if type == "__clock"
          clock_type = getClockType(address)
          unit_number = getClockUnitNumber(address)
          device = Ops.get_string(i, "device", "")
          if device == ""
            # table cell, %1 is integer 0-3
            device = Builtins.sformat(_("Unit Number: %1"), unit_number)
          end
          device = "" if clock_type == 1 && unit_number == 0
          clock_name = Ops.get(@clock_types, [clock_type, "name"], "")
          if clock_name == ""
            # table cell, NTP relationship type
            clock_name = _("Local Radio Clock")
          end
          CommandLine.Print(Builtins.sformat("%1 %2", clock_name, device))
        else
          CommandLine.Print(
            Builtins.sformat("%1 %2", Ops.get_string(types, type, ""), address)
          )
        end
      end
      false
    end

### - (`Boolean`) NtpStatusHandler(options)

Handler for command line interface

Parameters:

- options (`Hash`) —

  map options from the command line

Returns:

- (`Boolean`) —

  true if settings have been changed

    247
    248
    249
    250
    251
    252
    253
    254
    255
    256
    257
    # File '../../src/include/ntp-client/commandline.rb', line 247

    def NtpStatusHandler(options)
      options = deep_copy(options)
      CommandLine.Print(
        NtpClient.run_service ?
          # status information for command line
          _("NTP daemon is enabled.") :
          # status information for command line
          _("NTP daemon is disabled.")
      )
      false
    end

### - (`Boolean`) updateSyncRecord(options)

Update the synchronization record

Parameters:

- options (`Hash`) —

  map of command line options

Returns:

- (`Boolean`) —

  true on success

    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
    # File '../../src/include/ntp-client/commandline.rb', line 207

    def updateSyncRecord(options)
      options = deep_copy(options)
      type = Ops.get_string(NtpClient.selected_record, "type", "")
      if type == ""
        type = getSyncRecordType(options)
        Ops.set(NtpClient.selected_record, "type", type)
      end
      if Builtins.haskey(options, type)
        Ops.set(
          NtpClient.selected_record,
          "address",
          Ops.get_string(options, type, "")
        )
      end
      if Builtins.haskey(options, "options")
        Ops.set(
          NtpClient.selected_record,
          "options",
          Ops.get_string(options, "options", "")
        )
      end
      if Builtins.haskey(options, "fudge")
        Ops.set(
          NtpClient.selected_record,
          "fudge_options",
          Ops.get_string(options, "fudge", "")
        )
      end
      if Builtins.haskey(options, "initial")
        Builtins.y2warning("option 'initial' is obsolete")
      end
      if Builtins.haskey(options, "no-initial")
        Builtins.y2warning("option 'no-initial' is obsolete")
      end
      NtpClient.storeSyncRecord
    end