Module: Pairzone::Api::PairzoneLifecycle

Included in:
Pairzone
Defined in:
lib/pairzone/api/pairzone_lifecycle.rb

Constant Summary collapse

DEFAULT_START_WAIT_INTERVAL =
5

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#start_wait_intervalObject

Returns the value of attribute start_wait_interval.



5
6
7
# File 'lib/pairzone/api/pairzone_lifecycle.rb', line 5

def start_wait_interval
  @start_wait_interval
end

Instance Method Details

#report_starting_status(pairzone) ⇒ Object



16
17
18
19
20
21
# File 'lib/pairzone/api/pairzone_lifecycle.rb', line 16

def report_starting_status(pairzone)
  Logger.info("Pairzone '#{pairzone.name}' started.")
  pairzone.collaborators.each do |collaborator|
    Logger.info("Collaborator '#{collaborator}' added.")
  end
end

#start(options) ⇒ Object



8
9
10
11
12
13
14
# File 'lib/pairzone/api/pairzone_lifecycle.rb', line 8

def start(options)
  Logger.info("Starting Pairzone for project '#{options[:project_name]}'...")
  pairzone = create(:project_name => options[:project_name], :collaborators => options[:collaborators])
  report_starting_status(pairzone)

  wait_for(pairzone)
end

#wait_for(pairzone) ⇒ Object



23
24
25
26
27
28
29
30
31
# File 'lib/pairzone/api/pairzone_lifecycle.rb', line 23

def wait_for(pairzone)
  while pairzone.status != 'started' do
    Logger.info("Waiting for pairzone to boot...")
    sleep start_wait_interval || DEFAULT_START_WAIT_INTERVAL
    pairzone = find_by_project_name(pairzone.name)
  end
  Logger.info("Pairzone booted: ip address #{pairzone.ip}")
  pairzone
end