Class: VagrantPlugins::DockerProvider::Provider

Inherits:
Object
  • Object
show all
Defined in:
lib/docker-provider/provider.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(machine) ⇒ Provider

Returns a new instance of Provider.



9
10
11
12
13
# File 'lib/docker-provider/provider.rb', line 9

def initialize(machine)
  @logger  = Log4r::Logger.new("vagrant::provider::docker")
  @machine = machine
  @driver  = Driver.new
end

Instance Attribute Details

#driverObject (readonly)

Returns the value of attribute driver.



7
8
9
# File 'lib/docker-provider/provider.rb', line 7

def driver
  @driver
end

Instance Method Details

#action(name) ⇒ Object

See Also:

  • Vagrant::Plugin::V2::Provider#action


16
17
18
19
20
# File 'lib/docker-provider/provider.rb', line 16

def action(name)
  action_method = "action_#{name}"
  return Action.send(action_method) if Action.respond_to?(action_method)
  nil
end

#ssh_infoObject

Returns the SSH info for accessing the Container.



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/docker-provider/provider.rb', line 23

def ssh_info
  # If the Container is not created then we cannot possibly SSH into it, so
  # we return nil.
  return nil if state == :not_created

  network = @driver.inspect_container(@machine.id)['NetworkSettings']
  ip      = network['IPAddress']

  # If we were not able to identify the container's IP, we return nil
  # here and we let Vagrant core deal with it ;)
  return nil unless ip

  {
    :host => ip,
    :port => @machine.config.ssh.guest_port
  }
end

#stateObject



41
42
43
44
45
46
47
48
49
50
51
# File 'lib/docker-provider/provider.rb', line 41

def state
  state_id = nil
  state_id = :not_created if !@machine.id || !@driver.created?(@machine.id)
  state_id = @driver.state(@machine.id) if @machine.id && !state_id
  state_id = :unknown if !state_id

  short = state_id.to_s.gsub("_", " ")
  long  = I18n.t("vagrant.commands.status.#{state_id}")

  Vagrant::MachineState.new(state_id, short, long)
end

#to_sObject



53
54
55
56
# File 'lib/docker-provider/provider.rb', line 53

def to_s
  id = @machine.id ? @machine.id : "new container"
  "Docker (#{id})"
end