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:



28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/bosh/director/api/instance_manager.rb', line 28

def agent_client_for(instance)
  vm = instance.vm
  if vm.nil?
    raise InstanceVmMissing,
          "`#{instance.job}/#{instance.index}' doesn't reference a VM"
  end

  if vm.agent_id.nil?
    raise VmAgentIdMissing, "VM `#{vm.cid}' doesn't have an agent id"
  end

  AgentClient.with_defaults(vm.agent_id)
end

#fetch_logs(user, deployment_name, job, index, options = {}) ⇒ Object



42
43
44
45
46
47
48
49
50
51
# File 'lib/bosh/director/api/instance_manager.rb', line 42

def fetch_logs(user, deployment_name, job, index, options = {})
  if deployment_name.nil? || job.nil? || index.nil?
    raise DirectorError,
          'deployment, job and index parameters are required'
  end

  instance = find_by_name(deployment_name, job, index)

  JobQueue.new.enqueue(user, 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:



22
23
24
# File 'lib/bosh/director/api/instance_manager.rb', line 22

def filter_by(filter)
  InstanceLookup.new.by_filter(filter)
end

#find_by_name(deployment_name, job, index) ⇒ Models::Instance

Parameters:

  • deployment_name (String)

    Deployment name

  • job (String)

    Job name

  • index (String)

    Job index

Returns:



15
16
17
# File 'lib/bosh/director/api/instance_manager.rb', line 15

def find_by_name(deployment_name, job, index)
  InstanceLookup.new.by_attributes(deployment_name, job, index)
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(user, options) ⇒ Object



53
54
55
56
57
58
# File 'lib/bosh/director/api/instance_manager.rb', line 53

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

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