Class: Cumulus::VPC::DhcpConfig

Inherits:
Object
  • Object
show all
Defined in:
lib/vpc/models/DhcpConfig.rb

Overview

Public: An object representing configuration for a VPC’s dhcp options

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(json = nil) ⇒ DhcpConfig

Public: Constructor

json - a hash containing the JSON configuration for the dhcp options



24
25
26
27
28
29
30
31
32
# File 'lib/vpc/models/DhcpConfig.rb', line 24

def initialize(json = nil)
  if !json.nil?
    @domain_name_servers = json["domain-name-servers"] || []
    @domain_name = json["domain-name"]
    @ntp_servers = json["ntp-servers"] || []
    @netbios_name_servers = json["netbios-name-servers"] || []
    @netbios_node_type = json["netbios-node-type"]
  end
end

Instance Attribute Details

#domain_nameObject (readonly)

Returns the value of attribute domain_name.



13
14
15
# File 'lib/vpc/models/DhcpConfig.rb', line 13

def domain_name
  @domain_name
end

#domain_name_serversObject (readonly)

Returns the value of attribute domain_name_servers.



12
13
14
# File 'lib/vpc/models/DhcpConfig.rb', line 12

def domain_name_servers
  @domain_name_servers
end

#netbios_name_serversObject (readonly)

Returns the value of attribute netbios_name_servers.



15
16
17
# File 'lib/vpc/models/DhcpConfig.rb', line 15

def netbios_name_servers
  @netbios_name_servers
end

#netbios_node_typeObject (readonly)

Returns the value of attribute netbios_node_type.



16
17
18
# File 'lib/vpc/models/DhcpConfig.rb', line 16

def netbios_node_type
  @netbios_node_type
end

#ntp_serversObject (readonly)

Returns the value of attribute ntp_servers.



14
15
16
# File 'lib/vpc/models/DhcpConfig.rb', line 14

def ntp_servers
  @ntp_servers
end

Instance Method Details

#diff(aws) ⇒ Object

Public: Produce an array of differences between this local configuration and the configuration in AWS

aws - the AWS resource

Returns an array of the DhcpDiffs that were found



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
# File 'lib/vpc/models/DhcpConfig.rb', line 69

def diff(aws)
  diffs = []

  aws_domain_name_servers = (aws.domain_name_servers || []).sort
  if @domain_name_servers.sort != aws_domain_name_servers
    domain_servers_diff = DhcpDiff.domain_servers(aws_domain_name_servers, @domain_name_servers)
    diffs << domain_servers_diff if domain_servers_diff
  end

  if @domain_name != aws.domain_name
    diffs << DhcpDiff.new(DhcpChange::DOMAIN_NAME, aws.domain_name, @domain_name)
  end

  if @ntp_servers.sort != aws.ntp_servers.sort
    ntp_diff = DhcpDiff.ntp_servers(aws.ntp_servers, @ntp_servers)
    diffs << ntp_diff if ntp_diff
  end

  if @netbios_name_servers.sort != aws.netbios_name_servers.sort
    netbios_diff = DhcpDiff.netbios_servers(aws.netbios_name_servers, @netbios_name_servers)
    diffs << netbios_diff if netbios_diff
  end

  if @netbios_node_type != aws.netbios_node_type
    diffs << DhcpDiff.new(DhcpChange::NETBIOS_NODE, aws.netbios_node_type, @netbios_node_type)
  end

  diffs
end

#populate!(aws) ⇒ Object



53
54
55
56
57
58
59
60
61
# File 'lib/vpc/models/DhcpConfig.rb', line 53

def populate!(aws)
  @domain_name_servers = aws.domain_name_servers
  @domain_name = aws.domain_name
  @ntp_servers = aws.ntp_servers
  @netbios_name_servers = aws.netbios_name_servers
  @netbios_node_type = aws.netbios_node_type

  self
end

#to_awsObject



44
45
46
47
48
49
50
51
# File 'lib/vpc/models/DhcpConfig.rb', line 44

def to_aws
  to_hash.map do |key, value|
    {
      key: key,
      values: [value].flatten
    }
  end
end

#to_hashObject



34
35
36
37
38
39
40
41
42
# File 'lib/vpc/models/DhcpConfig.rb', line 34

def to_hash
  {
    "domain-name-servers" => @domain_name_servers.sort,
    "domain-name" => @domain_name,
    "ntp-servers" => @ntp_servers.sort,
    "netbios-name-servers" => @netbios_name_servers.sort,
    "netbios-node-type" => @netbios_node_type,
  }.reject { |k, v| v.nil? or v.empty? }
end