hetzner-api 1.0.0.alpha.1 → 1.0.0.alpha.2

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.
Files changed (45) hide show
  1. data/Gemfile.lock +1 -1
  2. data/bin/hetzner +11 -1
  3. data/features/hetzner.feature +2 -2
  4. data/features/support/env.rb +1 -0
  5. data/hetzner-api.gemspec +2 -2
  6. data/lib/hetzner/api/boot/plesk.rb +8 -0
  7. data/lib/hetzner/api/boot/rescue.rb +21 -0
  8. data/lib/hetzner/api/boot/vnc.rb +27 -0
  9. data/lib/hetzner/api/boot/windows.rb +22 -0
  10. data/lib/{hetzner-api → hetzner}/api/boot.rb +5 -0
  11. data/lib/{hetzner-api → hetzner}/api/cli.rb +6 -7
  12. data/lib/{hetzner-api → hetzner}/api/failover.rb +1 -1
  13. data/lib/hetzner/api/ip.rb +35 -0
  14. data/lib/{hetzner-api → hetzner}/api/rdns.rb +0 -0
  15. data/lib/{hetzner-api → hetzner}/api/reset.rb +0 -0
  16. data/lib/hetzner/api/server.rb +6 -0
  17. data/lib/hetzner/api/subnet.rb +6 -0
  18. data/lib/hetzner/api/traffic.rb +6 -0
  19. data/lib/hetzner/api/version.rb +5 -0
  20. data/lib/{hetzner-api → hetzner}/api/wol.rb +0 -0
  21. data/lib/hetzner-api.rb +20 -13
  22. data/spec/api_stubs.rb +74 -12
  23. data/spec/fixtures/boot/get_with_ip.raw +29 -0
  24. data/spec/fixtures/boot/rescue/delete.raw +12 -0
  25. data/spec/fixtures/boot/rescue/post.raw +12 -0
  26. data/spec/fixtures/boot/vnc/delete.raw +13 -0
  27. data/spec/fixtures/boot/vnc/get.raw +13 -0
  28. data/spec/fixtures/boot/vnc/post.raw +13 -0
  29. data/spec/fixtures/ip/get.raw +27 -0
  30. data/spec/fixtures/ip/get_with_ip.raw +14 -0
  31. data/spec/fixtures/ip/get_with_server_ip.raw +27 -0
  32. data/spec/fixtures/ip/post_activate_with_data.raw +14 -0
  33. data/spec/fixtures/ip/post_deactivate_with_data.raw +14 -0
  34. data/spec/fixtures/rdns/delete_with_ip.raw +3 -0
  35. data/spec/fixtures/rdns/get_with_ip.raw +9 -0
  36. data/spec/fixtures/rdns/post_with_ip.raw +9 -0
  37. data/spec/fixtures/wol/get.raw +9 -0
  38. data/spec/fixtures/wol/post.raw +9 -0
  39. data/spec/{hetzner_spec.rb → hetzner_api_spec.rb} +75 -21
  40. data/spec/spec_constants.rb +3 -1
  41. metadata +37 -15
  42. data/lib/hetzner-api/api/rescue.rb +0 -19
  43. data/lib/hetzner-api/api/vnc.rb +0 -25
  44. data/lib/hetzner-api/api/windows.rb +0 -20
  45. data/lib/hetzner-api/version.rb +0 -5
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- hetzner-api (1.0.0)
4
+ hetzner-api (1.0.0.alpha.1)
5
5
  httparty
6
6
  thor
7
7
 
data/bin/hetzner CHANGED
@@ -1,3 +1,13 @@
1
1
  #!/usr/bin/env ruby
2
- require 'hetzner-api'
2
+ require "rubygems"
3
+ require "bundler/setup"
4
+ require "hetzner-api"
5
+
6
+ if ENV['HETZNER_API_CUCUMBER_TEST']
7
+ puts 'testing mode'
8
+ require 'fakeweb'
9
+ require File.expand_path File.dirname(__FILE__) + '/../spec/spec_constants'
10
+ require File.expand_path File.dirname(__FILE__) + '/../spec/api_stubs'
11
+ end
12
+
3
13
  Hetzner::API::CLI.start
@@ -4,5 +4,5 @@ Feature: Hetzner
4
4
  I want to provider a decent, objective interface
5
5
 
6
6
  Scenario: Display boot options for one server
7
- When I run "hetzner boot show 78.46.50.215 --username --password "
8
- Then the output should contain "178.46.50.215"
7
+ When I run "hetzner boot get 11.11.11.111 --username='myusername' --password='mycoolpassword'"
8
+ Then the output should contain "11.11.11.111"
@@ -0,0 +1 @@
1
+ ENV['HETZNER_API_CUCUMBER_TEST'] = "1"
data/hetzner-api.gemspec CHANGED
@@ -1,9 +1,9 @@
1
1
  # -*- encoding: utf-8 -*-
2
- require File.expand_path("../lib/hetzner-api/version", __FILE__)
2
+ require File.expand_path("../lib/hetzner/api/version", __FILE__)
3
3
 
4
4
  Gem::Specification.new do |s|
5
5
  s.name = "hetzner-api"
6
- s.version = Hetzner::Api::VERSION
6
+ s.version = Hetzner::API::VERSION
7
7
  s.platform = Gem::Platform::RUBY
8
8
  s.authors = ['Roland Moriz']
9
9
  s.email = ['roland@moriz.de']
