vultrlife 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +3 -0
- data/.rspec +2 -0
- data/.ruby-version +1 -0
- data/.travis.yml +6 -0
- data/Gemfile +3 -0
- data/Gemfile.lock +43 -0
- data/LICENSE +20 -0
- data/README.md +121 -0
- data/Rakefile +6 -0
- data/lib/vultrlife/account.rb +23 -0
- data/lib/vultrlife/agent.rb +105 -0
- data/lib/vultrlife/plan_verifier.rb +4 -0
- data/lib/vultrlife/server/configuration.rb +15 -0
- data/lib/vultrlife/server.rb +72 -0
- data/lib/vultrlife/version.rb +3 -0
- data/lib/vultrlife.rb +8 -0
- data/spec/fixtures/v1_availability_of_tokyo.json +1 -0
- data/spec/fixtures/v1_os.json +1 -0
- data/spec/fixtures/v1_plans.json +1 -0
- data/spec/fixtures/v1_regions.json +1 -0
- data/spec/fixtures/v1_server_list.json +1 -0
- data/spec/spec_helper.rb +5 -0
- data/spec/vultrlife/account_spec.rb +60 -0
- data/spec/vultrlife/agent_spec.rb +170 -0
- data/spec/vultrlife/server/configuration_spec.rb +92 -0
- data/spec/vultrlife/server_spec.rb +139 -0
- data/spec/vultrlife_spec.rb +7 -0
- data/vultrlife.gemspec +28 -0
- metadata +153 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: a9836c0639934c0c3ba8c8f3d7868448f9407c3d
|
4
|
+
data.tar.gz: 39a9e88d238d3c792bf4f54885f947e775c76aa5
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 0763d20b670f0fe219ddffd785c65cbeb20b7e9e826f54e2744cf500457d5e57c05ddfe5e7234571c240c713d33beb399142ff5ed23c4b53a37361d3d6b122c2
|
7
|
+
data.tar.gz: 0a3acbffedf9558a8578c4259275b970e1f72726d2732872085482fa8632b3b6786e2fbebfb210d60da4109a47e39a3df4a3af9dd886da7b1ced43239cd619ed
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.ruby-version
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
2.1.2
|
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,43 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
vultrlife (0.0.2)
|
5
|
+
|
6
|
+
GEM
|
7
|
+
remote: https://rubygems.org/
|
8
|
+
specs:
|
9
|
+
addressable (2.3.6)
|
10
|
+
coderay (1.1.0)
|
11
|
+
crack (0.4.2)
|
12
|
+
safe_yaml (~> 1.0.0)
|
13
|
+
diff-lcs (1.2.5)
|
14
|
+
method_source (0.8.2)
|
15
|
+
pry (0.9.12.6)
|
16
|
+
coderay (~> 1.0)
|
17
|
+
method_source (~> 0.8)
|
18
|
+
slop (~> 3.4)
|
19
|
+
rake (10.1.0)
|
20
|
+
rspec (2.14.1)
|
21
|
+
rspec-core (~> 2.14.0)
|
22
|
+
rspec-expectations (~> 2.14.0)
|
23
|
+
rspec-mocks (~> 2.14.0)
|
24
|
+
rspec-core (2.14.8)
|
25
|
+
rspec-expectations (2.14.5)
|
26
|
+
diff-lcs (>= 1.1.3, < 2.0)
|
27
|
+
rspec-mocks (2.14.6)
|
28
|
+
safe_yaml (1.0.3)
|
29
|
+
slop (3.5.0)
|
30
|
+
webmock (1.18.0)
|
31
|
+
addressable (>= 2.3.6)
|
32
|
+
crack (>= 0.3.2)
|
33
|
+
|
34
|
+
PLATFORMS
|
35
|
+
ruby
|
36
|
+
|
37
|
+
DEPENDENCIES
|
38
|
+
bundler (~> 1.5)
|
39
|
+
pry
|
40
|
+
rake
|
41
|
+
rspec
|
42
|
+
vultrlife!
|
43
|
+
webmock
|
data/LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2014 Tsuyoshi Hoshino
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
6
|
+
this software and associated documentation files (the "Software"), to deal in
|
7
|
+
the Software without restriction, including without limitation the rights to
|
8
|
+
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
9
|
+
the Software, and to permit persons to whom the Software is furnished to do so,
|
10
|
+
subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
13
|
+
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, FITNESS
|
17
|
+
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
18
|
+
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
19
|
+
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
20
|
+
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,121 @@
|
|
1
|
+
# Vultrlife
|
2
|
+
|
3
|
+
Vultr VPS API wrapper
|
4
|
+
|
5
|
+
![travis-batch](https://travis-ci.org/hoshinotsuyoshi/vultrlife.svg?branch=master)
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
Add this line to your application's Gemfile:
|
10
|
+
|
11
|
+
gem 'vultrlife'
|
12
|
+
|
13
|
+
And then execute:
|
14
|
+
|
15
|
+
$ bundle
|
16
|
+
|
17
|
+
Or install it yourself as:
|
18
|
+
|
19
|
+
$ gem install vultrlife
|
20
|
+
|
21
|
+
## Usage
|
22
|
+
|
23
|
+
### Create/Destroy Server
|
24
|
+
|
25
|
+
```
|
26
|
+
require 'vultrlife'
|
27
|
+
|
28
|
+
# Create Your Account Object
|
29
|
+
account = Vultrlife::Account.new do |account|
|
30
|
+
account.api_key = 'xxxxxxxxxxxxxxxxxxx'
|
31
|
+
end
|
32
|
+
|
33
|
+
# Check Your Servers
|
34
|
+
puts account.servers
|
35
|
+
# => [] (if you have no servers)
|
36
|
+
|
37
|
+
# Create A Server(CentOS)
|
38
|
+
account.server_create! do |server|
|
39
|
+
server.plan = '768 MB RAM,15 GB SSD,0.10 TB BW'
|
40
|
+
server.region = :tokyo
|
41
|
+
server.os = 'CentOS 6 x64'
|
42
|
+
end
|
43
|
+
|
44
|
+
# Check The Server
|
45
|
+
puts account.servers.last
|
46
|
+
# => {"os"=>"CentOS 6 x64",
|
47
|
+
# "ram"=>"768 MB",
|
48
|
+
# "disk"=>"Virtual 15 GB",
|
49
|
+
# "main_ip"=>"108.61.200.210",
|
50
|
+
# "default_password"=>"eqsaqenynelu!2",
|
51
|
+
# ...and more....
|
52
|
+
|
53
|
+
# Create A Server(CustomOS)
|
54
|
+
account.server_create! do |server|
|
55
|
+
server.plan = '768 MB RAM,15 GB SSD,0.10 TB BW, Custom ISO'
|
56
|
+
server.region = :tokyo
|
57
|
+
server.os = 'Custom'
|
58
|
+
server.ipxe_chain_url = 'http://......' #(optional)
|
59
|
+
end
|
60
|
+
|
61
|
+
# Check Your Servers
|
62
|
+
puts account.servers
|
63
|
+
|
64
|
+
# Destroy A Server
|
65
|
+
account.servers.first.destroy!
|
66
|
+
```
|
67
|
+
|
68
|
+
### List Plans/OSs/Regions/Plans_Regions_Availavility
|
69
|
+
|
70
|
+
```
|
71
|
+
require 'vultrlife'
|
72
|
+
|
73
|
+
Vultrlife::Agent.plans_list
|
74
|
+
#Same as API: GET /v1/plans/list
|
75
|
+
|
76
|
+
Vultrlife::Agent.regions_list
|
77
|
+
#Same as API: GET /v1/regions/list
|
78
|
+
|
79
|
+
Vultrlife::Agent.os_list
|
80
|
+
#Same as API: GET /v1/os/list
|
81
|
+
|
82
|
+
Vultrlife::Agent.regions_availability(dcid)
|
83
|
+
#Same as API: GET /v1/regions/availability
|
84
|
+
|
85
|
+
```
|
86
|
+
|
87
|
+
## Support API
|
88
|
+
```
|
89
|
+
#GET /v1/plans/list
|
90
|
+
Vultrlife::Agent.plans_list
|
91
|
+
|
92
|
+
#GET /v1/regions/list
|
93
|
+
Vultrlife::Agent.regions_list
|
94
|
+
|
95
|
+
#GET /v1/os/list
|
96
|
+
Vultrlife::Agent.os_list
|
97
|
+
|
98
|
+
#GET /v1/regions/availability
|
99
|
+
Vultrlife::Agent.regions_availability(dcid)
|
100
|
+
|
101
|
+
#GET /v1/server/list (needs api_key)
|
102
|
+
Vultrlife::Agent.server_list(api_key)
|
103
|
+
|
104
|
+
#POST /v1/server/create (needs api_key)
|
105
|
+
Vultrlife::Agent.server_create(body)
|
106
|
+
|
107
|
+
#POST /v1/server/destroy (needs api_key)
|
108
|
+
Vultrlife::Agent.server_destroy(body)
|
109
|
+
|
110
|
+
```
|
111
|
+
|
112
|
+
## Requirement
|
113
|
+
* MRI(>=1.9.3)
|
114
|
+
|
115
|
+
## Contributing
|
116
|
+
|
117
|
+
1. Fork it ( http://github.com/<my-github-username>/vultrlife/fork )
|
118
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
119
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
120
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
121
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
module Vultrlife
|
2
|
+
class Account
|
3
|
+
attr_reader :config
|
4
|
+
attr_accessor :api_key
|
5
|
+
def initialize(&b)
|
6
|
+
@api_key = ''
|
7
|
+
if block_given?
|
8
|
+
yield self
|
9
|
+
end
|
10
|
+
self
|
11
|
+
end
|
12
|
+
|
13
|
+
def servers
|
14
|
+
Server.show_servers(self)
|
15
|
+
end
|
16
|
+
|
17
|
+
def server_create!(&b)
|
18
|
+
config = Server::Configuration.new(self)
|
19
|
+
yield config
|
20
|
+
Server.create!(config)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,105 @@
|
|
1
|
+
require 'json'
|
2
|
+
require 'net/https'
|
3
|
+
|
4
|
+
module Vultrlife
|
5
|
+
module Agent
|
6
|
+
API_HOST = 'https://api.vultr.com'
|
7
|
+
|
8
|
+
# GET
|
9
|
+
|
10
|
+
def self.http_get(endpoint, params={})
|
11
|
+
response = ''
|
12
|
+
|
13
|
+
uri = URI.parse("#{API_HOST}#{endpoint}")
|
14
|
+
https = Net::HTTP.new(uri.host, 443)
|
15
|
+
https.use_ssl = true
|
16
|
+
https.start{|https|
|
17
|
+
response = https.get(uri.path + '?'+ query(params))
|
18
|
+
}
|
19
|
+
|
20
|
+
if response.body.to_s.empty?
|
21
|
+
''
|
22
|
+
else
|
23
|
+
JSON.parse(response.body)
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
def self.plans_list
|
28
|
+
#/v1/plans/list
|
29
|
+
#GET - public
|
30
|
+
|
31
|
+
self.http_get('/v1/plans/list')
|
32
|
+
end
|
33
|
+
|
34
|
+
def self.regions_list
|
35
|
+
#/v1/regions/list
|
36
|
+
#GET - public
|
37
|
+
|
38
|
+
self.http_get('/v1/regions/list')
|
39
|
+
end
|
40
|
+
|
41
|
+
def self.os_list
|
42
|
+
#/v1/os/list
|
43
|
+
#GET - public
|
44
|
+
|
45
|
+
self.http_get('/v1/os/list')
|
46
|
+
end
|
47
|
+
|
48
|
+
def self.regions_availability(dcid)
|
49
|
+
#/v1/regions/availability
|
50
|
+
#GET - public
|
51
|
+
|
52
|
+
self.http_get('/v1/regions/availability', DCID: dcid)
|
53
|
+
.map(&:to_s)
|
54
|
+
end
|
55
|
+
|
56
|
+
def self.server_list(api_key)
|
57
|
+
#/v1/server/list
|
58
|
+
#GET - account
|
59
|
+
|
60
|
+
self.http_get('/v1/server/list', api_key: api_key)
|
61
|
+
end
|
62
|
+
|
63
|
+
# POST
|
64
|
+
|
65
|
+
def self.http_post(endpoint, body)
|
66
|
+
response = ''
|
67
|
+
|
68
|
+
api_key = body.delete(:api_key)
|
69
|
+
|
70
|
+
uri = URI.parse("#{API_HOST}#{endpoint}")
|
71
|
+
https = Net::HTTP.new(uri.host, 443)
|
72
|
+
https.use_ssl = true
|
73
|
+
https.start{|https|
|
74
|
+
response = https.post("#{uri.path}?api_key=#{api_key}",query(body))
|
75
|
+
}
|
76
|
+
|
77
|
+
if response.body.to_s.empty?
|
78
|
+
''
|
79
|
+
else
|
80
|
+
JSON.parse(response.body)
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
def self.server_create(body)
|
85
|
+
#/v1/server/create
|
86
|
+
#POST - account
|
87
|
+
|
88
|
+
self.http_post('/v1/server/create', body)
|
89
|
+
end
|
90
|
+
|
91
|
+
def self.server_destroy(body)
|
92
|
+
#/v1/server/destroy
|
93
|
+
#POST - account
|
94
|
+
|
95
|
+
self.http_post('/v1/server/destroy', body)
|
96
|
+
end
|
97
|
+
|
98
|
+
# helper
|
99
|
+
|
100
|
+
def self.query(option)
|
101
|
+
return '' if option.empty?
|
102
|
+
option.map{|e| e.join '='}.join('&')
|
103
|
+
end
|
104
|
+
end
|
105
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
module Vultrlife
|
2
|
+
class Server < Hash
|
3
|
+
class Configuration
|
4
|
+
attr_accessor :region, :plan, :os, :ipxe_chain_url, :api_key
|
5
|
+
|
6
|
+
def initialize(account)
|
7
|
+
@api_key = account.api_key
|
8
|
+
end
|
9
|
+
|
10
|
+
def verify_plan(&b)
|
11
|
+
yield Vultrlife::PlanVerifier.new
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,72 @@
|
|
1
|
+
require 'vultrlife/server/configuration'
|
2
|
+
module Vultrlife
|
3
|
+
class Server < Hash
|
4
|
+
attr_reader :subid
|
5
|
+
def initialize(subid, account=nil, hash=nil)
|
6
|
+
@subid = subid
|
7
|
+
@account = account
|
8
|
+
self.merge!(hash) if hash
|
9
|
+
end
|
10
|
+
|
11
|
+
def destroy!
|
12
|
+
Agent.server_destroy(SUBID: @subid, api_key: @account.api_key)
|
13
|
+
self['destroyed'] = true
|
14
|
+
@subid
|
15
|
+
end
|
16
|
+
|
17
|
+
def destroyed?
|
18
|
+
!!self['destroyed']
|
19
|
+
end
|
20
|
+
|
21
|
+
def self.create!(config)
|
22
|
+
self.validate_config(config)
|
23
|
+
self.exec_create
|
24
|
+
end
|
25
|
+
|
26
|
+
def self.show_servers(account)
|
27
|
+
servers = Agent.server_list(account.api_key)
|
28
|
+
servers = servers.map do |subid, attributes|
|
29
|
+
self.new(subid, account, attributes)
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
private
|
34
|
+
def self.exec_create
|
35
|
+
subid_hash = Agent.server_create(@option)
|
36
|
+
self.new(subid_hash['SUBID'].to_i)
|
37
|
+
end
|
38
|
+
|
39
|
+
def self.validate_config(config)
|
40
|
+
plans = Agent.plans_list
|
41
|
+
plans = plans.select{|key,value| config.plan == value['name'] }
|
42
|
+
|
43
|
+
raise if not plans.size == 1
|
44
|
+
|
45
|
+
regions = Agent.regions_list
|
46
|
+
regions = regions.select{|key,value| config.region.to_s == value['name'].downcase }
|
47
|
+
|
48
|
+
raise if not regions.keys.size == 1
|
49
|
+
|
50
|
+
oss = Agent.os_list
|
51
|
+
oss = oss.select{|key,value| config.os == value['name'] }
|
52
|
+
|
53
|
+
raise if not oss.keys.size == 1
|
54
|
+
|
55
|
+
dcid = regions.keys.first
|
56
|
+
available_plans = Agent.regions_availability(dcid).map(&:to_i)
|
57
|
+
|
58
|
+
raise if not available_plans.include?(plans.keys.first.to_i)
|
59
|
+
|
60
|
+
@option = {
|
61
|
+
VPSPLANID: plans.keys.first.to_i,
|
62
|
+
DCID: dcid.to_i,
|
63
|
+
OSID: oss.keys.first.to_i,
|
64
|
+
api_key: config.api_key,
|
65
|
+
}
|
66
|
+
|
67
|
+
if config.ipxe_chain_url
|
68
|
+
@option[:ipxe_chain_url] = config.ipxe_chain_url
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
data/lib/vultrlife.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
[31,52,47,32,53,48,51,8,54,33,49,50,34,55]
|
@@ -0,0 +1 @@
|
|
1
|
+
{"127":{"name":"CentOS 6 x64","arch":"x64","family":"centos","windows":false},"147":{"name":"CentOS 6 i386","arch":"i386","family":"centos","windows":false},"162":{"name":"CentOS 5 x64","arch":"x64","family":"centos","windows":false},"163":{"name":"CentOS 5 i386","arch":"i386","family":"centos","windows":false},"160":{"name":"Ubuntu 14.04 x64","arch":"x64","family":"ubuntu","windows":false},"161":{"name":"Ubuntu 14.04 i386","arch":"i386","family":"ubuntu","windows":false},"131":{"name":"Ubuntu 13.10 x64","arch":"x64","family":"ubuntu","windows":false},"150":{"name":"Ubuntu 13.10 i386","arch":"i386","family":"ubuntu","windows":false},"129":{"name":"Ubuntu 12.10 x64","arch":"x64","family":"ubuntu","windows":false},"149":{"name":"Ubuntu 12.10 i386","arch":"i386","family":"ubuntu","windows":false},"128":{"name":"Ubuntu 12.04 x64","arch":"x64","family":"ubuntu","windows":false},"148":{"name":"Ubuntu 12.04 i386","arch":"i386","family":"ubuntu","windows":false},"138":{"name":"Debian 6 x64 (squeeze)","arch":"x64","family":"debian","windows":false},"151":{"name":"Debian 6 i386 (squeeze)","arch":"i386","family":"debian","windows":false},"139":{"name":"Debian 7 x64 (wheezy)","arch":"x64","family":"debian","windows":false},"152":{"name":"Debian 7 i386 (wheezy)","arch":"i386","family":"debian","windows":false},"140":{"name":"FreeBSD 10 x64","arch":"x64","family":"freebsd","windows":false},"124":{"name":"Windows 2012 R2 x64","arch":"x64","family":"windows","windows":true},"159":{"name":"Custom","arch":"x64","family":"iso","windows":false},"164":{"name":"Snapshot","arch":"x64","family":"snapshot","windows":false}}
|
@@ -0,0 +1 @@
|
|
1
|
+
{"40":{"name":"512 MB RAM,160 GB SATA,1.00 TB BW, Custom ISO","vcpu_count":"1","ram":"512","disk":"160","bandwidth":"1.00","price_per_month":"5.00","windows":false},"11":{"name":"512 MB RAM,160 GB SATA,1.00 TB BW","vcpu_count":"1","ram":"512","disk":"160","bandwidth":"1.00","price_per_month":"5.00","windows":false},"45":{"name":"768 MB RAM,15 GB SSD,1.00 TB BW, Custom ISO","vcpu_count":"1","ram":"768","disk":"15","bandwidth":"1.00","price_per_month":"5.00","windows":false},"31":{"name":"768 MB RAM,15 GB SSD,0.10 TB BW","vcpu_count":"1","ram":"768","disk":"15","bandwidth":"0.10","price_per_month":"5.00","windows":false},"29":{"name":"768 MB RAM,15 GB SSD,1.00 TB BW","vcpu_count":"1","ram":"768","disk":"15","bandwidth":"1.00","price_per_month":"5.00","windows":false},"52":{"name":"768 MB RAM,15 GB SSD,0.10 TB BW, Custom ISO","vcpu_count":"1","ram":"768","disk":"15","bandwidth":"0.10","price_per_month":"5.00","windows":false},"41":{"name":"1024 MB RAM,320 GB SATA,2.00 TB BW, Custom ISO","vcpu_count":"1","ram":"1024","disk":"320","bandwidth":"2.00","price_per_month":"8.00","windows":false},"61":{"name":"1024 MB RAM,320 GB SATA,2.00 TB BW","vcpu_count":"1","ram":"1024","disk":"320","bandwidth":"2.00","price_per_month":"23.00","windows":true},"46":{"name":"1024 MB RAM,20 GB SSD,2.00 TB BW, Custom ISO","vcpu_count":"1","ram":"1024","disk":"20","bandwidth":"2.00","price_per_month":"7.00","windows":false},"35":{"name":"1024 MB RAM,20 GB SSD,1.00 TB BW","vcpu_count":"1","ram":"1024","disk":"20","bandwidth":"1.00","price_per_month":"23.00","windows":true},"47":{"name":"1024 MB RAM,20 GB SSD,0.10 TB BW","vcpu_count":"1","ram":"1024","disk":"20","bandwidth":"0.10","price_per_month":"23.00","windows":true},"32":{"name":"1024 MB RAM,20 GB SSD,0.20 TB BW","vcpu_count":"1","ram":"1024","disk":"20","bandwidth":"0.20","price_per_month":"7.00","windows":false},"12":{"name":"1024 MB RAM,320 GB SATA,2.00 TB BW","vcpu_count":"1","ram":"1024","disk":"320","bandwidth":"2.00","price_per_month":"8.00","windows":false},"30":{"name":"1024 MB RAM,20 GB SSD,2.00 TB BW","vcpu_count":"1","ram":"1024","disk":"20","bandwidth":"2.00","price_per_month":"7.00","windows":false},"53":{"name":"1024 MB RAM,20 GB SSD,0.20 TB BW, Custom ISO","vcpu_count":"1","ram":"1024","disk":"20","bandwidth":"0.20","price_per_month":"7.00","windows":false},"48":{"name":"2048 MB RAM,40 GB SSD,0.20 TB BW","vcpu_count":"1","ram":"2048","disk":"40","bandwidth":"0.20","price_per_month":"39.00","windows":true},"42":{"name":"2048 MB RAM,640 GB SATA,3.00 TB BW, Custom ISO","vcpu_count":"1","ram":"2048","disk":"640","bandwidth":"3.00","price_per_month":"15.00","windows":false},"51":{"name":"2048 MB RAM,40 GB SSD,0.30 TB BW, Custom ISO","vcpu_count":"2","ram":"2048","disk":"40","bandwidth":"0.30","price_per_month":"15.00","windows":false},"3":{"name":"2048 MB RAM,40 GB SSD,3.00 TB BW","vcpu_count":"2","ram":"2048","disk":"40","bandwidth":"3.00","price_per_month":"15.00","windows":false},"39":{"name":"2048 MB RAM,40 GB SSD,3.00 TB BW, Custom ISO","vcpu_count":"2","ram":"2048","disk":"40","bandwidth":"3.00","price_per_month":"15.00","windows":false},"8":{"name":"2048 MB RAM,40 GB SSD,0.30 TB BW","vcpu_count":"2","ram":"2048","disk":"40","bandwidth":"0.30","price_per_month":"15.00","windows":false},"13":{"name":"2048 MB RAM,640 GB SATA,3.00 TB BW","vcpu_count":"1","ram":"2048","disk":"640","bandwidth":"3.00","price_per_month":"15.00","windows":false},"60":{"name":"2048 MB RAM,640 GB SATA,3.00 TB BW","vcpu_count":"1","ram":"2048","disk":"640","bandwidth":"3.00","price_per_month":"39.00","windows":true},"36":{"name":"2048 MB RAM,40 GB SSD,2.00 TB BW","vcpu_count":"1","ram":"2048","disk":"40","bandwidth":"2.00","price_per_month":"39.00","windows":true},"37":{"name":"4096 MB RAM,60 GB SSD,4.00 TB BW","vcpu_count":"2","ram":"4096","disk":"60","bandwidth":"4.00","price_per_month":"49.00","windows":true},"54":{"name":"4096 MB RAM,65 GB SSD,0.40 TB BW, Custom ISO","vcpu_count":"2","ram":"4096","disk":"65","bandwidth":"0.40","price_per_month":"35.00","windows":false},"43":{"name":"4096 MB RAM,65 GB SSD,4.00 TB BW, Custom ISO","vcpu_count":"2","ram":"4096","disk":"65","bandwidth":"4.00","price_per_month":"35.00","windows":false},"27":{"name":"4096 MB RAM,65 GB SSD,4.00 TB BW","vcpu_count":"2","ram":"4096","disk":"65","bandwidth":"4.00","price_per_month":"35.00","windows":false},"33":{"name":"4096 MB RAM,65 GB SSD,0.40 TB BW","vcpu_count":"2","ram":"4096","disk":"65","bandwidth":"0.40","price_per_month":"35.00","windows":false},"49":{"name":"4096 MB RAM,60 GB SSD,0.30 TB BW","vcpu_count":"2","ram":"4096","disk":"60","bandwidth":"0.30","price_per_month":"49.00","windows":true},"50":{"name":"8192 MB RAM,120 GB SSD,0.40 TB BW","vcpu_count":"4","ram":"8192","disk":"120","bandwidth":"0.40","price_per_month":"90.00","windows":true},"28":{"name":"8192 MB RAM,120 GB SSD,5.00 TB BW","vcpu_count":"4","ram":"8192","disk":"120","bandwidth":"5.00","price_per_month":"70.00","windows":false},"44":{"name":"8192 MB RAM,120 GB SSD,5.00 TB BW, Custom ISO","vcpu_count":"4","ram":"8192","disk":"120","bandwidth":"5.00","price_per_month":"70.00","windows":false},"34":{"name":"8192 MB RAM,120 GB SSD,0.50 TB BW","vcpu_count":"4","ram":"8192","disk":"120","bandwidth":"0.50","price_per_month":"70.00","windows":false},"55":{"name":"8192 MB RAM,120 GB SSD,0.50 TB BW, Custom ISO","vcpu_count":"4","ram":"8192","disk":"120","bandwidth":"0.50","price_per_month":"70.00","windows":false},"38":{"name":"8192 MB RAM,120 GB SSD,5.00 TB BW","vcpu_count":"4","ram":"8192","disk":"120","bandwidth":"5.00","price_per_month":"90.00","windows":true}}
|
@@ -0,0 +1 @@
|
|
1
|
+
{"19":{"name":"Australia","country":"AU","continent":"Australia","state":""},"9":{"name":"Frankfurt","country":"DE","continent":"Europe","state":""},"24":{"name":"France","country":"FR","continent":"Europe","state":""},"8":{"name":"London","country":"GB","continent":"Europe","state":""},"25":{"name":"Tokyo","country":"JP","continent":"Asia","state":""},"7":{"name":"Amsterdam","country":"NL","continent":"Europe","state":""},"6":{"name":"Atlanta","country":"US","continent":"North America","state":"GA"},"2":{"name":"Chicago","country":"US","continent":"North America","state":"IL"},"3":{"name":"Dallas","country":"US","continent":"North America","state":"TX"},"5":{"name":"Los Angeles","country":"US","continent":"North America","state":"CA"},"1":{"name":"New Jersey","country":"US","continent":"North America","state":"NJ"},"4":{"name":"Seattle","country":"US","continent":"North America","state":"WA"}}
|
@@ -0,0 +1 @@
|
|
1
|
+
{"1356876":{"os":"CentOS 6 x64","ram":"768 MB","disk":"Virtual 15 GB","main_ip":"108.61.223.121","vcpu_count":"1","location":"Tokyo","default_password":"moskety!7j","date_created":"2014-05-25 07:28:35","pending_charges":"0.01","status":"active","cost_per_month":"5.00","current_bandwidth_gb":0,"netmask_v4":"255.255.255.0","gateway_v4":"108.61.223.1","power_status":"running"}}
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,60 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Vultrlife::Account do
|
4
|
+
let(:account){ Vultrlife::Account.new }
|
5
|
+
|
6
|
+
describe '#servers' do
|
7
|
+
it 'calls Vultrlife::Server.show_servers' do
|
8
|
+
expect(Vultrlife::Server).to receive(:show_servers).with(account)
|
9
|
+
|
10
|
+
account.servers
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
describe '#server_create!' do
|
15
|
+
context 'given no block' do
|
16
|
+
it 'raises error' do
|
17
|
+
expect{ account.server_create! }.to raise_error
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
def server_create!(&b)
|
22
|
+
config = Server::Configuration.new(self)
|
23
|
+
yield config
|
24
|
+
Server.create!(config)
|
25
|
+
end
|
26
|
+
|
27
|
+
context 'given a block' do
|
28
|
+
it 'yields Vultrlife::Server::Configuration' do
|
29
|
+
config = double(:config)
|
30
|
+
expect(Vultrlife::Server::Configuration).to receive(:new).with(account).and_return(config)
|
31
|
+
expect(config).to receive(:setting_a=).with('setting_a')
|
32
|
+
expect(config).to receive(:setting_b=).with('setting_b')
|
33
|
+
config.stub(:plan)
|
34
|
+
expect(Vultrlife::Server).to receive(:create!).with(config)
|
35
|
+
|
36
|
+
server = account.server_create! do |server|
|
37
|
+
server.setting_a = 'setting_a'
|
38
|
+
server.setting_b = 'setting_b'
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
it 'returns a new Vultrlife::Server' do
|
43
|
+
pending('this spec must be feature test')
|
44
|
+
config = double(:config)
|
45
|
+
expect(Vultrlife::Server::Configuration).to receive(:new).with(account).and_return(config)
|
46
|
+
expect(config).to receive(:setting_a=).with('setting_a')
|
47
|
+
expect(config).to receive(:setting_b=).with('setting_b')
|
48
|
+
config.stub(:plan)
|
49
|
+
expect(Vultrlife::Server).to receive(:create!).with(config)
|
50
|
+
|
51
|
+
server = account.server_create! do |server|
|
52
|
+
server.setting_a = 'setting_a'
|
53
|
+
server.setting_b = 'setting_b'
|
54
|
+
end
|
55
|
+
|
56
|
+
server.should be_a(Vultrlife::Server)
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
@@ -0,0 +1,170 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Vultrlife::Agent do
|
4
|
+
describe '.plans_list' do
|
5
|
+
context 'when API responds normally' do
|
6
|
+
let(:v1_plans) do
|
7
|
+
File.read('spec/fixtures/v1_plans.json')
|
8
|
+
end
|
9
|
+
|
10
|
+
it 'returns plans(Hash)' do
|
11
|
+
WebMock.stub_request(:get, 'https://api.vultr.com/v1/plans/list')
|
12
|
+
.to_return(:body => v1_plans)
|
13
|
+
|
14
|
+
response = Vultrlife::Agent.plans_list
|
15
|
+
expect(response.keys.sort).to eq(
|
16
|
+
%w(11 12 13 27 28 29 3 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 60 61 8)
|
17
|
+
)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
describe '.regions_list' do
|
23
|
+
context 'when API responds normally' do
|
24
|
+
let(:v1_regions) do
|
25
|
+
File.read('spec/fixtures/v1_regions.json')
|
26
|
+
end
|
27
|
+
|
28
|
+
it 'returns regions(Hash)' do
|
29
|
+
WebMock.stub_request(:get, 'https://api.vultr.com/v1/regions/list')
|
30
|
+
.to_return(:body => v1_regions)
|
31
|
+
|
32
|
+
response = Vultrlife::Agent.regions_list
|
33
|
+
expect(response.keys.sort).to eq(
|
34
|
+
%w(1 19 2 24 25 3 4 5 6 7 8 9)
|
35
|
+
)
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
describe '.os_list' do
|
41
|
+
context 'when API responds normally' do
|
42
|
+
let(:v1_os) do
|
43
|
+
File.read('spec/fixtures/v1_os.json')
|
44
|
+
end
|
45
|
+
|
46
|
+
it 'returns oss(Hash)' do
|
47
|
+
WebMock.stub_request(:get, 'https://api.vultr.com/v1/os/list')
|
48
|
+
.to_return(:body => v1_os)
|
49
|
+
|
50
|
+
response = Vultrlife::Agent.os_list
|
51
|
+
expect(response.keys.sort).to eq(
|
52
|
+
%w(124 127 128 129 131 138 139 140 147 148 149 150 151 152 159 160 161 162 163 164)
|
53
|
+
)
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
describe '.regions_availability' do
|
59
|
+
context 'when API responds normally' do
|
60
|
+
let(:v1_availability_of_tokyo) do
|
61
|
+
File.read('spec/fixtures/v1_availability_of_tokyo.json')
|
62
|
+
end
|
63
|
+
|
64
|
+
it 'returns available plans(Array)' do
|
65
|
+
WebMock.stub_request(:get, 'https://api.vultr.com/v1/regions/availability?DCID=25')
|
66
|
+
.to_return(:body => v1_availability_of_tokyo)
|
67
|
+
|
68
|
+
response = Vultrlife::Agent.regions_availability('25') # 25 -> tokyo
|
69
|
+
expect(response.sort).to eq(
|
70
|
+
%w(31 32 33 34 47 48 49 50 51 52 53 54 55 8)
|
71
|
+
)
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
describe '.server_list' do
|
77
|
+
context 'when API responds normally' do
|
78
|
+
let(:v1_server_list) do
|
79
|
+
File.read('spec/fixtures/v1_server_list.json')
|
80
|
+
end
|
81
|
+
|
82
|
+
it 'returns my servers(Hash)' do
|
83
|
+
WebMock.stub_request(:get, 'https://api.vultr.com/v1/server/list?api_key=APIKEY')
|
84
|
+
.to_return(body: v1_server_list)
|
85
|
+
|
86
|
+
response = Vultrlife::Agent.server_list('APIKEY')
|
87
|
+
expect(response).to eq(
|
88
|
+
{
|
89
|
+
"1356876" => {
|
90
|
+
"os" => "CentOS 6 x64",
|
91
|
+
"ram" => "768 MB",
|
92
|
+
"disk" => "Virtual 15 GB",
|
93
|
+
"main_ip" => "108.61.223.121",
|
94
|
+
"vcpu_count" => "1",
|
95
|
+
"location" => "Tokyo",
|
96
|
+
"default_password" => "moskety!7j",
|
97
|
+
"date_created" => "2014-05-25 07:28:35",
|
98
|
+
"pending_charges" => "0.01",
|
99
|
+
"status" => "active",
|
100
|
+
"cost_per_month" => "5.00",
|
101
|
+
"current_bandwidth_gb" => 0,
|
102
|
+
"netmask_v4" => "255.255.255.0",
|
103
|
+
"gateway_v4" => "108.61.223.1",
|
104
|
+
"power_status" => "running"
|
105
|
+
}
|
106
|
+
}
|
107
|
+
)
|
108
|
+
end
|
109
|
+
end
|
110
|
+
end
|
111
|
+
|
112
|
+
describe '.server_create' do
|
113
|
+
context 'given valid option' do
|
114
|
+
context 'when API responds normally' do
|
115
|
+
it 'returns server\'s sub_id(Hash)' do
|
116
|
+
data = "DCID=25"
|
117
|
+
data << "&VPSPLANID=31"
|
118
|
+
data << "&OSID=127"
|
119
|
+
WebMock.stub_request(:post, 'https://api.vultr.com/v1/server/create?api_key=APIKEY')
|
120
|
+
.with(body: data)
|
121
|
+
.to_return(body: %q{{"SUBID" : "1312965"}})
|
122
|
+
|
123
|
+
option = {DCID: 25, VPSPLANID: 31, OSID: 127, api_key: 'APIKEY'}
|
124
|
+
response = Vultrlife::Agent.server_create(option)
|
125
|
+
expect(response).to eq(
|
126
|
+
{'SUBID' => '1312965'}
|
127
|
+
)
|
128
|
+
end
|
129
|
+
end
|
130
|
+
end
|
131
|
+
|
132
|
+
context 'given valid option with ipxe_chain_url(custom_os)' do
|
133
|
+
context 'when API responds normally' do
|
134
|
+
it 'returns server\'s sub_id(Hash)' do
|
135
|
+
data = "DCID=25"
|
136
|
+
data << "&VPSPLANID=52"
|
137
|
+
data << "&OSID=159"
|
138
|
+
data << "&ipxe_chain_url=http://example.com/script.txt"
|
139
|
+
WebMock.stub_request(:post, 'https://api.vultr.com/v1/server/create?api_key=APIKEY')
|
140
|
+
.with(body: data)
|
141
|
+
.to_return(body: %q{{"SUBID" : "1312965"}})
|
142
|
+
|
143
|
+
option = {DCID: 25, VPSPLANID: 52, OSID: 159, api_key: 'APIKEY', ipxe_chain_url: 'http://example.com/script.txt'}
|
144
|
+
response = Vultrlife::Agent.server_create(option)
|
145
|
+
expect(response).to eq(
|
146
|
+
{'SUBID' => '1312965'}
|
147
|
+
)
|
148
|
+
end
|
149
|
+
end
|
150
|
+
end
|
151
|
+
end
|
152
|
+
|
153
|
+
describe '.server_destroy' do
|
154
|
+
context 'given valid option' do
|
155
|
+
context 'when API responds normally server\'s "" with status 200' do
|
156
|
+
it 'returns ""' do
|
157
|
+
WebMock.stub_request(:post, 'https://api.vultr.com/v1/server/destroy?api_key=APIKEY')
|
158
|
+
.with(body: 'SUBID=111111')
|
159
|
+
.to_return(status: 200, body: '')
|
160
|
+
|
161
|
+
option = {SUBID: '111111', api_key: 'APIKEY'}
|
162
|
+
response = Vultrlife::Agent.server_destroy(option)
|
163
|
+
expect(response).to eq(
|
164
|
+
''
|
165
|
+
)
|
166
|
+
end
|
167
|
+
end
|
168
|
+
end
|
169
|
+
end
|
170
|
+
end
|
@@ -0,0 +1,92 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Vultrlife::Server::Configuration do
|
4
|
+
let(:config) do
|
5
|
+
|
6
|
+
account = Vultrlife::Account.new
|
7
|
+
|
8
|
+
Vultrlife::Server::Configuration.new(account)
|
9
|
+
end
|
10
|
+
|
11
|
+
describe '#region=' do
|
12
|
+
context 'given :tokyo' do
|
13
|
+
it 'sets @region :tokyo' do
|
14
|
+
expect do
|
15
|
+
config.region= :tokyo
|
16
|
+
end.to change {
|
17
|
+
config.instance_variable_get(:@region)
|
18
|
+
}.from(nil).to(:tokyo)
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
describe '#plan=' do
|
24
|
+
context 'given :starter' do
|
25
|
+
it 'sets @plan :starter' do
|
26
|
+
expect do
|
27
|
+
config.plan = :starter
|
28
|
+
end.to change {
|
29
|
+
config.instance_variable_get(:@plan)
|
30
|
+
}.from(nil).to(:starter)
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
describe '#os=' do
|
36
|
+
context 'given :custom' do
|
37
|
+
it 'sets @os :custom' do
|
38
|
+
expect do
|
39
|
+
config.os = :custom
|
40
|
+
end.to change {
|
41
|
+
config.instance_variable_get(:@os)
|
42
|
+
}.from(nil).to(:custom)
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
describe '#ipxe_chain_url=' do
|
48
|
+
context 'given url' do
|
49
|
+
it 'sets @ipxe_chain_url the url' do
|
50
|
+
expect do
|
51
|
+
config.ipxe_chain_url = 'http://example.com/script.txt'
|
52
|
+
end.to change {
|
53
|
+
config.instance_variable_get(:@ipxe_chain_url)
|
54
|
+
}.from(nil).to('http://example.com/script.txt')
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
describe '#api_key=' do
|
60
|
+
context 'given api_key' do
|
61
|
+
it 'sets @api_key the api_key' do
|
62
|
+
expect do
|
63
|
+
config.api_key = 'API_KEY'
|
64
|
+
end.to change {
|
65
|
+
config.instance_variable_get(:@api_key)
|
66
|
+
}.from('').to('API_KEY')
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
describe '#verify_plan' do
|
72
|
+
context 'given block' do
|
73
|
+
it 'yields Vultrlife::PlanVerifier' do
|
74
|
+
verifier = double(:verifier)
|
75
|
+
Vultrlife::PlanVerifier.should_receive(:new).and_return(verifier)
|
76
|
+
verifier.should_receive(:costs_at_most=).with(7)
|
77
|
+
verifier.should_receive(:vcpu_count= ).with(1)
|
78
|
+
verifier.should_receive(:ram= ).with(1024)
|
79
|
+
verifier.should_receive(:disk= ).with(30)
|
80
|
+
verifier.should_receive(:bandwidth= ).with(2)
|
81
|
+
|
82
|
+
config.verify_plan do |verify|
|
83
|
+
verify.costs_at_most = 7
|
84
|
+
verify.vcpu_count = 1
|
85
|
+
verify.ram = 1024
|
86
|
+
verify.disk = 30
|
87
|
+
verify.bandwidth = 2
|
88
|
+
end
|
89
|
+
end
|
90
|
+
end
|
91
|
+
end
|
92
|
+
end
|
@@ -0,0 +1,139 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'json'
|
3
|
+
|
4
|
+
describe Vultrlife::Server do
|
5
|
+
describe '.show_servers' do
|
6
|
+
context 'when some servers exist' do
|
7
|
+
let(:account) do
|
8
|
+
Vultrlife::Account.new do |account|
|
9
|
+
account.api_key = 'APIKEY'
|
10
|
+
end
|
11
|
+
end
|
12
|
+
it 'returns Server array' do
|
13
|
+
server_hash = {"1356867"=>
|
14
|
+
{"os"=>"CentOS 6 x64",
|
15
|
+
"ram"=>"768 MB",
|
16
|
+
"disk"=>"Virtual 15 GB",
|
17
|
+
"main_ip"=>"108.61.223.121",
|
18
|
+
"vcpu_count"=>"1",
|
19
|
+
"location"=>"Tokyo",
|
20
|
+
"default_password"=>"moskety!7j",
|
21
|
+
"date_created"=>"2014-05-25 07:28:35",
|
22
|
+
"pending_charges"=>"0.02",
|
23
|
+
"status"=>"active",
|
24
|
+
"cost_per_month"=>"5.00",
|
25
|
+
"current_bandwidth_gb"=>0.028,
|
26
|
+
"netmask_v4"=>"255.255.255.0",
|
27
|
+
"gateway_v4"=>"108.61.223.1",
|
28
|
+
"power_status"=>"running"}
|
29
|
+
}
|
30
|
+
Vultrlife::Agent.should_receive(:server_list).with('APIKEY').and_return(server_hash)
|
31
|
+
|
32
|
+
servers = Vultrlife::Server.show_servers(account)
|
33
|
+
expect(servers.size).to eq 1
|
34
|
+
expect(servers.first).to include("os"=>"CentOS 6 x64")
|
35
|
+
expect(servers.first).to be_a Vultrlife::Server
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
context 'when no servers exist' do
|
40
|
+
it 'returns []' do
|
41
|
+
pending
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
describe '#destroy!' do
|
47
|
+
context 'when successfully' do
|
48
|
+
it 'returns subid' do
|
49
|
+
account = Vultrlife::Account.new do |account|
|
50
|
+
account.api_key = 'API_KEY'
|
51
|
+
end
|
52
|
+
server = Vultrlife::Server.new('111111', account)
|
53
|
+
|
54
|
+
Vultrlife::Agent.should_receive(:server_destroy).with(SUBID: '111111', api_key: 'API_KEY')
|
55
|
+
expect(server.destroy!).to eq '111111'
|
56
|
+
expect(server).to be_destroyed
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
describe '.create!' do
|
62
|
+
let(:v1_plans) do
|
63
|
+
JSON.parse File.read('spec/fixtures/v1_plans.json')
|
64
|
+
end
|
65
|
+
|
66
|
+
let(:v1_regions) do
|
67
|
+
JSON.parse File.read('spec/fixtures/v1_regions.json')
|
68
|
+
end
|
69
|
+
|
70
|
+
let(:v1_os) do
|
71
|
+
JSON.parse File.read('spec/fixtures/v1_os.json')
|
72
|
+
end
|
73
|
+
|
74
|
+
let(:v1_availability_of_tokyo) do
|
75
|
+
JSON.parse File.read('spec/fixtures/v1_availability_of_tokyo.json')
|
76
|
+
end
|
77
|
+
|
78
|
+
let(:centos_config) do
|
79
|
+
account = Vultrlife::Account.new do |account|
|
80
|
+
account.api_key = 'API_KEY'
|
81
|
+
end
|
82
|
+
centos_config = Vultrlife::Server::Configuration.new(account)
|
83
|
+
centos_config.instance_eval do
|
84
|
+
@plan = '768 MB RAM,15 GB SSD,0.10 TB BW'
|
85
|
+
@region = :tokyo
|
86
|
+
@os = 'CentOS 6 x64'
|
87
|
+
@api_key = 'API_KEY'
|
88
|
+
end
|
89
|
+
centos_config
|
90
|
+
end
|
91
|
+
|
92
|
+
context 'given a config for CentOS' do
|
93
|
+
context 'the instance has a valid specific @plan, @region, @os' do
|
94
|
+
it 'check plans, availability, region' do
|
95
|
+
Vultrlife::Agent.should_receive(:plans_list).and_return(v1_plans)
|
96
|
+
Vultrlife::Agent.should_receive(:regions_list).and_return(v1_regions)
|
97
|
+
Vultrlife::Agent.should_receive(:os_list).and_return(v1_os)
|
98
|
+
Vultrlife::Agent.should_receive(:regions_availability).with('25').and_return(v1_availability_of_tokyo)
|
99
|
+
Vultrlife::Agent.should_receive(:server_create).with(VPSPLANID: 31, DCID: 25, OSID: 127, api_key: 'API_KEY').and_return("SUBID" => "1312965")
|
100
|
+
|
101
|
+
server = Vultrlife::Server.create!(centos_config)
|
102
|
+
expect(server.subid).to eq(1312965)
|
103
|
+
end
|
104
|
+
end
|
105
|
+
end
|
106
|
+
|
107
|
+
let(:custom_os_config) do
|
108
|
+
account = Vultrlife::Account.new do |account|
|
109
|
+
account.api_key = 'API_KEY'
|
110
|
+
end
|
111
|
+
custom_os_config = Vultrlife::Server::Configuration.new(account)
|
112
|
+
custom_os_config.instance_eval do
|
113
|
+
@plan = '768 MB RAM,15 GB SSD,0.10 TB BW, Custom ISO'
|
114
|
+
@region = :tokyo
|
115
|
+
@os = 'Custom'
|
116
|
+
@api_key = 'API_KEY'
|
117
|
+
@ipxe_chain_url = 'http://example.com/script.txt'
|
118
|
+
end
|
119
|
+
custom_os_config
|
120
|
+
end
|
121
|
+
|
122
|
+
context 'given a config for custom_os' do
|
123
|
+
context 'the instance has a valid specific @plan, @region, @os' do
|
124
|
+
it 'check plans, availability, region' do
|
125
|
+
Vultrlife::Agent.should_receive(:plans_list).and_return(v1_plans)
|
126
|
+
Vultrlife::Agent.should_receive(:regions_list).and_return(v1_regions)
|
127
|
+
Vultrlife::Agent.should_receive(:os_list).and_return(v1_os)
|
128
|
+
Vultrlife::Agent.should_receive(:regions_availability).with('25').and_return(v1_availability_of_tokyo)
|
129
|
+
Vultrlife::Agent.should_receive(:server_create)
|
130
|
+
.with(VPSPLANID: 52, DCID: 25, OSID: 159, api_key: 'API_KEY',ipxe_chain_url: 'http://example.com/script.txt')
|
131
|
+
.and_return("SUBID" => "1312965")
|
132
|
+
|
133
|
+
server = Vultrlife::Server.create!(custom_os_config)
|
134
|
+
expect(server.subid).to eq(1312965)
|
135
|
+
end
|
136
|
+
end
|
137
|
+
end
|
138
|
+
end
|
139
|
+
end
|
data/vultrlife.gemspec
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'vultrlife/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "vultrlife"
|
8
|
+
spec.version = Vultrlife::VERSION
|
9
|
+
spec.authors = ["hoshinotsuyoshi"]
|
10
|
+
spec.email = ["guitarpopnot330@gmail.com"]
|
11
|
+
spec.summary = %q{Vultr VPS API wrapper}
|
12
|
+
spec.description = %q{Vultr VPS API wrapper}
|
13
|
+
spec.homepage = ""
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files -z`.split("\x0")
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_development_dependency "bundler", "~> 1.5"
|
22
|
+
spec.add_development_dependency "rake"
|
23
|
+
spec.add_development_dependency "rspec"
|
24
|
+
spec.add_development_dependency "pry"
|
25
|
+
spec.add_development_dependency "webmock"
|
26
|
+
|
27
|
+
spec.required_ruby_version = '>= 1.9.3'
|
28
|
+
end
|
metadata
ADDED
@@ -0,0 +1,153 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: vultrlife
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.2
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- hoshinotsuyoshi
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-06-01 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.5'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.5'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '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: pry
|
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: webmock
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
description: Vultr VPS API wrapper
|
84
|
+
email:
|
85
|
+
- guitarpopnot330@gmail.com
|
86
|
+
executables: []
|
87
|
+
extensions: []
|
88
|
+
extra_rdoc_files: []
|
89
|
+
files:
|
90
|
+
- ".gitignore"
|
91
|
+
- ".rspec"
|
92
|
+
- ".ruby-version"
|
93
|
+
- ".travis.yml"
|
94
|
+
- Gemfile
|
95
|
+
- Gemfile.lock
|
96
|
+
- LICENSE
|
97
|
+
- README.md
|
98
|
+
- Rakefile
|
99
|
+
- lib/vultrlife.rb
|
100
|
+
- lib/vultrlife/account.rb
|
101
|
+
- lib/vultrlife/agent.rb
|
102
|
+
- lib/vultrlife/plan_verifier.rb
|
103
|
+
- lib/vultrlife/server.rb
|
104
|
+
- lib/vultrlife/server/configuration.rb
|
105
|
+
- lib/vultrlife/version.rb
|
106
|
+
- spec/fixtures/v1_availability_of_tokyo.json
|
107
|
+
- spec/fixtures/v1_os.json
|
108
|
+
- spec/fixtures/v1_plans.json
|
109
|
+
- spec/fixtures/v1_regions.json
|
110
|
+
- spec/fixtures/v1_server_list.json
|
111
|
+
- spec/spec_helper.rb
|
112
|
+
- spec/vultrlife/account_spec.rb
|
113
|
+
- spec/vultrlife/agent_spec.rb
|
114
|
+
- spec/vultrlife/server/configuration_spec.rb
|
115
|
+
- spec/vultrlife/server_spec.rb
|
116
|
+
- spec/vultrlife_spec.rb
|
117
|
+
- vultrlife.gemspec
|
118
|
+
homepage: ''
|
119
|
+
licenses:
|
120
|
+
- MIT
|
121
|
+
metadata: {}
|
122
|
+
post_install_message:
|
123
|
+
rdoc_options: []
|
124
|
+
require_paths:
|
125
|
+
- lib
|
126
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
127
|
+
requirements:
|
128
|
+
- - ">="
|
129
|
+
- !ruby/object:Gem::Version
|
130
|
+
version: 1.9.3
|
131
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
132
|
+
requirements:
|
133
|
+
- - ">="
|
134
|
+
- !ruby/object:Gem::Version
|
135
|
+
version: '0'
|
136
|
+
requirements: []
|
137
|
+
rubyforge_project:
|
138
|
+
rubygems_version: 2.2.2
|
139
|
+
signing_key:
|
140
|
+
specification_version: 4
|
141
|
+
summary: Vultr VPS API wrapper
|
142
|
+
test_files:
|
143
|
+
- spec/fixtures/v1_availability_of_tokyo.json
|
144
|
+
- spec/fixtures/v1_os.json
|
145
|
+
- spec/fixtures/v1_plans.json
|
146
|
+
- spec/fixtures/v1_regions.json
|
147
|
+
- spec/fixtures/v1_server_list.json
|
148
|
+
- spec/spec_helper.rb
|
149
|
+
- spec/vultrlife/account_spec.rb
|
150
|
+
- spec/vultrlife/agent_spec.rb
|
151
|
+
- spec/vultrlife/server/configuration_spec.rb
|
152
|
+
- spec/vultrlife/server_spec.rb
|
153
|
+
- spec/vultrlife_spec.rb
|