foreman_snapshot_management 1.6.0 → 1.6.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (33) hide show
  1. checksums.yaml +4 -4
  2. data/Rakefile +2 -0
  3. data/app/controllers/api/v2/snapshots_controller.rb +3 -1
  4. data/app/controllers/concerns/foreman/controller/parameters/snapshot.rb +2 -0
  5. data/app/controllers/foreman_snapshot_management/snapshots_controller.rb +4 -2
  6. data/app/helpers/concerns/foreman_snapshot_management/hosts_helper_extension.rb +2 -0
  7. data/app/helpers/foreman_snapshot_management/snapshot_helper.rb +2 -0
  8. data/app/models/concerns/fog_extensions/vsphere/snapshots/mock.rb +2 -0
  9. data/app/models/concerns/fog_extensions/vsphere/snapshots/real.rb +2 -0
  10. data/app/models/foreman_snapshot_management/snapshot.rb +2 -0
  11. data/app/models/foreman_snapshot_management/vmware_extensions.rb +2 -0
  12. data/app/views/api/v2/snapshots/base.json.rabl +2 -0
  13. data/app/views/api/v2/snapshots/create.json.rabl +2 -0
  14. data/app/views/api/v2/snapshots/destroy.json.rabl +2 -0
  15. data/app/views/api/v2/snapshots/index.json.rabl +2 -0
  16. data/app/views/api/v2/snapshots/main.json.rabl +2 -0
  17. data/app/views/api/v2/snapshots/revert.json.rabl +2 -0
  18. data/app/views/api/v2/snapshots/show.json.rabl +2 -0
  19. data/app/views/api/v2/snapshots/update.json.rabl +2 -0
  20. data/app/views/{foreman_snapshot_management/hosts/_snapshots_tab_content.html.erb → hosts/_snapshots_tab.html.erb} +0 -0
  21. data/config/routes.rb +2 -0
  22. data/lib/foreman_snapshot_management.rb +2 -0
  23. data/lib/foreman_snapshot_management/engine.rb +8 -1
  24. data/lib/foreman_snapshot_management/version.rb +3 -1
  25. data/lib/tasks/foreman_snapshot_management_tasks.rake +31 -10
  26. data/locale/gemspec.rb +2 -0
  27. data/test/controllers/api/v2/snapshots_test.rb +2 -0
  28. data/test/controllers/foreman_snapshot_management/snapshots_controller_test.rb +2 -0
  29. data/test/test_plugin_helper.rb +2 -0
  30. metadata +9 -26
  31. data/app/models/foreman_snapshot_management/proxmox_extensions.rb +0 -75
  32. data/app/overrides/hosts/add_tab_to_host_overview.rb +0 -11
  33. data/app/views/foreman_snapshot_management/hosts/_snapshots_tab.html.erb +0 -3
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: b7fe9653d419d1bbb857d758ce0bf7edb2f34a60344995ccc4ce420b9bc37c4f
4
- data.tar.gz: 12b830b6f2a268d0d0a95a522dba69c5ca2a2583bb04803184249e997f479242
3
+ metadata.gz: f1f7ac4fa53eca310f5b7effafa4fca21cfdf0ce1f97981892165dfa9ebc1f19
4
+ data.tar.gz: 1440f1529c9d5c02428dac9371f1d02faca2ea6c95064e51c4efa900bed5126a
5
5
  SHA512:
6
- metadata.gz: 3926abe02b802ebafd9753441760f49b4ded0c1f10fdd4c56749830d7b25598756742bdc53956ed61e43e935c79b23c5c6fef06a4226a33f216bf1af9e793a53
7
- data.tar.gz: 1d8935a1c0678ac93cba42099524b2fcb25482840fb4d1c2b6ea45623216086e279d7cef73aeeb80e3b452f06edfa99625c5dae4012ad9c61b80f0dfbc138f7f
6
+ metadata.gz: 41df800a5a9d08c2dac58f5bc1319840dbdaa39ee1e4cf79ef71677645cc9d64cee3de0cf310d49e0d16ba9fc41a820ae42bf31f848398d040610b42ecd88649
7
+ data.tar.gz: ca5116f54a696fbe6062d05369747a02898a283276252ae118884b075ac01fe05a3864cbf583f2cfcf6b57801283e278ac4c0949f9bf0c5ae918262cf6a7468f
data/Rakefile CHANGED
@@ -1,4 +1,6 @@
1
1
  #!/usr/bin/env rake
