Module: Yast::NfsRoutinesInclude

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

Overview

Miscellaneous

Instance Method Summary (collapse)

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



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

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



129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
# File '../../src/include/nfs/routines.rb', line 129

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.



162
163
164
165
166
167
168
169
170
171
172
# File '../../src/include/nfs/routines.rb', line 162

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



47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# File '../../src/include/nfs/routines.rb', line 47

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)



7
8
9
10
11
12
13
14
15
# File '../../src/include/nfs/routines.rb', line 7

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?



104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
# File '../../src/include/nfs/routines.rb', line 104

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



176
177
178
# File '../../src/include/nfs/routines.rb', line 176

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

- (Object) SpecToServPath(spec)

Parameters:

  • spec (String)

    “server:/path/specification”



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File '../../src/include/nfs/routines.rb', line 19

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
    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



152
153
154
155
156
157
158
# File '../../src/include/nfs/routines.rb', line 152

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