Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
add dot_xen submodule, update actor with execute method
- Loading branch information
Joshua Sierles
authored and
Joshua Sierles
committed
Jul 3, 2008
1 parent
d599a18
commit 948a86f
Showing
28 changed files
with
1,117 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
[submodule "vendor/dot_xen"] | ||
path = vendor/dot_xen | ||
url = git@github.com:atmos/dot_xen.git |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
Copyright (c) 2008 Corey Donohoe <cdonohoe at engineyard> | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining | ||
a copy of this software and associated documentation files (the | ||
"Software"), to deal in the Software without restriction, including | ||
without limitation the rights to use, copy, modify, merge, publish, | ||
distribute, sublicense, and/or sell copies of the Software, and to | ||
permit persons to whom the Software is furnished to do so, subject to | ||
the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be | ||
included in all copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, | ||
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF | ||
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND | ||
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE | ||
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION | ||
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION | ||
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
dot_xen | ||
======= | ||
|
||
A gem that provides reading and writing of xen files | ||
|
||
Usage | ||
===== | ||
|
||
mpro% irb | ||
>> require 'lib/dot_xen' | ||
=> true | ||
>> puts XenConfigFile::Parser.new.simple_parse(File.read("spec/fixtures/ey00-s00348.xen")).to_s | ||
# -*- mode: python; -*- | ||
kernel = "/boot/vmlinuz-2.6.18-xenU" | ||
memory = 712 | ||
maxmem = 4096 | ||
name = "ey00-s00348" | ||
vif = [ "bridge=xenbr0" ] | ||
root = "/dev/sda1 ro" | ||
vcpus = 1 | ||
cpu_cap = 100 | ||
disk = [ | ||
"phy:/dev/ey00-data4/root-s00348,sda1,w", | ||
"phy:/dev/ey00-data4/swap-s00348,sda2,w", | ||
"phy:/dev/ey00-data4/gfs-00218,sdb1,w!", | ||
] | ||
=> nil | ||
|
||
|
||
There's two parts to this | ||
|
||
The .simple_parse traverses the tree and builds the representation using the models in lib/xen/ast.rb. It'll return nil if the document is invalid. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
require 'rubygems' | ||
require 'rake/gempackagetask' | ||
require 'rubygems/specification' | ||
require 'spec' | ||
require 'spec/rake/spectask' | ||
require 'date' | ||
|
||
GEM = "dot_xen" | ||
GEM_VERSION = "0.0.1" | ||
AUTHOR = "Corey Donohoe" | ||
EMAIL = "atmos@atmos.org" | ||
HOMEPAGE = "http://atmos.org" | ||
SUMMARY = "A gem that provides reading and writing utils for xen config files. It's also a really simple use of treetop" | ||
|
||
spec = Gem::Specification.new do |s| | ||
s.name = GEM | ||
s.version = GEM_VERSION | ||
s.platform = Gem::Platform::RUBY | ||
s.has_rdoc = true | ||
s.extra_rdoc_files = ["README", "LICENSE", 'TODO'] | ||
s.summary = SUMMARY | ||
s.description = s.summary | ||
s.author = AUTHOR | ||
s.email = EMAIL | ||
s.homepage = HOMEPAGE | ||
|
||
# Uncomment this to add a dependency | ||
s.add_dependency "treetop" | ||
|
||
s.require_path = 'lib' | ||
s.autorequire = GEM | ||
s.files = %w(LICENSE README Rakefile TODO) + Dir.glob("{lib,specs}/**/*") | ||
end | ||
|
||
Rake::GemPackageTask.new(spec) do |pkg| | ||
pkg.gem_spec = spec | ||
end | ||
|
||
desc "install the gem locally" | ||
task :install => [:package] do | ||
sh %{sudo gem install pkg/#{GEM}-#{GEM_VERSION}} | ||
end | ||
|
||
desc "create a gemspec file" | ||
task :make_spec do | ||
File.open("#{GEM}.gemspec", "w") do |file| | ||
file.puts spec.to_ruby | ||
end | ||
end | ||
|
||
task :default => ['spec:run'] | ||
namespace :spec do | ||
Spec::Rake::SpecTask.new('run') do |t| | ||
t.spec_files = FileList['spec/**/**/*.rb'] | ||
end | ||
|
||
desc "Generate specdocs for examples for inclusion in RDoc" | ||
Spec::Rake::SpecTask.new('doc') do |t| | ||
t.spec_files = FileList['spec/**/**/*.rb'] | ||
t.spec_opts = ["--format", "specdoc"] | ||
end | ||
end | ||
|
||
namespace :spec do | ||
desc "Run unit specifications" | ||
Spec::Rake::SpecTask.new(:unit) do |t| | ||
t.spec_opts << '--format' << 'specdoc' << '--colour' | ||
t.spec_opts << '--loadby' << 'random' | ||
t.spec_files = %w(units).collect { |dir| Dir["spec/#{dir}/**/*_spec.rb"] }.flatten | ||
t.rcov = ENV.has_key?('NO_RCOV') ? ENV['NO_RCOV'] != 'true' : true | ||
t.rcov_opts << '--exclude' << 'spec,' | ||
t.rcov_opts << '--text-summary' | ||
t.rcov_opts << '--sort' << 'coverage' << '--sort-reverse' | ||
t.rcov_opts << '--only-uncovered' | ||
end | ||
|
||
desc "Run integration specifications" | ||
Spec::Rake::SpecTask.new(:integration) do |t| | ||
t.spec_opts << '--format' << 'specdoc' << '--colour' | ||
t.spec_opts << '--loadby' << 'random' | ||
t.rcov = ENV.has_key?('NO_RCOV') ? ENV['NO_RCOV'] != 'true' : true | ||
t.spec_files = File.dirname(__FILE__) + '/spec/integrations/**/*_spec.rb' | ||
t.rcov_opts << '--exclude' << 'spec,' | ||
t.rcov_opts << '--text-summary' | ||
t.rcov_opts << '--sort' << 'coverage' << '--sort-reverse' | ||
t.rcov_opts << '--only-uncovered' | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
TODO: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
Gem::Specification.new do |s| | ||
s.name = %q{dot_xen} | ||
s.version = "0.0.1" | ||
|
||
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version= | ||
s.authors = ["Corey Donohoe"] | ||
s.autorequire = %q{dot_xen} | ||
s.date = %q{2008-06-28} | ||
s.description = %q{A gem that provides reading and writing utils for xen config files. It's also a really simple use of treetop} | ||
s.email = %q{atmos@atmos.org} | ||
s.extra_rdoc_files = ["README", "LICENSE", "TODO"] | ||
s.files = ["LICENSE", "README", "Rakefile", "TODO", "lib/dot_xen.rb", "lib/xen", "lib/xen/ast.rb", "lib/xen/xen_config_file_you_shouldnt_use.treetop", "lib/xen/xen_config_file_you_shouldnt_use_node_classes.rb"] | ||
s.has_rdoc = true | ||
s.homepage = %q{http://atmos.org} | ||
s.require_paths = ["lib"] | ||
s.rubygems_version = %q{1.2.0} | ||
s.summary = %q{A gem that provides reading and writing utils for xen config files. It's also a really simple use of treetop} | ||
|
||
if s.respond_to? :specification_version then | ||
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION | ||
s.specification_version = 2 | ||
|
||
if current_version >= 3 then | ||
s.add_runtime_dependency(%q<treetop>, [">= 0"]) | ||
else | ||
s.add_dependency(%q<treetop>, [">= 0"]) | ||
end | ||
else | ||
s.add_dependency(%q<treetop>, [">= 0"]) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
require 'rubygems' | ||
require 'treetop' | ||
|
||
require File.dirname(__FILE__) + '/xen/ast' | ||
Treetop.load File.dirname(__FILE__) + '/xen/xen_config_file_you_shouldnt_use' | ||
require File.dirname(__FILE__) + '/xen/xen_config_file_you_shouldnt_use_node_classes' | ||
|
||
module XenConfigFile | ||
class Parser < Treetop::Runtime::CompiledParser | ||
include XenConfigFileYouShouldntUse | ||
|
||
def simple_parse(io) | ||
parsed = parse(io) | ||
parsed.eval({}) unless parsed.nil? | ||
end | ||
end | ||
end | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
require 'pp' | ||
module XenConfigFile | ||
module AST | ||
# base class for hooking children nodes up | ||
class Base | ||
def self.inherited(subclass) | ||
subclass.send(:define_method, :accept) do |visitor| | ||
visitor.send("visit#{subclass.name.split(/::/).last}", self) | ||
end | ||
end | ||
end | ||
|
||
|
||
# what you get back from simple_parse | ||
class ConfigFile < Base | ||
attr_accessor :disks, :vars, :comments | ||
def initialize(contents) | ||
@vars = [ ] | ||
@comments = contents.delete(:comments) | ||
@disks = ArrayAssignment.new(:disk, Disk.build(contents)) | ||
contents[:variables] << @disks | ||
|
||
contents[:variables].each do |var| | ||
@vars << var | ||
end | ||
end | ||
|
||
# convenience to checkout a params value | ||
def [](key) | ||
@vars.detect { |v| v.lhs == key }.rhs rescue nil | ||
end | ||
|
||
# set variables in existing ASTs with this | ||
def []=(key, value) | ||
@vars << if value.kind_of?(Array) | ||
ArrayAssignment.new(key, value.collect { |v| v.kind_of?(String) ? LiteralString.new(v) : LiteralNumber.new(v) }) | ||
else | ||
Assignment.new(key, value.kind_of?(String) ? LiteralString.new(value) : LiteralNumber.new(value)) | ||
end | ||
end | ||
end | ||
|
||
# disks associated with the image | ||
class Disk < Base | ||
attr_accessor :volume, :device, :mode | ||
|
||
def self.build(contents) | ||
disks = contents[:variables].detect { |var| var.lhs == :disk } | ||
unless disks.nil? | ||
contents[:variables].delete(disks) | ||
|
||
disks.rhs.map do |disk| | ||
volume, device, mode = disk.split(/,/) | ||
new(volume, device, mode) | ||
end unless disks.rhs.nil? | ||
end | ||
end | ||
|
||
def initialize(volume, device, mode) | ||
@volume, @device, @mode = volume, device, mode | ||
end | ||
end | ||
|
||
# lhs is the param name, rhs is a literal string or literal number | ||
class Assignment < Base | ||
attr_accessor :lhs, :rhs | ||
def initialize(lhs, rhs) | ||
@lhs, @rhs = lhs, rhs | ||
end | ||
end | ||
|
||
# lhs is the param name, rhs is an array of literal strings or number | ||
class ArrayAssignment < Assignment | ||
end | ||
|
||
# internal representation of a string | ||
class LiteralString < Base | ||
attr_accessor :value | ||
def initialize(value) | ||
@value = value | ||
end | ||
def ==(value) | ||
if value.kind_of?LiteralString | ||
@value == value.value | ||
else | ||
@value == value | ||
end | ||
end | ||
def split(pattern) | ||
@value.split(pattern) | ||
end | ||
end | ||
|
||
# internal representation of a whole number | ||
class LiteralNumber < Base | ||
attr_accessor :value | ||
def initialize(value) | ||
@value = value | ||
end | ||
def ==(value) | ||
@value == value | ||
end | ||
end | ||
end | ||
end |
Oops, something went wrong.