ref: refs/heads/master
commit 6754295b132e2d2eeb142b5fd6bacc208d15bb65
Author: Michal Zugec
Date: Fri Sep 4 09:09:35 2009 +0200
added controller and model for interfaces
---
.../controllers/network/interfaces_controller.rb | 45 ++++++++++++++++
plugins/network/app/models/interface.rb | 56 ++++++++++++++++++++
2 files changed, 101 insertions(+), 0 deletions(-)
diff --git a/plugins/network/app/controllers/network/interfaces_controller.rb b/plugins/network/app/controllers/network/interfaces_controller.rb
new file mode 100644
index 0000000..0eccdb5
--- /dev/null
+++ b/plugins/network/app/controllers/network/interfaces_controller.rb
@@ -0,0 +1,45 @@
+# = Hostname controller
+# Provides access to hostname settings for authenticated users.
+# Main goal is checking permissions.
+class Network::InterfacesController < ApplicationController
+
+ before_filter :login_required
+
+ # Sets hostname settings. Requires write permissions for network YaPI.
+ def update
+ unless permission_check( "org.opensuse.yast.modules.yapi.network.write")
+ render ErrorResult.error(403, 1, "no permission") and return
+ end
+
+ root = params[:interfaces]
+ if root == nil
+ render ErrorResult.error(404, 2, "format or internal error") and return
+ end
+
+ @iface = Interface.new(root)
+ @iface.save
+ render :show
+ end
+
+ # See update
+ def create
+ update
+ end
+
+ # Shows hostname settings. Requires read permission for network YaPI.
+ def show
+
+ unless permission_check( "org.opensuse.yast.modules.yapi.network.read")
+ render ErrorResult.error( 403, 1, "no permission" ) and return
+ end
+
+ @ifce = Interface.find(params[:id])
+
+ respond_to do |format|
+ format.html { render :xml => @difce.to_xml( :root => "interfaces", :dasherize => false ) }
+ format.xml { render :xml => @ifce.to_xml( :root => "interfaces", :dasherize => false ) }
+ format.json { render :json => @ifce.to_json }
+ end
+ end
+
+end
diff --git a/plugins/network/app/models/interface.rb b/plugins/network/app/models/interface.rb
new file mode 100644
index 0000000..00b44d9
--- /dev/null
+++ b/plugins/network/app/models/interface.rb
@@ -0,0 +1,56 @@
+# = Hostname model
+# Provides set and gets resources from YaPI network module.
+# Main goal is handle YaPI specific calls and data formats. Provides cleaned
+# and well defined data.
+class Interface
+
+ # the short hostname
+ attr_accessor :bootproto
+ # the domain name
+ attr_accessor :ipaddr
+
+ private
+
+ public
+
+ def initialize(kwargs)
+ @bootproto = kwargs["bootproto"]
+ @ipaddr = kwargs["ipaddr"]
+ end
+
+ # fills time instance with data from YaPI.
+ #
+ # +warn+: Doesn't take any parameters.
+ def Interface.find(which)
+ response = YastService.Call("YaPI::NETWORK::Read") # hostname: 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,
+ }
+ YastService.Call("YaPI::NETWORK::Write",{"interfaces" => settings})
+ # TODO success or not?
+ end
+
+ def to_xml( options = {} )
+ xml = options[:builder] ||= Builder::XmlMarkup.new(options)
+ xml.instruct! unless options[:skip_instruct]
+
+ xml.interface do
+ xml.bootproto @bootproto
+ xml.ipaddr @ipaddr
+ end
+ end
+
+ def to_json( options = {} )
+ hash = Hash.from_xml(to_xml())
+ return hash.to_json
+ end
+
+end
--
To unsubscribe, e-mail: yast-commit+unsubscribe@opensuse.org
For additional commands, e-mail: yast-commit+help@opensuse.org