Permalink
Browse files

fixes #1957 - remove old libvirt hypervisors code

Since foreman 1.0 libvirt hypervisors are now part of compute resources
this patch removes the old code and migrate any existing hypervisors to
be libvirt based compute resources.
  • Loading branch information...
1 parent 7c08e30 commit 3f482b824d6bd6aeccca1ff32f2a3f9357f4f3ab @ohadlevy ohadlevy committed Nov 19, 2012
Showing with 33 additions and 948 deletions.
  1. +0 −5 app/controllers/hostgroups_controller.rb
  2. +0 −8 app/controllers/hosts_controller.rb
  3. +0 −59 app/controllers/hypervisors/guests_controller.rb
  4. +0 −62 app/controllers/hypervisors_controller.rb
  5. +0 −3 app/helpers/home_helper.rb
  6. +0 −15 app/helpers/hosts_and_hostgroups_helper.rb
  7. +3 −0 app/helpers/hosts_helper.rb
  8. +0 −17 app/helpers/hypervisors/guests_helper.rb
  9. +0 −2 app/helpers/hypervisors_helper.rb
  10. +3 −4 app/models/host.rb
  11. +1 −32 app/models/hostgroup.rb
  12. +0 −96 app/models/hypervisor.rb
  13. +0 −24 app/models/hypervisor/guest.rb
  14. +0 −1 app/models/orchestration.rb
  15. +0 −120 app/models/orchestration/libvirt.rb
  16. +0 −27 app/models/vm.rb
  17. +0 −26 app/views/common/_hypervisor.html.erb
  18. +0 −7 app/views/hostgroups/_form.html.erb
  19. +1 −5 app/views/hosts/_form.html.erb
  20. +1 −5 app/views/hosts/_unattended.html.erb
  21. +0 −7 app/views/hypervisors/_form.html.erb
  22. +0 −3 app/views/hypervisors/edit.html.erb
  23. +0 −34 app/views/hypervisors/guests/index.html.erb
  24. +0 −55 app/views/hypervisors/guests/show.html.erb
  25. +0 −29 app/views/hypervisors/index.html.erb
  26. +0 −3 app/views/hypervisors/new.html.erb
  27. +0 −24 app/views/hypervisors/show.html.erb
  28. +1 −1 bundler.d/libvirt.rb
  29. +2 −2 config/boot.rb
  30. +0 −11 config/routes.rb
  31. +0 −14 db/migrate/20110106132600_create_hypervisors.rb
  32. +19 −0 db/migrate/20121118120028_migrate_hypervisors_to_compute_resources.rb
  33. +0 −14 lib/foreman/access_permissions.rb
  34. +0 −56 lib/foreman/controller/host_details.rb
  35. +0 −3 lib/foreman/default_data/loader.rb
  36. +2 −30 public/javascripts/host_edit.js
  37. +0 −5 test/fixtures/hypervisors.yml
  38. +0 −8 test/functional/hypervisors/guests_controller_test.rb
  39. +0 −78 test/functional/hypervisors_controller_test.rb
  40. +0 −4 test/unit/helpers/hypervisors/guests_helper_test.rb
  41. +0 −9 test/unit/host_test.rb
  42. +0 −21 test/unit/hostgroup_test.rb
  43. +0 −8 test/unit/hypervisor/guest_test.rb
  44. +0 −11 test/unit/hypervisor_test.rb
