Class List Method List File List

# Module: Yast::NfsRoutinesInclude

Defined in:
  ../../src/include/nfs/routines.rb

## Instance Method Summary (collapse)

- - (Object) CheckHostName(name)

  Check for the validity of a hostname: nonempty, shorter than 50 chars, [-A-Za-z._].

- - (Object) CheckPath(name)

  Check for the validity of a path/mountpoint: nonempty, fewer than 70 chars, starts with a slash.

- - (Object) FormatHostnameForFstab(hostname)

  Formats hostname into form suitable for fstab.

- - (Object) FstabTableItems(fstab)

  Creates a list of ui table items for nfs fstab entries.

- - (Object) initialize_nfs_routines(include_target)
- - (Object) IsMpInFstab(fstab, mpoint)

  Check if a mountpoint is in the fstab.

- - (Boolean) IsPortmapperInstalled(portmapper)

  Check whether pormap is installed, ask user to install it if it is missing.

- - (Object) SpecToServPath(spec)
- - (Object) StripExtraSlash(p)

  Strips a superfluous slash off the end of a pathname.

## Instance Method Details

### - (`Object`) CheckHostName(name)

Check for the validity of a hostname: nonempty, shorter than 50 chars, [-A-Za-z._]. If invalid, a message is displayed.

Parameters:

- name (`String`) —

  a hostname

Returns:

- whether valid

    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
    # File '../../src/include/nfs/routines.rb', line 85

    def CheckHostName(name)
      Builtins.y2milestone("CheckHostName: hostname=%1", name)

      if Ops.greater_than(Builtins.size(name), 0) &&
          Ops.less_than(Builtins.size(name), 50)
        return true if IP.Check4(name)
        return true if IP.Check6(IP.UndecorateIPv6(name))
        return true if Hostname.CheckDomain(name)
      end

      # error popup message

      Report.Error(
        Builtins.sformat(
          _(
            "The hostname entered is invalid. It must be\n" +
              "shorter than 50 characters and only use\n" +
              "valid IPv4, IPv6 or domain name.\n" +
              "Valid IPv4: %1\n" +
              "Valid IPv6: %2\n" +
              "Valid domain: %3"
          ),
          IP.Valid4,
          IP.Valid6,
          Hostname.ValidDomain
        )
      )

      false
    end

### - (`Object`) CheckPath(name)

Check for the validity of a path/mountpoint: nonempty, fewer than 70 chars, starts with a slash. If invalid, a message is displayed.

Parameters:

- name (`String`) —

  path

Returns:

- whether valid

    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    # File '../../src/include/nfs/routines.rb', line 145

    def CheckPath(name)
      if Ops.greater_than(Builtins.size(name), 0) &&
          Ops.less_than(Builtins.size(name), 70) &&
          Builtins.substring(name, 0, 1) == "/"
        return true
      end

      # error popup message (spaces are now allowed)
      Report.Error(
        Builtins.sformat(
          _(
            "The path entered is invalid.\n" +
              "It must be shorter than 70 characters\n" +
              "and it must begin with a slash (/)."
          )
        )
      )
      false
    end

### - (`Object`) FormatHostnameForFstab(hostname)

Formats hostname into form suitable for fstab. If given param is IPv6 then encloses it into square brackets.

    179
    180
    181
    182
    183
    184
    185
    186
    187
    188
    189
    # File '../../src/include/nfs/routines.rb', line 179

    def FormatHostnameForFstab(hostname)
      Builtins.y2milestone("FormatHostnameForFstab: hostname=%1", hostname)

      if IP.Check6(IP.UndecorateIPv6(hostname))
        return Builtins.sformat(
          Builtins.regexpmatch(hostname, "\\[.*\\]") ? "%1" : "[%1]",
          hostname
        )
      end
      hostname
    end

### - (`Object`) FstabTableItems(fstab)

Creates a list of ui table items for nfs fstab entries

Examples:

