Class: CloudfoundryBlueGreenDeploy::Cloudfoundry

Inherits:
Object
  • Object
show all
Defined in:
lib/cloudfoundry_blue_green_deploy/cloudfoundry.rb

Class Method Summary collapse

Class Method Details

.appsObject



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/cloudfoundry_blue_green_deploy/cloudfoundry.rb', line 11

def self.apps
  apps = []
  cmd = "cf apps"
  output = CommandLine.backtick(cmd)
  found_header = false

  lines = output.lines

  lines.each do |line|
    line = line.split
    if line[0] == 'name' && found_header == false
      found_header = true
      next
    end

    if found_header
      apps << App.new(name: line[0], state: line[1])
    end
  end

  apps
end

.map_route(app, domain, host) ⇒ Object



74
75
76
# File 'lib/cloudfoundry_blue_green_deploy/cloudfoundry.rb', line 74

def self.map_route(app, domain, host)
  execute("cf map-route #{app} #{domain} -n #{host}")
end

.push(app) ⇒ Object



34
35
36
# File 'lib/cloudfoundry_blue_green_deploy/cloudfoundry.rb', line 34

def self.push(app)
  execute("cf push #{app}")
end

.routesObject



42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# File 'lib/cloudfoundry_blue_green_deploy/cloudfoundry.rb', line 42

def self.routes
  routes = []
  cmd = "cf routes"
  output = CommandLine.backtick(cmd)
  success = !output.include?('FAILED')
  if success
    lines = output.lines
    found_header = false
    lines.each do |line|
      line = line.split
      if !found_header && line.include?('host') && line.include?('domain') && line.include?('apps')
        found_header = true
        @host_index = line.find_index('host')
        @domain_index = line.find_index('domain')
        @apps_index = line.find_index('apps')
        next
      end

      if found_header
        routes << Route.new(line[@host_index], line[@domain_index], line[@apps_index])
      end
    end
    routes
  else
    raise CloudfoundryCliError.new("\"#{cmd}\" returned \"#{success}\".  The output of the command was \n\"#{output}\".")
  end
end

.stop(app) ⇒ Object



38
39
40
# File 'lib/cloudfoundry_blue_green_deploy/cloudfoundry.rb', line 38

def self.stop(app)
  execute("cf stop #{app}")
end

.unmap_route(app, domain, host) ⇒ Object



70
71
72
# File 'lib/cloudfoundry_blue_green_deploy/cloudfoundry.rb', line 70

def self.unmap_route(app, domain, host)
  execute("cf unmap-route #{app} #{domain} -n #{host}")
end