stingray-exec 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (40) hide show
  1. data/.gitignore +19 -0
  2. data/.rspec +2 -0
  3. data/.simplecov +7 -0
  4. data/AUTHORS.md +2 -0
  5. data/CONTRIBUTING.md +8 -0
  6. data/Gemfile +12 -0
  7. data/LICENSE.txt +22 -0
  8. data/README.md +66 -0
  9. data/Rakefile +22 -0
  10. data/bin/stingray-exec +3 -0
  11. data/examples/add-pool +10 -0
  12. data/examples/bork +6 -0
  13. data/examples/credentials.conf +4 -0
  14. data/examples/delete-pool +10 -0
  15. data/examples/list-pools +8 -0
  16. data/examples/list-virtual-servers +8 -0
  17. data/generate-actions.rb +119 -0
  18. data/lib/stingray-exec.rb +5 -0
  19. data/lib/stingray/control_api.rb +112 -0
  20. data/lib/stingray/control_api/actions.rb +49 -0
  21. data/lib/stingray/control_api/catalog_rule_methods.rb +31 -0
  22. data/lib/stingray/control_api/endpoint.rb +23 -0
  23. data/lib/stingray/control_api/generated-actions-9.0.yml +9036 -0
  24. data/lib/stingray/control_api/generated-actions-9.1.yml +9172 -0
  25. data/lib/stingray/control_api/pool_methods.rb +156 -0
  26. data/lib/stingray/control_api/soap_helper_methods.rb +69 -0
  27. data/lib/stingray/exec.rb +16 -0
  28. data/lib/stingray/exec/cli.rb +134 -0
  29. data/lib/stingray/exec/dsl.rb +48 -0
  30. data/lib/stingray/exec/version.rb +5 -0
  31. data/lib/stingray/junk.rb +16 -0
  32. data/spec/integration/catalog_rule_spec.rb +116 -0
  33. data/spec/integration/pool_spec.rb +61 -0
  34. data/spec/integration/users_spec.rb +21 -0
  35. data/spec/lib/stingray/control_api_spec.rb +51 -0
  36. data/spec/lib/stingray/exec/cli_spec.rb +7 -0
  37. data/spec/lib/stingray/exec/version_spec.rb +5 -0
  38. data/spec/spec_helper.rb +26 -0
  39. data/stingray-exec.gemspec +29 -0
  40. metadata +131 -0
