Class: VagrantDockerNetworksManager::Config

Inherits:
Object
  • Object
show all
Defined in:
lib/vagrant-docker-networks-manager/config.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeConfig

Returns a new instance of Config.



12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/vagrant-docker-networks-manager/config.rb', line 12

def initialize
  @network_name       = UNSET_VALUE
  @network_subnet     = UNSET_VALUE
  @network_type       = UNSET_VALUE
  @network_gateway    = UNSET_VALUE
  @network_parent     = UNSET_VALUE
  @network_attachable = UNSET_VALUE
  @enable_ipv6        = UNSET_VALUE
  @ip_range           = UNSET_VALUE
  @cleanup_on_destroy = UNSET_VALUE
  @locale             = UNSET_VALUE
end

Instance Attribute Details

#cleanup_on_destroyObject

Returns the value of attribute cleanup_on_destroy.



8
9
10
# File 'lib/vagrant-docker-networks-manager/config.rb', line 8

def cleanup_on_destroy
  @cleanup_on_destroy
end

#enable_ipv6Object

Returns the value of attribute enable_ipv6.



8
9
10
# File 'lib/vagrant-docker-networks-manager/config.rb', line 8

def enable_ipv6
  @enable_ipv6
end

#ip_rangeObject

Returns the value of attribute ip_range.



8
9
10
# File 'lib/vagrant-docker-networks-manager/config.rb', line 8

def ip_range
  @ip_range
end

#localeObject

Returns the value of attribute locale.



8
9
10
# File 'lib/vagrant-docker-networks-manager/config.rb', line 8

def locale
  @locale
end

#network_attachableObject

Returns the value of attribute network_attachable.



8
9
10
# File 'lib/vagrant-docker-networks-manager/config.rb', line 8

def network_attachable
  @network_attachable
end

#network_gatewayObject

Returns the value of attribute network_gateway.



8
9
10
# File 'lib/vagrant-docker-networks-manager/config.rb', line 8

def network_gateway
  @network_gateway
end

#network_nameObject

Returns the value of attribute network_name.



8
9
10
# File 'lib/vagrant-docker-networks-manager/config.rb', line 8

def network_name
  @network_name
end

#network_parentObject

Returns the value of attribute network_parent.



8
9
10
# File 'lib/vagrant-docker-networks-manager/config.rb', line 8

def network_parent
  @network_parent
end

#network_subnetObject

Returns the value of attribute network_subnet.



8
9
10
# File 'lib/vagrant-docker-networks-manager/config.rb', line 8

def network_subnet
  @network_subnet
end

#network_typeObject

Returns the value of attribute network_type.



8
9
10
# File 'lib/vagrant-docker-networks-manager/config.rb', line 8

def network_type
  @network_type
end

Instance Method Details

#finalize!Object



25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/vagrant-docker-networks-manager/config.rb', line 25

def finalize!
  @network_name       = "network_lo1"       if @network_name       == UNSET_VALUE
  @network_subnet     = "172.28.100.0/26"   if @network_subnet     == UNSET_VALUE
  @network_type       = "bridge"            if @network_type       == UNSET_VALUE
  @network_gateway    = "172.28.100.1"      if @network_gateway    == UNSET_VALUE
  @network_parent     = nil                 if @network_parent     == UNSET_VALUE
  @network_attachable = false               if @network_attachable == UNSET_VALUE
  @enable_ipv6        = false               if @enable_ipv6        == UNSET_VALUE
  @ip_range           = nil                 if @ip_range           == UNSET_VALUE
  @cleanup_on_destroy = true                if @cleanup_on_destroy == UNSET_VALUE
  @locale             = "en"                if @locale             == UNSET_VALUE
end

#validate(_machine) ⇒ Object



38
39
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
# File 'lib/vagrant-docker-networks-manager/config.rb', line 38

def validate(_machine)
  VagrantDockerNetworksManager::UiHelpers.setup_i18n! rescue nil
  errors = []

  unless @network_name.is_a?(String) && !@network_name.strip.empty? && docker_name?(@network_name)
    errors << ::I18n.t("errors.invalid_name")
  end

  unless ipv4_cidr_aligned?(@network_subnet)
    errors << ::I18n.t("errors.invalid_subnet")
  end

  unless @network_type.is_a?(String) && %w[bridge macvlan].include?(@network_type)
    errors << ::I18n.t("errors.invalid_type")
  end

  if present?(@network_gateway)
    if !ipv4?(@network_gateway)
      errors << ::I18n.t("errors.invalid_gateway")
    elsif ipv4_cidr_aligned?(@network_subnet) && !gateway_host_addr?(@network_subnet, @network_gateway)
      errors << ::I18n.t("errors.invalid_gateway")
    end
  end

  if present?(@network_parent) && !@network_parent.is_a?(String)
    errors << ::I18n.t("errors.invalid_parent")
  end

  if @network_type.to_s == "macvlan" && !present?(@network_parent)
    errors << ::I18n.t("errors.invalid_parent")
  end

  unless [true, false].include?(@network_attachable)
    errors << ::I18n.t("errors.invalid_attachable")
  end

  unless [true, false].include?(@enable_ipv6)
    errors << ::I18n.t("errors.invalid_ipv6")
  end

  if present?(@ip_range)
    if !ipv4_cidr?(@ip_range)
      errors << ::I18n.t("errors.invalid_ip_range")
    elsif ipv4_cidr_aligned?(@network_subnet) && !cidr_within_cidr?(@network_subnet, @ip_range)
      errors << ::I18n.t("errors.invalid_ip_range")
    end
  end

  unless [true, false].include?(@cleanup_on_destroy)
    errors << ::I18n.t("errors.invalid_cleanup")
  end

  unless @locale.is_a?(String) && %w[fr en].include?(@locale.to_s[0,2].downcase)
    errors << ::I18n.t("errors.invalid_locale")
  end

  { "vagrant-docker-networks-manager" => errors }
end