marathon_client 0.0.6 → 0.0.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/bin/marathon +98 -88
- data/lib/marathon/client.rb +7 -2
- data/lib/marathon/version.rb +1 -1
- data/marathon_client.gemspec +1 -1
- metadata +5 -5
    
        checksums.yaml
    CHANGED
    
    | @@ -1,7 +1,7 @@ | |
| 1 1 | 
             
            ---
         | 
| 2 2 | 
             
            SHA1:
         | 
| 3 | 
            -
              metadata.gz:  | 
| 4 | 
            -
              data.tar.gz:  | 
| 3 | 
            +
              metadata.gz: 6c9e596d1d9a22eed7059f0abcb32e19a5f09bf3
         | 
| 4 | 
            +
              data.tar.gz: f454fed66fad61cc4aa9c3a20564c014ca2c3e75
         | 
| 5 5 | 
             
            SHA512:
         | 
| 6 | 
            -
              metadata.gz:  | 
| 7 | 
            -
              data.tar.gz:  | 
| 6 | 
            +
              metadata.gz: aaee3ee5f3221bddcce683faf3f4aee1afbc1946c7f149160d15661a29394eb9d35eb337c432026a3852bda70edc313df4de94f473ca1eac7dbf4e39565e84b6
         | 
| 7 | 
            +
              data.tar.gz: 9e0aaf7370257182cf9062f94b650a4490d4da57d88c45738d92dd1e580d636a1d44cd539d6e70c80083ec1c0fdd01da20a840303d79e73fae4c6119e72afa76
         | 
    
        data/bin/marathon
    CHANGED
    
    | @@ -1,99 +1,109 @@ | |
| 1 1 | 
             
            #!/usr/bin/env ruby
         | 
| 2 2 |  | 
| 3 3 | 
             
            require File.expand_path(File.join(File.dirname(__FILE__), '..', 'lib', 'marathon'))
         | 
| 4 | 
            -
            require ' | 
| 5 | 
            -
             | 
| 6 | 
            -
             | 
| 7 | 
            -
             | 
| 8 | 
            -
             | 
| 9 | 
            -
             | 
| 10 | 
            -
               | 
| 11 | 
            -
             | 
| 12 | 
            -
             | 
| 13 | 
            -
             | 
| 14 | 
            -
             | 
| 15 | 
            -
             | 
| 16 | 
            -
             | 
| 17 | 
            -
                 | 
| 18 | 
            -
                 | 
| 19 | 
            -
             | 
| 20 | 
            -
             | 
| 21 | 
            -
             | 
| 22 | 
            -
             | 
| 23 | 
            -
             | 
| 24 | 
            -
             | 
| 25 | 
            -
             | 
| 26 | 
            -
             | 
| 27 | 
            -
             | 
| 28 | 
            -
             | 
| 29 | 
            -
             | 
| 30 | 
            -
             | 
| 31 | 
            -
             | 
| 32 | 
            -
             | 
| 33 | 
            -
             | 
| 34 | 
            -
             | 
| 35 | 
            -
                   | 
| 36 | 
            -
                   | 
| 37 | 
            -
                   | 
| 4 | 
            +
            require 'trollop'
         | 
| 5 | 
            +
             | 
| 6 | 
            +
            SUB_COMMANDS = %w[start stop scale list]
         | 
| 7 | 
            +
             | 
| 8 | 
            +
            global_opts = Trollop.options do
         | 
| 9 | 
            +
              version Marathon::VERSION
         | 
| 10 | 
            +
              banner <<-EOS
         | 
| 11 | 
            +
            Usage: marathon [command] [options]
         | 
| 12 | 
            +
             | 
| 13 | 
            +
            Available commands:
         | 
| 14 | 
            +
             | 
| 15 | 
            +
              start   Start a new app.
         | 
| 16 | 
            +
              scale   Scale the number of app instances.
         | 
| 17 | 
            +
              stop    Stop an app and remove it from Marathon.
         | 
| 18 | 
            +
              list    Show a list of running apps and their options.
         | 
| 19 | 
            +
             | 
| 20 | 
            +
            Global options:
         | 
| 21 | 
            +
            EOS
         | 
| 22 | 
            +
             | 
| 23 | 
            +
              opt :marathon_host, 'Marathon host (default http://localhost:8080, or MARATHON_HOST)', :short => '-H', :type => String
         | 
| 24 | 
            +
              opt :marathon_user, 'User name to authenticate against Marathon (optional).', :short => '-U', :type => String
         | 
| 25 | 
            +
              opt :marathon_pass, 'Password to authenticate against Marathon (optional).', :short => '-P', :type => String
         | 
