Sha256: 3f2375acdf4a6fbf87b414e49d8c57036cc2d5994bc71a2d9aa9458fc24f18ac

Contents?: true

Size: 1.91 KB

Versions: 11

Compression:

Stored size: 1.91 KB

Contents

require 'chef/provider/lwrp_base'
require 'chef/provider/chef_node'
require 'openssl'
require 'chef/provisioning/chef_provider_action_handler'

class Chef
  class Provider
    class LoadBalancer < Chef::Provider::LWRPBase

      def action_handler
        @action_handler ||= Chef::Provisioning::ChefProviderActionHandler.new(self)
      end

      def whyrun_supported?
        true
      end

      def new_driver
        @new_driver ||= run_context.chef_metal.driver_for(new_resource.driver)
      end

      def chef_managed_entry_store
        @chef_managed_entry_store ||= Provisioning.chef_managed_entry_store(new_resource.chef_server)
      end

      action :create do
        lb_spec = chef_managed_entry_store.get_or_new(:load_balancer, new_resource.name)

        Chef::Log.debug "Creating load balancer: #{new_resource.name}; loaded #{lb_spec.inspect}"
        if new_resource.machines
          machine_specs = new_resource.machines.map { |machine| get_machine_spec!(machine) }
        end

        new_driver.allocate_load_balancer(action_handler, lb_spec, lb_options, machine_specs)
        lb_spec.save(action_handler)
        new_driver.ready_load_balancer(action_handler, lb_spec, lb_options, machine_specs)
      end

      action :destroy do
        lb_spec = chef_managed_entry_store.get(:load_balancer, new_resource.name)
        if lb_spec
          new_driver.destroy_load_balancer(action_handler, lb_spec, lb_options)
        end
      end

      private

      def get_machine_spec!(machine_name)
        Chef::Log.debug "Getting machine spec for #{machine_name}"
        Provisioning.chef_managed_entry_store(new_resource.chef_server).get!(:machine, machine_name)
      end

      def lb_options
        new_resource.load_balancer_options
      end

    end
  end
end

require 'chef/provisioning/chef_managed_entry_store'
Chef::Provisioning::ChefManagedEntryStore.type_names_for_backcompat[:load_balancer] = "loadbalancers"

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
chef-provisioning-1.3.0 lib/chef/provider/load_balancer.rb
chef-provisioning-1.2.1 lib/chef/provider/load_balancer.rb
chef-provisioning-1.2.0 lib/chef/provider/load_balancer.rb
chef-provisioning-1.1.1 lib/chef/provider/load_balancer.rb
chef-provisioning-1.1.0 lib/chef/provider/load_balancer.rb
chef-provisioning-1.0.1 lib/chef/provider/load_balancer.rb
chef-provisioning-1.0.0 lib/chef/provider/load_balancer.rb
chef-provisioning-1.0.0.rc.2 lib/chef/provider/load_balancer.rb
chef-provisioning-0.20.1 lib/chef/provider/load_balancer.rb
chef-provisioning-1.0.0.rc.1 lib/chef/provider/load_balancer.rb
chef-provisioning-0.20 lib/chef/provider/load_balancer.rb