Revision 805358df
Added by Jason Montleon over 10 years ago
app/controllers/compute_resources_controller.rb | ||
---|---|---|
include Foreman::Controller::AutoCompleteSearch
|
||
AJAX_REQUESTS = %w{hardware_profile_selected cluster_selected}
|
||
before_filter :ajax_request, :only => AJAX_REQUESTS
|
||
before_filter :find_by_id, :only => [:show, :edit, :update, :destroy, :ping] + AJAX_REQUESTS
|
||
before_filter :find_by_id, :only => [:show, :edit, :update, :destroy, :ping, :associate] + AJAX_REQUESTS
|
||
|
||
def index
|
||
begin
|
||
... | ... | |
def edit
|
||
end
|
||
|
||
def associate
|
||
count = 0
|
||
if @compute_resource.respond_to?(:associated_host)
|
||
@compute_resource.vms.each do |vm|
|
||
if Host.where(:uuid => vm.identity).empty?
|
||
host = @compute_resource.associated_host(vm)
|
||
if host.present?
|
||
host.uuid = vm.identity
|
||
host.compute_resource_id = @compute_resource.id
|
||
host.save!(:validate => false) # don't want to trigger callbacks
|
||
count += 1
|
||
end
|
||
end
|
||
end
|
||
end
|
||
process_success(:success_msg => n_("%s VM associated to a host", "%s VMs associated to hosts", count) % count)
|
||
end
|
||
|
||
def update
|
||
params[:compute_resource].except!(:password) if params[:compute_resource][:password].blank?
|
||
if @compute_resource.update_attributes(params[:compute_resource])
|
app/controllers/compute_resources_vms_controller.rb | ||
---|---|---|
class ComputeResourcesVmsController < ApplicationController
|
||
before_filter :find_compute_resource
|
||
before_filter :find_vm, :only => [:show, :power, :pause, :console]
|
||
before_filter :find_vm, :only => [:show, :power, :pause, :console, :associate]
|
||
|
||
def index
|
||
@vms = @compute_resource.vms.all(params[:filters] || {})
|
||
... | ... | |
end
|
||
end
|
||
|
||
def associate
|
||
if Host.where(:uuid => @vm.identity).any?
|
||
process_error(:error_msg => _("VM already associated with a host"), :redirect => compute_resource_vm_path(:compute_resource_id => params[:compute_resource_id], :id => @vm.identity))
|
||
else
|
||
host = @compute_resource.associated_host(@vm) if @compute_resource.respond_to?(:associated_host)
|
||
if host.present?
|
||
host.uuid = @vm.identity
|
||
host.compute_resource_id = @compute_resource.id
|
||
host.save!(:validate => false) # don't want to trigger callbacks
|
||
process_success(:success_msg => _("VM associated to host #{host.name}"), :success_redirect => host_path(host))
|
||
else
|
||
process_error(:error_msg => _("No host found to associate this VM with"), :redirect => compute_resource_vm_path(:compute_resource_id => params[:compute_resource_id], :id => @vm.identity))
|
||
end
|
||
end
|
||
end
|
||
|
||
def show
|
||
respond_to do |format|
|
||
format.html
|
app/models/compute_resources/foreman/model/ec2.rb | ||
---|---|---|
false
|
||
end
|
||
|
||
def associated_host(vm)
|
||
Host.my_hosts.where(:ip => [vm.public_ip_address, vm.private_ip_address]).first
|
||
end
|
||
|
||
private
|
||
|
||
def client
|
app/models/compute_resources/foreman/model/libvirt.rb | ||
---|---|---|
client.nodes.first
|
||
end
|
||
|
||
def associated_host(vm)
|
||
Host.my_hosts.where(:mac => vm.mac).first
|
||
end
|
||
|
||
protected
|
||
|
||
def client
|
app/models/compute_resources/foreman/model/openstack.rb | ||
---|---|---|
vm.console.body.merge({'timestamp' => Time.now.utc})
|
||
end
|
||
|
||
def associated_host(vm)
|
||
Host.my_hosts.where(:ip => [vm.floating_ip_address, vm.private_ip_address]).first
|
||
end
|
||
|
||
private
|
||
|
||
def client
|
app/models/compute_resources/foreman/model/ovirt.rb | ||
---|---|---|
false
|
||
end
|
||
|
||
def associated_host(vm)
|
||
Host.my_hosts.where(:mac => vm.mac).first
|
||
end
|
||
|
||
protected
|
||
|
||
def bootstrap(args)
|
app/models/compute_resources/foreman/model/rackspace.rb | ||
---|---|---|
end
|
||
end
|
||
|
||
def associated_host(vm)
|
||
Host.my_hosts.where(:ip => [vm.public_ip_address, vm.private_ip_address]).first
|
||
end
|
||
|
||
private
|
||
|
||
def client
|
app/models/compute_resources/foreman/model/vmware.rb | ||
---|---|---|
attrs[:pubkey_hash] = key
|
||
end
|
||
|
||
def associated_host(vm)
|
||
Host.my_hosts.where(:mac => vm.mac).first
|
||
end
|
||
|
||
private
|
||
|
||
def dc
|
app/services/foreman/access_permissions.rb | ||
---|---|---|
:update_multiple_hostgroup, :update_multiple_parameters, :toggle_manage,
|
||
:select_multiple_organization, :update_multiple_organization,
|
||
:select_multiple_location, :update_multiple_location].push(*ajax_actions),
|
||
:compute_resources => cr_ajax_actions,
|
||
:compute_resources => [:associate].push(cr_ajax_actions),
|
||
:compute_resources_vms => [:associate],
|
||
:puppetclasses => pc_ajax_actions,
|
||
:subnets => subnets_ajax_actions,
|
||
:"api/v1/hosts" => [:update],
|
app/views/compute_resources/show.html.erb | ||
---|---|---|
<%= javascript "compute_resource" %>
|
||
<% title @compute_resource.name %>
|
||
|
||
<% title_actions link_to(_('Edit'), edit_compute_resource_path(@compute_resource), :class => "btn") %>
|
||
<% title_actions display_link_if_authorized(_("Associate VMs"), hash_for_associate_compute_resource_path(:compute_resource_id => @compute_resource), :title=> _("Associate VMs to Foreman hosts"), :method => :put, :class=>"btn"),
|
||
link_to(_('Edit'), edit_compute_resource_path(@compute_resource), :class => "btn") %>
|
||
|
||
<ul class="nav nav-tabs" data-tabs="tabs">
|
||
<li class="active"><a href="#primary" data-toggle="tab"><%= _("Compute Resource") %></a></li>
|
app/views/compute_resources_vms/show.html.erb | ||
---|---|---|
<% title_actions *available_actions(@vm),
|
||
show_console_action(@vm.ready?,
|
||
link_to_if_authorized(_("Console"), hash_for_console_compute_resource_vm_path, {:disabled => @vm.nil? || !@vm.ready?, :class => "btn btn-info"})),
|
||
display_link_if_authorized(_("Associate VM"), hash_for_associate_compute_resource_vm_path(:compute_resource_id => @compute_resource, :id => @vm.id), :title=> _("Associate VM to a Foreman host"), :method => :put, :class=>"btn"),
|
||
link_to(_("Back"), compute_resource_path(@compute_resource), :class=>'btn')
|
||
%>
|
config/routes.rb | ||
---|---|---|
post 'hardware_profile_selected'
|
||
post 'cluster_selected'
|
||
post 'ping'
|
||
put 'associate'
|
||
end
|
||
constraints(:id => /[^\/]+/) do
|
||
resources :vms, :controller => "compute_resources_vms" do
|
||
member do
|
||
put 'power'
|
||
put 'pause'
|
||
put 'associate'
|
||
get 'console'
|
||
end
|
||
end
|
Also available in: Unified diff
fixes #1923 - matches vms on a compute resource to hosts