Class: Bosh::Director::Api::InstanceLookup

Inherits:
Object
  • Object
show all
Defined in:
lib/bosh/director/api/instance_lookup.rb

Instance Method Summary collapse

Instance Method Details

#by_attributes(deployment_name, job_name, job_index) ⇒ Object



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/bosh/director/api/instance_lookup.rb', line 14

def by_attributes(deployment_name, job_name, job_index)
  deployment = DeploymentLookup.new.by_name(deployment_name)

  # 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?

  filter = {
    deployment_id: deployment.id,
    job: job_name,
    index: job_index
  }

  instance = Models::Instance.find(filter)
  if instance.nil?
    raise InstanceNotFound,
          "`#{deployment_name}/#{job_name}/#{job_index}' doesn't exist"
  end
  instance
end

#by_filter(filter) ⇒ Object



34
35
36
37
38
39
40
# File 'lib/bosh/director/api/instance_lookup.rb', line 34

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) ⇒ Object



6
7
8
9
10
11
12
# 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

#find_allObject



42
43
44
# File 'lib/bosh/director/api/instance_lookup.rb', line 42

def find_all
  Models::Instance.all
end