[Ovirt-devel] [PATCH] Make cobbler profile choice optional.
Scott Seago
sseago at redhat.com
Wed Aug 20 21:43:52 UTC 2008
new VM page allows choice of any cobbler profile, or PXE (pxe boot without managing provisioning), or HD boot.
renamed cobbler_profile VM field 'provisioning', and store field as "cobbler:profile:$profilename".
This allows for cobbler image support, and possibly other provisioning schemes without rewriting the VM mode
Signed-off-by: Scott Seago <sseago at redhat.com>
---
wui/src/app/controllers/vm_controller.rb | 11 ++++-
wui/src/app/models/vm.rb | 46 ++++++++++++++++++++--
wui/src/app/views/vm/_form.rhtml | 2 +-
wui/src/app/views/vm/show.rhtml | 4 +-
wui/src/db/migrate/015_rename_cobbler_profile.rb | 28 +++++++++++++
wui/src/task-omatic/task_vm.rb | 22 +++++++----
6 files changed, 95 insertions(+), 18 deletions(-)
create mode 100644 wui/src/db/migrate/015_rename_cobbler_profile.rb
diff --git a/wui/src/app/controllers/vm_controller.rb b/wui/src/app/controllers/vm_controller.rb
index 81c3d3f..eae8c2e 100644
--- a/wui/src/app/controllers/vm_controller.rb
+++ b/wui/src/app/controllers/vm_controller.rb
@@ -223,7 +223,14 @@ class VmController < ApplicationController
@perm_obj = @vm.vm_resource_pool
@redir_controller = 'resources'
@current_pool_id=@perm_obj.id
- @cobbler_profiles = Cobbler::Profile.find.collect {|profile| profile.name }
+ @provisioning_options = [[Vm::PXE_OPTION_LABEL, Vm::PXE_OPTION_VALUE],
+ [Vm::HD_OPTION_LABEL, Vm::HD_OPTION_VALUE]]
+ # FIXME add cobbler images too
+ @provisioning_options += Cobbler::Profile.find.collect do |profile|
+ [profile.name + Vm::COBBLER_PROFILE_SUFFIX,
+ Vm::COBBLER_PREFIX + Vm::PROVISIONING_DELIMITER +
+ Vm::PROFILE_PREFIX + Vm::PROVISIONING_DELIMITER + profile.name]
+ end
end
def pre_create
params[:vm][:state] = Vm::STATE_PENDING
@@ -235,8 +242,6 @@ class VmController < ApplicationController
vm_resource_pool.create_with_parent(hardware_pool)
params[:vm][:vm_resource_pool_id] = vm_resource_pool.id
end
- #set boot device to network for first boot (install)
- params[:vm][:boot_device] = Vm::BOOT_DEV_NETWORK unless params[:vm][:boot_device]
@vm = Vm.new(params[:vm])
@perm_obj = @vm.vm_resource_pool
@redir_controller = 'resources'
diff --git a/wui/src/app/models/vm.rb b/wui/src/app/models/vm.rb
index 9ac24d9..80c7efb 100644
--- a/wui/src/app/models/vm.rb
+++ b/wui/src/app/models/vm.rb
@@ -34,10 +34,22 @@ class Vm < ActiveRecord::Base
acts_as_xapian :texts => [ :uuid, :description, :vnic_mac_addr, :state ],
:terms => [ [ :search_users, 'U', "search_users" ] ]
- BOOT_DEV_HD = "hd"
- BOOT_DEV_NETWORK = "network"
- BOOT_DEV_CDROM = "cdrom"
- BOOT_DEV_FIELDS = [ BOOT_DEV_HD, BOOT_DEV_NETWORK, BOOT_DEV_CDROM ]
+ BOOT_DEV_HD = "hd"
+ BOOT_DEV_NETWORK = "network"
+ BOOT_DEV_CDROM = "cdrom"
+ BOOT_DEV_FIELDS = [ BOOT_DEV_HD, BOOT_DEV_NETWORK, BOOT_DEV_CDROM ]
+
+ PROVISIONING_DELIMITER = ":"
+ COBBLER_PREFIX = "cobbler"
+ PROFILE_PREFIX = "profile"
+ IMAGE_PREFIX = "image"
+ COBBLER_PROFILE_SUFFIX = " (Cobbler Profile)"
+ COBBLER_IMAGE_SUFFIX = " (Cobbler Profile)"
+
+ PXE_OPTION_LABEL = "PXE Boot"
+ PXE_OPTION_VALUE = "pxe"
+ HD_OPTION_LABEL = "Boot from HD"
+ HD_OPTION_VALUE = "hd"
NEEDS_RESTART_FIELDS = [:uuid,
:num_vcpus_allocated,
@@ -121,6 +133,32 @@ class Vm < ActiveRecord::Base
self[:memory_used]=(mb_to_kb(mem))
end
+ def provisioning_and_boot_settings=(settings)
+ if settings==PXE_OPTION_VALUE
+ self[:boot_device]= BOOT_DEV_NETWORK
+ self[:provisioning]= nil
+ elsif settings==HD_OPTION_VALUE
+ self[:boot_device]= BOOT_DEV_HD
+ self[:provisioning]= nil
+ else
+ self[:boot_device]= BOOT_DEV_NETWORK
+ self[:provisioning]= settings
+ end
+ end
+ def provisioning_and_boot_settings
+ if provisioning == nil
+ if boot_device==BOOT_DEV_NETWORK
+ PXE_OPTION_VALUE
+ elsif boot_device==BOOT_DEV_HD
+ HD_OPTION_VALUE
+ else
+ PXE_OPTION_VALUE
+ end
+ else
+ provisioning
+ end
+ end
+
def get_pending_state
pending_state = state
pending_state = EFFECTIVE_STATE[state] if pending_state
diff --git a/wui/src/app/views/vm/_form.rhtml b/wui/src/app/views/vm/_form.rhtml
index 308ad71..b3a8957 100644
--- a/wui/src/app/views/vm/_form.rhtml
+++ b/wui/src/app/views/vm/_form.rhtml
@@ -8,7 +8,7 @@
<%= hidden_field_tag 'hardware_pool_id', @hardware_pool.id if @hardware_pool %>
<%= text_field_with_label "Name:", "vm", "description", {:style=>"width:250px;"} %>
- <%= select_with_label "Operating System:", 'vm', 'cobbler_profile', @cobbler_profiles, :style=>"width:250px;" if create %>
+ <%= select_with_label "Operating System:", 'vm', 'provisioning_and_boot_settings', @provisioning_options, :style=>"width:250px;" if create %>
<div class="clear_row" style="height:15px;"></div>
<div class="form_heading">Resources</div>
diff --git a/wui/src/app/views/vm/show.rhtml b/wui/src/app/views/vm/show.rhtml
index 4e9eab1..f361131 100644
--- a/wui/src/app/views/vm/show.rhtml
+++ b/wui/src/app/views/vm/show.rhtml
@@ -94,7 +94,7 @@
Memory used:<br/>
vNIC MAC address:<br/>
Boot device:<br/>
- Cobbler profile:<br/>
+ Provisioning source:<br/>
State:<br/>
Pending State:<br/>
</div>
@@ -106,7 +106,7 @@
<%=h @vm.memory_used_in_mb %> MB<br/>
<%=h @vm.vnic_mac_addr %><br/>
<%=h @vm.boot_device %><br/>
- <%=h @vm.cobbler_profile %><br/>
+ <%=h @vm.provisioning_and_boot_settings %><br/>
<%=h @vm.state %>
<%unless @vm.needs_restart.nil? or @vm.needs_restart == 0 -%>
(needs restart)
diff --git a/wui/src/db/migrate/015_rename_cobbler_profile.rb b/wui/src/db/migrate/015_rename_cobbler_profile.rb
new file mode 100644
index 0000000..7471c6b
--- /dev/null
+++ b/wui/src/db/migrate/015_rename_cobbler_profile.rb
@@ -0,0 +1,28 @@
+#
+# Copyright (C) 2008 Red Hat, Inc.
+# Written by Scott Seago <sseago at redhat.com>
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; version 2 of the License.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
+# MA 02110-1301, USA. A copy of the GNU General Public License is
+# also available at http://www.gnu.org/copyleft/gpl.html.
+
+class RenameCobblerProfile < ActiveRecord::Migration
+ def self.up
+ rename_column :vms, :cobbler_profile, :provisioning
+ end
+
+ def self.down
+ rename_column :vms, :provisioning, :cobbler_profile
+ end
+end
diff --git a/wui/src/task-omatic/task_vm.rb b/wui/src/task-omatic/task_vm.rb
index 6276d04..fca978f 100644
--- a/wui/src/task-omatic/task_vm.rb
+++ b/wui/src/task-omatic/task_vm.rb
@@ -153,16 +153,22 @@ def create_vm(task)
# create cobbler system profile
begin
- if !vm.cobbler_profile or vm.cobbler_profile.empty?
- raise "Cobbler profile not specified"
+ if vm.provisioning and !vm.provisioning.empty?
+ provisioning_arr = vm.provisioning.split(Vm::PROVISIONING_DELIMITER)
+ if provisioning_arr[0]==Vm::COBBLER_PREFIX
+ if provisioning_arr[1]==Vm::PROFILE_PREFIX
+ system = Cobbler::System.new('name' => vm.uuid,
+ 'profile' => provisioning_arr[2])
+ system.interfaces=[Cobbler::NetworkInterface.new(
+ ["intf",{'mac_address' => vm.vnic_mac_addr}]
+ )]
+ system.save
+ elsif provisioning_arr[1]==Vm::IMAGE_PREFIX
+ #FIXME handle cobbler images
+ end
+ end
end
- system = Cobbler::System.new('name' => vm.uuid,
- 'profile' => vm.cobbler_profile)
- system.interfaces=[Cobbler::NetworkInterface.new(
- ["intf",{'mac_address' => vm.vnic_mac_addr}]
- )]
- system.save
setVmState(vm, Vm::STATE_STOPPED)
rescue Exception => error
setVmState(vm, Vm::STATE_CREATE_FAILED)
--
1.5.5.1
More information about the ovirt-devel
mailing list