Skip to content

Commit

Permalink
vmbuilder script pushes chef client into machine
Browse files Browse the repository at this point in the history
  • Loading branch information
root committed Nov 15, 2011
1 parent b70df0d commit a2e565d
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 12 deletions.
18 changes: 14 additions & 4 deletions PyVmBuilder/pyvmbuilder.py
Expand Up @@ -24,8 +24,8 @@ def __init__( self, hypervisor = 'kvm', distro = 'ubuntu', options = None, vmbui
'flavour': 'virtual',
'variant': 'minbase',
'arch': 'i386',
'addpkg': ['sudo', 'acpid'],
'timezone': 'America/Denver',
'addpkg': ['gpgv', 'ubuntu-keyring', 'libterm-readline-gnu-perl', 'sudo', 'acpid', 'apt-utils', 'openssh-server'],
'dest': "%s-%s" % (self.distro, self.hypervisor)
}
else:
self.opts = options
Expand Down Expand Up @@ -54,8 +54,11 @@ def _build_opts( self ):
return opts

def vm_image_path( self ):
"""
Return the path to the generated vm image. This has to be run after build_vm
"""
base_path = os.path.abspath( '.' )
vm_path = os.path.join( base_path, 'ubuntu-kvm' )
vm_path = os.path.join( base_path, self.opts['dest'] )
files = os.listdir( vm_path )
vm_name = ''
for f in files:
Expand All @@ -64,13 +67,20 @@ def vm_image_path( self ):
return os.path.join( vm_path, vm_name )

def setOpt( self, opt, value ):
"""
Allows you to set any option that vmbuilder has by supplying the option name(long name not short)
and the value for that option.
"""
self.opts[opt] = value

def get_build_command( self ):
return [self.vmbuilder_path, self.hypervisor, self.distro] + self._build_opts( )

def build_vm( self ):
""" Build the vm using the options given """
if not self._isRoot( ):
raise
p = Popen( self.get_build_command(), stdout = PIPE, stderr = STDOUT )
cmd = self.get_build_command()
print "Building VM with %s" % cmd
p = Popen( cmd, stdout = PIPE, stderr = STDOUT )
return p
17 changes: 9 additions & 8 deletions PyVmBuilder/test.py → PyVmBuilder/test/test.py
@@ -1,19 +1,20 @@
from pyvmbuilder import vmbuilder
from ..pyvmbuilder import vmbuilder
import os
import sys

def buildvm( ):
builder = vmbuilder( )
builder.setOpt( 'mirror', 'http://ubuntu.osuosl.org/ubuntu' )
builder.setOpt( 'user', 'install' )
builder.setOpt( 'pass', '123457' )
builder.setOpt( 'hostname', 'acg01' )
builder.setOpt( 'domain', 'msu.montana.edu' )
builder.setOpt( 'ip', '153.90.237.133' )
builder.setOpt( 'gw', '153.90.237.254' )
builder.setOpt( 'destdir', 'acg01' )
builder.setOpt( 'pass', 'password' )
builder.setOpt( 'hostname', 'ubuntu-01' )
builder.setOpt( 'domain', 'example.com' )
builder.setOpt( 'ip', '1.1.1.2' )
builder.setOpt( 'gw', '1.1.1.1' )
builder.setOpt( 'dest', 'some-dest-folder' )
builder.setOpt( 'timezone', 'America/Denver' )
try:
p = vmbuilder().build_vm()
p = builder.build_vm()
except Exception as e:
print "Make sure you run as root"
print e
Expand Down
2 changes: 2 additions & 0 deletions README
Expand Up @@ -5,6 +5,7 @@ REQUIREMENTS
PyChef (Installed by pip below)
Django (Installed by pip below)
Vmbuilder (https://launchpad.net/vmbuilder or apt-get install vmbuilder)
Chef Server

NOTES
=====
Expand All @@ -18,6 +19,7 @@ INSTALL
1) pip install -r requirements.txt
2) Install PyVmBuilder
2.1) cd PyVmBuilder; python setup.py install
3) Setup a client in chef for ChefMox to use in root's homedirectory


TROUBLESHOOTING
Expand Down
13 changes: 13 additions & 0 deletions vmbuilder_execscripts/base_chef_install.sh
@@ -0,0 +1,13 @@
#!/bin/bash

mkdir $1/etc/chef
knife configure client $1/etc/chef/

chroot $1 sudo apt-get update
chroot $1 sudo apt-get install --force-yes -y ruby ruby-dev libopenssl-ruby rdoc ri irb build-essential wget ssl-cert lsb-release

chroot $1 wget http://production.cf.rubygems.org/rubygems/rubygems-1.7.2.tgz -O /tmp/rubygems-1.7.2.tgz
chroot $1 tar zxf /tmp/rubygems-1.7.2.tgz -C /tmp
chroot $1 sudo ruby /tmp/rubygems-1.7.2/setup.rb --no-format-executable

chroot $1 sudo gem install chef --no-ri --no-rdoc

0 comments on commit a2e565d

Please sign in to comment.