Class: OsCtld::Mount::Entry

Inherits:
Object
  • Object
show all
Defined in:
lib/osctld/mount/entry.rb

Constant Summary collapse

PARAMS =
%i[fs mountpoint type opts automount dataset temp].freeze

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(fs, mountpoint, type, opts, automount, dataset: nil, map_ids: false, temp: false, in_config: false) ⇒ Entry

Returns a new instance of Entry.



25
26
27
28
29
30
31
32
33
34
35
# File 'lib/osctld/mount/entry.rb', line 25

def initialize(fs, mountpoint, type, opts, automount, dataset: nil, map_ids: false, temp: false, in_config: false)
  @fs = fs
  @mountpoint = mountpoint
  @type = type
  @opts = opts
  @automount = automount
  @dataset = dataset
  @map_ids = map_ids
  @temp = temp
  @in_config = in_config
end

Instance Attribute Details

#automountObject (readonly) Also known as: automount?

Returns the value of attribute automount.



4
5
6
# File 'lib/osctld/mount/entry.rb', line 4

def automount
  @automount
end

#datasetObject (readonly)

Returns the value of attribute dataset.



4
5
6
# File 'lib/osctld/mount/entry.rb', line 4

def dataset
  @dataset
end

#in_configObject (readonly) Also known as: in_config?

Returns the value of attribute in_config.



4
5
6
# File 'lib/osctld/mount/entry.rb', line 4

def in_config
  @in_config
end

#map_idsObject (readonly)

Returns the value of attribute map_ids.



4
5
6
# File 'lib/osctld/mount/entry.rb', line 4

def map_ids
  @map_ids
end

#mountpointObject (readonly)

Returns the value of attribute mountpoint.



4
5
6
# File 'lib/osctld/mount/entry.rb', line 4

def mountpoint
  @mountpoint
end

#optsObject (readonly)

Returns the value of attribute opts.



4
5
6
# File 'lib/osctld/mount/entry.rb', line 4

def opts
  @opts
end

#tempObject (readonly) Also known as: temp?

Returns the value of attribute temp.



4
5
6
# File 'lib/osctld/mount/entry.rb', line 4

def temp
  @temp
end

#typeObject (readonly)

Returns the value of attribute type.



4
5
6
# File 'lib/osctld/mount/entry.rb', line 4

def type
  @type
end

Class Method Details

.load(ct, cfg) ⇒ Object

Load from config



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/osctld/mount/entry.rb', line 7

def self.load(ct, cfg)
  dataset = cfg['dataset'] && OsCtl::Lib::Zfs::Dataset.new(
    cfg['dataset'] == '/' ? ct.dataset.name : File.join(ct.dataset.name, cfg['dataset']),
    base: ct.dataset.name
  )

  new(
    cfg['fs'],
    cfg['mountpoint'],
    cfg['type'],
    cfg['opts'],
    cfg['automount'],
    dataset:,
    map_ids: cfg.fetch('map_ids', !dataset.nil?),
    temp: cfg['temporary']
  )
end

Instance Method Details

#dumpObject

Dump to config



62
63
64
65
66
67
68
69
70
71
72
73
# File 'lib/osctld/mount/entry.rb', line 62

def dump
  {
    'fs' => dataset ? nil : fs,
    'mountpoint' => mountpoint,
    'type' => type,
    'opts' => opts,
    'automount' => automount,
    'dataset' => dataset && dataset.relative_name,
    'map_ids' => map_ids,
    'temporary' => temp
  }
end

#dup(new_ct) ⇒ Object



75
76
77
78
79
80
81
82
83
84
85
86
# File 'lib/osctld/mount/entry.rb', line 75

def dup(new_ct)
  ret = super()

  if dataset
    ret.instance_variable_set('@dataset', OsCtl::Lib::Zfs::Dataset.new(
                                            File.join(new_ct.dataset.name, dataset.relative_name).chomp('/'),
                                            base: new_ct.dataset.name
                                          ))
  end

  ret
end

#exportObject

Export to client



48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/osctld/mount/entry.rb', line 48

def export
  {
    fs:,
    mountpoint:,
    type:,
    opts:,
    automount:,
    dataset: dataset && dataset.relative_name,
    map_ids: map_ids,
    temporary: temp
  }
end

#fsObject



37
38
39
# File 'lib/osctld/mount/entry.rb', line 37

def fs
  dataset ? dataset.private_path : @fs
end

#lxc_mountpointObject



41
42
43
44
45
# File 'lib/osctld/mount/entry.rb', line 41

def lxc_mountpoint
  ret = String.new(mountpoint)
  ret.slice!(0) while ret.start_with?('/')
  ret
end