Module: ForemanSnapshotManagement::VmwareExtensions
- Defined in:
- app/models/foreman_snapshot_management/vmware_extensions.rb
Instance Method Summary collapse
-
#capabilities ⇒ Object
Extend VMWare’s capabilities with snapshots.
-
#create_snapshot(uuid, name, description) ⇒ Object
Create a Snapshot.
-
#get_snapshot(server_id, snapshot_id) ⇒ Object
Get Snapshot.
-
#get_snapshots(server_id) ⇒ Object
Get Snapshots.
-
#remove_snapshot(snapshot, remove_children) ⇒ Object
Remove Snapshot.
-
#revert_snapshot(snapshot) ⇒ Object
Revert Snapshot.
-
#update_snapshot(snapshot, name, description) ⇒ Object
Update Snapshot.
Instance Method Details
#capabilities ⇒ Object
Extend VMWare’s capabilities with snapshots.
4 5 6 |
# File 'app/models/foreman_snapshot_management/vmware_extensions.rb', line 4 def capabilities super + [:snapshots] end |
#create_snapshot(uuid, name, description) ⇒ Object
Create a Snapshot.
This method creates a Snapshot with a given name and optional description.
11 12 13 14 15 16 17 |
# File 'app/models/foreman_snapshot_management/vmware_extensions.rb', line 11 def create_snapshot(uuid, name, description) task = client.vm_take_snapshot('instance_uuid' => uuid, 'name' => name, 'description' => description) task_successful?(task) rescue RbVmomi::Fault => e Foreman::Logging.exception('Error creating VMWare Snapshot', e) raise ::Foreman::WrappedException.new(e, N_('Unable to create VMWare Snapshot')) end |
#get_snapshot(server_id, snapshot_id) ⇒ Object
Get Snapshot
This methods returns a specific Snapshot for a given host.
55 56 57 58 59 60 61 62 63 |
# File 'app/models/foreman_snapshot_management/vmware_extensions.rb', line 55 def get_snapshot(server_id, snapshot_id) snapshot = client.snapshots(server_id: server_id).get(snapshot_id) # Workaround for https://github.com/fog/fog-vsphere/commit/d808255cd19c3d43d3227825f1e0d72d3f6ee6b9 # Remove, when fog-vshpere 1.11 lands in foreman while snapshot && snapshot.ref != snapshot_id snapshot = snapshot.get_child(snapshot_id) end snapshot end |
#get_snapshots(server_id) ⇒ Object
Get Snapshots
This methods returns Snapshots from a given host.
68 69 70 |
# File 'app/models/foreman_snapshot_management/vmware_extensions.rb', line 68 def get_snapshots(server_id) client.snapshots(server_id: server_id).all(recursive: true) end |
#remove_snapshot(snapshot, remove_children) ⇒ Object
Remove Snapshot
This method removes a Snapshot from a given host.
22 23 24 25 26 27 28 |
# File 'app/models/foreman_snapshot_management/vmware_extensions.rb', line 22 def remove_snapshot(snapshot, remove_children) task = client.remove_snapshot('snapshot' => snapshot, 'removeChildren' => remove_children) task_successful?(task) rescue RbVmomi::Fault => e Foreman::Logging.exception('Error removing VMWare Snapshot', e) raise ::Foreman::WrappedException.new(e, N_('Unable to remove VMWare Snapshot')) end |
#revert_snapshot(snapshot) ⇒ Object
Revert Snapshot
This method revert a host to a given Snapshot.
33 34 35 36 37 38 39 |
# File 'app/models/foreman_snapshot_management/vmware_extensions.rb', line 33 def revert_snapshot(snapshot) task = client.revert_to_snapshot(snapshot) task_successful?(task) rescue RbVmomi::Fault => e Foreman::Logging.exception('Error reverting VMWare Snapshot', e) raise ::Foreman::WrappedException.new(e, N_('Unable to revert VMWare Snapshot')) end |
#update_snapshot(snapshot, name, description) ⇒ Object
Update Snapshot
This method renames a Snapshot from a given host.
44 45 46 47 48 49 50 |
# File 'app/models/foreman_snapshot_management/vmware_extensions.rb', line 44 def update_snapshot(snapshot, name, description) client.rename_snapshot('snapshot' => snapshot, 'name' => name, 'description' => description) true rescue RbVmomi::Fault => e Foreman::Logging.exception('Error updating VMWare Snapshot', e) raise ::Foreman::WrappedException.new(e, N_('Unable to update VMWare Snapshot')) end |