hetzner-api 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/.document ADDED
@@ -0,0 +1,5 @@
1
+ README.rdoc
2
+ lib/**/*.rb
3
+ bin/*
4
+ features/**/*.feature
5
+ LICENSE
data/.gitignore ADDED
@@ -0,0 +1,21 @@
1
+ ## MAC OS
2
+ .DS_Store
3
+
4
+ ## TEXTMATE
5
+ *.tmproj
6
+ tmtags
7
+
8
+ ## EMACS
9
+ *~
10
+ \#*
11
+ .\#*
12
+
13
+ ## VIM
14
+ *.swp
15
+
16
+ ## PROJECT::GENERAL
17
+ coverage
18
+ rdoc
19
+ pkg
20
+
21
+ ## PROJECT::SPECIFIC
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2010 Roland Moriz
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.rdoc ADDED
@@ -0,0 +1,13 @@
1
+ = hetzner-api
2
+
3
+ A HTTParty based wrapper for Hetzner.de's server management interface.
4
+ see http://wiki.hetzner.de/index.php/Robot_Webservice for details.
5
+
6
+ This is not an official Hetzner AG software!
7
+ The gem and the author are not related to Hetzner AG!
8
+
9
+ <b>Use at your very own risk! Satisfaction NOT guaranteed!</b>
10
+
11
+ == Copyright
12
+
13
+ Copyright (c) 2010 Roland Moriz. See LICENSE for details.
data/Rakefile ADDED
@@ -0,0 +1,44 @@
1
+ require 'rubygems'
2
+ require 'rake'
3
+
4
+ begin
5
+ require 'jeweler'
6
+ Jeweler::Tasks.new do |gem|
7
+ gem.name = "hetzner-api"
8
+ gem.summary = %Q{A small, unofficial wrapper for Hetzner.de's API (server management)}
9
+ gem.description = %Q{A small, unofficial wrapper for Hetzner.de's API (server management)}
10
+ gem.email = "roland@rails.io"
11
+ gem.homepage = "http://github.com/rmoriz/hetzner-api"
12
+ gem.authors = ["Roland Moriz"]
13
+ gem.add_development_dependency "rspec", ">= 1.2.9"
14
+ end
15
+ Jeweler::GemcutterTasks.new
16
+ rescue LoadError
17
+ puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
18
+ end
19
+
20
+ require 'spec/rake/spectask'
21
+ Spec::Rake::SpecTask.new(:spec) do |spec|
22
+ spec.libs << 'lib' << 'spec'
23
+ spec.spec_files = FileList['spec/**/*_spec.rb']
24
+ end
25
+
26
+ Spec::Rake::SpecTask.new(:rcov) do |spec|
27
+ spec.libs << 'lib' << 'spec'
28
+ spec.pattern = 'spec/**/*_spec.rb'
29
+ spec.rcov = true
30
+ end
31
+
32
+ task :spec => :check_dependencies
33
+
34
+ task :default => :spec
35
+
36
+ require 'rake/rdoctask'
37
+ Rake::RDocTask.new do |rdoc|
38
+ version = File.exist?('VERSION') ? File.read('VERSION') : ""
39
+
40
+ rdoc.rdoc_dir = 'rdoc'
41
+ rdoc.title = "hetzner #{version}"
42
+ rdoc.rdoc_files.include('README*')
43
+ rdoc.rdoc_files.include('lib/**/*.rb')
44
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.0.1
@@ -0,0 +1,63 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = %q{hetzner-api}
8
+ s.version = "0.0.1"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["Roland Moriz"]
12
+ s.date = %q{2010-09-02}
13
+ s.description = %q{A small, unofficial wrapper for Hetzner.de's API (server management)}
14
+ s.email = %q{roland@rails.io}
15
+ s.extra_rdoc_files = [
16
+ "LICENSE",
17
+ "README.rdoc"
18
+ ]
19
+ s.files = [
20
+ ".document",
21
+ ".gitignore",
22
+ "LICENSE",
23
+ "README.rdoc",
24
+ "Rakefile",
25
+ "VERSION",
26
+ "hetzner-api.gemspec",
27
+ "lib/api/boot.rb",
28
+ "lib/api/failover.rb",
29
+ "lib/api/rdns.rb",
30
+ "lib/api/rescue.rb",
31
+ "lib/api/reset.rb",
32
+ "lib/api/vnc.rb",
33
+ "lib/api/windows.rb",
34
+ "lib/api/wol.rb",
35
+ "lib/hetzner-api.rb",
36
+ "spec/hetzner_spec.rb",
37
+ "spec/spec.opts",
38
+ "spec/spec_helper.rb"
39
+ ]
40
+ s.homepage = %q{http://github.com/rmoriz/hetzner-api}
41
+ s.rdoc_options = ["--charset=UTF-8"]
42
+ s.require_paths = ["lib"]
43
+ s.rubygems_version = %q{1.3.6}
44
+ s.summary = %q{A small, unofficial wrapper for Hetzner.de's API (server management)}
45
+ s.test_files = [
46
+ "spec/hetzner_spec.rb",
47
+ "spec/spec_helper.rb"
48
+ ]
49
+
50
+ if s.respond_to? :specification_version then
51
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
52
+ s.specification_version = 3
53
+
54
+ if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
55
+ s.add_development_dependency(%q<rspec>, [">= 1.2.9"])
56
+ else
57
+ s.add_dependency(%q<rspec>, [">= 1.2.9"])
58
+ end
59
+ else
60
+ s.add_dependency(%q<rspec>, [">= 1.2.9"])
61
+ end
62
+ end
63
+
data/lib/api/boot.rb ADDED
@@ -0,0 +1,11 @@
1
+ module Hetzner
2
+ class API
3
+ module Boot
4
+ def boot?(ip = nil)
5
+ path = "/boot"
6
+ path << "/#{ip}" if ip
7
+ perform_get path
8
+ end
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,16 @@
1
+ module Hetzner
2
+ class API
3
+ module Failover
4
+ def failover?(ip = nil)
5
+ path = "/failover"
6
+ path << "/#{ip}" if @ip
7
+ perform_get path
8
+ end
9
+
10
+ def failover!(failover_ip, active_server_ip)
11
+ path = "/rdns/#{failover_ip}"
12
+ perform_post path, :query => { :active_server_ip => active_server_ip }
13
+ end
14
+ end
15
+ end
16
+ end
data/lib/api/rdns.rb ADDED
@@ -0,0 +1,25 @@
1
+ module Hetzner
2
+ class API
3
+ module Rdns
4
+ def rdns?(ip)
5
+ path = "/rdns/#{ip}"
6
+ perform_get path
7
+ end
8
+
9
+ def rdns!(ip, ptr)
10
+ path = "/rdns/#{ip}"
11
+ perform_post path, :query => { :ptr => ptr }
12
+ end
13
+
14
+ def initialize_rdns!(ip, ptr)
15
+ path = "/rdns/#{ip}"
16
+ perform_put path, :query => { :ptr => ptr }
17
+ end
18
+
19
+ def delete_rdns!(ip)
20
+ path = "/rdns/#{ip}"
21
+ perform_delete path
22
+ end
23
+ end
24
+ end
25
+ end
data/lib/api/rescue.rb ADDED
@@ -0,0 +1,13 @@
1
+ module Hetzner
2
+ class API
3
+ module Rescue
4
+ def enable_rescue!(ip, os = 'linux', arch = '64')
5
+ perform_post "/boot/#{ip}/rescue", :query => { :os => os, :arch => arch }
6
+ end
7
+
8
+ def disable_rescue!(ip)
9
+ perform_delete "/boot/#{ip}/rescue"
10
+ end
11
+ end
12
+ end
13
+ end
data/lib/api/reset.rb ADDED
@@ -0,0 +1,15 @@
1
+ module Hetzner
2
+ class API
3
+ module Reset
4
+ def reset?(ip = nil)
5
+ path = "/reset"
6
+ path << "/#{ip}" if ip
7
+ perform_get path
8
+ end
9
+
10
+ def reset!(ip, type)
11
+ perform_post "/reset/#{ip}", :query => { :type => type }
12
+ end
13
+ end
14
+ end
15
+ end
data/lib/api/vnc.rb ADDED
@@ -0,0 +1,20 @@
1
+ module Hetzner
2
+ class API
3
+ module VNC
4
+ def boot_vnc?(ip)
5
+ path = "/boot/#{ip}/vnc"
6
+ perform_get path
7
+ end
8
+
9
+ def boot_vnc!(ip, dist, arch, lang)
10
+ path = "/boot/#{ip}/vnc"
11
+ perform_post path, :query => { :dist => dist, :arch => arch, :lang => lang }
12
+ end
13
+
14
+ def disable_boot_vnc!(ip)
15
+ path = "/boot/#{ip}/vnc"
16
+ perform_delete path
17
+ end
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,20 @@
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
data/lib/api/wol.rb ADDED
@@ -0,0 +1,14 @@
1
+ module Hetzner
2
+ class API
3
+ module WOL
4
+ def wol?(ip)
5
+ path = "/wol/#{ip}"
6
+ perform_get path
7
+ end
8
+ def wol!(ip)
9
+ path = "/wol/#{ip}"
10
+ perform_post path
11
+ end
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,55 @@
1
+ require 'httparty'
2
+ require 'forwardable'
3
+
4
+ require 'api/boot'
5
+ require 'api/failover'
6
+ require 'api/rdns'
7
+ require 'api/rescue'
8
+ require 'api/reset'
9
+ require 'api/vnc'
10
+ require 'api/windows'
11
+ require 'api/wol'
12
+
13
+ module Hetzner
14
+ class API
15
+ include ::HTTParty
16
+ format :json
17
+ base_uri 'https://robot-ws.your-server.de'
18
+
19
+ include Boot
20
+ include Failover
21
+ include Rdns
22
+ include Rescue
23
+ include Reset
24
+ include VNC
25
+ include Windows
26
+ include WOL
27
+
28
+ def initialize(username, password)
29
+ @auth = {:username => username, :password => password}
30
+ end
31
+
32
+ private
33
+
34
+ def perform_get(path, options = {})
35
+ options.merge!({:basic_auth => @auth})
36
+ Hetzner::API.get path, options
37
+ end
38
+
39
+ def perform_post(path, options = {})
40
+ options.merge!({:basic_auth => @auth})
41
+ options[:headers] = { 'Content-Type' => 'application/x-www-form-urlencoded' }
42
+ Hetzner::API.post path, options
43
+ end
44
+
45
+ def perform_delete(path, options = {})
46
+ options.merge!({:basic_auth => @auth})
47
+ Hetzner::API.delete path, options
48
+ end
49
+
50
+ def perform_put(path, options = {})
51
+ options.merge!({:basic_auth => @auth})
52
+ Hetzner::API.put path, options
53
+ end
54
+ end
55
+ end
@@ -0,0 +1,139 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
+
3
+ TEST_IP = ''
4
+ TEST_PTR = ''
5
+ RDNS_TEST_IP = ''
6
+ USERNAME = ''
7
+ PASSWORD = ''
8
+
9
+ describe "Reset" do
10
+ describe "query status" do
11
+ before(:all) do
12
+ @h = Hetzner::API.new(USERNAME, PASSWORD)
13
+ end
14
+
15
+ it "should list available reset options" do
16
+ result = @h.reset?
17
+ result.should == [{"reset"=>{"server_ip"=>TEST_IP, "type"=>["man", "hw", "sw"]}}]
18
+ end
19
+
20
+ it "should list available reset options" do
21
+ result = @h.reset? TEST_IP
22
+ result.should == {"reset"=>{"server_ip"=>TEST_IP, "type"=>["man", "hw", "sw"]}}
23
+ end
24
+
25
+ it "should fail on a unknown ip" do
26
+ result = @h.reset? "127.0.0.1"
27
+ result['error']['status'].should == 404
28
+ end
29
+ end
30
+
31
+ describe "do reset" do
32
+ before(:all) do
33
+ @h = Hetzner::API.new(USERNAME, PASSWORD)
34
+ end
35
+
36
+ it "should reset the server" do
37
+ result = @h.reset! "123.123.123.223", :sw
38
+ result.should == { "reset"=> {"server_ip"=>"123.123.123.123", "type"=> "sw" } }
39
+ end
40
+ end
41
+ end
42
+
43
+ describe "Boot" do
44
+ describe "query boot configuration" do
45
+ before(:all) do
46
+ @h = Hetzner::API.new(USERNAME, PASSWORD)
47
+ end
48
+
49
+ it "should display the boot configuration" do
50
+ result = @h.boot? TEST_IP
51
+ result.should == {"boot"=>{"vnc"=>{"arch"=>[64, 32], "server_ip"=>TEST_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"=>TEST_IP, "password"=>nil, "active"=>false}, "windows"=>{"server_ip"=>TEST_IP, "lang"=>nil, "dist"=>nil, "password"=>nil, "active"=>false}}}
52
+ end
53
+ end
54
+
55
+ describe "Rescue" do
56
+ before(:all) do
57
+ @h = Hetzner::API.new(USERNAME, PASSWORD)
58
+ end
59
+ it "should be able to activate" do
60
+ result = @h.enable_rescue! TEST_IP
61
+
62
+ # {"rescue"=>{"arch"=>64, "os"=>"linux", "server_ip"=>TEST_IP, "password"=>"h9JbXPz8", "active"=>true}}
63
+ result['rescue']['arch'].should == 64
64
+ result['rescue']['os'].should == 'linux'
65
+ result['rescue']['active'].should be_true
66
+ end
67
+
68
+ it "should be able to deactivate" do
69
+ result = @h.disable_rescue! TEST_IP
70
+ result.should == {"rescue"=>{"arch"=>[64, 32], "os"=>["linux", "freebsd", "opensolaris", "vkvm"], "server_ip"=>TEST_IP, "password"=>nil, "active"=>false}}
71
+ end
72
+ end
73
+ end
74
+
75
+ describe "Rdns" do
76
+ before(:all) do
77
+ @h = Hetzner::API.new(USERNAME, PASSWORD)
78
+ end
79
+
80
+ it "should query the current rdns status" do
81
+ result = @h.rdns? TEST_IP
82
+ result['rdns']['ip'].should == TEST_IP
83
+ result['rdns']['ptr'].should == TEST_PTR
84
+ end
85
+
86
+ it "should be able to set a new ptr" do
87
+ result = @h.rdns! RDNS_TEST_IP, 'testen.de'
88
+ result['rdns']['ip'].should == RDNS_TEST_IP
89
+ result['rdns']['ptr'].should == 'testen.de'
90
+ end
91
+
92
+ it "should be able to remove a new ptr" do
93
+ result = @h.delete_rdns! RDNS_TEST_IP
94
+ puts result
95
+ end
96
+ end
97
+
98
+ describe "VNC" do
99
+ before(:all) do
100
+ @h = Hetzner::API.new(USERNAME, PASSWORD)
101
+ end
102
+
103
+ it "should be able to query vnc boot status" do
104
+ result = @h.boot_vnc? TEST_IP
105
+ result['vnc']['server_ip'].should == TEST_IP
106
+ result['vnc']['active'].should be_false
107
+ result['vnc']['password'].should be_nil
108
+ end
109
+
110
+ it "should be able to set vnc boot status" do
111
+ result = @h.boot_vnc! TEST_IP, 'Fedora-13', '32', 'en_US'
112
+ result['vnc']['server_ip'].should == TEST_IP
113
+ result['vnc']['active'].should be_true
114
+ result['vnc']['password'].should_not be_nil
115
+ end
116
+
117
+ it "should be able to disable vnc boot status" do
118
+ result = @h.disable_boot_vnc! TEST_IP
119
+ result['vnc']['server_ip'].should == TEST_IP
120
+ result['vnc']['active'].should be_false
121
+ result['vnc']['password'].should be_nil
122
+ end
123
+ end
124
+
125
+ describe "WOL" do
126
+ before(:all) do
127
+ @h = Hetzner::API.new(USERNAME, PASSWORD)
128
+ end
129
+
130
+ it "should be able to query WOL status" do
131
+ result = @h.wol? TEST_IP
132
+ result['wol']['server_ip'].should == TEST_IP
133
+ end
134
+
135
+ it "should be able to send a WOL notification" do
136
+ result = @h.wol! TEST_IP
137
+ result['wol']['server_ip'].should == TEST_IP
138
+ end
139
+ end
data/spec/spec.opts ADDED
@@ -0,0 +1 @@
1
+ --color
@@ -0,0 +1,11 @@
1
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
2
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
3
+
4
+ require 'rubygems'
5
+ require 'hetzner'
6
+ require 'spec'
7
+ require 'spec/autorun'
8
+
9
+ Spec::Runner.configure do |config|
10
+
11
+ end
metadata ADDED
@@ -0,0 +1,95 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: hetzner-api
3
+ version: !ruby/object:Gem::Version
4
+ prerelease: false
5
+ segments:
6
+ - 0
7
+ - 0
8
+ - 1
9
+ version: 0.0.1
10
+ platform: ruby
11
+ authors:
12
+ - Roland Moriz
13
+ autorequire:
14
+ bindir: bin
15
+ cert_chain: []
16
+
17
+ date: 2010-09-02 00:00:00 +02:00
18
+ default_executable:
19
+ dependencies:
20
+ - !ruby/object:Gem::Dependency
21
+ name: rspec
22
+ prerelease: false
23
+ requirement: &id001 !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - ">="
26
+ - !ruby/object:Gem::Version
27
+ segments:
28
+ - 1
29
+ - 2
30
+ - 9
31
+ version: 1.2.9
32
+ type: :development
33
+ version_requirements: *id001
34
+ description: A small, unofficial wrapper for Hetzner.de's API (server management)
35
+ email: roland@rails.io
36
+ executables: []
37
+
38
+ extensions: []
39
+
40
+ extra_rdoc_files:
41
+ - LICENSE
42
+ - README.rdoc
43
+ files:
44
+ - .document
45
+ - .gitignore
46
+ - LICENSE
47
+ - README.rdoc
48
+ - Rakefile
49
+ - VERSION
50
+ - hetzner-api.gemspec
51
+ - lib/api/boot.rb
52
+ - lib/api/failover.rb
53
+ - lib/api/rdns.rb
54
+ - lib/api/rescue.rb
55
+ - lib/api/reset.rb
56
+ - lib/api/vnc.rb
57
+ - lib/api/windows.rb
58
+ - lib/api/wol.rb
59
+ - lib/hetzner-api.rb
60
+ - spec/hetzner_spec.rb
61
+ - spec/spec.opts
62
+ - spec/spec_helper.rb
63
+ has_rdoc: true
64
+ homepage: http://github.com/rmoriz/hetzner-api
65
+ licenses: []
66
+
67
+ post_install_message:
68
+ rdoc_options:
69
+ - --charset=UTF-8
70
+ require_paths:
71
+ - lib
72
+ required_ruby_version: !ruby/object:Gem::Requirement
73
+ requirements:
74
+ - - ">="
75
+ - !ruby/object:Gem::Version
76
+ segments:
77
+ - 0
78
+ version: "0"
79
+ required_rubygems_version: !ruby/object:Gem::Requirement
80
+ requirements:
81
+ - - ">="
82
+ - !ruby/object:Gem::Version
83
+ segments:
84
+ - 0
85
+ version: "0"
86
+ requirements: []
87
+
88
+ rubyforge_project:
89
+ rubygems_version: 1.3.6
90
+ signing_key:
91
+ specification_version: 3
92
+ summary: A small, unofficial wrapper for Hetzner.de's API (server management)
93
+ test_files:
94
+ - spec/hetzner_spec.rb
95
+ - spec/spec_helper.rb