@@ -0,0 +1,8 @@
1
+ module Hetzner
2
+ class API
3
+ module Boot
4
+ module Plesk
5
+ end
6
+ end
7
+ end
8
+ end
@@ -0,0 +1,21 @@
1
+ module Hetzner
2
+ class API
3
+ module Boot
4
+ module Rescue
5
+ # enables the rescue systm for given IP address/server using <em>os</em> (operating system) and <em>arch</em> (architecture)
6
+ #
7
+ # see <em>boot?</em> method to query the API for available options
8
+ #
9
+ # defaults to 64bit Linux
10
+ def enable_rescue!(ip, os = 'linux', arch = '64')
11
+ perform_post "/boot/#{ip}/rescue", :query => { :os => os, :arch => arch }
12
+ end
13
+
14
+ # disables the rescue system for a given IP address/server
15
+ def disable_rescue!(ip)
16
+ perform_delete "/boot/#{ip}/rescue"
17
+ end
18
+ end
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,27 @@
1
+ module Hetzner
2
+ class API
3
+ module Boot
4
+ module VNC
5
+ # queries the vnc boot status of one IP address/server
6
+ def boot_vnc?(ip)
7
+ path = "/boot/#{ip}/vnc"
8
+ perform_get path
9
+ end
10
+
11
+ # enables vnc boot option for one IP address/server
12
+ #
13
+ # see <em>Boot</em> to query the API for available options
14
+ def boot_vnc!(ip, dist, arch, lang)
15
+ path = "/boot/#{ip}/vnc"
16
+ perform_post path, :query => { :dist => dist, :arch => arch, :lang => lang }
17
+ end
18
+
19
+ # disables the vnc boot status of one IP address/server
20
+ def disable_boot_vnc!(ip)
21
+ path = "/boot/#{ip}/vnc"
22
+ perform_delete path
23
+ end
24
+ end
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,22 @@
1
+ module Hetzner
2
+ class API
3
+ module Boot
4
+ module Windows
5
+ def boot_windows?(ip)
6
+ path = "/boot/#{ip}/windows"
7
+ perform_get path
8
+ end
9
+
10
+ def boot_windows!(ip, lan)
11
+ path = "/boot/#{ip}/windows"
12
+ perform_post path, :query => { :lang => lang }
13
+ end
14
+
15
+ def disable_boot_windows!(ip)
16
+ path = "/boot/#{ip}/windows"
17
+ perform_delete path
18
+ end
19
+ end
20
+ end
21
+ end
22
+ end
@@ -1,6 +1,11 @@
1
1
  module Hetzner
2
2
  class API
3
3
  module Boot
4
+ include Plesk
5
+ include Rescue
6
+ include VNC
7
+ include Windows
8
+
4
9
  # lists boot options for a given IP address/server or all servers of the account
5
10
  def boot?(ip = nil)
6
11
  path = "/boot"
@@ -15,13 +15,12 @@ module Hetzner
15
15
  def boot(action, ip = '')
16
16
  generate_api_instance
17
17
  case action
18
- when 'get'
19
- require_ip ip
20
- result = @api.boot?(ip)
21
- pp result.parsed_response
22
- #result.body.to_yaml
23
- else
24
- raise UnknownArgumentError, "'#{action}' is not a valid action!"
18
+ when 'get'
19
+ require_ip ip
20
+ result = @api.boot? ip
21
+ pp result.parsed_response
22
+ else
23
+ raise UnknownArgumentError, "'#{action}' is not a valid action!"
25
24
  end
26
25
  end
27
26
 
@@ -4,7 +4,7 @@ module Hetzner
4
4
  # queries the failover status of one IP address or all failover IP addresses of the account
5
5
  def failover?(ip = nil)
6
6
  path = "/failover"
7
- path << "/#{ip}" if @ip
7
+ path << "/#{ip}" if ip
8
8
  perform_get path
9
9
  end
10
10
 
@@ -0,0 +1,35 @@
1
+ module Hetzner
2
+ class API
3
+ module IP
4
+ # shows all addresses that belong to the main server IP
5
+ def ips_for_server?(server_ip)
6
+ path = "/ip"
7
+ perform_get path, :query => { :server_ip => server_ip }
8
+ end
9
+
10
+ # shows information of all IP addresses of the customer
11
+ def ips?
12
+ get_ip_or_ips
13
+ end
14
+
15
+ # shows information of a given IP addresses of the customer
16
+ def ip?(ip)
17
+ get_ip_or_ips ip
18
+ end
19
+
20
+ # sets or unsets traffic warning limits on a specific IP address
21
+ def ip!(ip, options = {})
22
+ path = "/ip/#{ip}"
23
+ perform_post path, :query => options
24
+ end
25
+
26
+ private
27
+
28
+ def get_ip_or_ips(ip = nil)
29
+ path = "/ip"
30
+ path << "/#{ip}" if ip
31
+ perform_get path
32
+ end
33
+ end
34
+ end
35
+ end
File without changes
File without changes
@@ -0,0 +1,6 @@
1
+ module Hetzner
2
+ class API
3
+ module Server
4
+ end
5
+ end
6
+ end
@@ -0,0 +1,6 @@
1
+ module Hetzner
2
+ class API
3
+ module Subnet
4
+ end
5
+ end
6
+ end
@@ -0,0 +1,6 @@
1
+ module Hetzner
2
+ class API
3
+ module Traffic
4
+ end
5
+ end
6
+ end
@@ -0,0 +1,5 @@
1
+ module Hetzner
2
+ class API
3
+ VERSION = "1.0.0.alpha.2"
4
+ end
5
+ end
File without changes
data/lib/hetzner-api.rb CHANGED
@@ -1,15 +1,21 @@
1
1
  require 'httparty'
