Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
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...
commit 3f482b824d6bd6aeccca1ff32f2a3f9357f4f3ab 1 parent 7c08e30
@ohadlevy ohadlevy authored
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
View
5 app/controllers/hostgroups_controller.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
View
8 app/controllers/hosts_controller.rb
@@ -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
View
59 app/controllers/hypervisors/guests_controller.rb
@@ -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
View
62 app/controllers/hypervisors_controller.rb
@@ -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
View
3  app/helpers/home_helper.rb
@@ -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],
View
15 app/helpers/hosts_and_hostgroups_helper.rb
@@ -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
View
3  app/helpers/hosts_helper.rb
@@ -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(
View
17 app/helpers/hypervisors/guests_helper.rb
@@ -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
View
2  app/helpers/hypervisors_helper.rb
@@ -1,2 +0,0 @@
-module HypervisorsHelper
-end
View
7 app/models/host.rb
@@ -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
View
33 app/models/hostgroup.rb
@@ -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
View
96 app/models/hypervisor.rb
@@ -1,96 +0,0 @@
-require 'hypervisor/guest'
-require 'timeout'
-
-class Hypervisor < ActiveRecord::Base
- attr_accessible :name, :uri, :kind
- attr_reader :host
-
- validates_presence_of :name, :uri, :kind
- validates_uniqueness_of :name, :uri
- before_save :try_to_connect
- default_scope :order => 'LOWER(hypervisors.name)'
-
- KINDS= %w{libvirt}
- MEMORY_SIZE = (1..8).to_a.map {|n| 2**n*1024*128}
- NETWORK_TYPES = %w{ bridge NAT }
-
- # interfaces is a special case with libvirt, as its supported only on platforms that run netcf
- def interfaces
- query {host.interfaces + host.networks}
- rescue => e
- logger.debug e.to_s
- []
- end
-
- def storage_pools
- query {host.storage_pools.map(&:name)}
- end
-
- def to_param
- name
- end
-
- def guests
- query { Virt::Guest.all }
- end
-
- def memory
- query {host.connection.node_get_info.memory }
- end
-
- def free_memory
- query {host.connection.node_free_memory } rescue nil
- end
-
- def cpus
- query {host.connection.node_get_info.cpus}
- end
-
- def connect
- return true if Rails.env == "test"
- logger.debug "trying to contact Hypervisor #{name}"
- Timeout::timeout(10, StandardError) { @host = Virt.connect(uri).host }
- rescue => e
- logger.warn "Failed to connect to hypervisor #{name} - #{e}"
- @host = nil
- raise
- end
-
- def disconnect
- return true if Rails.env == "test"
- logger.debug "Closing connection to #{name}"
- Timeout::timeout(10, StandardError) { host.disconnect } if host
- rescue => e
- logger.warn "Failed to disconnect from hypervisor #{name} - #{e}"
- false
- ensure
- @host = nil
- end
-
- private
- def try_to_connect
- connect
- rescue => e
- errors.add :base, "Unable to connect to Hypervisor: #{e}"
- false
- ensure
- disconnect
- end
-
- # we query the hypervisor
- # if the connection was open before, we leave it open
- # otherwise we open and close the connection
- def query
- return [] if Rails.env.test?
- c = connected?
- connect unless c
- result = yield if block_given?
- disconnect unless c
- result
- end
-
- def connected?
- @host and !@host.closed?
- end
-
-end
View
24 app/models/hypervisor/guest.rb
@@ -1,24 +0,0 @@
-module Virt
-
- class Guest
-
- def self.all
- Virt.connection.host.guests.values.flatten.sort
- end
-
- def self.find(name)
- Virt.connection.host.find_guest_by_name name
- rescue
- raise ActiveRecord::RecordNotFound
- end
-
- def to_param
- to_s
- end
-
- def as_json opts
- {to_s => {:memory => memory, :vcpu => vcpu, :running => running?, :volume => {:size => volume.size, :pool => volume.pool.name}}}
- end
-
- end
-end
View
1  app/models/orchestration.rb
@@ -15,7 +15,6 @@ def self.included(base)
include Orchestration::DHCP
include Orchestration::TFTP
include Orchestration::Puppetca
- include Orchestration::Libvirt
include Orchestration::Compute
include Orchestration::SSHProvision
View
120 app/models/orchestration/libvirt.rb
@@ -1,120 +0,0 @@
-module Orchestration::Libvirt
- def self.included(base)
- base.send :include, InstanceMethods
- base.class_eval do
- include Vm
- attr_accessor :powerup
- after_validation :initialize_libvirt, :queue_libvirt
- before_destroy :initialize_libvirt, :queue_libvirt_destroy
- end
- end
-
- module InstanceMethods
- def libvirt?
- hypervisor? and !memory.blank? and !vcpu.blank? and !storage_pool.blank? and \
- !interface.blank? and !network_type.blank? and !disk_size.blank?
- end
-
- protected
- def initialize_libvirt
- return unless libvirt?
- (@hypervisor = Hypervisor.find(hypervisor_id)).connect
- @guest = @hypervisor.host.create_guest({:name => name, :memory => memory, :arch => architecture.name,
- :vcpu => vcpu, :pool => storage_pool, :size => disk_size,
- :device => interface, :type => network_type})
- rescue => e
- failure "Failed to initialize the Libvirt connection: #{e}"
- end
-
- def queue_libvirt
- return unless libvirt? and errors.empty?
- new_record? ? queue_libvirt_create : queue_libvirt_update
- end
-
- def queue_libvirt_create
- queue.create(:name => "Libvirt: Settings up storage for instance #{self}", :priority => 1,
- :action => [self, :setLibvirtVolume])
- queue.create(:name => "Settings up libvirt instance #{self}", :priority => 2,
- :action => [self, :setLibvirt])
- queue.create(:name => "Settings up libvirt instance #{self} to start", :priority => 1000,
- :action => [self, :setPowerUp]) if powerup
- queue.create(:name => "Disconnect from hypervisor", :priority => 1001,
- :action => [self, :setDisconnectFromHypervisor])
- end
-
- def queue_libvirt_update
- end
-
- def queue_libvirt_destroy
- return unless errors.empty?
- return unless libvirt? or (hostgroup and hostgroup.hypervisor?)
- @hypervisor ||= hostgroup.hypervisor.connect
- @guest ||= Virt::Guest.find(name) rescue nil
- return if @guest.nil?
- queue.create(:name => "Removing libvirt instance #{self}", :priority => 1,
- :action => [self, :delLibvirt])
- queue.create(:name => "Removing libvirt Storage #{self}", :priority => 2,
- :action => [self, :delLibvirtVolume])
- end
-
- def setLibvirtVolume
- logger.info "Adding Libvirt instance storage for #{name}"
- @guest.volume.save
- rescue => e
- failure "Failed to create Storage for Libirt instance #{name}: #{e}"
- end
-
- def delLibvirtVolume
- logger.info "Removing Libvirt instance storage for #{name}"
- @guest.volume.destroy
- rescue => e
- failure "Failed to destroy Storage for Libirt instance #{name}: #{e}"
- end
-
- def setLibvirt
- logger.info "Adding Libvirt instance for #{name}"
- if @guest.save and !(self.mac = @guest.interface.mac).empty?
- # we can't ensure uniqueness of MAC using normal rails validations as the mac gets in a later step in the process
- # therefore we must validate its not used already in our db.
- normalize_addresses
- if (other_host = Host.find_by_mac(mac))
- delLibvirt
- return failure("MAC Address #{mac} is already used by #{other_host}")
- end
- true
- else
- failure "failed to save virtual machine"
- end
- rescue => e
- failure "Failed to create Libirt instance #{name}: #{e}"
- end
-
- def delLibvirt
- logger.info "Removing Libvirt instance for for #{name}"
- @guest.destroy
- rescue => e
- failure "Failed to destroy Libirt instance #{name}: #{e}"
- end
-
- def setPowerUp
- @guest.start
- rescue => e
- failure "Failed to start Guest: #{e}"
- end
-
- def delPowerUp
- @guest.stop
- rescue => e
- failure "Failed to stop Guest: #{e}"
- end
-
- def setDisconnectFromHypervisor
- @hypervisor.disconnect
- true
- end
-
- def delDisconnectFromHypervisor
- @hypervisor.connect
- end
- end
-end
View
27 app/models/vm.rb
@@ -1,27 +0,0 @@
-module Vm
- PROPERTIES = [ :hypervisor_id, :storage_pool, :interface, :memory, :vcpu, :disk_size, :network_type ]
-
- def self.included(base)
- base.send :include, InstanceMethods
- base.class_eval do
- Vm::PROPERTIES.each {|a| attr_accessor(a)}
- validates_presence_of :memory, :vcpu, :storage_pool, :disk_size, :network_type, :interface, :if => Proc.new{|h| h.hypervisor?}
- end
- end
-
- module InstanceMethods
- def hypervisor?
- !hypervisor_id.blank?
- end
-
- def hypervisor
- return nil unless hypervisor?
- Hypervisor.find(hypervisor_id)
- rescue ActiveRecord::RecordNotFound
- # we stored an invalid hypervisor
- self.hypervisor_id = nil
- end
-
- end
-
-end
View
26 app/views/common/_hypervisor.html.erb
@@ -1,26 +0,0 @@
-<%= fields_for item do |f| %>
- <div id="vm">
- <%= selectable_f f, :hypervisor_id, select_hypervisor(item),
- { :include_blank => "Select Hypervisor" },
- { :label => "Provision on", :help_inline => image_tag("spinner.gif", :id => "vm_indicator", :class => "hide"),
- :onchange => 'hypervisor_selected(this);', :'data-url' => method_path('hypervisor_selected') }
- %>
- <div id="vm_details">
- <% if @hypervisor ||= item.try(:hypervisor) -%>
-
- <%= selectable_f f, :memory, select_memory(item) %>
- <%= text_f f, :vcpu, :value => (item.vcpu || @guest.vcpu), :label => "VCPU" %>
- <%= text_f f, :disk_size, :value => volume_size(item), :help_inline => "in GB" %>
- <%= selectable_f f, :storage_pool, @hypervisor.storage_pools %>
- <%= selectable_f f, :network_type, Hypervisor::NETWORK_TYPES %>
- <% if (interfaces = @hypervisor.interfaces).empty? -%>
- <%= text_f f, :interface, :help_inline => "Physical Interface on #{@hypervisor}" %>
- <% else -%>
- <%= selectable_f f, :interface, interfaces %>
- <% end -%>
- <%= checkbox_f f, :powerup, :help_inline => "Power up this instance", :checked => true, :label => "Start?" if type == "host" %>
- <% end -%>
- </div>
- </div>
-<% end -%>
-
View
7 app/views/hostgroups/_form.html.erb
@@ -8,9 +8,6 @@
<% if SETTINGS[:unattended] -%>
<li><a href="#network" data-toggle="tab">Network</a></li>
<li><a href="#os" data-toggle="tab">Operating System</a></li>
- <% if !Hypervisor.first.nil? and authorized_for("Hypervisors::Guests", :create) -%>
- <li><a href="#virtual_machine" data-toggle="tab">Virtual Machine</a></li>
- <% end -%>
<% end -%>
<li><a href="#params" data-toggle="tab">Parameters</a></li>
</ul>
@@ -45,10 +42,6 @@
<%= password_f f, :root_pass, :label => "Root Password" %>
</div>
- <div class="tab-pane" id="virtual_machine">
- <%= render('common/hypervisor', :item => @hostgroup) %>
- </div>
-
<div class="tab-pane" id="params">
<%= render "common_parameters/parameters", { :f => f, :type => :group_parameters } %>
</div>
View
6 app/views/hosts/_form.html.erb
@@ -11,9 +11,6 @@
<li><a href="#network" data-toggle="tab">Network</a></li>
<li><a href="#os" data-toggle="tab">Operating System</a></li>
<% if authorized_for("Hypervisors::Guests", :create) -%>
- <% if @host.new_record? and !Hypervisor.first.nil? -%>
- <li id="libvirt_tab" <%= display? !(params[:host] && params[:host][:hypervisor_id].present?) %>><a href="#virtual_machine" data-toggle="tab">Virtual Machine</a></li>
- <% end -%>
<li id="compute_resource_tab" <%= display? !(@host.compute_resource_id || params[:host] && params[:host][:compute_resource_id].present?)%>><a href="#compute_resource" data-toggle="tab">Virtual Machine</a></li>
<% end -%>
<% end -%>
@@ -25,8 +22,7 @@
<div class="tab-pane active" id="primary">
<%= text_f f, :name, :class => "input-xlarge", :value => name_field(@host) %>
- <% libvirt = Hypervisor.first.nil? ? [] : [OpenStruct.new(:to_label => 'Libvirt')] -%>
- <%= select_f f, :compute_resource_id, libvirt + ComputeResource.my_compute_resources, :id, :to_label,
+ <%= select_f f, :compute_resource_id, ComputeResource.my_compute_resources, :id, :to_label,
{ :include_blank => 'Bare Metal' },
{:label => "Deploy on", :disabled => !@host.new_record?, :'data-url' => compute_resource_selected_hosts_path ,
:onchange => 'computeResourceSelected(this);'} if SETTINGS[:unattended] && @host.new_record? || @host.compute_resource_id %>
View
6 app/views/hosts/_unattended.html.erb
@@ -1,13 +1,9 @@
-<div class="tab-pane" id="virtual_machine">
- <%= render('common/hypervisor', :item => @host) if @host.new_record? and !Hypervisor.first.nil? and authorized_for("Hypervisors::Guests", :create) %>
-</div>
-
<div class="tab-pane" id="compute_resource">
<%= render 'compute', :compute_resource => @host.compute_resource if @host.compute_resource_id %>
</div>
<div class="tab-pane" id="network">
- <div id="mac_address" <%= display? (@hypervisor or @host.compute_resource_id)%> >
+ <div id="mac_address" <%= display? @host.compute_resource_id %> >
<%= text_f f, :mac, :label => "MAC", :help_inline => "MAC address for this host", :autocomplete => 'off' %>
</div>
View
7 app/views/hypervisors/_form.html.erb
@@ -1,7 +0,0 @@
-<%= form_for @hypervisor do |f| %>
- <%= base_errors_for @hypervisor %>
- <%= text_f f, :name %>
- <%= text_f f, :uri, :label => "URI", :class =>"input-xxlarge" %>
- <%= selectable_f f, :kind, Hypervisor::KINDS %>
- <%= submit_or_cancel f %>
-<% end %>
View
3  app/views/hypervisors/edit.html.erb
@@ -1,3 +0,0 @@
-<% title "Edit Hypervisor" %>
-
-<%= render :partial => 'form' %>
View
34 app/views/hypervisors/guests/index.html.erb
@@ -1,34 +0,0 @@
-<% title "Guests on #{@hypervisor}" %>
-
-<table class="table table-bordered">
- <th> Name </th>
- <th> CPUs </th>
- <th> Memory </th>
- <th> NIC </th>
- <th> Disk </th>
- <th> Storage </th>
- <th> Power </th>
- <th></th>
- <% @guests.each do |guest| -%>
- <tr>
- <td> <%= link_to_if_authorized guest, hash_for_hypervisor_guest_path(:hypervisor_id => @hypervisor, :id => guest) %> </td>
- <td> <%= guest.vcpu %> </td>
- <td> <%= number_to_human_size guest.memory*1024 %> </td>
- <td> <%= guest.interface.device rescue "N/A" %> </td>
- <td> <%= guest.volume.size %> GB </td>
- <td> <%= guest.volume.pool %> </td>
- <td <%= power_class(guest.running?)%>> <%= state(!guest.running?) %> </td>
- <td>
- <%= action_buttons(power_action(guest),
- display_delete_if_authorized(hash_for_hypervisor_guest_path(:hypervisor_id => @hypervisor, :id => guest))) %>
- </td>
- </tr>
- <% end -%>
-</table>
-
-<p>
-Total of <%= number_to_human_size @guests.delete_if{|g| !g.running?}.sum {|g| g.memory*1024} %> / <%= number_to_human_size @hypervisor.memory * 1024 %> memory used
-</p>
-
-<%= page_entries_info @guests %>
-<%= will_paginate @guests %>
View
55 app/views/hypervisors/guests/show.html.erb
@@ -1,55 +0,0 @@
-<% title @guest %>
-
-<div class='row'>
- <div class='span12'>
- <table class="table table-bordered table-striped">
- <tr><th colspan="2">Properties</th></tr>
- <tr>
- <td>Machine Type</td>
- <td><%= @guest.type %> / <%= @guest.machine %> / <%= @guest.arch %></td>
- </tr>
-
- <tr>
- <td>VCPU(s)</td>
- <td><%= @guest.vcpu %></td>
- </tr>
-
- <tr>
- <td>UUID</td>
- <td><%= @guest.uuid %></td>
- </tr>
- <tr>
- <td>Memory</td>
- <td><%= number_to_human_size @guest.memory*1024 %> <%= "(Allocated: #{number_to_human_size @guest.current_memory.to_i*1024})" if @guest.current_memory %></td>
- </tr>
-
- <% if @guest.interface -%>
- <tr>
- <td>Network</td>
- <td><%= @guest.interface.device || @guest.interface.network %></td>
- </tr>
- <tr>
- <td>NIC</td>
- <td><%= "#{@guest.interface.mac} (#{@guest.interface.model})" %></td>
- </tr>
- <% end -%>
- <tr>
- <td>Disk</td>
- <td><%= "#{@guest.volume.size}GB (#{@guest.volume.pool} storage pool)" %></td>
- </tr>
-
- <div>
- <td>Boot Device</td>
- <td><%= @guest.boot_device %></td>
- </div>
-
- <tr>
- <td>Running on</td>
- <td><%= link_to @hypervisor, hypervisor_path(@hypervisor) %></td>
- </tr>
- </table>
- </div>
-</div>
-<% title_actions display_link_if_authorized("Power#{state(@guest.running?)}", hash_for_power_hypervisor_guest_path(:hypervisor_id => @hypervisor, :id => @guest), :confirm => 'Are you sure?', :method => :put, :class=>'btn ' + (@guest.running? ? "danger" : "success")),
- display_delete_if_authorized(hash_for_hypervisor_guest_path(:hypervisor_id => @hypervisor, :id => @guest), :class=>'btn btn-danger'),
- display_link_if_authorized("Other Guests on this hypervisor", hash_for_hypervisor_guests_path(:hypervisor_id => @hypervisor), :class=>'btn') %>
View
29 app/views/hypervisors/index.html.erb
@@ -1,29 +0,0 @@
-<% title "Hypervisors" %>
-
-<% title_actions display_link_if_authorized("New Hypervisor", hash_for_new_hypervisor_path) %>
-
-<%= alert(:text => "Hypervisors are now <b>depreciated</b> in favour of #{link_to "Compute Resources", compute_resources_path}, please don't use it unless you have to", :class => 'alert-block')%>
-
-<table class="table table-bordered table-striped">
- <tr>
- <th>Name</th>
- <th>Uri</th>
- <th>Kind</th>
- <th></th>
- </tr>
- <% for hypervisor in @hypervisors %>
- <tr>
- <td><%=link_to_if_authorized h(hypervisor), hash_for_hypervisor_path(:id => hypervisor.name) %></td>
- <td><%=h hypervisor.uri %></td>
- <td><%=h hypervisor.kind %></td>
- <td>
- <%= action_buttons(
- display_link_if_authorized("Guests", hash_for_hypervisor_guests_path(:hypervisor_id => hypervisor.name), :class=>"btn btn-small"),
- display_link_if_authorized("Edit", hash_for_edit_hypervisor_path(:id => hypervisor.name)),
- display_delete_if_authorized(hash_for_hypervisor_path(:id => hypervisor.name), :confirm => "Delete #{hypervisor.name}?"))%>
- </td>
- </tr>
- <% end %>
-</table>
-<%= page_entries_info @hypervisors %>
-<%= will_paginate @hypervisors %>
View
3  app/views/hypervisors/new.html.erb
@@ -1,3 +0,0 @@
-<% title "New Hypervisor" %>
-
-<%= render :partial => 'form' %>
View
24 app/views/hypervisors/show.html.erb
@@ -1,24 +0,0 @@
-<% title "Hypervisor #{@hypervisor} details" %>
-
-<% fields = %w{cores cpus memory mhz model nodes sockets threads} -%>
-<div class='row'>
- <div class='span12'>
-<table class="table table-bordered table-striped">
- <tr><th colspan="2">Properties</th></tr>
- <% fields.each do |key| -%>
- <tr>
- <td> <%= key.titleize %></td>
- <td> <%= @host.connection.node_get_info.send(key.to_sym) rescue "N/A"%></td>
- </tr>
- <% end -%>
- <tr>
- <td> Available memory</td>
- <td> <%= number_to_human_size @host.connection.node_free_memory rescue "N/A" %> </td>
- </tr>
-</table>
- </div>
-</div>
-<br>
-
-<%= link_to "Guests", hypervisor_guests_path(@hypervisor), :class => "btn btn-primary" %>
-<%= link_to "Back", hypervisors_path, :class => "btn" %>
View
2  bundler.d/libvirt.rb
@@ -1,3 +1,3 @@
group :libvirt do
- gem "virt", ">= 0.2.1"
+ gem "ruby-libvirt", :require => 'libvirt'
end
View
4 config/boot.rb
@@ -16,8 +16,8 @@
begin
if SETTINGS[:unattended]
Bundler.setup(:unattended)
- Bundler.setup(:virt)
- require 'virt'
+ Bundler.setup(:libvirt)
+ require 'libvirt'
SETTINGS[:libvirt] = true
else
SETTINGS[:libvirt] = false
View
11 config/routes.rb
@@ -59,7 +59,6 @@
get 'puppetclass_parameters'
post 'process_hostgroup'
post 'hostgroup_or_environment_selected'
- post 'hypervisor_selected'
post 'architecture_selected'
post 'os_selected'
post 'domain_selected'
@@ -91,15 +90,6 @@
end
end
- resources :hypervisors do
- constraints(:id => /[^\/]+/) do
- resources :guests, :controller => "Hypervisors::Guests", :except => [:edit] do
- member do
- put 'power'
- end
- end
- end
- end if SETTINGS[:libvirt]
end
resources :settings, :only => [:index, :update] do
@@ -133,7 +123,6 @@
collection do
get 'auto_complete_search'
post 'environment_selected'
- post 'hypervisor_selected'
post 'architecture_selected'
post 'os_selected'
post 'domain_selected'
View
14 db/migrate/20110106132600_create_hypervisors.rb
@@ -1,14 +0,0 @@
-class CreateHypervisors < ActiveRecord::Migration
- def self.up
- create_table :hypervisors do |t|
- t.string :name
- t.string :uri
- t.string :kind
- t.timestamps
- end
- end
-
- def self.down
- drop_table :hypervisors
- end
-end
View
19 db/migrate/20121118120028_migrate_hypervisors_to_compute_resources.rb
@@ -0,0 +1,19 @@
+class MigrateHypervisorsToComputeResources < ActiveRecord::Migration
+ class Hypervisor < ActiveRecord::Base; end
+ def self.up
+ return unless Hypervisor.table_exists?
+
+ Hypervisor.all.each do |hypervisor|
+ host = Foreman::Model::Libvirt.find_by_url hypervisor.url
+ next if host # this host already exits
+ host.name = hypervisor.name
+ host.description = "Automaticilly migrated from hypervisor #{hypervisor.name} / #{hypervisor.url}"

Quick thing - "Automaticilly" should be "Automatically"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
+ say host.description
+ host.save
+ end
+ drop_table :hypervisors
+ end
+
+ def self.down
+ end
+end
View
14 lib/foreman/access_permissions.rb
@@ -108,20 +108,6 @@
map.permission :destroy_params, {:host_editing => [:destroy_params]}
end
- map.security_block :hypervisors do |map|
- map.permission :view_hypervisors, {:hypervisors => [:index, :show]}
- map.permission :create_hypervisors, {:hypervisors => [:new, :create]}
- map.permission :edit_hypervisors, {:hypervisors => [:edit, :update]}
- map.permission :destroy_hypervisors, {:hypervisors => [:destroy]}
- end
-
- map.security_block :hypervisors_guests do |map|
- map.permission :view_hypervisors_guests, {:hypervisors_guests => [:index, :show]}
- map.permission :create_hypervisors_guests, {:hypervisors_guests => [:create, :update]}
- map.permission :destroy_hypervisors_guests, {:hypervisors_guests => [:destroy]}
- map.permission :power_hypervisors_guests, {:hypervisors_guests => [:power]}
- end
-
map.security_block :media do |map|
map.permission :view_media, {:media => [:index, :show]}
map.permission :create_media, {:media => [:new, :create]}
View
56 lib/foreman/controller/host_details.rb
@@ -2,11 +2,6 @@
# Mainly used within the host and the hostgroup controllers
module Foreman::Controller::HostDetails
- def self.included(base)
- base.class_eval do
- after_filter :disconnect_from_hypervisor, :only => :hypervisor_selected
- end
- end
def architecture_selected
assign_parameter "architecture", "common/os_selection/"
@@ -30,33 +25,6 @@ def use_image_selected
render :json => {:use_image => item.use_image, :image_file => item.image_file}
end
- def hypervisor_selected
- hypervisor_id = params["hypervisor_id"].to_i
-
- # bare metal selected
- hypervisor_defaults and return if hypervisor_id == 0
-
- item = item_object
- if ((item.hypervisor_id = hypervisor_id) > 0) and (@hypervisor = Hypervisor.find(item.hypervisor_id))
- begin
- @hypervisor.connect
- rescue => e
- # we reset to default
- item.hypervisor_id = nil
- logger.warn e.to_s
- hypervisor_defaults(e.to_s) and return
- end
-
- @guest = @hypervisor.host.create_guest({ :name => (item.try(:name) || "new-#{Time.now.to_i}") })
-
- render :update do |page|
- controller.send(:update_hypervisor_details, item, page)
- end
- else
- head(:not_found)
- end
- end
-
private
def assign_parameter name, root = ""
if params["#{name}_id"].to_i > 0 and eval("@#{name} = #{name.capitalize}.find(params['#{name}_id'])")
@@ -78,28 +46,4 @@ def item_object
eval("@#{name} = #{name.capitalize}.new params[:#{name}]")
end
- def update_hypervisor_details item, page
- page['#virtual_machine'].html(render(:partial => "common/hypervisor", :locals => { :item => item }))
- page << "$('#host_mac').hide()"
- page << "$('#libvirt_tab').show()"
- end
-
- def disconnect_from_hypervisor
- @hypervisor.disconnect if @hypervisor
- end
-
- def hypervisor_defaults msg = nil
- @hypervisor = nil
- render :update do |page|
- item = controller.send(:item_object)
- page.alert(msg) if msg
- page['#virtual_machine'].html(render :partial => "common/hypervisor", :locals => { :item => item })
- # you can only select bare metal after you successfully selected a hypervisor before
- page << "if ($('#host_mac').length == 0) {"
- page << "$('#host_mac').show()" if controller_name == "hosts"
- page[:host_hypervisor_id].value = ""
- page << " }"
- end
- end
-
end
View
3  lib/foreman/default_data/loader.rb
@@ -60,7 +60,6 @@ def load(reset=false)
viewer.update_attribute :permissions, [:view_hosts,
:view_puppetclasses,
:view_hostgroups,
- :view_hypervisors,
:view_domains,
:view_operatingsystems,
:view_media,
@@ -100,8 +99,6 @@ def load(reset=false)
:view_globals,
:view_hostgroups,
:view_hosts,
- :view_hypervisors,
- :view_hypervisors_guests,
:view_smart_proxies_puppetca,
:view_smart_proxies_autosign,
:create_hosts,
View
32 public/javascripts/host_edit.js
@@ -8,26 +8,14 @@ function computeResourceSelected(item){
$("#model_name").show();
$('#compute_resource').empty();
$('#vm_details').empty();
- $("#libvirt_tab").hide();
- $('#host_hypervisor_id').val("");
$("#compute_resource_tab").hide();
update_capabilities('build');
- }else if(label == 'Libvirt'){
- $('#mac_address').hide();
- $('#bmc').hide();
- $("#model_name").show();
- $("#libvirt_tab").show();
- $("#compute_resource_tab").hide();
- $('#compute_resource').empty();
- $(item).children(":selected").val("");
- update_capabilities('build');
}
- else {
+ else
+ {
$('#mac_address').hide();
$('#bmc').hide();
- $("#libvirt_tab").hide();
$("#model_name").hide();
- $('#host_hypervisor_id').val("");
$("#compute_resource_tab").show();
$('#vm_details').empty();
var url = $(item).attr('data-url');
@@ -235,22 +223,6 @@ function hostgroup_changed(element) {
}
}
-
-function hypervisor_selected(element){
- var hypervisor_id = $(element).val();
- var url = $(element).attr('data-url');
- $('#vm_indicator').show();
- $.ajax({
- data:'hypervisor_id=' + hypervisor_id,
- type:'post',
- url: url,
- complete: function(){
- $('#vm_indicator').hide();
- if ($('#host_name').size() == 0 ) $('#host_powerup').parent().parent().remove();
- }
- })
-}
-
function subnet_selected(element){
var subnet_id = $(element).val();
if (subnet_id == '' || $('#host_ip').size() == 0) return;
View
5 test/fixtures/hypervisors.yml
@@ -1,5 +0,0 @@
-one:
- name: kvm
- uri: qemu:///system
- kind: libvirtd
- id: 123
View
8 test/functional/hypervisors/guests_controller_test.rb
@@ -1,8 +0,0 @@
-require 'test_helper'
-
-class Hypervisors::GuestsControllerTest < ActionController::TestCase
- # Replace this with your real tests.
- test "the truth" do
- assert true
- end
-end
View
78 test/functional/hypervisors_controller_test.rb
@@ -1,78 +0,0 @@
-require 'test_helper'
-
-class HypervisorsControllerTest < ActionController::TestCase
- def test_index
- get :index, {}, set_session_user
- assert_template 'index'
- end
-
- def test_index_json
- get :index, {:format => "json"}, set_session_user
- hypervisors = ActiveSupport::JSON.decode(@response.body)
- assert hypervisors.is_a?(Array)
- assert_response :success
- end
-
- def test_new
- get :new, {}, set_session_user
- assert_template 'new'
- end
-
- def test_create_invalid
- Hypervisor.any_instance.stubs(:valid?).returns(false)
- post :create, {}, set_session_user
- assert_template 'new'
- end
-
- def test_create_valid
- Hypervisor.any_instance.stubs(:valid?).returns(true)
- post :create, {}, set_session_user
- assert_redirected_to hypervisors_url
- end
-
- def test_create_valid_json
- Hypervisor.any_instance.stubs(:valid?).returns(true)
- post :create, {:format => "json"}, set_session_user
- hypervisor = ActiveSupport::JSON.decode(@response.body)
- assert_response :created
- end
-
- def test_edit
- get :edit, {:id => Hypervisor.first.name}, set_session_user
- assert_template 'edit'
- end
-
- def test_update_invalid
- Hypervisor.any_instance.stubs(:valid?).returns(false)
- put :update, {:id => Hypervisor.first.name}, set_session_user
- assert_template 'edit'
- end
-
- def test_update_valid
- Hypervisor.any_instance.stubs(:valid?).returns(true)
- put :update, {:id => Hypervisor.first.name}, set_session_user
- assert_redirected_to hypervisors_url
- end
-
- def test_update_valid_json
- Hypervisor.any_instance.stubs(:valid?).returns(true)
- put :update, {:format => "json", :id => Hypervisor.first.name}, set_session_user
- hypervisor = ActiveSupport::JSON.decode(@response.body)
- assert_response :ok
- end
-
- def test_destroy
- hypervisor = Hypervisor.first
- delete :destroy, {:id => hypervisor.name}, set_session_user
- assert_redirected_to hypervisors_url
- assert !Hypervisor.exists?(hypervisor.id)
- end
-
- def test_destroy_json
- hypervisor = Hypervisor.first
- delete :destroy, {:format => "json", :id => hypervisor.name}, set_session_user
- hypervisor = ActiveSupport::JSON.decode(@response.body)
- assert_response :ok
- assert !Hypervisor.exists?(hypervisor['id'])
- end
-end
View
4 test/unit/helpers/hypervisors/guests_helper_test.rb
@@ -1,4 +0,0 @@
-require 'test_helper'
-
-class Hypervisors::GuestsHelperTest < ActionView::TestCase
-end
View
9 test/unit/host_test.rb
@@ -360,15 +360,6 @@ def setup_user_and_host
assert_equal h.architecture, architectures(:sparc)
end
- test "hostgroup should set default vm values when none exists" do
- hg = hostgroups(:db)
- assert_not_nil hg.memory
- h = Host.new
- h.hostgroup = hg
- assert !h.valid?
- assert_equal hg.memory, h.memory
- end
-
test "host os attributes must be associated with the host os" do
h = hosts(:redhat)
h.managed = true
View
21 test/unit/hostgroup_test.rb
@@ -140,25 +140,4 @@ def setup_user operation
assert Hostgroup.find(second.id).is_root?
end
- test "vm_defaults_should_be_a_hash" do
- assert_kind_of Hash, hostgroups(:common).vm_defaults
- end
-
- test "hostgroup_should_have_vm_attributes" do
- assert !Vm::PROPERTIES.empty?
- hg = hostgroups(:common)
- Vm::PROPERTIES.each do |attr|
- assert_respond_to hg, attr
- end
- end
-
- test "vm attributes should be serialized" do
- hg = hostgroups(:common)
- hg.memory = 1024
- hg.interface = "br0"
- assert hg.save
- assert_equal 1024, Hostgroup.find(hg.id).memory
- assert_equal "br0", Hostgroup.find(hg.id).interface
- end
-
end
View
8 test/unit/hypervisor/guest_test.rb
@@ -1,8 +0,0 @@
-require 'test_helper'
-
-class Hypervisor::GuestTest < ActiveSupport::TestCase
- # Replace this with your real tests.
- test "the truth" do
- assert true
- end
-end
View
11 test/unit/hypervisor_test.rb
@@ -1,11 +0,0 @@
-require 'test_helper'
-
-class HypervisorTest < ActiveSupport::TestCase
- def test_should_be_valid
-
- name = "my kvm hypervisor"
- uri = "qemu+ssh://mysystem/system"
- kind = "libvirt"
- assert Hypervisor.new(:name => name, :uri => uri, :kind => kind).valid?
- end
-end
@skottler

Quick thing - "Automaticilly" should be "Automatically"

Please sign in to comment.
Something went wrong with that request. Please try again.