scalr_api_v2 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +11 -0
- data/.rspec +2 -0
- data/.rubocop.yml +44 -0
- data/.travis.yml +10 -0
- data/CODE_OF_CONDUCT.md +49 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +21 -0
- data/README.md +61 -0
- data/Rakefile +6 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/exe/scalr_api_v2 +3 -0
- data/lib/scalr_api_v2/cli.rb +85 -0
- data/lib/scalr_api_v2/config.rb +21 -0
- data/lib/scalr_api_v2/farms.rb +20 -0
- data/lib/scalr_api_v2/request.rb +128 -0
- data/lib/scalr_api_v2/scripts.rb +61 -0
- data/lib/scalr_api_v2/servers.rb +20 -0
- data/lib/scalr_api_v2/version.rb +4 -0
- data/lib/scalr_api_v2.rb +10 -0
- data/scalr_api_v2.gemspec +44 -0
- metadata +249 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: bfaa11e42bd9e4ffd2b715cf1abbef70f4b0395c
|
4
|
+
data.tar.gz: cdbca4d590cc172a600fb582d6731eab9199974d
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: bc3f4781eeb9d7050d58a2b187763f4cd09635af7353484a7ddd2ac9a8c59f80b2efc47f3201c0adb54731d9e30e8892d9f79daf2636d0af875bc45a22d0a76f
|
7
|
+
data.tar.gz: ef9e6679d121005e3b56d3713c1cf65a877d8a44bd429441b0de5728ca8916ff8beee7b06394eb21f63d8c0467efd640c47307ddf5dce70e9a1e8b038150ad92
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.rubocop.yml
ADDED
@@ -0,0 +1,44 @@
|
|
1
|
+
# This configuration was generated by
|
2
|
+
# `rubocop --auto-gen-config`
|
3
|
+
# on 2017-04-21 12:42:15 +0000 using RuboCop version 0.41.2.
|
4
|
+
# The point is for the user to remove these configuration records
|
5
|
+
# one by one as the offenses are removed from the code base.
|
6
|
+
# Note that changes in the inspected code, or installation of new
|
7
|
+
# versions of RuboCop, may require this file to be generated again.
|
8
|
+
|
9
|
+
AllCops:
|
10
|
+
Exclude:
|
11
|
+
- 'localbundle/**/*'
|
12
|
+
|
13
|
+
# Offense count: 1
|
14
|
+
Metrics/AbcSize:
|
15
|
+
Max: 50
|
16
|
+
|
17
|
+
# Offense count: 9
|
18
|
+
# Configuration parameters: AllowHeredoc, AllowURI, URISchemes.
|
19
|
+
# URISchemes: http, https
|
20
|
+
Metrics/LineLength:
|
21
|
+
Max: 200
|
22
|
+
|
23
|
+
# Offense count: 1
|
24
|
+
# Configuration parameters: CountComments.
|
25
|
+
Metrics/MethodLength:
|
26
|
+
Max: 60
|
27
|
+
|
28
|
+
Metrics/BlockLength:
|
29
|
+
Max: 60
|
30
|
+
|
31
|
+
# Offense count: 1
|
32
|
+
# Configuration parameters: MinBodyLength.
|
33
|
+
Style/GuardClause:
|
34
|
+
Exclude:
|
35
|
+
- 'scalr_api_v2.gemspec'
|
36
|
+
|
37
|
+
# Offense count: 6
|
38
|
+
# Cop supports --auto-correct.
|
39
|
+
# Configuration parameters: AllowMultipleReturnValues.
|
40
|
+
Style/RedundantReturn:
|
41
|
+
Enabled: false
|
42
|
+
|
43
|
+
Style/BracesAroundHashParameters:
|
44
|
+
Enabled: false
|
data/.travis.yml
ADDED
data/CODE_OF_CONDUCT.md
ADDED
@@ -0,0 +1,49 @@
|
|
1
|
+
# Contributor Code of Conduct
|
2
|
+
|
3
|
+
As contributors and maintainers of this project, and in the interest of
|
4
|
+
fostering an open and welcoming community, we pledge to respect all people who
|
5
|
+
contribute through reporting issues, posting feature requests, updating
|
6
|
+
documentation, submitting pull requests or patches, and other activities.
|
7
|
+
|
8
|
+
We are committed to making participation in this project a harassment-free
|
9
|
+
experience for everyone, regardless of level of experience, gender, gender
|
10
|
+
identity and expression, sexual orientation, disability, personal appearance,
|
11
|
+
body size, race, ethnicity, age, religion, or nationality.
|
12
|
+
|
13
|
+
Examples of unacceptable behavior by participants include:
|
14
|
+
|
15
|
+
* The use of sexualized language or imagery
|
16
|
+
* Personal attacks
|
17
|
+
* Trolling or insulting/derogatory comments
|
18
|
+
* Public or private harassment
|
19
|
+
* Publishing other's private information, such as physical or electronic
|
20
|
+
addresses, without explicit permission
|
21
|
+
* Other unethical or unprofessional conduct
|
22
|
+
|
23
|
+
Project maintainers have the right and responsibility to remove, edit, or
|
24
|
+
reject comments, commits, code, wiki edits, issues, and other contributions
|
25
|
+
that are not aligned to this Code of Conduct, or to ban temporarily or
|
26
|
+
permanently any contributor for other behaviors that they deem inappropriate,
|
27
|
+
threatening, offensive, or harmful.
|
28
|
+
|
29
|
+
By adopting this Code of Conduct, project maintainers commit themselves to
|
30
|
+
fairly and consistently applying these principles to every aspect of managing
|
31
|
+
this project. Project maintainers who do not follow or enforce the Code of
|
32
|
+
Conduct may be permanently removed from the project team.
|
33
|
+
|
34
|
+
This code of conduct applies both within project spaces and in public spaces
|
35
|
+
when an individual is representing the project or its community.
|
36
|
+
|
37
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
38
|
+
reported by contacting a project maintainer at davemeekin.github@gmail.com. All
|
39
|
+
complaints will be reviewed and investigated and will result in a response that
|
40
|
+
is deemed necessary and appropriate to the circumstances. Maintainers are
|
41
|
+
obligated to maintain confidentiality with regard to the reporter of an
|
42
|
+
incident.
|
43
|
+
|
44
|
+
This Code of Conduct is adapted from the [Contributor Covenant][homepage],
|
45
|
+
version 1.3.0, available at
|
46
|
+
[http://contributor-covenant.org/version/1/3/0/][version]
|
47
|
+
|
48
|
+
[homepage]: http://contributor-covenant.org
|
49
|
+
[version]: http://contributor-covenant.org/version/1/3/0/
|
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2017 david.meekin
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,61 @@
|
|
1
|
+
[![Build Status](https://travis-ci.org/autotraderuk/scalr_api_v2.svg?branch=master)](https://travis-ci.org/autotraderuk/scalr_api_v2)
|
2
|
+
# ScalrApiV2
|
3
|
+
|
4
|
+
Ruby gem to allow you to develop against V2 of the [SCALR API](https://api-explorer.scalr.com)
|
5
|
+
|
6
|
+
## Installation
|
7
|
+
|
8
|
+
Add this line to your application's Gemfile:
|
9
|
+
|
10
|
+
```ruby
|
11
|
+
gem 'scalr_api_v2'
|
12
|
+
```
|
13
|
+
|
14
|
+
And then execute:
|
15
|
+
|
16
|
+
$ bundle
|
17
|
+
|
18
|
+
Or install it yourself as:
|
19
|
+
|
20
|
+
$ gem install scalr_api_v2
|
21
|
+
|
22
|
+
## Usage
|
23
|
+
|
24
|
+
Set the below environment variables:
|
25
|
+
|
26
|
+
export SCALR_API_KEY=your-api-key
|
27
|
+
export SCALR_API_SECRET=your-api-secret
|
28
|
+
export SCALR_URL=scalr-api-url
|
29
|
+
export SCALR_ENV_ID=id-of-desired-environment
|
30
|
+
|
31
|
+
### in your code
|
32
|
+
|
33
|
+
require 'scalr_api_v2'
|
34
|
+
scalr = ScalrApiV2::Farms.new
|
35
|
+
puts scalr.list
|
36
|
+
|
37
|
+
|
38
|
+
### from your shell
|
39
|
+
|
40
|
+
$ scalr_api_v2 farm list
|
41
|
+
|
42
|
+
### limitations
|
43
|
+
|
44
|
+
At present there is a limited subset of api commands avaialble via this GEM. Functionality is limited to working with scripts. As well as listing farms and servers.
|
45
|
+
Examples of the functionality provided can be found in the rspec tests.
|
46
|
+
|
47
|
+
## Development
|
48
|
+
|
49
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `bundle exec rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
50
|
+
|
51
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `lib/scalr_api_v2/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).
|
52
|
+
|
53
|
+
## Contributing
|
54
|
+
|
55
|
+
Bug reports and pull requests (with tests) are welcome on GitHub at https://github.com/autotraderuk/scalr_api_v2. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
|
56
|
+
|
57
|
+
|
58
|
+
## License
|
59
|
+
|
60
|
+
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
61
|
+
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'bundler/setup'
|
4
|
+
require 'scalr_api_v2'
|
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
|
data/bin/setup
ADDED
data/exe/scalr_api_v2
ADDED
@@ -0,0 +1,85 @@
|
|
1
|
+
# ScalrApiV2::CLI
|
2
|
+
module ScalrApiV2
|
3
|
+
require 'thor'
|
4
|
+
require 'scalr_api_v2'
|
5
|
+
|
6
|
+
# define CLI class that extends Thor
|
7
|
+
class Script < Thor
|
8
|
+
desc 'list', 'lists scripts avaialble in scalr'
|
9
|
+
def list
|
10
|
+
puts JSON.generate(ScalrApiV2::Scripts.new.list)
|
11
|
+
end
|
12
|
+
|
13
|
+
desc 'versions', 'lists script versions avaialble in scalr'
|
14
|
+
option :script_id, required: true
|
15
|
+
def versions
|
16
|
+
puts JSON.generate(ScalrApiV2::Scripts.new.versions(options[:script_id]))
|
17
|
+
end
|
18
|
+
|
19
|
+
desc 'create', 'creates script and makes it available in scalr'
|
20
|
+
option :script_object, required: true
|
21
|
+
def create
|
22
|
+
puts JSON.generate(ScalrApiV2::Scripts.new.create(options[:script_object]))
|
23
|
+
end
|
24
|
+
|
25
|
+
desc 'create_version', 'creates script version and makes it available in scalr'
|
26
|
+
option :script_id, required: true
|
27
|
+
option :script_object, required: true
|
28
|
+
def create_version
|
29
|
+
puts JSON.generate(ScalrApiV2::Scripts.new.create_version(options[:script_id], options[:script_object]))
|
30
|
+
end
|
31
|
+
|
32
|
+
desc 'update', 'updates script version and makes it available in scalr'
|
33
|
+
option :script_id, required: true
|
34
|
+
option :script_version, required: true
|
35
|
+
option :script_object, required: true
|
36
|
+
def update
|
37
|
+
puts JSON.generate(ScalrApiV2::Scripts.new.update_version(options[:script_id], options[:script_version], options[:script_object]))
|
38
|
+
end
|
39
|
+
|
40
|
+
desc 'execute', 'executes script on server specified'
|
41
|
+
option :script_id, required: true
|
42
|
+
option :script_version, required: false
|
43
|
+
option :script_execution_object, required: true
|
44
|
+
def execute
|
45
|
+
if options[script_version].nil?
|
46
|
+
puts JSON.generate(ScalrApiV2::Scripts.new.execute(options[:script_id], options[:script_execution_object]))
|
47
|
+
else
|
48
|
+
puts JSON.generate(ScalrApiV2::Scripts.new.execute_version(options[:script_id], options[:script_version], ooptions[:script_execution_object]))
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
# define CLI class that extends Thor
|
54
|
+
class Farm < Thor
|
55
|
+
desc 'list', 'lists farms avaialble in scalr'
|
56
|
+
def list
|
57
|
+
puts JSON.generate(ScalrApiV2::Farms.new.list)
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
# define CLI class that extends Thor
|
62
|
+
class Server < Thor
|
63
|
+
desc 'list', 'lists servers avaialble in scalr'
|
64
|
+
def list
|
65
|
+
puts JSON.generate(ScalrApiV2::Servers.new.list)
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
# define CLI class that extends Thor
|
70
|
+
class CLI < Thor
|
71
|
+
desc 'version', 'prints version number'
|
72
|
+
def version
|
73
|
+
puts ScalrApiV2::VERSION
|
74
|
+
end
|
75
|
+
|
76
|
+
desc 'scripts', 'provides access to manage scalr scripts'
|
77
|
+
subcommand 'script', Script
|
78
|
+
|
79
|
+
desc 'farm', 'provides access to manage scalr farms'
|
80
|
+
subcommand 'farm', Farm
|
81
|
+
|
82
|
+
desc 'server', 'provides access to manage scalr servers'
|
83
|
+
subcommand 'server', Server
|
84
|
+
end
|
85
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
module ScalrApiV2
|
2
|
+
# config class
|
3
|
+
class Config
|
4
|
+
def initialize; end
|
5
|
+
|
6
|
+
def config
|
7
|
+
config = {}
|
8
|
+
|
9
|
+
if ENV['SCALR_URL'].nil? || ENV['SCALR_KEY_ID'].nil? || ENV['SCALR_KEY_SECRET'].nil? || ENV['SCALR_ENV_ID'].nil?
|
10
|
+
config['error'] = 'Missing Environment variables, please configure SCALR_URL, SCALR_KEY_ID, SCALR_KEY_SECRET, SCALR_ENV_ID'
|
11
|
+
raise 'Missing Environment variables, please configure SCALR_URL, SCALR_KEY_ID, SCALR_KEY_SECRET, SCALR_ENV_ID'
|
12
|
+
else
|
13
|
+
config['url'] = ENV['SCALR_URL']
|
14
|
+
config['key_id'] = ENV['SCALR_KEY_ID']
|
15
|
+
config['key_secret'] = ENV['SCALR_KEY_SECRET']
|
16
|
+
config['env_id'] = ENV['SCALR_ENV_ID']
|
17
|
+
end
|
18
|
+
return config
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
# ScalrApiV2::Farms
|
2
|
+
module ScalrApiV2
|
3
|
+
require 'json'
|
4
|
+
|
5
|
+
# connection and request methods for interacting with the Scalr API
|
6
|
+
class Farms
|
7
|
+
def initialize
|
8
|
+
@config = ScalrApiV2::Config.new.config
|
9
|
+
@scalr = ScalrApiV2::Request.new
|
10
|
+
end
|
11
|
+
|
12
|
+
# List all scripts
|
13
|
+
def list
|
14
|
+
list = @scalr.list(format('/api/v1beta0/user/%s/farms/', @config['env_id']))
|
15
|
+
return list
|
16
|
+
end
|
17
|
+
|
18
|
+
# TODO: add remainig api calls
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,128 @@
|
|
1
|
+
# ScalrApiV2::Request
|
2
|
+
module ScalrApiV2
|
3
|
+
require 'uri'
|
4
|
+
require 'time'
|
5
|
+
require 'openssl'
|
6
|
+
require 'base64'
|
7
|
+
require 'rest-client'
|
8
|
+
require 'json'
|
9
|
+
|
10
|
+
# connection and request methods for interacting with the Scalr API
|
11
|
+
class Request
|
12
|
+
def initialize
|
13
|
+
@api_config = ScalrApiV2::Config.new.config
|
14
|
+
end
|
15
|
+
|
16
|
+
def request(method, url, body = '')
|
17
|
+
# JSON encode body if set
|
18
|
+
body = body.to_json if body != ''
|
19
|
+
|
20
|
+
# Split URL into components
|
21
|
+
parts = URI.parse(@api_config['url'] + url)
|
22
|
+
|
23
|
+
path = parts.path
|
24
|
+
# host = parts.host
|
25
|
+
# port = parts.port
|
26
|
+
|
27
|
+
query = ''
|
28
|
+
unless parts.query.nil?
|
29
|
+
# Convert querystring into an array
|
30
|
+
q = parts.query.split('&')
|
31
|
+
|
32
|
+
# Sort the querystring array
|
33
|
+
q.sort!
|
34
|
+
|
35
|
+
# Convert querystring array back to string
|
36
|
+
query = q.join('&')
|
37
|
+
end
|
38
|
+
|
39
|
+
# Create ISO 8601 date/time string
|
40
|
+
time = Time.now.utc.iso8601 + '+00:00'
|
41
|
+
|
42
|
+
# Collection of request data for generating signature
|
43
|
+
request = [
|
44
|
+
method,
|
45
|
+
time,
|
46
|
+
path,
|
47
|
+
query,
|
48
|
+
body
|
49
|
+
]
|
50
|
+
|
51
|
+
# Calculate signature based on request data
|
52
|
+
signature = 'V1-HMAC-SHA256 ' + Base64.encode64(OpenSSL::HMAC.digest(OpenSSL::Digest.new('sha256'), @api_config['key_secret'], request.join("\n"))).strip
|
53
|
+
|
54
|
+
# HTTP request headers
|
55
|
+
headers = {
|
56
|
+
'X-Scalr-Key-Id' => @api_config['key_id'],
|
57
|
+
'X-Scalr-Signature' => signature,
|
58
|
+
'X-Scalr-Date' => time,
|
59
|
+
'X-Scalr-Debug' => '1'
|
60
|
+
}
|
61
|
+
|
62
|
+
headers['Content-Type'] = 'application/json' if body != ''
|
63
|
+
begin
|
64
|
+
response = RestClient::Request.execute(
|
65
|
+
method: method,
|
66
|
+
url: @api_config['url'] + url,
|
67
|
+
headers: headers,
|
68
|
+
payload: body
|
69
|
+
)
|
70
|
+
rescue => e
|
71
|
+
raise "#{e} #{e.response}"
|
72
|
+
end
|
73
|
+
response = '{\n \"Error\": \"A problem occured: Response was empty\"\n}}' if response == ''
|
74
|
+
JSON.parse(response)
|
75
|
+
end
|
76
|
+
|
77
|
+
# List items from API
|
78
|
+
def list(url)
|
79
|
+
data = []
|
80
|
+
until url.nil?
|
81
|
+
response = request('GET', url)
|
82
|
+
if response['Error'].nil?
|
83
|
+
data.concat response['data']
|
84
|
+
url = response['pagination']['next']
|
85
|
+
else
|
86
|
+
data = response['Error']
|
87
|
+
url = nil
|
88
|
+
end
|
89
|
+
end
|
90
|
+
return data
|
91
|
+
end
|
92
|
+
|
93
|
+
# Fetch a single item from API
|
94
|
+
def fetch(url)
|
95
|
+
response = request('GET', url)
|
96
|
+
response['data'] = response['Error'] unless response['Error'].nil?
|
97
|
+
return response['data']
|
98
|
+
end
|
99
|
+
|
100
|
+
# Create item in API
|
101
|
+
def create(url, data)
|
102
|
+
response = request('POST', url, data)
|
103
|
+
response['data'] = response['Error'] unless response['Error'].nil?
|
104
|
+
return response['data']
|
105
|
+
end
|
106
|
+
|
107
|
+
# Delete item from API
|
108
|
+
def delete(url)
|
109
|
+
response = request('DELETE', url)
|
110
|
+
response['data'] = response['Error'] unless response['Error'].nil?
|
111
|
+
return response['data']
|
112
|
+
end
|
113
|
+
|
114
|
+
# Edit items in API
|
115
|
+
def post(url, data)
|
116
|
+
response = request('POST', url, data)
|
117
|
+
response['data'] = response['Error'] unless response['Error'].nil?
|
118
|
+
return response['data']
|
119
|
+
end
|
120
|
+
|
121
|
+
# Update items in API
|
122
|
+
def patch(url, data)
|
123
|
+
response = request('PATCH', url, data)
|
124
|
+
response['data'] = response['Error'] unless response['Error'].nil?
|
125
|
+
return response['data']
|
126
|
+
end
|
127
|
+
end
|
128
|
+
end
|
@@ -0,0 +1,61 @@
|
|
1
|
+
# ScalrApiV2::Scripts
|
2
|
+
module ScalrApiV2
|
3
|
+
# Class with the name of the GEM
|
4
|
+
# require 'uri'
|
5
|
+
# require 'time'
|
6
|
+
# require 'openssl'
|
7
|
+
# require 'base64'
|
8
|
+
# require 'rest_client'
|
9
|
+
# require 'json'
|
10
|
+
require 'json'
|
11
|
+
|
12
|
+
# connection and request methods for interacting with the Scalr API
|
13
|
+
class Scripts
|
14
|
+
def initialize
|
15
|
+
@config = ScalrApiV2::Config.new.config
|
16
|
+
@scalr = ScalrApiV2::Request.new
|
17
|
+
end
|
18
|
+
|
19
|
+
# List all scripts
|
20
|
+
def list
|
21
|
+
list = @scalr.list(format('/api/v1beta0/user/%s/scripts/', @config['env_id']))
|
22
|
+
return list
|
23
|
+
end
|
24
|
+
|
25
|
+
# List all script versions
|
26
|
+
def versions(script_id = 1)
|
27
|
+
list = @scalr.list(format('/api/v1beta0/user/%s/scripts/%s/script-versions/', @config['env_id'], script_id))
|
28
|
+
return list
|
29
|
+
end
|
30
|
+
|
31
|
+
# Create script accepts script_object as hash and generates JSON before making SCALR api call
|
32
|
+
def create(script_object)
|
33
|
+
item = @scalr.create(format('/api/v1beta0/user/%s/scripts/', @config['env_id']), JSON.generate(script_object))
|
34
|
+
return item
|
35
|
+
end
|
36
|
+
|
37
|
+
# Create script version
|
38
|
+
def create_version(script_id, script_object)
|
39
|
+
item = @scalr.create(format('/api/v1beta0/user/%s/scripts/%s/script-versions/', @config['env_id'], script_id), JSON.generate(script_object))
|
40
|
+
return item
|
41
|
+
end
|
42
|
+
|
43
|
+
# Update script version
|
44
|
+
def update_version(script_id, script_version, script_object)
|
45
|
+
item = @scalr.patch(format('/api/v1beta0/user/%s/scripts/%s/script-versions/%s/', @config['env_id'], script_id, script_version), JSON.generate(script_object))
|
46
|
+
return item
|
47
|
+
end
|
48
|
+
|
49
|
+
# execute version
|
50
|
+
def execute(script_id, script_execution_object)
|
51
|
+
item = @scalr.post(format('/api/v1beta0/user/%s/scripts/%s/actions/execute', @config['env_id'], script_id), JSON.generate(script_execution_object))
|
52
|
+
return item
|
53
|
+
end
|
54
|
+
|
55
|
+
# execute script version
|
56
|
+
def execute_version(script_id, script_version, script_execution_object)
|
57
|
+
item = @scalr.post(format('/api/v1beta0/user/%s/scripts/%s/script-versions/%s/actions/execute', @config['env_id'], script_id, script_version), JSON.generate(script_execution_object))
|
58
|
+
return item
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
# ScalrApiV2::Servers
|
2
|
+
module ScalrApiV2
|
3
|
+
require 'json'
|
4
|
+
|
5
|
+
# connection and request methods for interacting with the Scalr API
|
6
|
+
class Servers
|
7
|
+
def initialize
|
8
|
+
@config = ScalrApiV2::Config.new.config
|
9
|
+
@scalr = ScalrApiV2::Request.new
|
10
|
+
end
|
11
|
+
|
12
|
+
# List all scripts
|
13
|
+
def list
|
14
|
+
list = @scalr.list(format('/api/v1beta0/user/%s/servers/', @config['env_id']))
|
15
|
+
return list
|
16
|
+
end
|
17
|
+
|
18
|
+
# TODO: add remaining api calls
|
19
|
+
end
|
20
|
+
end
|
data/lib/scalr_api_v2.rb
ADDED
@@ -0,0 +1,44 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
|
3
|
+
lib = File.expand_path('../lib', __FILE__)
|
4
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
5
|
+
require 'scalr_api_v2/version'
|
6
|
+
|
7
|
+
Gem::Specification.new do |spec|
|
8
|
+
spec.name = 'scalr_api_v2'
|
9
|
+
spec.version = ScalrApiV2::VERSION
|
10
|
+
spec.authors = ['david.meekin']
|
11
|
+
spec.email = ['davemeekin.github@gmail.com']
|
12
|
+
|
13
|
+
spec.summary = 'ruby gem providing interface to Scalr API v2 methods'
|
14
|
+
spec.description = 'provides a connection to scalr and a non exhuastive list of api calls as methods.'
|
15
|
+
spec.homepage = 'https://github.com/autotraderuk'
|
16
|
+
spec.license = 'MIT'
|
17
|
+
|
18
|
+
# Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
|
19
|
+
# to allow pushing to a single host or delete this section to allow pushing to any host.
|
20
|
+
# if spec.respond_to?(:metadata)
|
21
|
+
# spec.metadata['allowed_push_host'] = 'http://mygemserver.com'
|
22
|
+
# else
|
23
|
+
# raise 'RubyGems 2.0 or newer is required to protect against public gem pushes.'
|
24
|
+
# end
|
25
|
+
|
26
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
27
|
+
spec.bindir = 'exe'
|
28
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
29
|
+
spec.require_paths = ['lib']
|
30
|
+
|
31
|
+
spec.add_development_dependency 'bundler', '~> 1.12'
|
32
|
+
spec.add_development_dependency 'rake', '~> 10.0'
|
33
|
+
spec.add_development_dependency 'rspec', '~> 3.0'
|
34
|
+
spec.add_development_dependency 'climate_control'
|
35
|
+
spec.add_development_dependency 'rack', '~> 1.6.8'
|
36
|
+
spec.add_development_dependency 'webmock', '~> 3.0.1'
|
37
|
+
spec.add_development_dependency 'sinatra', '~>1.4.8'
|
38
|
+
spec.add_development_dependency 'cucumber', '~> 2.4.0'
|
39
|
+
spec.add_development_dependency 'aruba', '~>0.14.2'
|
40
|
+
spec.add_development_dependency 'rubocop', '~>0.48.1'
|
41
|
+
spec.add_dependency 'rest-client', '~>2.0.2'
|
42
|
+
spec.add_dependency 'json', '~> 2.1.0'
|
43
|
+
spec.add_dependency 'thor', '~> 0.19.4'
|
44
|
+
end
|
metadata
ADDED
@@ -0,0 +1,249 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: scalr_api_v2
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- david.meekin
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2017-05-18 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.12'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ~>
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.12'
|
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: '3.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ~>
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '3.0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: climate_control
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
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: rack
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ~>
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: 1.6.8
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ~>
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: 1.6.8
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: webmock
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ~>
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: 3.0.1
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ~>
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: 3.0.1
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: sinatra
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - ~>
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: 1.4.8
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - ~>
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: 1.4.8
|
111
|
+
- !ruby/object:Gem::Dependency
|
112
|
+
name: cucumber
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - ~>
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: 2.4.0
|
118
|
+
type: :development
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - ~>
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: 2.4.0
|
125
|
+
- !ruby/object:Gem::Dependency
|
126
|
+
name: aruba
|
127
|
+
requirement: !ruby/object:Gem::Requirement
|
128
|
+
requirements:
|
129
|
+
- - ~>
|
130
|
+
- !ruby/object:Gem::Version
|
131
|
+
version: 0.14.2
|
132
|
+
type: :development
|
133
|
+
prerelease: false
|
134
|
+
version_requirements: !ruby/object:Gem::Requirement
|
135
|
+
requirements:
|
136
|
+
- - ~>
|
137
|
+
- !ruby/object:Gem::Version
|
138
|
+
version: 0.14.2
|
139
|
+
- !ruby/object:Gem::Dependency
|
140
|
+
name: rubocop
|
141
|
+
requirement: !ruby/object:Gem::Requirement
|
142
|
+
requirements:
|
143
|
+
- - ~>
|
144
|
+
- !ruby/object:Gem::Version
|
145
|
+
version: 0.48.1
|
146
|
+
type: :development
|
147
|
+
prerelease: false
|
148
|
+
version_requirements: !ruby/object:Gem::Requirement
|
149
|
+
requirements:
|
150
|
+
- - ~>
|
151
|
+
- !ruby/object:Gem::Version
|
152
|
+
version: 0.48.1
|
153
|
+
- !ruby/object:Gem::Dependency
|
154
|
+
name: rest-client
|
155
|
+
requirement: !ruby/object:Gem::Requirement
|
156
|
+
requirements:
|
157
|
+
- - ~>
|
158
|
+
- !ruby/object:Gem::Version
|
159
|
+
version: 2.0.2
|
160
|
+
type: :runtime
|
161
|
+
prerelease: false
|
162
|
+
version_requirements: !ruby/object:Gem::Requirement
|
163
|
+
requirements:
|
164
|
+
- - ~>
|
165
|
+
- !ruby/object:Gem::Version
|
166
|
+
version: 2.0.2
|
167
|
+
- !ruby/object:Gem::Dependency
|
168
|
+
name: json
|
169
|
+
requirement: !ruby/object:Gem::Requirement
|
170
|
+
requirements:
|
171
|
+
- - ~>
|
172
|
+
- !ruby/object:Gem::Version
|
173
|
+
version: 2.1.0
|
174
|
+
type: :runtime
|
175
|
+
prerelease: false
|
176
|
+
version_requirements: !ruby/object:Gem::Requirement
|
177
|
+
requirements:
|
178
|
+
- - ~>
|
179
|
+
- !ruby/object:Gem::Version
|
180
|
+
version: 2.1.0
|
181
|
+
- !ruby/object:Gem::Dependency
|
182
|
+
name: thor
|
183
|
+
requirement: !ruby/object:Gem::Requirement
|
184
|
+
requirements:
|
185
|
+
- - ~>
|
186
|
+
- !ruby/object:Gem::Version
|
187
|
+
version: 0.19.4
|
188
|
+
type: :runtime
|
189
|
+
prerelease: false
|
190
|
+
version_requirements: !ruby/object:Gem::Requirement
|
191
|
+
requirements:
|
192
|
+
- - ~>
|
193
|
+
- !ruby/object:Gem::Version
|
194
|
+
version: 0.19.4
|
195
|
+
description: provides a connection to scalr and a non exhuastive list of api calls
|
196
|
+
as methods.
|
197
|
+
email:
|
198
|
+
- davemeekin.github@gmail.com
|
199
|
+
executables:
|
200
|
+
- scalr_api_v2
|
201
|
+
extensions: []
|
202
|
+
extra_rdoc_files: []
|
203
|
+
files:
|
204
|
+
- .gitignore
|
205
|
+
- .rspec
|
206
|
+
- .rubocop.yml
|
207
|
+
- .travis.yml
|
208
|
+
- CODE_OF_CONDUCT.md
|
209
|
+
- Gemfile
|
210
|
+
- LICENSE.txt
|
211
|
+
- README.md
|
212
|
+
- Rakefile
|
213
|
+
- bin/console
|
214
|
+
- bin/setup
|
215
|
+
- exe/scalr_api_v2
|
216
|
+
- lib/scalr_api_v2.rb
|
217
|
+
- lib/scalr_api_v2/cli.rb
|
218
|
+
- lib/scalr_api_v2/config.rb
|
219
|
+
- lib/scalr_api_v2/farms.rb
|
220
|
+
- lib/scalr_api_v2/request.rb
|
221
|
+
- lib/scalr_api_v2/scripts.rb
|
222
|
+
- lib/scalr_api_v2/servers.rb
|
223
|
+
- lib/scalr_api_v2/version.rb
|
224
|
+
- scalr_api_v2.gemspec
|
225
|
+
homepage: https://github.com/autotraderuk
|
226
|
+
licenses:
|
227
|
+
- MIT
|
228
|
+
metadata: {}
|
229
|
+
post_install_message:
|
230
|
+
rdoc_options: []
|
231
|
+
require_paths:
|
232
|
+
- lib
|
233
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
234
|
+
requirements:
|
235
|
+
- - '>='
|
236
|
+
- !ruby/object:Gem::Version
|
237
|
+
version: '0'
|
238
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
239
|
+
requirements:
|
240
|
+
- - '>='
|
241
|
+
- !ruby/object:Gem::Version
|
242
|
+
version: '0'
|
243
|
+
requirements: []
|
244
|
+
rubyforge_project:
|
245
|
+
rubygems_version: 2.6.12
|
246
|
+
signing_key:
|
247
|
+
specification_version: 4
|
248
|
+
summary: ruby gem providing interface to Scalr API v2 methods
|
249
|
+
test_files: []
|