Add initial disk management config class

This commit is contained in:
Brian Cain 2019-10-17 15:24:27 -07:00
parent 1d9533113c
commit aa5a3ef7f7
No known key found for this signature in database
GPG Key ID: 9FC4639B2E4510A0
2 changed files with 103 additions and 0 deletions

View File

@ -0,0 +1,79 @@
require "log4r"
require "securerandom"
module VagrantPlugins
module Kernel_V2
class VagrantConfigDisk < Vagrant.plugin("2", :config)
#-------------------------------------------------------------------
# Config class for a given Disk
#-------------------------------------------------------------------
# Note: This value is for internal use only
#
# @return [String]
attr_reader :id
# Name for the given Disk. Defaults to nil.
#
# TODO: Should probably default to a string+short integer id
#
# @return [String]
attr_accessor :name
# Type of disk to create
#
# @return [Symbol]
attr_accessor :type
# Size of disk to create
#
# @return [Integer]
attr_accessor :size
# Provider specific options
#
# TODO: INTERNAL??
#
# @return [Hash]
attr_accessor :options
def initialize(type)
@logger = Log4r::Logger.new("vagrant::config::vm::trigger::config")
@name = UNSET_VALUE
@type = UNSET_VALUE
@size = UNSET_VALUE
@options = UNSET_VALUE
# Internal options
@id = SecureRandom.uuid
end
def finalize!
# Ensure all config options are set to nil or default value if untouched
# by user
@name = nil if @name == UNSET_VALUE
@type = nil if @type == UNSET_VALUE
@size = nil if @size == UNSET_VALUE
@options = nil if @options == UNSET_VALUE
end
# @return [Array] array of strings of error messages from config option validation
def validate(machine)
errors = _detected_errors
# validate type with list of known disk types
errors
end
# The String representation of this Disk.
#
# @return [String]
def to_s
"disk config"
end
end
end
end

View File

@ -11,6 +11,7 @@ require "vagrant/util/experimental"
require File.expand_path("../vm_provisioner", __FILE__)
require File.expand_path("../vm_subvm", __FILE__)
require File.expand_path("../disk", __FILE__)
module VagrantPlugins
module Kernel_V2
@ -79,6 +80,7 @@ module VagrantPlugins
@__compiled_provider_configs = {}
@__defined_vm_keys = []
@__defined_vms = {}
@__drives = {}
@__finalized = false
@__networks = {}
@__providers = {}
@ -123,6 +125,11 @@ module VagrantPlugins
end
end
# Merge defined drives
# TODO: Actually write this
other_drives = other.instance_variable_get(:@__drives)
new_drives = @__drives.dup
# Merge the providers by prepending any configuration blocks we
# have for providers onto the new configuration.
other_providers = other.instance_variable_get(:@__providers)
@ -185,6 +192,7 @@ module VagrantPlugins
result.instance_variable_set(:@__defined_vm_keys, new_defined_vm_keys)
result.instance_variable_set(:@__defined_vms, new_defined_vms)
result.instance_variable_set(:@__drives, new_drives)
result.instance_variable_set(:@__providers, new_providers)
result.instance_variable_set(:@__provider_order, new_order)
result.instance_variable_set(:@__provider_overrides, new_overrides)
@ -384,6 +392,17 @@ module VagrantPlugins
@__defined_vms[name].config_procs << [options[:config_version], block] if block
end
def disk(type, &block)
disk = VagrantConfigDisk.new(type)
if block.is_a?(Hash)
disk.set_options(block)
else
block.call(disk, VagrantConfigDisk)
end
@__drives[disk[:id]] = disk
end
#-------------------------------------------------------------------
# Internal methods, don't call these.
#-------------------------------------------------------------------
@ -547,6 +566,11 @@ module VagrantPlugins
end
end
# TODO: This might need to be more complicated
@__drives.each do |d|
d.finalize!
end
if !current_dir_shared && !@__synced_folders["/vagrant"]
synced_folder(".", "/vagrant")
end