2
+ # frozen_string_literal: true
3
+
2
4
  begin
3
5
  require 'bundler/setup'
4
6
  rescue LoadError
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Api
2
4
  module V2
3
5
  class SnapshotsController < V2::BaseController
@@ -83,7 +85,7 @@ module Api
83
85
  end
84
86
 
85
87
  def check_snapshot_capability
86
- not_found unless @nested_obj.compute_resource && @nested_obj.compute_resource.capabilities.include?(:snapshots)
88
+ not_found unless @nested_obj.compute_resource&.capabilities&.include?(:snapshots)
87
89
  end
88
90
 
89
91
  def action_permission
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Foreman::Controller::Parameters::Snapshot
2
4
  extend ActiveSupport::Concern
3
5
 
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module ForemanSnapshotManagement
2
4
  class SnapshotsController < ApplicationController
3
5
  include Foreman::Controller::ActionPermissionDsl
@@ -88,7 +90,7 @@ module ForemanSnapshotManagement
88
90
  end
89
91
  end
90
92
  error _('Error occurred while creating Snapshot for<br /><dl>%s</dl>') % errors.map { |e| "<dt>#{e[0]}</dt><dd>#{e[1]}</dd>" }.join('<br />') unless errors.empty?
91
- if snapshots_created > 0
93
+ if snapshots_created.positive?
92
94
  msg = _('Created %{snapshots} for %{num} %{hosts}') % {
93
95
  snapshots: n_('Snapshot', 'Snapshots', snapshots_created),
94
96
  num: snapshots_created,
@@ -169,7 +171,7 @@ module ForemanSnapshotManagement
169
171
  end
170
172
 
171
173
  def check_snapshot_capability
172
- not_found unless @host.compute_resource && @host.compute_resource.capabilities.include?(:snapshots)
174
+ not_found unless @host.compute_resource&.capabilities&.include?(:snapshots)
173
175
  end
174
176
 
175
177
  def enumerate_snapshots
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module ForemanSnapshotManagement
2
4
  module HostsHelperExtension
3
5
  def multiple_actions
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module ForemanSnapshotManagement
2
4
  module SnapshotHelper
3
5
  def foreman_snapshot_management_snapshot_path(snapshot)
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module FogExtensions
2
4
  module Vsphere
3
5
  module Snapshots
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module FogExtensions
2
4
  module Vsphere
3
5
  module Snapshots
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'date'
2
4
 
3
5
  module ForemanSnapshotManagement
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module ForemanSnapshotManagement
2
4
  module VmwareExtensions
3
5
  # Extend VMWare's capabilities with snapshots.
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  object @snapshot
2
4
 
3
5
  attributes :id, :name
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  object @snapshot
2
4
 
3
5
  extends 'api/v2/snapshots/show'
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  object @snapshot
2
4
 
3
5
  extends 'api/v2/snapshots/show'
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  collection @snapshots
2
4
 
3
5
  extends 'api/v2/snapshots/main'
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  object @snapshot
2
4
 
3
5
  extends 'api/v2/snapshots/base'
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  object @snapshot
2
4
 
3
5
  extends 'api/v2/snapshots/show'
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  object @snapshot
2
4
 
3
5
  extends 'api/v2/snapshots/main'
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  object @snapshot
2
4
 
3
5
  extends 'api/v2/snapshots/show'
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  Rails.application.routes.draw do
2
4
  namespace :api, :defaults => { :format => 'json' } do
3
5
  scope '(:apiv)', :module => :v2,
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'foreman_snapshot_management/engine'
2
4
 
3
5
  module ForemanSnapshotManagement
@@ -1,4 +1,4 @@
1
- require 'deface'
1
+ # frozen_string_literal: true
2
2
 
3
3
  module ForemanSnapshotManagement
4
4
  class Engine < ::Rails::Engine
@@ -51,6 +51,13 @@ module ForemanSnapshotManagement
51
51
  :destroy_snapshots,
52
52
  :revert_snapshots
53
53
  ]
