Class: ForemanSnapshotManagement::Snapshot
- Inherits:
-
Object
- Object
- ForemanSnapshotManagement::Snapshot
- Extended by:
- ActiveModel::Callbacks, ActiveModel::Naming
- Includes:
- ActiveModel::Conversion, ActiveModel::Dirty, ActiveModel::ForbiddenAttributesProtection, ActiveModel::Model
- Defined in:
- app/models/foreman_snapshot_management/snapshot.rb
Instance Attribute Summary collapse
- #create_time ⇒ Object
-
#description ⇒ Object
Returns the value of attribute description.
-
#host_id ⇒ Object
Returns the value of attribute host_id.
-
#id ⇒ Object
Returns the value of attribute id.
-
#include_ram ⇒ Object
Returns the value of attribute include_ram.
-
#name ⇒ Object
Returns the value of attribute name.
-
#parent ⇒ Object
Returns the value of attribute parent.
-
#quiesce ⇒ Object
Returns the value of attribute quiesce.
-
#raw_snapshot ⇒ Object
Returns the value of attribute raw_snapshot.
-
#snapshot_mode ⇒ Object
Returns the value of attribute snapshot_mode.
Class Method Summary collapse
- .all_for_host(host) ⇒ Object
- .any? ⇒ Boolean
- .find_for_host(host, id) ⇒ Object
- .find_for_host_by_name(host, name) ⇒ Object
- .model_name ⇒ Object
- .new_for_host(host) ⇒ Object
Instance Method Summary collapse
- #assign_attributes(new_attributes) ⇒ Object
-
#create ⇒ Object
crud.
- #destroy ⇒ Object
- #formatted_create_time ⇒ Object
-
#host ⇒ Object
host accessors.
- #host=(host) ⇒ Object
- #inspect ⇒ Object
- #persisted? ⇒ Boolean
- #revert ⇒ Object
- #save ⇒ Object
- #to_s ⇒ Object
- #update(new_attributes) ⇒ Object
Instance Attribute Details
#create_time ⇒ Object
103 104 105 |
# File 'app/models/foreman_snapshot_management/snapshot.rb', line 103 def create_time raw_snapshot.try(:create_time) end |
#description ⇒ Object
Returns the value of attribute description.
17 18 19 |
# File 'app/models/foreman_snapshot_management/snapshot.rb', line 17 def description @description end |
#host_id ⇒ Object
Returns the value of attribute host_id.
17 18 19 |
# File 'app/models/foreman_snapshot_management/snapshot.rb', line 17 def host_id @host_id end |
#id ⇒ Object
Returns the value of attribute id.
15 16 17 |
# File 'app/models/foreman_snapshot_management/snapshot.rb', line 15 def id @id end |
#include_ram ⇒ Object
Returns the value of attribute include_ram.
17 18 19 |
# File 'app/models/foreman_snapshot_management/snapshot.rb', line 17 def include_ram @include_ram end |
#name ⇒ Object
Returns the value of attribute name.
17 18 19 |
# File 'app/models/foreman_snapshot_management/snapshot.rb', line 17 def name @name end |
#parent ⇒ Object
Returns the value of attribute parent.
15 16 17 |
# File 'app/models/foreman_snapshot_management/snapshot.rb', line 15 def parent @parent end |
#quiesce ⇒ Object
Returns the value of attribute quiesce.
15 16 17 |
# File 'app/models/foreman_snapshot_management/snapshot.rb', line 15 def quiesce @quiesce end |
#raw_snapshot ⇒ Object
Returns the value of attribute raw_snapshot.
15 16 17 |
# File 'app/models/foreman_snapshot_management/snapshot.rb', line 15 def raw_snapshot @raw_snapshot end |
#snapshot_mode ⇒ Object
Returns the value of attribute snapshot_mode.
15 16 17 |
# File 'app/models/foreman_snapshot_management/snapshot.rb', line 15 def snapshot_mode @snapshot_mode end |
Class Method Details
.all_for_host(host) ⇒ Object
40 41 42 |
# File 'app/models/foreman_snapshot_management/snapshot.rb', line 40 def self.all_for_host(host) host.compute_resource.get_snapshots(host) end |
.any? ⇒ Boolean
32 33 34 |
# File 'app/models/foreman_snapshot_management/snapshot.rb', line 32 def self.any? true end |
.find_for_host(host, id) ⇒ Object
44 45 46 |
# File 'app/models/foreman_snapshot_management/snapshot.rb', line 44 def self.find_for_host(host, id) host.compute_resource.get_snapshot(host, id) end |
.find_for_host_by_name(host, name) ⇒ Object
48 49 50 |
# File 'app/models/foreman_snapshot_management/snapshot.rb', line 48 def self.find_for_host_by_name(host, name) host.compute_resource.get_snapshot_by_name(host, name) end |
.model_name ⇒ Object
21 22 23 24 25 26 27 28 29 30 |
# File 'app/models/foreman_snapshot_management/snapshot.rb', line 21 def self.model_name Struct.new(:name, :klass, :singular, :plural, :element, :human, :collection, :param_key, :i18n_key, :route_key, :singular_route_key).new( 'ForemanSnapshotManagement::Snapshot', ForemanSnapshotManagement::Snapshot, 'foreman_snapshot_management_snapshot', 'foreman_snapshot_management_snapshots', 'snapshot', 'Snapshot', 'foreman_snapshot_management/snapshots', 'snapshot', :'foreman_snapshot_management/snapshot', 'foreman_snapshot_management_snapshots', 'foreman_snapshot_management_snapshot' ) end |
.new_for_host(host) ⇒ Object
36 37 38 |
# File 'app/models/foreman_snapshot_management/snapshot.rb', line 36 def self.new_for_host(host) host.compute_resource.new_snapshot(host) end |
Instance Method Details
#assign_attributes(new_attributes) ⇒ Object
107 108 109 110 111 112 113 |
# File 'app/models/foreman_snapshot_management/snapshot.rb', line 107 def assign_attributes(new_attributes) attributes = new_attributes.stringify_keys attributes = sanitize_for_mass_assignment(attributes) attributes.each do |k, v| public_send("#{k}=", v) end end |
#create ⇒ Object
crud
121 122 123 124 125 126 127 128 129 130 |
# File 'app/models/foreman_snapshot_management/snapshot.rb', line 121 def create run_callbacks(:create) do handle_snapshot_errors do host.audit_comment = "Create snapshot #{name}" host.save! host.compute_resource.create_snapshot(host, name, description, include_ram, quiesce) changes_applied end end end |
#destroy ⇒ Object
143 144 145 146 147 148 149 150 151 152 153 |
# File 'app/models/foreman_snapshot_management/snapshot.rb', line 143 def destroy run_callbacks(:destroy) do result = handle_snapshot_errors do host.audit_comment = "Destroy snapshot #{name}" host.save! result = host.compute_resource.remove_snapshot(raw_snapshot) end @id = nil result end end |
#formatted_create_time ⇒ Object
60 61 62 |
# File 'app/models/foreman_snapshot_management/snapshot.rb', line 60 def formatted_create_time create_time&.strftime('%F %H:%M') end |
#host ⇒ Object
host accessors
85 86 87 |
# File 'app/models/foreman_snapshot_management/snapshot.rb', line 85 def host @host ||= Host.find(@host_id) end |
#host=(host) ⇒ Object
96 97 98 99 100 101 |
# File 'app/models/foreman_snapshot_management/snapshot.rb', line 96 def host=(host) return if @host_id == host.id @host_id = host.id @host = host end |
#inspect ⇒ Object
52 53 54 |
# File 'app/models/foreman_snapshot_management/snapshot.rb', line 52 def inspect "#<#{self.class}:0x#{self.__id__.to_s(16)} name=#{name} id=#{id} description=#{description} host_id=#{host_id} parent=#{parent.try(:id)}>" end |
#persisted? ⇒ Boolean
64 65 66 |
# File 'app/models/foreman_snapshot_management/snapshot.rb', line 64 def persisted? @id.present? end |
#revert ⇒ Object
155 156 157 158 159 160 161 162 163 |
# File 'app/models/foreman_snapshot_management/snapshot.rb', line 155 def revert run_callbacks(:revert) do handle_snapshot_errors do host.audit_comment = "Revert snapshot #{name}" host.save! host.compute_resource.revert_snapshot(raw_snapshot) end end end |
#save ⇒ Object
132 133 134 135 136 137 138 139 140 141 |
# File 'app/models/foreman_snapshot_management/snapshot.rb', line 132 def save run_callbacks(:save) do handle_snapshot_errors do host.audit_comment = "Update snapshot #{name}" host.save! host.compute_resource.update_snapshot(raw_snapshot, name, description) changes_applied end end end |
#to_s ⇒ Object
56 57 58 |
# File 'app/models/foreman_snapshot_management/snapshot.rb', line 56 def to_s _('Snapshot') end |
#update(new_attributes) ⇒ Object
115 116 117 118 |
# File 'app/models/foreman_snapshot_management/snapshot.rb', line 115 def update(new_attributes) assign_attributes(new_attributes) save if changed? end |