Class: Fog::Compute::Google::InstanceGroups

Inherits:
Fog::Collection
  • Object
show all
Defined in:
lib/fog/compute/google/models/instance_groups.rb

Instance Method Summary collapse

Instance Method Details

#add_instance(params) ⇒ Object

TODO: To be deprecated


38
39
40
41
42
43
44
# File 'lib/fog/compute/google/models/instance_groups.rb', line 38

def add_instance(params)
  Fog::Logger.deprecation(
    "#{self.class}.#{__method__} is deprecated, use Fog::Compute::Google::InstanceGroup.#{__method__} instead [light_black](#{caller(0..0)})[/]"
  )
  params[:instance] = [params[:instance]] unless params[:instance] == Array
  service.add_instance_group_instances(params[:group], params[:zone], params[:instance])
end

#all(filters = {}) ⇒ Object


7
8
9
10
11
12
13
14
15
16
17
18
# File 'lib/fog/compute/google/models/instance_groups.rb', line 7

def all(filters = {})
  if filters[:zone]
    data = Array(service.list_instance_groups(filters[:zone]))
  else
    data = []
    service.list_aggregated_instance_groups.items.each_value do |group|
      data.concat(group.instance_groups) if group.instance_groups
    end
  end

  load(data.map(&:to_h))
end

#get(identity, zone = nil) ⇒ Object


20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/fog/compute/google/models/instance_groups.rb', line 20

def get(identity, zone = nil)
  if zone.nil?
    zones = service.list_aggregated_instance_groups(:filter => "name eq .*#{identity}").items
    instance_groups = zones.each_value.map(&:instance_groups).compact.first
    if instance_groups
      zone = instance_groups.first.zone.split("/")[-1]
    end
  end

  if instance_group = service.get_instance_group(identity, zone)
    new(instance_group.to_h)
  end
rescue ::Google::Apis::ClientError => e
  raise e unless e.status_code == 404
  nil
end

#remove_instance(params) ⇒ Object

TODO: To be deprecated


47
48
49
50
51
52
53
# File 'lib/fog/compute/google/models/instance_groups.rb', line 47

def remove_instance(params)
  Fog::Logger.deprecation(
    "#{self.class}.#{__method__} is deprecated, use Fog::Compute::Google::InstanceGroup.#{__method__} instead [light_black](#{caller(0..0)})[/]"
  )
  params[:instance] = [params[:instance]] unless params[:instance] == Array
  service.remove_instance_group_instances(params[:group], params[:zone], params[:instance])
end