Sunday, January 15, 2012

Teensy hacking

The Teensy is "a complete USB-based microcontroller development system, in a very small footprint, capable of implementing many types of projects". I'm using it as an intro to USB. I see USB protocol as my white whale. I'm comfortable with other lower level protocols, but those are going away. Most computers do not even come with a RS232 port, so if you want to create any device that is configured by plugging it into a computer, USB is the way to go. I'm hoping to get some of the basics of implementing a USB profile with the Teensy. I know very little about this, so I'm hoping to write this article to learn the USB stack. Any thing said here should be understood that I might have no idea what I'm talking about.

USB consists of 4 wires, 5V+, GND, D+ and D-.  The USB spec talks about these in detail, but in general, D+ and D- are what send data between devices, and is referred to as the bus. On an established USB bus, their is one node (master) that controls all data flowing on the bus and no device can send data without the master node allowing it. I would call this a poll based architecture.

Well, that was rather brief, but layout out a few things. I'm going to be diving into this tutorial, in hopes to have some C code posted that will do something fancy with a Teensy, outside of the stock examples.

Wednesday, December 7, 2011

Shelve in Mercurial

I've been using Mercurial, specifically TortoiseHg, and I very much like the ability to shelve changes in my working set. The interface in TortoiseHg allows you to move chunks of a file into your shelf. I'm a little upset that I've been using a GUI for this, but it's spoiled me. Before I learned about shelving, I would try to work on small bugs in branches, but I didn't want to push those branches to my "central" repo. I then looked into the local branch extension, but it seemed like over kill. The shelve extension comes with TortoiseHg and , as I said before, the UI is very pretty. I think I need to get back to the CLI.  Maybe I'll do a follow up post on using the shelve extension from the command line.

Thursday, May 26, 2011

Installing hgsubversion on Debian

I was digging around the interwebs for quite some time, and I would like to post my struggles, in hopes that someone won't bang their head against a wall as long as I did.

So what I was trying to do was use mercurial with svn, and the hgsubversion plugin seemed like the best way to do this. Now following the instructions, I see I just need to clone the plugin to my local machine, using:

hg clone -u 1.2.1 ~/hgsubversion
I then added the plugin to my .hg file in my home directory

[extensions] hgsubversion = ~/hgsubversion/hgsubversion
Now, all the tutorials that I saw, said that was it! Your all done ... lies. Try to clone an svn repo, and I got the following message:

abort: no compatible bindings available:

Subversion 1.5.0 or later required, but no bindings were found
Subvertpy 0.7.4 or later required, but 0.7.3 found

Please install either Subvertpy or the Subversion Python SWIG bindings!

Googling the phrases in the above message, didn't really give me too much info on how to get this working on my Debian machine. I won't bore you with the details, here is what I had to do to get the bindings installed:

#:apt-get install python-subversion

Duh. Hope this helps someone.

Tuesday, April 12, 2011

Hooks in Genati

At my current job, we have a few servers that are running virtualization software. We were originally using Xen, but with the latest version of Debian Squeeze, we were force to upgrade and in doing so, found that KVM seem to work a bit better in our system. I did not set up our cluster, so I'm not going to go into detail about our setup, but I can go into how to set up hooks.

Hooks allow you to run a custom script right before a new instance is setup. You can do things like set up your network interfaces, firewalls and apt-get new programs. First thing is first, where the hell do you put the script? Here:
 $ /etc/ganeti/instance-debootstrap/hooks/
In this directory, I have a file called "clear-root-password". I uses this as the basis for my files. The things that I needed to do when I setup a new instance:
  • set up my network interface
  • download some standard programs
  • set up my firewall
Now that I have my goals, how the hell do I get it working? So the first thing that I learned, was the Ganeti documentation is ... ok. I can't say that the things that I did will work for you, but it worked for me. To run the bash scripts, you have to make Ganeti run your script, make the file executable. When the hook script is running, there is no output to standard output. If everything works correctly, it just tells you everything is ok. If there is an error, the tail of the log file for that operation is printed to the screen.

You can add an network interface by adding the following line to your hook file:
echo "iface eth0 inet static" >> "$TARGET"/etc/network/interface
echo "address $NIC_0_IP" >> "$TARGET"/etc/network/interface
echo "netmask" >> "$TARGET"/etc/network/interface
echo "gateway" >> "$TARGET"/etc/network/interface
The idea behind this is that the $TARGET variable is the temporary path that is the file system of your new instance. You can copy files from the node's filesystem to the new instance too. It's just like a normal file. Pretty sweet if you ask me. Also, the $NIC_0_IP is the ip address that I passed into --net parameter when running gnt-instance add.

Next, what about apt-get? I want to run a command on this new instance and install vim. You can do this by issuing the following command:
 chroot "$TARGET" apt-get install vim
If you don't know about chroot, now you do. It's freaking sweet. You can now run a command as if "$TARGET" was your root directory ( / ), so apt-get will install vim on your new instance.

Finally, when setting up a firewall file, you want to make sure that it can only be read by root. To do this on your new instance, you can issue the following command:
 cp /etc/ "$TARGET"/root/
chmod 600 "$TARGET"/root/
When changing the permissions on the instance, just issue the chmod command as normal.

Using "printenv" bash command allowed me to see the variables that were given to me by Ganeti in the bash script, as the documentation didn't seem to match up exactly with what I was getting in my environment.

Hope this helps someone, leave a comment if you have a question or some point to make.