@@ -39,10 +39,6 @@ def clone
new.puppetclasses = @hostgroup.puppetclasses
# Clone any parameters as well
@hostgroup.group_parameters.each{|param| new.group_parameters << param.clone}
- if @hypervisor
- new.vm_defaults = @hostgroup.vm_defaults
- new.send(:deserialize_vm_attributes)
- end
new.name = ""
new.valid?
@hostgroup = new
@@ -113,7 +109,6 @@ def load_vars_for_ajax
@architecture = @hostgroup.architecture
@operatingsystem = @hostgroup.operatingsystem
@domain = @hostgroup.domain
- @hypervisor = @hostgroup.hypervisor
end
end
@@ -411,13 +411,6 @@ def process_hostgroup
page['#puppet_klasses'].html(render(:partial => 'puppetclasses/class_selection', :locals => {:obj => @host})) if @environment
if SETTINGS[:unattended]
- if !@host.compute_resource_id and (@hypervisor = @hostgroup.hypervisor)
- @hypervisor.connect
- # we are in a view context
- controller.send(:update_hypervisor_details, @host, page)
- @hypervisor.disconnect
- end
-
if @architecture
page['#os_select'].html(render(:partial => 'common/os_selection/architecture', :locals => {:item => @host}))
page['#*[id*=architecture_id]'].val(@architecture.id)
@@ -474,7 +467,6 @@ def load_vars_for_ajax
@domain = @host.domain
@operatingsystem = @host.operatingsystem
@medium = @host.medium
- @hypervisor = @host.hypervisor if @host.respond_to?(:hypervisor)
if @host.compute_resource_id && params[:host] && params[:host][:compute_attributes]
@host.compute_attributes = params[:host][:compute_attributes]
end
@@ -1,59 +0,0 @@
-require 'hypervisor/guest'
-
-class Hypervisors::GuestsController < ApplicationController
- before_filter :find_hypervisor
- before_filter :find_guest, :only => [:show, :power, :destroy]
- after_filter :disconnect_from_hypervisor
-
- def index
- @guests = @hypervisor.guests.paginate :page => params[:page]
- respond_to do |format|
- format.html
- format.json { render :json => @guests }
- end
- end
-
- def show
- respond_to do |format|
- format.html
- format.json { render :json => @guest }
- end
- end
-
- def power
- action = @guest.running? ? :stop : :start
-
- if (@guest.send(action) rescue false)
- state = @guest.running? ? "running" : "stopped"
- notice "#{@guest.name} is now #{state}"
- redirect_to hypervisor_guests_path(params[:hypervisor_id])
- else
- error "failed to #{action} #{@guest.name}"
- redirect_to :back
- end
- end
-
- def destroy
- if @guest.volume.destroy and @guest.destroy
- process_success({:success_redirect => hypervisor_guests_path(@hypervisor)})
- else
- process_error({:redirect => hypervisor_guests_path(@hypervisor)})
- end
- end
-
- private
-
- def find_hypervisor
- @hypervisor = Hypervisor.find_by_name(params[:hypervisor_id])
- @hypervisor.connect if @hypervisor
- end
-
- def disconnect_from_hypervisor
- @hypervisor.disconnect if @hypervisor
- end
-
- def find_guest
- @guest = Virt::Guest.find(params[:id])
- end
-
-end
@@ -1,62 +0,0 @@
-class HypervisorsController < ApplicationController
- before_filter :find_by_name, :only => [:show, :edit, :update, :destroy]
- before_filter :connect_to_hypervisor, :only => :show
- after_filter :disconnect_from_hypervisor, :only => :show
-
- def index
- respond_to do |format|
- format.html {@hypervisors = Hypervisor.paginate :page => params[:page]}
- format.json { render :json => Hypervisor.all }
- end
- end
-
- def new
- @hypervisor = Hypervisor.new
- end
-
- def show
- respond_to do |format|
- format.html {}
- format.json { render :json => @hypervisor }
- end
- end
-
- def create
- @hypervisor = Hypervisor.new(params[:hypervisor])
- if @hypervisor.save
- process_success
- else
- process_error
- end
- end
-
- def edit
- end
-
- def update
- if @hypervisor.update_attributes(params[:hypervisor])
- process_success
- else
- process_error
- end
- end
-
- def destroy
- if @hypervisor.destroy
- process_success
- else
- process_error
- end
- end
-
- private
-
- def connect_to_hypervisor
- @host = @hypervisor.connect
- end
-
- def disconnect_from_hypervisor
- @hypervisor.disconnect
- end
-
-end
@@ -16,12 +16,9 @@ def setting_options
if SETTINGS[:unattended]
choices += [
- [:divider],
['Compute Resources', :compute_resources]
]
- choices += [ ['Hypervisors', :hypervisors ] ] if SETTINGS[:libvirt]
-
choices += [
[:divider],
['Architectures', :architectures],
@@ -28,21 +28,6 @@ def parent_classes obj
[]
end
- def select_hypervisor item
- options_for_select Hypervisor.all.map{|h| [h.name, h.id]}, item.try(:hypervisor_id).try(:to_i)
- end
-
- def select_memory item = nil
- memory = item.try(:memory) if item
- memory ||= @guest.memory if @guest
- options_for_select Hypervisor::MEMORY_SIZE.map {|mem| [number_to_human_size(mem*1024), mem]}, memory.to_i
- end
-
- def volume_size item
- return item.disk_size if item.try(:disk_size)
- return @guest.volume.size if @guest
- end
-
def accessible_domains
(User.current.domains.any? and !User.current.admin?) ? User.current.domains : Domain.all
end
@@ -203,6 +203,9 @@ def possible_images cr, arch = nil, os = nil
cr.images.where(:architecture_id => arch, :operatingsystem_id => os)
end
+ def state s
+ s ? " Off" : " On"
+ end
def host_title_actions(host, vm)
title_actions(
@@ -1,17 +0,0 @@
-module Hypervisors::GuestsHelper
-
- def state s
- s ? " Off" : " On"
- end
-
- def power_class s
- "class='label #{s ? "label-success" : ""}'"
- end
-
- def power_action guest
- opts = hash_for_power_hypervisor_guest_path(:hypervisor_id => @hypervisor, :id => guest)
- html = guest.running? ? { :confirm => 'Are you sure?', :class => "btn btn-small btn-danger" } : { :class => "btn btn-small btn-info" }
-
- display_link_if_authorized "Power#{state(guest.running?)}" , opts, html.merge(:method => :put)
- end
-end
@@ -1,2 +0,0 @@
-module HypervisorsHelper
-end
View
@@ -150,15 +150,15 @@ class Jail < ::Safemode::Jail
include HostTemplateHelpers
validates_uniqueness_of :ip, :if => Proc.new {|host| host.require_ip_validation?}
- validates_uniqueness_of :mac, :unless => Proc.new { |host| host.hypervisor? or host.compute? or !host.managed }
+ validates_uniqueness_of :mac, :unless => Proc.new { |host| host.compute? or !host.managed }
validates_uniqueness_of :sp_mac, :allow_nil => true, :allow_blank => true
validates_uniqueness_of :sp_name, :sp_ip, :allow_blank => true, :allow_nil => true
validates_presence_of :architecture_id, :operatingsystem_id, :if => Proc.new {|host| host.managed}
validates_presence_of :domain_id, :if => Proc.new {|host| host.managed}
- validates_presence_of :mac, :unless => Proc.new { |host| host.hypervisor? or host.compute? or !host.managed }
+ validates_presence_of :mac, :unless => Proc.new { |host| host.compute? or !host.managed }
validates_length_of :root_pass, :minimum => 8,:too_short => 'should be 8 characters or more'
- validates_format_of :mac, :with => Net::Validations::MAC_REGEXP, :unless => Proc.new { |host| host.hypervisor_id or host.compute? or !host.managed }
+ validates_format_of :mac, :with => Net::Validations::MAC_REGEXP, :unless => Proc.new { |host| host.compute? or !host.managed }
validates_format_of :ip, :with => Net::Validations::IP_REGEXP, :if => Proc.new { |host| host.require_ip_validation? }
validates_presence_of :ptable_id, :message => "cant be blank unless a custom partition has been defined",
:if => Proc.new { |host| host.managed and host.disk.empty? and not defined?(Rake) and capabilities.include?(:build) }
@@ -602,7 +602,6 @@ def set_hostgroup_defaults
assign_hostgroup_attributes(%w{environment domain puppet_proxy puppet_ca_proxy})
if SETTINGS[:unattended] and (new_record? or managed?)
assign_hostgroup_attributes(%w{operatingsystem medium architecture ptable subnet})
- assign_hostgroup_attributes(Vm::PROPERTIES) if hostgroup.hypervisor? and not compute_resource_id
end
end
@@ -2,7 +2,6 @@ class Hostgroup < ActiveRecord::Base
has_ancestry :orphan_strategy => :rootify
include Authorization
include HostCommon
- include Vm
has_many :hostgroup_classes, :dependent => :destroy
has_many :puppetclasses, :through => :hostgroup_classes
has_and_belongs_to_many :users, :join_table => "user_hostgroups"
@@ -14,9 +13,7 @@ class Hostgroup < ActiveRecord::Base
before_destroy EnsureNotUsedBy.new(:hosts)
has_many :config_templates, :through => :template_combinations
has_many :template_combinations
- before_save :serialize_vm_attributes
before_save :remove_duplicated_nested_class
- after_find :deserialize_vm_attributes
alias_attribute :os, :operatingsystem
alias_attribute :label, :to_label
@@ -71,7 +68,7 @@ def to_param
end
def as_json(options={})
- super({:only => [:name, :subnet_id, :operatingsystem_id, :domain_id, :environment_id, :id, :ancestry], :methods => [:label, :parameters, :puppetclass_ids].concat(Vm::PROPERTIES)})
+ super({:only => [:name, :subnet_id, :operatingsystem_id, :domain_id, :environment_id, :id, :ancestry], :methods => [:label, :parameters, :puppetclass_ids]})
end
def hostgroup
@@ -115,18 +112,6 @@ def params
parameters
end
- def vm_defaults
- YAML.load(read_attribute(:vm_defaults))
- rescue
- {}
- end
-
- def vm_defaults=(v={})
- raise "defaults must be a hash" unless v.is_a?(Hash)
- v.delete_if{|attr, value| not Vm::PROPERTIES.include?(attr.to_sym)}
- write_attribute :vm_defaults, v.to_yaml
- end
-
# no need to store anything in the db if the password is our default
def root_pass
read_attribute(:root_pass) || nested_root_pw
@@ -141,22 +126,6 @@ def nested_root_pw
nil
end
- def serialize_vm_attributes
- hash = {}
- Vm::PROPERTIES.each do |attr|
- value = self.send(attr)
- hash[attr.to_s] = value if value
- end
- self.vm_defaults = hash
- end
-
- def deserialize_vm_attributes
- hash = vm_defaults
- Vm::PROPERTIES.each do |attr|
- eval("@#{attr} = hash[attr.to_s]") if hash.has_key?(attr.to_s)
- end
- end
-
def remove_duplicated_nested_class
self.puppetclasses -= ancestors.map(&:puppetclasses).flatten
end
Oops, something went wrong.

0 comments on commit 3f482b8

Please sign in to comment.