openSUSE:Appliances events workshop Nuremberg 2010 projects use WebYaST

Jump to: navigation, search

SLMS

We found out that SLMS configuration is already WIP (git://git.suse.de/slms/slms.git), so we only tried to run it and use it as an inspiration for SMT module

SMT

We looked into current YaST module for SMT configuration (http://svn.suse.de/svn/yep/trunk/yast/) for

- UI inspiration 
- backend routines to accessing SMT configuration

We started with creating WebYaST module for configuration of SMT. Our project is located at http://svn.suse.de/svn/yep/branches/webyast/webyast-smt-ws/ and http://svn.suse.de/svn/yep/branches/webyast/webyast-smt-ui. It's very simple, currently enables editing of two values from the config file.

The WebYaST module is basically a frontent to /etc/smt.conf file. For accessing the file, it uses the API of yast2-smt package, which contains the config file parser. It would be possible to use some parser directly, so we could go without the YaST layer.

Installation

To use it, checkout the source of both parts, install WebYaST and link the new modules to the plugins directories of running WebYaST:

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

Install yast2-smt package (which is needed as a prerequisite)... probably from https://build.suse.de/package/binaries?package=yast2-smt&project=Devel%3ASMT&repository=standard

Install the YaPI file from webyast-smt-ws repository:

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

Install the policy file and grant the access rights:

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

Restart your webclient and webservice (rcyastwc restart, rcyastws restart) and point your browser to http://localhost:54984/smt.

Files

This is all the file tree we needed for basic WebYaST module: The web service (WS) part:

$ 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

The web ui part:

$ 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

Summary of the SMT sub-project

  • We've seen how to create new WebYaST module from scratch
  • If there's a need for SMT WebYaST configurator in future, we have a starting point with already working backend

SUSE Studio

Studio will use the WebYaST backend to do some firstboot tasks.

Tasks:

  • Get communication going with WebYaST backend [DONE]
  • use the administrator resource to change the root password [DONE]
  • make it possible to accept the EULA [DONE]
  • register with NCC [DONE]


Issues we ran into:

  • License instances are always new (@license.new?) after retrieving it from the backend.
 Fix: Set the primary name
 class License < ActiveResource::Base
   set_primary_key "name"
   ...
 end
  • Array.to_xml doesn't work for strings (["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

Emulating a SLES product on OpenSuSE in order to test the registration

Generate a directory like

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 is a file which should be copied from a existing SLES system

Remove /var/cache/suse_register

Restart services (rcdbus and rcyastws)

Rails Generator for WebYaST

Even though writing new WebYaST module from scratch is not hard when following the tutorial, the barier can be still lowered a lot using a generator to create a skeleton for both UI and WS modules. We are working on such generator at the moment.

TODO push to git repo