Class: BuildCloud::DHCPOptionsSet

Inherits:
Object
  • Object
show all
Includes:
Component
Defined in:
lib/build-cloud/dhcpoptionsset.rb

Constant Summary collapse

@@objects =
[]

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Component

included

Constructor Details

#initialize(fog_interfaces, log, options = {}) ⇒ DHCPOptionsSet

Returns a new instance of DHCPOptionsSet.



25
26
27
28
29
30
31
32
33
34
35
# File 'lib/build-cloud/dhcpoptionsset.rb', line 25

def initialize ( fog_interfaces, log, options = {} )

    @compute = fog_interfaces[:compute]
    @log     = log
    @options = options

    @log.debug( options.inspect )

    required_options(:dhcp_configuration_set)

end

Class Method Details

.get_id_by_name(name) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/build-cloud/dhcpoptionsset.rb', line 7

def self.get_id_by_name( name )

    dhcp_option = self.search( :name => name ).first

    unless dhcp_option
        raise "Couldn't get a DHCP Options Set object for #{name} - is it defined?"
    end

    dhcp_option_fog = dhcp_option.read

    unless dhcp_option_fog
        raise "Couldn't get a DHCP Options Set fog object for #{name} - is it created?"
    end

    dhcp_option_fog.id

end

Instance Method Details

#[](key) ⇒ Object



72
73
74
# File 'lib/build-cloud/dhcpoptionsset.rb', line 72

def [](key)
    @options[key]
end

#createObject



37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/build-cloud/dhcpoptionsset.rb', line 37

def create
    
    return if exists?

    @log.info( "Creating new DHCP Options Set for #{@options[:name]}" )

    options = @options.dup

    options[:tags] = { 'Name' => options.delete(:name) }

    dhcp_option = @compute.dhcp_options.new( options )
    dhcp_option.save

    @compute.create_tags( dhcp_option.id, options[:tags] )

    @log.debug( dhcp_option.inspect )

end

#deleteObject



62
63
64
65
66
67
68
69
70
# File 'lib/build-cloud/dhcpoptionsset.rb', line 62

def delete

    return unless exists?

    @log.info( "Deleting DHCP Options Set for #{@options[:name]}" )

    fog_object.destroy

end

#readObject Also known as: fog_object



56
57
58
# File 'lib/build-cloud/dhcpoptionsset.rb', line 56

def read
    @compute.dhcp_options.select { |d| d.tag_set['Name'] == @options[:name] }.first
end