Module: Yast::PartitioningEpNfsInclude

Defined in:
../../src/include/partitioning/ep-nfs.rb

Instance Method Summary (collapse)

Instance Method Details

- (Object) CreateNfsMainPanel(user_data)



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
# File '../../src/include/partitioning/ep-nfs.rb', line 40

def CreateNfsMainPanel(user_data)
  user_data = deep_copy(user_data)
  nfs_list = []
  _Predicate = lambda do |disk, partition|
    disk = deep_copy(disk)
    partition = deep_copy(partition)
    StorageFields.PredicateDiskType(disk, partition, [:CT_NFS])
  end

  _CreateContent = lambda do
    pkg_installed = false
    #fallback dialog content
    fallback_content = VBox(
      Left(
        Label(
          _(
            "NFS configuration is not available. Check yast2-nfs-client package installation."
          )
        )
      ),
      VStretch(),
      HStretch()
    )

    #Check if we have y2-nfs-client installed
    if !Stage.initial
      pkgs = ["yast2-nfs-client"]
      PackageCallbacks.RegisterEmptyProgressCallbacks
      pkg_installed = PackageSystem.CheckAndInstallPackages(pkgs)
      PackageCallbacks.RestorePreviousProgressCallbacks
    else
      filename = "nfs-client4part"
      pkg_installed = WFM.ClientExists(filename)
    end

    if pkg_installed
      content = Convert.to_term(
        WFM.CallFunction("nfs-client4part", ["CreateUI"])
      )
      if content != nil
        return deep_copy(content)
      else
        Builtins.y2error(
          "Failed to retrieve dialog content from yast2-nfs-client"
        )
      end
    end

    #Obviously something went wrong - reset the help text and put a fallback content in
    Wizard.SetHelpText(" ")
    deep_copy(fallback_content)
  end

  _Initialize = lambda do
    @target_map = Storage.GetTargetMap

    #No NFS shares so far, set empty 'partitions' list
    if !Builtins.haskey(@target_map, "/dev/nfs")
      Ops.set(
        @target_map,
        "/dev/nfs",
        { "type" => :CT_NFS, "partitions" => [] }
      )
    end
    nfs_list = Ops.get_list(@target_map, ["/dev/nfs", "partitions"], [])

    Builtins.y2milestone("Found NFS shares: %1", nfs_list)

    if !Stage.initial && !@already_initialized
      Builtins.y2milestone("Reading NFS settings")
      WFM.CallFunction("nfs-client4part", ["Read"])
      @already_initialized = true
    end

    nil
  end



  UI.ReplaceWidget(
    :tree_panel,
    Greasemonkey.Transform(
      VBox(
        HStretch(),
        # heading
        term(
          :IconAndHeading,
          _("Network File System (NFS)"),
          StorageIcons.nfs_icon
        ),
        _CreateContent.call
      )
    )
  )

  _Initialize.call

  WFM.CallFunction(
    "nfs-client4part",
    ["FromStorage", { "shares" => nfs_list }]
  )

  nil
end

- (Object) CreateNfsPanel(user_data)



278
279
280
281
282
283
284
285
# File '../../src/include/partitioning/ep-nfs.rb', line 278

def CreateNfsPanel(user_data)
  user_data = deep_copy(user_data)
  #a hack - we don't have overviews for nfs dirs, so let's switch to the main panel ...
  CreateNfsMainPanel(user_data)
  UI.ChangeWidget(:tree, :CurrentItem, :nfs)

  nil
end

- (Object) HandleNfsMainPanel(user_data, event)



146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
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
265
266
267
268
269
270
271
272
273
274
275
276
# File '../../src/include/partitioning/ep-nfs.rb', line 146

