LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Slackware
User Name
Password
Slackware This Forum is for the discussion of Slackware Linux.

Notices


Reply
  Search this Thread
Old 09-04-2010, 03:22 PM   #16
Ramurd
Member
 
Registered: Mar 2009
Location: Rotterdam, the Netherlands
Distribution: Slackwarelinux
Posts: 703

Original Poster
Rep: Reputation: 111Reputation: 111

You should; As Eric said, it was my main reason to start using VDE as well: no root authority needed to start a VM with "true" networking support.

Btw; got a bit early home tonight, so started on the script; the crude 1st part of parsing the ini file is done now, more or less. It's very basic and won't start your VM yet; in fact it does nothing other than echo stuff, but it gives an idea of the direction I'm thinking of going... Share your ideas with me and it may grow to something quite funny :-)

Code:
#!/bin/ksh

# ksh is more or less required due to scoping of variables
# bash is picky and doesn't scope outside piped loops :-(

machine=${1}
inifile="check.ini"

parse_inifile()
{
	section_start=`cat ${inifile} | grep -v "^#" | grep -n "^\[${machine}\]$" | cut -d ':' -f 1`
	
	if [ -z "${section_start}" ]
	then
	        echo "Not found; valid sections are: "
	        cat ${inifile} | grep -v "^#" | grep -e "^\[.*\]$" | cut -d '[' -f 2 - | cut -d ']' -f 1
	        exit
	fi
	
	section_end=`cat ${inifile} | grep -v "^#" | grep -e "^$" -n | cut -d ':' -f 1 | while read num
	do
		if [ ${num} -gt ${section_start} ]
		then
			echo ${num}
		fi
	done | head -n 1`
	
	((diff=section_end - section_start))
	
	echo "Start: ${section_start}"
	echo "End  : ${section_end}"
	echo "Diff : ${diff}"
	cat ${inifile} | grep -v "^#" | tail -n +${section_start} | head -n ${diff} | while read option
	do
		echo "${#OPT[*]}: ${option}" 
		OPT[${#OPT[*]}]=${option}
	done 
}

parse_options()
{
	COUNT=0
	PARAMETERS=""

	while [ ${COUNT} -lt ${#OPT[*]} ]
	do
		((COUNT+=1)) # we can safely do this; as OPT[0] is the section header
		ARG=`echo ${OPT[${COUNT}]} | cut -d '=' -f 1` 
		VAL=`echo ${OPT[${COUNT}]} | cut -d '=' -f 2-`

		case ${ARG} in
			"")
				PARAMETERS=${PARAMETERS}
				;; # yes pretty silly, right?

			"machine")
				PARAMETERS="${PARAMETERS}-M ${VAL} "
				;;
			*)
				PARAMETERS="${PARAMETERS} -${ARG} ${VAL} "
				;;
		esac
	done
	echo ${PARAMETERS}
}

main()
{
	parse_inifile
	parse_options
}

main
The idea is to have an ini file that has these requirements:
- Each machine starts with [<machine name>]
- an empty line means the end of the machine definition
- comments are possible with an # at the very start of the line
- parameters to be passed to qemu are similar put as <parameter minus the leading ->=<value>
- other things can be put in the ini file, for which I have to write the support yet; e.g. qemu_binary=/usr/bin/qemu

Last edited by Ramurd; 09-04-2010 at 03:33 PM.
 
Old 09-04-2010, 04:20 PM   #17
Chuck56
Member
 
Registered: Dec 2006
Location: Colorado, USA
Distribution: Slackware
Posts: 930

Rep: Reputation: 479Reputation: 479Reputation: 479Reputation: 479Reputation: 479
Quote:
Originally Posted by Ramurd View Post
You should; As Eric said, it was my main reason to start using VDE as well: no root authority needed to start a VM with "true" networking support.
That is a valuable attribute of VDE but I currently use a slightly different approach. Any machine, desktop or server, that has qemu-kvm installed also has my bridge start up script run from rc.local. I run the bridge all the time on those machines. Does that make sense?

Granted I have to provision a separate tap interface for each guest but I rarely run more than 3 guests simultaneously so I setup 3 tap interfaces that are referenced in my consolidated guest config file. The config file is not an ini or xml but just a script that is called by other scripts and assigns values to variables and arrays.

I really like what you're doing with your script and look forward to future updates on your progress!
 
Old 09-04-2010, 07:21 PM   #18
Slax-Dude
Member
 
Registered: Mar 2006
Location: Valadares, V.N.Gaia, Portugal
Distribution: Slackware
Posts: 528

Rep: Reputation: 272Reputation: 272Reputation: 272
Quote:
Originally Posted by Chuck56 View Post
I currently use a slightly different approach. Any machine, desktop or server, that has qemu-kvm installed also has my bridge start up script run from rc.local. I run the bridge all the time on those machines. Does that make sense?
It makes perfect sense to me
Before I switched to libvirt, I used VDE + bridge, because I wanted my VMs to access all my physical machines as well as the internet, instead of being confined to their own network segment. It also makes things simpler, as I didn't need dnsmasq to make a separate network.

All I did was make the tap0 with VDE, then bridge that with eth0, and there you go: VDE switch bridged with the rest of my network

Quote:
Originally Posted by Chuck56 View Post
Granted I have to provision a separate tap interface for each guest but I rarely run more than 3 guests simultaneously so I setup 3 tap interfaces that are referenced in my consolidated guest config file.
One of the advantages of VDE is you only need one TAP device, as long as you define unique MAC addresses on your virtual NICs.
 
Old 09-05-2010, 06:02 AM   #19
Ramurd
Member
 
Registered: Mar 2009
Location: Rotterdam, the Netherlands
Distribution: Slackwarelinux
Posts: 703

Original Poster
Rep: Reputation: 111Reputation: 111
Got the script working in basics now:

Code:
#!/bin/ksh

# ksh is more or less required due to scoping of variables
# bash is picky and doesn't scope outside piped loops :-(

machine=${1}
inifile="manage_vm.ini"

parse_inifile()
{
	if [ "${machine}" = "list"  ]
	then
		cat ${inifile} | grep -v "^#" | grep -e "^\[.*\]$" | cut -d '[' -f 2 - | cut -d ']' -f 1
		return
	fi

	section_start=`cat ${inifile} | grep -v "^#" | grep -n "^\[${machine}\]$" | cut -d ':' -f 1`
	
	if [ -z "${section_start}" ]
	then
	        echo "No [${machine}] section found; valid sections are: "
	        cat ${inifile} | grep -v "^#" | grep -e "^\[.*\]$" | cut -d '[' -f 2 - | cut -d ']' -f 1
	        exit
	fi
	
	section_end=`cat ${inifile} | grep -v "^#" | grep -e "^$" -n | cut -d ':' -f 1 | while read num
	do
		if [ ${num} -gt ${section_start} ]
		then
			echo ${num}
		fi
	done | head -n 1`
	
	((diff=section_end - section_start))
	
	echo "Start: ${section_start}"
	echo "End  : ${section_end}"
	echo "Diff : ${diff}"
	cat ${inifile} | grep -v "^#" | tail -n +${section_start} | head -n ${diff} | while read option
	do
		echo "${#OPT[*]}: ${option}" 
		OPT[${#OPT[*]}]=${option}
	done 
}

parse_options()
{
	COUNT=0
	PARAMETERS=""
	QEMU_BIN=/usr/bin/qemu-system-x86_64

	while [ ${COUNT} -lt ${#OPT[*]} ]
	do
		((COUNT+=1)) # we can safely do this; as OPT[0] is the section header
		ARG=`echo ${OPT[${COUNT}]} | cut -d '=' -f 1` 
		VAL=`echo ${OPT[${COUNT}]} | cut -d '=' -f 2-`

		case ${ARG} in
			"")
				echo "${machine} parsed."
				;; # yes pretty silly, right?
			"qemu_bin") # with qemu_bin you can configure another qemu binary
				QEMU_BIN="${VAL}"
				;;
			"machine")
				PARAMETERS="${PARAMETERS}-M ${VAL} "
				;;
			*)
				PARAMETERS="${PARAMETERS} -${ARG} ${VAL} "
				;;
		esac
	done
	echo ${PARAMETERS}
}

main()
{
	parse_inifile
	parse_options
	
	case $1 in
		"stop")
			echo "Not implemented yet."
			;;
		"start")
			${QEMU_BIN} ${PARAMETERS}
			;;
	esac
}