54
+
55
+ extend_page('hosts/show') do |context|
56
+ context.add_pagelet :main_tabs,
57
+ :name => N_('Snapshots'),
58
+ :partial => 'hosts/snapshots_tab',
59
+ :onlyif => proc { |host| host&.compute_resource&.capable?(:snapshots) }
60
+ end
54
61
  end
55
62
  end
56
63
 
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module ForemanSnapshotManagement
2
- VERSION = '1.6.0'.freeze
4
+ VERSION = '1.6.1'
3
5
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  # Tests
2
4
  namespace :test do
3
5
  desc 'Test ForemanSnapshotManagement'
@@ -10,20 +12,39 @@ namespace :test do
10
12
  end
11
13
  end
12
14
 
13
- namespace :foreman_snapshot_management do
14
- task :rubocop do
15
- begin
16
- require 'rubocop/rake_task'
15
+ begin
16
+ require 'rubocop/rake_task'
17
+
18
+ test_patterns = ["#{ForemanSnapshotManagement::Engine.root}/app/**/*.rb",
19
+ "#{ForemanSnapshotManagement::Engine.root}/lib/**/*.rb",
20
+ "#{ForemanSnapshotManagement::Engine.root}/test/**/*.rb"]
21
+
22
+ namespace :foreman_snapshot_management do
23
+ task :rubocop do
17
24
  RuboCop::RakeTask.new(:rubocop_foreman_snapshot_management) do |task|
18
- task.patterns = ["#{ForemanSnapshotManagement::Engine.root}/app/**/*.rb",
19
- "#{ForemanSnapshotManagement::Engine.root}/lib/**/*.rb",
20
- "#{ForemanSnapshotManagement::Engine.root}/test/**/*.rb"]
25
+ task.patterns = test_patterns
21
26
  end
22
- rescue StandardError
23
- puts 'Rubocop not loaded.'
27
+
28
+ Rake::Task['rubocop_foreman_snapshot_management'].invoke
24
29
  end
25
30
 
26
- Rake::Task['rubocop_foreman_snapshot_management'].invoke
31
+ desc 'Runs Rubocop style checker with xml output for Jenkins'
32
+ RuboCop::RakeTask.new('rubocop:jenkins') do |task|
33
+ task.patterns = test_patterns
34
+ task.requires = ['rubocop/formatter/checkstyle_formatter']
35
+ task.formatters = ['RuboCop::Formatter::CheckstyleFormatter']
36
+ task.options = ['--no-color', '--out', 'rubocop.xml']
37
+ end
38
+ end
39
+ rescue LoadError
40
+ puts 'Rubocop not loaded.'
41
+ end
42
+
43
+ namespace :jenkins do
44
+ desc 'Test ForemanSnapshotManagement with XML output for jenkins'
45
+ task 'foreman_snapshot_management' do
46
+ Rake::Task['jenkins:setup:minitest'].invoke
47
+ Rake::Task['rake:test:foreman_snapshot_management'].invoke
27
48
  end
28
49
  end
29
50
 
@@ -1,2 +1,4 @@
1
+ # frozen_string_literal: true
2
+
1
3
  # Matches foreman_snapshot_management.gemspec
2
4
  _('Foreman-plugin to manage snapshots in a vSphere environment.')
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'test_helper'
2
4
 
3
5
  class Api::V2::SnapshotsControllerTest < ActionController::TestCase
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'test_helper'
2
4
 
3
5
  module ForemanSnapshotManagement
@@ -1,2 +1,4 @@
1
+ # frozen_string_literal: true
2
+
1
3
  # This calls the main test_helper in Foreman-core
2
4
  require 'test_helper'
metadata CHANGED
@@ -1,57 +1,43 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: foreman_snapshot_management
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.6.0
4
+ version: 1.6.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - ATIX AG
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-04-11 00:00:00.000000000 Z
11
+ date: 2019-09-17 00:00:00.000000000 Z
12
12
  dependencies:
13
- - !ruby/object:Gem::Dependency
14
- name: deface
15
- requirement: !ruby/object:Gem::Requirement
16
- requirements:
17
- - - ">="
18
- - !ruby/object:Gem::Version
19
- version: '0'
20
- type: :runtime
21
- prerelease: false
22
- version_requirements: !ruby/object:Gem::Requirement
23
- requirements:
24
- - - ">="
25
- - !ruby/object:Gem::Version
26
- version: '0'
27
13
  - !ruby/object:Gem::Dependency
