bin/forj in forj-0.0.48 vs bin/forj in forj-1.0.0

- old
+ new

@@ -23,10 +23,11 @@ $APP_PATH = File.dirname(__FILE__) $LIB_PATH = File.expand_path(File.join(File.dirname($APP_PATH),'lib')) $LOAD_PATH << $LIB_PATH +$LOAD_PATH << File.join($LIB_PATH, 'lib-forj', 'lib') require 'appinit.rb' # Load generic Application level function # Initialize forj paths AppInit::forj_initialize() @@ -36,31 +37,30 @@ require 'forj-config.rb' # Load class ForjConfig and Meta data class variables. Requires Logging to be fully set. require 'forj-account.rb' # Load class ForjAccount require 'connection.rb' # Load class ForjConnection -require 'boot.rb' require 'down.rb' -require 'setup.rb' require 'ssh.rb' -include Boot include Down -include Setup include Ssh require 'forj-settings.rb' # Settings features #require 'debugger' # Use to debug with Ruby < 2.0 #require 'byebug' # Use to debug with Ruby >= 2.0 +require 'lib-forj.rb' +$LIB_FORJ_DEBUG = 1 # less verbose class ForjThor < Thor class_option :debug, :aliases => '-d', :desc => 'Set debug mode' class_option :verbose, :aliases => '-v', :desc => 'Set verbose mode' class_option :config, :aliases => '-c', :desc => 'Path to a different forj config file. By default, use ~/.forj/config.yaml' + class_option :libforj_debug, :desc => "Set lib-forj debug level verbosity. 1 to 5. Default is one." desc "help [action]", "Describe available FORJ actions or one specific action" def help(task = nil, subcommand = false) if task @@ -142,10 +142,15 @@ def boot(blueprint, on_or_name, old_accountname = nil, as = nil, old_name = nil) Logging.set_level(Logger::INFO) if options[:verbose] Logging.set_level(Logger::DEBUG) if options[:debug] + unless options[:libforj_debug].nil? + $LIB_FORJ_DEBUG = options[:libforj_debug].to_i + Logging.set_level(Logger::DEBUG) + end + oConfig = ForjConfig.new(options[:config]) # depreciated: <BluePrint> on <AccountName> as <InstanceName> if old_accountname and as and old_name @@ -177,10 +182,11 @@ oConfig.set(:bp_flavor, options[:bp_flavor]) oConfig.set(:maestro_repo , options[:maestro_repo]) oConfig.set(:branch , options[:branch]) oConfig.set(:test_box, File.expand_path(options[:test_box])) if options[:test_box] and File.directory?(File.expand_path(options[:test_box])) + Logging.warning("test_box is currently disabled in this version. It will be re-activated in newer version.") if options[:test_box] if options[:key_path] mFound = options[:key_path].match(/^(.*)(\.pub)?$/) if mFound key_path = File.expand_path(mFound[1]) @@ -190,12 +196,32 @@ oConfig.set(:keypair_path, key_path) else Logging.fatal(1, "'%s' is not a valid keypair files. At least the public key (.pub) is have to exist.") end end + aProcesses = [] - Boot.boot(blueprint, name, options[:build], options[:boothook], options[:box_name], oForjAccount) + # Defines how to manage Maestro and forges + # create a maestro box. Identify a forge instance, delete it,... + aProcesses << File.join($LIB_PATH, 'forj', 'ForjCore.rb') + + # Defines how cli will control FORJ features + # boot/down/ssh/... + aProcesses << File.join($LIB_PATH, 'forj', 'ForjCli.rb') + + oCloud = ForjCloud.new(oForjAccount, oConfig[:account_name], aProcesses) + + oConfig[:instance_name] = name + + if blueprint == 'maestro' + Logging.info("Starting boot process of '%s'. No blueprint requested." % oConfig[:instance_name]) + else + oConfig[:blueprint] = blueprint + Logging.info("Starting boot process of '%s' with blueprint '%s'." % [oConfig[:instance_name], oConfig[:blueprint]]) + end + oCloud.Create(:forge) + #Boot.boot(blueprint, name, options[:build], options[:boothook], options[:box_name], oForjAccount) end ################################# Show defaults desc 'show <Object> [name]', 'Show Object (default valuesr, account data, etc...) values.' long_desc <<-LONGDESC @@ -365,16 +391,13 @@ oConfig.set(:account_name, options[:account_name]) if options[:account_name] Ssh.connect(name, server, oConfig) end ################################# SETUP - method_option :keypair_name, :aliases => '-k', :desc => "config keypair_name : Keypair name attached as default to your FORJ account." - method_option :keypair_path, :aliases => '-p', :desc => "config keypair_path : SSH key file (private or public) to attach as default to your FORJ account. - It will attach any detected private/public key thanks to the file name - (without extension/.pem = private, .pub = public)" desc 'setup [AccountName [Provider]] [options]', "Setup FORJ cloud account credentials and information." + long_desc <<-LONGDESC This setup will configure a FORJ account used to connect to your cloud system. \x5It will ask for your cloud provider credentials and services. If AccountName is not set, 'hpcloud' will be used for AccountName and provider name, by default. @@ -387,17 +410,36 @@ \x5- user/password (password is encrypted) \x5- DNS settings if you want Maestro to manage it. \x5- domain name to add to each boxes hostname LONGDESC def setup(sAccountName = 'hpcloud', sProvider = "hpcloud") - Logging.set_level(Logger::INFO) if options[:verbose] - Logging.set_level(Logger::DEBUG) if options[:debug] - oConfig=ForjConfig.new(options[:config]) - oConfig.set(:provider, sProvider) - oConfig.set(:account_name, sAccountName) - oConfig.set(:keypair_path, options[:keypair_path]) if options[:keypair_path] - oConfig.set(:keypair_name, options[:keypair_name]) if options[:keypair_name] - Setup.setup(oConfig) + Logging.set_level(Logger::INFO) if options[:verbose] + Logging.set_level(Logger::DEBUG) if options[:debug] + + unless options[:libforj_debug].nil? + $LIB_FORJ_DEBUG = options[:libforj_debug].to_i + Logging.set_level(Logger::DEBUG) + end + + oConfig=ForjConfig.new(options[:config]) + oConfig.set(:provider_name, sProvider) + oConfig.set(:account_name, sAccountName) + + aProcesses = [] + + # Defines how to manage Maestro and forges + # create a maestro box. Identify a forge instance, delete it,... + aProcesses << File.join($LIB_PATH, 'forj', 'ForjCore.rb') + + # Defines how cli will control FORJ features + # boot/down/ssh/... + aProcesses << File.join($LIB_PATH, 'forj', 'ForjCli.rb') + + oCloud = ForjCloud.new(oConfig, sAccountName, aProcesses) + + oCloud.Setup(:forge, sAccountName) + oCloud.config.ac_save() + end end