Class: VagrantPlugins::PersistentStorage::Config

Inherits:
Object
  • Object
show all
Defined in:
lib/vagrant-persistent-storage/config.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeConfig

Returns a new instance of Config.



36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/vagrant-persistent-storage/config.rb', line 36

def initialize
  @size = UNSET_VALUE
  @variant = UNSET_VALUE
  @create = true
  @mount = true
  @manage = true
  @format = true
  @use_lvm = true
  @enabled = UNSET_VALUE
  @partition = true
  @location = UNSET_VALUE
  @mountname = UNSET_VALUE
  @mountpoint = UNSET_VALUE
  @mountoptions = UNSET_VALUE
  @attachoptions = UNSET_VALUE
  @diskdevice = UNSET_VALUE
  @filesystem = UNSET_VALUE
  @volgroupname = UNSET_VALUE
  @drive_letter = UNSET_VALUE
  @part_type_code = UNSET_VALUE
  @logger = Log4r::Logger.new('vagrant::persistent_storage::config')
end

Instance Attribute Details

#attachoptionsObject

Returns the value of attribute attachoptions.



20
21
22
# File 'lib/vagrant-persistent-storage/config.rb', line 20

def attachoptions
  @attachoptions
end

#createObject Also known as: create?

Returns the value of attribute create.



10
11
12
# File 'lib/vagrant-persistent-storage/config.rb', line 10

def create
  @create
end

#diskdeviceObject

Returns the value of attribute diskdevice.



22
23
24
# File 'lib/vagrant-persistent-storage/config.rb', line 22

def diskdevice
  @diskdevice
end

#drive_letterObject

Returns the value of attribute drive_letter.



25
26
27
# File 'lib/vagrant-persistent-storage/config.rb', line 25

def drive_letter
  @drive_letter
end

#enabledObject Also known as: enabled?

Returns the value of attribute enabled.



14
15
16
# File 'lib/vagrant-persistent-storage/config.rb', line 14

def enabled
  @enabled
end

#filesystemObject

Returns the value of attribute filesystem.



23
24
25
# File 'lib/vagrant-persistent-storage/config.rb', line 23

def filesystem
  @filesystem
end

#formatObject Also known as: format?

Returns the value of attribute format.



13
14
15
# File 'lib/vagrant-persistent-storage/config.rb', line 13

def format
  @format
end

#locationObject

Returns the value of attribute location.



16
17
18
# File 'lib/vagrant-persistent-storage/config.rb', line 16

def location
  @location
end

#manageObject Also known as: manage?

Returns the value of attribute manage.



12
13
14
# File 'lib/vagrant-persistent-storage/config.rb', line 12

def manage
  @manage
end

#mountObject Also known as: mount?

Returns the value of attribute mount.



11
12
13
# File 'lib/vagrant-persistent-storage/config.rb', line 11

def mount
  @mount
end

#mountnameObject

Returns the value of attribute mountname.



17
18
19
# File 'lib/vagrant-persistent-storage/config.rb', line 17

def mountname
  @mountname
end

#mountoptionsObject

Returns the value of attribute mountoptions.



19
20
21
# File 'lib/vagrant-persistent-storage/config.rb', line 19

def mountoptions
  @mountoptions
end

#mountpointObject

Returns the value of attribute mountpoint.



18
19
20
# File 'lib/vagrant-persistent-storage/config.rb', line 18

def mountpoint
  @mountpoint
end

#part_type_codeObject

Returns the value of attribute part_type_code.



26
27
28
# File 'lib/vagrant-persistent-storage/config.rb', line 26

def part_type_code
  @part_type_code
end

#partitionObject Also known as: partition?

Returns the value of attribute partition.



21
22
23
# File 'lib/vagrant-persistent-storage/config.rb', line 21

def partition
  @partition
end

#sizeObject

Returns the value of attribute size.



8
9
10
# File 'lib/vagrant-persistent-storage/config.rb', line 8

def size
  @size
end

#use_lvmObject Also known as: use_lvm?

Returns the value of attribute use_lvm.



15
16
17
# File 'lib/vagrant-persistent-storage/config.rb', line 15

def use_lvm
  @use_lvm
end

#variantObject

Returns the value of attribute variant.



9
10
11
# File 'lib/vagrant-persistent-storage/config.rb', line 9

def variant
  @variant
end

#volgroupnameObject

Returns the value of attribute volgroupname.



24
25
26
# File 'lib/vagrant-persistent-storage/config.rb', line 24

def volgroupname
  @volgroupname
end

Instance Method Details

#finalize!Object



59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
# File 'lib/vagrant-persistent-storage/config.rb', line 59

