lib/boot.rb in forj-0.0.43 vs lib/boot.rb in forj-0.0.44

- old
+ new

@@ -32,26 +32,17 @@ # # Boot module # module Boot - def boot(blueprint, name, build, branch, boothook, box_name, oConfig) + def boot(blueprint, name, build, boothook, box_name, oConfig) begin Logging.fatal(1, 'FORJ account not specified. Did you used `forj setup`, before?') if not oConfig.get(:account_name) - oForjAccount = ForjAccount.new(oConfig) - - oForjAccount.ac_load() - - - # Load Forj account data - forjAccountFile = File.join($FORJ_ACCOUNTS_PATH, oConfig.get(:account_name)) - oConfig.ExtraLoad(forjAccountFile, :forj_accounts, oConfig.get(:account_name)) - # Check options and set data - cloud_provider = oForjAccount.getAccountData(:account, :provider, 'hpcloud') + cloud_provider = oConfig.get(:provider_name, 'hpcloud') if cloud_provider != 'hpcloud' Logging.fatal(1, "forj setup support only hpcloud. '%s' is currently not supported." % cloud_provider) end @@ -59,11 +50,11 @@ Logging.high_level_msg(initial_msg) ################# # Initialize defaults maestro_url = oConfig.get(:maestro_url) - infra_dir = File.expand_path(oForjAccount.get(:infra_repo)) + infra_dir = File.expand_path(oConfig.get(:infra_repo)) # Check about infra repo compatibility with forj cli bBuildInfra = Repositories.infra_rebuild_required?(oConfig, infra_dir) @@ -78,51 +69,51 @@ Logging.info('Exiting.') return end # Get FORJ DNS setting - yDNS = rhGet(oForjAccount.hAccountData, :dns) - Logging.fatal(1, "DNS or domain name are missing. Please execute forj setup %s" % oForjAccount.getAccountData(:account, 'name')) if not yDNS + yDNS = rhGet(oConfig.hAccountData, :dns) + Logging.fatal(1, "DNS or domain name are missing. Please execute forj setup %s" % oConfig.getAccountData(:account, 'name')) if not yDNS - branch = oConfig.get(:branch) unless branch + branch = oConfig.get(:branch, 'master') # Step Maestro Clone - if not oForjAccount.get(:maestro_repo) + if not oConfig.get(:maestro_repo) Logging.info('cloning maestro repo from \'%s\'...' % maestro_url) Repositories.clone_repo(maestro_url) maestro_repo=File.expand_path('~/.forj/maestro') else - maestro_repo=File.expand_path(oForjAccount.get(:maestro_repo)) + maestro_repo=File.expand_path(oConfig.get(:maestro_repo)) if not File.exists?('%s/templates/infra/maestro.box.%s.env' % [maestro_repo, branch]) - Logging.fatal(1, "'%s' is not a recognized Maestro repository. forj cli searched for templates/infra/%s-maestro.box.GITBRANCH.env.tmpl" % [maestro_repo, cloud_provider]) + Logging.fatal(1, "'%s' is not a recognized Maestro repository. forj cli searched for templates/infra/maestro.box.%s.env" % [maestro_repo, branch]) end Logging.info('Using your maestro cloned repo \'%s\'...' % maestro_repo) end if bBuildInfra Logging.info('Building your infra... in \'%s\'' % [infra_dir]) - Repositories.create_infra(maestro_repo) + Repositories.create_infra(maestro_repo, branch) end # Connect to services oFC=ForjConnection.new(oConfig) - Logging.info('Configuring network \'%s\'' % [oForjAccount.get('network')]) + Logging.info('Configuring network \'%s\'' % [oConfig.get('network_name')]) begin - network = Network.get_or_create_network(oFC, oForjAccount.get('network')) + network = Network.get_or_create_network(oFC, oConfig.get('network_name')) subnet = Network.get_or_create_subnet(oFC, network.id, network.name) Network.get_or_create_router(oFC, network, subnet) rescue => e Logging.fatal(1, "Network properly configured is required.", e) end - Logging.info('Configuring keypair \'%s\'' % [oForjAccount.get('keypair_name')]) - SecurityGroup.hpc_import_key(oForjAccount) + Logging.info('Configuring keypair \'%s\'' % [oConfig.get('keypair_name')]) + SecurityGroup.hpc_import_key(oConfig) - Logging.info('Configuring Security Group \'%s\'' % [oForjAccount.get('security_group')]) - security_group = SecurityGroup.get_or_create_security_group(oFC, oForjAccount.get('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) ports.each do |port| port = port.to_s if port.class != String if not (/^\d+(-\d+)?$/ =~ port) @@ -133,28 +124,24 @@ portmax = (mPortFound[3]) ? (mPortFound[3]) : (portmin) Network.get_or_create_rule(oFC, security_group.id, 'tcp', portmin, portmax) end end - # oForjAccount data get are retrieved from the account file under section described in defaults.yaml, as soon as this mapping exist. - # If not found, get the data from the local configuration file. Usually ~/.forj/config.yaml - # If not found, get the data from defaults.yaml - # otherwise, use the get default parameter as value. Default is nil. 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', oForjAccount.get('security_group')) - oBuildEnv.set('FORJ_KEYPAIR', oForjAccount.get('keypair_name')) - oBuildEnv.set('FORJ_HPC_NOVA_KEYPUB', oForjAccount.get('keypair_path') + '.pub') - oBuildEnv.set('FORJ_BASE_IMG', oForjAccount.get('image')) - oBuildEnv.set('FORJ_FLAVOR', oForjAccount.get('flavor')) - oBuildEnv.set('FORJ_BP_FLAVOR', oForjAccount.get('bp_flavor')) - oBuildEnv.set('FORJ_TENANT_NAME', oForjAccount.get(:tenant_name)) - oBuildEnv.set('FORJ_HPC_COMPUTE', rhGet(oConfig.ExtraGet(:hpc_accounts, oFC.sAccountName, :regions), :compute)) + 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_BP_FLAVOR', oConfig.get('bp_flavor')) + oBuildEnv.set('FORJ_TENANT_NAME', oConfig.get(:tenant_name)) + oBuildEnv.set('FORJ_HPC_COMPUTE', rhGet(oConfig.oConfig.ExtraGet(:hpc_accounts, oFC.sAccountName, :regions), :compute)) oBuildEnv.set('FORJ_DOMAIN', yDNS[:domain_name]) if yDNS[:tenant_id] @@ -166,12 +153,12 @@ # run build.sh to boot maestro puts build = 'bin/build.sh' unless build - build_config = oForjAccount.get('build_config') - box_name = oForjAccount.get('box_name') + build_config = oConfig.get('build_config') + box_name = oConfig.get('box_name') arg = '--meta blueprint=%s ' % [blueprint] arg += "--test-box '%s' " % oConfig.get(:test_box) if oConfig.exist?(:test_box) 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, arg] @@ -207,16 +194,16 @@ attr_reader :sBuildEnvFile def initialize(oConfig) - oConfig.fatal_if_inexistent(:infra_repo) - oConfig.fatal_if_inexistent(:account_name) + oConfig.oConfig.fatal_if_inexistent(:infra_repo) + oConfig.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) + AppInit.ensure_dir_exists(sBuildDir) @yBuildEnvVar = {} @oConfig = oConfig end def set(key, value) @@ -232,10 +219,10 @@ def save() begin File.open(@sBuildEnvFile, 'w') do |out| @yBuildEnvVar.each do | key, value | - desc = @oConfig.getAppDefault(:description, key) + desc = @oConfig.oConfig.getAppDefault(:description, key) out.write("# %s - %s\n" % [key, desc]) if desc value = "" if not value out.write("%s='%s'\n\n" % [key, value]) end end