| 26 | 
            +
              stop_on SUB_COMMANDS
         | 
| 27 | 
            +
            end
         | 
| 28 | 
            +
             | 
| 29 | 
            +
            cmd = ARGV.shift # get the subcommand
         | 
| 30 | 
            +
             | 
| 31 | 
            +
            cmd_opts = case cmd
         | 
| 32 | 
            +
              when 'start'
         | 
| 33 | 
            +
                Trollop.options do
         | 
| 34 | 
            +
                  opt :id, 'A unique identifier for the app.', :short => '-i', :type => String
         | 
| 35 | 
            +
                  opt :command, 'The command to start the app.', :short => '-C', :type => String
         | 
| 36 | 
            +
                  opt :num_instances, 'The number of instances to run (default 1).', :short => '-n', :type => Integer
         | 
| 37 | 
            +
                  opt :cpus, 'The number of CPUs to give to this app, can be a fraction (default 1.0).', :short => '-c', :type => Float
         | 
| 38 | 
            +
                  opt :mem, 'The memory limit for this app, in MB, can be a fraction (default 10.0).', :short => '-m', :type => Float
         | 
| 39 | 
            +
                  opt :uri, 'URIs to download and unpack into the working directory.', :short => '-u', :type => Array
         | 
| 40 | 
            +
                  opt :env, 'Environment variables to add to the process, as NAME=VALUE.', :short => '-e', :type => Array
         | 
| 38 41 | 
             
                end
         | 
| 39 | 
            -
               | 
| 40 | 
            -
             | 
| 41 | 
            -
             | 
| 42 | 
            -
             | 
| 43 | 
            -
             | 
| 44 | 
            -
                on :H=, :marathon_host=, 'Marathon host (default http://localhost:8080, or MARATHON_HOST)'
         | 
| 45 | 
            -
                on :i=, :id=, 'A unique identifier for the app.'
         | 
| 46 | 
            -
                on :n=, :num_instances=, 'The number of instances to run.', :as => Integer
         | 
| 47 | 
            -
             | 
| 48 | 
            -
                run do |opts, args|
         | 
| 49 | 
            -
                  puts "Scaling app '#{opts[:id]}' to #{opts[:num_instances]} instances"
         | 
| 50 | 
            -
                  res = Marathon::Client.new(opts[:marathon_host]).scale(opts[:id], opts[:num_instances])
         | 
| 51 | 
            -
                  puts res
         | 
| 42 | 
            +
              when 'scale'
         | 
| 43 | 
            +
                Trollop.options do
         | 
| 44 | 
            +
                  opt :id, 'A unique identifier for the app.', :short => '-i', :type => String
         | 
| 45 | 
            +
                  opt :num_instances, 'The number of instances to run (default 1).', :short => '-n', :type => Integer
         | 
| 52 46 | 
             
                end
         | 
| 53 | 
            -
               | 
| 54 | 
            -
             | 
| 55 | 
            -
             | 
| 56 | 
            -
                description 'Stop an app and remove it from Marathon.'
         | 
| 57 | 
            -
             | 
| 58 | 
            -
                on :H=, :marathon_host=, 'Marathon host (default http://localhost:8080, or MARATHON_HOST)'
         | 
| 59 | 
            -
                on :i=, :id=, 'A unique identifier for the app.'
         | 
| 60 | 
            -
             | 
| 61 | 
            -
                run do |opts, args|
         | 
| 62 | 
            -
                  puts "Stopping app '#{opts[:id]}'"
         | 
| 63 | 
            -
                  res = Marathon::Client.new(opts[:marathon_host]).stop(opts[:id])
         | 
| 64 | 
            -
                  puts res
         | 
| 47 | 
            +
              when 'stop'
         | 
| 48 | 
            +
                Trollop.options do
         | 
| 49 | 
            +
                  opt :id, 'A unique identifier for the app.', :short => '-i', :type => String
         | 
| 65 50 | 
             
                end
         | 
| 51 | 
            +
              else
         | 
| 52 | 
            +
                {}
         | 
| 66 53 | 
             
              end
         | 
| 67 54 |  | 
| 68 | 
            -
             | 
| 69 | 
            -
             | 
| 70 | 
            -
             | 
| 71 | 
            -
             | 
| 72 | 
            -
             | 
| 73 | 
            -
             | 
| 74 | 
            -
             | 
| 75 | 
            -
             | 
| 76 | 
            -
             | 
| 77 | 
            -
             | 
| 78 | 
            -
             | 
| 79 | 
            -
             | 
| 80 | 
            -
             | 
| 81 | 
            -
             | 
