Mailinglist Archive: yast-commit (2114 mails)

< Previous Next >
[yast-commit] <rest-service> jr_ntp : implemented routes - default only (previous commit was incomplete)
  • From: Michal Zugec <mzugec@xxxxxxx>
  • Date: Mon, 31 Aug 2009 09:54:36 +0200
  • Message-id: <E1Mpkq6-0004kg-Hu@xxxxxxxxxxxxxxxx>
ref: refs/heads/jr_ntp
commit 2434c6fb420074c8655aea500069ad356b1ab918
Author: Michal Zugec <mzugec@xxxxxxx>
Date: Mon Aug 31 09:54:36 2009 +0200

implemented routes - default only (previous commit was incomplete)
---
.../network/app/controllers/routes_controller.rb | 12 ++++----
plugins/network/app/models/route.rb | 26 ++++++++++---------
plugins/network/config/resources/routes.yml | 1 -
plugins/network/test/unit/route_test.rb | 25 +++++++++++++++++++
plugins/network/test/unit/routes_test.rb | 25 -------------------
5 files changed, 45 insertions(+), 44 deletions(-)

diff --git a/plugins/network/app/controllers/routes_controller.rb
b/plugins/network/app/controllers/routes_controller.rb
index 2c91e6f..dea97a8 100644
--- a/plugins/network/app/controllers/routes_controller.rb
+++ b/plugins/network/app/controllers/routes_controller.rb
@@ -11,12 +11,12 @@ class RoutesController < ApplicationController
render ErrorResult.error(403, 1, "no permission") and return
end

- root = params[:routing]
+ root = params[:routes]
if root == nil
render ErrorResult.error(404, 2, "format or internal error") and return
end

- @routing = Routing.new(root)
+ @routing = Route.new(root)
@routing.save
render :show
end
@@ -33,12 +33,12 @@ class RoutesController < ApplicationController
render ErrorResult.error( 403, 1, "no permission" ) and return
end

- @routes = Routes.find
+ @route = Route.find(params[:id])

respond_to do |format|
- format.html { render :xml => @routes.to_xml( :root => "routes",
:dasherize => false ) }
- format.xml { render :xml => @routes.to_xml( :root => "routes",
:dasherize => false ) }
- format.json { render :json => @routes.to_json }
+ format.html { render :xml => @route.to_xml( :root => "route", :dasherize
=> false ) }
+ format.xml { render :xml => @route.to_xml( :root => "route", :dasherize
=> false ) }
+ format.json { render :json => @route.to_json }
end
end

diff --git a/plugins/network/app/models/route.rb
b/plugins/network/app/models/route.rb
index 388417d..b3c34ac 100644
--- a/plugins/network/app/models/route.rb
+++ b/plugins/network/app/models/route.rb
@@ -2,25 +2,27 @@
# 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 Routes
+class Route

- # default route
- attr_accessor :default
+ # default gateway
+ attr_accessor :via,
+ :id

private

public

def initialize(kwargs)
- @default = kwargs["default"]
+ @via = kwargs["via"]
end

# fills route instance with data from YaPI.
#
- # +warn+: Doesn't take any parameters.
- def Routes.find
- response = YastService.Call("YaPI::NETWORK::Read") # hostname: true
- ret = Routes.new(response["routes"])
+ # +warn+: YaPI implements default only.
+ def Route.find( which )
+ response = YastService.Call("YaPI::NETWORK::Read")
+ ret = Route.new(response["routes"][which])
+ ret.id = which
return ret
end

@@ -28,9 +30,9 @@ class Routes
# so it support partial safe (e.g. save only new timezone if rest of fields
is not set).
def save
settings = {
- "default" => @default,
+ @id => { 'via'=>@via },
}
- YastService.Call("YaPI::NETWORK::Write",{"routes" => settings})
+ YastService.Call("YaPI::NETWORK::Write",{"route" => settings})
# TODO success or not?
end

@@ -38,8 +40,8 @@ class Routes
xml = options[:builder] ||= Builder::XmlMarkup.new(options)
xml.instruct! unless options[:skip_instruct]

- xml.hostname do
- xml.default @default
+ xml.route do
+ xml.via @via
end
end

diff --git a/plugins/network/config/resources/routes.yml
b/plugins/network/config/resources/routes.yml
index 3f765a5..09c08d5 100644
--- a/plugins/network/config/resources/routes.yml
+++ b/plugins/network/config/resources/routes.yml
@@ -1,4 +1,3 @@
interface: org.opensuse.yast.modules.yapi.network.routes
policy: org.opensuse.yast.modules.yapi.network
controller: network/routes
-singular: true
diff --git a/plugins/network/test/unit/route_test.rb
b/plugins/network/test/unit/route_test.rb
new file mode 100644
index 0000000..c5bbd4a
--- /dev/null
+++ b/plugins/network/test/unit/route_test.rb
@@ -0,0 +1,25 @@
+require File.expand_path(File.dirname(__FILE__) + "/../test_helper")
+
+class RouteTest < ActiveSupport::TestCase
+
+ RESPONSE_FULL = {
+ 'interfaces'=>{
+ 'eth0'=>{'bootproto'=>'dhcp'},
+ 'eth1'=>{'bootproto'=>'static',
'ipaddr'=>'192.168.3.27/24'}},
+ 'routes'=>{'default'=>{'via'=>'10.20.7.254'}},
+ 'dns'=>{'dnsservers'=>'10.20.0.15 10.20.0.8',
'dnsdomains'=>'suse.cz suse.de'},
+ 'hostname'=>{'name'=>'linux', 'domain'=>'suse.cz'}
+ }
+
+ def setup
+ YastService.stubs(:Call).with("YaPI::NETWORK::Read").returns(RESPONSE_FULL)
+ end
+
+ def test_getter
+ route=Route.find('default')
+# assert_equal("linux", hostname.name)
+# assert_equal("suse.cz", hostname.domain)
+ end
+
+end
+
diff --git a/plugins/network/test/unit/routes_test.rb
b/plugins/network/test/unit/routes_test.rb
deleted file mode 100644
index 4b815aa..0000000
--- a/plugins/network/test/unit/routes_test.rb
+++ /dev/null
@@ -1,25 +0,0 @@
-require File.expand_path(File.dirname(__FILE__) + "/../test_helper")
-
-class RoutesTest < ActiveSupport::TestCase
-
- RESPONSE_FULL = {
- 'interfaces'=>{
- 'eth0'=>{'bootproto'=>'dhcp'},
- 'eth1'=>{'bootproto'=>'static',
'ipaddr'=>'192.168.3.27/24'}},
- 'routes'=>{'default'=>'10.20.7.254'},
- 'dns'=>{'dnsservers'=>'10.20.0.15 10.20.0.8',
'dnsdomains'=>'suse.cz suse.de'},
- 'hostname'=>{'name'=>'linux', 'domain'=>'suse.cz'}
- }
-
- def setup
- YastService.stubs(:Call).with("YaPI::NETWORK::Read").returns(RESPONSE_FULL)
- end
-
- def test_getter
- hostname=Routes.find
-# assert_equal("linux", hostname.name)
-# assert_equal("suse.cz", hostname.domain)
- end
-
-end
-
--
To unsubscribe, e-mail: yast-commit+unsubscribe@xxxxxxxxxxxx
For additional commands, e-mail: yast-commit+help@xxxxxxxxxxxx

< Previous Next >
This Thread
  • No further messages