Mailinglist Archive: yast-devel (246 mails)

< Previous Next >
[yast-devel] Re: [yast-commit] <rest-service> master : custom-services rest plugin (originaly services plugin for fate 306696)
  • From: Josef Reidinger <jreidinger@xxxxxxx>
  • Date: Mon, 17 Aug 2009 10:17:26 +0200
  • Message-id: <4A891216.1030703@xxxxxxx>
Hi, few comments

On 08/17/2009 10:01 AM, Jiri Suchomel wrote:
ref: refs/heads/master
commit 51c4d88d32d55c56e38a96fd782310e8890e41ea
Author: Jiri Suchomel <jsuchome@xxxxxxx>
Date: Mon Aug 17 10:01:21 2009 +0200

custom-services rest plugin (originaly services plugin for fate 306696)
---
plugins/custom_services/.gitignore | 3 +
plugins/custom_services/MIT-LICENSE | 20 +++++
plugins/custom_services/README | 7 ++
plugins/custom_services/Rakefile | 10 +++
.../app/controllers/custom_services_controller.rb | 54 +++++++++++++
.../custom_services/app/models/custom_service.rb | 70 ++++++++++++++++
.../app/views/custom_services/index.html.erb | 1 +
.../app/views/custom_services/index.json.erb | 1 +
.../app/views/custom_services/index.xml.erb | 1 +
.../app/views/custom_services/show.html.erb | 1 +
.../app/views/custom_services/show.json.erb | 1 +
.../app/views/custom_services/show.xml.erb | 1 +
plugins/custom_services/config/rails_parent.rb | 15 ++++
.../config/resources/custom_services.yml | 2 +
plugins/custom_services/init.rb | 1 +
plugins/custom_services/install.rb | 1 +
.../org.opensuse.yast.modules.yapi.services.policy | 39 +++++++++
.../package/yast2-webservice-services.changes | 16 ++++
.../package/yast2-webservice-services.spec | 83
++++++++++++++++++++
.../tasks/custom_services_tasks.rake | 6 ++
.../functional/custom_services_controller_test.rb | 51 ++++++++++++
plugins/custom_services/test/test_helper.rb | 52 ++++++++++++
plugins/custom_services/uninstall.rb | 1 +
23 files changed, 437 insertions(+), 0 deletions(-)

<snip />
diff --git a/plugins/custom_services/app/models/custom_service.rb
b/plugins/custom_services/app/models/custom_service.rb
new file mode 100644
index 0000000..26ce7ef
--- /dev/null
+++ b/plugins/custom_services/app/models/custom_service.rb
@@ -0,0 +1,70 @@
+require 'yast_service'
+
+class CustomService
+
+ attr_accessor :name
+ attr_accessor :status
+
+ def initialize
+ end
+
+ # services = CustomService.find_all
+ def self.find_all

This is not much convention for model. I think we should for better
readiness use same method as do ActiveRecord...so instead find_all use
find(:all) (use all as parameter)

+
+ services = []
+ yapi_ret = YastService.Call("YaPI::SERVICES::Read")
+
+Rails.logger.debug "reading YAPI ----------------------------"
+
+ if yapi_ret.nil?
+ raise "Can't get services list"
+ else
+ yapi_ret.each do |s|
+ service = CustomService.new
+ service.name = s["name"]
+ service.status = s["status"]
+ Rails.logger.debug "service: #{service.inspect}"
+ services << service
+ end
+ end
+ services
+ end
+
+ # load the status of the service
+ def self.find(id)
+ yapi_ret = YastService.Call("YaPI::SERVICES::Get", id)
+
+ raise "Got no data while loading service" if yapi_ret.empty?
+
+ service = CustomService.new
+ service.name = yapi_ret["name"]
+ service.status = yapi_ret["status"]
+
+ Rails.logger.debug service.inspect
+ service
+ end
+
+
+ def save(cmd)
+ ret = YastService.Call("YaPI::SERVICES::Execute", self.name, cmd)
+
+ Rails.logger.debug "Command returns: #{ret.inspect}"
+ ret
+ end
+
+ def to_xml( options = {} )
+ xml = options[:builder] ||= Builder::XmlMarkup.new(options)
+ xml.instruct! unless options[:skip_instruct]
+
+ xml.service do
+ xml.tag!(:name, name )
+ xml.tag!(:status, status, {:type => "integer"} )
+ end
+ end
+
+ def to_json( options = {} )
+ hash = Hash.from_xml(to_xml())
+ return hash.to_json
+ end
+
+end
new file mode 100644
index 0000000..0f5d8ab
--- /dev/null
+++
b/plugins/custom_services/package/org.opensuse.yast.modules.yapi.services.policy
@@ -0,0 +1,39 @@
+<?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>Novell, Inc.</vendor>
+ <vendor_url>http://www.novell.com</vendor_url>
+
+ <action id="org.opensuse.yast.modules.yapi.services.read">
+ <description>Get list of services.</description>
+ <message>System policy prevents the Yast DBus service from reading
service list.</message>
+ <defaults>
+ <allow_any>no</allow_any>
+ <allow_inactive>no</allow_inactive>
+ <allow_active>auth_admin_keep_session</allow_active>
+ </defaults>
+ </action>
+
+ <action id="org.opensuse.yast.modules.yapi.services.get">
+ <description>Get the information about given service.</description>
+ <message>System policy prevents the Yast DBus service from reading
service info.</message>
+ <defaults>
+ <allow_any>no</allow_any>
+ <allow_inactive>no</allow_inactive>
+ <allow_active>auth_admin_keep_session</allow_active>
+ </defaults>
+ </action>
+
+ <action id="org.opensuse.yast.modules.yapi.services.execute">
+ <description>Starting/stopping services.</description>
+ <message>System policy prevents the Yast DBus service from executing
service script.</message>
+ <defaults>
+ <allow_any>no</allow_any>
+ <allow_inactive>no</allow_inactive>
+ <allow_active>auth_admin_keep_session</allow_active>
+ </defaults>
+ </action>
+</policyconfig>
+

We should unify location of policy files. I as yapi is reachable via
dbus and uses policy kit I add it to directly to yast module. Maybe
someone (Klaus?) should say where is correct location for this file.


--
Josef Reidinger
YaST team
maintainer of perl-Bootloader, YaST2-Repair, webyast modules language
and time
--
To unsubscribe, e-mail: yast-devel+unsubscribe@xxxxxxxxxxxx
For additional commands, e-mail: yast-devel+help@xxxxxxxxxxxx

< Previous Next >