| 82 | 
            -
             | 
| 83 | 
            -
             | 
| 84 | 
            -
             | 
| 85 | 
            -
             | 
| 86 | 
            -
             | 
| 87 | 
            -
             | 
| 88 | 
            -
             | 
| 89 | 
            -
             | 
| 90 | 
            -
             | 
| 91 | 
            -
             | 
| 92 | 
            -
             | 
| 93 | 
            -
             | 
| 94 | 
            -
             | 
| 95 | 
            -
             | 
| 55 | 
            +
            marathon = Marathon::Client.new(
         | 
| 56 | 
            +
              global_opts[:marathon_host],
         | 
| 57 | 
            +
              global_opts[:marathon_user],
         | 
| 58 | 
            +
              global_opts[:marathon_pass]
         | 
| 59 | 
            +
            )
         | 
| 60 | 
            +
             | 
| 61 | 
            +
            # Run
         | 
| 62 | 
            +
            case cmd
         | 
| 63 | 
            +
            when 'start'
         | 
| 64 | 
            +
              app_opts = {
         | 
| 65 | 
            +
                :instances => cmd_opts[:num_instances] || 1,
         | 
| 66 | 
            +
                :uris => cmd_opts[:uri] || [],
         | 
| 67 | 
            +
                :cmd => cmd_opts[:command],
         | 
| 68 | 
            +
                :env => cmd_opts[:env].nil? ? {} : Hash[cmd_opts[:env].map { |e| e.split('=', 2) }],
         | 
| 69 | 
            +
                :cpus => cmd_opts[:cpus] || 1.0,
         | 
| 70 | 
            +
                :mem => cmd_opts[:mem] || 10.0
         | 
| 71 | 
            +
              }
         | 
| 72 | 
            +
              puts "Starting app '#{cmd_opts[:id]}'"
         | 
| 73 | 
            +
              res = marathon.start(cmd_opts[:id], app_opts)
         | 
| 74 | 
            +
              puts res
         | 
| 75 | 
            +
            when 'scale'
         | 
| 76 | 
            +
              puts "Scaling app '#{cmd_opts[:id]}' to #{cmd_opts[:num_instances]} instances"
         | 
| 77 | 
            +
              res = marathon.scale(cmd_opts[:id], cmd_opts[:num_instances])
         | 
| 78 | 
            +
              puts res
         | 
| 79 | 
            +
            when 'stop'
         | 
| 80 | 
            +
              puts "Stopping app '#{cmd_opts[:id]}'"
         | 
| 81 | 
            +
              res = marathon.stop(cmd_opts[:id])
         | 
| 82 | 
            +
              puts res
         | 
| 83 | 
            +
            when 'list'
         | 
| 84 | 
            +
              res = marathon.list
         | 
| 85 | 
            +
              if res.success?
         | 
| 86 | 
            +
                res.parsed_response.each do |app|
         | 
| 87 | 
            +
                  puts "App ID:    #{app['id']}"
         | 
| 88 | 
            +
                  puts "Command:   #{app['cmd']}"
         | 
| 89 | 
            +
                  puts "Instances: #{app['instances']}"
         | 
| 90 | 
            +
                  puts "CPUs:      #{app['cpus']}"
         | 
| 91 | 
            +
                  puts "Memory:    #{app['mem']} MB"
         | 
| 92 | 
            +
                  app['uris'].each do |uri|
         | 
| 93 | 
            +
                    puts "URI:       #{uri}"
         | 
| 94 | 
            +
                  end
         | 
| 95 | 
            +
                  app['env'].each do |k, v|
         | 
| 96 | 
            +
                    puts "ENV:       #{k}=#{v}"
         | 
| 96 97 | 
             
                  end
         | 
| 98 | 
            +
                  puts
         | 
| 99 | 
            +
                end
         | 
| 100 | 
            +
             | 
| 101 | 
            +
                if res.parsed_response.empty?
         | 
| 102 | 
            +
                  puts "No apps are currently running"
         | 
| 97 103 | 
             
                end
         | 
| 104 | 
            +
              else
         | 
| 105 | 
            +
                puts res
         | 
| 98 106 | 
             
              end
         | 
| 99 | 
            -
             | 
| 107 | 
            +
            else
         | 
| 108 | 
            +
              Trollop.die "unknown subcommand #{cmd.inspect}"
         | 
| 109 | 
            +
            end
         | 
    
        data/lib/marathon/client.rb
    CHANGED
    
    | @@ -8,8 +8,13 @@ module Marathon | |
| 8 8 | 
             
                default_timeout 5
         | 
