An experimental version of FreeNAS based on FreeBSD 8.1 is now available to checkout from sourceforge.net.
Two items to consider before checking out the source:
http://sourceforge.net/apps/phpbb/freenas/viewtopic.php?f=5&t=5819&start=10#p37152
– Warner Losh’s blog post on this release
http://freenas.svn.sourceforge.net/viewvc/freenas/experimental/ix/README
– The README file
Understanding the new FreeNAS UI
The most experimental part of FreeNAS is most likely the new user-interface written using the Django Framework. I have lofty goals and idealistic dreams – care to join me?
I used the following to build the django-based UI
When starting a new project I prefer to brainstorm on a whiteboard. Thankfully, dry-erase markers are plentiful behind my desk at iXsystems. It is often easier to write Models when I have a rough sketch of the schema behind me to glance over. Once the Models are finished, the second step is creating Forms from those models using ModelForms. Then the View, which, you guessed it, provides a way to “view” the model. The template used for the view can be super simple and auto-generate the form’s HTML, or one can choose to define the HTML for each form field. I haven’t given much love to the template, yet. The last thing I usually do is define my url and test.
Let’s break it down into simple parts:
In models.py,
## Disk Choices populates a list of disks on the system where FreeNAS is installed.
class DiskChoices:
def __init__(self):
pipe = popen('/sbin/sysctl -n kern.disks')
self._disklist = pipe.read().strip().split(' ')
self.max_choices = len(self._disklist)
def __iter__(self):
return iter((i, i) for i in self._disklist)
## Disk made from the disk you choose, a name you give the disk, and a description.
class Disk(models.Model):
disks = models.CharField(max_length=120, choices=DiskChoices(),verbose_name='Disks')
name = models.CharField(max_length=25, verbose_name='Disk Name')
description = models.CharField(max_length=120, verbose_name='Description', blank=True)
## When saved the disk will be named something like, 'ada0 (Disk Name)'
def __unicode__(self):
return self.disks + ' (' + self.name + ')'
In forms.py,
# DiskForm takes a normal django Model and renders it as a django form
class DiskForm(ModelForm):
class Meta:
model = Disk
In views.py,
# DiskView uses the django form and a template to display the form
def DiskView(request):
if request.method == 'POST':
form = DiskForm(request.POST)
if form.is_valid():
form.save()
else:
form = DiskForm()
variables = RequestContext(request, {
'form': form
})
return render_to_response('freenas/disks/disk.html', variables)
In urls.py,
# the urlpattern defines a URL to use with the View
urlpatterns = patterns('',
(r'^freenas/disk/$', DiskView),
)
There are several more things to familiarize yourself with before it all really fits together, this is a simple example about the different pieces of the puzzle. I didn’t cover how I used FormWizard, but the links provided above should suffice, for now. The most fun is when Xin Li connects the UI to his magical middleware; which communicates with the FreeBSD box and the UI. As these portions of FreeNAS are still experimental, bugs are sure to be found. I’m sure a code-cleanup is in order as well…
If you’re interested in the freenas project visit #freenas on Freenode, freenas.org, or blog.freenas.org.
YO! Check it:
svn co https://freenas.svn.sourceforge.net/svnroot/freenas/experimental/ix/ freenas















