Class: Bosh::Director::DeploymentPlan::Stemcell

Inherits:
Object
  • Object
show all
Includes:
ValidationHelper
Defined in:
lib/bosh/director/deployment_plan/stemcell.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from ValidationHelper

#invalid_type, #safe_property

Constructor Details

#initialize(spec) ⇒ Stemcell

Returns a new instance of Stemcell.

Parameters:

  • spec (Hash)

    Raw stemcell spec according to deployment manifest



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/bosh/director/deployment_plan/stemcell.rb', line 21

def initialize(spec)
  @alias = safe_property(spec, "alias", :class => String, :optional => true)

  @name = safe_property(spec, "name", :class => String, :optional => true)
  @os = safe_property(spec, "os", :class => String, :optional => true)

  if @name.nil? && @os.nil?
    raise ValidationMissingField, "Required property `os' or `name' was not specified in object (#{spec})"
  end

  if !@name.nil? && !@os.nil?
    raise StemcellBothNameAndOS, "Properties `os' and `name' are both specified for stemcell, choose one. (#{spec})"
  end

  @version = safe_property(spec, "version", :class => String)

  @manager = Api::StemcellManager.new
  @model = nil
end

Instance Attribute Details

#aliasObject (readonly)

Returns the value of attribute alias.



8
9
10
# File 'lib/bosh/director/deployment_plan/stemcell.rb', line 8

def alias
  @alias
end

#modelModels::Stemcell (readonly)

Returns Stemcell DB model.

Returns:



18
19
20
# File 'lib/bosh/director/deployment_plan/stemcell.rb', line 18

def model
  @model
end

#nameString (readonly)

Returns Stemcell name.

Returns:

  • (String)

    Stemcell name



12
13
14
# File 'lib/bosh/director/deployment_plan/stemcell.rb', line 12

def name
  @name
end

#osObject (readonly)

Returns the value of attribute os.



9
10
11
# File 'lib/bosh/director/deployment_plan/stemcell.rb', line 9

def os
  @os
end

#versionString (readonly)

Returns Stemcell version.

Returns:

  • (String)

    Stemcell version



15
16
17
# File 'lib/bosh/director/deployment_plan/stemcell.rb', line 15

def version
  @version
end

Instance Method Details

#add_stemcell_modelObject



60
61
62
63
64
65
66
67
68
# File 'lib/bosh/director/deployment_plan/stemcell.rb', line 60

def add_stemcell_model
  @model = is_using_os? ?
    @manager.find_by_os_and_version(@os, @version) :
    @manager.find_by_name_and_version(@name, @version)

  @name = @model.name
  @os = @model.operating_system
  @version = @model.version
end

#bind_model(deployment_plan) ⇒ void

This method returns an undefined value.

Looks up the stemcell matching provided spec



47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/bosh/director/deployment_plan/stemcell.rb', line 47

def bind_model(deployment_plan)
  deployment_model = deployment_plan.model
  if deployment_model.nil?
    raise DirectorError, "Deployment not bound in the deployment plan"
  end

  add_stemcell_model

  unless @model.deployments.include?(deployment_model)
    @model.add_deployment(deployment_model)
  end
end

#cidObject



74
75
76
# File 'lib/bosh/director/deployment_plan/stemcell.rb', line 74

def cid
  @model.cid
end

#descObject



70
71
72
# File 'lib/bosh/director/deployment_plan/stemcell.rb', line 70

def desc
  @model.desc
end

#idObject



78
79
80
# File 'lib/bosh/director/deployment_plan/stemcell.rb', line 78

def id
  @model.id
end

#is_using_os?Boolean

Returns:

  • (Boolean)


41
42
43
# File 'lib/bosh/director/deployment_plan/stemcell.rb', line 41

def is_using_os?
  !@os.nil? && @name.nil?
end

#specObject



82
83
84
85
86
87
# File 'lib/bosh/director/deployment_plan/stemcell.rb', line 82

def spec
  {
    "name" => @name,
    "version" => @version
  }
end