Tuesday, May 26, 2009

Automatic installation via PXE

This post is more howto than regular blog. I tried to setup PXE based automatic installation server.
There are some docu pages:
but they're both old and step-by-step doesn't work.

First of all, download openSUSE11.1.iso and create installation source:
wget http://download.opensuse.org/distribution/11.1/iso/openSUSE-11.1-DVD-i586.iso
mkdir /srv/www/htdocs/11.1
mount -o loop,uid=wwwrun openSUSE-11.1-DVD-i586.iso /srv/www/htdocs/11.1

Install apache web server:
zypper in apache2

Configure apache to use symlinks:
in /etc/apache2/default-server.conf, in section <Directory "/srv/www/htdocs">
change "Options None" to "Options FollowSymLinks"
restart apache:
rcapache2 restart

Note: my PXE server mas IP address. PXE client will have IP address and 08:00:27:B9:42:52 MAC address

Install DHCP server
zypper in dhcp-server

Configure DHCP server, to offer PXE, dhcpd.conf:
option domain-name-servers;
option routers;
default-lease-time 14400;
ddns-update-style none;
subnet netmask {
default-lease-time 14400;
max-lease-time 172800;
group { # id="pxe-client"
filename "pxelinux.0";
host PXEclient { hardware ethernet 08:00:27:B9:42:52; }

rcdhcpd restart

Install yast2-tftp-server and configure tftp service:
yast2 tftp (confirm to create /tftpboot)

Install syslinux and copy into /tftpboot:
zypper in syslinux
cp /usr/share/syslinux/pxelinux.0 /tftpboot/
rcxinetd restart

Copy and configure isolinux:
mkdir /tftpboot/pxelinux.cfg
cp iso/boot/i386/loader/isolinux.cfg /tftpboot/pxelinux.cfg/default

Copy kernel and initrd
cp iso/boot/i386/loader/linux
cp iso/boot/i386/loader/initrd

Edit config file to boot this as default:
default linux
label linux
append initrd=initrd splash=silent showopts install= insecure=1

implicit 1
display message
prompt 1
timeout 40

Configure your client (in BIOS setup) to "Boot from LAN", "PXE", "network boot" or something similar (depends on BIOS version).
Now we can start installation. On the last dialog, check "create reference profile" checkbox and click OK. When this will be done, copy profile from /root/autoyast.xml on your PXE server as /srv/www/htdocs/AY.xml.

Now you can update your /tftpboot/pxelinux.cfg/default (add autoyast option):
append initrd=initrd splash=silent showopts install= insecure=1 autoyast=

Ok, the result is what we wanted:
When you reboot client machine, it will be be automatically reinstalled to default installation (from autoyast profile). If you comment filename option (and restart dhcp server), client machine will only boot into installed system.

I hope it's clean to understand/reproduce and I hope it will help to somebody.
If not, I'm looking for your feedback ;-)

Tuesday, April 7, 2009

UML diagram of yui objects

Recently I found UML modeling tool - Umbrello. Well, it's not very stable, but there is autosave function ;-)
So I created Class diagram for my small widget_library:

Some objects are missing (work in progress), anyway it's important to visualise objects from begining. It's could be too late when library becomes too complex and relations complicated ...

Friday, March 13, 2009

OOP YaST GUI: event handling

OOP in YaST GUI: Event handling

Hello, here I am again ...

I played with idea of event handling, but if possible better way than we do in ycp now.
Also using inheritance: when you define some behavior, you can inherit class and override handling method or just use objects and handling will be done automatically (using composition).
So the basic idea is that event loop is done automatically and it executes handle function of object that is responsible for such event or which is listening.

Event loop is implemented in parent object (root object in hierarchy - CDialog). Because of this, all inherited objects (MainDialog, PopupDialog) will have this functionality automatically.

class CDialog:
def __init__(self):
self.factory = yui.YUI.widgetFactory()

def listen(self, newList):
self.listeners = newList
while etype!=5:
event = self.dialog.waitForEvent()
etype = event.eventType()
for item in self.listeners:
if (item.getInstance()==event.widget()): item.handle(event)

class CButton:
def __init__(self, factory, parent, label):
self.button = factory.createPushButton( parent, label )
def getInstance(self):
return self.button

self.pbAdd = CButton(self.f, hbox2, "&Add")
self.pbEdit = CButton(self.f, hbox2, "&Edit")
self.pbDel = CButton(self.f, hbox2, "&Delete")
d.listen([self.pbAdd, self.pbEdit, self.pbDel])

When you want to handle something (button click for example), you need to:
- define function that will executed
- connect function to the object
- start event loop with list of "listeners" (objects with connected functions)

There are 3 kinds of functons:
1 - function without any connection to object

self.pbAdd.handle = self.handleAdd

2 - function with connection just to object

self.pbAdd.handle = new.instancemethod(mujhandler, self.pbAdd, self.pbAdd.__class__)

3 - function with visibility outside of the object (example: function can see whole dialog)

self.pbAdd.handle = new.instancemethod(self.handleAdd.im_func, self.pbAdd, self.pbAdd.__class__)

Code is submitted into subversion

How to test this code:
- svn checkout http://svn.opensuse.org/svn/yast/branches/tmp/mzugec/python-yui/
- make sure you have installed packages: python-yui, yast2-libyui, yast2-qt, yast2-ncurses
- run "./main.py" to see Qt version, "unset DISPLAY;./main.py" for ncurses version (unfortunately,in ncurses only way how to terminate application is to kill it, TODO)

Tuesday, February 17, 2009

Object Oriented UI for YaST


After my last blog I worked on YaST (what a surprise) and didn't have any time to post anything until now.
Meanwhile I read some chapters from the "Thinking in Java" book. There are some chapters about OOP in general and it brings me to idea, how it would be great in YaST. As a side effect it also means get away from ycp ;-). Thanks to UI independence I can use Python with the YaST UI.

Here's some code example:


# -*- coding: utf-8 -*-
import yui

class MainDialog:
def __init__(self):
self.factory = yui.YUI.widgetFactory()
self.dialog = self.factory.createMainDialog()
def __del__(self):

class Popup:
def __init__(self):
self.factory = yui.YUI.widgetFactory()
self.dialog = self.factory.createPopupDialog()
def __del__(self):

class TableDialog:
def __init__(self, d):
self.f = d.factory
vbox1 =self.f.createVBox( d.dialog )
hbox1 =self.f.createHBox( vbox1 )
vbox2 =self.f.createVBox( hbox1 )

self.Table( vbox2 )

vspace =self.f.createVSpacing(vbox1,2)

while etype!=5:
event = d.dialog.waitForEvent()
etype = event.eventType()
self.HandleEvent( event )
print etype

def Table(self,parent):
vbox3 =self.f.createVBox( parent )
theader = yui.YTableHeader()
self.table =self.f.createTable( vbox3, theader )
hbox2 =self.f.createHBox( vbox3 )
self.pbAdd =self.f.createPushButton( hbox2, "&Add" )
self.pbEdit =self.f.createPushButton( hbox2, "&Edit" )
self.pbDel =self.f.createPushButton( hbox2, "&Delete")

def customWidget(self,parent):

def HandleEvent(self,event):
if (event.widget()==self.pbAdd):
elif (event.widget()==self.pbEdit):
elif (event.widget()==self.pbDel):

def enableDisableButtons(self):


# -*- coding: utf-8 -*-
import yui
from widget_library import *

class TargetDialog(TableDialog):
def __init__(self,d):

def customWidget(self,parent):
hbox =self.f.createHBox( parent )
self.f.createInputField(hbox, "Target")
self.f.createInputField(hbox, "Identifier")

def handleAdd(self, event):
print "add target item"
def handleEdit(self,event):
print "edit target item ..."
def handleDel(self,event):
print "delete target item ..."

class MyTable(TableDialog):
def __init__(self,d):

def handleAdd(self,event):
print "adding ..."

def handleEdit(self,event):
print "edit item ..."
def handleDel(self,event):
print "delete item ..."

if __name__== "__main__":
td = TargetDialog(MainDialog())

I know that code is not nice and not very useful, but here's some nice OOP examples:
inheritance, composition, etc ...

Easily put into constructor, what kind of dialog I want:
TableDialog(MainDialog()) or TargetDialog(Popup())

Inherit some class and override methods you want (see MyTable.handle*())
This is much better than generate file from template (as we do now).

I like this way and I'll keep working on it during my ITO.