class Capistrano::Gcp::Autoscaling::Core::Instance

Constants

INSTANCE_PATTERN
NONE_ACTION
RUNNING_STATUS
SEPARATOR
VERIFYING_ACTION
ZONE_PATTERN

Attributes

compute_service[R]
managed_instance[R]
options[R]

Public Class Methods

new(compute_service, managed_instance, options = {}) click to toggle source
# File lib/capistrano/gcp/autoscaling/core/instance.rb, line 15
def initialize(compute_service, managed_instance, options = {})
  @compute_service = compute_service
  @managed_instance = managed_instance
  @options = options
end

Public Instance Methods

available?() click to toggle source
# File lib/capistrano/gcp/autoscaling/core/instance.rb, line 29
def available?
  running? && (verifying? || do_nothing?)
end
created_at() click to toggle source
# File lib/capistrano/gcp/autoscaling/core/instance.rb, line 25
def created_at
  Time.parse(instance.creation_timestamp)
end
network_ip() click to toggle source
# File lib/capistrano/gcp/autoscaling/core/instance.rb, line 21
def network_ip
  instance.network_interfaces.first.network_ip
end

Private Instance Methods

do_nothing?() click to toggle source
# File lib/capistrano/gcp/autoscaling/core/instance.rb, line 41
def do_nothing?
  managed_instance.current_action == NONE_ACTION
end
instance() click to toggle source
# File lib/capistrano/gcp/autoscaling/core/instance.rb, line 49
def instance
  @instance ||= compute_service.get_instance(options.fetch(:gcp_project_id), instance_zone, instance_name)
end
instance_name() click to toggle source
# File lib/capistrano/gcp/autoscaling/core/instance.rb, line 57
def instance_name
  parse_managed_instance(INSTANCE_PATTERN)
end
instance_zone() click to toggle source
# File lib/capistrano/gcp/autoscaling/core/instance.rb, line 53
def instance_zone
  parse_managed_instance(ZONE_PATTERN)
end
parse_managed_instance(pattern, separator = SEPARATOR) click to toggle source
# File lib/capistrano/gcp/autoscaling/core/instance.rb, line 61
def parse_managed_instance(pattern, separator = SEPARATOR)
  managed_instance.instance.scan(pattern).last.split(separator).last
end
running?() click to toggle source
# File lib/capistrano/gcp/autoscaling/core/instance.rb, line 37
def running?
  managed_instance.instance_status == RUNNING_STATUS
end
verifying?() click to toggle source
# File lib/capistrano/gcp/autoscaling/core/instance.rb, line 45
def verifying?
  managed_instance.current_action == VERIFYING_ACTION
end