def HandleNfsMainPanel(user_data, event)
  user_data = deep_copy(user_data)
  event = deep_copy(event)
  _AddShare = lambda do |entry|
    entry = deep_copy(entry)
    Builtins.y2milestone(
      "Adding NFS share: %1 mountpoint: %2 options: %3",
      Ops.get_string(entry, "device", ""),
      Ops.get_string(entry, "mount", ""),
      Ops.get_string(entry, "fstopt", "")
    )
    @target_map = Storage.GetTargetMap
    nfs_list = Ops.get_list(@target_map, ["/dev/nfs", "partitions"], [])

    device = Ops.get_string(entry, "device", "")
    mount = Ops.get_string(entry, "mount", "")
    opts = Ops.get_string(entry, "fstopt", "")
    nfs4 = Ops.get_string(entry, "vfstype", "nfs") == "nfs4"

    sizeK = Storage.CheckNfsVolume(device, opts, nfs4)
    if Ops.less_or_equal(sizeK, 0)
      #rollback only if user does not want to save (#450060)
      #the mount might fail later if the errors are not corrected, but the user has been warned
      if !Popup.YesNo(
          Builtins.sformat(
            _("Test mount of NFS share '%1' failed.\nSave it anyway?"),
            Ops.get_string(entry, "device", "")
          )
        )
        WFM.CallFunction(
          "nfs-client4part",
          ["FromStorage", { "shares" => nfs_list }]
        )
        return
      end
      Builtins.y2warning(
        "Test mount of NFS share %1 failed, but user decided to save it anyway - this might not work.",
        Ops.get_string(entry, "device", "")
      )

      #this really sucks - but libstorage returns negative integers (error code) instead of
      #real size - Perl then wants to die in addNfsVolume call
      sizeK = 0
    end
    Storage.AddNfsVolume(device, opts, sizeK, mount, nfs4)

    nil
  end

  _EditShare = lambda do |entry|
    entry = deep_copy(entry)
    Builtins.y2milestone(
      "Changing NFS share: %1 mountpoint: %2 options: %3",
      Ops.get_string(entry, "device", ""),
      Ops.get_string(entry, "mount", ""),
      Ops.get_string(entry, "fstopt", "")
    )

    #device got renamed -
    #delete the one with old name and create new
    if Builtins.haskey(entry, "old_device")
      Storage.DeleteDevice(Ops.get_string(entry, "old_device", ""))
      _AddShare.call(entry)
    else
      dev = Ops.get_string(entry, "device", "")
      @target_map = Storage.GetTargetMap
      nfs_list = Ops.get_list(@target_map, ["/dev/nfs", "partitions"], [])

      nfs_list = Builtins.maplist(nfs_list) do |m|
        if Ops.get_string(m, "device", "") == dev
          Ops.set(m, "fstopt", Ops.get_string(entry, "fstopt", ""))
          Ops.set(m, "mount", Ops.get_string(entry, "mount", ""))
          Ops.set(
            m,
            "vfstype",
            Ops.get_symbol(entry, "used_fs", :nfs) == :nfs ? "nfs" : "nfs4"
          )
        end
        deep_copy(m)
      end
      Ops.set(@target_map, ["/dev/nfs", "partitions"], nfs_list)
      Storage.SetTargetMap(@target_map)
    end

    nil
  end

  _DeleteShare = lambda do |entry|
    entry = deep_copy(entry)
    Builtins.y2milestone(
      "Deleting NFS share: %1 mountpoint: %2 options: %3",
      Ops.get_string(entry, "device", ""),
      Ops.get_string(entry, "mount", ""),
      Ops.get_string(entry, "fstopt", "")
    )
    dev = Ops.get_string(entry, "device", "")

    Storage.DeleteDevice(dev)

    nil
  end

  line = Convert.convert(
    WFM.CallFunction(
      "nfs-client4part",
      ["HandleEvent", { "widget_id" => Event.IsWidgetActivated(event) }]
    ),
    :from => "any",
    :to   => "map <string, any>"
  )

  #do something only if y2-nfs-client returns some reasonable data
  if line != {} && line != nil
    case Event.IsWidgetActivated(event)
      when :newbut
        _AddShare.call(line)
      when :editbut
        _EditShare.call(line)
      when :delbut
        _DeleteShare.call(line)
      else

    end
    UI.SetFocus(Id(:fstable))
    UpdateMainStatus()
  end 
  #FIXME: Take care that non-fstab settings of nfs-client
  #(firewall, sysconfig, idmapd) get written on closing partitioner

  nil
end

- (Object) initialize_partitioning_ep_nfs(include_target)



28
29
30
31
32
33
34
35
36
37
38
# File '../../src/include/partitioning/ep-nfs.rb', line 28

def initialize_partitioning_ep_nfs(include_target)
  textdomain "storage"

  Yast.import "PackageCallbacks"
  Yast.import "PackageSystem"


  #boolean initialized = false;
  @target_map = {}
  @already_initialized = false
end