@@ -0,0 +1,19 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ /.*.integration.env
7
+ Gemfile.lock
8
+ InstalledFiles
9
+ _yardoc
10
+ coverage
11
+ doc/
12
+ lib/bundler/man
13
+ pkg
14
+ rdoc
15
+ spec/reports
16
+ test/tmp
17
+ test/version_tmp
18
+ tmp
19
+ /ZeusTM_*.tgz
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --require spec_helper
2
+ --color
@@ -0,0 +1,7 @@
1
+ if ENV['COVERAGE']
2
+ SimpleCov.start do
3
+ add_filter '/spec/'
4
+ end
5
+ end
6
+
7
+ # vim:filetype=ruby
@@ -0,0 +1,2 @@
1
+ - Dan Buch
2
+ - Jake Ritorto
@@ -0,0 +1,8 @@
1
+ # Contributing
2
+
3
+ 1. Fork it
4
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
5
+ 3. Add yourself to the `AUTHORS.md` file
6
+ 4. Commit your changes (`git commit -v`)
7
+ 5. Push to the branch (`git push -u origin my-new-feature`)
8
+ 6. Create new Pull Request
data/Gemfile ADDED
@@ -0,0 +1,12 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec
4
+
5
+ gem 'rake'
6
+
7
+ group :test do
8
+ gem 'nyan-cat-formatter'
9
+ gem 'pry'
10
+ gem 'rspec'
11
+ gem 'simplecov'
12
+ end
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 ModCloth, Inc.
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,66 @@
1
+ # `stingray-exec`
2
+
3
+ Stingray Traffic Manager Control API Client
4
+
5
+ ## Installation
6
+
7
+ Install it via `gem`:
8
+
9
+ $ gem install stingray-exec
10
+
11
+ ## Usage
12
+
13
+ TODO: yup
14
+
15
+ ## Hacking
16
+
17
+ Some (all?) of this may be obvious for those familiar with Ruby modern
18
+ projects. It'll be okay.
19
+
20
+ Clone down a copy
21
+ ````` bash
22
+ git clone git://github.com/modcloth/stingray-exec.git
23
+ pushd stingray-exec
24
+ `````
25
+
26
+ Make sure you have `bundler`
27
+ ````` bash
28
+ gem install bundler
29
+ `````
30
+
31
+ Pull in dependencies with `bundler`
32
+ ````` bash
33
+ bundle install
34
+ `````
35
+
36
+ Verify basic operation with the `stingray-exec` script
37
+ ````` bash
38
+ bundle exec bin/stingray-exec --help
39
+ `````
40
+
41
+ As you'll see in the usage text, all of the command-line flags may also
42
+ be passed as environmental variables. The idea here is that it's
43
+ sometimes easier to define an environmental variable soup instead of
44
+ having to pass lots of flags for every invocation.
45
+
46
+ ### Running the tests
47
+
48
+ The test suite uses RSpec. By default, all specs tagged with
49
+ `:integration => true` are excluded. This results in very little being
50
+ tested. In order to exercise the really interesting tests, you'll have
51
+ to define a `STINGRAY_ENDOINT` environmental variable. Some examples of
52
+ how to do this are available in the `.local.integration.env` and
53
+ `.vagrant.integration.env` files in the root of the project tree.
54
+
55
+ ````` bash
56
+ bundle exec rspec
57
+ `````
58
+
59
+ ## Examples
60
+
61
+ There are some example `stingray-exec` scripts present in the
62
+ `./examples` directory. The `stingray-exec` script accepts a filename
63
+ as positional argument, so using it in the shebang line works great.
64
+
65
+ **WARNING**: some of the examples are destructive, so don't go pointing
66
+ them at production systems or any such nonsense.
@@ -0,0 +1,22 @@
1
+ require "bundler/gem_tasks"
2
+
3
+ stingray_tarball_name = 'ZeusTM_91_Linux-x86_64.tgz'
4
+ stingray_tarball_url = 'https://support.riverbed.com/download.htm' <<
5
+ "?filename=public/software/stingray/trafficmanager/9.1/#{stingray_tarball_name}"
6
+ stingray_tarball_sha1sum = 'bef75c80dbf7f13572ccfefec7791083180e78e0'
7
+
8
+ desc 'downloads zeus/stingray traffic manager tarball'
9
+ task :download_stingray do
10
+ unless have_stingray_tarball?(stingray_tarball_name, stingray_tarball_sha1sum)
11
+ sh "curl -o '#{stingray_tarball_name}' '#{stingray_tarball_url}'"
12
+ end
13
+ end
14
+
15
+ def have_stingray_tarball?(tarball, sha1sum)
16
+ File.exists?(tarball) &&
17
+ get_stingray_tarball_sha1sum(tarball) == sha1sum
18
+ end
19
+
20
+ def get_stingray_tarball_sha1sum(tarball)
21
+ `openssl dgst -sha1 #{tarball}`.chomp.split.last
22
+ end
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env ruby
2
+ require 'stingray-exec'
3
+ exit Stingray::Exec::Cli.main
@@ -0,0 +1,10 @@
1
+ #!/usr/bin/env stingray-exec
2
+ # vim:filetype=ruby
3
+
4
+ ssl_verify_mode :none
5
+
6
+ # Adds a pool named by the first positional argument with nodes given from all
7
+ # remaining arguments. Note that we don't start at `ARGV.first` because this
8
+ # script is evaluated from within an existing ruby process.
9
+ pool.add_pool(ARGV[1] => ARGV[2..ARGV.length])
10
+ puts "Added!"
@@ -0,0 +1,6 @@
1
+ #!/usr/bin/env stingray-exec
2
+ # vim:filetype=ruby
3
+
4
+ # Running this script with DEBUG=1 should demonstrate how the
5
+ # backtrace includes *this* filename and the correct line number.
6
+ bork
@@ -0,0 +1,4 @@
1
+ # comments are ignored
2
+ # indented ones, too!
3
+ admin:admin
4
+ anything after the first non-comment line is discarded, too
@@ -0,0 +1,10 @@
1
+ #!/usr/bin/env stingray-exec
2
+ # vim:filetype=ruby
3
+
4
+ ssl_verify_mode :none
5
+
6
+ # Removes any number of named pools given as positional arguments. Note that
7
+ # we don't start at `ARGV.first` because this script is evaluated from within
8
+ # an existing ruby process.
9
+ pool.delete_pool(*ARGV[1..ARGV.length])
10
+ puts "Deleted!"
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env stingray-exec
2
+ # vim:filetype=ruby
3
+
4
+ ssl_verify_mode :none
5
+
6
+ foreach(pool.get_pool_names[:pool_names][:item]) do |n|
7
+ puts n
8
+ end
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env stingray-exec
2
+ # vim:filetype=ruby
3
+
4
+ ssl_verify_mode :none
5
+
6
+ foreach(virtual_server.get_virtual_server_names[:names][:item]) do |n|
7
+ puts n
8
+ end
@@ -0,0 +1,119 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'wasabi'
4
+
5
+ USAGE = <<-EOU
6
+ Usage: #{File.basename($0)} [-h|--help] <stingray-wsdl-dir>
7
+
8
+ Generate a YAML blob containing all methods found in the WSDL files provided in
9
+ the built-in Stingray docs. This is done so that we can use Savon::Model to
10
+ build classes with predefined actions without having to distribute the WSDL
11
+ files ourselves, which would be uncool and probably illegal.
12
+ EOU
13
+ STINGRAY_WSDL_CONFIGURATIONS = %w(
14
+ AFM
15
+ AlertCallback
16
+ Alerting.Action
17
+ Alerting.EventType
18
+ Catalog.Aptimizer.Profile
19
+ Catalog.Authenticators
20
+ Catalog.Bandwidth
21
+ Catalog.JavaExtension
22
+ Catalog.Monitor
23
+ Catalog.Persistence
24
+ Catalog.Protection
25
+ Catalog.Rate
26
+ Catalog.Rule
27
+ Catalog.SLM
28
+ Catalog.SSL.CertificateAuthorities
29
+ Catalog.SSL.Certificates
30
+ Catalog.SSL.ClientCertificates
31
+ Catalog.SSL.DNSSEC
32
+ Conf.Extra_1_0
33
+ Conf.Extra
34
+ Diagnose_1_0
35
+ Diagnose
36
+ GLB.Service
37
+ GlobalSettings
38
+ Location
39
+ Pool
40
+ System.AccessLogs
41
+ System.Backups
42
+ System.Cache_1_0
43
+ System.Cache_1_1
44
+ System.Cache
45
+ System.CloudCredentials
46
+ System.Connections
47
+ System.LicenseKeys
48
+ System.Log
49
+ System.MachineInfo
50
+ System.Management
51
+ System.RequestLogs
52
+ System.Stats
53
+ System.Steelhead
54
+ TrafficIPGroups
55
+ Users
56
+ VirtualServer
57
+ )
58
+
59
+ class ActionsGenerator
60
+ def self.main(argv)
61
+ wsdl_root = argv.first
62
+ if %w(-h --help).include?(wsdl_root)
63
+ $stderr.puts(USAGE)
64
+ return 0
65
+ elsif wsdl_root.nil? || wsdl_root.empty?
66
+ $stderr.puts "ERROR: Missing required argument <stingray-wsdl-dir>"
67
+ $stderr.puts(USAGE)
68
+ return 1
69
+ end
70
+
71
+ return new(wsdl_root).generate!
72
+ rescue => e
73
+ $stderr.puts "ERROR: #{e.class.name} #{e.message}"
74
+ $stderr.puts e.backtrace.join("\n") if ENV['DEBUG']
75
+ return 2
76
+ end
77
+
78
+ def initialize(wsdl_root, out = $stdout)
79
+ @wsdl_root = wsdl_root
80
+ @out = out
81
+ end
82
+
83
+ def generate!
84
+ @out.puts generate_actions_json
85
+ return 0
86
+ rescue => e
87
+ $stderr.puts "ERROR: #{e.class.name} #{e.message}"
88
+ $stderr.puts e.backtrace.join("\n") if ENV['DEBUG']
89
+ return 2
90
+ end
91
+
92
+ private
93
+ def generate_actions_json
94
+ actions = {}
95
+ STINGRAY_WSDL_CONFIGURATIONS.each do |cfg|
96
+ actions[cfg] = generate_actions_for_config(cfg)
97
+ end
98
+
99
+ YAML.dump(actions)
100
+ end
101
+
102
+ def generate_actions_for_config(cfg)
103
+ doc = Wasabi.document(File.read("#{@wsdl_root}/#{cfg}.wsdl"))
104
+ sorted_ops = {}
105
+ ops = doc.operations
106
+ ops.keys.sort.each do |k|
107
+ sorted_ops[k] = ops[k]
108
+ end
109
+ sorted_ops
110
+ rescue => e
111
+ $stderr.puts "ERROR: getting operations for #{cfg}: #{e.class.name} #{e.message}"
112
+ $stderr.puts e.backtrace.join("\n") if ENV['DEBUG']
113
+ {}
114
+ end
115
+ end
116
+
117
+ if $0 == __FILE__
118
+ exit(ActionsGenerator.main(ARGV))
119
+ end
@@ -0,0 +1,5 @@
1
+ module Stingray
2
+ end
3
+
4
+ require 'stingray/exec/version'
5
+ require 'stingray/exec/cli'
@@ -0,0 +1,112 @@
1
+ require 'stingray/junk'
2
+
3
+ module Stingray
4
+ module ControlApi
5
+ CONFIGURATIONS = {}.tap do |c|
6
+ %w(
7
+ AFM
8
+ AlertCallback
9
+ Alerting.Action
10
+ Alerting.EventType
11
+ Catalog.Aptimizer.Profile
12
+ Catalog.Authenticators
13
+ Catalog.Bandwidth
14
+ Catalog.JavaExtension
15
+ Catalog.Monitor
16
+ Catalog.Persistence
17
+ Catalog.Protection
18
+ Catalog.Rate
19
+ Catalog.Rule
20
+ Catalog.SLM
21
+ Catalog.SSL.CertificateAuthorities
22
+ Catalog.SSL.Certificates
23
+ Catalog.SSL.ClientCertificates
24
+ Catalog.SSL.DNSSEC
25
+ Conf.Extra_1_0
26
+ Conf.Extra
27
+ Diagnose_1_0
28
+ Diagnose
29
+ GLB.Service
30
+ GlobalSettings
31
+ Location
32
+ Pool
33
+ System.AccessLogs
34
+ System.Backups
35
+ System.Cache_1_0
36
+ System.Cache_1_1
37
+ System.Cache
38
+ System.CloudCredentials
39
+ System.Connections
40
+ System.LicenseKeys
41
+ System.Log
42
+ System.MachineInfo
43
+ System.Management
44
+ System.RequestLogs
45
+ System.Stats
46
+ System.Steelhead
47
+ TrafficIPGroups
48
+ Users
49
+ VirtualServer
50
+ ).each do |cfg|
51
+ c[cfg] = {
52
+ :snaked => Stingray::Junk.snakify(cfg),
53
+ :consted => Stingray::Junk.constify(cfg),
54
+ }
55
+ end
56
+ end
57
+ CONFIGURATIONS_BY_CONST = {}.tap do |c|
58
+ CONFIGURATIONS.each do |k, v|
59
+ c[v[:consted]] = v.merge(:ns => k)
60
+ end
61
+ end
62
+
63
+ def self.const_missing(sym)
64
+ const = sym.to_s
65
+ snaked = (CONFIGURATIONS_BY_CONST[const] || {})[:snaked]
66
+ unless snaked
67
+ return super
68
+ end
69
+
70
+ require 'savon'
71
+ require 'stingray/control_api/endpoint'
72
+ require 'stingray/control_api/actions'
73
+
74
+ const_set(sym, Class.new(Object) do
75
+ extend Savon::Model
76
+
77
+ class << self
78
+ attr_accessor :_action_map
79
+ end
80
+ self._action_map = Stingray::ControlApi::Actions.send(:"#{snaked}_action_map")
81
+
82
+ actions(*_action_map.keys.map(&:to_sym))
83
+ _action_map.keys.each do |action|
84
+ action_str = action.to_s
85
+ response_key = :"#{action_str}_response"
86
+ define_method(action) do |*args|
87
+ custom_method = :"_custom_#{action_str}"
88
+ if respond_to?(custom_method)
89
+ # use a custom method defined in a *Methods module
90
+ return send(custom_method, *args).body[response_key]
91
+ else
92
+ # fall back to the Savon::Model version
93
+ return super(*args).body[response_key]
94
+ end
95
+ end
96
+ end
97
+
98
+ basic_auth(*Stingray::ControlApi::Endpoint.auth)
99
+ endpoint Stingray::ControlApi::Endpoint.full_endpoint_uri
100
+ namespace Stingray::ControlApi::Actions.send(:"#{snaked}_namespace")
101
+
102
+ _methods_file = File.expand_path("../control_api/#{snaked}_methods.rb", __FILE__)
103
+ if File.exists?(_methods_file)
104
+ load _methods_file
105
+ instance_eval do
106
+ include Stingray::ControlApi.const_get("#{const}Methods")
107
+ end
108
+ end
109
+ end)
110
+ end
111
+ end
112
+ end