Class: AWS::EC2::DHCPOptions

Inherits:
Resource show all
Includes:
TaggedItem
Defined in:
lib/aws/ec2/dhcp_options.rb

Instance Attribute Summary collapse

Attributes included from Core::Model

#config

Instance Method Summary collapse

Methods included from TaggedItem

#add_tag, #cached_tags, #clear_tags, #tagging_resource_type, #tags

Methods inherited from Core::Resource

attribute_providers, attribute_providers_for, attributes, #attributes_from_response, define_attribute_type, #eql?, #inspect, new_from

Methods included from Core::Cacheable

included, #retrieve_attribute

Methods included from Core::Model

#client, #config_prefix, #inspect

Constructor Details

#initialize(dhcp_options_id, options = {}) ⇒ DHCPOptions

Returns a new instance of DHCPOptions.



22
23
24
25
# File 'lib/aws/ec2/dhcp_options.rb', line 22

def initialize dhcp_options_id, options = {}
  @dhcp_options_id = dhcp_options_id
  super
end

Instance Attribute Details

#dhcp_options_idString (readonly) Also known as: id

Returns:

  • (String)


28
29
30
# File 'lib/aws/ec2/dhcp_options.rb', line 28

def dhcp_options_id
  @dhcp_options_id
end

Instance Method Details

#associate(vpc) ⇒ nil

Associates this set of options to the given VPC.

Parameters:

  • vpc (VPC, String)

    A VPC object or a vpc id string.

Returns:

  • (nil)


60
61
62
63
64
65
66
# File 'lib/aws/ec2/dhcp_options.rb', line 60

def associate vpc
  client_opts = {}
  client_opts[:dhcp_options_id] = dhcp_options_id
  client_opts[:vpc_id] = vpc_id_option(vpc)
  client.associate_dhcp_options(client_opts)
  nil
end

#configurationHash

Returns:

  • (Hash)


47
48
49
50
51
52
53
54
55
# File 'lib/aws/ec2/dhcp_options.rb', line 47

def configuration
  dhcp_configuration_set.to_a.inject({}) do |config,opt|
    key = opt[:key].gsub(/-/, '_').to_sym
    values = opt[:value_set].map{|v| v[:value] }
    values = values.first if key == :domain_name
    values = values.first.to_i if key == :netbios_node_type
    config.merge(key => values)
  end
end

#deletenil

Deletes these DHCP options. An error will be raised if these options are currently associated to a VPC. To disassociate this set of options from a VPC, associate a different set of options with the VPC.

Returns:

  • (nil)


75
76
77
78
79
80
# File 'lib/aws/ec2/dhcp_options.rb', line 75

def delete
  client_opts = {}
  client_opts[:dhcp_options_id] = dhcp_options_id
  client.delete_dhcp_options(client_opts)
  nil
end

#exists?Boolean

Returns true if the dhcp options exists.

Returns:

  • (Boolean)

    Returns true if the dhcp options exists.



90
91
92
93
94
95
96
97
# File 'lib/aws/ec2/dhcp_options.rb', line 90

def exists?
  begin
    get_resource
    true
  rescue Errors::InvalidDhcpOptionID::NotFound
    false
  end
end

#vpcsVPCCollection

Returns a collection that represents all VPCs currently using this dhcp options.

Returns:

  • (VPCCollection)

    Returns a collection that represents all VPCs currently using this dhcp options.



84
85
86
87
# File 'lib/aws/ec2/dhcp_options.rb', line 84

def vpcs
  vpcs = VPCCollection.new(:config => config)
  vpcs.filter('dhcp-options-id', dhcp_options_id)
end