2
- require 'forwardable'
2
+ #require 'forwardable'
3
3
 
4
- require 'hetzner-api/api/cli'
5
- require 'hetzner-api/api/boot'
6
- require 'hetzner-api/api/failover'
7
- require 'hetzner-api/api/rdns'
8
- require 'hetzner-api/api/rescue'
9
- require 'hetzner-api/api/reset'
10
- require 'hetzner-api/api/vnc'
11
- require 'hetzner-api/api/windows'
12
- require 'hetzner-api/api/wol'
4
+ require 'hetzner/api/cli'
5
+
6
+ require 'hetzner/api/failover'
7
+ require 'hetzner/api/rdns'
8
+ require 'hetzner/api/reset'
9
+ require 'hetzner/api/wol'
10
+ require 'hetzner/api/server'
11
+ require 'hetzner/api/ip'
12
+ require 'hetzner/api/subnet'
13
+ require 'hetzner/api/traffic'
14
+ require 'hetzner/api/boot/rescue'
15
+ require 'hetzner/api/boot/vnc'
16
+ require 'hetzner/api/boot/windows'
17
+ require 'hetzner/api/boot/plesk'
18
+ require 'hetzner/api/boot'
13
19
 
14
20
  module Hetzner
15
21
  class API
@@ -20,11 +26,12 @@ module Hetzner
20
26
  include Boot
21
27
  include Failover
22
28
  include Rdns
23
- include Rescue
24
29
  include Reset
25
- include VNC
26
- include Windows
27
30
  include WOL
31
+ include Server
32
+ include IP
33
+ include Subnet
34
+ include Traffic
28
35
 
29
36
  def initialize(username, password)
30
37
  @auth = {:username => username, :password => password}
data/spec/api_stubs.rb CHANGED
@@ -3,47 +3,109 @@ require 'fakeweb'
3
3
  @base_dir = File.dirname(__FILE__)
4
4
 
5
5
  def fixture(path)
6
- File.expand_path(@base_dir + '/fixtures/' + @resource + '/' + path)
6
+ file = File.expand_path(@base_dir + '/fixtures/' + @resource + '/' + path)
7
+ file
7
8
  end
8
9
 
9
- def uri(path = nil)
10
+ def uri(path = nil, args = nil)
10
11
  url = "https://#{API_USERNAME}:#{API_PASSWORD}@#{API_SERVER}/#{@resource}"
11
12
  url << "/#{path}" if path
13
+ url << "#{args}" if args
12
14
  url
13
15
  end
14
16
 
17
+
15
18
  FakeWeb.allow_net_connect = false
16
19
 
17
20
 
18
21
  @resource = 'reset'
19
22
 
20
- FakeWeb.register_uri :get, uri,
23
+ FakeWeb.register_uri :get, uri,
21
24
  :response => fixture('get.raw')
22
25
 
23
- FakeWeb.register_uri :get, uri("#{WORKING_IP}"),
26
+ FakeWeb.register_uri :get, uri("#{WORKING_IP}"),
24
27
  :response => fixture('get_with_ip.raw')
25
28
 
26
- FakeWeb.register_uri :get, uri("#{UNKOWN_IP}"),
29
+ FakeWeb.register_uri :get, uri("#{UNKOWN_IP}"),
27
30
  :response => fixture('get_with_ip_unknown.raw')
28
31
 
29
- FakeWeb.register_uri :get, uri("#{RESET_IP_NOT_AVAILABLE}"),
32
+ FakeWeb.register_uri :get, uri("#{RESET_IP_NOT_AVAILABLE}"),
30
33
  :response => fixture('get_with_ip_unavailable.raw')
31
34
 
32
-
33
- FakeWeb.register_uri :post, uri("#{WORKING_IP}?type=sw"),
35
+ FakeWeb.register_uri :post, uri("#{WORKING_IP}?type=sw"),
34
36
  :response => fixture('post_with_ip.raw')
35
37
 
36
- FakeWeb.register_uri :post, uri("#{WORKING_IP}?type=foo"),
38
+ FakeWeb.register_uri :post, uri("#{WORKING_IP}?type=foo"),
37
39
  :response => fixture('post_with_ip_invalid_input.raw')
38
40
 
39
- FakeWeb.register_uri :post, uri("#{RESET_IP_MANUAL_ACTIVE}?type=sw"),
41
+ FakeWeb.register_uri :post, uri("#{RESET_IP_MANUAL_ACTIVE}?type=sw"),
40
42
  :response => fixture('post_with_ip_manual_active.raw')
41
43
 
42
- FakeWeb.register_uri :post, uri("#{RESET_IP_NOT_AVAILABLE}?type=sw"),
44
+ FakeWeb.register_uri :post, uri("#{RESET_IP_NOT_AVAILABLE}?type=sw"),
43
45
  :response => fixture('post_with_ip_unavailable.raw')
44
46
 
45
- FakeWeb.register_uri :post, uri("#{UNKOWN_IP}?type=sw"),
47
+ FakeWeb.register_uri :post, uri("#{UNKOWN_IP}?type=sw"),
46
48
  :response => fixture('post_with_ip_unknown.raw')
