neustar_pfm_cli 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 31e10ae19309549fbb8eb80086dc6a1c15b38a3d
4
+ data.tar.gz: 8ef4098d878dddd220e18ce0b8dd38f57b1d818b
5
+ SHA512:
6
+ metadata.gz: 1d6c941726dd0f34508642f4e2ece92b9a6190e0998d704f97d9d6f5e75c8c9056782e64c28806b47ec9a923ef1c2939f403466ca4d1e733aeb10d97895ab2df
7
+ data.tar.gz: f3270aa03810d943ad6e16776587e47ca44d84547f4da71d289a1c8335924975a0a423b40f53baae98c2a7b0e3299f50b303ff7be29209d7e0f620da31a07655
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
@@ -0,0 +1,4 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.2.2
4
+ before_install: gem install bundler -v 1.10.6
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in neustar_pfm_cli.gemspec
4
+ gemspec
@@ -0,0 +1,109 @@
1
+ # neustar-pfm-cli
2
+
3
+ ## About
4
+
5
+ - Neustar WebPerformance Management API を叩く非公認コマンドラインツール
6
+ - 負荷試験シナリオスクリプトのアップロード、Local Validate 等を行うことが出来る
7
+ - 負荷試験のスケジュール等を行うことが出来る
8
+
9
+ ## Reference
10
+
11
+ - https://apidocs.wpm.neustar.biz/loadtesting
12
+ - https://apidocs.wpm.neustar.biz/script
13
+
14
+ ## Installation
15
+
16
+ Add this line to your application's Gemfile:
17
+
18
+ ```ruby
19
+ gem 'neustar_pfm_cli'
20
+ ```
21
+
22
+ And then execute:
23
+
24
+ $ bundle
25
+
26
+ Or install it yourself as:
27
+
28
+ $ gem install neustar_pfm_cli
29
+
30
+ ## Usage
31
+
32
+ ### 環境変数
33
+
34
+ - API キー及び、Shared Secret
35
+
36
+ ```sh
37
+ export NEUSTAR_API_KEY="xxxxxxxxxxxxxxxxxxxxxxxxxx"
38
+ export NEUSTAR_SHARED_KEY="xxxxxxx"
39
+ ```
40
+
41
+ - Local Validator
42
+
43
+ ```sh
44
+ export NEUSTAR_LOCAL_VALIDATOR_PATH="/path/to/local-validator-4.34.17/bin/validator"
45
+ ```
46
+
47
+ ### loadtest
48
+
49
+ - ls ... 負荷試験一覧を取得する
50
+
51
+ ```sh
52
+ bundle exec bin/npc-loadtest ls | jq '.data.items[]'
53
+ ```
54
+
55
+ - del ... 指定した負荷試験を削除する
56
+
57
+ ```sh
58
+ bundle exec bin/npc-loadtest del -i $(bundle exec bin/npc-loadtest ls | jq '.data.items[].id')
59
+ ```
60
+
61
+ - sc ... 指定した負荷試験をスケジュールする
62
+
63
+ ```sh
64
+ bundle exec bin/npc-loadtest sc -f loadtest.yml
65
+ ```
66
+
67
+ loadtest.yml は以下のように定義する。
68
+
69
+ ```yaml
70
+ name: "myloadtest"
71
+ region: "AP_NORTHEAST"
72
+ scripts:
73
+ - percentage: 100
74
+ scriptId: "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
75
+ parts:
76
+ - duration: 5
77
+ maxUsers: 10
78
+ type: "RAMP"
79
+ ```
80
+
81
+ ### scripting
82
+
83
+ - ls ... 負荷試験シナリオスクリプト一覧を取得する
84
+
85
+ ```sh
86
+ bundle exec bin/npc-scripting ls | jq '.data.items[]'
87
+ ```
88
+
89
+ - val ... 指定した負荷試験シナリオスクリプトを Local Validator を利用してチェックする
90
+
91
+ ```sh
92
+ bundle exec bin/npc-scripting val -f path/to/script.js
93
+ ```
94
+ - up ... 指定した負荷試験シナリオスクリプトをアップロードする
95
+
96
+ ```sh
97
+ bundle exec bin/npc-scripting up -n script_name -f path/to/script.js -t tag1,tag2 -d description
98
+ ```
99
+
100
+ ## Development
101
+
102
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake false` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
103
+
104
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
105
+
106
+ ## Contributing
107
+
108
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/neustar_pfm_cli.
109
+
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "neustar_pfm_cli"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start
@@ -0,0 +1,7 @@
1
+ #!/usr/bin/env ruby
2
+ # coding: utf-8
3
+
4
+ # require "thor"
5
+ require "neustar_pfm_cli/loadtest"
6
+
7
+ NeustarPfmCli::LoadTest.start
@@ -0,0 +1,7 @@
1
+ #!/usr/bin/env ruby
2
+ # coding: utf-8
3
+
4
+ require "thor"
5
+ require "neustar_pfm_cli/scripting"
6
+
7
+ NeustarPfmCli::Scripting.start
@@ -0,0 +1,7 @@
1
+ #!/bin/bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+
5
+ bundle install
6
+
7
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,5 @@
1
+ require "neustar_pfm_cli/version"
2
+
3
+ module NeustarPfmCli
4
+ # Your code goes here...
5
+ end
@@ -0,0 +1,13 @@
1
+ require "digest/md5"
2
+ require "faraday"
3
+
4
+ def request
5
+ $api_key = ENV["NEUSTAR_API_KEY"]
6
+ shared_key = ENV["NEUSTAR_SHARED_KEY"]
7
+ timestamp = Time.now.to_i
8
+ $sig = Digest::MD5.hexdigest($api_key + shared_key + timestamp.to_s)
9
+
10
+ Faraday::Connection.new(:url => 'https://api.neustar.biz') do |builder|
11
+ builder.use Faraday::Adapter::NetHttp
12
+ end
13
+ end
@@ -0,0 +1,61 @@
1
+ require "neustar_pfm_cli/common"
2
+ require "thor"
3
+ require "yaml"
4
+ require "json"
5
+
6
+ module NeustarPfmCli
7
+ class LoadTest < Thor
8
+ desc "list", "負荷試験の一覧を取得する"
9
+ method_option :limit, :type => :string, :aliases => '-l', :desc => "取得する件数を指定", :default => "10"
10
+ def ls
11
+ begin
12
+ res = request.get "/performance/load/1.0/list?limit=#{options[:limit]}&apikey=#{$api_key}&sig=#{$sig}"
13
+ puts res.body
14
+ rescue => e
15
+ puts "[" + "\e[31m" + "ERROR" + "\e[0m" + "] #{e}"
16
+ end
17
+ end
18
+
19
+ desc "delete", "負荷試験を削除する"
20
+ method_option :id, :type => :string, :aliases => '-i', :desc => "loadTestId を指定する"
21
+ def del
22
+ begin
23
+ res = request.delete "/performance/load/1.0/#{options[:id]}/delete?apikey=#{$api_key}&sig=#{$sig}"
24
+ puts res.body
25
+ rescue => e
26
+ puts "[" + "\e[31m" + "ERROR" + "\e[0m" + "] #{e}"
27
+ end
28
+ end
29
+
30
+ desc "sc", "負荷試験をスケジュールする"
31
+ method_option :file, :type => :string, :aliases => '-f', :desc => "負荷試験定義ファイルのパスを指定"
32
+ def sc
33
+ begin
34
+ params = load_loadtest_file(options[:file])
35
+ rescue => e
36
+ puts "[" + "\e[31m" + "ERROR" + "\e[0m" + "] #{e}"
37
+ end
38
+
39
+ begin
40
+ res = request.post do |req|
41
+ req.url "/performance/load/1.0/schedule?apikey=#{$api_key}&sig=#{$sig}"
42
+ req.headers["Content-Type"] = "application/json"
43
+ puts req.body = params.to_json
44
+ end
45
+ puts res.body
46
+ rescue => e
47
+ puts "[" + "\e[31m" + "ERROR" + "\e[0m" + "] #{e}"
48
+ exit 1
49
+ end
50
+
51
+ end
52
+
53
+ private
54
+
55
+ def load_loadtest_file(filename)
56
+ params = YAML.load_file(filename)
57
+ return params
58
+ end
59
+
60
+ end
61
+ end
@@ -0,0 +1,81 @@
1
+ require "neustar_pfm_cli/common"
2
+ require "yaml"
3
+ require "json"
4
+ require "open3"
5
+
6
+ module NeustarPfmCli
7
+ class Scripting < Thor
8
+
9
+ desc "list", "シナリオスクリプト一覧を取得する"
10
+ method_option :limit, :type => :string, :aliases => '-l', :desc => "取得する件数を指定", :default => "10"
11
+ def ls
12
+ begin
13
+ res = request.get "/performance/script/1.0/ValidScripts/?limit#{options[:limit]}&apikey=#{$api_key}&sig=#{$sig}"
14
+ puts res.body
15
+ rescue => e
16
+ puts "[" + "\e[31m" + "ERROR" + "\e[0m" + "] #{e}"
17
+ exit 1
18
+ end
19
+ end
20
+
21
+ desc "validate", "シナリオスクリプトを Local Validator を使って validate する"
22
+ method_option :file, :type => :string, :aliases => '-f', :desc => "スクリプトファイルのパスを指定"
23
+ def val
24
+ begin
25
+ unless ENV["NEUSTAR_LOCAL_VALIDATOR_PATH"] == nil then
26
+ Open3.popen3("#{ENV["NEUSTAR_LOCAL_VALIDATOR_PATH"]} -verbose #{options[:file]}") do |stdin, stdout, stderr|
27
+ puts "\e[32m" + stdout.read + "\e[0m"
28
+ puts "\e[33m" + stderr.read + "\e[0m"
29
+ end
30
+ else
31
+ puts "[" + "\e[31m" + "ERROR" + "\e[0m" + "] 環境変数 NEUSTAR_LOCAL_VALIDATOR_PATH に Local Validator のパスを指定して下さい!!"
32
+ exit 1
33
+ end
34
+ rescue => e
35
+ puts "[" + "\e[31m" + "ERROR" + "\e[0m" + "] #{e}"
36
+ exit 1
37
+ end
38
+ end
39
+
40
+ desc "upload", "シナリオスクリプトをアップロードする"
41
+ method_option :name, :type => :string, :aliases => '-n', :desc => "スクリプト名を指定"
42
+ method_option :file, :type => :string, :aliases => '-f', :desc => "スクリプトファイルのパスを指定"
43
+ method_option :tags, :type => :string, :aliases => '-t', :desc => "スクリプトの Tag を指定", :require => false
44
+ method_option :desc, :type => :string, :aliases => '-d', :desc => "スクリプトの Description を指定", :require => false
45
+ def up
46
+
47
+ begin
48
+ tags = { "tags" => options[:tags].split(",") }
49
+ desc = { "description" => options[:desc] }
50
+ params = tags.merge(desc)
51
+ rescue => e
52
+ puts "[" + "\e[31m" + "ERROR" + "\e[0m" + "] #{e}"
53
+ end
54
+
55
+ begin
56
+ res = request.post do |req|
57
+ req.url "/performance/script/1.0/upload/body?apikey=#{$api_key}&sig=#{$sig}"
58
+ req.headers["Content-Type"] = "application/json"
59
+ puts req.body = {
60
+ "name": options[:name],
61
+ "scriptBody": load_scenario_file(options[:file])
62
+ }.merge(params).to_json
63
+ end
64
+ puts res.body
65
+ rescue => e
66
+ puts "[" + "\e[31m" + "ERROR" + "\e[0m" + "] #{e}"
67
+ exit 1
68
+ end
69
+ end
70
+
71
+ private
72
+
73
+ def load_scenario_file(file_name)
74
+ file = open(file_name)
75
+ scenario = file.read
76
+ file.close
77
+ return scenario
78
+ end
79
+
80
+ end
81
+ end
@@ -0,0 +1,3 @@
1
+ module NeustarPfmCli
2
+ VERSION = "0.0.2"
3
+ end
@@ -0,0 +1,27 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'neustar_pfm_cli/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "neustar_pfm_cli"
8
+ spec.version = NeustarPfmCli::VERSION
9
+ spec.authors = ["inokappa"]
10
+ spec.email = ["inokara at gmail.com"]
11
+
12
+ spec.summary = %q{Command Line Tool for Neustar WebPerformance Management API}
13
+ spec.description = %q{Command Line Tool for Neustar WebPerformance Management API}
14
+ spec.homepage = "https://github.com/inokappa"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
17
+ spec.bindir = "exe"
18
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency "bundler", "~> 1.10"
22
+ spec.add_development_dependency "rake", "~> 10.0"
23
+ spec.add_development_dependency "rspec"
24
+
25
+ spec.add_runtime_dependency "faraday"
26
+ spec.add_runtime_dependency "thor"
27
+ end
metadata ADDED
@@ -0,0 +1,128 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: neustar_pfm_cli
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.2
5
+ platform: ruby
6
+ authors:
7
+ - inokappa
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2016-07-15 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.10'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.10'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: faraday
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: thor
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ description: Command Line Tool for Neustar WebPerformance Management API
84
+ email:
85
+ - inokara at gmail.com
86
+ executables: []
87
+ extensions: []
88
+ extra_rdoc_files: []
89
+ files:
90
+ - ".gitignore"
91
+ - ".travis.yml"
92
+ - Gemfile
93
+ - README.md
94
+ - Rakefile
95
+ - bin/console
96
+ - bin/npc-loadtest
97
+ - bin/npc-scripting
98
+ - bin/setup
99
+ - lib/neustar_pfm_cli.rb
100
+ - lib/neustar_pfm_cli/common.rb
101
+ - lib/neustar_pfm_cli/loadtest.rb
102
+ - lib/neustar_pfm_cli/scripting.rb
103
+ - lib/neustar_pfm_cli/version.rb
104
+ - neustar_pfm_cli.gemspec
105
+ homepage: https://github.com/inokappa
106
+ licenses: []
107
+ metadata: {}
108
+ post_install_message:
109
+ rdoc_options: []
110
+ require_paths:
111
+ - lib
112
+ required_ruby_version: !ruby/object:Gem::Requirement
113
+ requirements:
114
+ - - ">="
115
+ - !ruby/object:Gem::Version
116
+ version: '0'
117
+ required_rubygems_version: !ruby/object:Gem::Requirement
118
+ requirements:
119
+ - - ">="
120
+ - !ruby/object:Gem::Version
121
+ version: '0'
122
+ requirements: []
123
+ rubyforge_project:
124
+ rubygems_version: 2.6.4
125
+ signing_key:
126
+ specification_version: 4
127
+ summary: Command Line Tool for Neustar WebPerformance Management API
128
+ test_files: []