Sha256: 515b4eecd8f7fa63086c1d04c40efb34c491d849fe3623f7190d93b93f05dcde

Contents?: true

Size: 1.98 KB

Versions: 37

Compression:

Stored size: 1.98 KB

Contents

require 'fog/core/model'

module Fog
  module HP
    class LB

      class LoadBalancer < Fog::Model
        identity  :id

        attribute :name
        attribute :protocol
        attribute :port
        attribute :algorithm
        attribute :status
        attribute :status_description, :aliases => 'statusDescription'
        attribute :nodes
        attribute :virtual_ips, :aliases => 'virtualIps'
        attribute :node_count,  :aliases => 'nodeCount'
        attribute :created_at,  :aliases => 'created'
        attribute :updated_at , :aliases => 'updated'

        def destroy
          requires :id
          service.delete_load_balancer(id)
          true
        end

        def ready?
          self.status == 'ACTIVE'
        end

        def save
          identity ? update : create
        end

        def nodes
          @nodes ||= begin
            Fog::HP::LB::Nodes.new({
              :service  => service,
              :load_balancer   => self
            })
          end
        end

        def nodes=(new_nodes=[])
          nodes.load(new_nodes)
        end

        private

        def create
          requires :name, :nodes

          options = {}
          options['virtualIps'] = virtual_ips if virtual_ips
          options['port']       = port if port
          options['protocol']   = protocol if protocol
          options['algorithm']  = algorithm if algorithm
          merge_attributes(service.create_load_balancer(name, nodes_to_hash, options).body)
          true
        end

        def update
          requires :id

          options = {}
          options['name']       = name if name
          options['algorithm']  = algorithm if algorithm
          service.update_load_balancer(id, options).body
          true
        end

        def nodes_to_hash
          if nodes
            nodes.collect do |node|
              { 'address' => node.address, 'port' => node.port, 'condition' => node.condition }
            end
          end
        end
      end
    end
  end
end

Version data entries

37 entries across 37 versions & 2 rubygems

Version Path
fog-1.22.0 lib/fog/hp/models/lb/load_balancer.rb
fog-1.21.0 lib/fog/hp/models/lb/load_balancer.rb
fog-maestrodev-1.20.0.20140305101839 lib/fog/hp/models/lb/load_balancer.rb
fog-maestrodev-1.20.0.20140305101305 lib/fog/hp/models/lb/load_balancer.rb
fog-maestrodev-1.19.0.20140212012611 lib/fog/hp/models/lb/load_balancer.rb
fog-1.20.0 lib/fog/hp/models/lb/load_balancer.rb
fog-maestrodev-1.19.0.20140110004459 lib/fog/hp/models/lb/load_balancer.rb
fog-maestrodev-1.19.0.20140110003812 lib/fog/hp/models/lb/load_balancer.rb
fog-maestrodev-1.19.0.20140109202555 lib/fog/hp/models/lb/load_balancer.rb
fog-maestrodev-1.19.0.20140107192102 lib/fog/hp/models/lb/load_balancer.rb
fog-maestrodev-1.19.0.20140107142106 lib/fog/hp/models/lb/load_balancer.rb
fog-maestrodev-1.19.0.20131219203941 lib/fog/hp/models/lb/load_balancer.rb
fog-maestrodev-1.18.0.20131219193542 lib/fog/hp/models/lb/load_balancer.rb
fog-1.19.0 lib/fog/hp/models/lb/load_balancer.rb
fog-maestrodev-1.18.0.20131219033443 lib/fog/hp/models/lb/load_balancer.rb
fog-maestrodev-1.18.0.20131219032002 lib/fog/hp/models/lb/load_balancer.rb
fog-maestrodev-1.18.0.20131219030716 lib/fog/hp/models/lb/load_balancer.rb
fog-maestrodev-1.18.0.20131219022322 lib/fog/hp/models/lb/load_balancer.rb
fog-maestrodev-1.18.0.20131218202447 lib/fog/hp/models/lb/load_balancer.rb
fog-maestrodev-1.18.0.20131209091424 lib/fog/hp/models/lb/load_balancer.rb