ref: refs/heads/jr_ntp
commit c48cbc9d9eea48ec8469e1a51d8812494972c27b
Author: Martin Vidner
Date: Fri Aug 21 11:04:53 2009 +0200
Restarted the network service.
hostname reading works (when I fake YaPI::Network)
---
.../network/app/controllers/hostname_controller.rb | 45 ++++++++++
.../network/app/controllers/networks_controller.rb | 87 --------------------
plugins/network/app/models/hostname.rb | 56 +++++++++++++
plugins/network/config/resources/hostname.yml | 3 +
plugins/network/config/resources/interfaces.yml | 2 +
plugins/network/config/resources/network.yml | 5 +-
plugins/network/config/resources/routes.yml | 2 +
.../org.opensuse.yast.modules.yapi.network.policy | 32 +++++++
.../org.opensuse.yast.system.network.policy | 33 --------
.../test/functional/networks_controller_test.rb | 31 -------
10 files changed, 143 insertions(+), 153 deletions(-)
diff --git a/plugins/network/app/controllers/hostname_controller.rb b/plugins/network/app/controllers/hostname_controller.rb
new file mode 100644
index 0000000..bb2db89
--- /dev/null
+++ b/plugins/network/app/controllers/hostname_controller.rb
@@ -0,0 +1,45 @@
+# = Hostname controller
+# Provides access to hostname settings for authenticated users.
+# Main goal is checking permissions.
+class HostnameController < 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[:hostname]
+ if root == nil
+ render ErrorResult.error(404, 2, "format or internal error") and return
+ end
+
+ @hostname = Hostname.new(root)
+ @hostname.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
+
+ @hostname = Hostname.find
+
+ respond_to do |format|
+ format.html { render :xml => @hostname.to_xml( :root => "hostname", :dasherize => false ) }
+ format.xml { render :xml => @hostname.to_xml( :root => "hostname", :dasherize => false ) }
+ format.json { render :json => @hostname.to_json }
+ end
+ end
+
+end
diff --git a/plugins/network/app/controllers/networks_controller.rb b/plugins/network/app/controllers/networks_controller.rb
deleted file mode 100644
index 91ee181..0000000
--- a/plugins/network/app/controllers/networks_controller.rb
+++ /dev/null
@@ -1,87 +0,0 @@
-include ApplicationHelper
-
-class NetworksController < ApplicationController
-
- before_filter :login_required
-
-# def show
-# unless permission_check("org.opensuse.yast.system.network.read")
-# render ErrorResult.error(403, 1, "no permission") and return
-# else
-# @network = Network.new
-# end
-# end
-
- def index
- # read all network settings
- if !permission_check("org.opensuse.yast.system.network.read")
- render ErrorResult.error(403, 1, "no permission") and return
- end
-
- @networks = Network.find_all
-
- respond_to do |format|
- format.html { render :xml => @networks, :location => "none" } #return xml only
- format.xml { render :xml => @networks, :location => "none" }
- format.json { render :json => @networks.to_json, :location => "none" }
- end
- end
-
- def get_device (id)
- ret = Scr.instance.execute(["/sbin/yast2", "lan", "show", "id=#{id}"])
- if (!ret or
- ret[:stderr].include?("There is no such device."))
- return false
- end
- lines = ret[:stderr].split "\n"
- counter = 0
- @network = Network.new
- @network.id = id
-
- @network.description = ""
- @network.mac = ""
- @network.dev_name = ""
- @network.startup = ""
-
- begin
- @network.description = lines[0].strip
- rescue
- end
-
- begin
- @network.mac = (lines[1].split ": ")[1].strip
- rescue
- end
-
- begin
- @network.dev_name = (lines[2].split ": ")[1].strip
- rescue
- end
-
- begin
- @network.startup = lines[3].strip
- rescue
- end
-
- return true
- end
-
-
- # GET /users/1
- # GET /users/1.xml
- def show
- unless permission_check( "org.opensuse.yast.system.network.read")
- render ErrorResult.error(403, 1, "no permission") and return
- end
- if params[:id].blank?
- render ErrorResult.error(404, 2, "empty parameter") and return
- end
- unless get_device params[:id]
- render ErrorResult.error(404, 2, "user not found") and return
- end
- end
-
-
-end
-
-
diff --git a/plugins/network/app/models/hostname.rb b/plugins/network/app/models/hostname.rb
new file mode 100644
index 0000000..c9bfefc
--- /dev/null
+++ b/plugins/network/app/models/hostname.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 Hostname
+
+ # the short hostname
+ attr_accessor :name
+ # the domain name
+ attr_accessor :domain
+
+ private
+
+ public
+
+ def initialize(kwargs)
+ @name = kwargs["name"]
+ @domain = kwargs["domain"]
+ end
+
+ # fills time instance with data from YaPI.
+ #
+ # +warn+: Doesn't take any parameters.
+ def Hostname.find
+ response = YastService.Call("YaPI::Network::Read") # hostname: true
+ ret = Hostname.new(response["hostname"])
+ 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 = {
+ "name" => @name,
+ "domain" => @domain,
+ }
+ YastService.Call("YaPI::Network::Write",{"hostname" => settings})
+ # TODO success or not?
+ end
+
+ def to_xml( options = {} )
+ xml = options[:builder] ||= Builder::XmlMarkup.new(options)
+ xml.instruct! unless options[:skip_instruct]
+
+ xml.hostname do
+ xml.name @name
+ xml.domain @domain
+ end
+ end
+
+ def to_json( options = {} )
+ hash = Hash.from_xml(to_xml())
+ return hash.to_json
+ end
+
+end
diff --git a/plugins/network/config/resources/hostname.yml b/plugins/network/config/resources/hostname.yml
new file mode 100644
index 0000000..4c51233
--- /dev/null
+++ b/plugins/network/config/resources/hostname.yml
@@ -0,0 +1,3 @@
+interface: org.opensuse.yast.modules.yapi.network.hostname
+controller: network/hostname
+singular: true
diff --git a/plugins/network/config/resources/interfaces.yml b/plugins/network/config/resources/interfaces.yml
new file mode 100644
index 0000000..c3b0f62
--- /dev/null
+++ b/plugins/network/config/resources/interfaces.yml
@@ -0,0 +1,2 @@
+interface: org.opensuse.yast.modules.yapi.network.interfaces
+controller: network/interfaces
diff --git a/plugins/network/config/resources/network.yml b/plugins/network/config/resources/network.yml
index 48619ca..6528132 100644
--- a/plugins/network/config/resources/network.yml
+++ b/plugins/network/config/resources/network.yml
@@ -1,2 +1,3 @@
-interface: org.opensuse.yast.system.networks
-controller: networks
+interface: org.opensuse.yast.modules.yapi.network
+controller: network
+singular: true
diff --git a/plugins/network/config/resources/routes.yml b/plugins/network/config/resources/routes.yml
new file mode 100644
index 0000000..bfda187
--- /dev/null
+++ b/plugins/network/config/resources/routes.yml
@@ -0,0 +1,2 @@
+interface: org.opensuse.yast.modules.yapi.network.routes
+controller: network/routes
diff --git a/plugins/network/package/org.opensuse.yast.modules.yapi.network.policy b/plugins/network/package/org.opensuse.yast.modules.yapi.network.policy
new file mode 100644
index 0000000..779d990
--- /dev/null
+++ b/plugins/network/package/org.opensuse.yast.modules.yapi.network.policy
@@ -0,0 +1,32 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE policyconfig PUBLIC
+ "-//freedesktop//DTD PolicyKit Policy Configuration 1.0//EN"
+ "http://www.freedesktop.org/standards/PolicyKit/1.0/policyconfig.dtd">
+<policyconfig>
+
+ <vendor>YaST Webservice Project</vendor>
+ http://en.opensuse.org/WebYaST
+
+<!--
+Rights for network
+-->
+
+ <action id="org.opensuse.yast.modules.yapi.network.read">
+ <description>Reading network information</description>
+ <message>Authentication is required to read network settings</message>
+ <defaults>
+ no
+ no
+ </defaults>
+ </action>
+
+ <action id="org.opensuse.yast.modules.yapi.network.write">
+ <description>Writing network information</description>
+ <message>Authentication is required to write network settings</message>
+ <defaults>
+ no
+ no
+ </defaults>
+ </action>
+
+</policyconfig>
diff --git a/plugins/network/package/org.opensuse.yast.system.network.policy b/plugins/network/package/org.opensuse.yast.system.network.policy
deleted file mode 100644
index 14f43e8..0000000
--- a/plugins/network/package/org.opensuse.yast.system.network.policy
+++ /dev/null
@@ -1,33 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!DOCTYPE policyconfig PUBLIC
- "-//freedesktop//DTD PolicyKit Policy Configuration 1.0//EN"
- "http://www.freedesktop.org/standards/PolicyKit/1.0/policyconfig.dtd">
-<policyconfig>
-
- <vendor>YaST Webservice Project</vendor>
- http://en.opensuse.org/YAST
-
-
-
- <action id="org.opensuse.yast.system.network.read">
- <description>Reading network information</description>
- <message>Authentication is required to read network settings</message>
- <defaults>
- no
- no
- </defaults>
- </action>
-
- <action id="org.opensuse.yast.system.network.writelimits">
- <description>Writing limits for network information</description>
- <message>Authentication is required to write limits for network settings</message>
- <defaults>
- no
- no
- </defaults>
- </action>
-
-</policyconfig>
-
diff --git a/plugins/network/test/functional/networks_controller_test.rb b/plugins/network/test/functional/networks_controller_test.rb
deleted file mode 100644
index 82edf05..0000000
--- a/plugins/network/test/functional/networks_controller_test.rb
+++ /dev/null
@@ -1,31 +0,0 @@
-require File.expand_path(File.dirname(__FILE__) + "/../test_helper")
-require 'test/unit'
-require 'rubygems'
-require "scr"
-require 'mocha'
-
-# Prevent contacting the system bus
-# This looks ugly but the stubs(:initialize) below causes a warning
-class Scr
- def initialize
- end
-end
-
-class NetworksControllerTest < ActionController::TestCase
- fixtures :accounts
- def setup
- @controller = NetworksController.new
- @request = ActionController::TestRequest.new
- # http://railsforum.com/viewtopic.php?id=1719
- @request.session[:account_id] = 1 # defined in fixtures
-
- Scr.any_instance.stubs(:execute).with(["/sbin/yast2", "lan", "list"]).returns({:stderr=>"lo\tlocal\neth0\texternal\n", :exit=>16, :stdout=>""})
-
- end
-
- test "access index" do
- get :index
- assert_response :success
- end
-
-end
--
To unsubscribe, e-mail: yast-commit+unsubscribe@opensuse.org
For additional commands, e-mail: yast-commit+help@opensuse.org