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_logs(username, deployment_name, job, index_or_id, options = {}) ⇒ Object
-
#filter_by(filter) ⇒ Array
List of instances that matched the filter.
- #find_by_name(deployment_name, job, index_or_id) ⇒ Models::Instance
-
#find_instance(instance_id) ⇒ Models::Instance
Instance.
- #ssh(username, options) ⇒ Object
Instance Method Details
#agent_client_for(instance) ⇒ AgentClient
Returns Agent client to talk to instance.
33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/bosh/director/api/instance_manager.rb', line 33 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_logs(username, deployment_name, job, index_or_id, options = {}) ⇒ Object
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/bosh/director/api/instance_manager.rb', line 46 def fetch_logs(username, deployment_name, job, index_or_id, = {}) if deployment_name.nil? || job.nil? || index_or_id.nil? raise DirectorError, 'deployment, job 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_name, job, index_or_id) else instance = filter_by(uuid: index_or_id).first end JobQueue.new.enqueue(username, Jobs::FetchLogs, 'fetch logs', [instance.id, ]) end |
#filter_by(filter) ⇒ Array
Returns List of instances that matched the filter.
27 28 29 |
# File 'lib/bosh/director/api/instance_manager.rb', line 27 def filter_by(filter) InstanceLookup.new.by_filter(filter) end |
#find_by_name(deployment_name, 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_name, 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_name, job, index_or_id) else InstanceLookup.new.by_uuid(deployment_name, 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 |
#ssh(username, options) ⇒ Object
62 63 64 65 66 67 |
# File 'lib/bosh/director/api/instance_manager.rb', line 62 def ssh(username, ) description = "ssh: #{options['command']}:#{options['target']}" deployment = DeploymentLookup.new.by_name(['deployment_name']) JobQueue.new.enqueue(username, Jobs::Ssh, description, [deployment.id, ]) end |