UI::ChangeWidget(`id(`fstable), `Items, FstabTableItems(nfs_entries));

Parameters:

- fstab (`Array<Hash>`) —

  list of nfs fstab entries

Returns:

- itemized table entries

    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    # File '../../src/include/nfs/routines.rb', line 63

    def FstabTableItems(fstab)
      fstab = deep_copy(fstab)
      count = 0
      Builtins.maplist(fstab) do |entry|
        sp = SpecToServPath(Ops.get_string(entry, "spec", ""))
        it = Item(
          Id(count),
          Ops.add(Ops.get_string(sp, 0, ""), " "),
          Ops.add(Ops.get_string(sp, 1, ""), " "),
          Ops.add(Ops.get_string(entry, "file", ""), " "),
          Ops.get_string(entry, "vfstype", " "),
          Ops.add(Ops.get_string(entry, "mntops", ""), " ")
        )
        count = Ops.add(count, 1)
        deep_copy(it)
      end
    end

### - (`Object`) initialize_nfs_routines(include_target)

    22
    23
    24
    25
    26
    27
    28
    29
    30
    # File '../../src/include/nfs/routines.rb', line 22

    def initialize_nfs_routines(include_target)
      textdomain "nfs"

      Yast.import "Package"
      Yast.import "Report"
      Yast.import "IP"
      Yast.import "Hostname"
      Yast.import "String"
    end

### - (`Object`) IsMpInFstab(fstab, mpoint)

Check if a mountpoint is in the fstab. If yes, display a message.

Parameters:

- fstab (`Array<Hash>`) —

  in .etc.fstab format (must contain the key “file”)

- mpoint (`String`) —

  mount point

Returns:

- is it there?

    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    # File '../../src/include/nfs/routines.rb', line 120

    def IsMpInFstab(fstab, mpoint)
      fstab = deep_copy(fstab)
      tmp = Builtins.filter(fstab) do |fse|
        Ops.get_string(fse, "file", "") == mpoint
      end

      if Builtins.size(tmp) == 0
        return false
      else
        # error popup message
        Report.Error(
          Builtins.sformat(
            _("fstab already contains an entry\nwith mount point '%1'."),
            mpoint
          )
        )
      end
      true
    end

### - (`Boolean`) IsPortmapperInstalled(portmapper)

Check whether pormap is installed, ask user to install it if it is missing

Returns:

- (`Boolean`) —

  true if portmap is installed

    193
    194
    195
    # File '../../src/include/nfs/routines.rb', line 193

    def IsPortmapperInstalled(portmapper)
      Package.Install(portmapper)
    end

### - (`Object`) SpecToServPath(spec)

Parameters:

- spec (`String`) —

  “server:/path/specification”

    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    # File '../../src/include/nfs/routines.rb', line 34

    def SpecToServPath(spec)
      # split using ":/" (because of IPv6)
      path_begin = Builtins.search(spec, ":/")
      serv = ""

      # no :/ inside => <server>: or [/]<path>
      if path_begin == nil
        if spec ==
            Ops.add(
              Builtins.filterchars(spec, Ops.add("-_.", String.CAlnum)),
              ":"
            )
          # matches [a-zA-Z0-1.-_] and ends with colon? => <server>:
          path_begin = Ops.subtract(Builtins.size(spec), 1)
        end
      end

      if path_begin != nil
        serv = Builtins.substring(spec, 0, path_begin)
        spec = Builtins.substring(spec, Ops.add(path_begin, 1))
      end
      term(:couple, serv, spec)
    end

### - (`Object`) StripExtraSlash(p)

Strips a superfluous slash off the end of a pathname.

Parameters:

- p (`String`) —

  pathname

Returns:

- stripped pathname

    169
    170
    171
    172
    173
    174
    175
    # File '../../src/include/nfs/routines.rb', line 169

    def StripExtraSlash(p)
      if Builtins.regexpmatch(p, "^.+/$")
        return Builtins.regexpsub(p, "^(.+)/$", "\\1")
      else
        return p
      end
    end