hetzner-api 1.0.0.alpha.2 → 1.0.0.alpha.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/Gemfile.lock +1 -1
- data/lib/hetzner/api/boot/plesk.rb +20 -0
- data/lib/hetzner/api/server.rb +17 -0
- data/lib/hetzner/api/subnet.rb +29 -0
- data/lib/hetzner/api/traffic.rb +65 -0
- data/lib/hetzner/api/version.rb +1 -1
- data/spec/api_stubs.rb +48 -1
- data/spec/fixtures/boot/plesk/delete.raw +14 -0
- data/spec/fixtures/boot/plesk/get.raw +14 -0
- data/spec/fixtures/boot/plesk/post.raw +14 -0
- data/spec/fixtures/server/get.raw +29 -0
- data/spec/fixtures/server/get_with_server_ip.raw +23 -0
- data/spec/fixtures/subnet/get.raw +33 -0
- data/spec/fixtures/subnet/get_with_server_ip.raw +19 -0
- data/spec/fixtures/subnet/get_with_subnet_ip.raw +17 -0
- data/spec/fixtures/traffic/post_with_one_ip_and_one_subnet_day.raw +37 -0
- data/spec/fixtures/traffic/post_with_two_ips_and_no_subnet_month.raw +22 -0
- data/spec/fixtures/traffic/post_with_two_subnets_and_no_ip_year.raw +52 -0
- data/spec/hetzner_api_spec.rb +141 -0
- data/spec/spec_constants.rb +3 -0
- metadata +15 -4
data/Gemfile.lock
CHANGED
@@ -2,6 +2,26 @@ module Hetzner
|
|
2
2
|
class API
|
3
3
|
module Boot
|
4
4
|
module Plesk
|
5
|
+
# queries the plesk boot status of one IP address/server
|
6
|
+
def boot_plesk?(ip)
|
7
|
+
path = "/boot/#{ip}/plesk"
|
8
|
+
perform_get path
|
9
|
+
end
|
10
|
+
|
11
|
+
# enables plesk boot option for one IP address/server
|
12
|
+
#
|
13
|
+
# see <em>Boot</em> to query the API for available options
|
14
|
+
def boot_plesk!(ip, dist, arch, lang, hostname)
|
15
|
+
path = "/boot/#{ip}/plesk"
|
16
|
+
perform_post path, :query => { :dist => dist, :arch => arch, :lang => lang, :hostname => hostname }
|
17
|
+
end
|
18
|
+
|
19
|
+
# disables the vnc boot status of one IP address/server
|
20
|
+
def disable_boot_plesk!(ip)
|
21
|
+
path = "/boot/#{ip}/plesk"
|
22
|
+
perform_delete path
|
23
|
+
end
|
24
|
+
|
5
25
|
end
|
6
26
|
end
|
7
27
|
end
|
data/lib/hetzner/api/server.rb
CHANGED
@@ -1,6 +1,23 @@
|
|
1
1
|
module Hetzner
|
2
2
|
class API
|
3
3
|
module Server
|
4
|
+
# returns a list of all servers of the customer
|
5
|
+
def servers?
|
6
|
+
get_server_or_servers
|
7
|
+
end
|
8
|
+
|
9
|
+
# returns a list of all servers or just for a specific server ip
|
10
|
+
def server?(server_ip)
|
11
|
+
get_server_or_servers server_ip
|
12
|
+
end
|
13
|
+
|
14
|
+
private
|
15
|
+
|
16
|
+
def get_server_or_servers(server_ip = nil)
|
17
|
+
path = "/server"
|
18
|
+
path << "/#{server_ip}" if server_ip
|
19
|
+
perform_get path
|
20
|
+
end
|
4
21
|
end
|
5
22
|
end
|
6
23
|
end
|
data/lib/hetzner/api/subnet.rb
CHANGED
@@ -1,6 +1,35 @@
|
|
1
1
|
module Hetzner
|
2
2
|
class API
|
3
3
|
module Subnet
|
4
|
+
# shows all IP subnets that belong to the main server IP
|
5
|
+
def subnets_for_server?(server_ip)
|
6
|
+
path = "/subnet"
|
7
|
+
perform_get path, :query => { :server_ip => server_ip }
|
8
|
+
end
|
9
|
+
|
10
|
+
# shows information of all IP subnets of the customer
|
11
|
+
def subnets?
|
12
|
+
get_subnet_or_subnets
|
13
|
+
end
|
14
|
+
|
15
|
+
# shows information of a given IP subnet of the customer
|
16
|
+
def subnet?(ip)
|
17
|
+
get_subnet_or_subnets ip
|
18
|
+
end
|
19
|
+
|
20
|
+
# sets or unsets traffic warning limits on a specific IP subnet address
|
21
|
+
def subnet!(ip, options = {})
|
22
|
+
path = "/subnet/#{ip}"
|
23
|
+
perform_post path, :query => options
|
24
|
+
end
|
25
|
+
|
26
|
+
private
|
27
|
+
|
28
|
+
def get_subnet_or_subnets(ip = nil)
|
29
|
+
path = "/subnet"
|
30
|
+
path << "/#{ip}" if ip
|
31
|
+
perform_get path
|
32
|
+
end
|
4
33
|
end
|
5
34
|
end
|
6
35
|
end
|
data/lib/hetzner/api/traffic.rb
CHANGED
@@ -1,6 +1,71 @@
|
|
1
1
|
module Hetzner
|
2
2
|
class API
|
3
3
|
module Traffic
|
4
|
+
# returns the traffic information for an IP and/or subnet according to the selected time frame.
|
5
|
+
def traffic?(options = {})
|
6
|
+
|
7
|
+
ips = options[:ips]
|
8
|
+
subnets = options[:subnets]
|
9
|
+
from = options[:from]
|
10
|
+
to = options[:to]
|
11
|
+
type = options[:type].to_sym
|
12
|
+
|
13
|
+
from = DateTime.parse(from) unless from.is_a? Date
|
14
|
+
to = DateTime.parse(to) unless to.is_a? Date
|
15
|
+
|
16
|
+
case type
|
17
|
+
when :year
|
18
|
+
format = "%Y-%m" # 2010-01
|
19
|
+
from_date = from.strftime format
|
20
|
+
to_date = to.strftime format
|
21
|
+
when :month
|
22
|
+
format = "%Y-%m-%d" # 2010-12-30
|
23
|
+
from_date = from.strftime format
|
24
|
+
to_date = to.strftime format
|
25
|
+
when :day
|
26
|
+
format = "%Y-%m-%dT%H" # 2010-01-01T15
|
27
|
+
from_date = from.strftime format
|
28
|
+
to_date = to.strftime format
|
29
|
+
else
|
30
|
+
raise ArgumentError, 'Invalid time frame type. Must be one of: :year, :month, :day'
|
31
|
+
end
|
32
|
+
|
33
|
+
validate_dates_and_type from, to, type
|
34
|
+
|
35
|
+
perform_post "/traffic", :query => {
|
36
|
+
:ip => ips,
|
37
|
+
:subnet => subnets,
|
38
|
+
:from => from_date,
|
39
|
+
:to => to_date,
|
40
|
+
:type => type
|
41
|
+
}
|
42
|
+
end
|
43
|
+
|
44
|
+
private
|
45
|
+
|
46
|
+
def validate_dates_and_type(from, to, type)
|
47
|
+
today = DateTime.now
|
48
|
+
|
49
|
+
case type
|
50
|
+
when :month
|
51
|
+
#if (same_year_and_month?(today, from) || same_year_and_month?(today, to))
|
52
|
+
# raise ArgumentError, 'Invalid timeframe: Time frame :month for this date is available AFTER CURRENT MONTH ONLY! => try :day instead'
|
53
|
+
#end
|
54
|
+
|
55
|
+
when :day
|
56
|
+
unless same_day?(from, to)
|
57
|
+
raise ArgumentError, 'Invalid date for timeframe. for type == :day queries both dates have to be on the same *day*'
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
def same_year_and_month?(a,b)
|
63
|
+
a.strftime("%Y-%m") == b.strftime("%Y-%m")
|
64
|
+
end
|
65
|
+
|
66
|
+
def same_day?(a,b)
|
67
|
+
a.strftime("%Y-%m-%d") == b.strftime("%Y-%m-%d")
|
68
|
+
end
|
4
69
|
end
|
5
70
|
end
|
6
71
|
end
|
data/lib/hetzner/api/version.rb
CHANGED
data/spec/api_stubs.rb
CHANGED
@@ -68,6 +68,15 @@ FakeWeb.register_uri :post, uri("#{WORKING_IP}/vnc?arch=32&lang=en_US&dist=Fed
|
|
68
68
|
FakeWeb.register_uri :delete, uri("#{WORKING_IP}/vnc"),
|
69
69
|
:response => fixture('vnc/delete.raw')
|
70
70
|
|
71
|
+
FakeWeb.register_uri :get, uri("#{WORKING_IP}/plesk"),
|
72
|
+
:response => fixture('plesk/get.raw')
|
73
|
+
|
74
|
+
FakeWeb.register_uri :post, uri("#{WORKING_IP}/plesk?arch=32&lang=en_US&dist=Fedora-13&hostname=dr-gerner-aus-gzsz.confixx.de"),
|
75
|
+
:response => fixture('plesk/post.raw') # perl2exe insider
|
76
|
+
|
77
|
+
FakeWeb.register_uri :delete, uri("#{WORKING_IP}/plesk"),
|
78
|
+
:response => fixture('plesk/delete.raw')
|
79
|
+
|
71
80
|
|
72
81
|
@resource = 'wol'
|
73
82
|
|
@@ -103,9 +112,47 @@ FakeWeb.register_uri :get, uri("#{WORKING_IP}"),
|
|
103
112
|
|
104
113
|
FakeWeb.register_uri :post, uri("#{WORKING_IP}?traffic_warnings=true&traffic_monthly=2342"),
|
105
114
|
:response => fixture('post_activate_with_data.raw')
|
106
|
-
|
115
|
+
|
107
116
|
FakeWeb.register_uri :post, uri("#{WORKING_IP}?traffic_warnings=false"),
|
108
117
|
:response => fixture('post_deactivate_with_data.raw')
|
109
118
|
|
110
119
|
|
120
|
+
@resource = 'subnet'
|
121
|
+
|
122
|
+
FakeWeb.register_uri :get, uri,
|
123
|
+
:response => fixture('get.raw')
|
124
|
+
|
125
|
+
FakeWeb.register_uri :get, uri(nil, "?server_ip=#{WORKING_IP}"),
|
126
|
+
:response => fixture('get_with_server_ip.raw')
|
127
|
+
|
128
|
+
FakeWeb.register_uri :get, uri("#{WORKING_SUBNET_IP}"),
|
129
|
+
:response => fixture('get_with_subnet_ip.raw')
|
130
|
+
|
131
|
+
FakeWeb.register_uri :post, uri("#{WORKING_SUBNET_IP}?traffic_warnings=true&traffic_monthly=2342"),
|
132
|
+
:response => fixture('post_activate_with_data.raw')
|
133
|
+
|
134
|
+
FakeWeb.register_uri :post, uri("#{WORKING_SUBNET_IP}?traffic_warnings=false"),
|
135
|
+
:response => fixture('post_deactivate_with_data.raw')
|
136
|
+
|
137
|
+
|
138
|
+
@resource = 'server'
|
139
|
+
|
140
|
+
FakeWeb.register_uri :get, uri,
|
141
|
+
:response => fixture('get.raw')
|
142
|
+
|
143
|
+
FakeWeb.register_uri :get, uri("#{WORKING_IP}"),
|
144
|
+
:response => fixture('get_with_server_ip.raw')
|
145
|
+
|
146
|
+
|
147
|
+
@resource = 'traffic'
|
148
|
+
|
149
|
+
FakeWeb.register_uri :post, uri(nil, "?from=2010-10-10T01&type=day&ip[]=#{WORKING_IP}&to=2010-10-10T10&subnet[]=#{WORKING_SUBNET_IP}"),
|
150
|
+
:response => fixture('post_with_one_ip_and_one_subnet_day.raw')
|
151
|
+
|
152
|
+
FakeWeb.register_uri :post, uri(nil, "?from=2010-09-01&type=month&ip[]=#{WORKING_IP}&to=2010-10-01&ip[]=#{WORKING_IP_2}"),
|
153
|
+
:response => fixture('post_with_two_ips_and_no_subnet_month.raw')
|
154
|
+
|
155
|
+
FakeWeb.register_uri :post, uri(nil, "?from=2010-01&to=2010-10&type=year&subnet[]=#{WORKING_SUBNET_IP}&subnet[]=#{WORKING_SUBNET_IP_2}"),
|
156
|
+
:response => fixture('post_with_two_subnets_and_no_ip_year.raw')
|
157
|
+
|
111
158
|
#pp FakeWeb::Registry.instance.uri_map
|
@@ -0,0 +1,14 @@
|
|
1
|
+
HTTP/1.1 200 OK
|
2
|
+
Content-Type: application/json
|
3
|
+
|
4
|
+
{
|
5
|
+
"plesk": {
|
6
|
+
"server_ip": "11.11.11.111",
|
7
|
+
"dist": ["CentOS 5.4 minimal","Debian 5.0 minimal"],
|
8
|
+
"arch": [64,32],
|
9
|
+
"lang": ["en","de"],
|
10
|
+
"active": false,
|
11
|
+
"password": null,
|
12
|
+
"hostname": null
|
13
|
+
}
|
14
|
+
}
|
@@ -0,0 +1,14 @@
|
|
1
|
+
HTTP/1.1 200 OK
|
2
|
+
Content-Type: application/json
|
3
|
+
|
4
|
+
{
|
5
|
+
"plesk": {
|
6
|
+
"server_ip": "11.11.11.111",
|
7
|
+
"dist": ["CentOS 5.4 minimal","Debian 5.0 minimal"],
|
8
|
+
"arch": [64,32],
|
9
|
+
"lang": ["en","de"],
|
10
|
+
"active": false,
|
11
|
+
"password": null,
|
12
|
+
"hostname": null
|
13
|
+
}
|
14
|
+
}
|
@@ -0,0 +1,14 @@
|
|
1
|
+
HTTP/1.1 200 OK
|
2
|
+
Content-Type: application/json
|
3
|
+
|
4
|
+
{
|
5
|
+
"plesk": {
|
6
|
+
"server_ip": "11.11.11.111",
|
7
|
+
"dist": "CentOS 5.4 minimal",
|
8
|
+
"arch": 32,
|
9
|
+
"lang": "de",
|
10
|
+
"active": true,
|
11
|
+
"password": "ie8Nhz6R",
|
12
|
+
"hostname": "dr-gerner-aus-gzsz.confixx.de"
|
13
|
+
}
|
14
|
+
}
|
@@ -0,0 +1,29 @@
|
|
1
|
+
HTTP/1.1 200 OK
|
2
|
+
Content-Type: application/json
|
3
|
+
|
4
|
+
[
|
5
|
+
{
|
6
|
+
"server": {
|
7
|
+
"server_ip": "11.11.11.111",
|
8
|
+
"product": "DS 3000",
|
9
|
+
"dc": 6,
|
10
|
+
"traffic": "5 TB",
|
11
|
+
"status": "ready",
|
12
|
+
"throttled": true,
|
13
|
+
"cancelled": false,
|
14
|
+
"paid_until": "2010-09-02"
|
15
|
+
}
|
16
|
+
},
|
17
|
+
{
|
18
|
+
"server": {
|
19
|
+
"server_ip": "11.11.11.112",
|
20
|
+
"product": "X5",
|
21
|
+
"dc": 5,
|
22
|
+
"traffic": "2 TB",
|
23
|
+
"status": "ready",
|
24
|
+
"throttled": false,
|
25
|
+
"cancelled": false,
|
26
|
+
"paid_until": "2010-06-11"
|
27
|
+
}
|
28
|
+
}
|
29
|
+
]
|
@@ -0,0 +1,23 @@
|
|
1
|
+
HTTP/1.1 200 OK
|
2
|
+
Content-Type: application/json
|
3
|
+
|
4
|
+
{
|
5
|
+
"server": {
|
6
|
+
"server_ip": "11.11.11.111",
|
7
|
+
"product": "EQ 8",
|
8
|
+
"dc": 11,
|
9
|
+
"traffic": "5 TB",
|
10
|
+
"status": "ready",
|
11
|
+
"throttled": false,
|
12
|
+
"cancelled": false,
|
13
|
+
"paid_until": "2010-08-04",
|
14
|
+
"ip": ["11.11.11.111"],
|
15
|
+
"subnet": [{"ip": "2a01:4f8:111:4221::", "mask": "64"}],
|
16
|
+
"reset": true,
|
17
|
+
"rescue": true,
|
18
|
+
"vnc": true,
|
19
|
+
"windows": true,
|
20
|
+
"plesk": true,
|
21
|
+
"wol": true
|
22
|
+
}
|
23
|
+
}
|
@@ -0,0 +1,33 @@
|
|
1
|
+
HTTP/1.1 200 OK
|
2
|
+
Content-Type: application/json
|
3
|
+
|
4
|
+
[
|
5
|
+
{
|
6
|
+
"subnet": {
|
7
|
+
"ip": "11.11.12.111",
|
8
|
+
"mask": 29,
|
9
|
+
"gateway": "123.123.123.123",
|
10
|
+
"server_ip": "88.198.123.123",
|
11
|
+
"failover": false,
|
12
|
+
"locked": false,
|
13
|
+
"traffic_warnings": false,
|
14
|
+
"traffic_hourly": 100,
|
15
|
+
"traffic_daily": 500,
|
16
|
+
"traffic_monthly": 2
|
17
|
+
}
|
18
|
+
},
|
19
|
+
{
|
20
|
+
"subnet":{
|
21
|
+
"ip": "11.11.13.111",
|
22
|
+
"mask": 25,
|
23
|
+
"gateway": "178.63.123.124",
|
24
|
+
"server_ip": null,
|
25
|
+
"failover": false,
|
26
|
+
"locked": false,
|
27
|
+
"traffic_warnings": false,
|
28
|
+
"traffic_hourly": 100,
|
29
|
+
"traffic_daily": 500,
|
30
|
+
"traffic_monthly": 2
|
31
|
+
}
|
32
|
+
}
|
33
|
+
]
|
@@ -0,0 +1,19 @@
|
|
1
|
+
HTTP/1.1 200 OK
|
2
|
+
Content-Type: application/json
|
3
|
+
|
4
|
+
[
|
5
|
+
{
|
6
|
+
"subnet": {
|
7
|
+
"ip": "11.11.12.111",
|
8
|
+
"mask": 29,
|
9
|
+
"gateway": "123.123.123.123",
|
10
|
+
"server_ip": "88.198.123.123",
|
11
|
+
"failover": false,
|
12
|
+
"locked": false,
|
13
|
+
"traffic_warnings": false,
|
14
|
+
"traffic_hourly": 100,
|
15
|
+
"traffic_daily": 500,
|
16
|
+
"traffic_monthly": 2
|
17
|
+
}
|
18
|
+
}
|
19
|
+
]
|
@@ -0,0 +1,17 @@
|
|
1
|
+
HTTP/1.1 200 OK
|
2
|
+
Content-Type: application/json
|
3
|
+
|
4
|
+
{
|
5
|
+
"subnet": {
|
6
|
+
"ip": "11.11.12.111",
|
7
|
+
"mask": 29,
|
8
|
+
"gateway": "123.123.123.123",
|
9
|
+
"server_ip": "88.198.123.123",
|
10
|
+
"failover": false,
|
11
|
+
"locked": false,
|
12
|
+
"traffic_warnings": false,
|
13
|
+
"traffic_hourly": 100,
|
14
|
+
"traffic_daily": 500,
|
15
|
+
"traffic_monthly": 2
|
16
|
+
}
|
17
|
+
}
|
@@ -0,0 +1,37 @@
|
|
1
|
+
HTTP/1.1 200 OK
|
2
|
+
Content-Type: application/json
|
3
|
+
|
4
|
+
{
|
5
|
+
"traffic": {
|
6
|
+
"data": {
|
7
|
+
"11.11.11.111": {
|
8
|
+
"sum": 0.0107,
|
9
|
+
"out": 0.0078,
|
10
|
+
"in": 0.0029
|
11
|
+
},
|
12
|
+
"11.11.12.111": {
|
13
|
+
"sum": 0.1002,
|
14
|
+
"out": 0.0128,
|
15
|
+
"in": 0.0874
|
16
|
+
},
|
17
|
+
"11.11.12.112": {
|
18
|
+
"sum": 0.0095,
|
19
|
+
"out": 0.0066,
|
20
|
+
"in": 0.0029
|
21
|
+
},
|
22
|
+
"11.11.12.113": {
|
23
|
+
"sum": 0.0128,
|
24
|
+
"out": 0.0094,
|
25
|
+
"in": 0.0034
|
26
|
+
},
|
27
|
+
"11.11.12.114": {
|
28
|
+
"sum": 0.0109,
|
29
|
+
"out": 0.0079,
|
30
|
+
"in": 0.003
|
31
|
+
}
|
32
|
+
},
|
33
|
+
"from": "2010-10-108T01:00+0200",
|
34
|
+
"to": "2010-10-10T10:00+0200",
|
35
|
+
"type": "day"
|
36
|
+
}
|
37
|
+
}
|
@@ -0,0 +1,22 @@
|
|
1
|
+
HTTP/1.1 200 OK
|
2
|
+
Content-Type: application/json
|
3
|
+
|
4
|
+
{
|
5
|
+
"traffic": {
|
6
|
+
"data": {
|
7
|
+
"11.11.11.111": {
|
8
|
+
"sum": 0.0107,
|
9
|
+
"out": 0.0078,
|
10
|
+
"in": 0.0029
|
11
|
+
},
|
12
|
+
"11.11.11.112": {
|
13
|
+
"sum": 0.1002,
|
14
|
+
"out": 0.0128,
|
15
|
+
"in": 0.0874
|
16
|
+
}
|
17
|
+
},
|
18
|
+
"from": "2010-09-01",
|
19
|
+
"to": "2010-10-01",
|
20
|
+
"type": "month"
|
21
|
+
}
|
22
|
+
}
|
@@ -0,0 +1,52 @@
|
|
1
|
+
HTTP/1.1 200 OK
|
2
|
+
Content-Type: application/json
|
3
|
+
|
4
|
+
{
|
5
|
+
"traffic": {
|
6
|
+
"data": {
|
7
|
+
"11.11.12.111": {
|
8
|
+
"sum": 0.1002,
|
9
|
+
"out": 0.0128,
|
10
|
+
"in": 0.0874
|
11
|
+
},
|
12
|
+
"11.11.12.112": {
|
13
|
+
"sum": 0.0095,
|
14
|
+
"out": 0.0066,
|
15
|
+
"in": 0.0029
|
16
|
+
},
|
17
|
+
"11.11.12.113": {
|
18
|
+
"sum": 0.0128,
|
19
|
+
"out": 0.0094,
|
20
|
+
"in": 0.0034
|
21
|
+
},
|
22
|
+
"11.11.12.114": {
|
23
|
+
"sum": 0.0109,
|
24
|
+
"out": 0.0079,
|
25
|
+
"in": 0.003
|
26
|
+
},
|
27
|
+
"11.11.13.111": {
|
28
|
+
"sum": 0.1002,
|
29
|
+
"out": 0.0128,
|
30
|
+
"in": 0.0874
|
31
|
+
},
|
32
|
+
"11.11.13.112": {
|
33
|
+
"sum": 0.0095,
|
34
|
+
"out": 0.0066,
|
35
|
+
"in": 0.0029
|
36
|
+
},
|
37
|
+
"11.11.13.113": {
|
38
|
+
"sum": 0.0128,
|
39
|
+
"out": 0.0094,
|
40
|
+
"in": 0.0034
|
41
|
+
},
|
42
|
+
"11.11.13.114": {
|
43
|
+
"sum": 0.0109,
|
44
|
+
"out": 0.0079,
|
45
|
+
"in": 0.003
|
46
|
+
}
|
47
|
+
},
|
48
|
+
"from": "2010-01",
|
49
|
+
"to": "2010-10",
|
50
|
+
"type": "year"
|
51
|
+
}
|
52
|
+
}
|
data/spec/hetzner_api_spec.rb
CHANGED
@@ -219,3 +219,144 @@ describe 'IP' do
|
|
219
219
|
end
|
220
220
|
end
|
221
221
|
|
222
|
+
describe 'Subnet' do
|
223
|
+
describe "information" do
|
224
|
+
before(:all) do
|
225
|
+
@h = Hetzner::API.new API_USERNAME, API_PASSWORD
|
226
|
+
end
|
227
|
+
it "should be able to display all IP subnets of the customer account" do
|
228
|
+
result = @h.subnets?
|
229
|
+
result.response.should be_an_instance_of Net::HTTPOK
|
230
|
+
result.parsed_response.should have_at_least(2).entries
|
231
|
+
end
|
232
|
+
|
233
|
+
it "should be able to display a IP subnet of the customer account" do
|
234
|
+
result = @h.subnet? WORKING_SUBNET_IP
|
235
|
+
result.response.should be_an_instance_of Net::HTTPOK
|
236
|
+
result.parsed_response.should have(1).entry
|
237
|
+
end
|
238
|
+
|
239
|
+
it "should be able to display all IP addresses for a given server IP address" do
|
240
|
+
result = @h.subnets_for_server? WORKING_IP
|
241
|
+
result.response.should be_an_instance_of Net::HTTPOK
|
242
|
+
result.parsed_response.should have(1).entry
|
243
|
+
end
|
244
|
+
end
|
245
|
+
|
246
|
+
describe "manage traffic warnings" do
|
247
|
+
before(:all) do
|
248
|
+
@h = Hetzner::API.new API_USERNAME, API_PASSWORD
|
249
|
+
end
|
250
|
+
|
251
|
+
it "should be able to activate and set traffic warning limits on a specific IP address" do
|
252
|
+
result = @h.ip! WORKING_IP, :traffic_warnings => 'true', :traffic_monthly => TRAFFIC_LIMIT_IN_GIGABYTE
|
253
|
+
result.response.should be_an_instance_of Net::HTTPOK
|
254
|
+
result.parsed_response.should have(1).entry
|
255
|
+
end
|
256
|
+
|
257
|
+
it "should be able to deactivate traffic warnings for a specific IP address" do
|
258
|
+
result = @h.ip! WORKING_IP, :traffic_warnings => 'false'
|
259
|
+
result.response.should be_an_instance_of Net::HTTPOK
|
260
|
+
result.parsed_response.should have(1).entry
|
261
|
+
end
|
262
|
+
end
|
263
|
+
end
|
264
|
+
|
265
|
+
|
266
|
+
describe "Server" do
|
267
|
+
describe "information" do
|
268
|
+
before(:all) do
|
269
|
+
@h = Hetzner::API.new API_USERNAME, API_PASSWORD
|
270
|
+
end
|
271
|
+
|
272
|
+
it "should be able to display all servers of the customer account" do
|
273
|
+
result = @h.servers?
|
274
|
+
result.response.should be_an_instance_of Net::HTTPOK
|
275
|
+
result.parsed_response.should have_at_least(2).entries
|
276
|
+
end
|
277
|
+
|
278
|
+
it "should be able to display a specific server by its IP address" do
|
279
|
+
result = @h.server? WORKING_IP
|
280
|
+
result.response.should be_an_instance_of Net::HTTPOK
|
281
|
+
result.parsed_response.should have_at_least(1).entry
|
282
|
+
end
|
283
|
+
end
|
284
|
+
end
|
285
|
+
|
286
|
+
describe "Plesk" do
|
287
|
+
before(:all) do
|
288
|
+
@h = Hetzner::API.new API_USERNAME, API_PASSWORD
|
289
|
+
end
|
290
|
+
|
291
|
+
it "should be able to query plesk boot option status" do
|
292
|
+
result = @h.boot_plesk? WORKING_IP
|
293
|
+
result.response.should be_an_instance_of Net::HTTPOK
|
294
|
+
result['plesk']['server_ip'].should == WORKING_IP
|
295
|
+
result['plesk']['active'].should be_false
|
296
|
+
result['plesk']['password'].should be_nil
|
297
|
+
end
|
298
|
+
|
299
|
+
it "should be able to activate plesk boot option" do
|
300
|
+
result = @h.boot_plesk! WORKING_IP, 'Fedora-13', '32', 'en_US', 'dr-gerner-aus-gzsz.confixx.de'
|
301
|
+
result.response.should be_an_instance_of Net::HTTPOK
|
302
|
+
result['plesk']['server_ip'].should == WORKING_IP
|
303
|
+
result['plesk']['active'].should be_true
|
304
|
+
result['plesk']['password'].should_not be_nil
|
305
|
+
end
|
306
|
+
|
307
|
+
it "should be able to disable plesk boot option" do
|
308
|
+
result = @h.disable_boot_plesk! WORKING_IP
|
309
|
+
result.response.should be_an_instance_of Net::HTTPOK
|
310
|
+
result['plesk']['server_ip'].should == WORKING_IP
|
311
|
+
result['plesk']['active'].should be_false
|
312
|
+
result['plesk']['password'].should be_nil
|
313
|
+
end
|
314
|
+
end
|
315
|
+
|
316
|
+
describe "Traffic" do
|
317
|
+
before(:all) do
|
318
|
+
@h = Hetzner::API.new API_USERNAME, API_PASSWORD
|
319
|
+
end
|
320
|
+
|
321
|
+
it "should display the traffic for a specific ip address and a subnet" do
|
322
|
+
options = {
|
323
|
+
:ips => [WORKING_IP],
|
324
|
+
:subnets => [WORKING_SUBNET_IP],
|
325
|
+
:from => DateTime.parse('10.10.2010 01:00'),
|
326
|
+
:to => DateTime.parse('10.10.2010 10:21'),
|
327
|
+
:type => :day
|
328
|
+
}
|
329
|
+
|
330
|
+
result = @h.traffic? options
|
331
|
+
|
332
|
+
result.response.should be_an_instance_of Net::HTTPOK
|
333
|
+
end
|
334
|
+
|
335
|
+
it "should display the traffic for serveral IP addresse and no subnet" do
|
336
|
+
options = {
|
337
|
+
:ips => [WORKING_IP, WORKING_IP_2],
|
338
|
+
:subnets => [],
|
339
|
+
:from => "01.09.2010",
|
340
|
+
:to => "01.10.2010",
|
341
|
+
:type => :month
|
342
|
+
}
|
343
|
+
|
344
|
+
result = @h.traffic? options
|
345
|
+
|
346
|
+
result.response.should be_an_instance_of Net::HTTPOK
|
347
|
+
end
|
348
|
+
|
349
|
+
it "should display the traffic for subnets and no ip address" do
|
350
|
+
options = {
|
351
|
+
:ips => [],
|
352
|
+
:subnets => [WORKING_SUBNET_IP, WORKING_SUBNET_IP_2],
|
353
|
+
:from => "01.01.2010",
|
354
|
+
:to => "01.10.2010",
|
355
|
+
:type => :year
|
356
|
+
}
|
357
|
+
|
358
|
+
result = @h.traffic? options
|
359
|
+
|
360
|
+
result.response.should be_an_instance_of Net::HTTPOK
|
361
|
+
end
|
362
|
+
end
|
data/spec/spec_constants.rb
CHANGED
metadata
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: hetzner-api
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash: -
|
4
|
+
hash: -3702664326
|
5
5
|
prerelease: true
|
6
6
|
segments:
|
7
7
|
- 1
|
8
8
|
- 0
|
9
9
|
- 0
|
10
10
|
- alpha
|
11
|
-
-
|
12
|
-
version: 1.0.0.alpha.
|
11
|
+
- 3
|
12
|
+
version: 1.0.0.alpha.3
|
13
13
|
platform: ruby
|
14
14
|
authors:
|
15
15
|
- Roland Moriz
|
@@ -17,7 +17,7 @@ autorequire:
|
|
17
17
|
bindir: bin
|
18
18
|
cert_chain: []
|
19
19
|
|
20
|
-
date: 2010-10-
|
20
|
+
date: 2010-10-09 00:00:00 +02:00
|
21
21
|
default_executable:
|
22
22
|
dependencies:
|
23
23
|
- !ruby/object:Gem::Dependency
|
@@ -190,6 +190,9 @@ files:
|
|
190
190
|
- lib/hetzner/api/wol.rb
|
191
191
|
- spec/api_stubs.rb
|
192
192
|
- spec/fixtures/boot/get_with_ip.raw
|
193
|
+
- spec/fixtures/boot/plesk/delete.raw
|
194
|
+
- spec/fixtures/boot/plesk/get.raw
|
195
|
+
- spec/fixtures/boot/plesk/post.raw
|
193
196
|
- spec/fixtures/boot/rescue/delete.raw
|
194
197
|
- spec/fixtures/boot/rescue/post.raw
|
195
198
|
- spec/fixtures/boot/vnc/delete.raw
|
@@ -212,6 +215,14 @@ files:
|
|
212
215
|
- spec/fixtures/reset/post_with_ip_manual_active.raw
|
213
216
|
- spec/fixtures/reset/post_with_ip_unavailable.raw
|
214
217
|
- spec/fixtures/reset/post_with_ip_unknown.raw
|
218
|
+
- spec/fixtures/server/get.raw
|
219
|
+
- spec/fixtures/server/get_with_server_ip.raw
|
220
|
+
- spec/fixtures/subnet/get.raw
|
221
|
+
- spec/fixtures/subnet/get_with_server_ip.raw
|
222
|
+
- spec/fixtures/subnet/get_with_subnet_ip.raw
|
223
|
+
- spec/fixtures/traffic/post_with_one_ip_and_one_subnet_day.raw
|
224
|
+
- spec/fixtures/traffic/post_with_two_ips_and_no_subnet_month.raw
|
225
|
+
- spec/fixtures/traffic/post_with_two_subnets_and_no_ip_year.raw
|
215
226
|
- spec/fixtures/wol/get.raw
|
216
227
|
- spec/fixtures/wol/post.raw
|
217
228
|
- spec/hetzner_api_spec.rb
|