[Ovirt-devel] [PATCH] Introduce ability to select any kind of nic model, not just default or virtio.

Nicolas Ochem nicolas.ochem at gmail.com
Fri Dec 17 13:56:53 UTC 2010


pushed

On Mon, Oct 11, 2010 at 10:04 AM, Nicolas Ochem <nicolas.ochem at gmail.com>wrote:

> There was no release since virtio support was introduced, so a proper
> migration is not necessary.
>
> This amended commit introduces the "default" model which leaves the
> model choice up to qemu-kvm.
> ---
>  src/app/controllers/vm_controller.rb   |    6 ++-
>  src/app/models/nic.rb                  |    2 +
>  src/app/views/vm/_form.rhtml           |   25 +++++++++-------
>  src/db/migrate/046_add_model_to_nic.rb |   29 ++++++++++++++++++
>  src/public/stylesheets/components.css  |   51
> +++++++++++++++++++++++--------
>  src/task-omatic/task_vm.rb             |    5 +--
>  src/task-omatic/taskomatic.rb          |    2 +-
>  7 files changed, 89 insertions(+), 31 deletions(-)
>  create mode 100644 src/db/migrate/046_add_model_to_nic.rb
>
> diff --git a/src/app/controllers/vm_controller.rb
> b/src/app/controllers/vm_controller.rb
> index adc8988..54abd15 100644
> --- a/src/app/controllers/vm_controller.rb
> +++ b/src/app/controllers/vm_controller.rb
> @@ -199,7 +199,7 @@ class VmController < ApplicationController
>          nnic = Nic.new(:mac => nic.mac,
>                         :vm_id => @vm.id,
>                         :network => nic.network,
> -                        :virtio => nic.virtio)
> +                        :model => nic.model)
>
>          if(nic.network.boot_type.proto == 'static')
>            nnic.ip_addresses << IpAddress.new(:address => nic.ip_address)
> @@ -221,6 +221,8 @@ class VmController < ApplicationController
>         @nics.push nnic
>     }
>
> +    @nic_models = Nic::NIC_MODELS
> +
>   end
>
>   # merges vm / network parameters as submitted on the vm form
> @@ -241,7 +243,7 @@ class VmController < ApplicationController
>              nic = { :mac => params[:macs][i],
>                      :network_id => network_id,
>                      :bandwidth => 0,
> -                     :virtio => params[:virtio][i.to_s] }
> +                     :model => params[:models][i] }
>
>              if(Network.find(network_id).boot_type.proto == 'static')
>                 # FIXME make this able to be v4 or v6 address
> diff --git a/src/app/models/nic.rb b/src/app/models/nic.rb
> index 51425bc..93aef17 100644
> --- a/src/app/models/nic.rb
> +++ b/src/app/models/nic.rb
> @@ -53,6 +53,8 @@ class Nic < ActiveRecord::Base
>   validates_numericality_of :bandwidth,
>      :greater_than_or_equal_to => 0
>
> +  NIC_MODELS =
> ["default","ne2k_pci","i82551","i82557b","i82559er","rtl8139","e1000","pcnet","virtio"]
> +
>   # Returns whether the nic has networking defined.
>   def networking?
>     (network != nil)
> diff --git a/src/app/views/vm/_form.rhtml b/src/app/views/vm/_form.rhtml
> index 1ab6dda..465733d 100644
> --- a/src/app/views/vm/_form.rhtml
> +++ b/src/app/views/vm/_form.rhtml
> @@ -67,6 +67,7 @@
>       <div id="vm_network_config_header">
>         <div id="vm_network_config_header_network">Network:</div>
>         <div id="vm_network_config_header_mac">MAC Address:</div>
> +        <div id="vm_network_config_header_model">Model:</div>
>
>         <%# this column is only populated if a static ip network is
> selected: %>
>         <div id="vm_network_config_header_ip" style="display: none;">IP
> Address:</div>
> @@ -92,14 +93,16 @@
>                 <input name="macs[]" id="vm_network_config_mac_<%= i %>"
> ></input>
>               </div>
>
> -              <div class="vm_network_config_ip">
> -                 
> +              <div class="vm_network_config_model">
> +                <select name="models[]" id="vm_network_config_model_<%= i
> %>" class="vm_network_config_select">
> +                  <% @nic_models.each { |model| %>
> +                     <option value="<%= model %>"><%= model %></option>
> +                  <% } %>
> +                </select>
>               </div>
>
> -              <div class="vm_network_config_virtio">
> -                <%= hidden_field_tag "virtio[#{i}]", "0" %>
> -                <%= check_box_tag "virtio[#{i}]", "1", @nics[i].virtio,
> :id => "vm_network_config_virtio_#{i}" %>
> -               <%= label_tag "vm_network_config_virtio_#{i}", "Use virtio"
> %>
> +              <div class="vm_network_config_ip">
> +                 
>               </div>
>
>               <% if i != 0 %>
> @@ -196,7 +199,7 @@ ${htmlList(pools, id)}
>        jnic.name        = "<%= rnic.network.name %>";
>        jnic.mac         = "<%= rnic.mac %>";
>        jnic.ip          = "<%= rnic.ip_address %>";
> -       jnic.virtio      = <%= rnic.virtio ? 'true' : 'false' %>;
> +       jnic.model      = "<%= rnic.model %>"
>        jnic.static_ip   = <%= rnic.network.boot_type.proto == 'static' %>;
>        jnic.selected    = false;
>        jnic.row         = null;
> @@ -270,15 +273,15 @@ ${htmlList(pools, id)}
>              $('#vm_network_config_mac_'+row).attr('value', nic.mac);
>
>              // show / hide ip address textbox
> -             ip_div = $('#vm_network_config_mac_'+row).parent().next();
> +             ip_div = $('#vm_network_config_model_'+row).parent().next();
>              if(nic.static_ip){
>                   ip_div.html('<input name="ip_addresses[]"
> id="#vm_network_config_ip_'+row+'" value="'+nic.ip+'" />');
>              }else{
>                ip_div.html(' ');
>                 }
>
> -             // set virtio if checked
> -             $('#vm_network_config_virtio_'+row).attr('checked',
> nic.virtio ? 'checked' : '');
> +             // set model
> +             $('#vm_network_config_model_'+row).attr('value', nic.model);
>
>              // show new row only if last row's select box was
>              // previously empty, and if all are not shown
> @@ -302,7 +305,7 @@ ${htmlList(pools, id)}
>             // clear row mac and ip addresses
>             $('#vm_network_config_mac_'+row).attr('value', '');
>
> $('#vm_network_config_mac_'+row).parent().next().html(' ');
> -            $('#vm_network_config_virtio_'+row).attr('checked', '');
> +            //$('#vm_network_config_virtio_'+row).attr('checked', '');
>
>             // hide row if not the first
>                if(row != 0){
> diff --git a/src/db/migrate/046_add_model_to_nic.rb
> b/src/db/migrate/046_add_model_to_nic.rb
> new file mode 100644
> index 0000000..1ec42a9
> --- /dev/null
> +++ b/src/db/migrate/046_add_model_to_nic.rb
> @@ -0,0 +1,29 @@
> +# Copyright (C) 2010 Alcatel-Lucent
> +# Written by Nicolas Ochem <nicolas.ochem at alcatel-lucent.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 AddModelToNic < ActiveRecord::Migration
> +  def self.up
> +    add_column :nics, :model, :string
> +    remove_column :nics, :virtio
> +  end
> +
> +  def self.down
> +    remove_column :nics, :model
> +    add_column :nics, :virtio, :boolean, :default => false
> +  end
> +end
> +
> diff --git a/src/public/stylesheets/components.css
> b/src/public/stylesheets/components.css
> index 3cdbf49..fe4043e 100644
> --- a/src/public/stylesheets/components.css
> +++ b/src/public/stylesheets/components.css
> @@ -349,41 +349,66 @@
>    min-width: 500px;
>  }
>
> -#vm_network_config_header_network,
> -#vm_network_config_header_mac,
>  #vm_network_config_header_ip{
>   float: left;
> -  width: 150px;
> +  width: 102px;
>  }
>
> -.vm_network_config_net,
> -.vm_network_config_mac{
> +#vm_network_config_header_network{
> +  float: left;
> +  width:92px;
> +}
> +
> +#vm_network_config_header_mac{
> +  float: left;
> +  width: 132px;
> +}
> +
> +#vm_network_config_header_model{
> +  float: left;
> +  width: 76px;
> +}
> +
> +.vm_network_config_net{
>   float: left;
> -  width: 150px;
> +  width: 92px;
>  }
>
> +.vm_network_config_mac{
> +  float: left;
> +  width: 132px;
> +}
>  .vm_network_config_ip{
>   float: left;
> -  max-width: 150px;
> +  width: 100px;
>  }
>
> -.vm_network_config_virtio {
> +.vm_network_config_model {
>   float: left;
> -  width: 80px;
> +  width: 76px;
> +}
> +
> +.vm_network_config_ip input{
> +  width: 100px;
>  }
>
> -.vm_network_config_net select,
> -.vm_network_config_mac input,
> -.vm_network_config_ip input {
> -  width: 130px;
> +.vm_network_config_net select{
> +  width: 90px;
>  }
>
> +.vm_network_config_model select {
> +  width: 74px;
> +}
> +.vm_network_config_mac input{
> +  width:125px;
> +}
>  .vm_network_config_remove {
>   float: left;
>   color: #0033CC;
>   padding-top: 5px;
>   padding-left: 5px;
>  }
> +
>  .vm_network_config_remove:hover {
>   cursor: pointer;
>  }
> diff --git a/src/task-omatic/task_vm.rb b/src/task-omatic/task_vm.rb
> index cf84ea2..165363a 100644
> --- a/src/task-omatic/task_vm.rb
> +++ b/src/task-omatic/task_vm.rb
> @@ -99,10 +99,7 @@ def create_vm_xml(name, uuid, memAllocated, memUsed,
> vcpus, bootDevice,
>     interface.add_attribute("type", "bridge")
>     interface.add_element("mac", {"address" => nic[:mac]})
>     interface.add_element("source", {"bridge" => nic[:interface]})
> -
> -    if nic[:virtio]
> -      interface.add_element("model", {"type" => "virtio"})
> -    end
> +    interface.add_element("model", {"type" => nic[:model]}) unless
> nic[:model]=="default"
>     doc.root.elements["devices"] << interface
>   }
>
> diff --git a/src/task-omatic/taskomatic.rb b/src/task-omatic/taskomatic.rb
> index a24a80e..d9efecc 100755
> --- a/src/task-omatic/taskomatic.rb
> +++ b/src/task-omatic/taskomatic.rb
> @@ -413,7 +413,7 @@ class TaskOmatic
>        else
>           net_device = "breth0" # FIXME remove this default at some point
>        end
> -       net_interfaces.push({ :mac => nic.mac, :interface => net_device,
> :virtio => nic.virtio })
> +       net_interfaces.push({ :mac => nic.mac, :interface => net_device,
> :model => nic.model })
>     }
>     # network_always indicates that the boot device is "network" and will
> not change
>     # upon reboot.
> --
> 1.7.2.1
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://listman.redhat.com/archives/ovirt-devel/attachments/20101217/87d90c79/attachment.htm>


More information about the ovirt-devel mailing list