Sha256: 26147e21a9160616ef5d841b8318f8361aa6829e5418aff5ab95d36c8e42ccb3

Contents?: true

Size: 1.44 KB

Versions: 4

Compression:

Stored size: 1.44 KB

Contents

#!/usr/bin/env ruby

def generate(number_apps)
	header = 'include "../modules/node/node.sfp"
include "../modules/mockcloud/mockcloud.sfp"
include "../modules/vm/vm.sfp"
include "../modules/apache/apache.sfp"
include "../modules/mysql/mysql.sfp"
include "../modules/wordpresscluster/wordpresscluster.sfp"

proxy isa Node {
	sfpAddress is "localhost"
	cloud isa MockCloud
}
'
	vmlb = 'vmlb isa VM {
	apache isa Apache {
		running is true
		is_load_balancer is true
		lb_members is (%members%)
	}
}'
	vmapp = '%vmapp% isa VM {
	apache isa Apache {
		running is true
	}
	wp_web isa WordpressWeb {
		installed is true
		http is %vmapp%.apache
		database is vmdb.wp_db
	}
}'
	vmdb = 'vmdb isa VM {
	mysql isa Mysql {
		running is true
	}
	wp_db isa WordpressDB {
		installed is true
		mysql is vmdb.mysql
	}
}'
	output = ''
	members = ''
	global = "global {\n"
	1.upto(number_apps) do |i|
		name = "vmapp#{i}"
		output += vmapp.gsub(/%vmapp%/, name) + "\n"
		members += "#{name},"
		global += "\tif vmlb.apache.running is true then #{name}.apache.running is true\n"
		global += "\tif #{name}.apache.running is true then vmdb.mysql.running is true\n"
	end
	global += "}\n"
	output = header +
	         vmlb.sub(/%members%/, members.chop) + "\n" +
	         output + vmdb + "\n" + global
	output
end

if $0 == __FILE__
	if ARGV[0] == 'help'
		puts "Usage: generator.rb [total-app-layer]"
	else
		number_apps = (ARGV.length > 0 ? ARGV[0].to_i : 3)
		puts generate(number_apps)
	end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
nuri-0.5.4 examples/mockcloud/generator.rb.bak
nuri-0.5.3 examples/mockcloud/generator.rb.bak
nuri-0.5.2 examples/mockcloud/generator.rb
nuri-0.5.1 examples/generator.rb