Mailinglist Archive: yast-commit (1914 mails)

< Previous Next >
[yast-commit] <rest-service> master : implemented index for interfaces
  • From: Michal Zugec <mzugec@xxxxxxx>
  • Date: Mon, 7 Sep 2009 10:31:16 +0200
  • Message-id: <E1MlP9e-00058t-25@xxxxxxxxxxxxxxxx>
ref: refs/heads/master
commit c79316190c7247a0bc6cae7f0cb5521f385c2047
Author: Michal Zugec <mzugec@xxxxxxx>
Date: Mon Sep 7 10:31:16 2009 +0200

implemented index for interfaces
---
.../controllers/network/interfaces_controller.rb | 7 ++-
plugins/network/app/models/interface.rb | 52 ++++++++------------
.../network/app/views/network/interfaces/index.erb | 1 -
3 files changed, 27 insertions(+), 33 deletions(-)

diff --git a/plugins/network/app/controllers/network/interfaces_controller.rb
b/plugins/network/app/controllers/network/interfaces_controller.rb
index 4dea4a7..a8f491a 100644
--- a/plugins/network/app/controllers/network/interfaces_controller.rb
+++ b/plugins/network/app/controllers/network/interfaces_controller.rb
@@ -36,7 +36,12 @@ class Network::InterfacesController < ApplicationController
end

def index
- @interfaces = Interface.find_all
+ ifaces_a = Interface.find(:all).values
+ respond_to do |format|
+ format.html { render :xml => ifaces_a.to_xml( :root => "interfaces",
:dasherize => false ) }
+ format.xml { render :xml => ifaces_a.to_xml( :root => "interfaces",
:dasherize => false ) }
+ format.json { render :json => ifaces_a.to_json }
+ end
end

end
diff --git a/plugins/network/app/models/interface.rb
b/plugins/network/app/models/interface.rb
index 69c75ab..1d6c293 100644
--- a/plugins/network/app/models/interface.rb
+++ b/plugins/network/app/models/interface.rb
@@ -4,56 +4,45 @@
# and well defined data.
class Interface

- # the short hostname
- attr_accessor :bootproto
- # the domain name
- attr_accessor :ipaddr
+ attr_accessor :bootproto,
+ :ipaddr,
+ :id

private

public

- def initialize(kwargs)
+ def initialize(kwargs, id=nil)
@bootproto = kwargs["bootproto"]
@ipaddr = kwargs["ipaddr"]
+ @id = kwargs["id"] || id
end

- def self.find_all
- interfaces = []
- response = YastService.Call("YaPI::NETWORK::Read") # interfaces: true
- response = response["interfaces"]
-
- if response.nil?
- raise "Can't get interfaces list"
- else
- response.each do |key, val|
- ifce = Interface.new({'bootproto'=>val["bootproto"],
'ipaddr'=>val["ipaddr"]})
-# ifce.id = val[""]
- ifce.bootproto = val["bootproto"]
- ifce.ipaddr = val["ipaddr"]
- interfaces << ifce
+ def self.find( which )
+ response = YastService.Call("YaPI::NETWORK::Read")
+ ifaces_h = response["interfaces"]
+ if which == :all
+ ret = Hash.new
+ ifaces_h.each do |id, ifaces_h|
+ ret[id] = Interface.new(ifaces_h, id)
end
+ else
+ ret = Interface.new(ifaces_h[which], which)
end
- interfaces
- end
-
- # fills time instance with data from YaPI.
- #
- # +warn+: Doesn't take any parameters.
- def Interface.find(which)
- response = YastService.Call("YaPI::NETWORK::Read") # interfaces: true
- ret = Interface.new(response["interfaces"][which])
return ret
end

+
# Saves data from model to system via YaPI. Saves only setted data,
# so it support partial safe (e.g. save only new timezone if rest of fields
is not set).
def save
settings = {
- "bootproto" => @bootproto,
- "ipaddr" => @ipaddr,
+ @id => {
+ "bootproto" => @bootproto,
+ "ipaddr" => @ipaddr
+ }
}
- YastService.Call("YaPI::NETWORK::Write",{"interfaces" => settings})
+ YastService.Call("YaPI::NETWORK::Write",{"interface" => settings})
# TODO success or not?
end

@@ -62,6 +51,7 @@ class Interface
xml.instruct! unless options[:skip_instruct]

xml.interface do
+ xml.id @id
xml.bootproto @bootproto
xml.ipaddr @ipaddr
end
diff --git a/plugins/network/app/views/network/interfaces/index.erb
b/plugins/network/app/views/network/interfaces/index.erb
deleted file mode 100644
index 1818d17..0000000
--- a/plugins/network/app/views/network/interfaces/index.erb
+++ /dev/null
@@ -1 +0,0 @@
-<%= @interfaces.to_xml( :root => "interfaces", :dasherize => false ) -%>
--
To unsubscribe, e-mail: yast-commit+unsubscribe@xxxxxxxxxxxx
For additional commands, e-mail: yast-commit+help@xxxxxxxxxxxx

< Previous Next >
This Thread
  • No further messages