Class: Hcloud::LoadBalancerResource
- Inherits:
-
AbstractResource
- Object
- AbstractResource
- Hcloud::LoadBalancerResource
- Defined in:
- lib/hcloud/load_balancer_resource.rb
Instance Attribute Summary
Attributes inherited from AbstractResource
Instance Method Summary collapse
- #[](arg) ⇒ Object
- #create(name:, load_balancer_type:, algorithm:, location: nil, network_zone: nil, network: nil, public_interface: nil, services: nil, targets: nil, labels: {}) ⇒ Object
Methods inherited from AbstractResource
#all, bind_to, #each, filter_attributes, #find, #find_by, #initialize, #limit, #order, #page, #pagination, #per_page, resource, resource_class, resource_path, resource_url, #run, #where
Constructor Details
This class inherits a constructor from Hcloud::AbstractResource
Instance Method Details
#[](arg) ⇒ Object
9 10 11 12 13 14 |
# File 'lib/hcloud/load_balancer_resource.rb', line 9 def [](arg) case arg when Integer then find_by(id: arg) when String then find_by(name: arg) end end |
#create(name:, load_balancer_type:, algorithm:, location: nil, network_zone: nil, network: nil, public_interface: nil, services: nil, targets: nil, labels: {}) ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/hcloud/load_balancer_resource.rb', line 16 def create( name:, load_balancer_type:, algorithm:, location: nil, network_zone: nil, network: nil, public_interface: nil, services: nil, targets: nil, labels: {} ) raise Hcloud::Error::InvalidInput, 'no name given' if name.blank? raise Hcloud::Error::InvalidInput, 'no type given' if load_balancer_type.blank? if !algorithm.to_h.key?(:type) || algorithm[:type].blank? raise Hcloud::Error::InvalidInput, 'invalid algorithm given' end if location.blank? && network_zone.blank? raise Hcloud::Error::InvalidInput, 'either location or network_zone must be given' end prepare_request( 'load_balancers', j: COLLECT_ARGS.call(__method__, binding), expected_code: 201 ) do |response| action = Action.new(client, response[:action]) if response[:action] [action, LoadBalancer.new(client, response[:load_balancer])] end end |