Module: Bosh::Cli::DeploymentHelper

Instance Method Summary collapse

Methods included from VersionCalc

#major_version, #minor_version, #version_cmp, #version_greater, #version_less, #version_same

Instance Method Details

#deployment_changed?(current_manifest, manifest, show = true) ⇒ Boolean

Check if the 2 deployments are different. Print out a summary if “show” is true.

Returns:

  • (Boolean)


70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
# File 'lib/cli/deployment_helper.rb', line 70

def deployment_changed?(current_manifest, manifest, show = true)
  diff = Bosh::Cli::HashChangeset.new
  diff.add_hash(normalize_deployment_manifest(manifest), :new)
  diff.add_hash(normalize_deployment_manifest(current_manifest), :old)
  changed = diff.changed?

  if changed && show
    @_diff_key_visited = {}
    diff.keys.each do |key|
      unless @_diff_key_visited[key]
        print_summary(diff, key)
        nl
      end
    end
  end

  changed
end

#inspect_deployment_changes(manifest, options = { }) ⇒ Object

Interactive walkthrough of deployment changes, expected to bail out of CLI using ‘cancel_deployment’ if something goes wrong, so it doesn’t need to have a meaningful return value.

Returns:

  • Boolean Were there any changes in deployment manifest?



94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
# File 'lib/cli/deployment_helper.rb', line 94

def inspect_deployment_changes(manifest, options = { })
  show_empty_changeset = true

  if options.has_key?(:show_empty_changeset)
    show_empty_changeset = options[:show_empty_changeset]
  end

  manifest = manifest.dup
  current_deployment = director.get_deployment(manifest["name"])

  # We cannot retrieve current manifest until there was at least one
  # successful deployment. There used to be a warning about that
  # but it turned out to be confusing to many users and thus has
  # been removed.
  return if current_deployment["manifest"].nil?
  current_manifest = YAML.load(current_deployment["manifest"])

  unless current_manifest.is_a?(Hash)
    err("Current deployment manifest format is invalid, " +
            "check if director works properly")
  end

  # TODO: validate new deployment manifest
  diff = Bosh::Cli::HashChangeset.new
  diff.add_hash(normalize_deployment_manifest(manifest), :new)
  diff.add_hash(normalize_deployment_manifest(current_manifest), :old)
  @_diff_key_visited = { "name" => 1, "director_uuid" => 1 }

  say("Detecting changes in deployment...".green)
  nl

  if !diff.changed? && !show_empty_changeset
    return false
  end

  if diff[:release]
    print_summary(diff, :release)
    warn_about_release_changes(diff[:release])
    nl
  end

  if diff[:releases]
    print_summary(diff, :releases)
    diff[:releases].each do |release_diff|
      warn_about_release_changes(release_diff)
    end
    nl
  end

  print_summary(diff, :compilation)
  nl

  print_summary(diff, :update)
  nl

  print_summary(diff, :resource_pools)

  old_stemcells = Set.new
  new_stemcells = Set.new

  diff[:resource_pools].each do |pool|
    old_stemcells << {
      :name => pool[:stemcell][:name].old,
      :version => pool[:stemcell][:version].old
    }
    new_stemcells << {
      :name => pool[:stemcell][:name].new,
      :version => pool[:stemcell][:version].new
    }
  end

  if old_stemcells != new_stemcells
    unless confirmed?("Stemcell update has been detected. " +
                      "Are you sure you want to update stemcells?")
      cancel_deployment
    end
  end

  if old_stemcells.size != new_stemcells.size
    say("Stemcell update seems to be inconsistent with current ".red +
        "deployment. Please carefully review changes above.".red)
    unless confirmed?("Are you sure this configuration is correct?")
      cancel_deployment
    end
  end

  nl
  print_summary(diff, :networks)
  nl
  print_summary(diff, :jobs)
  nl
  print_summary(diff, :properties)
  nl

  diff.keys.each do |key|
    unless @_diff_key_visited[key]
      print_summary(diff, key)
      nl
    end
  end

  diff.changed?
rescue Bosh::Cli::ResourceNotFound
  say("Cannot get current deployment information from director, " +
      "possibly a new deployment".red)
  true
end

#prepare_deployment_manifest(options = {}) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
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
# File 'lib/cli/deployment_helper.rb', line 7

def prepare_deployment_manifest(options = {})
  # TODO: extract to helper class
  deployment_required
  manifest_filename = deployment

  unless File.exists?(manifest_filename)
    err("Cannot find deployment manifest in `#{manifest_filename}'")
  end

  manifest = load_yaml_file(manifest_filename)
  manifest_yaml = File.read(manifest_filename)

  if manifest["name"].blank?
    err("Deployment name not found in the deployment manifest")
  end

  if manifest["target"]
    err(manifest_target_upgrade_notice)
  end

  if options[:resolve_properties]
    compiler = DeploymentManifestCompiler.new(manifest_yaml)
    properties = {}

    begin
      say("Getting deployment properties from director...")
      properties = director.list_properties(manifest["name"])
    rescue Bosh::Cli::DirectorError
      say("Unable to get properties list from director, " +
          "trying without it...")
    end

    say("Compiling deployment manifest...")
    compiler.properties = properties.inject({}) do |hash, property|
      hash[property["name"]] = property["value"]
      hash
    end

    manifest = YAML.load(compiler.result)
  end

  if manifest["name"].blank? || manifest["director_uuid"].blank?
    err("Invalid manifest `#{File.basename(deployment)}': " +
        "name and director UUID are required")
  end

  if director.uuid != manifest["director_uuid"]
    err("Target director UUID doesn't match UUID from deployment manifest")
  end

  if manifest["release"].blank? && manifest["releases"].blank?
    err("Deployment manifest doesn't have release information: '" +
        "please add 'release' or 'releases' section")
  end

  resolve_release_aliases(manifest)
  resolve_stemcell_aliases(manifest)

  options[:yaml] ? YAML.dump(manifest) : manifest
end