Class: Bosh::Director::Models::Instance
- Defined in:
- lib/bosh/director/models/instance.rb
Instance Method Summary collapse
- #cloud_properties_hash ⇒ Object
- #cloud_properties_hash=(hash) ⇒ Object
- #credentials ⇒ Object
- #credentials=(spec) ⇒ Object
- #dns_record_names ⇒ Object
- #dns_record_names=(list) ⇒ Object
- #latest_rendered_templates_archive ⇒ Object
- #name ⇒ Object
- #persistent_disk ⇒ Object
- #persistent_disk_cid ⇒ Object
- #spec ⇒ Object
- #spec=(spec) ⇒ Object
- #stale_rendered_templates_archives ⇒ Object
- #to_s ⇒ Object
- #validate ⇒ Object
- #vm_env ⇒ Object
Instance Method Details
#cloud_properties_hash ⇒ Object
42 43 44 45 46 47 48 49 |
# File 'lib/bosh/director/models/instance.rb', line 42 def cloud_properties_hash if cloud_properties.nil? return {} if spec.nil? || spec['vm_type'].nil? spec['vm_type']['cloud_properties'] || {} else JSON.parse(cloud_properties) end end |
#cloud_properties_hash=(hash) ⇒ Object
51 52 53 |
# File 'lib/bosh/director/models/instance.rb', line 51 def cloud_properties_hash=(hash) self.cloud_properties = JSON.dump(hash) end |
#credentials ⇒ Object
107 108 109 110 |
# File 'lib/bosh/director/models/instance.rb', line 107 def credentials return nil if credentials_json.nil? Yajl::Parser.parse(credentials_json) end |
#credentials=(spec) ⇒ Object
112 113 114 |
# File 'lib/bosh/director/models/instance.rb', line 112 def credentials=(spec) self.credentials_json = Yajl::Encoder.encode(spec) end |
#dns_record_names ⇒ Object
55 56 57 58 59 |
# File 'lib/bosh/director/models/instance.rb', line 55 def dns_record_names return nil if dns_records.nil? JSON.parse(dns_records) end |
#dns_record_names=(list) ⇒ Object
61 62 63 |
# File 'lib/bosh/director/models/instance.rb', line 61 def dns_record_names=(list) self.dns_records = JSON.dump(list) end |
#latest_rendered_templates_archive ⇒ Object
29 30 31 |
# File 'lib/bosh/director/models/instance.rb', line 29 def latest_rendered_templates_archive rendered_templates_archives_dataset.order(:created_at).last end |
#name ⇒ Object
65 66 67 |
# File 'lib/bosh/director/models/instance.rb', line 65 def name "#{self.job}/#{self.uuid}" end |
#persistent_disk ⇒ Object
18 19 20 21 |
# File 'lib/bosh/director/models/instance.rb', line 18 def persistent_disk # Currently we support only 1 persistent disk. self.persistent_disks.find { |disk| disk.active } end |
#persistent_disk_cid ⇒ Object
23 24 25 26 27 |
# File 'lib/bosh/director/models/instance.rb', line 23 def persistent_disk_cid disk = persistent_disk return disk.disk_cid if disk nil end |
#spec ⇒ Object
73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 |
# File 'lib/bosh/director/models/instance.rb', line 73 def spec return nil if spec_json.nil? result = Yajl::Parser.parse(spec_json) if result['resource_pool'].nil? result else if result['vm_type'].nil? result['vm_type'] = { 'name' => result['resource_pool']['name'], 'cloud_properties' => result['resource_pool']['cloud_properties'] } end if result['resource_pool']['stemcell'] && result['stemcell'].nil? result['stemcell'] = result['resource_pool']['stemcell'] result['stemcell']['alias'] = result['resource_pool']['name'] end result.delete('resource_pool') result end end |
#spec=(spec) ⇒ Object
98 99 100 |
# File 'lib/bosh/director/models/instance.rb', line 98 def spec=(spec) self.spec_json = Yajl::Encoder.encode(spec) end |
#stale_rendered_templates_archives ⇒ Object
33 34 35 36 37 38 39 40 |
# File 'lib/bosh/director/models/instance.rb', line 33 def stale_rendered_templates_archives stale_archives = rendered_templates_archives_dataset if latest = latest_rendered_templates_archive stale_archives.exclude(id: latest.id) else stale_archives end end |
#to_s ⇒ Object
69 70 71 |
# File 'lib/bosh/director/models/instance.rb', line 69 def to_s "#{self.job}/#{self.index} (#{self.uuid})" end |
#validate ⇒ Object
11 12 13 14 15 16 |
# File 'lib/bosh/director/models/instance.rb', line 11 def validate validates_presence [:deployment_id, :job, :index, :state] validates_unique [:deployment_id, :job, :index] validates_integer :index validates_includes %w(started stopped detached), :state end |
#vm_env ⇒ Object
102 103 104 105 |
# File 'lib/bosh/director/models/instance.rb', line 102 def vm_env return {} if spec.nil? spec['env'] || {} end |