lib/boot.rb in forj-0.0.36 vs lib/boot.rb in forj-0.0.37
- old
+ new
@@ -32,47 +32,56 @@
#
# Boot module
#
module Boot
- def boot(blueprint, name,
- build, infra_dir, build_config,
+ def boot(blueprint, name, build, build_config,
branch, maestro_repo, boothook, box_name,
- oConfig, test = false)
+ oConfig)
begin
# Check options and set data
cloud_provider=oConfig.get('provider')
Logging.fatal(1, 'No provider specified.') if not cloud_provider
if cloud_provider != 'hpcloud'
Logging.fatal(1, "forj setup support only hpcloud. '%s' is currently not supported." % cloud_provider)
end
- oConfig.setDefault('account_name', cloud_provider)
+ oConfig.set('account_name', cloud_provider)
initial_msg = 'booting %s on %s (~/.forj/forj.log)' % [blueprint , cloud_provider]
Logging.high_level_msg(initial_msg) #################
# Initialize defaults
maestro_url = oConfig.get('maestro_url')
- infra_dir = oConfig.get('infra_repo') unless infra_dir
+ infra_dir = File.expand_path(oConfig.get('infra_repo'))
+
+ # Load Forj account data
+ forjAccountFile = File.join($FORJ_ACCOUNTS_PATH, oConfig.get('account_name'))
+ oConfig.ExtraLoad(forjAccountFile, :forj_accounts, oConfig.get('account_name'))
+ # Check about infra repo compatibility with forj cli
+ bBuildInfra = Repositories.infra_rebuild_required?(oConfig, infra_dir)
+
# Ask information if needed.
- bBuildInfra=false
if not Dir.exist?(File.expand_path(infra_dir))
sAsk = 'Your \'%s\' infra directory doesn\'t exist. Do you want to create a new one from Maestro(repo github)/templates/infra (yes/no)?' % [infra_dir]
bBuildInfra=agree(sAsk)
else
- Logging.info('Re-using your infra... in \'%s\'' % [infra_dir])
+ Logging.info('Re-using your infra... in \'%s\'' % [infra_dir]) if not bBuildInfra
end
if not Dir.exist?(File.expand_path(infra_dir)) and not bBuildInfra
Logging.info ('Exiting.')
return
end
+ # Get FORJ DNS setting
+ yDNS = oConfig.ExtraGet(:forj_accounts, oConfig.get('account_name'), :dns)
+ Logging.fatal(1, "DNS or domain name are missing. Please execute forj setup %s" % oConfig.get('account_name')) if not yDNS
+
# Step Maestro Clone
if not maestro_repo
Logging.high_level_msg('cloning maestro repo ...' ) #################
Logging.info('cloning maestro repo from \'%s\'...' % maestro_url)
Repositories.clone_repo(maestro_url)
@@ -103,73 +112,130 @@
Logging.fatal(1, "Network properly configured is required.\n%s\n%s" % [e.message, e.backtrace.join("\n")])
end
Logging.state('Configuring keypair...') #################
Logging.info('Configuring keypair \'%s\'' % [oConfig.get('keypair_name')])
- SecurityGroup.hpc_import_pubkey(oConfig, oFC.sAccountName)
+ SecurityGroup.hpc_import_key(oConfig, oFC.sAccountName)
Logging.state('Configuring security group...') #################
Logging.info('Configuring Security Group \'%s\'' % [oConfig.get('security_group')])
security_group = SecurityGroup.get_or_create_security_group(oFC, oConfig.get('security_group'))
ports = oConfig.get('ports')
Logging.state('Configuring security group ports...') #################
ports.each do |port|
port = port.to_s if port.class != String
- if not /^\d+(-\d+)?$/ =~ port
+ if not /^\d+(-\d+)?$/ =~ port
Logging.error("Port '%s' is not valid. Must be <Port> or <PortMin>-<PortMax>" % [port])
- else
+ else
mPortFound = /^(\d+)(-(\d+))?$/.match(port)
portmin = mPortFound[1]
portmax = (mPortFound[3]) ? (mPortFound[3]) : (portmin)
Network.get_or_create_rule(oFC, security_group.id, 'tcp', portmin, portmax)
- end
+ end
end
- ENV['FORJ_HPC'] = oFC.sAccountName
- ENV['FORJ_HPC_NET'] = network.name
- ENV['FORJ_SECURITY_GROUP'] = oConfig.get('security_group')
- ENV['FORJ_KEYPAIR'] = oConfig.get('keypair_name')
- ENV['FORJ_HPC_NOVA_KEYPUB'] = oConfig.get('keypair_path')
- ENV['FORJ_BASE_IMG'] = oConfig.get('image')
+ oBuildEnv = BuildEnv.new(oConfig)
+ ENV['FORJ_CLI_ENV'] = oBuildEnv.sBuildEnvFile
+ oBuildEnv.set('FORJ_HPC', oFC.sAccountName)
+ oBuildEnv.set('FORJ_HPC_NET', network.name)
+ oBuildEnv.set('FORJ_SECURITY_GROUP', oConfig.get('security_group'))
+ oBuildEnv.set('FORJ_KEYPAIR', oConfig.get('keypair_name'))
+ oBuildEnv.set('FORJ_HPC_NOVA_KEYPUB', oConfig.get('keypair_path') + '.pub')
+ oBuildEnv.set('FORJ_BASE_IMG', oConfig.get('image'))
+ oBuildEnv.set('FORJ_FLAVOR', oConfig.get('flavor'))
+ oBuildEnv.set('FORJ_TENANT_NAME', rhGet(oConfig.ExtraGet(:forj_accounts, oFC.sAccountName, :compute), :tenant_name))
+
+ oBuildEnv.set('FORJ_DOMAIN', yDNS[:domain_name])
+
+ if yDNS[:tenant_id]
+ oBuildEnv.set('FORJ_DNS_TENANTID', yDNS[:tenant_id])
+ oBuildEnv.set('FORJ_DNS_ZONE', yDNS[:service])
+ end
+ oBuildEnv.save()
+
# run build.sh to boot maestro
puts
build = 'bin/build.sh' unless build
- build_config = oConfig.get('build_config') unless build_config
-
+ build_config = oConfig.get('build_config')
branch = oConfig.get('branch') unless branch
+ box_name = oConfig.get('box_name')
- box_name = oConfig.get('box_name') unless box_name
-
meta = '--meta blueprint=%s ' % [blueprint]
command = '%s --build_ID %s --box-name %s --build-conf-dir %s --build-config %s --gitBranch %s --debug-box %s' % [build, name, box_name, infra_dir, build_config, branch, meta]
- maestro_build_path = File.expand_path('~/.forj/maestro/build')
+ maestro_build_path = File.join(maestro_repo, 'build')
current_dir = Dir.pwd
+ Dir.chdir(maestro_build_path)
- Dir.chdir(File.expand_path('~/.forj/maestro/build'))
-
Logging.info("Calling '%s' from '%s'" % [build, Dir.pwd])
- Logging.debug(command)
+ Logging.debug("%s=%s %s" % ['FORJ_CLI_ENV', ENV['FORJ_CLI_ENV'], command])
Kernel.system(ENV, command)
Dir.chdir(current_dir)
- if test
- Logging.debug 'test flag is on, deleting objects'
- Network.delete_router_interface(subnet.id, router)
- Network.delete_subnet(subnet.id)
- Network.delete_network(network.name)
- end
+# if test
+# Logging.debug 'test flag is on, deleting objects'
+# Network.delete_router_interface(subnet.id, router)
+# Network.delete_subnet(subnet.id)
+# Network.delete_network(network.name)
+# end
rescue Interrupt
Logging.message("\n'%s' boot from '%s' interrupted by user" % [name, blueprint])
rescue => e
Logging.error("%s\n%s" % [e.message, e.backtrace.join("\n")])
end
end
+
+end
+
+
+class BuildEnv
+
+ attr_reader :sBuildEnvFile
+
+ def initialize(oConfig)
+
+ oConfig.fatal_if_inexistent('infra_repo')
+ oConfig.fatal_if_inexistent('account_name')
+
+ sBuildDir = File.expand_path(File.join(oConfig.get('infra_repo'),'build'))
+ @sBuildEnvFile = File.join(sBuildDir, oConfig.get('account_name')+'.build.env')
+ Helpers.ensure_dir_exists(sBuildDir)
+ @yBuildEnvVar = {}
+ @oConfig = oConfig
+ end
+
+ def set(key, value)
+ # This file creates the in-memory data required to configure specific project build_env.
+ # Name : ~/.forj/account/<Account>.build.env
+ if value
+ Logging.debug("Setting '%s' = '%s'" % [key, value])
+ @yBuildEnvVar[key] = value
+ else
+ Logging.debug("'%s' is not set" % [key])
+ end
+ end
+
+ def save()
+ begin
+ File.open(@sBuildEnvFile, 'w') do |out|
+ @yBuildEnvVar.each do | key, value |
+ if rhExist?(@oConfig.yConfig, 'description', key)
+ out.write("# %s - %s\n" % [key, rhGet(@oConfig.yConfig, 'description', key)])
+ end
+ value = "" if not value
+ out.write("%s='%s'\n\n" % [key, value])
+ end
+ end
+ Logging.debug("'%s' written." % [@sBuildEnvFile])
+ rescue => e
+ Logging.error("%s\n%s" % [e.message, e.backtrace.join("\n")])
+ end
+ end
end