def finalize!
  @size = 0 if @size == UNSET_VALUE
  @variant = "Standard" if @variant == UNSET_VALUE
  @create = true if @create == UNSET_VALUE
  @mount = true if @mount == UNSET_VALUE
  @manage = true if @manage == UNSET_VALUE
  @format = true if @format == UNSET_VALUE
  @use_lvm = true if @use_lvm == UNSET_VALUE
  @partition = true if @partition == UNSET_VALUE
  @enabled = false if @enabled == UNSET_VALUE
  @location = "" if @location == UNSET_VALUE
  @mountname = "" if @mountname == UNSET_VALUE
  @mountpoint = "" if @mountpoint == UNSET_VALUE
  @mountoptions = [] if @mountoptions == UNSET_VALUE
  @attachoptions = [] if @attachoptions == UNSET_VALUE
  @diskdevice = "" if @diskdevice == UNSET_VALUE
  @filesystem = "" if @filesystem == UNSET_VALUE
  @volgroupname = "" if @volgroupname == UNSET_VALUE
  @drive_letter = 0 if @drive_letter == UNSET_VALUE
  @part_type_code = "8e" if @part_type_code == UNSET_VALUE
end

#validate(machine) ⇒ Object



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
164
165
166
167
168
169
170
171
172
173
174
175
176
177
# File 'lib/vagrant-persistent-storage/config.rb', line 81

def validate(machine)
  errors = _detected_errors

  @enabled = false if @enabled == UNSET_VALUE

  errors << validate_bool('persistent_storage.create', @create)
  errors << validate_bool('persistent_storage.mount', @mount)
  errors << validate_bool('persistent_storage.manage', @manage)
  errors << validate_bool('persistent_storage.format', @format)
  errors << validate_bool('persistent_storage.use_lvm', @use_lvm)
  errors << validate_bool('persistent_storage.enabled', @enabled)
  errors << validate_bool('persistent_storage.partition', @partition)
  errors.compact!

  if !machine.config.persistent_storage.size.kind_of?(Integer)
    errors << I18n.t('vagrant_persistent_storage.config.not_a_number', {
      :config_key => 'persistent_storage.size',
      :is_class   => size.class.to_s,
    })
  end
  if !machine.config.persistent_storage.location.kind_of?(String)
    errors << I18n.t('vagrant_persistent_storage.config.not_a_string', {
      :config_key => 'persistent_storage.location',
      :is_class   => location.class.to_s,
    })
  end
  if !machine.config.persistent_storage.mountname.kind_of?(String)
    errors << I18n.t('vagrant_persistent_storage.config.not_a_string', {
      :config_key => 'persistent_storage.mountname',
      :is_class   => mountname.class.to_s,
    })
  end
  if !machine.config.persistent_storage.mountpoint.kind_of?(String)
    errors << I18n.t('vagrant_persistent_storage.config.not_a_string', {
      :config_key => 'persistent_storage.mountpoint',
      :is_class   => mountpoint.class.to_s,
    })
  end
  if !machine.config.persistent_storage.diskdevice.kind_of?(String)
    errors << I18n.t('vagrant_persistent_storage.config.not_a_string', {
      :config_key => 'persistent_storage.diskdevice',
      :is_class   => diskdevice.class.to_s,
    })
  end
  if !machine.config.persistent_storage.filesystem.kind_of?(String)
    errors << I18n.t('vagrant_persistent_storage.config.not_a_string', {
      :config_key => 'persistent_storage.filesystem',
      :is_class   => filesystem.class.to_s,
    })
  end
  if !machine.config.persistent_storage.part_type_code.kind_of?(String)
     errors << I18n.t('vagrant_persistent_storage.config.not_a_string', {
       :config_key => 'persistent_storage.part_type_code',
       :is_class   => part_type_code.class.to_s,
     })
  end
  if !machine.config.persistent_storage.volgroupname.kind_of?(String)
    errors << I18n.t('vagrant_persistent_storage.config.not_a_string', {
      :config_key => 'persistent_storage.volgroupname',
      :is_class   => volgroupname.class.to_s,
    })
  end
  if !machine.config.persistent_storage.variant.kind_of?(String)
    errors << I18n.t('vagrant_persistent_storage.config.not_a_string', {
      :config_key => 'persistent_storage.variant',
      :is_class   => variant.class.to_s,
    })
 end

  mount_point_path = Pathname.new("#{machine.config.persistent_storage.location}")
  if ! (mount_point_path.absolute? || mount_point_path.relative?)
    errors << I18n.t('vagrant_persistent_storage.config.not_a_path', {
      :config_key => 'persistent_storage.location',
      :is_path   => location.class.to_s,
    })
  end

  if ! Pathname.new(machine.config.persistent_storage.location).absolute?
    # Non-absolute paths are relative to machine's root directory (where
    # Vagrantfile is placed). Paths under HOME, e.g., ~/disk.vdi), are
    # expanded as expected.
    new_location = File.expand_path(machine.config.persistent_storage.location, machine.env.root_path)
    @logger.info "Found non-absolute location #{machine.config.persistent_storage.location}. Using location #{new_location} instead."
    machine.config.persistent_storage.location = new_location
  end

  machine.ui.info "Using #{machine.config.persistent_storage.location} for persistent storage."

  if ! File.exist?@location.to_s and ! @create == "true"
    errors << I18n.t('vagrant_persistent_storage.config.no_create_and_missing', {
      :config_key => 'persistent_storage.create',
      :is_path   => location.class.to_s,
    })
  end

  { 'Persistent Storage configuration' => errors }
end