class Bosh::Director::Api::InstanceLookup

Public Instance Methods

by_attributes(deployment, job_name, job_index) click to toggle source
# File lib/bosh/director/api/instance_lookup.rb, line 14
def by_attributes(deployment, job_name, job_index)
  # Postgres cannot coerce an empty string to integer, and fails on Models::Instance.find
  job_index = nil if job_index.is_a?(String) && job_index.empty?

  instance = Models::Instance.find(deployment: deployment, job: job_name, index: job_index)
  if instance.nil?
    raise InstanceNotFound,
          "'#{deployment.name}/#{job_name}/#{job_index}' doesn't exist"
  end
  instance
end
by_deployment(deployment) click to toggle source
# File lib/bosh/director/api/instance_lookup.rb, line 47
def by_deployment(deployment)
  Models::Instance.filter(deployment: deployment).all
end
by_filter(filter) click to toggle source
# File lib/bosh/director/api/instance_lookup.rb, line 35
def by_filter(filter)
  instances = Models::Instance.filter(filter).all
  if instances.empty?
    raise InstanceNotFound, "No instances matched #{filter.inspect}"
  end
  instances
end
by_id(instance_id) click to toggle source
# File lib/bosh/director/api/instance_lookup.rb, line 6
def by_id(instance_id)
  instance = Models::Instance[instance_id]
  if instance.nil?
    raise InstanceNotFound, "Instance #{instance_id} doesn't exist"
  end
  instance
end
by_uuid(deployment, job_name, uuid) click to toggle source
# File lib/bosh/director/api/instance_lookup.rb, line 26
def by_uuid(deployment, job_name, uuid)
  instance = Models::Instance.find(deployment: deployment, job: job_name, uuid: uuid)
  if instance.nil?
    raise InstanceNotFound,
          "'#{deployment.name}/#{job_name}/#{uuid}' doesn't exist"
  end
  instance
end
find_all() click to toggle source
# File lib/bosh/director/api/instance_lookup.rb, line 43
def find_all
  Models::Instance.all
end