2011-02-08 07:26:18 +00:00
|
|
|
require 'vm_driver'
|
|
|
|
|
2011-05-24 15:56:32 +00:00
|
|
|
#
|
|
|
|
# $Id$
|
|
|
|
#
|
2011-02-08 07:26:18 +00:00
|
|
|
|
2011-05-24 15:56:32 +00:00
|
|
|
#
|
|
|
|
# To use this driver, you have to have a lab which is preconfigured. The best / easiest
|
|
|
|
# way i've found to to set up a lab is GNS3
|
|
|
|
#
|
2011-02-08 07:26:18 +00:00
|
|
|
|
|
|
|
module Lab
|
|
|
|
module Drivers
|
|
|
|
class DynagenDriver < VmDriver
|
|
|
|
|
|
|
|
attr_accessor :type
|
|
|
|
attr_accessor :location
|
|
|
|
|
2011-05-24 15:56:32 +00:00
|
|
|
def initialize(vmid,location,platform)
|
2011-07-18 20:26:26 +00:00
|
|
|
|
|
|
|
@vmid = filter_command(vmid)
|
|
|
|
@location = filter_command(location)
|
2011-05-24 15:56:32 +00:00
|
|
|
|
2011-02-08 07:26:18 +00:00
|
|
|
if !File.exist?(location)
|
|
|
|
raise ArgumentError,"Couldn't find: " + location
|
|
|
|
end
|
|
|
|
|
|
|
|
@type = "dynagen"
|
|
|
|
@running = false
|
2011-07-18 20:26:26 +00:00
|
|
|
@platform = filter_command(platform)
|
2011-05-24 15:56:32 +00:00
|
|
|
@credentials = []
|
2011-02-08 07:26:18 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def start
|
2011-05-24 15:56:32 +00:00
|
|
|
# TODO - write the location-file to a temp-file
|
|
|
|
# and set the autostart property
|
2011-02-08 07:26:18 +00:00
|
|
|
|
2011-05-24 15:56:32 +00:00
|
|
|
## start background dynamips process
|
|
|
|
system_command("dynamips -H #{@platform} &")
|
2011-02-08 07:26:18 +00:00
|
|
|
system_command("dynagen #{@location}")
|
|
|
|
@running = true
|
|
|
|
end
|
|
|
|
|
|
|
|
def stop
|
|
|
|
system_command("killall dynagen")
|
|
|
|
@running = false
|
|
|
|
end
|
|
|
|
|
|
|
|
def cleanup
|
|
|
|
`killall dynagen`
|
|
|
|
`killall dynamips`
|
|
|
|
@running = false
|
|
|
|
end
|
|
|
|
|
|
|
|
def running?
|
|
|
|
return @running
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|