47
49
 
48
50
 
51
+ @resource = 'boot'
52
+
53
+ FakeWeb.register_uri :get, uri("#{WORKING_IP}"),
54
+ :response => fixture('get_with_ip.raw')
55
+
56
+ FakeWeb.register_uri :post, uri("#{WORKING_IP}/rescue?arch=64&os=linux"),
57
+ :response => fixture('rescue/post.raw')
58
+
59
+ FakeWeb.register_uri :delete, uri("#{WORKING_IP}/rescue"),
60
+ :response => fixture('rescue/delete.raw')
61
+
62
+ FakeWeb.register_uri :get, uri("#{WORKING_IP}/vnc"),
63
+ :response => fixture('vnc/get.raw')
64
+
65
+ FakeWeb.register_uri :post, uri("#{WORKING_IP}/vnc?arch=32&lang=en_US&dist=Fedora-13"),
66
+ :response => fixture('vnc/post.raw')
67
+
68
+ FakeWeb.register_uri :delete, uri("#{WORKING_IP}/vnc"),
69
+ :response => fixture('vnc/delete.raw')
70
+
71
+
72
+ @resource = 'wol'
73
+
74
+ FakeWeb.register_uri :get, uri("#{WORKING_IP}"),
75
+ :response => fixture('get.raw')
76
+
77
+ FakeWeb.register_uri :post, uri("#{WORKING_IP}"),
78
+ :response => fixture('post.raw')
79
+
80
+
81
+ @resource = 'rdns'
82
+
83
+ FakeWeb.register_uri :get, uri("#{WORKING_IP}"),
84
+ :response => fixture('get_with_ip.raw')
85
+
86
+ FakeWeb.register_uri :post, uri("#{WORKING_IP}?ptr=testen.de"),
87
+ :response => fixture('post_with_ip.raw')
88
+
89
+ FakeWeb.register_uri :delete, uri("#{WORKING_IP}"),
90
+ :response => fixture('delete_with_ip.raw')
91
+
92
+
93
+ @resource = 'ip'
94
+
95
+ FakeWeb.register_uri :get, uri,
96
+ :response => fixture('get.raw')
97
+
98
+ FakeWeb.register_uri :get, uri(nil, "?server_ip=#{WORKING_IP}"),
99
+ :response => fixture('get_with_server_ip.raw')
100
+
101
+ FakeWeb.register_uri :get, uri("#{WORKING_IP}"),
102
+ :response => fixture('get_with_ip.raw')
103
+
104
+ FakeWeb.register_uri :post, uri("#{WORKING_IP}?traffic_warnings=true&traffic_monthly=2342"),
105
+ :response => fixture('post_activate_with_data.raw')
106
+
107
+ FakeWeb.register_uri :post, uri("#{WORKING_IP}?traffic_warnings=false"),
108
+ :response => fixture('post_deactivate_with_data.raw')
109
+
110
+
49
111
  #pp FakeWeb::Registry.instance.uri_map
