Module: VMC::App::Create

Included in:
Push
Defined in:
lib/vmc/cli/app/push/create.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#inputObject

Returns the value of attribute input.



3
4
5
# File 'lib/vmc/cli/app/push/create.rb', line 3

def input
  @input
end

#path=(value) ⇒ Object (writeonly)

Sets the attribute path

Parameters:

  • value

    the value to set the attribute path to.



4
5
6
# File 'lib/vmc/cli/app/push/create.rb', line 4

def path=(value)
  @path = value
end

Instance Method Details

#bind_services(app) ⇒ Object



97
98
99
100
101
102
103
104
105
# File 'lib/vmc/cli/app/push/create.rb', line 97

def bind_services(app)
  return unless input[:bind_services]

  while true
    invoke :bind_service, :app => app
    break if (all_instances - app.services).empty?
    break unless ask("Bind another service?", :default => false)
  end
end

#create_app(inputs) ⇒ Object



51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/vmc/cli/app/push/create.rb', line 51

def create_app(inputs)
  app = client.app

  inputs.each { |key, value| app.send(:"#{key}=", value) }

  app = filter(:create_app, app)

  with_progress("Creating #{c(app.name, :name)}") do
    app.create!
  end

  app
end

#create_services(app) ⇒ Object



88
89
90
91
92
93
94
95
# File 'lib/vmc/cli/app/push/create.rb', line 88

def create_services(app)
  return unless input[:create_services]

  while true
    invoke :create_service, { :app => app }, :plan => :interact
    break unless ask("Create another service?", :default => false)
  end
end

#determine_frameworkObject



22
23
24
25
26
27
28
29
30
# File 'lib/vmc/cli/app/push/create.rb', line 22

def determine_framework
  return input[:framework] if input.given?(:framework)

  if (detected_framework = detector.detect_framework)
    input[:framework, [detected_framework], detected_framework, :other]
  else
    input[:framework, detector.all_frameworks, nil, nil]
  end
end

#determine_runtime(framework) ⇒ Object



32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/vmc/cli/app/push/create.rb', line 32

def determine_runtime(framework)
  return input[:runtime] if input.given?(:runtime)

  detected_runtimes =
    if framework.name == "standalone"
      detector.detect_runtimes
    else
      detector.runtimes(framework)
    end

  default_runtime = detected_runtimes.size == 1 ? detected_runtimes.first : nil

  if detected_runtimes.empty?
    input[:runtime, detector.all_runtimes, nil, nil]
  else
    input[:runtime, detected_runtimes, default_runtime, :other]
  end
end

#get_inputsObject



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/vmc/cli/app/push/create.rb', line 6

def get_inputs
  inputs = {}
  inputs[:name] = input[:name]
  inputs[:total_instances] = input[:instances]
  inputs[:space] = client.current_space if client.current_space
  inputs[:production] = !!(input[:plan] =~ /^p/i) if v2?
  inputs[:framework] = framework = determine_framework
  inputs[:command] = input[:command] if framework.name == "standalone"
  inputs[:runtime] = determine_runtime(framework)

  human_mb = human_mb(detector.suggested_memory(framework) || 64)
  inputs[:memory] = megabytes(input[:memory, human_mb])

  inputs
end

#map_url(app) ⇒ Object



65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
# File 'lib/vmc/cli/app/push/create.rb', line 65

def map_url(app)
  line unless quiet?

  url = input[:url, app.name]

  mapped_url = false
  until !url || mapped_url
    begin
      invoke :map, :app => app, :url => url
      mapped_url = true
    rescue CFoundry::RouteHostTaken, CFoundry::UriAlreadyTaken => e
      line c(e.description, :bad)
      line

      input.forget(:url)
      url = input[:url, app.name]

      # version bumps on v1 even though mapping fails
      app.invalidate! unless v2?
    end
  end
end

#start_app(app) ⇒ Object



107
108
109
# File 'lib/vmc/cli/app/push/create.rb', line 107

def start_app(app)
  invoke :start, :app => app if input[:start]
end