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:



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

#filter_by(filter) ⇒ Array

Returns List of instances that matched the filter.

Parameters:

  • filter (Hash)

    Sequel-style DB record filter

Returns:

  • (Array)

    List of instances that matched the filter

Raises:



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

Parameters:

  • deployment_name (String)

    Deployment name

  • 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_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.

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

#ssh(username, options) ⇒ Object



62
63
64
65
66
67
# File 'lib/bosh/director/api/instance_manager.rb', line 62

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

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