openSUSE:Appliances events workshop Nuremberg 2010 projects use WebYaST

跳转到:导航搜索

SLMS

我们发现SLMS配置已经在进行中(git://git.suse.de/slms/slms.git),所以我们只是尝试运行它,并将其作为SMT模块的灵感

SMT

我们研究了当前的YaST模块,用于SMT配置(http://svn.suse.de/svn/yep/trunk/yast/)用于

- UI inspiration 
- backend routines to accessing SMT configuration

我们开始创建用于配置SMT的WebYaST模块。我们的项目位于http://svn.suse.de/svn/yep/branches/webyast/webyast-smt-ws/http://svn.suse.de/svn/yep/branches/webyast/webyast-smt-ui。它非常简单,目前只能编辑配置文件中的两个值。

WebYaST模块基本上是/etc/smt.conf文件的前端。为了访问该文件,它使用yast2-smt包的API,该包包含配置文件解析器。可以直接使用一些解析器,从而可以避免YaST层。

安装

要使用它,请签出两个部分的代码,安装WebYaST,并将新模块链接到正在运行的WebYaST的插件目录

# ln -s webyast-smt-ws /srv/www/yastws/vendor/plugins/smt
# ln -s webyast-smt-ui /srv/www/yast/vendor/plugins/smt

安装yast2-smt包(作为先决条件需要)…可能来自https://build.suse.de/package/binaries?package=yast2-smt&project=Devel%3ASMT&repository=standard

从webyast-smt-ws仓库安装YaPI文件

# cp webyast-smt-ws/package/SMT.pm /usr/share/YaST2/modules/YaPI/

安装策略文件并授予访问权限

# cp webyast-smt-ws/package/org.opensuse.yast.modules.yapi.smt.policy /usr/share/PolicyKit/policy/
# grantwebyastrights --user yastws --action grant

重新启动您的webclient和webservice (rcyastwc restart, rcyastws restart),并将浏览器指向https://:54984/smt

文件

这是我们需要的基础WebYaST模块的所有文件树:Web服务(WS)部分

$ tree webyast-smt-ws
webyast-smt-ws
|-- app
|   |-- controllers
|   |   `-- smt_controller.rb     # executes backend REST requests using the SMT WebYaST WS model
|   `-- models
|       `-- smt.rb                # code getting and manipulating data on system
|-- config
|   |-- rails_parent.rb           # needed only for testing & development environment
|   `-- resources
|       `-- smt.yml               # defines routes for the SMT WebYaST WS module
|-- init.rb                       # dummy rails plugin initialization file
`-- package
    |-- SMT.pm                    # only needed to access legacy YaST module from yast2-smt
    `-- org.opensuse.yast.modules.yapi.smt.policy  # PolicyKit file for the SMT WebYaST web service

Web UI部分

$ tree webyast-smt-ui
webyast-smt-ui
|-- app
|   |-- controllers
|   |   `-- smt_controller.rb   # executes ui REST requests using the SMT WebYaST UI model
|   |-- models
|   |   `-- smt.rb              # YaSTModel talking to SMT WebYaST WS using REST requests
|   `-- views
|       `-- smt
|           `-- index.html.erb  # The module view
|-- config
|   `-- rails_parent.rb         # needed only for testing & development environment
`-- shortcuts.yml               # defines SMT module icon

SMT子项目的总结

  • 我们已经了解了如何从头开始创建新的WebYaST模块
  • 如果将来需要SMT WebYaST配置器,我们已经有了一个带有可工作后端的起点

SUSE Studio

Studio将使用WebYaST后端来执行一些首次启动任务。

任务

  • 与WebYaST后端建立通信 [完成]
  • 使用管理员资源更改root密码 [完成]
  • 使接受EULA成为可能 [完成]
  • 注册NCC [完成]


我们遇到的问题

  • 从后端检索后,许可证实例总是新的(@license.new?)。
 Fix: Set the primary name
 class License < ActiveResource::Base
   set_primary_key "name"
   ...
 end
  • Array.to_xml对字符串不起作用(["a","b"].to_xml => RuntimeError: Not all elements respond to to_xml)
 Workaround: override Array.to_xml
  class Array
    def to_xml(options = {})
      require 'builder' unless defined?(Builder)

      options = options.dup
      options[:root]     ||= all? { |e| e.is_a?(first.class) && first.class.to_s != "Hash" } ? first.class.to_s.underscore.pluralize : "array"
      options[:children] ||= options[:root].singularize
      options[:indent]   ||= 2
      options[:builder]  ||= Builder::XmlMarkup.new(:indent => options[:indent])

      root     = options.delete(:root).to_s
      children = options.delete(:children)

      if !options.has_key?(:dasherize) || options[:dasherize]
        root = root.dasherize
      end
  
      options[:builder].instruct! unless options.delete(:skip_instruct)

      opts = options.merge({ :root => children })

      xml = options[:builder]
      if empty?
        xml.tag!(root, options[:skip_types] ? {} : {:type => "array"})
      else
        xml.tag!(root, options[:skip_types] ? {} : {:type => "array"}) {
          yield xml if block_given?
          each do |e|
            if e.respond_to? :to_xml
              e.to_xml(opts.merge({ :skip_instruct => true }))
            else
              xml.tag!(children,e.to_s)
            end
          end
        }
      end
    end
  end

为了测试注册,在OpenSuSE上模拟SLES产品

生成一个目录,例如

linux:/etc/products.d> ls -l
insgesamt 20
drwxr-xr-x   2 root root  4096 24. Feb 2009  ./
drwxr-xr-x 119 root root 12288 16. Jun 13:14 ../
lrwxrwxrwx   1 root root    13 24. Feb 2009  baseproduct -> SUSE_SLES.prod
-rw-r--r--   1 root root  1783  4. Dez 2008  SUSE_SLES.prod

SUSE_SLES.prod 是应该从现有的SLES系统复制的文件

删除 /var/cache/suse_register

重新启动服务 (rcdbus 和 rcyastws)

WebYaST的Rails生成器

即使遵循教程编写新的WebYaST模块并不难,但使用生成器为UI和WS模块创建一个骨架,仍然可以大大降低门槛。我们目前正在开发这样的生成器。

TODO 推送到git仓库