foreman_snapshot_management 1.5.1 → 1.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: d57bbba1e33d99aefa82a4af43d69810abd02fee0bd56a971083a6d83950bf5f
4
- data.tar.gz: f79a6a83310c1b0ee3f05ea2204cded44d690df624773ad642e88a9a323f372a
3
+ metadata.gz: b7fe9653d419d1bbb857d758ce0bf7edb2f34a60344995ccc4ce420b9bc37c4f
4
+ data.tar.gz: 12b830b6f2a268d0d0a95a522dba69c5ca2a2583bb04803184249e997f479242
5
5
  SHA512:
6
- metadata.gz: 40e538d6c79a89036baa265408dbeecd99ce7fcb2c4cb9693e1bc92111001f592e8ea13d003028160b366ce2332702e0c51fedb2c07ec2a6ecbaab99622d5d91
7
- data.tar.gz: a1c2345211c2d5eb3a2a6d63c74ca952d74351e014ad0f3b1957afcf6a5ba8dc3d3b9ddac69bd52344eeee235676f732f654d7bebfb46d9b69a655b0c904297f
6
+ metadata.gz: 3926abe02b802ebafd9753441760f49b4ded0c1f10fdd4c56749830d7b25598756742bdc53956ed61e43e935c79b23c5c6fef06a4226a33f216bf1af9e793a53
7
+ data.tar.gz: 1d8935a1c0678ac93cba42099524b2fcb25482840fb4d1c2b6ea45623216086e279d7cef73aeeb80e3b452f06edfa99625c5dae4012ad9c61b80f0dfbc138f7f
data/README.md CHANGED
@@ -20,10 +20,202 @@ See [How_to_Install_a_Plugin](http://projects.theforeman.org/projects/foreman/wi
20
20
 
21
21
  | Foreman Version | Plugin Version |
22
22
  | --------------- | -------------- |
23
+ | 1.22 | >= 1.6.0 |
24
+ | 1.21 | >= 1.5.0 |
25
+ | 1.20 | >= 1.5.0 |
23
26
  | 1.19 | >= 1.5.0 |
24
27
  | 1.18 | >= 1.5.0 |
25
28
  | 1.17 | >= 1.5.0 |
26
29
 
30
+ ## Usage
31
+
32
+ You will get a new tab named "Snapshots" in the hosts page in Foreman.
33
+
34
+ Following rights are required to view snapshots:
35
+
36
+ - Snapshot Viewer
37
+ - Viewer
38
+
39
+ Following **additional** rights are required for creating, modifying, deleting and rollback:
40
+
41
+ - Snapshot Manger
42
+ - Site Manager
43
+
44
+ ## API usage examples
45
+
46
+ Documentation for the api v2 endpoints provided by this Plugin can be found at `https://<your.foreman.installation>/apidoc/v2/snapshots.html`.
47
+ Some examples using `curl` and `jq` are given here.
48
+
49
+ The api user requires the same rights as a normal one.
50
+
51
+ ### Environment
52
+
53
+ Environment variables used in this examples, edit to your needs.
54
+
55
+ ```bash
56
+ FOREMAN="foreman.example.lan" # fqdn or ip to foreman
57
+ AUTH="snapper:mysupersecretpassword123" # foreman user
58
+ HOST="vm001.example.lan" # the servers name or id
59
+ ```
60
+
61
+ ### List all snapshots
62
+
63
+ ```bash
64
+ curl -s -u "$AUTH" \
65
+ -H 'Accept: application/json' \
66
+ "https://${FOREMAN}/api/v2/hosts/${HOST}/snapshots" \
67
+ | jq
68
+ ```
69
+
70
+ ```json
71
+ {
72
+ "total": 2,
73
+ "subtotal": 2,
74
+ "page": 1,
75
+ "per_page": 30,
76
+ "search": null,
77
+ "sort": {
78
+ "by": null,
79
+ "order": null
80
+ },
81
+ "results": [
82
+ {
83
+ "description": "",
84
+ "id": "snapshot-646",
85
+ "name": "clean",
86
+ "created_at": "2018-10-08 08:07:30 UTC",
87
+ "parent_id": null,
88
+ "children_ids": [
89
+ "snapshot-658"
90
+ ]
91
+ },
92
+ {
93
+ "description": "test",
94
+ "id": "snapshot-658",
95
+ "name": "test",
96
+ "created_at": "2018-10-18 09:50:03 UTC",
97
+ "parent_id": null,
98
+ "children_ids": []
99
+ }
100
+ ]
101
+ }
102
+ ```
103
+
104
+ ### Show a snapshot
105
+
106
+ ```bash
107
+ curl -s -u "$AUTH" \
108
+ -H 'Accept: application/json' \
109
+ "https://${FOREMAN}/api/v2/hosts/${HOST}/snapshots/${SNAP_ID}" \
110
+ | jq
111
+ ```
112
+
113
+ ```json
114
+ {
115
+ "description": "test",
116
+ "id": "snapshot-658",
117
+ "name": "test",
118
+ "created_at": "2018-10-18 09:50:03 UTC",
119
+ "parent_id": null,
120
+ "children_ids": []
121
+ }
122
+ ```
123
+
124
+ ### Create a snapshot
125
+
126
+ ```bash
127
+ curl -s -u "$AUTH" \
128
+ -X POST \
129
+ -H 'Accept: application/json' \
130
+ -H 'Content-Type: application/json' \
131
+ --data "{ \"name\": \"${SNAP_NAME}\", \"description\": \"${DESCRIPTION}\" }" \
132
+ "https://${FOREMAN}/api/v2/hosts/${HOST}/snapshots" \
133
+ | jq
134
+ ```
135
+
136
+ ```json
137
+ {
138
+ "description": "A wonderful snapshot.",
139
+ "id": null,
140
+ "name": "wonderful",
141
+ "created_at": null,
142
+ "parent_id": null,
143
+ "children_ids": []
144
+ }
145
+ ```
146
+
147
+ ### Delete a snashot
148
+
149
+ ```bash
150
+ curl -s -u "$AUTH" \
151
+ -X DELETE \
152
+ -H 'Accept: application/json' \
153
+ -H 'Content-Type: application/json' \
154
+ "https://${FOREMAN}/api/v2/hosts/${HOST}/snapshots/${SNAP_ID}" \
155
+ | jq
156
+ ```
157
+
158
+ ```json
159
+ {
160
+ "description": "A wonderful snapshot.",
161
+ "id": null,
162
+ "name": "wonderful",
163
+ "created_at": "2018-10-19 07:03:37 UTC",
164
+ "parent_id": null,
165
+ "children_ids": []
166
+ }
167
+ ```
168
+
169
+ ### Update a snapshot
170
+
171
+ This updates only name and description, not the data.
172
+
173
+ ```bash
174
+ curl -s -u "$AUTH" \
175
+ -X PUT \
176
+ -H 'Accept: application/json' \
177
+ -H 'Content-Type: application/json' \
178
+ --data "{ \"name\": \"${SNAP_NAME}\", \"description\": \"${DESCRIPTION}\" }" \
179
+ "https://${FOREMAN}/api/v2/hosts/${HOST}/snapshots/${SNAP_ID}" \
180
+ | jq
181
+ ```
182
+
183
+ ```json
184
+ {
185
+ "description": "An exceptional snapshot.",
186
+ "id": "snapshot-666",
187
+ "name": "exceptional",
188
+ "created_at": "2018-10-19 07:11:24 UTC",
189
+ "parent_id": null,
190
+ "children_ids": []
191
+ }
192
+ ```
193
+
194
+ ### Revert a snapshot
195
+
196
+ This request will block until the snapshot is reverted. Make sure to check your timeouts.
197
+
198
+ ```bash
199
+ curl -s -u "$AUTH" \
200
+ --max-time 600 \
201
+ -X PUT \
202
+ -H 'Content-Type: application/json' \
203
+ -H 'Accept: application/json' \
204
+ "https://${FOREMAN}/api/v2/hosts/${HOST}/snapshots/${SNAP_ID}/revert" \
205
+ | jq
206
+ ```
207
+
208
+ ```json
209
+ {
210
+ "description": "test",
211
+ "id": "snapshot-658",
212
+ "name": "test",
213
+ "created_at": "2018-10-18 09:50:03 UTC",
214
+ "parent_id": null,
215
+ "children_ids": []
216
+ }
217
+ ```
218
+
27
219
  ## Contributing
28
220
 
29
221
  Fork and send a Pull Request. Thanks!
@@ -122,6 +122,7 @@ module ForemanSnapshotManagement
122
122
  end
123
123
  @host = Host.authorized("#{action_permission}_snapshots".to_sym, Host).friendly.find(host_id)
124
124
  return @host if @host
125
+
125
126
  not_found
126
127
  false
127
128
  end
@@ -7,7 +7,7 @@ module FogExtensions
7
7
  raise ArgumentError, 'snapshot is a required parameter' unless options.key? 'snapshot'
8
8
  raise ArgumentError, 'removeChildren is a required parameter' unless options.key? 'removeChildren'
9
9
 
10
- raise ArgumentError, 'snapshot is a required parameter' unless ::Fog::Compute::Vsphere::Snapshot === options['snapshot']
10
+ raise ArgumentError, 'snapshot is a required parameter' unless ::ForemanSnapshotManagement.fog_vsphere_namespace::Snapshot === options['snapshot']
11
11
 
12
12
  task = options['snapshot'].mo_ref.RemoveSnapshot_Task(
13
13
  removeChildren: options['removeChildren']
@@ -26,7 +26,7 @@ module FogExtensions
26
26
  raise ArgumentError, 'name is a required parameter' unless options.key? 'name'
27
27
  raise ArgumentError, 'description is a required parameter' unless options.key? 'description'
28
28
 
29
- raise ArgumentError, 'snapshot is a required parameter' unless ::Fog::Compute::Vsphere::Snapshot === options['snapshot']
29
+ raise ArgumentError, 'snapshot is a required parameter' unless ::ForemanSnapshotManagement.fog_vsphere_namespace::Snapshot === options['snapshot']
30
30
 
31
31
  options['snapshot'].mo_ref.RenameSnapshot(
32
32
  name: options['name'],
@@ -0,0 +1,75 @@
1
+ module ForemanSnapshotManagement
2
+ module ProxmoxExtensions
3
+ # Extend Proxmox's capabilities with snapshots.
4
+ def capabilities
5
+ super + [:snapshots]
6
+ end
7
+
8
+ # Create a Snapshot.
9
+ #
10
+ # This method creates a Snapshot with a given name and optional description.
11
+ def create_snapshot(uuid, name, description, include_ram = false)
12
+ server = node.servers.get uuid
13
+ snapshot = server.snapshots.create name
14
+ snapshot.description = description
15
+ snapshot.update
16
+ end
17
+
18
+ # Remove Snapshot
19
+ #
20
+ # This method removes a Snapshot from a given host.
21
+ def remove_snapshot(snapshot, remove_children)
22
+ task = client.remove_snapshot('snapshot' => snapshot, 'removeChildren' => remove_children)
23
+ task_successful?(task)
24
+ rescue RbVmomi::Fault => e
25
+ Foreman::Logging.exception('Error removing VMWare Snapshot', e)
26
+ raise ::Foreman::WrappedException.new(e, N_('Unable to remove VMWare Snapshot'))
27
+ end
28
+
29
+ # Revert Snapshot
30
+ #
31
+ # This method revert a host to a given Snapshot.
32
+ def revert_snapshot(snapshot)
33
+ task = client.revert_to_snapshot(snapshot)
34
+ task_successful?(task)
35
+ rescue RbVmomi::Fault => e
36
+ Foreman::Logging.exception('Error reverting VMWare Snapshot', e)
37
+ raise ::Foreman::WrappedException.new(e, N_('Unable to revert VMWare Snapshot'))
38
+ end
39
+
40
+ # Update Snapshot
41
+ #
42
+ # This method renames a Snapshot from a given host.
43
+ def update_snapshot(snapshot, name, description)
44
+ client.rename_snapshot('snapshot' => snapshot, 'name' => name, 'description' => description)
45
+ true
46
+ rescue RbVmomi::Fault => e
47
+ Foreman::Logging.exception('Error updating VMWare Snapshot', e)
48
+ raise ::Foreman::WrappedException.new(e, N_('Unable to update VMWare Snapshot'))
49
+ end
50
+
51
+ # Get Snapshot
52
+ #
53
+ # This methods returns a specific Snapshot for a given host.
54
+ def get_snapshot(server_id, snapshot_id)
55
+ snapshot = client.snapshots(server_id: server_id).get(snapshot_id)
56
+ # Workaround for https://github.com/fog/fog-vsphere/commit/d808255cd19c3d43d3227825f1e0d72d3f6ee6b9
57
+ # Remove, when fog-vshpere 1.11 lands in foreman
58
+ snapshot = snapshot.get_child(snapshot_id) while snapshot && snapshot.ref != snapshot_id
59
+ snapshot
60
+ end
61
+
62
+ # Get Snapshots
63
+ #
64
+ # This methods returns Snapshots from a given host.
65
+ def get_snapshots(server_id)
66
+ client.snapshots(server_id: server_id).all(recursive: true)
67
+ end
68
+
69
+ private
70
+
71
+ def task_successful?(task)
72
+ task['task_state'] == 'success' || task['state'] == 'success'
73
+ end
74
+ end
75
+ end
@@ -39,6 +39,7 @@ module ForemanSnapshotManagement
39
39
 
40
40
  def children
41
41
  return [] unless raw_snapshot
42
+
42
43
  child_snapshots = raw_snapshot.child_snapshots.flat_map do |child_snapshot|
43
44
  self.class.new_from_vmware(host, child_snapshot, parent: self)
44
45
  end
@@ -73,6 +74,7 @@ module ForemanSnapshotManagement
73
74
 
74
75
  def include_ram=(value)
75
76
  raise Exception('Cannot modify include_ram on existing snapshots.') if persisted?
77
+
76
78
  @include_ram = value
77
79
  end
78
80
 
@@ -83,12 +85,14 @@ module ForemanSnapshotManagement
83
85
 
84
86
  def host_id=(host_id)
85
87
  return if @host_id == host_id
88
+
86
89
  @host_id = host_id
87
90
  @host = nil
88
91
  end
89
92
 
90
93
  def host=(host)
91
94
  return if @host_id == host.id
95
+
92
96
  @host_id = host.id
93
97
  @host = host
94
98
  end
@@ -79,8 +79,8 @@ module ForemanSnapshotManagement
79
79
 
80
80
  # Load Fog extensions
81
81
  if Foreman::Model::Vmware.available?
82
- Fog::Compute::Vsphere::Real.send(:prepend, FogExtensions::Vsphere::Snapshots::Real)
83
- Fog::Compute::Vsphere::Mock.send(:prepend, FogExtensions::Vsphere::Snapshots::Mock)
82
+ ForemanSnapshotManagement.fog_vsphere_namespace::Real.send(:prepend, FogExtensions::Vsphere::Snapshots::Real)
83
+ ForemanSnapshotManagement.fog_vsphere_namespace::Mock.send(:prepend, FogExtensions::Vsphere::Snapshots::Mock)
84
84
  end
85
85
  rescue StandardError => e
86
86
  Rails.logger.warn "ForemanSnapshotManagement: skipping engine hook (#{e})"
@@ -99,4 +99,17 @@ module ForemanSnapshotManagement
99
99
  Foreman::Gettext::Support.add_text_domain locale_domain, locale_dir
100
100
  end
101
101
  end
102
+
103
+ def self.fog_vsphere_namespace
104
+ @fog_vsphere_namespace ||= calculate_fog_vsphere_namespace
105
+ end
106
+
107
+ def self.calculate_fog_vsphere_namespace
108
+ require 'fog/vsphere/version'
109
+ if Gem::Version.new(Fog::Vsphere::VERSION) >= Gem::Version.new('3.0.0')
110
+ Fog::Vsphere::Compute
111
+ else
112
+ Fog::Compute::Vsphere
113
+ end
114
+ end
102
115
  end
@@ -1,3 +1,3 @@
1
1
  module ForemanSnapshotManagement
2
- VERSION = '1.5.1'.freeze
2
+ VERSION = '1.6.0'.freeze
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: foreman_snapshot_management
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.5.1
4
+ version: 1.6.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - ATIX AG
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-10-18 00:00:00.000000000 Z
11
+ date: 2019-04-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: deface
@@ -69,6 +69,7 @@ files:
69
69
  - app/helpers/foreman_snapshot_management/snapshot_helper.rb
70
70
  - app/models/concerns/fog_extensions/vsphere/snapshots/mock.rb
71
71
  - app/models/concerns/fog_extensions/vsphere/snapshots/real.rb
72
+ - app/models/foreman_snapshot_management/proxmox_extensions.rb
72
73
  - app/models/foreman_snapshot_management/snapshot.rb
73
74
  - app/models/foreman_snapshot_management/vmware_extensions.rb
74
75
  - app/overrides/hosts/add_tab_to_host_overview.rb
@@ -115,7 +116,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
115
116
  version: '0'
116
117
  requirements: []
117
118
  rubyforge_project:
118
- rubygems_version: 2.7.6
119
+ rubygems_version: 2.7.6.2
119
120
  signing_key:
120
121
  specification_version: 4
121
122
  summary: Snapshot Management for VMware vSphere