Class: Bosh::Director::Api::InstanceLookup
- Defined in:
- lib/bosh/director/api/instance_lookup.rb
Instance Method Summary collapse
- #by_attributes(deployment, job_name, job_index) ⇒ Object
- #by_deployment(deployment) ⇒ Object
- #by_filter(filter) ⇒ Object
- #by_id(instance_id) ⇒ Object
- #by_uuid(deployment, job_name, uuid) ⇒ Object
- #find_all ⇒ Object
Instance Method Details
#by_attributes(deployment, job_name, job_index) ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 |
# 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) ⇒ Object
47 48 49 |
# File 'lib/bosh/director/api/instance_lookup.rb', line 47 def by_deployment(deployment) Models::Instance.filter(deployment: deployment).all end |
#by_filter(filter) ⇒ Object
35 36 37 38 39 40 41 |
# 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) ⇒ 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 |
#by_uuid(deployment, job_name, uuid) ⇒ Object
26 27 28 29 30 31 32 33 |
# 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 |