@@ -0,0 +1,29 @@
1
+ HTTP/1.1 200 OK
2
+ Content-Type: application/json
3
+
4
+ {
5
+ "boot": {
6
+ "rescue": {
7
+ "server_ip" : "11.11.11.111",
8
+ "os": ["linux","freebsd","opensolaris","vkvm"],
9
+ "arch": [64,32],
10
+ "active": false,
11
+ "password": null
12
+ },
13
+ "vnc": {
14
+ "server_ip": "11.11.11.111",
15
+ "dist": ["centOS-5.0","Fedora-6","openSUSE-10.2"],
16
+ "arch": [64,32],
17
+ "lang": ["de_DE","en_US"],
18
+ "active": false,
19
+ "password": null
20
+ },
21
+ "windows": {
22
+ "server_ip": "11.11.11.111",
23
+ "dist": null,
24
+ "lang": null,
25
+ "active": false,
26
+ "password": null
27
+ }
28
+ }
29
+ }
@@ -0,0 +1,12 @@
1
+ HTTP/1.1 200 OK
2
+ Content-Type: application/json
3
+
4
+ {
5
+ "rescue": {
6
+ "server_ip": "123.123.123.123",
7
+ "os": ["linux","freebsd","opensolaris","vkvm"],
8
+ "arch": [64,32],
9
+ "active": false,
10
+ "password": null
11
+ }
12
+ }
@@ -0,0 +1,12 @@
1
+ HTTP/1.1 200 OK
2
+ Content-Type: application/json
3
+
4
+ {
5
+ "rescue": {
6
+ "server_ip": "11.11.11.111",
7
+ "os": ["linux","freebsd","opensolaris","vkvm"],
8
+ "arch": [64,32],
9
+ "active": false,
10
+ "password": null
11
+ }
12
+ }
@@ -0,0 +1,13 @@
1
+ HTTP/1.1 200 OK
2
+ Content-Type: application/json
3
+
4
+ {
5
+ "vnc": {
6
+ "server_ip": "11.11.11.111",
7
+ "dist": ["centOS-5.0","Fedora-6","openSUSE-10.2"],
8
+ "arch": [64,32],
9
+ "lang": ["de_DE","en_US"],
10
+ "active": false,
11
+ "password": null
12
+ }
13
+ }
@@ -0,0 +1,13 @@
1
+ HTTP/1.1 200 OK
2
+ Content-Type: application/json
3
+
4
+ {
5
+ "vnc": {
6
+ "server_ip": "11.11.11.111",
7
+ "dist": ["centOS-5.0","Fedora-6","openSUSE-10.2"],
8
+ "arch": [64,32],
9
+ "lang": ["de_DE","en_US"],
10
+ "active": false,
11
+ "password": null
12
+ }
13
+ }
@@ -0,0 +1,13 @@
1
+ HTTP/1.1 200 OK
2
+ Content-Type: application/json
3
+
4
+ {
5
+ "vnc": {
6
+ "server_ip": "11.11.11.111",
7
+ "dist": "Fedora-13",
8
+ "arch": 32,
9
+ "lang" : "en_US",
10
+ "active": true,
11
+ "password": "u7Ng5j43"
12
+ }
13
+ }
@@ -0,0 +1,27 @@
1
+ HTTP/1.1 200 OK
2
+ Content-Type: application/json
3
+
4
+ [
5
+ {
6
+ "ip": {
7
+ "ip":"11.11.11.111",
8
+ "server_ip": "11.11.11.111",
9
+ "locked": false,
10
+ "traffic_warnings": false,
11
+ "traffic_hourly": 50,
12
+ "traffic_daily": 50,
13
+ "traffic_monthly":8
14
+ }
15
+ },
16
+ {
17
+ "ip": {
18
+ "ip": "11.11.11.112",
19
+ "server_ip": "11.11.11.111",
20
+ "locked": false,
21
+ "traffic_warnings": false,
22
+ "traffic_hourly": 200,
23
+ "traffic_daily": 2000,
24
+ "traffic_monthly": 20
25
+ }
26
+ }
27
+ ]
@@ -0,0 +1,14 @@
1
+ HTTP/1.1 200 OK
2
+ Content-Type: application/json
3
+
4
+ {
5
+ "ip": {
6
+ "ip":"11.11.11.111",
7
+ "server_ip": "11.11.11.111",
8
+ "locked": false,
9
+ "traffic_warnings": false,
10
+ "traffic_hourly": 50,
11
+ "traffic_daily": 50,
12
+ "traffic_monthly": 8
13
+ }
14
+ }
@@ -0,0 +1,27 @@
1
+ HTTP/1.1 200 OK
2
+ Content-Type: application/json
3
+
4
+ [
5
+ {
6
+ "ip": {
7
+ "ip":"11.11.11.111",
8
+ "server_ip": "11.11.11.111",
9
+ "locked": false,
10
+ "traffic_warnings": false,
11
+ "traffic_hourly": 50,
12
+ "traffic_daily": 50,
13
+ "traffic_monthly":8
14
+ }
15
+ },
16
+ {
17
+ "ip": {
18
+ "ip": "11.11.11.112",
19
+ "server_ip": "11.11.11.111",
20
+ "locked": false,
21
+ "traffic_warnings": false,
22
+ "traffic_hourly": 200,
23
+ "traffic_daily": 2000,
24
+ "traffic_monthly": 20
25
+ }
26
+ }
27
+ ]
@@ -0,0 +1,14 @@
1
+ HTTP/1.1 200 OK
2
+ Content-Type: application/json
3
+
4
+ {
5
+ "ip": {
6
+ "ip":"11.11.11.111",
7
+ "server_ip": "11.11.11.111",
8
+ "locked": false,
9
+ "traffic_warnings": true,
10
+ "traffic_hourly": 50,
11
+ "traffic_daily": 50,
12
+ "traffic_monthly":8
13
+ }
14
+ }
@@ -0,0 +1,14 @@
1
+ HTTP/1.1 200 OK
2
+ Content-Type: application/json
3
+
4
+ {
5
+ "ip": {
6
+ "ip":"11.11.11.111",
7
+ "server_ip": "11.11.11.111",
8
+ "locked": false,
9
+ "traffic_warnings": false,
10
+ "traffic_hourly": 50,
11
+ "traffic_daily": 50,
12
+ "traffic_monthly":8
13
+ }
14
+ }
@@ -0,0 +1,3 @@
1
+ HTTP/1.1 200 OK
2
+ Content-Type: application/json
3
+
@@ -0,0 +1,9 @@
1
+ HTTP/1.1 200 OK
2
+ Content-Type: application/json
3
+
4
+ {
5
+ "rdns": {
6
+ "ip": "11.11.11.111",
7
+ "ptr": "testen.de"
8
+ }
9
+ }
@@ -0,0 +1,9 @@
1
+ HTTP/1.1 200 OK
2
+ Content-Type: application/json
3
+
4
+ {
5
+ "rdns": {
6
+ "ip": "11.11.11.111",
7
+ "ptr": "testen.de"
8
+ }
9
+ }
@@ -0,0 +1,9 @@
1
+ HTTP/1.1 200 OK
2
+ Content-Type: application/json
3
+
4
+ {
5
+ "wol":
6
+ {
7
+ "server_ip":"11.11.11.111"
8
+ }
9
+ }
@@ -0,0 +1,9 @@
1
+ HTTP/1.1 200 OK
2
+ Content-Type: application/json
3
+
4
+ {
5
+ "wol":
6
+ {
7
+ "server_ip":"11.11.11.111"
8
+ }
9
+ }
@@ -4,7 +4,7 @@ require 'spec_helper'
4
4
  describe "Reset" do
5
5
  describe "query" do
6
6
  before(:all) do
