Class: Bosh::Director::Api::InstanceManager

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

Instance Method Summary collapse

Instance Method Details

#agent_client_for(instance) ⇒ AgentClient

Returns Agent client to talk to instance.

Parameters:

Returns:



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, options = {})
  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, options], deployment)
end

#filter_by(deployment, filter) ⇒ Array

Returns List of instances that matched the filter.

Parameters:

Returns:

  • (Array)

    List of instances that matched the filter

Raises:



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

Parameters:

  • deployment (Models::Deployment)
  • job (String)

    Job name

  • index_or_id (String)

    Job index or id

Returns:



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.

Parameters:

  • instance_id (Integer)

    Instance id

Returns:

Raises:



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

#ssh(username, deployment, options) ⇒ Object



75
76
77
78
79
# File 'lib/bosh/director/api/instance_manager.rb', line 75

def ssh(username, deployment, options)
  description = "ssh: #{options['command']}:#{options['target']}"

  JobQueue.new.enqueue(username, Jobs::Ssh, description, [deployment.id, options])
end