Module: Skytap
- Extended by:
- Skytap
- Included in:
- Skytap
- Defined in:
- lib/skytap.rb,
lib/skytap/error.rb,
lib/skytap/logger.rb,
lib/skytap/version.rb,
lib/skytap/commands.rb,
lib/skytap/response.rb,
lib/skytap/skytaprc.rb,
lib/skytap/requester.rb,
lib/skytap/templates.rb,
lib/skytap/api_schema.rb,
lib/skytap/command_line.rb,
lib/skytap/commands/base.rb,
lib/skytap/commands/help.rb,
lib/skytap/commands/http.rb,
lib/skytap/commands/root.rb,
lib/skytap/plugins/vm_upload.rb,
lib/skytap/plugins/vm_download.rb,
lib/skytap/plugins/vm_copy_to_region.rb
Defined Under Namespace
Modules: ApiSchema, Commands, SkytapRC, Templates Classes: CommandLine, Error, Logger, Option, Requester, Response
Constant Summary collapse
- SCHEMA =
Skytap::ApiSchema.get
- BASE_RESOURCES =
%w[asset configuration credential export import ip template user vm]
- VERSION =
'0.2.6'
Instance Method Summary collapse
-
#exec! ⇒ Object
Returns a numeric code indicating exit status; 0 iff success.
-
#invoke(username, api_token, args, command_options = {}, global_options = {}, &invoker) ⇒ Object
Invokes the command in a way suitable for Ruby programs which use Skytap as a third-party library, or for Skytap plugins.
- #invoke!(*args, &block) ⇒ Object
- #specification ⇒ Object
Instance Method Details
#exec! ⇒ Object
Returns a numeric code indicating exit status; 0 iff success.
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 |
# File 'lib/skytap.rb', line 47 def exec! #TODO:NLA Rename to something indicating that this is called when running from a command-line context. response = begin args, , = CommandLine.parse(ARGV) logger = Logger.new([:'log-level']) # Disable color if needed. We don't unconditionally execute this line so that # color is still disabled for non-TTY terminals irrespective of the colorize # setting. Sickill::Rainbow.enabled = false unless [:colorize] build_response(Commands::Root.go!(logger, args, , )) rescue SystemExit raise rescue Interrupt return 0 rescue Exception => ex log_exception(ex, args, , ) build_response(ex) end if response.error? if logger logger.info response. else $stderr.puts response. end return 1 else return 0 end end |
#invoke(username, api_token, args, command_options = {}, global_options = {}, &invoker) ⇒ Object
Invokes the command in a way suitable for Ruby programs which use Skytap as a third-party library, or for Skytap plugins.
82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 |
# File 'lib/skytap.rb', line 82 def invoke(username, api_token, args, = {}, = {}, &invoker) #TODO:NLA This is hacky, and basically just to get the defaults for global options. FIXME _, , _ = CommandLine.parse([]) = .merge().merge(:username => username, :'api-token' => api_token) if args.is_a?(String) args = args.split end logger = Logger.new([:'log-level']).tap do |l| l.mute! unless l.log_level == 'verbose' end build_response(Commands::Root.go!(logger, args, , , true, &invoker)) end |
#invoke!(*args, &block) ⇒ Object
98 99 100 101 102 103 104 105 |
# File 'lib/skytap.rb', line 98 def invoke!(*args, &block) resp = invoke(*args, &block) if resp.error? raise Skytap::Error.new resp. else resp.payload end end |
#specification ⇒ Object
107 108 109 110 111 112 |
# File 'lib/skytap.rb', line 107 def specification resources.inject({}) do |acc, resource| acc[resource] = SCHEMA[resource] || {} acc end end |