Class: Bosh::Director::Api::InstanceManager
- Defined in:
- lib/bosh/director/api/instance_manager.rb
Instance Method Summary collapse
-
#agent_client_for(instance) ⇒ AgentClient
Agent client to talk to instance.
- #fetch_instances(username, deployment, format) ⇒ Object
- #fetch_instances_with_vm(username, deployment, format) ⇒ Object
- #fetch_logs(username, deployment, job, index_or_id, options = {}) ⇒ Object
-
#filter_by(deployment, filter) ⇒ Array
List of instances that matched the filter.
- #find_by_name(deployment, job, index_or_id) ⇒ Models::Instance
-
#find_instance(instance_id) ⇒ Models::Instance
Instance.
- #find_instances_by_deployment(deployment) ⇒ Object
- #ssh(username, deployment, options) ⇒ Object
Instance Method Details
#agent_client_for(instance) ⇒ AgentClient
Returns Agent client to talk to instance.
38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/bosh/director/api/instance_manager.rb', line 38 def agent_client_for(instance) unless instance.vm_cid raise InstanceVmMissing, "'#{instance}' doesn't reference a VM" end unless instance.agent_id raise VmAgentIdMissing, "VM '#{instance.vm_cid}' doesn't have an agent id" end AgentClient.with_vm_credentials_and_agent_id(instance.credentials, instance.agent_id) end |
#fetch_instances(username, deployment, format) ⇒ Object
67 68 69 |
# File 'lib/bosh/director/api/instance_manager.rb', line 67 def fetch_instances(username, deployment, format) JobQueue.new.enqueue(username, Jobs::VmState, 'retrieve vm-stats', [deployment.id, format, true], deployment) end |
#fetch_instances_with_vm(username, deployment, format) ⇒ Object
71 72 73 |
# File 'lib/bosh/director/api/instance_manager.rb', line 71 def fetch_instances_with_vm(username, deployment, format) JobQueue.new.enqueue(username, Jobs::VmState, 'retrieve vm-stats', [deployment.id, format], deployment) end |
#fetch_logs(username, deployment, job, index_or_id, options = {}) ⇒ Object
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/bosh/director/api/instance_manager.rb', line 51 def fetch_logs(username, deployment, job, index_or_id, = {}) if deployment.nil? || job.nil? || index_or_id.nil? raise DirectorError, 'deployment, instance group and index/id parameters are required' end # This is for backwards compatibility and can be removed when we move to referencing job by instance id only. if index_or_id.to_s =~ /^\d+$/ instance = find_by_name(deployment, job, index_or_id) else instance = filter_by(deployment, uuid: index_or_id).first end JobQueue.new.enqueue(username, Jobs::FetchLogs, 'fetch logs', [instance.id, ], deployment) end |
#filter_by(deployment, filter) ⇒ Array
Returns List of instances that matched the filter.
32 33 34 |
# File 'lib/bosh/director/api/instance_manager.rb', line 32 def filter_by(deployment, filter) InstanceLookup.new.by_filter(filter.merge(deployment_id: deployment.id)) end |
#find_by_name(deployment, job, index_or_id) ⇒ Models::Instance
15 16 17 18 19 20 21 22 |
# File 'lib/bosh/director/api/instance_manager.rb', line 15 def find_by_name(deployment, job, index_or_id) # This is for backwards compatibility and can be removed when we move to referencing job by instance id only. if index_or_id.to_s =~ /^\d+$/ InstanceLookup.new.by_attributes(deployment, job, index_or_id) else InstanceLookup.new.by_uuid(deployment, job, index_or_id) end end |
#find_instance(instance_id) ⇒ Models::Instance
Returns Instance.
7 8 9 |
# File 'lib/bosh/director/api/instance_manager.rb', line 7 def find_instance(instance_id) InstanceLookup.new.by_id(instance_id) end |
#find_instances_by_deployment(deployment) ⇒ Object
24 25 26 |
# File 'lib/bosh/director/api/instance_manager.rb', line 24 def find_instances_by_deployment(deployment) InstanceLookup.new.by_deployment(deployment) end |