bin/forj in forj-0.0.39 vs bin/forj in forj-0.0.40

- old
+ new

@@ -34,10 +34,11 @@ include Down include Setup include Ssh require 'forj-config.rb' # Load class ForjConfig +require 'forj-account.rb' # Load class ForjAccount require 'log.rb' # Load default loggers require 'connection.rb' # Load class ForjConnection #require 'debugger' # Use to debug with Ruby < 2.0 #require 'byebug' # Use to debug with Ruby >= 2.0 @@ -65,68 +66,108 @@ else puts <<-LONGDESC Quick steps: How to create a forj? ---------------------------------- -1. Setup your first forj account. - `$ forj setup [Provider]` +To test a forj blueprint, you will need an account on a cloud solution. +Currently forj cli supports only HPHelion (https://horizon.hp.com) but will be expanded to support most of known clouds supported by FOG. (http://fog.io) - Ex: `forj setup hpcloud`. In this example, your account will be named 'hpcloud'. +1. Setup your FORJ account. + `$ forj setup [AccountName] [--provider Provider]` -IMPORTANT NOTE: Without any provider, forj setup will choose 'hpcloud' as provider. - Currently, forj supports only hpcloud. Openstack will be available soon. + Ex: `forj setup MyForjAccount`. In this example, you will setup 'MyForjAccount' with your HPHelion account. The first time, this account will become the default one. +**IMPORTANT NOTE** By default, forj setup will propose you to create your forge on HPHelion (provider 'hpcloud'). +If AccountName is not set, the account name will be proposed to be name 'hpcloud' as well! + 2. Create your forge on your default account - `$ forj boot <blueprint> on <Provider> as <InstanceName> ` + `$ forj boot <blueprint> <InstanceName>` - Ex: `forj boot redstone on hpcloud as MyForge` + Ex: `forj boot redstone MyForge`. In this example, forj will create a `redstone` blueprint forge named `MyForge`, using the default `MyForjAccount` forj command line details: -------------------------- LONGDESC self.class.help(shell, subcommand) end end - # BOOT +################################# BOOT desc 'boot <Blueprint> on <Provider> as <InstanceName> [options]', 'boot a Maestro box and instruct it to provision the blueprint' long_desc <<-LONGDESC This task boot a new forge with the following options \x5- blueprint : Is the name of the blueprint (currently cli only supports redstone) -\x5- Provider : in which cloud provider to deploy the forge \x5- InstanceName : name of the forge Ex: forj boot redstone on hpcloud as maestro_test -`forj boot` load predefine valued from `lib/defaults.yaml`. If you need to change one of them, add this value in your ~/.forj/config.yaml. +`forj boot` load predefined forj values from `lib/defaults.yaml`. If you need to change one of them, add the key/value in your local config (-c or `~/.forj/config.yaml`). The list of predefined values can be retrieved with forj show defaults LONGDESC - method_option :account_name, :aliases => '-a', :desc => 'Set the forj account name to use. By default, it takes the provider name.' - method_option :infra, :aliases => '-i', :desc => 'Defines your Infra directory to use while booting. You can also set FORJ_INFRA_DIR.' - method_option :maestro_repo, :aliases => '-m', :desc => 'To use a different Maestro repository already cloned. By default, Maestro is cloned to ~/.forj/maestro from github.' - method_option :key_name, :aliases => '-k', :desc => "Keypair name to use." - method_option :key_path, :aliases => '-p', :desc => "Private or Public key file. forj will determine if you provide a public key or a private, if respectively the extension '.pub' exist or not." + method_option :account_name, :aliases => '-a', :desc => "Set the forj account name to use. By default, uses the default account set in your local config file." + method_option :maestro_repo, :aliases => '-m', :desc => "To use a different Maestro repository already cloned. + By default, Maestro is systematically cloned to ~/.forj/maestro from github. + +Following options superseed your config file or forj defaults." + method_option :infra, :aliases => '-r', :desc => 'config: infra_repo : Defines your Infra directory to use while booting. You can also set FORJ_INFRA_DIR.' + method_option :key_name, :aliases => '-k', :desc => "config: keypair_name : Keypair name to use." + method_option :key_path, :aliases => '-p', :desc => "config: keypair_path : Private or Public key file to use." + method_option :security_group, :aliases => '-s', :desc => "config: security_group: Security group name to use and configure." + method_option :image, :aliases => '-i', :desc => "config: image : Image name to use to build Maestro and blueprint nodes." + method_option :maestro_flavor, :aliases => '-f', :desc => "config: flavor : Maestro flavor to use." + method_option :bp_flavor, :aliases => '-b', :desc => "config: bp_flavor : Blueprint nodes default flavor to use. +Build system options:" method_option :boothook, :aliases => '-H', :desc => 'By default, boothook file used is build/bin/build-tools/boothook.sh. Use this option to set another one.' method_option :build, :aliases => '-B', :desc => 'Replace the default build.sh' - method_option :branch, :aliases => '-B', :desc => 'The build will extract from git branch name. It sets the configuration build <config> to the branch name <branch>.' - method_option :test_box, :aliases => '-T', :desc => 'Create test.rb-box meta from the repository path provided.' + method_option :branch, :aliases => '-R', :desc => "Branch name to clone for maestro. - def boot(blueprint, on, cloud_provider, as, name) +Maestro/infra bootstrap debugging:" + method_option :test_box, :aliases => '-T', :desc => "Identify a path to become your test-box repository. + Ex: if your maestro is in ~/src/forj-oss, --test_box ~/src/forj-oss/maestro build.sh and + test-box will send your local maestro repo to your box, for boot." + + 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] - oConfig=ForjConfig.new(options[:config]) + oConfig = ForjConfig.new(options[:config]) + + + # depreciated: <BluePrint> on <AccountName> as <InstanceName> + if old_accountname and as and old_name + msg = "The syntax `forj boot '%s' on '%s' as '%s'` is depreciated.\nUse `forj boot '%s' '%s'" % [blueprint, old_accountname, old_name, blueprint, old_name] + if oConfig.get('account_name') == old_accountname + Logging.warning("%s` instead." % msg) + else + Logging.warning("%s -a '%s'` instead." % [msg, old_accountname]) + end + name = old_name + oConfig.set('account_name', old_accountname) + else + name = on_or_name + end + Logging.fatal(1, "instance name '%s' not supported. Support only lower case, numeric and dash caracters." % [name]) if not /^[\d[[:lower:]]-]+$/ =~ name # Options are added if they are set. Otherwise, get will retrieve the default value. - oConfig.set('account_name', options[:account_name]) - oConfig.set('infra_repo', options[:infra]) - oConfig.set('keypair_name', options[:key_name]) + oConfig.set('account_name', options[:account_name]) if options[:account_name] + oConfig.set('infra_repo', options[:infra]) + oConfig.set('keypair_name', options[:key_name]) + oConfig.set('keypair_path', options[:key_path]) + oConfig.set('security_group', options[:security_group]) + oConfig.set('image', options[:image]) + oConfig.set('flavor', options[:maestro_flavor]) + oConfig.set('bp_flavor', options[:bp_flavor]) + oConfig.set(:maestro_repo , options[:maestro_repo]) + oConfig.set(:test_box, File.expand_path(options[:test_box])) if options[:test_box] and File.directory?(File.expand_path(options[:test_box])) + + if options[:key_path] mFound = options[:key_path].match(/^(.*)(\.pub)?$/) if mFound key_path = File.expand_path(mFound[1]) if mFound[2] and not File.exists?(File.expand_path(mFound[1]+mFound[2])) @@ -136,43 +177,50 @@ else Logging.fatal(1, "'%s' is not a valid keypair files. At least the public key (.pub) is have to exist.") end end - # TODO: Be able to support the default provider from config.yaml - oConfig.set('provider', cloud_provider) - Boot.boot(blueprint, name, - options[:build], + Boot.boot(blueprint, name, options[:build], options[:build_config], options[:branch], - options[:maestro_repo], options[:boothook], - options[:box_name], oConfig) + options[:boothook], options[:box_name], oConfig) end - desc 'show defaults', 'Show list of predefined value you can update in your ~/.forj/config.yaml' +################################# Show defaults + desc 'show defaults', 'Show list of predefined value you can update in your ~/.forj/config.yaml' + method_option :account_name, :aliases => '-a', :desc => "Set the forj account name to use. By default, uses the default account set in your local config file." - def show(name) - oConfig=ForjConfig.new() + def show(name) + case name + when 'defaults' + oConfig=ForjConfig.new() + oConfig.set('account_name', options[:account_name]) + oForjAccount = ForjAccount.new(oConfig) + oForjAccount.ac_load() - puts 'List of default values: ---------------------------' - puts rhGet(oConfig.yConfig,'default').to_yaml() - puts '--------------------------' - puts "You can change any of those variables by editing/adding them in your ~/.forj/config.yaml, under section 'default:'" - end - # DOWN + puts 'List of default values: (local refer to your config file. hash refer to your FORJ account data)' + puts '-----------------------' + puts oConfig.default_dump([oForjAccount.hAccountData]).to_yaml + puts '-----------------------' + puts "To change default values, update your ~/.forj/config.yaml and add the key/value entry under 'default' section." + else + Logging.error("object '%s' unknown." % name) + end + end + +################################# DOWN desc 'down', 'delete the Maestro box and all systems installed by the blueprint' long_desc <<-LONGDESC Not yet implemented LONGDESC def down(name) Logging.set_level(Logger::INFO) if options[:verbose] - Logging.set_level(Logger::DEBUG) if options[:debug] - Down.down(name) + Logging.set_level(Logger::DEBUG) if options[:debug] + Down.down(name) end - # SSH +################################# SSH desc 'ssh', 'connect to your forge thru ssh' long_desc <<-LONGDESC Connect through ssh to an existing instance not yet implemented @@ -182,29 +230,40 @@ Logging.set_level(Logger::INFO) if options[:verbose] Logging.set_level(Logger::DEBUG) if options[:debug] Ssh.connect(name, server) end - # SETUP - method_option :account_name, :aliases => '-a', :desc => 'Set the forj account name to use. By default, it takes the provider name.' +################################# 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 [Provider] [options]', 'set the hpcloud credentials for forj cli' + desc 'setup [AccountName [Provider]] [options]', "Setup FORJ cloud account credentials and information." long_desc <<-LONGDESC -Set the cloud credentials and services for forj. Currently supports only hpcloud provider. +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. +\x5If AccountName is not set without provider, 'hpcloud' provider will be used, by default. + +WARNING! Currently supports only hpcloud provider. + Several data will be requested like: -\x5- access_key: access key from hpcloud -\x5- secret_key: secret key from hpcloud -\x5- auth_uri: identity endpoint -\x5- tenant_id: id for the tenant you want to use -\x5- availability_zone: which availability zone will be deployed +\x5- Cloud provider credentials and services. +\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(sProvider = 'hpcloud') + 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) - Setup.setup(oConfig, options) + 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) end end