28
14
  name: rdoc
29
15
  requirement: !ruby/object:Gem::Requirement
30
16
  requirements:
31
- - - ">="
17
+ - - "~>"
32
18
  - !ruby/object:Gem::Version
33
- version: '0'
19
+ version: '5.1'
34
20
  type: :development
35
21
  prerelease: false
36
22
  version_requirements: !ruby/object:Gem::Requirement
37
23
  requirements:
38
- - - ">="
24
+ - - "~>"
39
25
  - !ruby/object:Gem::Version
40
- version: '0'
26
+ version: '5.1'
41
27
  - !ruby/object:Gem::Dependency
42
28
  name: rubocop
43
29
  requirement: !ruby/object:Gem::Requirement
44
30
  requirements:
45
31
  - - '='
46
32
  - !ruby/object:Gem::Version
47
- version: 0.49.1
33
+ version: 0.54.0
48
34
  type: :development
49
35
  prerelease: false
50
36
  version_requirements: !ruby/object:Gem::Requirement
51
37
  requirements:
52
38
  - - '='
53
39
  - !ruby/object:Gem::Version
54
- version: 0.49.1
40
+ version: 0.54.0
55
41
  description: Foreman-plugin to manage snapshots in a vSphere environment.
56
42
  email:
57
43
  - info@atix.de
@@ -69,10 +55,8 @@ files:
69
55
  - app/helpers/foreman_snapshot_management/snapshot_helper.rb
70
56
  - app/models/concerns/fog_extensions/vsphere/snapshots/mock.rb
71
57
  - app/models/concerns/fog_extensions/vsphere/snapshots/real.rb
72
- - app/models/foreman_snapshot_management/proxmox_extensions.rb
73
58
  - app/models/foreman_snapshot_management/snapshot.rb
74
59
  - app/models/foreman_snapshot_management/vmware_extensions.rb
75
- - app/overrides/hosts/add_tab_to_host_overview.rb
76
60
  - app/views/api/v2/snapshots/base.json.rabl
77
61
  - app/views/api/v2/snapshots/create.json.rabl
78
62
  - app/views/api/v2/snapshots/destroy.json.rabl
@@ -81,10 +65,9 @@ files:
81
65
  - app/views/api/v2/snapshots/revert.json.rabl
82
66
  - app/views/api/v2/snapshots/show.json.rabl
83
67
  - app/views/api/v2/snapshots/update.json.rabl
84
- - app/views/foreman_snapshot_management/hosts/_snapshots_tab.html.erb
85
- - app/views/foreman_snapshot_management/hosts/_snapshots_tab_content.html.erb
86
68
  - app/views/foreman_snapshot_management/snapshots/_index.html.erb
87
69
  - app/views/foreman_snapshot_management/snapshots/select_multiple_host.html.erb
70
+ - app/views/hosts/_snapshots_tab.html.erb
88
71
  - config/routes.rb
89
72
  - lib/foreman_snapshot_management.rb
90
73
  - lib/foreman_snapshot_management/engine.rb
@@ -1,75 +0,0 @@
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
@@ -1,11 +0,0 @@
1
- # Add a Snapshots tab in the view of a host
2
- Deface::Override.new(virtual_path: 'hosts/show',
3
- name: 'add_host_snapshot_tab',
4
- insert_bottom: 'ul',
5
- partial: 'foreman_snapshot_management/hosts/snapshots_tab')
6
-
7
- # Load content of Snapshots tab
8
- Deface::Override.new(virtual_path: 'hosts/show',
9
- name: 'add_host_snapshots_tab_content',
10
- insert_bottom: 'div#myTabContent',
11
- partial: 'foreman_snapshot_management/hosts/snapshots_tab_content')
@@ -1,3 +0,0 @@
1
- <% if @host.compute_resource && @host.compute_resource.capabilities.include?(:snapshots) && authorized_for(:auth_object => @host, :permission => :view_snapshots) %>
2
- <li><a href='#snapshots' data-toggle='tab'><%= _('Snapshots') %></a></li>
3
- <% end %>