Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Removing deprecated rhc- commands.

  • Loading branch information...
commit ae4f7d0fa39edbabb0791c97521e17c64677e162 1 parent 01978a2
Justin Harris authored
View
549 bin/rhc-app
@@ -1,549 +0,0 @@
-#!/usr/bin/env ruby
-
-require 'rhc/coverage_helper'
-
-require 'rhc-common'
-require 'base64'
-
-if ["add-alias", "remove-alias"].include? ARGV[0]
- RHC::Helpers.deprecated_command('rhc alias (add|remove)',true)
-elsif "snapshot" == ARGV[0]
- RHC::Helpers.deprecated_command('rhc snapshot (save|restore)',true)
-elsif "tail" == ARGV[0]
- RHC::Helpers.deprecated_command('rhc tail',true)
-elsif "cartridge" == ARGV[0]
- RHC::Helpers.deprecated_command('rhc cartridge (add|remove|status|stop|start|restart|reload)',true)
-else
- RHC::Helpers.deprecated_command('rhc app (create|delete|show|stop|force-stop|start|restart|reload|tidy)',true)
-end
-
-$embed_mapper = { 'add' => 'configure', 'remove' => 'deconfigure' }
-
-#
-# print help
-#
-def p_usage(exit_code = 255)
- libra_server = get_var('libra_server')
- rhlogin = get_var('default_rhlogin') ? "Default: #{get_var('default_rhlogin')}" : "required"
- type_keys = RHC::get_cartridge_listing(nil, ', ', libra_server, RHC::Config.default_proxy, 'standalone', false)
- puts <<USAGE
-
-Usage: rhc app (<command> | cartridge <cartridge-action> | --help) [<args>]
-Create and manage an OpenShift application.
-
-List of commands
- create Create a new application on OpenShift
- show Display information about a user
- start Starts the application (includes all cartridges)
- stop Stops the application (includes all cartridges)
- force-stop Stops all application processes
- restart Restart the application
- reload Reloads application configuration
- status Returns application status
- destroy Destroys the application
- tidy Garbage collects the git repo and empties log/tmp dirs
- add-alias Add a custom domain name for the application
- remove-alias Remove a custom domain name for the application
- tail Tail the logs of an application
- snapshot [save|restore] Saves/Restores an application snapshot to/from a tarball at the location specified using --filepath (default: ./$APPNAME.tar.gz)
- cartridge <action> Manage a cartridge running in this application
-
-List of cartridge actions
- list List of supported embedded cartridges
- add Add a cartridge to this application
- remove Remove a cartridge from this application
- stop Stop a cartridge
- start Start a cartridge
- restart Restart a cartridge
- status Returns cartridge status
- reload Reloads cartridge configuration
-
-List of arguments
- -l|--rhlogin rhlogin OpenShift login (#{rhlogin})
- -p|--password password Password (optional, will prompt)
- -a|--app application Application name (alphanumeric - max #{RHC::APP_NAME_MAX_LENGTH} chars) (required)
- -t|--type type Type of app to create (#{type_keys}) (required for creating an application)
- -c|--cartridge cartridge The embedded cartrige to manage (required for the cartridge command)
- -g|--gear-size size The size of the gear for this app ([small|medium], defaults to small)
- -s|--scaling Enable scaling for this app
- -r|--repo path Git Repo path (defaults to ./$app_name)
- -n|--nogit Only create remote space, don't pull it locally
- --no-dns Skip DNS check. Must be used in combination with --nogit
- -d|--debug Print Debug info
- -h|--help Show Usage info
- -b|--bypass Bypass warnings (applicable to application destroying only)
- -f|--filepath filepath Applicable in case of snapshot and log command
- -o|--opts options Options to pass to the server-side (linux based) tail command (applicable to tail command only) (-f is implicit. See the linux tail man page full list of options.) (Ex: --opts '-n 100')
- --alias alias Specify server alias (when using add/remove-alias)
- --config path Path of alternate config file
- --timeout # Timeout, in seconds, for the session
- --enable-jenkins [name] Enables builds for your application with Jenkins. You may optionally specify the name of the Jenkins application that is created (default: 'jenkins'). Note that --no-dns is ignored for the creation of the Jenkins application.
-USAGE
-exit exit_code
-end
-
-
-def validate_args(val_type=true, val_cartridge=false, val_timeout=true)
-
- # If provided a config path, check it
- RHC::Config.check_cpath($opt)
-
- # Pull in configs from files
- $libra_server = get_var('libra_server')
- debug = get_var('debug') == 'false' ? nil : get_var('debug')
-
- $opt['rhlogin'] = get_var('default_rhlogin') unless $opt['rhlogin']
- p_usage if !RHC::check_rhlogin($opt['rhlogin'])
-
- p_usage if !RHC::check_app($opt['app'])
-
- if val_type && !$opt['type']
- puts "Application Type is required"
- p_usage
- end
-
- if val_cartridge && !$opt['cartridge']
- puts "Cartridge name is required"
- p_usage
- end
-
- debug = true if $opt.has_key? 'debug'
- RHC::debug(debug)
-
- RHC::timeout($opt["timeout"], get_var('timeout')) if val_timeout
- RHC::connect_timeout($opt["timeout"], get_var('timeout')) if val_timeout
-
- $password = $opt['password'] ? $opt['password'] : RHC::get_password
-end
-
-def create_app
- validate_args
-
- user_info = RHC::get_user_info($libra_server, $opt['rhlogin'], $password, RHC::Config.default_proxy, false)
- app_info = user_info['app_info']
-
- if app_info[$opt['app']]
- puts "An application named '#{$opt['app']}' in namespace '#{user_info['user_info']['domains'][0]['namespace']}' already exists"
- exit 255
- end
-
- jenkins_app_name = nil
- has_jenkins = false
- if $opt['enable-jenkins']
- app_info.each do |app_name, app|
- if app['framework'] == 'jenkins-1.4'
- jenkins_app_name = app_name
- has_jenkins = true
- puts "
-Found existing Jenkins application: #{jenkins_app_name}
-"
- if !$opt['enable-jenkins'].empty?
- puts "Ignoring specified Jenkins app name: #{$opt['enable-jenkins']}"
- end
- end
- end
- if !has_jenkins
- if $opt['type'] =~ /^jenkins-/
- has_jenkins = true
- if $opt['no-dns']
- puts "
-The --no-dns option can't be used in conjunction with --enable-jenkins
-when creating a #{$opt['type']} application. Either remove the --no-dns
-option or first install your #{$opt['type']} application with --no-dns
-and then use 'rhc app cartridge add' to embed the Jenkins client.
-"
- exit 255
- end
- jenkins_app_name = $opt['app']
- puts "
-The Jenkins client will be embedded into the Jenkins application
-currently being created: '#{$opt['app']}'
-"
- end
- end
- if !has_jenkins
- if !$opt['enable-jenkins'].empty?
- jenkins_app_name = $opt['enable-jenkins']
- else
- jenkins_app_name = 'jenkins'
- end
-
- if !RHC::check_app(jenkins_app_name)
- p_usage
- end
-
- if jenkins_app_name == $opt['app']
- puts "You must specify a different name for your application and Jenkins ('#{$opt['app']}')."
- exit 100
- end
-
- if app_info.has_key?(jenkins_app_name)
- puts "You already have an application named '#{jenkins_app_name}'."
- puts "In order to continue you'll need to specify a different name"
- puts "with --enable-jenkins or destroy the existing application."
- exit 100
- end
- end
- end
-
- $opt['gear-size']='small' unless $opt['gear-size']
-
- $opt['repo'] = $opt['app'] unless $opt['repo']
-
- if @mydebug
- puts "
- Found a bug? Post to the forum and we'll get right on it.
- IRC: #openshift on freenode
- Forums: https://openshift.redhat.com/community/forums/openshift
-
- "
- end
-
- #
- # Confirm local git repo exists
- #
- unless $opt['nogit']
- if File.exists?($opt['repo'])
- puts "We will not overwrite an existing git repo. Please remove:"
- puts " #{File.expand_path($opt['repo'])}"
- puts "Then try again."
- puts
- exit 210
- else
- begin
- # Create the parent directory for the git repo
- @git_parent = File.expand_path($opt['repo'] + "/../")
- FileUtils.mkdir_p(@git_parent)
- rescue Exception => e
- puts "Could not write to #{@git_parent}"
- puts "Reason: #{e.message}"
- puts
- puts "Please re-run from a directory you have write access to or specify -r with a"
- puts "path you have write access to"
- puts
- exit 211
- end
- end
- end
-
- if jenkins_app_name && !has_jenkins
- jenkins_app = RHC::create_app($libra_server, RHC::Config.default_proxy, user_info, jenkins_app_name, 'jenkins-1.4', $opt['rhlogin'], $password, nil, false, true, true)
- available = RHC::check_app_available(RHC::Config.default_proxy, jenkins_app[:app_name], jenkins_app[:fqdn], jenkins_app[:health_check_path], jenkins_app[:result], jenkins_app[:git_url], nil, true)
- if !available
- puts "Unable to access your new Jenkins application."
- exit 1
- end
- end
-
- #
- # Create remote application space
- #
- main_app = RHC::create_app($libra_server, RHC::Config.default_proxy, user_info, $opt['app'], $opt['type'], $opt['rhlogin'], $password, $opt['repo'], $opt['no-dns'], $opt['nogit'], false, $opt['gear-size'], $opt['scaling'])
- if jenkins_app_name
- puts "Now embedding the jenkins client into '#{$opt['app']}'..."
- RHC::ctl_app($libra_server, RHC::Config.default_proxy, $opt['app'], $opt['rhlogin'], $password, 'configure', true, 'jenkins-client-1.4', nil, false)
- end
-
- if $opt['no-dns']
- # In case of the no-dns option, the availability check is not made
- # This also results in the git information and app creation result not being displayed
- # Hence, for this case, we print out the git url and result here
- puts "git url: #{main_app[:git_url]}"
- if main_app[:result] && !main_app[:result].empty?
- puts "#{main_app[:result]}"
- end
- else
- available = RHC::check_app_available(RHC::Config.default_proxy, main_app[:app_name], main_app[:fqdn], main_app[:health_check_path], main_app[:result], main_app[:git_url], $opt['repo'], $opt['nogit'])
- if !available
- puts "Unable to access your new application."
- exit 1
- end
- end
-
-end
-
-def get_args(l)
- l.shift
- args = ""
- l.each do|a|
- if (a.to_s.strip.length == 0 || a.to_s.strip.match(/\s/) ); a = "'#{a}'" end
- args += " #{a}"
- end
- args
-end
-
-def show_app
- validate_args(false)
- user_info = RHC::get_user_info($libra_server, $opt['rhlogin'], $password, RHC::Config.default_proxy, true)
-
- app_found = false
- unless user_info['app_info'].empty?
- user_info['app_info'].each do |key, val|
- if key == $opt['app']
- app_found = true
- puts ""
- puts "Application Info"
- puts "================"
- puts key
- puts " Framework: #{val['framework']}"
- puts " Creation: #{val['creation_time']}"
- puts " UUID: #{val['uuid']}"
- puts " Git URL: ssh://#{val['uuid']}@#{key}-#{user_info['user_info']['domains'][0]['namespace']}.#{user_info['user_info']['rhc_domain']}/~/git/#{key}.git/"
- puts " Public URL: http://#{key}-#{user_info['user_info']['domains'][0]['namespace']}.#{user_info['user_info']['rhc_domain']}/"
- if val['aliases'] && !val['aliases'].empty?
- puts " Aliases: #{val['aliases'].join(', ')}"
- end
- puts ""
- puts " Embedded: "
- if val['embedded'] && !val['embedded'].empty?
- val['embedded'].each do |embed_key, embed_val|
- if embed_val.has_key?('info') && !embed_val['info'].empty?
- puts " #{embed_key} - #{embed_val['info']}"
- else
- puts " #{embed_key}"
- end
- end
- else
- puts " None"
- end
- puts ""
-
- # there should be a single application with the given app name
- break
-
- end
- end
- end
-
- if !app_found
- puts
- puts "Could not find app '#{$opt['app']}'. Please run 'rhc domain show' to get a list"
- puts "of your current running applications"
- puts
- exit 1
- end
-
-end
-
-def control_app(command)
- validate_args(false)
-
- if ($opt['alias'] and !(command =~ /-alias$/)) || (command =~ /-alias$/ and ! $opt['alias'])
- puts "When specifying alias make sure to use add-alias or remove-alias command"
- p_usage
- end
-
- command = "deconfigure" if command == "destroy"
-
- if !$opt["bypass"] and command == "deconfigure"
- # deconfigure is the actual hook called on 'destroy'
- # destroy is used for clarity
- puts <<WARNING
-!!!! WARNING !!!! WARNING !!!! WARNING !!!!
-You are about to destroy the #{$opt['app']} application.
-
-This is NOT reversible, all remote data for this application will be removed.
-WARNING
-
- print "Do you want to destroy this application (y/n): "
- begin
- agree = gets.chomp
- if agree != 'y'
- puts "\n"
- exit 217
- end
- rescue Interrupt
- puts "\n"
- exit 217
- end
- end
-
- RHC::ctl_app($libra_server, RHC::Config.default_proxy, $opt['app'], $opt['rhlogin'], $password, command, false, nil, $opt['alias'])
-end
-
-def control_cartridge(command)
- validate_args(false, true)
-
- # override command if it's in the mapper
- command = $embed_mapper[command] if $embed_mapper[command]
- framework = $opt['cartridge']
-
- RHC::ctl_app($libra_server, RHC::Config.default_proxy, $opt['app'], $opt['rhlogin'], $password, command, true, framework, $opt['alias'])
-end
-
-def show_embedded_list
- libra_server = get_var('libra_server')
- puts ""
- puts "List of supported embedded cartridges:"
- puts ""
- type_keys = RHC::get_cartridge_listing(nil, ', ', libra_server, RHC::Config.default_proxy, 'embedded', false)
- puts type_keys
- puts ""
-
- # we should always get something back unless there was an error
- exit 255 if type_keys.length == 0
- exit 0
-end
-
-def save_or_restore_snapshot(command)
- validate_args(false, false, true)
-
- user_info = RHC::get_user_info($libra_server, $opt['rhlogin'], $password, RHC::Config.default_proxy, @mydebug, false)
-
- app = $opt['app']
- $opt['filepath'] = "#{$opt['app']}.tar.gz" unless $opt['filepath']
-
- unless user_info['app_info'][app]
- puts
- puts "Could not find app '#{app}'. Please run 'rhc domain show' to get a list"
- puts "of your current running applications"
- puts
- exit 101
- end
-
- app_uuid = user_info['app_info'][app]['uuid']
- namespace = user_info['user_info']['domains'][0]['namespace']
- rhc_domain = user_info['user_info']['rhc_domain']
-
- if command == 'save'
- status = RHC.snapshot_create rhc_domain, namespace, app, app_uuid, $opt['filepath'], @mydebug
- exit status if ! status
- else
- status = RHC.snapshot_restore rhc_domain, namespace, app, app_uuid, $opt['filepath'], @mydebug
- exit status if ! status
- end
-
-end
-
-begin
- argv_c = ARGV.clone
-
- if ARGV[0] =~ /^create$/
- ARGV.shift
- opts = GetoptLong.new(
- ["--debug", "-d", GetoptLong::NO_ARGUMENT],
- ["--help", "-h", GetoptLong::NO_ARGUMENT],
- ["--rhlogin", "-l", GetoptLong::REQUIRED_ARGUMENT],
- ["--gear-size", "-g", GetoptLong::REQUIRED_ARGUMENT],
- ["--password", "-p", GetoptLong::REQUIRED_ARGUMENT],
- ["--no-dns", GetoptLong::NO_ARGUMENT],
- ["--nogit", "-n", GetoptLong::NO_ARGUMENT],
- ["--app", "-a", GetoptLong::REQUIRED_ARGUMENT],
- ["--repo", "-r", GetoptLong::REQUIRED_ARGUMENT],
- ["--type", "-t", GetoptLong::REQUIRED_ARGUMENT],
- ["--enable-jenkins", GetoptLong::OPTIONAL_ARGUMENT],
- ["--scaling", "-s", GetoptLong::OPTIONAL_ARGUMENT],
- ["--config", GetoptLong::REQUIRED_ARGUMENT],
- ["--timeout", GetoptLong::REQUIRED_ARGUMENT]
- )
- elsif ARGV[0] =~ /^(show|start|stop|force-stop|restart|reload|status|destroy|tidy|add-alias|remove-alias|destroy)$/
- ARGV.shift
- opts = GetoptLong.new(
- ["--debug", "-d", GetoptLong::NO_ARGUMENT],
- ["--help", "-h", GetoptLong::NO_ARGUMENT],
- ["--rhlogin", "-l", GetoptLong::REQUIRED_ARGUMENT],
- ["--password", "-p", GetoptLong::REQUIRED_ARGUMENT],
- ["--app", "-a", GetoptLong::REQUIRED_ARGUMENT],
- ["--alias", GetoptLong::REQUIRED_ARGUMENT],
- ["--bypass", "-b", GetoptLong::NO_ARGUMENT],
- ["--config", GetoptLong::REQUIRED_ARGUMENT],
- ["--timeout", GetoptLong::REQUIRED_ARGUMENT]
- )
- elsif ARGV[0] =~ /^cartridge$/
- ARGV.shift
- ARGV.shift if ARGV[0] =~ /^(add|remove|stop|start|restart|status|reload|list)$/
- opts = GetoptLong.new(
- ["--debug", "-d", GetoptLong::NO_ARGUMENT],
- ["--help", "-h", GetoptLong::NO_ARGUMENT],
- ["--rhlogin", "-l", GetoptLong::REQUIRED_ARGUMENT],
- ["--password", "-p", GetoptLong::REQUIRED_ARGUMENT],
- ["--app", "-a", GetoptLong::REQUIRED_ARGUMENT],
- ["--cartridge", "-c", GetoptLong::REQUIRED_ARGUMENT],
- ["--config", GetoptLong::REQUIRED_ARGUMENT],
- ["--timeout", GetoptLong::REQUIRED_ARGUMENT]
- )
- elsif ARGV[0] =~ /^tail$/
- ARGV.shift
- opts = GetoptLong.new(
- ["--debug", "-d", GetoptLong::NO_ARGUMENT],
- ["--help", "-h", GetoptLong::NO_ARGUMENT],
- ["--rhlogin", "-l", GetoptLong::REQUIRED_ARGUMENT],
- ["--password", "-p", GetoptLong::REQUIRED_ARGUMENT],
- ["--app", "-a", GetoptLong::REQUIRED_ARGUMENT],
- ["--opts", "-o", GetoptLong::REQUIRED_ARGUMENT],
- ["--filepath", "-f", GetoptLong::REQUIRED_ARGUMENT],
- ["--config", GetoptLong::REQUIRED_ARGUMENT],
- ["--timeout", GetoptLong::REQUIRED_ARGUMENT]
- )
- elsif ARGV[0] =~ /^snapshot$/
- ARGV.shift
- ARGV.shift if ARGV[0] =~ /^(save|restore)$/
- opts = GetoptLong.new(
- ["--debug", "-d", GetoptLong::NO_ARGUMENT],
- ["--help", "-h", GetoptLong::NO_ARGUMENT],
- ["--rhlogin", "-l", GetoptLong::REQUIRED_ARGUMENT],
- ["--password", "-p", GetoptLong::REQUIRED_ARGUMENT],
- ["--app", "-a", GetoptLong::REQUIRED_ARGUMENT],
- ["--filepath", "-f", GetoptLong::REQUIRED_ARGUMENT],
- ["--config", GetoptLong::REQUIRED_ARGUMENT],
- ["--timeout", GetoptLong::REQUIRED_ARGUMENT]
- )
- else
- opts = GetoptLong.new(
- ["--help", "-h", GetoptLong::NO_ARGUMENT]
- )
- unless ARGV[0] =~ /^(help|-h|--help)$/
- puts "Missing or invalid command!" unless ARGV[0] =~ /^(help|-h|--help)$/
- # just exit at this point
- # printing the usage description will be handled in the rescue
- exit 255
- end
- end
-
- $opt = {}
- opts.each do |o, a|
- $opt[o[2..-1]] = a.to_s
- end
-
-rescue Exception => e
- p_usage
-end
-
-p_usage 0 if $opt["help"]
-
-case argv_c[0]
- when "create"
- create_app
- when "show"
- show_app
- when "start", "stop", "force-stop", "restart", "reload", "status", "tidy", "add-alias", "remove-alias", "destroy"
- control_app(argv_c[0])
- when "tail"
- system("rhc-tail-files #{get_args argv_c} 2>&1")
- exit $?.exitstatus
- when "snapshot"
- case argv_c[1]
- when "save", "restore"
- save_or_restore_snapshot(argv_c[1])
- else
- puts "Missing or invalid snapshot action!"
- p_usage
- end
- when "cartridge"
- case argv_c[1]
- when "add", "remove", "start", "stop", "restart", "status", "reload"
- control_cartridge(argv_c[1])
- when "list", nil
- show_embedded_list
- else
- puts "Missing or invalid cartridge action!"
- p_usage
- end
- when "-h", "--help", "help", nil
- p_usage 0
- else
- puts "Invalid command!"
- p_usage
-end
-
-exit 0
View
595 bin/rhc-chk
@@ -1,595 +0,0 @@
-#!/usr/bin/env ruby
-
-require 'rhc/coverage_helper'
-
-require 'rhc-common'
-require 'net/http'
-require 'net/https'
-require 'net/ssh'
-require 'rbconfig'
-require 'yaml'
-require 'tempfile'
-require 'rhc/vendor/sshkey'
-
-if RUBY_VERSION.to_f == 1.9
- require 'rubygems'
- gem 'test-unit'#, '~> 1.2.3'
-end
-
-require 'test/unit'
-require 'test/unit/ui/console/testrunner'
-
-class Hash
- # given a potentially nested hash, overwrite the value
- # if the key matches the given key
- def deep_cleanse(key)
- each_pair do |k,v|
- case v
- when Hash
- v.deep_cleanse key
- when Array
- v.map {|e| e.deep_cleanse(key) if e.is_a? Hash}
- else
- if k.to_s == key
- self[k] = "*" * 12
- end
- end
- end
- end
-end
-
-#
-# print help
-#
-def p_usage(exit_code = 255)
- rhlogin = get_var('default_rhlogin') ? "Default: #{get_var('default_rhlogin')}" : "required"
- puts <<USAGE
-
-Usage: rhc domain status
-Run a simple check on local configs and credentials to confirm tools are
-properly setup. Often run to troubleshoot connection issues.
-
- -l|--rhlogin rhlogin OpenShift login (#{rhlogin})
- -p|--password password Password (optional, will prompt)
- -d|--debug Print Debug info
- -h|--help Show Usage info
- --config path Path of alternate config file
- --timeout # Timeout, in seconds, for the session
-
-USAGE
-exit exit_code
-end
-
-warn "#{$0} has been deprecated. Please run 'rhc setup' instead."
-
-begin
- opts = GetoptLong.new(
- ["--debug", "-d", GetoptLong::NO_ARGUMENT],
- ["--help", "-h", GetoptLong::NO_ARGUMENT],
- ["--rhlogin", "-l", GetoptLong::REQUIRED_ARGUMENT],
- ["--password", "-p", GetoptLong::REQUIRED_ARGUMENT],
- ["--config", GetoptLong::REQUIRED_ARGUMENT],
- ["--timeout", GetoptLong::REQUIRED_ARGUMENT]
- )
- $opt = {}
- opts.each do |o, a|
- $opt[o[2..-1]] = a.to_s
- end
-rescue Exception => e
- #puts e.message
- p_usage
-end
-
-if $opt["help"]
- p_usage 0
-end
-
-if 0 != ARGV.length
- p_usage
-end
-
-# If provided a config path, check it
-RHC::Config.check_cpath($opt)
-
-# Need to store the config information so tests can use it
-# since they are technically new objects
-$opts_config_path = @opts_config_path
-$local_config_path = @local_config_path
-$opts_config = @opts_config
-$local_config = @local_config
-$global_config = @global_config
-
-# Pull in configs from files
-$libra_server = get_var('libra_server')
-$debug = get_var('debug') == 'false' ? nil : get_var('debug')
-
-
-if $opt["debug"]
- $debug = true
-end
-RHC::debug($debug)
-
-RHC::timeout($opt["timeout"], get_var('timeout'))
-RHC::connect_timeout($opt["timeout"], get_var('timeout'))
-
-
-$opt["rhlogin"] = get_var('default_rhlogin') unless $opt["rhlogin"]
-if !RHC::check_rhlogin($opt['rhlogin'])
- p_usage
-end
-$rhlogin = $opt["rhlogin"]
-
-$password = $opt['password']
-if !$password
- $password = RHC::get_password
-end
-
-#
-# Generic Info
-#
-$debuginfo = {
- 'environment' => {
- 'Ruby Version' => RUBY_VERSION,
- "host_alias" => (Object.const_get(defined?(RbConfig) ? :RbConfig : :Config))::CONFIG['host_alias'],
- },
- 'options' => {
- "Command Line" => $opt,
- "Opts" => $opts_config,
- "Local" => $local_config,
- "Global" => $global_config
- }
-}
-
-#
-# Check for proxy environment
-#
-$http = RHC::Config.default_proxy
-$debuginfo['environment']['proxy'] = (RHC::Config.using_proxy? ? ENV['http_proxy'] : "none")
-
-#####################################
-# Done setting up environment #
-#####################################
-
-module TestBase
- def initialize(*args)
- super
- $connectivity ||= false
- # These need to be loaded for each test to be able to access them
- @opts_config_path = $opts_config_path
- @local_config_path = $local_config_path
- @opts_config = $opts_config
- @local_config = $local_config
- @global_config = $global_config
- end
-
- def fetch_url_json(uri, data)
- json_data = RHC::generate_json(data)
- url = URI.parse("https://#{$libra_server}#{uri}")
- req = $http::Post.new(url.path)
- req.set_form_data({'json_data' => json_data, 'password' => $password})
- http = $http.new(url.host, url.port)
- http.open_timeout = 10
- http.use_ssl = true
- http.verify_mode = OpenSSL::SSL::VERIFY_NONE
-
- response = http.start {|http| http.request(req)}
- return response
- ensure
- unless response.nil?
- $debuginfo['fetches'] ||= []
- body = RHC::json_decode(response.body)
- body['data'] = body['data'] && body['data'] != '' ? RHC::json_decode(body['data']) : ''
- $debuginfo['fetches'] << {url.to_s => {
- 'body' => body.deep_cleanse('password'),
- 'header' => response.instance_variable_get(:@header)
- }}
- end
- end
-
- def continue_test
- begin
- yield
- rescue Test::Unit::AssertionFailedError => e
- self.send(:add_failure,e.message,e.backtrace)
- end
- end
-end
-
-#####################################################
-# Tests start here #
-#####################################################
-# #
-# Note: Tests and testcases are run alphabetically #
-# #
-#####################################################
-
-def error_for(name,*args)
- # Make sure the name is a downcased symbol
- name = name.to_s.downcase.to_sym
-
- # Create message template
- message = [:errors,:solutions].map{|x| get_message(x,name) }.compact.join("\n")
-
- # Params for message template
- params = args.flatten
-
- # Ensure we have the right number of placeholders
- num_placeholders = message.scan("%s").length
- unless num_placeholders == params.length
- warn("\nWARNING: error_for called with wrong number of args from: \n\t%s\n" % caller[0]) if $debug
- # This will ensure we have the right number of arguments, but should not get here
- params << Array.new(num_placeholders,"???")
- end
-
- # Return the message
- message % params.flatten
-end
-
-def get_message(type,name)
- val = $messages[type][name]
- if val.is_a? Symbol
- val = get_message(type,val)
- end
- val
-end
-
-# This test tries to make sure we have the keys unlocked before testing
-# to ensure nicer workflow
-class Test0_SSH_Keys_Unlocked < Test::Unit::TestCase
- include TestBase
-
- def test_ssh_quick
- begin
- # Get user info from OpenShift
- data = {'rhlogin' => $rhlogin}
- response = fetch_url_json("/broker/userinfo", data)
- resp_json = RHC::json_decode(response.body)
- user_info = RHC::json_decode(resp_json['data'].to_s)
-
- # Get any keys Net::SSH thinks we'll need
- $ssh = Net::SSH
- needed_keys =
- user_info['app_info'].map do |name,opts|
- host = "%s-%s.%s" % [
- name,
- user_info['user_info']['namespace'],
- user_info['user_info']['rhc_domain']
- ]
- $ssh.configuration_for(host)[:keys].map{|f| File.expand_path(f)}
- end.compact.flatten
-
- agent_keys = Net::SSH::Authentication::Agent.connect.identities.map{|x| x.comment }
- missing_keys = needed_keys - agent_keys
-
- unless missing_keys.empty?
- $stderr.puts "\n NOTE: These tests may require you to unlock one or more of your SSH keys \n\n"
- end
- rescue
- end
- end
-
-end
-
-class Test1_Connectivity < Test::Unit::TestCase
- include TestBase
- def teardown
- # Set global variable in case we cannot connect to the server
- if method_name == 'test_connectivity'
- $connectivity = passed?
- end
- end
-
- #
- # Checking Connectivity / cart list
- #
- def test_connectivity
- data = {'cart_type' => 'standalone'}
-
- response = fetch_url_json("/broker/cartlist", data)
- assert_equal 200, response.code.to_i, error_for(:no_connectivity, $libra_server)
- end
-end
-
-class Test2_Authentication < Test::Unit::TestCase
- include TestBase
- #
- # Checking Authentication
- #
- def test_authentication
- assert $connectivity, error_for(:cant_connect)
-
- data = {'rhlogin' => $rhlogin}
- response = fetch_url_json("/broker/userinfo", data)
- resp_json = RHC::json_decode(response.body)
-
- case response.code.to_i
- when 404
- assert false, error_for(:_404, $rhlogin)
- when 401
- assert false, error_for(:_401, $rhlogin)
- when 200
- assert true
- else
- assert false, error_for(:_other_http, resp_json['result'])
- end
-
- $user_info = RHC::json_decode(resp_json['data'].to_s)
- end
-end
-
-#
-# Checking ssh key
-#
-class Test3_SSH < Test::Unit::TestCase
-
-
- include TestBase
-
- def setup
- @libra_kfile = get_kfile(false)
- if @libra_kfile
- @libra_kpfile = get_kpfile(@libra_kfile, false)
- end
- end
-
- def require_login(test)
- flunk(error_for(:no_account,test)) if $user_info.nil?
- end
-
- def require_domain(test)
- flunk(error_for(:no_domain,test)) if $user_info['user_info']['domains'].empty?
- end
-
- def require_remote_keys(test)
- require_login(test)
- require_domain(test)
- @@remote_pub_keys ||= (
- ssh_keys = RHC::get_ssh_keys($libra_server, $rhlogin, $password, $http)
- my_keys = [ssh_keys['ssh_key'], ssh_keys['keys'].values.map{|k| k['key']}].flatten
- my_keys.delete_if{|x| x.length == 0 }
- my_keys
- )
-
- missing_keys = [:nil?,:empty?].map{|f| @@remote_pub_keys.send(f) rescue false }.inject(:|)
-
- flunk(error_for(:no_remote_pub_keys,test)) if missing_keys
- end
-
- def require_agent_keys(fatal = true)
- @@agent_keys ||= (
- begin
- Net::SSH::Authentication::Agent.connect.identities
- rescue Exception
- nil
- end
- )
- flunk(error_for(:no_keys_loaded)) if (fatal && @@agent_keys.nil?)
- end
-
- def agent_key_names
- @@agent_keys.nil? ? nil : @@agent_keys.map{|x| File.expand_path(x.comment) }
- end
-
- def agent_key_fingerprints
- @@agent_keys.nil? ? nil : @@agent_keys.map{|x| x.fingerprint }
- end
-
- def libra_public_key
- @@local_ssh_pubkey ||= libra_public_key_content.split(' ')[1]
- end
-
- def libra_public_key_content
- @@local_ssh_pubkey_content ||= (
- fp = File.open(@libra_kpfile)
- fp.gets
- )
- ensure
- fp.close if fp
- end
-
- def libra_public_key_fingerprint
- @@local_ssh_pubkey_fingerprint ||= Net::SSH::KeyFactory.load_data_public_key(libra_public_key_content).fingerprint
- end
-
- def test_01_local_files
- [
- [@libra_kfile, /[4-7]00/], # Needs to at least be readable by user and nobody else
- [@libra_kpfile, /.../], # Any permissions are OK
- ].each do |args|
- continue_test{check_permissions(*args)}
- end
- end
-
- def test_02_ssh_agent
- require_agent_keys
-
- assert agent_key_fingerprints.include?(libra_public_key_fingerprint) ,error_for(:pubkey_not_loaded, ": #{@libra_kpfile}")
- end
-
- def test_03_remote_ssh_keys
- require_remote_keys("whether your local SSH keys match the ones in your account")
- require_agent_keys(false)
-
- assert !(@@remote_pub_keys & [agent_key_fingerprints,libra_public_key].flatten).empty? ,error_for(:pubkey_not_loaded," ")
- end
-
- def test_04_ssh_connect
- require_login("connecting to your applications")
- require_domain("connecting to your applications")
-
- host_template = "%%s-%s.%s" % [
- $user_info['user_info']['domains'][0]['namespace'],
- $user_info['user_info']['rhc_domain']
- ]
- $user_info['app_info'].each do |k,v|
- uuid = v['uuid']
- hostname = host_template % k
- timeout = 10
- begin
- @ssh = Net::SSH.start(hostname,uuid,{:timeout => timeout})
- rescue Timeout::Error
- if timeout < 30
- timeout += 10
- retry
- end
- ensure
- continue_test{ assert_not_nil @ssh, error_for(:cant_ssh, hostname) }
- @ssh.close if @ssh
- end
- end
- end
-
- private
- def check_permissions(file,permission)
- # IO#stat is platform-specific, on windows it's usually 644 but in fact it doesn't matter
- permission = /.../ if RHC::Helpers.windows?
-
- file = File.expand_path(file)
-
- assert File.exists?(file), error_for(:file_not_found,file)
-
- perms = sprintf('%o',File.stat(file).mode)[-3..-1]
-
- assert_match(permission, perms, error_for(:bad_permissions,[file,perms],permission.source))
- end
-end
-
-############################################################
-# Below this line is the custom Test::Runner code #
-# Modification should not be necessary to add/modify tests #
-############################################################
-
-class CheckRunner < Test::Unit::UI::Console::TestRunner
- def initialize(*args)
- super
- @output_level = 1
- puts get_message(:status,:started)
- end
-
- def add_fault(fault)
- @faults << fault
- print(fault.single_character_display)
- @already_outputted = true
- end
-
- def print_underlined(string)
- string = "|| #{string} ||"
- line = "=" * string.length
- puts
- puts line
- puts string
- puts line
- end
-
- def render_message(message)
- lines = message.send(message.respond_to?(:lines) ? :lines : :to_s).to_a
- message = []
- @num ||= 0
- message << "#{@num+=1}) #{lines.shift.strip}"
- lines.each do |line|
- # Break if we get the standard assert error information or a blank line
- break if line.match(/^\<.*?> /) or line.match(/^\s*$/)
- message << "\t#{line.strip}"
- end
- message.join("\n")
- end
-
- def finished(*args)
- super
- $debuginfo['errors'] = @faults
-
- if @faults.empty?
- print_underlined get_message(:status,:passed)
- else
- print_underlined get_message(:status,:failed)
- @errors = []
- # Need to separate the failures from the errors
-
- @faults.each do |f|
- case f
- when Test::Unit::Failure
- puts render_message(f.message)
- when Test::Unit::Error
- @errors << f
- end
- end
-
- # Errors mean something in the test is broken, not just failed
- unless @errors.empty?
- @num = 0
- print_underlined get_message(:status,:error)
- @errors.each do |e|
- display = e.long_display
- lines = display.send(display.respond_to?(:lines) ? :lines : :to_s).to_a[1..-1]
- puts "#{@num+=1}) #{lines.shift}"
- lines.each{|l| puts "\t#{l}"}
- end
- end
-
- end
-
- if $debug
- Tempfile.open(%w(rhc-chk. .log))do |file|
- ObjectSpace.undefine_finalizer(file) # persist tempfile
- file.write $debuginfo.deep_cleanse('password').to_yaml
- puts
- puts "Debugging information dumped to #{file.path}"
- end
- end
- end
-end
-
-# Need to register the default runner differently using the standard test-unit and the gem
-proc{|*r| CheckRunner}.tap do |_proc|
- if Test::Unit::AutoRunner.respond_to?(:register_runner)
- Test::Unit::AutoRunner.register_runner(:console, _proc)
- else
- Test::Unit::AutoRunner::RUNNERS[:console] = _proc
- end
-end
-
-############################
-# The following are the error messages to be used for different tests
-# You need to specify a value in :errors
-# If there is a solution, it may also be specified in :solutions
-#
-# Values in may be reused by specifying another symbol as the value
-# for instance the following will use the solution for :bar as the solution for :foo
-#
-# :solutions
-# :foo: :bar
-############################
-$messages = YAML.load <<-EOF
----
-:status:
- :started: Analyzing system
- :passed: Congratulations, your system has passed all tests
- :failed: Your system did not pass all of the tests
- :error: Something went wrong, and not all tests completed
-:errors:
- :no_derive: "We were unable to derive your public SSH key and compare it to the remote"
- :no_connectivity: "Cannot connect to server, therefore most tests will not work"
- :no_account: "You must have an account on the server in order to test: %s"
- :no_domain: "You must have a domain associated with this account in order to test: %s"
- :cant_connect: You need to be able to connect to the server in order to test authentication
- :no_match_pub: "Local %s does not match remote pub key, SSH auth will not work"
- :_404: "The user %s does not have an account on this server"
- :no_pubkey: We were unable to read your public SSH key to compare to %s
- :_401: "Invalid user credentials for %s"
- :file_not_found: File %s does not exist, cannot check permissions
- :_other_http: "There was an error communicating with the server: %s"
- :bad_permissions: "File %s has incorrect permissions %s"
- :no_keys_loaded: Either ssh-agent is not running or you do not have any keys loaded
- :pubkey_not_loaded: "Your public key is not loaded into a running ssh-agent%s"
- :cant_ssh: "Cannot SSH into your app: %s"
- :no_remote_pub_keys: "You do not have any public keys associated with your OpenShift account. Cannot test: %s"
-:solutions:
- :no_connectivity: "Ensure that you are able to connect to %s"
- :no_match_pub: "Perhaps you should regenerate your public key, or run 'rhc sshkey add' to add your new key"
- :_404: "Please ensure that you've entered the correct username or that you've created an account"
- :_401: "Please ensure you used the correct password"
- :bad_permissions: "Permissions should match %s"
- :no_remote_pub_keys: "You should try to add your ssh-key by running 'rhc sshkey add'"
- :pubkey_not_loaded: If this is your only error, your connection may still work, depending on your SSH configuration
- :no_keys_loaded: If this is your only error, your connection may still work, depending on your SSH configuration
-EOF
View
249 bin/rhc-create-app
@@ -1,249 +0,0 @@
-#!/usr/bin/env ruby
-
-require 'rhc/coverage_helper'
-
-require 'rhc-common'
-
-RHC::Helpers.deprecated_command('rhc app create',true)
-
-def p_usage(error_code = 255)
- libra_server = get_var('libra_server')
- rhlogin = get_var('default_rhlogin') ? "Default: #{get_var('default_rhlogin')}" : "required"
- type_keys = RHC::get_cartridge_listing(nil, ', ', libra_server, RHC::Config.default_proxy, 'standalone', false)
- puts <<USAGE
-
-Usage: #{$0}
-Create an OpenShift app.
-
- -a|--app application Application name (alphanumeric - max #{RHC::APP_NAME_MAX_LENGTH} chars) (required)
- -t|--type type Type of app to create (#{type_keys}) (required)
- -g|--gear-size size The size of the gear for this app ([small|medium], defaults to small)
- -s|--scaling Enable scaling for this app
- -l|--rhlogin rhlogin OpenShift login (#{rhlogin})
- -p|--password password Password (optional, will prompt)
- -r|--repo path Git Repo path (defaults to ./$app_name)
- -n|--nogit Only create remote space, don't pull it locally
- -d|--debug Print Debug info
- -h|--help Show Usage info
- --no-dns Skip DNS check. Must be used in combination with --nogit
- --config path Path of alternate config file
- --timeout # Timeout, in seconds, for the session
- --enable-jenkins [name] Create a Jenkins application (see Note 1)
-
-Notes:
-1. Jenkins applications will have Jenkins embedded. Their default name will be 'jenkins' if not specified and the '--no-dns' flag is ignored.
-
-USAGE
-exit error_code
-end
-
-begin
- opts = GetoptLong.new(
- ["--debug", "-d", GetoptLong::NO_ARGUMENT],
- ["--help", "-h", GetoptLong::NO_ARGUMENT],
- ["--no-dns", GetoptLong::NO_ARGUMENT],
- ["--nogit", "-n", GetoptLong::NO_ARGUMENT],
- ["--rhlogin", "-l", GetoptLong::REQUIRED_ARGUMENT],
- ["--password", "-p", GetoptLong::REQUIRED_ARGUMENT],
- ["--app", "-a", GetoptLong::REQUIRED_ARGUMENT],
- ["--repo", "-r", GetoptLong::REQUIRED_ARGUMENT],
- ["--config", GetoptLong::REQUIRED_ARGUMENT],
- ["--type", "-t", GetoptLong::REQUIRED_ARGUMENT],
- ["--gear-size", "-g", GetoptLong::REQUIRED_ARGUMENT],
- ["--timeout", GetoptLong::REQUIRED_ARGUMENT],
- ["--enable-jenkins", GetoptLong::OPTIONAL_ARGUMENT],
- ["--scaling", "-s", GetoptLong::OPTIONAL_ARGUMENT]
- )
- opt = {}
- opts.each do |o, a|
- opt[o[2..-1]] = a.to_s
- end
-rescue Exception => e
- #puts e.message
- p_usage
-end
-
-
-# If provided a config path, check it
-RHC::Config.check_cpath(opt)
-
-# Pull in configs from files
-libra_server = get_var('libra_server')
-debug = get_var('debug') == 'false' ? nil : get_var('debug')
-
-p_usage 0 if opt["help"]
-
-p_usage if 0 != ARGV.length
-
-debug = true if opt["debug"]
-
-RHC::debug(debug)
-
-RHC::timeout(opt['timeout'], get_var('timeout'))
-RHC::connect_timeout(opt["timeout"], get_var('timeout'))
-
-opt['rhlogin'] = get_var('default_rhlogin') unless opt['rhlogin']
-
-if !RHC::check_rhlogin(opt['rhlogin'])
- p_usage
-end
-
-if !RHC::check_app(opt['app'])
- p_usage
-end
-
-if !opt['type']
- puts 'Type is required'
- p_usage
-end
-
-if !opt['rhlogin'] || !opt['app'] || !opt['type']
- p_usage
-end
-
-# Default gear size is small
-gear_size = opt['gear-size']
-gear_size = 'small' if !gear_size
-
-
-password = opt['password']
-if !password
- password = RHC::get_password
-end
-
-user_info = RHC::get_user_info(libra_server, opt['rhlogin'], password, RHC::Config.default_proxy, false)
-app_info = user_info['app_info']
-
-if app_info[opt['app']]
- puts "An application named '#{opt['app']}' in namespace '#{user_info['user_info']['domains'][0]['namespace']}' already exists"
- exit 255
-end
-
-jenkins_app_name = nil
-has_jenkins = false
-if opt['enable-jenkins']
- app_info.each do |app_name, app|
- if app['framework'] == 'jenkins-1.4'
- jenkins_app_name = app_name
- has_jenkins = true
- puts "
-Found existing Jenkins application: #{jenkins_app_name}
-"
- if !opt['enable-jenkins'].empty?
- puts "Ignoring specified Jenkins app name: #{opt['enable-jenkins']}"
- end
- end
- end
- if !has_jenkins
- if opt['type'] =~ /^jenkins-/
- has_jenkins = true
- if opt['no-dns']
- puts "
-The --no-dns option can't be used in conjunction with --enable-jenkins
-when creating a #{opt['type']} application. Either remove the --no-dns
-option or first install your #{opt['type']} application with --no-dns
-and then use rhc-ctl-app to embed the Jenkins client.
-"
- exit 255
- end
- jenkins_app_name = opt['app']
- puts "
-The Jenkins client will be embedded into the Jenkins application
-currently being created: '#{opt['app']}'
-"
- end
- end
- if !has_jenkins
- if !opt['enable-jenkins'].empty?
- jenkins_app_name = opt['enable-jenkins']
- else
- jenkins_app_name = 'jenkins'
- end
-
- if !RHC::check_app(jenkins_app_name)
- p_usage
- end
-
- if jenkins_app_name == opt['app']
- puts "You must specify a different name for your application and Jenkins ('#{opt['app']}')."
- exit 100
- end
-
- if app_info.has_key?(jenkins_app_name)
- puts "You already have an application named '#{jenkins_app_name}'."
- puts "In order to continue you'll need to specify a different name"
- puts "with --enable-jenkins or destroy the existing application."
- exit 100
- end
- end
-end
-
-opt['repo'] = opt['app'] unless opt['repo']
-
-if @mydebug
- puts "
- Found a bug? Post to the forum and we'll get right on it.
- IRC: #openshift on freenode
- Forums: https://openshift.redhat.com/community/forums/openshift
-
- "
-end
-
-#
-# Confirm local git repo exists
-#
-unless opt['nogit']
- if File.exists?(opt['repo'])
- puts "We will not overwrite an existing git repo. Please remove:"
- puts " #{File.expand_path(opt['repo'])}"
- puts "Then try again."
- puts
- exit 210
- else
- begin
- # Create the parent directory for the git repo
- @git_parent = File.expand_path(opt['repo'] + "/../")
- FileUtils.mkdir_p(@git_parent)
- rescue Exception => e
- puts "Could not write to #{@git_parent}"
- puts "Reason: #{e.message}"
- puts
- puts "Please re-run from a directory you have write access to or specify -r with a"
- puts "path you have write access to"
- puts
- exit 211
- end
- end
-end
-
-if jenkins_app_name && !has_jenkins
- jenkins_app = RHC::create_app(libra_server, RHC::Config.default_proxy, user_info, jenkins_app_name, 'jenkins-1.4', opt['rhlogin'], password, nil, false, true, true)
- available = RHC::check_app_available(RHC::Config.default_proxy, jenkins_app[:app_name], jenkins_app[:fqdn], jenkins_app[:health_check_path], jenkins_app[:result], jenkins_app[:git_url], nil, true)
- if !available
- puts "Unable to access your new Jenkins application."
- exit 1
- end
-end
-
-#
-# Create remote application space
-#
-main_app = RHC::create_app(libra_server, RHC::Config.default_proxy, user_info, opt['app'], opt['type'], opt['rhlogin'], password, opt['repo'], opt['no-dns'], opt['nogit'], false, gear_size, opt['scaling'])
-
-if !main_app
- puts "Create app failed"
- exit 1
-end
-
-if jenkins_app_name
- puts "Now embedding the jenkins client into '#{opt['app']}'..."
- RHC::ctl_app(libra_server, RHC::Config.default_proxy, opt['app'], opt['rhlogin'], password, 'configure', true, 'jenkins-client-1.4', nil, false)
-end
-
-unless opt['no-dns']
- available = RHC::check_app_available(RHC::Config.default_proxy, main_app[:app_name], main_app[:fqdn], main_app[:health_check_path], main_app[:result], main_app[:git_url], opt['repo'], opt['nogit'])
- if !available
- puts "Unable to access your new application."
- exit 1
- end
-end
View
190 bin/rhc-create-domain
@@ -1,190 +0,0 @@
-#!/usr/bin/env ruby
-
-require 'rhc/coverage_helper'
-
-require 'rhc-common'
-
-RHC::Helpers.deprecated_command('rhc domain (create|update)',true)
-
-#
-# print help
-#
-def p_usage(exit_code = 255)
- rhlogin = get_var('default_rhlogin') ? "Default: #{get_var('default_rhlogin')}" : "required"
- puts <<USAGE
-
-Usage: #{$0}
-Bind a registered rhcloud user to a domain in rhcloud.
-
- NOTE: to change ssh key, alter your openshift <id_rsa> and
- <id_rsa>.pub keys, then re-run with --alter
-
- -n|--namespace namespace Namespace for your application(s) (alphanumeric - max #{RHC::DEFAULT_MAX_LENGTH} chars) (required)
- -l|--rhlogin rhlogin OpenShift login (#{rhlogin})
- -p|--password password Password (optional, will prompt)
- -a|--alter Alter namespace (will change urls) and/or ssh key
- -d|--debug Print Debug info
- -h|--help Show Usage info
- --config path Path of alternate config file
- --timeout # Timeout, in seconds, for the session
-
-USAGE
-exit exit_code
-end
-
-begin
- opts = GetoptLong.new(
- ["--debug", "-d", GetoptLong::NO_ARGUMENT],
- ["--help", "-h", GetoptLong::NO_ARGUMENT],
- ["--rhlogin", "-l", GetoptLong::REQUIRED_ARGUMENT],
- ["--password", "-p", GetoptLong::REQUIRED_ARGUMENT],
- ["--namespace", "-n", GetoptLong::REQUIRED_ARGUMENT],
- ["--config", GetoptLong::REQUIRED_ARGUMENT],
- ["--alter", "-a", GetoptLong::NO_ARGUMENT],
- ["--timeout", GetoptLong::REQUIRED_ARGUMENT]
- )
-
- opt = {}
- opts.each do |o, a|
- opt[o[2..-1]] = a.to_s
- end
-rescue Exception => e
- #puts e.message
- p_usage
-end
-
-# If provided a config path, check it
-RHC::Config.check_cpath(opt)
-
-# Pull in configs from files
-libra_server = get_var('libra_server')
-debug = get_var('debug') == 'false' ? nil : get_var('debug')
-opt['rhlogin'] = get_var('default_rhlogin') unless opt['rhlogin']
-
-ssh_key_file_path = get_kfile(false)
-ssh_pub_key_file_path = get_kpfile(ssh_key_file_path, opt['alter'])
-
-ssh_config = "#{ENV['HOME']}/.ssh/config"
-ssh_config_d = "#{ENV['HOME']}/.ssh/"
-
-p_usage 0 if opt["help"]
-p_usage if 0 != ARGV.length
-
-
-debug = true if opt["debug"]
-
-RHC::debug(debug)
-
-RHC::timeout(opt["timeout"], get_var('timeout'))
-RHC::connect_timeout(opt["timeout"], get_var('timeout'))
-
-if !RHC::check_namespace(opt['namespace'])
- p_usage
-end
-
-if !RHC::check_rhlogin(opt['rhlogin'])
- p_usage
-end
-
-
-if !opt["rhlogin"] || !opt["namespace"]
- p_usage
-end
-
-password = opt['password']
-if !password
- password = RHC::get_password
-end
-
-#
-# Check to see if a ssh_key_file_path exists, if not create it.
-#
-
-if File.readable?(ssh_key_file_path)
- puts "OpenShift key found at #{ssh_key_file_path}. Reusing..."
-else
- puts "Generating OpenShift ssh key to #{ssh_key_file_path}"
- # Use system for interaction
- system("ssh-keygen -t rsa -f '#{ssh_key_file_path}'")
-end
-
-ssh_keyfile_contents = File.open(ssh_pub_key_file_path).gets.chomp.split(' ')
-ssh_key = ssh_keyfile_contents[1]
-ssh_key_type = ssh_keyfile_contents[0]
-
-data = {'namespace' => opt['namespace'],
- 'rhlogin' => opt['rhlogin'],
- 'ssh' => ssh_key,
- 'key_type' => ssh_key_type}
-
-if (opt['alter'])
- data[:alter] = true
- not_found_message = "A user with rhlogin '#{opt['rhlogin']}' does not have a registered domain. Be sure to run rhc-create-domain without -a|--alter first."
- user_info = RHC::get_user_info(libra_server, opt['rhlogin'], password, RHC::Config.default_proxy, true, not_found_message)
-end
-if debug
- data[:debug] = true
-end
-RHC::print_post_data(data)
-json_data = RHC::generate_json(data)
-
-url = URI.parse("https://#{libra_server}/broker/domain")
-response = RHC::http_post(RHC::Config.default_proxy, url, json_data, password)
-
-if response.code == '200'
- begin
- json_resp = RHC::json_decode(response.body)
- RHC::print_response_success(json_resp)
- if opt['alter'] != ''
- puts <<EOF
-Creation successful
-
-You may now create an application.
-
-EOF
- else
- app_info = user_info['app_info']
- dns_success = true
- if !app_info.empty? && opt['namespace'] != user_info['user_info']['domains'][0]['namespace']
- #
- # Confirm that the host(s) exist in DNS
- #
- puts "Now your new domain name(s) are being propagated worldwide (this might take a minute)..."
- # Allow DNS to propogate
- sleep 15
- app_info.each_key do |appname|
- fqdn = "#{appname}-#{opt['namespace']}.#{user_info['user_info']['rhc_domain']}"
-
- # Now start checking for DNS
- loop = 0
- sleep_time = 2
- while loop < RHC::MAX_RETRIES && !RHC::hostexist?(fqdn)
- sleep sleep_time
- loop+=1
- puts " retry # #{loop} - Waiting for DNS: #{fqdn}"
- sleep_time = RHC::delay(sleep_time)
- end
-
- if loop >= RHC::MAX_RETRIES
- puts "Host could not be found: #{fqdn}"
- dns_success = false
- end
- end
- puts "You can use rhc-domain-info to view any url changes. Be sure to update any links"
- puts "including the url in your local git config: <local_git_repo>/.git/config"
- end
- if dns_success
- puts "Alteration successful."
- else
- puts "Alteration successful but at least one of the urls is still updating in DNS."
- end
- puts ""
- end
- exit 0
- rescue RHC::JsonError
- RHC::print_response_err(response)
- end
-else
- RHC::print_response_err(response)
-end
-exit 1
View
180 bin/rhc-ctl-app
@@ -1,180 +0,0 @@
-#!/usr/bin/env ruby
-
-require 'rhc/coverage_helper'
-
-require 'rhc-common'
-if ARGV.include? "--alias"
- RHC::Helpers.deprecated_command('rhc alias (add|remove)',true)
-elsif ARGV.include? "-e" or ARGV.include? "--embed"
- RHC::Helpers.deprecated_command('rhc cartridge (add|remove)',true)
-elsif ARGV.include? "-L" or ARGV.include? "--embed-list"
- RHC::Helpers.deprecated_command('rhc cartridge list',true)
-else
- RHC::Helpers.deprecated_command('rhc app (start|stop|force-stop|restart|reload|status|destroy|tidy)',true)
-end
-
-embed_mapper = { 'add' => 'configure', 'remove' => 'deconfigure' }
-
-def p_usage(exit_code = 255)
- rhlogin = get_var('default_rhlogin') ? "Default: #{get_var('default_rhlogin')}" : "required"
- puts <<USAGE
-
-Usage: #{$0}
-Control an OpenShift express app
-
- -a|--app application Application name (alphanumeric) (required)
- -l|--rhlogin rhlogin OpenShift login (#{rhlogin})
- -p|--password password Password (optional, will prompt)
- -c|--command command (start|stop|force-stop|restart|reload|status|destroy|tidy|add-alias|remove-alias)
- -L|--embedded-list List supported embedded cartridges
- -e|--embed (add|remove|stop|start|restart|status|reload)-$cartridge eg: add-mysql-5.1
- -b|--bypass Bypass warnings
- -d|--debug Print Debug info
- -h|--help Show Usage info
- --alias Specify server alias (when using add/remove-alias)
- --config path Path of alternate config file
- --timeout # Timeout, in seconds, for the session
-
-USAGE
-exit exit_code
-end
-
-def p_embedded_list
- libra_server = get_var('libra_server')
- puts ""
- puts "List of supported embedded cartridges:"
- puts ""
- type_keys = RHC::get_cartridge_listing(nil, ', ', libra_server, RHC::Config.default_proxy, 'embedded', false)
- puts type_keys
- puts ""
- exit 255
-end
-
-begin
- opts = GetoptLong.new(
- ["--debug", "-d", GetoptLong::NO_ARGUMENT],
- ["--help", "-h", GetoptLong::NO_ARGUMENT],
- ["--bypass", "-b", GetoptLong::NO_ARGUMENT],
- ["--embedded-list", "-L", GetoptLong::NO_ARGUMENT],
- ["--rhlogin", "-l", GetoptLong::REQUIRED_ARGUMENT],
- ["--embed", "-e", GetoptLong::REQUIRED_ARGUMENT],
- ["--password", "-p", GetoptLong::REQUIRED_ARGUMENT],
- ["--app", "-a", GetoptLong::REQUIRED_ARGUMENT],
- ["--alias", GetoptLong::REQUIRED_ARGUMENT],
- ["--config", GetoptLong::REQUIRED_ARGUMENT],
- ["--command", "-c", GetoptLong::REQUIRED_ARGUMENT],
- ["--timeout", GetoptLong::REQUIRED_ARGUMENT]
- )
- opt = {}
- opts.each do |o, a|
- opt[o[2..-1]] = a.to_s
- end
-rescue Exception => e
- #puts e.message
- p_usage
-end
-
-# If provided a config path, check it
-RHC::Config.check_cpath(opt)
-
-# Pull in configs from files
-libra_server = get_var('libra_server')
-debug = get_var('debug') == 'false' ? nil : get_var('debug')
-ssh_config = "#{ENV['HOME']}/.ssh/config"
-ssh_config_d = "#{ENV['HOME']}/.ssh/"
-
-if opt["embedded-list"]
- p_embedded_list
-end
-p_usage 0 if opt["help"]
-p_usage if 0 != ARGV.length
-
-debug = true if opt["debug"]
-
-RHC::debug(debug)
-
-RHC::timeout(opt["timeout"], get_var('timeout'))
-RHC::connect_timeout(opt["timeout"], get_var('timeout'))
-
-opt["rhlogin"] = get_var('default_rhlogin') unless opt["rhlogin"]
-
-if !RHC::check_rhlogin(opt['rhlogin'])
- p_usage
-end
-
-if !RHC::check_app(opt['app'])
- p_usage
-end
-
-unless opt["embed"] or opt["command"]
- puts "Command or embed is required"
- p_usage
-end
-
-if opt["command"]
- unless opt["command"] =~ /^(start|stop|force-stop|restart|reload|status|destroy|tidy|add-alias|remove-alias)$/
- puts "Invalid command '#{opt["command"]}' specified. Valid commands are (start|stop|force-stop|restart|reload|status|destroy|tidy|add-alias|remove-alias)"
- p_usage
- end
-elsif opt["embed"]
- action = opt['embed'].split('-')[0]
- unless action =~ /^(add|remove|start|stop|restart|status|reload)$/
- puts "Invalid embed action '#{action}' specified. Valid embed actions are (add|remove|start|stop|restart|status|reload)"
- p_usage
- end
-end
-
-unless opt['rhlogin'] && opt['app'] && (opt['command'] || opt['embed'])
- p_usage
-end
-
-if opt['command'] and (opt['alias'] and !(opt['command'] =~ /-alias$/)) || ((opt['command'] =~ /-alias$/) and ! opt['alias'])
- puts "When specifying alias make sure to use -c add-alias or -c remove-alias"
- p_usage
-end
-
-password = opt['password']
-if !password
- password = RHC::get_password
-end
-
-opt["command"] = "deconfigure" if opt["command"] == "destroy"
-
-if !opt["bypass"] and opt["command"] == "deconfigure"
- # deconfigure is the actual hook called on 'destroy'
- # destroy is used for clarity
-
-
- puts <<WARNING
-!!!! WARNING !!!! WARNING !!!! WARNING !!!!
-You are about to destroy the #{opt['app']} application.
-
-This is NOT reversible, all remote data for this application will be removed.
-WARNING
-
- print "Do you want to destroy this application (y/n): "
- begin
- agree = gets.chomp
- if agree != 'y'
- puts "\n"
- exit 217
- end
- rescue Interrupt
- puts "\n"
- exit 217
- end
-end
-
-framework = nil
-if opt['embed']
- action = opt['embed'].split('-')[0]
- # override action if it's in the mapper
- action = embed_mapper[opt['embed'].split('-')[0]] if embed_mapper[opt['embed'].split('-')[0]]
- framework = opt['embed'].split('-')[1..-1].join('-')
- url = URI.parse("https://#{libra_server}/broker/embed_cartridge")
-else
- action = opt['command']
- url = URI.parse("https://#{libra_server}/broker/cartridge")
-end
-
-RHC::ctl_app(libra_server, RHC::Config.default_proxy, opt['app'], opt['rhlogin'], password, action, opt['embed'], framework, opt['alias'])
View
191 bin/rhc-ctl-domain
@@ -1,191 +0,0 @@
-#!/usr/bin/env ruby
-
-require 'rhc/coverage_helper'
-
-require 'rhc-common'
-
-RHC::Helpers.deprecated_command('rhc sshkey',true)
-
-#
-# print help
-#
-def p_usage(exit_code = 255)
- rhlogin = get_var('default_rhlogin') ? "Default: #{get_var('default_rhlogin')}" : "required"
- puts <<USAGE
-
-Usage: #{$0}
-Manage multiple keys for the registered rhcloud user.
-
- rhc-ctl-domain [-l rhlogin] [-p password] [-d] [-h] [-n namespace] (-a key-name [-k ssh-pubkey] | -u key-name [-k ssh-pubkey] | -r key-name | --destroy)
-
- -l|--rhlogin rhlogin OpenShift login (#{rhlogin})
- -p|--password password Password (optional, will prompt)
- -n|--namespace namespace Namespace for your application(s) (alphanumeric - max #{RHC::DEFAULT_MAX_LENGTH} chars) (required for destroying domain)
- -a|--add-ssh-key key-name Add SSH key to the user account (key-name is the user-specified identifier for the key)
- -r|--remove-ssh-key key-name Remove SSH key from the user account
- -u|--update-ssh-key key-name Update SSH key for the user account
- --destroy Destroys the domain and any added ssh keys
- -k|--ssh key-filepath SSH public key filepath
- --config path Path of alternate config file
- -d|--debug Print Debug info
- -h|--help Show Usage info
-
-USAGE
-exit exit_code
-end
-
-begin
- opts = GetoptLong.new(
- ["--debug", "-d", GetoptLong::NO_ARGUMENT],
- ["--help", "-h", GetoptLong::NO_ARGUMENT],
- ["--rhlogin", "-l", GetoptLong::REQUIRED_ARGUMENT],
- ["--password", "-p", GetoptLong::REQUIRED_ARGUMENT],
- ["--namespace", "-n", GetoptLong::REQUIRED_ARGUMENT],
- ["--add-ssh-key", "-a", GetoptLong::REQUIRED_ARGUMENT],
- ["--remove-ssh-key", "-r", GetoptLong::REQUIRED_ARGUMENT],
- ["--update-ssh-key", "-u", GetoptLong::REQUIRED_ARGUMENT],
- ["--destroy", GetoptLong::NO_ARGUMENT],
- ["--ssh", "-k", GetoptLong::REQUIRED_ARGUMENT],
- ["--config", GetoptLong::REQUIRED_ARGUMENT]
- )
-
- command_list = ['add-ssh-key', 'remove-ssh-key', 'update-ssh-key', 'destroy']
- command_count = 0
- opt = {}
- opts.each do |o, a|
- opt[o[2..-1]] = a.to_s
-
- # check to see if there are multiple commands
- if command_list.include?(o[2..-1])
- command_count += 1
- end
- end
-rescue Exception => e
- #puts e.message
- p_usage
-end
-
-# If provided a config path, check it
-RHC::Config.check_cpath(opt)
-
-# Pull in configs from files
-libra_server = get_var('libra_server')
-debug = get_var('debug') == 'false' ? nil : get_var('debug')
-opt['rhlogin'] = get_var('default_rhlogin') unless opt['rhlogin']
-
-p_usage 0 if opt['help']
-p_usage if 0 != ARGV.length
-
-debug = true if opt['debug']
-
-RHC::debug(debug)
-
-# Validate for no command or multiple commands being specified
-if command_count == 0
- puts "Missing command! You must specify the operation to perform."
- p_usage
-elsif command_count > 1
- puts "Multiple commands specified! You can only perform one operation at a time."
- p_usage
-end
-
-if opt['destroy'] && !RHC::check_namespace(opt['namespace'])
- puts "Missing or invalid namespace! You must specify the namespace in order to destroy it."
- p_usage
-end
-
-
-# This is taken care of by the command_count validation performed earlier
-#if !opt['rhlogin'] || !(opt['add-key'] || opt['remove-key'] || opt['update-key'] || opt['list-keys']) || \
-# (opt['add-key'] && (opt['remove-key'] || opt['update-key'] || opt['list-keys'])) || \
-# (opt['remove-key'] && (opt['add-key'] || opt['update-key'] || opt['list-keys'])) || \
-# (opt['update-key'] && (opt['add-key'] || opt['remove-key'] || opt['list-keys'])) || \
-# (opt['list-keys'] && (opt['add-key'] || opt['remove-key'] || opt['update-key']))
-# p_usage
-#end
-
-if !RHC::check_rhlogin(opt['rhlogin']) || \
- (opt['add-ssh-key'] && !RHC::check_key(opt['add-ssh-key'])) || \
- (opt['remove-ssh-key'] && !RHC::check_key(opt['remove-ssh-key'])) || \
- (opt['update-ssh-key'] && !RHC::check_key(opt['update-ssh-key']))
- p_usage
-end
-
-password = opt['password']
-if !password
- password = RHC::get_password
-end
-
-#
-# Read user public ssh key
-if opt['add-ssh-key'] || opt['update-ssh-key']
- if opt['ssh']
- if File.readable?(opt['ssh'])
- begin
- ssh_keyfile_contents = File.open(opt['ssh']).gets.chomp.split(' ')
- ssh_key = ssh_keyfile_contents[1]
- ssh_key_type = ssh_keyfile_contents[0]
- rescue Exception => e
- puts "Invalid public keyfile format! Please specify a valid user public keyfile."
- exit 1
- end
- else
- puts "Unable to read user public keyfile #{opt['ssh']}"
- exit 1
- end
- else # create key
- key_name = opt['add-ssh-key'] ? opt['add-ssh-key'] : opt['update-ssh-key']
- puts "Generating ssh key pair for user '#{key_name}' in the dir '#{Dir.pwd}/'"
- # Use system for interaction
- system("ssh-keygen -t rsa -f '#{key_name}'")
- ssh_pub_key_file = Dir.pwd + '/' + key_name + '.pub'
- ssh_keyfile_contents = File.open(ssh_pub_key_file).gets.chomp.split(' ')
- ssh_key = ssh_keyfile_contents[1]
- ssh_key_type = ssh_keyfile_contents[0]
- end
-end
-
-data = {}
-data[:rhlogin] = opt['rhlogin']
-if opt['add-ssh-key']
- url = URI.parse("https://#{libra_server}/broker/ssh_keys")
- data[:key_name] = opt['add-ssh-key']
- data[:ssh] = ssh_key
- data[:action] = 'add-key'
- data[:key_type] = ssh_key_type
-elsif opt['remove-ssh-key']
- url = URI.parse("https://#{libra_server}/broker/ssh_keys")
- data[:key_name] = opt['remove-ssh-key']
- data[:action] = 'remove-key'
-elsif opt['update-ssh-key']
- url = URI.parse("https://#{libra_server}/broker/ssh_keys")
- data[:key_name] = opt['update-ssh-key']
- data[:ssh] = ssh_key
- data[:action] = 'update-key'
- data[:key_type] = ssh_key_type
-elsif opt['destroy']
- url = URI.parse("https://#{libra_server}/broker/domain")
- data[:delete] = true
- data[:namespace] = opt['namespace']
-end
-
-RHC::print_post_data(data)
-json_data = RHC::generate_json(data)
-
-response = RHC::http_post(RHC::Config.default_proxy, url, json_data, password)
-
-if response.code == '200'
- begin
- json_resp = RHC::json_decode(response.body)
- RHC::update_server_api_v(json_resp)
- RHC::print_response_success(json_resp)
- puts "Success"
- exit 0
- rescue RHC::JsonError
- RHC::print_response_err(response)
- end
-else
- RHC::print_response_err(response)
-end
-puts "Failure"
-exit 1
View
347 bin/rhc-domain
@@ -1,347 +0,0 @@
-#!/usr/bin/env ruby
-
-require 'rhc/coverage_helper'
-
-require 'rhc-common'
-
-RHC::Helpers.deprecated_command('rhc domain',true)
-
-#
-# print help
-#
-def p_usage(exit_code = 255)
- rhlogin = get_var('default_rhlogin') ? "Default: #{get_var('default_rhlogin')}" : "required"
- puts <<USAGE
-
-Usage: rhc domain (<command> | --help) [<args>]
-Manage a domain in rhcloud for a registered rhcloud user.
-
-List of commands
- create Bind a registered rhcloud user to a domain in rhcloud.
- show Display domain information and list the applications within the domain
- alter Alter namespace (will change urls).
- status Run a simple check on local configs and credentials to confirm tools are properly setup.
- destroy Destroys the domain and any added ssh keys
-
-List of arguments
- -l|--rhlogin rhlogin OpenShift login (#{rhlogin})
- -p|--password password Password (optional, will prompt)
- -n|--namespace namespace Namespace for your application(s) (alphanumeric - max #{RHC::DEFAULT_MAX_LENGTH} chars) (required for creating or destroying domain)
- -d|--debug Print Debug info
- -h|--help Show Usage info
- --config path Path of alternate config file
- --timeout # Timeout, in seconds, for the session
-
-USAGE
-exit exit_code
-end
-
-
-def get_args()
- args = ""
- $opt.each do |o, a|
- if a.length > 0 && a.to_s.strip.length == 0; a = "'#{a}'" end
- args += " --#{o} #{a}"
- end
- args
-end
-
-def validate_args(val_namespace=true, val_timeout=true)
- # If provided a config path, check it
- RHC::Config.check_cpath($opt)
-
- # Pull in configs from files
- $libra_server = get_var('libra_server')
- debug = get_var('debug') == 'false' ? nil : get_var('debug')
-
- $opt['rhlogin'] = get_var('default_rhlogin') unless $opt['rhlogin']
- p_usage if !RHC::check_rhlogin($opt['rhlogin'])
-
- p_usage if (val_namespace && !RHC::check_namespace($opt['namespace']))
-
- debug = $opt["debug"] ? true : false
- RHC::debug(debug)
-
- RHC::timeout($opt["timeout"], get_var('timeout')) if val_timeout
- RHC::connect_timeout($opt["timeout"], get_var('timeout')) if val_timeout
-
- $password = $opt['password'] ? $opt['password'] : RHC::get_password
-end
-
-def create_or_alter_domain(alter=false)
- validate_args()
-
- ssh_key_file_path = get_kfile(false)
- ssh_pub_key_file_path = get_kpfile(ssh_key_file_path, alter)
-
- ssh_config = "#{ENV['HOME']}/.ssh/config"
- ssh_config_d = "#{ENV['HOME']}/.ssh/"
-
- # Check to see if a ssh_key_file_path exists, if not create it.
- if File.readable?(ssh_key_file_path)
- puts "OpenShift key found at #{ssh_key_file_path}. Reusing..."
- else
- puts "Generating OpenShift ssh key to #{ssh_key_file_path}"
- w = RHC::SSHWizard.new($opt['rhlogin'], $password)
- w.run
- end
-
- ssh_keyfile_contents = File.open(ssh_pub_key_file_path).gets.chomp.split(' ')
- ssh_key = ssh_keyfile_contents[1]
- ssh_key_type = ssh_keyfile_contents[0]
-
- data = {'namespace' => $opt['namespace'],
- 'rhlogin' => $opt['rhlogin']}
-
- # send the ssh key and key type only in case of domain creation
- # key updates will be handled by the 'rhc sshkey update' command
- if !alter
- data[:ssh] = ssh_key
- data[:key_type] = ssh_key_type
- end
-
- if alter
- data[:alter] = true
- not_found_message = "A user with rhlogin '#{$opt['rhlogin']}' does not have a registered domain. Be sure to run 'rhc domain create' first."
- user_info = RHC::get_user_info($libra_server, $opt['rhlogin'], $password, RHC::Config.default_proxy, true, not_found_message)
- end
- if @mydebug
- data[:debug] = true
- end
- RHC::print_post_data(data)
- json_data = RHC::generate_json(data)
-
- url = URI.parse("https://#{$libra_server}/broker/domain")
- response = RHC::http_post(RHC::Config.default_proxy, url, json_data, $password)
-
- if response.code == '200'
- begin
- json_resp = RHC::json_decode(response.body)
- RHC::print_response_success(json_resp)
- json_rhlogininfo = RHC::json_decode(json_resp['data'])
- add_rhlogin_config(json_rhlogininfo['rhlogin'], json_rhlogininfo['uuid'])
- if !alter
- puts <<EOF
-Creation successful
-
-You may now create an application.
-
-EOF
- else
- app_info = user_info['app_info']
- dns_success = true
- if !app_info.empty? && $opt['namespace'] != user_info['user_info']['domains'][0]['namespace']
- #
- # Confirm that the host(s) exist in DNS
- #
- puts "Now your new domain name(s) are being propagated worldwide (this might take a minute)..."
- # Allow DNS to propogate
- sleep 15
- app_info.each_key do |appname|
- fqdn = "#{appname}-#{$opt['namespace']}.#{user_info['user_info']['rhc_domain']}"
-
- # Now start checking for DNS
- loop = 0
- sleep_time = 2
- while loop < RHC::MAX_RETRIES && !RHC::hostexist?(fqdn)
- sleep sleep_time
- loop+=1
- puts " retry # #{loop} - Waiting for DNS: #{fqdn}"
- sleep_time = RHC::delay(sleep_time)
- end
-
- if loop >= RHC::MAX_RETRIES
- puts "Host could not be found: #{fqdn}"
- dns_success = false
- end
- end
- puts "You can use 'rhc domain show' to view any url changes. Be sure to update any links"
- puts "including the url in your local git config: <local_git_repo>/.git/config"
- end
- if dns_success
- puts "Alteration successful."
- else
- puts "Alteration successful but at least one of the urls is still updating in DNS."
- end
- puts ""
- end
- exit 0
- rescue RHC::JsonError
- RHC::print_response_err(response)
- end
- else
- RHC::print_response_err(response)
- end
- exit 1
-end
-
-def destroy_domain()
- validate_args(true, false)
-
- url = URI.parse("https://#{$libra_server}/broker/domain")
- data = {}
- data[:rhlogin] = $opt['rhlogin']
- data[:delete] = true
- data[:namespace] = $opt['namespace']
-
- RHC::print_post_data(data)
- json_data = RHC::generate_json(data)
-
- response = RHC::http_post(RHC::Config.default_proxy, url, json_data, $password)
-
- if response.code == '200'
- begin
- json_resp = RHC::json_decode(response.body)
- RHC::update_server_api_v(json_resp)
- RHC::print_response_success(json_resp)
- puts "Success"
- exit 0
- rescue RHC::JsonError
- RHC::print_response_err(response)
- end
- else
- RHC::print_response_err(response)
- end
- puts "Failure"
- exit 1
-end
-
-def show_domain_info()
- validate_args(false, true)
-
- user_info = RHC::get_user_info($libra_server, $opt['rhlogin'], $password, RHC::Config.default_proxy, true)
-
- domains = user_info['user_info']['domains']
- num_domains = domains.length
-
- puts ""
- puts "User Info"
- puts "========="
-
- if num_domains == 0
- puts "Namespace: No namespaces found. You can use 'rhc domain create -n <namespace>' to create a namespace for your applications."
- elsif num_domains == 1
- puts "Namespace: #{domains[0]['namespace']}"
- else
- domains.each_index { |i| puts "Namespace(#{i}): #{domains[i]['namespace']}" }
- end
-
- #puts " UUID: #{user_info['user_info']['uuid']}"
- puts " OpenShift login: #{user_info['user_info']['rhlogin']}"
-
- puts "\n\n"
-
- puts "Application Info"
- puts "================"
- unless user_info['app_info'].empty?
- user_info['app_info'].each do |key, val|
- puts key
- puts " Framework: #{val['framework']}"
- puts " Creation: #{val['creation_time']}"
- puts " UUID: #{val['uuid']}"
- puts " Git URL: ssh://#{val['uuid']}@#{key}-#{user_info['user_info']['domains'][0]['namespace']}.#{user_info['user_info']['rhc_domain']}/~/git/#{key}.git/"
- puts " Public URL: http://#{key}-#{user_info['user_info']['domains'][0]['namespace']}.#{user_info['user_info']['rhc_domain']}/"
- if val['aliases'] && !val['aliases'].empty?
- puts " Aliases: #{val['aliases'].join(', ')}"
- end
- puts ""
- puts " Embedded: "
- if val['embedded'] && !val['embedded'].empty?
- val['embedded'].each do |embed_key, embed_val|
- if embed_val.has_key?('info') && !embed_val['info'].empty?
- puts " #{embed_key} - #{embed_val['info']}"
- else
- puts " #{embed_key}"
- end
- end
- else
- puts " None"
- end
- puts ""
- end
- else
- puts "No applications found. You can use 'rhc app create' to create new applications."
- end
-end
-
-def check_domain_status
- $opt['rhlogin'] = get_var('default_rhlogin') unless $opt['rhlogin']
- p_usage if !RHC::check_rhlogin($opt['rhlogin'])
-
- system("rhc-chk #{get_args} 2>&1")
- if ($? != 0); exit 1 end
-end
-
-
-begin
- argv_c = ARGV.clone
-
- if ARGV[0] =~ /^(create|alter|destroy)$/
- ARGV.shift
- opts = GetoptLong.new(
- ["--debug", "-d", GetoptLong::NO_ARGUMENT],
- ["--help", "-h", GetoptLong::NO_ARGUMENT],
- ["--rhlogin", "-l", GetoptLong::REQUIRED_ARGUMENT],
- ["--password", "-p", GetoptLong::REQUIRED_ARGUMENT],
- ["--namespace", "-n", GetoptLong::REQUIRED_ARGUMENT],
- ["--config", GetoptLong::REQUIRED_ARGUMENT],
- ["--timeout", GetoptLong::REQUIRED_ARGUMENT]
- )
- elsif ARGV[0] =~ /^(status|show)$/
- ARGV.shift
- opts = GetoptLong.new(
- ["--debug", "-d", GetoptLong::NO_ARGUMENT],
- ["--help", "-h", GetoptLong::NO_ARGUMENT],
- ["--rhlogin", "-l", GetoptLong::REQUIRED_ARGUMENT],
- ["--password", "-p", GetoptLong::REQUIRED_ARGUMENT],
- ["--config", GetoptLong::REQUIRED_ARGUMENT],
- ["--timeout", GetoptLong::REQUIRED_ARGUMENT]
- )
- else
- # if the user just enters "rhc domain", don't throw an error
- # let it be handled by the "rhc domain show" command
- if ARGV[0].to_s.strip.length == 0
- opts = []
- else
- opts = GetoptLong.new(
- ["--help", "-h", GetoptLong::NO_ARGUMENT]
- )
-
- unless ARGV[0] =~ /^(help|-h|--help)$/
- puts "Missing or invalid command!"
- # just exit at this point
- # printing the usage description will be handled in the rescue
- exit 255
- end
- end
- end
-
- $opt = {}
- opts.each do |o, a|
- $opt[o[2..-1]] = a.to_s
- end
-rescue Exception => e
- p_usage
-end
-
-p_usage 0 if $opt["help"]
-
-case argv_c[0]
-when "create"
- create_or_alter_domain(false)
-when "alter"
- create_or_alter_domain(true)
-when "status"
- check_domain_status
-when "show", nil
- show_domain_info
-when "destroy"
- destroy_domain
-when "-h", "--help", "help", nil
- p_usage
-else
- puts "Invalid command!"
- p_usage
-end
-
-exit 0
View
156 bin/rhc-domain-info
@@ -1,156 +0,0 @@
-#!/usr/bin/env ruby
-
-require 'rhc/coverage_helper'
-
-require 'rhc-common'
-
-RHC::Helpers.deprecated_command('rhc domain show',true)
-
-#
-# print help
-#
-def p_usage(error_code = 255)
- rhlogin = get_var('default_rhlogin') ? "Default: #{get_var('default_rhlogin')}" : "required"
- puts <<USAGE
-
-Usage: #{$0}
-Display information about a user
-
- -l|--rhlogin rhlogin OpenShift login (#{rhlogin})
- -p|--password password Password (optional, will prompt)
- -a|--apps List applications for rhlogin
- -i|--info Show user info
- -d|--debug Print Debug info
- -h|--help Show Usage info
- --config path Path of alternate config file
- --timeout # Timeout, in seconds, for the session
-
-USAGE
-exit error_code
-end
-
-begin
- opts = GetoptLong.new(
- ["--debug", "-d", GetoptLong::NO_ARGUMENT],
- ["--help", "-h", GetoptLong::NO_ARGUMENT],
- ["--apps", "-a", GetoptLong::NO_ARGUMENT],
- ["--info", "-i", GetoptLong::NO_ARGUMENT],
- ["--rhlogin", "-l", GetoptLong::REQUIRED_ARGUMENT],
- ["--config", GetoptLong::REQUIRED_ARGUMENT],
- ["--password", "-p", GetoptLong::REQUIRED_ARGUMENT],
- ["--timeout", GetoptLong::REQUIRED_ARGUMENT]
- )
- opt = {}
- opts.each do |o, a|
- opt[o[2..-1]] = a.to_s
- end
-rescue Exception => e
- #puts e.message
- p_usage
-end
-
-# If provided a config path, check it
-RHC::Config.check_cpath(opt)
-
-# Pull in configs from files
-libra_server = get_var('libra_server')
-debug = get_var('debug') == 'false' ? nil : get_var('debug')
-
-p_usage 0 if opt["help"]
-
-p_usage if 0 != ARGV.length
-
-debug = true if opt["debug"]
-
-RHC::debug(debug)
-
-RHC::timeout(opt["timeout"], get_var('timeout'))
-RHC::connect_timeout(opt["timeout"], get_var('timeout'))
-
-opt["rhlogin"] = get_var('default_rhlogin') unless opt["rhlogin"]
-
-if !RHC::check_rhlogin(opt['rhlogin'])
- p_usage
-end
-
-password = opt['password']
-if !password
- password = RHC::get_password
-end
-
-opt['apps'] = true if not opt['info'] and not opt['apps']
-user_info = RHC::get_user_info(libra_server, opt['rhlogin'], password, RHC::Config.default_proxy, true)
-
-if opt['info']
- ssh_keys = RHC::get_ssh_keys(libra_server, opt['rhlogin'], password, RHC::Config.default_proxy)
-
- domains = user_info['user_info']['domains']
- num_domains = domains.length
-
- puts "User Info"
- puts "========="
- if num_domains == 0
- puts "Namespace: No namespaces found. You can use 'rhc domain create -n <namespace>' to create a namespace for your applications."
- elsif num_domains == 1
- puts "Namespace: #{domains[0]['namespace']}"
- else
- domains.each_index { |i| puts "Namespace(#{i}): #{domains[i]['namespace']}" }
- end
- #puts " UUID: #{user_info['user_info']['uuid']}"
- puts " OpenShift login: #{user_info['user_info']['rhlogin']}"
- puts "Primary SSH key: #{user_info['user_info']['ssh_key']}"
- puts "Primary SSH key type: #{user_info['user_info'][