if [ -z "${1}" ]
then
	echo "Usage: $0 <machine|"list"> <stop|start|restart|status>"
	return 1
fi

if [ "${1}" = "list" ]
then
	main list
	return 0
fi

if [ -z "${2}" ]
then
	echo "Usage: $0 <machine|"list"> <stop|start|restart|status>"
	return 1
fi

case ${2} in
	"stop")
		echo "Not implemented yet."
		;;
	"start")
		main start
		;;
	"status")
		echo "Not implemented yet."
		;;
	"restart")
		echo "Not implemented yet."
		;;
	*)
		echo "Invalid action: actions are: stop, start, restart or status"
		;;
esac
and here my example of an ini file:
Code:
[slack64]
monitor=stdio
smp=2
cpu=qemu64
soundhw=sb16
vga=vmware
m=1500
localtime=
hda=/qcow/Slack64.qcow2
boot=order=dc,menu=off
net=nic,vlan=0,macaddr=52:54:00:e7:91:a4,model=virtio,name="slack64"
net=vde,vlan=0
enable-kvm=
name="Linux-x86_64"
qemu_bin=/usr/bin/qemu-system-x86_64
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
On qemu-kvm, qemu-ifup script not found on Slackware 13 AndrewGaven Linux - Virtualization and Cloud 14 01-29-2010 03:36 AM
qemu and vde help zoran119 Slackware 13 08-03-2009 09:09 AM
Qemu On Slackware bijit1709 Slackware 6 10-17-2007 03:39 PM
QEMU and VDE fr_laz Linux - Networking 0 07-06-2005 08:06 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Slackware

All times are GMT -5. The time now is 01:38 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration