[Ovirt-devel] [PATCH] adds cobbler provisioning to ovirt WUI

Scott Seago sseago at redhat.com
Thu Aug 14 21:56:49 UTC 2008


First, there are a few things either missing or not part of this patch:
1) current IPA/ovirt httpd conf breaks cobbler WUI. slinabery has fixes for this, but I'm not sure if those are pushed
2) since we're still using username/passwd for cobbler, you've got to set up cobbler with password access, and make sure username/password matches config/cobbler.yml
   This bit need to be built into the appliance setup
3) for this to work you've got to have cobbler profiles created.
4) vm creation w/ cobbler provisioning has not yet been tested, as we're having host image networking troubles right now.

Signed-off-by: Scott Seago <sseago at redhat.com>
---
 wui-appliance/common-pkgs.ks                 |    1 +
 wui/conf/ovirt-rails.sysconf                 |    3 ++
 wui/conf/ovirt-taskomatic                    |    1 +
 wui/ovirt-wui.spec                           |    1 +
 wui/src/app/controllers/vm_controller.rb     |    4 +++
 wui/src/app/views/vm/_form.rhtml             |    3 +-
 wui/src/app/views/vm/show.rhtml              |   22 +++++++++++---------
 wui/src/config/cobbler.yml                   |    5 ++++
 wui/src/db/migrate/013_add_cobbler_to_vms.rb |   28 ++++++++++++++++++++++++++
 wui/src/task-omatic/task_vm.rb               |   25 ++++++++++++++++++----
 10 files changed, 76 insertions(+), 17 deletions(-)
 create mode 100644 wui/src/config/cobbler.yml
 create mode 100644 wui/src/db/migrate/013_add_cobbler_to_vms.rb

diff --git a/wui-appliance/common-pkgs.ks b/wui-appliance/common-pkgs.ks
index 5688308..62f688f 100644
--- a/wui-appliance/common-pkgs.ks
+++ b/wui-appliance/common-pkgs.ks
@@ -22,6 +22,7 @@ xorg-x11-xauth
 virt-viewer
 rhpl
 cobbler
+rubygem-cobbler
 bind-utils
 augeas
 /usr/sbin/lokkit
diff --git a/wui/conf/ovirt-rails.sysconf b/wui/conf/ovirt-rails.sysconf
index bc9e237..abec394 100644
--- a/wui/conf/ovirt-rails.sysconf
+++ b/wui/conf/ovirt-rails.sysconf
@@ -1,3 +1,6 @@
 # sets ruby on Rails environment / mode of operation
 # http://wiki.rubyonrails.org/rails/pages/Environments
 #RAILS_ENV=production
+
+#sets the path of the cobbler.yml file for cobbler access
+#COBBLER_YML=/usr/share/ovirt-wui/config/cobbler.yml
diff --git a/wui/conf/ovirt-taskomatic b/wui/conf/ovirt-taskomatic
index 2e548b4..f5c0c51 100755
--- a/wui/conf/ovirt-taskomatic
+++ b/wui/conf/ovirt-taskomatic
@@ -11,6 +11,7 @@
 [ -r /etc/sysconfig/ovirt-rails ] && . /etc/sysconfig/ovirt-rails
 
 export RAILS_ENV="${RAILS_ENV:-production}"
+export COBBLER_YML="${COBBLER_YML:-/usr/share/ovirt-wui/config/cobbler.yml}"
 
 DAEMON=/usr/share/ovirt-wui/task-omatic/taskomatic.rb
 
diff --git a/wui/ovirt-wui.spec b/wui/ovirt-wui.spec
index 7746430..8e5a3da 100644
--- a/wui/ovirt-wui.spec
+++ b/wui/ovirt-wui.spec
@@ -18,6 +18,7 @@ Requires: rubygem(activeldap) >= 0.10.0
 Requires: rubygem(rails) >= 2.0.1
 Requires: rubygem(mongrel) >= 1.0.1
 Requires: rubygem(krb5-auth) >= 0.6
+Requires: rubygem(cobbler) >= 0.0.1
 Requires: ruby-gettext-package
 Requires: postgresql-server
 Requires: ruby-postgres
diff --git a/wui/src/app/controllers/vm_controller.rb b/wui/src/app/controllers/vm_controller.rb
index 4f9962d..28a88c9 100644
--- a/wui/src/app/controllers/vm_controller.rb
+++ b/wui/src/app/controllers/vm_controller.rb
@@ -17,6 +17,9 @@
 # MA  02110-1301, USA.  A copy of the GNU General Public License is
 # also available at http://www.gnu.org/copyleft/gpl.html.
 
+gem 'cobbler'
+require 'cobbler'
+
 class VmController < ApplicationController
   # GETs should be safe (see http://www.w3.org/2001/tag/doc/whenToUseGet.html)
   verify :method => :post, :only => [ :destroy, :create, :update ],
