Sha256: 2e3ca8e54752bc364815c0c3fc9479e51b7a77c9f795055272eac74ebd5b90dc

Contents?: true

Size: 1.53 KB

Versions: 29

Compression:

Stored size: 1.53 KB

Contents

class BuildCloud::DHCPOptionsSet

    include ::BuildCloud::Component

    @@objects = []

    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

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

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

        @log.debug( options.inspect )

        required_options(:dhcp_configuration_set)

    end

    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

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

    alias_method :fog_object, :read

    def delete

        return unless exists?

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

        fog_object.destroy

    end

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

end

Version data entries

29 entries across 29 versions & 1 rubygems

Version Path
build-cloud-1.1.7 lib/build-cloud/dhcpoptionsset.rb
build-cloud-1.1.6 lib/build-cloud/dhcpoptionsset.rb
build-cloud-1.1.5 lib/build-cloud/dhcpoptionsset.rb
build-cloud-1.1.4 lib/build-cloud/dhcpoptionsset.rb
build-cloud-1.1.3 lib/build-cloud/dhcpoptionsset.rb
build-cloud-1.1.2 lib/build-cloud/dhcpoptionsset.rb
build-cloud-1.0.1 lib/build-cloud/dhcpoptionsset.rb
build-cloud-1.1.1 lib/build-cloud/dhcpoptionsset.rb
build-cloud-1.0.0 lib/build-cloud/dhcpoptionsset.rb
build-cloud-0.0.24 lib/build-cloud/dhcpoptionsset.rb
build-cloud-0.0.23 lib/build-cloud/dhcpoptionsset.rb
build-cloud-0.0.22 lib/build-cloud/dhcpoptionsset.rb
build-cloud-0.0.21 lib/build-cloud/dhcpoptionsset.rb
build-cloud-0.0.20 lib/build-cloud/dhcpoptionsset.rb
build-cloud-0.0.19 lib/build-cloud/dhcpoptionsset.rb
build-cloud-0.0.18 lib/build-cloud/dhcpoptionsset.rb
build-cloud-0.0.17 lib/build-cloud/dhcpoptionsset.rb
build-cloud-0.0.16 lib/build-cloud/dhcpoptionsset.rb
build-cloud-0.0.15 lib/build-cloud/dhcpoptionsset.rb
build-cloud-0.0.14 lib/build-cloud/dhcpoptionsset.rb