| 9 9 |  | 
| 10 10 |  | 
| 11 | 
            -
                def initialize(host = nil)
         | 
| 11 | 
            +
                def initialize(host = nil, user = nil, pass = nil)
         | 
| 12 12 | 
             
                  @host = host || ENV['MARATHON_HOST'] || 'http://localhost:8080'
         | 
| 13 | 
            +
                  @default_options = {}
         | 
| 14 | 
            +
             | 
| 15 | 
            +
                  if user && pass
         | 
| 16 | 
            +
                    @default_options[:basic_auth] = {:username => user, :password => pass}
         | 
| 17 | 
            +
                  end
         | 
| 13 18 | 
             
                end
         | 
| 14 19 |  | 
| 15 20 | 
             
                def list
         | 
| @@ -35,11 +40,11 @@ module Marathon | |
| 35 40 | 
             
                private
         | 
| 36 41 |  | 
| 37 42 | 
             
                def wrap_request(method, url, options = {})
         | 
| 43 | 
            +
                  options = @default_options.merge(options)
         | 
| 38 44 | 
             
                  http = self.class.send(method, @host + url, options)
         | 
| 39 45 | 
             
                  Marathon::Response.new(http)
         | 
| 40 46 | 
             
                rescue => e
         | 
| 41 47 | 
             
                  Marathon::Response.error(e.message)
         | 
| 42 48 | 
             
                end
         | 
| 43 | 
            -
             | 
| 44 49 | 
             
              end
         | 
| 45 50 | 
             
            end
         | 
    
        data/lib/marathon/version.rb
    CHANGED
    
    
    
        data/marathon_client.gemspec
    CHANGED
    
    | @@ -18,7 +18,7 @@ Gem::Specification.new do |spec| | |
| 18 18 | 
             
              spec.test_files    = spec.files.grep(%r{^(test|spec|features)/})
         | 
| 19 19 | 
             
              spec.require_paths = ["lib"]
         | 
| 20 20 |  | 
| 21 | 
            -
              spec.add_dependency " | 
| 21 | 
            +
              spec.add_dependency "trollop", "~> 2.0"
         | 
| 22 22 | 
             
              spec.add_dependency "httparty", "~> 0.11.0"
         | 
| 23 23 |  | 
| 24 24 | 
             
              spec.add_development_dependency "bundler", "~> 1.3"
         | 
    
        metadata
    CHANGED
    
    | @@ -1,29 +1,29 @@ | |
| 1 1 | 
             
            --- !ruby/object:Gem::Specification
         | 
| 2 2 | 
             
            name: marathon_client
         | 
| 3 3 | 
             
            version: !ruby/object:Gem::Version
         | 
| 4 | 
            -
              version: 0.0. | 
| 4 | 
            +
              version: 0.0.7
         | 
| 5 5 | 
             
            platform: ruby
         | 
| 6 6 | 
             
            authors:
         | 
| 7 7 | 
             
            - Tobi Knaup
         | 
| 8 8 | 
             
            autorequire: 
         | 
| 9 9 | 
             
            bindir: bin
         | 
| 10 10 | 
             
            cert_chain: []
         | 
| 11 | 
            -
            date: 2013-08- | 
| 11 | 
            +
            date: 2013-08-24 00:00:00.000000000 Z
         | 
| 12 12 | 
             
            dependencies:
         | 
| 13 13 | 
             
            - !ruby/object:Gem::Dependency
         | 
| 14 | 
            -
              name:  | 
| 14 | 
            +
              name: trollop
         | 
| 15 15 | 
             
              requirement: !ruby/object:Gem::Requirement
         | 
| 16 16 | 
             
                requirements:
         | 
| 17 17 | 
             
                - - ~>
         | 
| 18 18 | 
             
                  - !ruby/object:Gem::Version
         | 
| 19 | 
            -
                    version:  | 
| 19 | 
            +
                    version: '2.0'
         | 
| 20 20 | 
             
              type: :runtime
         | 
| 21 21 | 
             
              prerelease: false
         | 
| 22 22 | 
             
              version_requirements: !ruby/object:Gem::Requirement
         | 
| 23 23 | 
             
                requirements:
         | 
| 24 24 | 
             
                - - ~>
         | 
| 25 25 | 
             
                  - !ruby/object:Gem::Version
         | 
| 26 | 
            -
                    version:  | 
| 26 | 
            +
                    version: '2.0'
         | 
| 27 27 | 
             
            - !ruby/object:Gem::Dependency
         | 
| 28 28 | 
             
              name: httparty
         | 
| 29 29 | 
             
              requirement: !ruby/object:Gem::Requirement
         |