7
- @h = Hetzner::API.new(API_USERNAME, API_PASSWORD)
7
+ @h = Hetzner::API.new API_USERNAME, API_PASSWORD
8
8
  end
9
9
 
10
10
  it "should list available reset options for all servers" do
@@ -34,7 +34,7 @@ describe "Reset" do
34
34
 
35
35
  describe "execution" do
36
36
  before(:all) do
37
- @h = Hetzner::API.new(API_USERNAME, API_PASSWORD)
37
+ @h = Hetzner::API.new API_USERNAME, API_PASSWORD
38
38
  end
39
39
 
40
40
  it "should reset the specific IP" do
@@ -71,65 +71,71 @@ end
71
71
  describe "Boot" do
72
72
  describe "query boot configuration" do
73
73
  before(:all) do
74
- @h = Hetzner::API.new(USERNAME, PASSWORD)
74
+ @h = Hetzner::API.new API_USERNAME, API_PASSWORD
75
75
  end
76
-
76
+
77
77
  it "should display the boot configuration" do
78
78
  result = @h.boot? WORKING_IP
79
- result.should == {"boot"=>{"vnc"=>{"arch"=>[64, 32], "server_ip"=>WORKING_IP, "lang"=>["de_DE", "en_US", "fr_FR"], "dist"=>["centOS-5.3", "centOS-5.4", "centOS-5.5", "Fedora-11", "Fedora-12", "Fedora-13", "Fedora-9", "openSUSE-11.0", "openSUSE-11.1", "openSUSE-11.3"], "password"=>nil, "active"=>false}, "rescue"=>{"arch"=>[64, 32], "os"=>["linux", "freebsd", "opensolaris", "vkvm"], "server_ip"=>WORKING_IP, "password"=>nil, "active"=>false}, "windows"=>{"server_ip"=>WORKING_IP, "lang"=>nil, "dist"=>nil, "password"=>nil, "active"=>false}}}
79
+ result.response.should be_an_instance_of Net::HTTPOK
80
80
  end
81
81
  end
82
+
82
83
 
83
- describe "Rescue" do
84
+ describe "the rescue system" do
84
85
  before(:all) do
85
- @h = Hetzner::API.new(USERNAME, PASSWORD)
86
+ @h = Hetzner::API.new API_USERNAME, API_PASSWORD
86
87
  end
88
+
87
89
  it "should be able to activate" do
88
90
  result = @h.enable_rescue! WORKING_IP
89
-
91
+ result.response.should be_an_instance_of Net::HTTPOK
92
+
90
93
  # {"rescue"=>{"arch"=>64, "os"=>"linux", "server_ip"=>WORKING_IP, "password"=>"h9JbXPz8", "active"=>true}}
91
- result['rescue']['arch'].should == 64
92
- result['rescue']['os'].should == 'linux'
93
- result['rescue']['active'].should be_true
94
+ #result['rescue']['arch'].should == 64
95
+ #result['rescue']['os'].should == 'linux'
96
+ #result['rescue']['active'].should be_true
94
97
  end
95
-
98
+
96
99
  it "should be able to deactivate" do
97
100
  result = @h.disable_rescue! WORKING_IP
98
- result.should == {"rescue"=>{"arch"=>[64, 32], "os"=>["linux", "freebsd", "opensolaris", "vkvm"], "server_ip"=>WORKING_IP, "password"=>nil, "active"=>false}}
101
+ result.response.should be_an_instance_of Net::HTTPOK
99
102
  end
100
103
  end
101
104
  end
102
105
 
103
106
  describe "Rdns" do
104
107
  before(:all) do
105
- @h = Hetzner::API.new(USERNAME, PASSWORD)
108
+ @h = Hetzner::API.new API_USERNAME, API_PASSWORD
106
109
  end
107
110
 
108
111
  it "should query the current rdns status" do
109
112
  result = @h.rdns? WORKING_IP
113
+ result.response.should be_an_instance_of Net::HTTPOK
110
114
  result['rdns']['ip'].should == WORKING_IP
111
115
  result['rdns']['ptr'].should == TEST_PTR
112
116
  end
113
117
 
114
118
  it "should be able to set a new ptr" do
115
- result = @h.rdns! RDNS_WORKING_IP, 'testen.de'
116
- result['rdns']['ip'].should == RDNS_WORKING_IP
117
- result['rdns']['ptr'].should == 'testen.de'
119
+ result = @h.rdns! WORKING_IP, TEST_PTR
120
+ result.response.should be_an_instance_of Net::HTTPOK
121
+ result['rdns']['ip'].should == WORKING_IP
122
+ result['rdns']['ptr'].should == TEST_PTR
118
123
  end
119
124
 
120
125
  it "should be able to remove a new ptr" do
121
- result = @h.delete_rdns! RDNS_WORKING_IP
122
- puts result
126
+ result = @h.delete_rdns! WORKING_IP
127
+ result.response.should be_an_instance_of Net::HTTPOK
123
128
  end
124
129
  end
125
130
 
126
131
  describe "VNC" do
127
132
  before(:all) do
128
- @h = Hetzner::API.new(USERNAME, PASSWORD)
133
+ @h = Hetzner::API.new API_USERNAME, API_PASSWORD
129
134
  end
130
135
 
131
136
  it "should be able to query vnc boot status" do
132
137
  result = @h.boot_vnc? WORKING_IP
138
+ result.response.should be_an_instance_of Net::HTTPOK
133
139
  result['vnc']['server_ip'].should == WORKING_IP
