Sha256: 771c1c07cad86df8222be50503d5fc9319c1c0ce612847a1947b9b6feff0c2a2

Contents?: true

Size: 1.65 KB

Versions: 2

Compression:

Stored size: 1.65 KB

Contents

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

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

      action :create do
        lb_spec = Chef::Provisioning::ChefLoadBalancerSpec.get(new_resource.name) ||
                  Chef::Provisioning::ChefLoadBalancerSpec.empty(new_resource.name)

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

        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::Provisioning::ChefLoadBalancerSpec.get(new_resource.name)
        new_driver.destroy_load_balancer(action_handler, lb_spec, lb_options)
      end

      private
      def get_machine_spec(machine_name)
        Chef::Log.debug "Getting machine spec for #{machine_name}"
        Chef::Provisioning::ChefMachineSpec.get(machine_name)
      end

      def lb_options
        new_resource.load_balancer_options
      end

    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
chef-provisioning-0.18 lib/chef/provider/load_balancer.rb
chef-provisioning-0.17 lib/chef/provider/load_balancer.rb