Class: Bosh::Director::Api::ReleaseManager

Inherits:
Object
  • Object
show all
Includes:
ApiHelper
Defined in:
lib/bosh/director/api/release_manager.rb

Constant Summary

Constants included from ApiHelper

ApiHelper::READ_CHUNK_SIZE

Instance Method Summary collapse

Methods included from ApiHelper

#check_available_disk_space, #json_decode, #json_encode, #send_disposable_file, #start_task, #write_file

Instance Method Details

#create_release_from_file_path(username, release_path, options) ⇒ Object



54
55
56
57
58
59
60
# File 'lib/bosh/director/api/release_manager.rb', line 54

def create_release_from_file_path(username, release_path, options)
  unless File.exists?(release_path)
    raise DirectorError, "Failed to create release: file not found - #{release_path}"
  end

  JobQueue.new.enqueue(username, Jobs::UpdateRelease, 'create release', [release_path, options])
end

#create_release_from_url(username, release_url, options) ⇒ Object



49
50
51
52
# File 'lib/bosh/director/api/release_manager.rb', line 49

def create_release_from_url(username, release_url, options)
  options[:remote] = true
  JobQueue.new.enqueue(username, Jobs::UpdateRelease, 'create release', [release_url, options])
end

#delete_release(username, release, options = {}) ⇒ Object



62
63
64
# File 'lib/bosh/director/api/release_manager.rb', line 62

def delete_release(username, release, options = {})
  JobQueue.new.enqueue(username, Jobs::DeleteRelease, "delete release: #{release.name}", [release.name, options])
end

#export_release(username, deployment_name, release_name, release_version, stemcell_os, stemcell_version) ⇒ Object



66
67
68
69
70
71
72
# File 'lib/bosh/director/api/release_manager.rb', line 66

def export_release(username, deployment_name, release_name, release_version, stemcell_os, stemcell_version)
  JobQueue.new.enqueue(
      username,
      Jobs::ExportRelease,
      "export release: '#{release_name}/#{release_version}' for '#{stemcell_os}/#{stemcell_version}'",
      [deployment_name, release_name, release_version, stemcell_os, stemcell_version])
end

#find_by_name(name) ⇒ Models::Release

Finds release by name

Raises:



10
11
12
13
14
15
16
# File 'lib/bosh/director/api/release_manager.rb', line 10

def find_by_name(name)
  release = Models::Release[:name => name]
  if release.nil?
    raise ReleaseNotFound, "Release `#{name}' doesn't exist"
  end
  release
end

#find_version(release, version) ⇒ Models::ReleaseVersion

Returns Release version model.



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
# File 'lib/bosh/director/api/release_manager.rb', line 22

def find_version(release, version)
  dataset = release.versions_dataset

  release_version = dataset.filter(:version => version).first
  if release_version.nil?
    begin
      new_formatted_version = Bosh::Common::Version::ReleaseVersion.parse(version)
    rescue SemiSemantic::ParseError
      raise ReleaseVersionInvalid, "Release version invalid: #{version}"
    end
    if version == new_formatted_version.to_s
      old_formatted_version = new_formatted_version.to_old_format
      if old_formatted_version
        release_version = dataset.filter(:version => old_formatted_version).first
      end
    else
      release_version = dataset.filter(:version => new_formatted_version.to_s).first
    end
    if release_version.nil?
      raise ReleaseVersionNotFound,
            "Release version `#{release.name}/#{version}' doesn't exist"
    end
  end

  release_version
end