@@ -223,6 +226,7 @@ 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 }
   end
   def pre_create
     params[:vm][:state] = Vm::STATE_PENDING
diff --git a/wui/src/app/views/vm/_form.rhtml b/wui/src/app/views/vm/_form.rhtml
index 023f04b..308ad71 100644
--- a/wui/src/app/views/vm/_form.rhtml
+++ b/wui/src/app/views/vm/_form.rhtml
@@ -8,8 +8,7 @@
 <%= hidden_field_tag 'hardware_pool_id', @hardware_pool.id if @hardware_pool %>
 
     <%= text_field_with_label "Name:", "vm", "description", {:style=>"width:250px;"}  %>
-    <!-- FIXME: cobbler stuff here. what do we do now? -->	
-    <%= select_tag_with_label "Operating System:", 'cobbler_profile', {"Fedora 9" => "fedora9"}, :style=>"width:250px;" %>
+    <%= select_with_label "Operating System:", 'vm', 'cobbler_profile', @cobbler_profiles, :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 674a66a..03395f7 100644
--- a/wui/src/app/views/vm/show.rhtml
+++ b/wui/src/app/views/vm/show.rhtml
@@ -87,24 +87,26 @@
 
     <div id="vms_selection_id" style="display:none"><%= @vm.id %></div>
     <div class="selection_key">
-        Uuid:<br/>                
-	Num vcpus allocated:<br/> 
-	Num vcpus used:<br/>      
-	Memory allocated:<br/>    
-	Memory used:<br/>         
-	vNIC MAC address:<br/>    
-	Boot device:<br/>         
-	State:<br/>    
-	Pending State:<br/>    
+        Uuid:<br/>
+	Num vcpus allocated:<br/>
+	Num vcpus used:<br/>
+	Memory allocated:<br/>
+	Memory used:<br/>
+	vNIC MAC address:<br/>
+	Boot device:<br/>
+        Cobbler profile:<br/>
+	State:<br/>
+	Pending State:<br/>
     </div>
     <div class="selection_value">
        <%=h @vm.uuid %><br/>
        <%=h @vm.num_vcpus_allocated %><br/>
-       <%=h @vm.num_vcpus_used %><br/> 
+       <%=h @vm.num_vcpus_used %><br/>
        <%=h @vm.memory_allocated_in_mb %> MB<br/>
        <%=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.state %>
        <%unless @vm.needs_restart.nil? or @vm.needs_restart == 0  -%>
          (needs restart)
diff --git a/wui/src/config/cobbler.yml b/wui/src/config/cobbler.yml
new file mode 100644
index 0000000..0f78d20
--- /dev/null
+++ b/wui/src/config/cobbler.yml
@@ -0,0 +1,5 @@
+# Cobbler connection details
+
+hostname: localhost
+username: ovirt
+password: ovirt
diff --git a/wui/src/db/migrate/013_add_cobbler_to_vms.rb b/wui/src/db/migrate/013_add_cobbler_to_vms.rb
new file mode 100644
index 0000000..a8f8250
--- /dev/null
+++ b/wui/src/db/migrate/013_add_cobbler_to_vms.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 AddCobblerToVms < ActiveRecord::Migration
+  def self.up
+    add_column :vms, :cobbler_profile, :string
+  end
+
+  def self.down
+    remove_column :vms, :cobbler_profile
+  end
+end
diff --git a/wui/src/task-omatic/task_vm.rb b/wui/src/task-omatic/task_vm.rb
index 34749e0..c9ea2cd 100644
--- a/wui/src/task-omatic/task_vm.rb
+++ b/wui/src/task-omatic/task_vm.rb
@@ -21,6 +21,9 @@ include REXML
 
 require 'utils'
 
+gem 'cobbler'
+require 'cobbler'
+
 def create_vm_xml(name, uuid, memAllocated, memUsed, vcpus, bootDevice,
                   macAddr, bridge, diskDevices)
   doc = Document.new
@@ -152,13 +155,25 @@ def create_vm(task)
   if vm.state != Vm::STATE_PENDING
     raise "VM not pending"
   end
-
   setVmState(vm, Vm::STATE_CREATING)
 
-  # FIXME: in here, we would do any long running creating tasks (allocating
-  # disk, etc.)
+  # create cobbler system profile
+  begin
+    if !vm.cobbler_profile or vm.cobbler_profile.empty?
+      raise "Cobbler profile not specified"
+    end
 
-  setVmState(vm, Vm::STATE_STOPPED)
+    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)
+    raise "Unable to create system: #{error.message}"
+  end
 end
 
 def shutdown_vm(task)
-- 
1.5.5.1




More information about the ovirt-devel mailing list