class Cumulus::VPC::DhcpConfig

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

Attributes

domain_name[R]
domain_name_servers[R]
netbios_name_servers[R]
netbios_node_type[R]
ntp_servers[R]

Public Class Methods

new(json = nil) click to toggle source

Public: Constructor

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

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

Public Instance Methods

diff(aws) click to toggle source

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

# File lib/vpc/models/DhcpConfig.rb, line 68
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) click to toggle source
# File lib/vpc/models/DhcpConfig.rb, line 52
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_aws() click to toggle source
# File lib/vpc/models/DhcpConfig.rb, line 43
def to_aws
  to_hash.map do |key, value|
    {
      key: key,
      values: [value].flatten
    }
  end
end
to_hash() click to toggle source
# File lib/vpc/models/DhcpConfig.rb, line 33
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