134
140
  result['vnc']['active'].should be_false
135
141
  result['vnc']['password'].should be_nil
@@ -137,6 +143,7 @@ describe "VNC" do
137
143
 
138
144
  it "should be able to set vnc boot status" do
139
145
  result = @h.boot_vnc! WORKING_IP, 'Fedora-13', '32', 'en_US'
146
+ result.response.should be_an_instance_of Net::HTTPOK
140
147
  result['vnc']['server_ip'].should == WORKING_IP
141
148
  result['vnc']['active'].should be_true
142
149
  result['vnc']['password'].should_not be_nil
@@ -144,6 +151,7 @@ describe "VNC" do
144
151
 
145
152
  it "should be able to disable vnc boot status" do
146
153
  result = @h.disable_boot_vnc! WORKING_IP
154
+ result.response.should be_an_instance_of Net::HTTPOK
147
155
  result['vnc']['server_ip'].should == WORKING_IP
148
156
  result['vnc']['active'].should be_false
149
157
  result['vnc']['password'].should be_nil
@@ -152,16 +160,62 @@ end
152
160
 
153
161
  describe "WOL" do
154
162
  before(:all) do
155
- @h = Hetzner::API.new(USERNAME, PASSWORD)
163
+ @h = Hetzner::API.new API_USERNAME, API_PASSWORD
156
164
  end
157
165
 
158
166
  it "should be able to query WOL status" do
159
167
  result = @h.wol? WORKING_IP
168
+ result.response.should be_an_instance_of Net::HTTPOK
160
169
  result['wol']['server_ip'].should == WORKING_IP
161
170
  end
162
171
 
163
172
  it "should be able to send a WOL notification" do
164
173
  result = @h.wol! WORKING_IP
174
+ result.response.should be_an_instance_of Net::HTTPOK
165
175
  result['wol']['server_ip'].should == WORKING_IP
166
176
  end
167
177
  end
178
+
179
+ describe 'IP' do
180
+ describe "information" do
181
+ before(:all) do
182
+ @h = Hetzner::API.new API_USERNAME, API_PASSWORD
183
+ end
184
+ it "should be able to display all IP addresses of the customer account" do
185
+ result = @h.ips?
186
+ result.response.should be_an_instance_of Net::HTTPOK
187
+ result.parsed_response.should have_at_least(2).entries
188
+ end
189
+
190
+ it "should be able to display a IP address of the customer account" do
191
+ result = @h.ip? WORKING_IP
192
+ result.response.should be_an_instance_of Net::HTTPOK
193
+ result.parsed_response.should have(1).entry
194
+ end
195
+
196
+ it "should be able to display all IP addresses for a given server IP address" do
197
+ result = @h.ips_for_server? WORKING_IP
198
+ result.response.should be_an_instance_of Net::HTTPOK
199
+ result.parsed_response.should have(2).entry
200
+ end
201
+ end
202
+
203
+ describe "manage traffic warnings" do
204
+ before(:all) do
205
+ @h = Hetzner::API.new API_USERNAME, API_PASSWORD
206
+ end
207
+
208
+ it "should be able to activate and set traffic warning limits on a specific IP address" do
209
+ result = @h.ip! WORKING_IP, :traffic_warnings => 'true', :traffic_monthly => TRAFFIC_LIMIT_IN_GIGABYTE
210
+ result.response.should be_an_instance_of Net::HTTPOK
211
+ result.parsed_response.should have(1).entry
212
+ end
213
+
214
+ it "should be able to deactivate traffic warnings for a specific IP address" do
215
+ result = @h.ip! WORKING_IP, :traffic_warnings => 'false'
216
+ result.response.should be_an_instance_of Net::HTTPOK
217
+ result.parsed_response.should have(1).entry
218
+ end
219
+ end
220
+ end
221
+
@@ -5,9 +5,11 @@ RESET_IP_NOT_AVAILABLE = '11.11.11.223'
5
5
  RESET_IP_MANUAL_ACTIVE = '11.11.11.224'
6
6
  RESET_IP_FAILED = '11.11.11.225'
7
7
 
8
- TEST_PTR = ''
8
+ TEST_PTR = 'testen.de'
9
9
  RDNS_TEST_IP = ''
10
10
 
11
+ TRAFFIC_LIMIT_IN_GIGABYTE = 2342
12
+
11
13
  API_SERVER = 'robot-ws.your-server.de'
12
14
  API_USERNAME = 'myusername'
13
15
  API_PASSWORD = 'mycoolpassword'
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: -3702664322
4
+ hash: -3702664328
5
5
  prerelease: true
6
6
  segments:
7
7
  - 1
8
8
  - 0
9
9
  - 0
10
10
  - alpha
11
- - 1
12
- version: 1.0.0.alpha.1
11
+ - 2
12
+ version: 1.0.0.alpha.2
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-07 00:00:00 +02:00
20
+ date: 2010-10-08 00:00:00 +02:00
21
21
  default_executable:
22
22
  dependencies:
23
23
  - !ruby/object:Gem::Dependency
@@ -169,20 +169,40 @@ files:
169
169
  - bin/hetzner
170
170
  - cucumber.yml
171
171
  - features/hetzner.feature
172
+ - features/support/env.rb
172
173
  - features/support/setup.rb
173
174
  - hetzner-api.gemspec
174
175
  - lib/hetzner-api.rb
175
- - lib/hetzner-api/api/boot.rb
176
- - lib/hetzner-api/api/cli.rb
177
- - lib/hetzner-api/api/failover.rb
178
- - lib/hetzner-api/api/rdns.rb
179
- - lib/hetzner-api/api/rescue.rb
180
- - lib/hetzner-api/api/reset.rb
181
- - lib/hetzner-api/api/vnc.rb
182
- - lib/hetzner-api/api/windows.rb
183
- - lib/hetzner-api/api/wol.rb
184
- - lib/hetzner-api/version.rb
176
+ - lib/hetzner/api/boot.rb
177
+ - lib/hetzner/api/boot/plesk.rb
178
+ - lib/hetzner/api/boot/rescue.rb
179
+ - lib/hetzner/api/boot/vnc.rb
180
+ - lib/hetzner/api/boot/windows.rb
181
+ - lib/hetzner/api/cli.rb
182
+ - lib/hetzner/api/failover.rb
183
+ - lib/hetzner/api/ip.rb
184
+ - lib/hetzner/api/rdns.rb
185
+ - lib/hetzner/api/reset.rb
186
+ - lib/hetzner/api/server.rb
187
+ - lib/hetzner/api/subnet.rb
188
+ - lib/hetzner/api/traffic.rb
189
+ - lib/hetzner/api/version.rb
190
+ - lib/hetzner/api/wol.rb
185
191
  - spec/api_stubs.rb
192
+ - spec/fixtures/boot/get_with_ip.raw
193
+ - spec/fixtures/boot/rescue/delete.raw
194
+ - spec/fixtures/boot/rescue/post.raw
195
+ - spec/fixtures/boot/vnc/delete.raw
196
+ - spec/fixtures/boot/vnc/get.raw
197
+ - spec/fixtures/boot/vnc/post.raw
198
+ - spec/fixtures/ip/get.raw
199
+ - spec/fixtures/ip/get_with_ip.raw
200
+ - spec/fixtures/ip/get_with_server_ip.raw
201
+ - spec/fixtures/ip/post_activate_with_data.raw
202
+ - spec/fixtures/ip/post_deactivate_with_data.raw
203
+ - spec/fixtures/rdns/delete_with_ip.raw
204
+ - spec/fixtures/rdns/get_with_ip.raw
205
+ - spec/fixtures/rdns/post_with_ip.raw
186
206
  - spec/fixtures/reset/get.raw
187
207
  - spec/fixtures/reset/get_with_ip.raw
188
208
  - spec/fixtures/reset/get_with_ip_unavailable.raw
@@ -192,7 +212,9 @@ files:
192
212
  - spec/fixtures/reset/post_with_ip_manual_active.raw
193
213
  - spec/fixtures/reset/post_with_ip_unavailable.raw
194
214
  - spec/fixtures/reset/post_with_ip_unknown.raw
195
- - spec/hetzner_spec.rb
215
+ - spec/fixtures/wol/get.raw
216
+ - spec/fixtures/wol/post.raw
217
+ - spec/hetzner_api_spec.rb
196
218
  - spec/spec_constants.rb
197
219
  - spec/spec_helper.rb
198
220
  has_rdoc: true
@@ -1,19 +0,0 @@
1
- module Hetzner
2
- class API
3
- module Rescue
4
- # enables the rescue systm for given IP address/server using <em>os</em> (operating system) and <em>arch</em> (architecture)
5
- #
6
- # see <em>boot?</em> method to query the API for available options
7
- #
8
- # defaults to 64bit Linux
9
- def enable_rescue!(ip, os = 'linux', arch = '64')
10
- perform_post "/boot/#{ip}/rescue", :query => { :os => os, :arch => arch }
11
- end
12
-
13
- # disables the rescue system for a given IP address/server
14
- def disable_rescue!(ip)
15
- perform_delete "/boot/#{ip}/rescue"
16
- end
17
- end
18
- end
19
- end
@@ -1,25 +0,0 @@
1
- module Hetzner
2
- class API
3
- module VNC
4
- # queries the vnc boot status of one IP address/server
5
- def boot_vnc?(ip)
6
- path = "/boot/#{ip}/vnc"
7
- perform_get path
8
- end
9
-
10
- # enables vnc boot option for one IP address/server
11
- #
12
- # see <em>Boot</em> to query the API for available options
13
- def boot_vnc!(ip, dist, arch, lang)
14
- path = "/boot/#{ip}/vnc"
15
- perform_post path, :query => { :dist => dist, :arch => arch, :lang => lang }
16
- end
17
-
18
- # disables the vnc boot status of one IP address/server
19
- def disable_boot_vnc!(ip)
20
- path = "/boot/#{ip}/vnc"
21
- perform_delete path
22
- end
23
- end
24
- end
25
- end
@@ -1,20 +0,0 @@
1
- module Hetzner
2
- class API
3
- module Windows
4
- def boot_windows?(ip)
5
- path = "/boot/#{ip}/windows"
6
- perform_get path
7
- end
8
-
9
- def boot_windows!(ip, lan)
10
- path = "/boot/#{ip}/windows"
11
- perform_post path, :query => { :lang => lang }
12
- end
13
-
14
- def disable_boot_windows!(ip)
15
- path = "/boot/#{ip}/windows"
16
- perform_delete path
17
- end
18
- end
19
- end
20
- end
@@ -1,5 +0,0 @@
1
- module Hetzner
2
- class Api
3
- VERSION = "1.0.0.alpha.1"
4
- end
5
- end