profitbricks 0.0.5 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (47) hide show
  1. data/CHANGELOG.md +7 -0
  2. data/Manifest.txt +37 -0
  3. data/README.md +1 -5
  4. data/lib/profitbricks/data_center.rb +1 -0
  5. data/lib/profitbricks/firewall.rb +76 -0
  6. data/lib/profitbricks/ip_block.rb +1 -1
  7. data/lib/profitbricks/load_balancer.rb +127 -0
  8. data/lib/profitbricks/model.rb +23 -11
  9. data/lib/profitbricks/nic.rb +2 -2
  10. data/lib/profitbricks/profitbricks.rb +5 -3
  11. data/lib/profitbricks/rule.rb +11 -0
  12. data/lib/profitbricks.rb +4 -1
  13. data/spec/fixtures/activate_firewalls/success.json +10 -0
  14. data/spec/fixtures/activate_firewalls/success.xml +1 -0
  15. data/spec/fixtures/activate_load_balancing_on_servers/success.json +10 -0
  16. data/spec/fixtures/activate_load_balancing_on_servers/success.xml +1 -0
  17. data/spec/fixtures/add_firewall_rules_to_load_balancer/success.json +17 -0
  18. data/spec/fixtures/add_firewall_rules_to_load_balancer/success.xml +1 -0
  19. data/spec/fixtures/add_firewall_rules_to_nic/success.json +24 -0
  20. data/spec/fixtures/add_firewall_rules_to_nic/success.xml +1 -0
  21. data/spec/fixtures/create_load_balancer/success.json +11 -0
  22. data/spec/fixtures/create_load_balancer/success.xml +1 -0
  23. data/spec/fixtures/deactivate_firewalls/success.json +10 -0
  24. data/spec/fixtures/deactivate_firewalls/success.xml +1 -0
  25. data/spec/fixtures/deactivate_load_balancing_on_servers/success.json +10 -0
  26. data/spec/fixtures/deactivate_load_balancing_on_servers/success.xml +1 -0
  27. data/spec/fixtures/delete_firewalls/success.json +10 -0
  28. data/spec/fixtures/delete_firewalls/success.xml +1 -0
  29. data/spec/fixtures/delete_load_balancer/success.json +10 -0
  30. data/spec/fixtures/delete_load_balancer/success.xml +1 -0
  31. data/spec/fixtures/deregister_servers_on_load_balancer/success.json +10 -0
  32. data/spec/fixtures/deregister_servers_on_load_balancer/success.xml +1 -0
  33. data/spec/fixtures/get_data_center/firewall.json +77 -0
  34. data/spec/fixtures/get_data_center/firewall.xml +1 -0
  35. data/spec/fixtures/get_firewall/success.json +24 -0
  36. data/spec/fixtures/get_firewall/success.xml +1 -0
  37. data/spec/fixtures/get_load_balancer/success.json +16 -0
  38. data/spec/fixtures/get_load_balancer/success.xml +1 -0
  39. data/spec/fixtures/register_servers_on_load_balancer/success.json +17 -0
  40. data/spec/fixtures/register_servers_on_load_balancer/success.xml +1 -0
  41. data/spec/fixtures/remove_firewall_rules/success.json +10 -0
  42. data/spec/fixtures/remove_firewall_rules/success.xml +1 -0
  43. data/spec/fixtures/update_load_balancer/success.json +10 -0
  44. data/spec/fixtures/update_load_balancer/success.xml +1 -0
  45. data/spec/profitbricks/firewall_spec.rb +49 -0
  46. data/spec/profitbricks/load_balancer_spec.rb +60 -0
  47. metadata +47 -14
data/CHANGELOG.md CHANGED
@@ -1,3 +1,10 @@
1
+ === 0.4.0 / 2012-04-11
2
+
3
+ * 2 major enhancements:
4
+
5
+ * Support for firewalls
6
+ * Support for load balancers
7
+
1
8
  === 0.0.5 / 2012-03-07
2
9
 
3
10
  * 1 major enhancement:
data/Manifest.txt CHANGED
@@ -13,14 +13,25 @@ lib/profitbricks.rb
13
13
  lib/profitbricks/config.rb
14
14
  lib/profitbricks/data_center.rb
15
15
  lib/profitbricks/extensions.rb
16
+ lib/profitbricks/firewall.rb
16
17
  lib/profitbricks/image.rb
17
18
  lib/profitbricks/ip_block.rb
19
+ lib/profitbricks/load_balancer.rb
18
20
  lib/profitbricks/model.rb
19
21
  lib/profitbricks/nic.rb
20
22
  lib/profitbricks/profitbricks.rb
23
+ lib/profitbricks/rule.rb
21
24
  lib/profitbricks/server.rb
22
25
  lib/profitbricks/storage.rb
23
26
  profitbricks.gemspec
27
+ spec/fixtures/activate_firewalls/success.json
28
+ spec/fixtures/activate_firewalls/success.xml
29
+ spec/fixtures/activate_load_balancing_on_servers/success.json
30
+ spec/fixtures/activate_load_balancing_on_servers/success.xml
31
+ spec/fixtures/add_firewall_rules_to_load_balancer/success.json
32
+ spec/fixtures/add_firewall_rules_to_load_balancer/success.xml
33
+ spec/fixtures/add_firewall_rules_to_nic/success.json
34
+ spec/fixtures/add_firewall_rules_to_nic/success.xml
24
35
  spec/fixtures/add_public_ip_to_nic/success.json
25
36
  spec/fixtures/add_public_ip_to_nic/success.xml
26
37
  spec/fixtures/clear_data_center/success.json
@@ -29,14 +40,24 @@ spec/fixtures/connect_storage_to_server/success.json
29
40
  spec/fixtures/connect_storage_to_server/success.xml
30
41
  spec/fixtures/create_data_center/success.json
31
42
  spec/fixtures/create_data_center/success.xml
43
+ spec/fixtures/create_load_balancer/success.json
44
+ spec/fixtures/create_load_balancer/success.xml
32
45
  spec/fixtures/create_nic/success.json
33
46
  spec/fixtures/create_nic/success.xml
34
47
  spec/fixtures/create_server/minimal.json
35
48
  spec/fixtures/create_server/minimal.xml
36
49
  spec/fixtures/create_storage/success.json
37
50
  spec/fixtures/create_storage/success.xml
51
+ spec/fixtures/deactivate_firewalls/success.json
52
+ spec/fixtures/deactivate_firewalls/success.xml
53
+ spec/fixtures/deactivate_load_balancing_on_servers/success.json
54
+ spec/fixtures/deactivate_load_balancing_on_servers/success.xml
38
55
  spec/fixtures/delete_data_center/success.json
39
56
  spec/fixtures/delete_data_center/success.xml
57
+ spec/fixtures/delete_firewalls/success.json
58
+ spec/fixtures/delete_firewalls/success.xml
59
+ spec/fixtures/delete_load_balancer/success.json
60
+ spec/fixtures/delete_load_balancer/success.xml
40
61
  spec/fixtures/delete_nic/success.json
41
62
  spec/fixtures/delete_nic/success.xml
42
63
  spec/fixtures/delete_server/success.json
@@ -45,6 +66,8 @@ spec/fixtures/delete_storage/failture.json
45
66
  spec/fixtures/delete_storage/failture.xml
46
67
  spec/fixtures/delete_storage/success.json
47
68
  spec/fixtures/delete_storage/success.xml
69
+ spec/fixtures/deregister_servers_on_load_balancer/success.json
70
+ spec/fixtures/deregister_servers_on_load_balancer/success.xml
48
71
  spec/fixtures/disconnect_storage_from_server/failture.json
49
72
  spec/fixtures/disconnect_storage_from_server/failture.xml
50
73
  spec/fixtures/disconnect_storage_from_server/success.json
@@ -59,14 +82,20 @@ spec/fixtures/get_all_public_ip_blocks/success.json
59
82
  spec/fixtures/get_all_public_ip_blocks/success.xml
60
83
  spec/fixtures/get_data_center/create.json
61
84
  spec/fixtures/get_data_center/create.xml
85
+ spec/fixtures/get_data_center/firewall.json
86
+ spec/fixtures/get_data_center/firewall.xml
62
87
  spec/fixtures/get_data_center/two_servers_with_storage.json
63
88
  spec/fixtures/get_data_center/two_servers_with_storage.xml
64
89
  spec/fixtures/get_data_center_state/in_process.json
65
90
  spec/fixtures/get_data_center_state/in_process.xml
66
91
  spec/fixtures/get_data_center_state/success.json
67
92
  spec/fixtures/get_data_center_state/success.xml
93
+ spec/fixtures/get_firewall/success.json
94
+ spec/fixtures/get_firewall/success.xml
68
95
  spec/fixtures/get_image/success.json
69
96
  spec/fixtures/get_image/success.xml
97
+ spec/fixtures/get_load_balancer/success.json
98
+ spec/fixtures/get_load_balancer/success.xml
70
99
  spec/fixtures/get_nic/success.json
71
100
  spec/fixtures/get_nic/success.xml
72
101
  spec/fixtures/get_nic/two_ips.json
@@ -79,8 +108,12 @@ spec/fixtures/get_storage/success.json
79
108
  spec/fixtures/get_storage/success.xml
80
109
  spec/fixtures/reboot_server/success.json
81
110
  spec/fixtures/reboot_server/success.xml
111
+ spec/fixtures/register_servers_on_load_balancer/success.json
112
+ spec/fixtures/register_servers_on_load_balancer/success.xml
82
113
  spec/fixtures/release_public_ip_block/success.json
83
114
  spec/fixtures/release_public_ip_block/success.xml
115
+ spec/fixtures/remove_firewall_rules/success.json
116
+ spec/fixtures/remove_firewall_rules/success.xml
84
117
  spec/fixtures/remove_public_ip_from_nic/success.json
85
118
  spec/fixtures/remove_public_ip_from_nic/success.xml
86
119
  spec/fixtures/reserve_public_ip_block/success.json
@@ -91,6 +124,8 @@ spec/fixtures/set_internet_access/success.json
91
124
  spec/fixtures/set_internet_access/success.xml
92
125
  spec/fixtures/update_data_center/success.json
93
126
  spec/fixtures/update_data_center/success.xml
127
+ spec/fixtures/update_load_balancer/success.json
128
+ spec/fixtures/update_load_balancer/success.xml
94
129
  spec/fixtures/update_nic/success.json
95
130
  spec/fixtures/update_nic/success.xml
96
131
  spec/fixtures/update_server/basic.json
@@ -98,8 +133,10 @@ spec/fixtures/update_server/basic.xml
98
133
  spec/fixtures/update_storage/success.json
99
134
  spec/fixtures/update_storage/success.xml
100
135
  spec/profitbricks/data_center_spec.rb
136
+ spec/profitbricks/firewall_spec.rb
101
137
  spec/profitbricks/image_spec.rb
102
138
  spec/profitbricks/ip_block_spec.rb
139
+ spec/profitbricks/load_balancer_spec.rb
103
140
  spec/profitbricks/model_spec.rb
104
141
  spec/profitbricks/nic_spec.rb
105
142
  spec/profitbricks/server_spec.rb
data/README.md CHANGED
@@ -7,8 +7,6 @@
7
7
  ## DESCRIPTION
8
8
  A Ruby client for the ProfitBricks API.
9
9
 
10
- BE AWARE: This software is in a very early state of development, the methods and responses will very likely change over time.
11
-
12
10
  ## Dependencies
13
11
  A Ruby interpreter (MRI 1.8.7, 1.9.2, 1.9.3 and JRuby 1.8 passing the tests).
14
12
 
@@ -44,11 +42,9 @@ or
44
42
 
45
43
  Server.create(:cores => 1, :ram => 256, :name => 'Test Server')
46
44
 
47
- Check out the examples directory for more detailed usage information.
45
+ Check out the examples directory for more detailed usage information, or have a look at the [documentation](http://rubydoc.info/github/dsander/profitbricks/master/frames) for the class reference.
48
46
 
49
47
  ## License
50
- This might also change!
51
-
52
48
  (The MIT License)
53
49
 
54
50
  Copyright (c) 2012 Dominik Sander
@@ -2,6 +2,7 @@ module Profitbricks
2
2
  class DataCenter < Profitbricks::Model
3
3
  has_many :servers
4
4
  has_many :storages
5
+ has_many :load_balancers
5
6
 
6
7
  # Deletes an empty Virtual Data Center. All components must be removed first.
7
8
  # @return [Boolean] true on success, false otherwise
@@ -0,0 +1,76 @@
1
+ module Profitbricks
2
+ class Firewall < Profitbricks::Model
3
+ has_many :rules, :class_name => :firewall_rule
4
+
5
+ def initialize(hash, parent)
6
+ @parent = parent
7
+ super(hash)
8
+ end
9
+
10
+
11
+ # Adds accept-rules to the firewall of a NIC or Load Balancer.
12
+ #
13
+ # If no firewall exists, a new inactive firewall is created.
14
+ #
15
+ # @param [Array<FirewallRule>] Array of FirewallRules to add
16
+ # @return [Boolean] true on success, false otherwise
17
+ def add_rules(rules)
18
+ xml = ""
19
+ rules.each do |rule|
20
+ xml += "<request>"
21
+ xml += rule.get_xml_and_update_attributes rule.attributes, rule.attributes.keys
22
+ xml += "</request>"
23
+ end
24
+ response = nil
25
+ if @parent.class == Profitbricks::LoadBalancer
26
+ xml += "<loadBalancerId>#{@parent.id}</loadBalancerId>"
27
+ response = Profitbricks.request :add_firewall_rules_to_load_balancer, xml
28
+ update_attributes(response.to_hash[:add_firewall_rules_to_load_balancer_response][:return])
29
+ return true if response.to_hash[:add_firewall_rules_to_load_balancer_response][:return]
30
+ else
31
+ xml += "<nicId>#{self.nic_id}</nicId>"
32
+ response = Profitbricks.request :add_firewall_rules_to_nic, xml
33
+ update_attributes(response.to_hash[:add_firewall_rules_to_nic_response][:return])
34
+ return true if response.to_hash[:add_firewall_rules_to_nic_response][:return]
35
+ end
36
+
37
+ end
38
+
39
+ # Activates the Firewall
40
+ #
41
+ # @return [Boolean] true on success, false otherwise
42
+ def activate
43
+ response = Profitbricks.request :activate_firewalls, "<firewallIds>#{self.id}</firewallIds>"
44
+ return true if response[:activate_firewalls_response][:return]
45
+ end
46
+
47
+ # Deactivates the Firewall
48
+ #
49
+ # @return [Boolean] true on success, false otherwise
50
+ def deactivate
51
+ response = Profitbricks.request :deactivate_firewalls, "<firewallIds>#{self.id}</firewallIds>"
52
+ return true if response[:deactivate_firewalls_response][:return]
53
+ end
54
+
55
+ # Deletes the Firewall
56
+ #
57
+ # @return [Boolean] true on success, false otherwise
58
+ def delete
59
+ response = Profitbricks.request :delete_firewalls, "<firewallIds>#{self.id}</firewallIds>"
60
+ return true if response[:delete_firewalls_response][:return]
61
+ end
62
+ class << self
63
+ # Returns information about the respective firewall.
64
+ # Each rule has an identifier for later modification.
65
+ #
66
+ # @param [Hash] options currently just :id is supported
67
+ # @option options [String] :id The id of the firewall to locate (required)
68
+ # @return [Firewall] The located Firewall
69
+ def find(options = {})
70
+ response = Profitbricks.request :get_firewall, "<firewallId>#{options[:id]}</firewallId>"
71
+ # FIXME we cannot load the Firewall without knowing if it is belonging to a NIC or a LoadBalancer
72
+ PB::Firewall.new(response.to_hash[:get_firewall_response][:return], nil)
73
+ end
74
+ end
75
+ end
76
+ end
@@ -2,7 +2,7 @@ module Profitbricks
2
2
  class IpBlock < Profitbricks::Model
3
3
  attr_reader :ips
4
4
 
5
- def initialize(hash)
5
+ def initialize(hash, parent=nil)
6
6
  if hash[:public_ips]
7
7
  @ips = [hash.delete(:public_ips)].flatten.compact.collect { |ip| ip[:ip] }
8
8
  end
@@ -0,0 +1,127 @@
1
+ module Profitbricks
2
+ class LoadBalancer < Profitbricks::Model
3
+ has_many :balanced_servers, :class_name => :server
4
+ belongs_to :firewall
5
+
6
+ # Changes the settings of an existing virtual load balancer.
7
+ #
8
+ # @param [Hash] options parameters for the new NIC
9
+ # @option options [String] :name Name of the load balancer to be created
10
+ # @option options [String] :algorithm load balancer algorithm. 'ROUND_ROBIN' is default and the only supported algorithm at the moment
11
+ # @option options [String] :ip Updates the IP address of the load balancer with the speficied IP. All servers connected to the load balancer will have their primary IP address updated with the same IP address of the load balancer implicitly Additional customer reserved IP addresses, which have been added to the server’s NIC, remain unchanged Set ip to empty, to reset the IP of load balancer with a Profitbricks assigned IP address.
12
+ # @return [Boolean] true on success, false otherwise
13
+ def update(options = {})
14
+ options.merge!(:load_balancer_id=> self.id)
15
+ xml = "<arg0>"
16
+ xml += get_xml_and_update_attributes options, [:load_balancer_id, :ip, :name, :algorithm]
17
+ xml += "</arg0>"
18
+ response = Profitbricks.request :update_load_balancer, xml
19
+ self.reload
20
+ return true if response.to_hash[:update_load_balancer_response][:return]
21
+ end
22
+
23
+ # Adds new servers to the Load Balancer within the respective LAN.
24
+ #
25
+ # If the server is not yet a member of the LAN, a new NIC is created, connected to the LAN and registered with the
26
+ # Load Balancer. The load balancer will distribute traffic to the server through this balanced NIC.
27
+ # If the server is already a member of the LAN, the appropriate NIC is used as balanced NIC.
28
+ # A server can be registered to more than one Load Balancer.
29
+ #
30
+ # @option [Array<Server>] Servers to connect to the LoadBalancer
31
+ # @return [Boolean] true on success, false otherwise
32
+ def register_servers(servers)
33
+ raise "You have to provide at least one server" unless servers
34
+ options = {:server_ids => servers.collect { |s| s.id }.join(','), :load_balancer_id=> self.id}
35
+ xml = get_xml_and_update_attributes options, [:server_ids, :load_balancer_id]
36
+ response = Profitbricks.request :register_servers_on_load_balancer, xml
37
+ update_attributes(response.to_hash[:register_servers_on_load_balancer_response][:return])
38
+ return true if response.to_hash[:register_servers_on_load_balancer_response][:return]
39
+ end
40
+
41
+ # Removes servers from the load balancer
42
+ #
43
+ # By deregistering a server, the server is being removed from the load balancer but still remains
44
+ # connected to the same LAN. The primary IP address of the NIC, through which the load balancer
45
+ # distributed traffic to the server before, is reset and replaced by a ProfitBricks assigned IP address.
46
+ #
47
+ # @option [Array<Server>] Servers to disconnect from the LoadBalancer
48
+ # @return [Boolean] true on success, false otherwise
49
+ def deregister_servers(servers)
50
+ raise "You have to provide at least one server" unless servers
51
+ options = {:server_ids => servers.collect { |s| s.id }.join(','), :load_balancer_id=> self.id}
52
+ xml = get_xml_and_update_attributes options, [:server_ids, :load_balancer_id]
53
+ response = Profitbricks.request :deregister_servers_on_load_balancer, xml
54
+ return true if response.to_hash[:deregister_servers_on_load_balancer_response][:return]
55
+ end
56
+
57
+ # Enables the load balancer to distribute traffic to the specified servers.
58
+ #
59
+ # @option [Array<Server>] Servers to enable
60
+ # @return [Boolean] true on success, false otherwise
61
+ def activate_servers(servers)
62
+ raise "You have to provide at least one server" unless servers
63
+ options = {:server_ids => servers.collect { |s| s.id }.join(','), :load_balancer_id=> self.id}
64
+ xml = get_xml_and_update_attributes options, [:server_ids, :load_balancer_id]
65
+ response = Profitbricks.request :activate_load_balancing_on_servers, xml
66
+ return true if response.to_hash[:activate_load_balancing_on_servers_response][:return]
67
+ end
68
+
69
+ # Disables the load balancer to distribute traffic to the specified servers.
70
+ #
71
+ # @option [Array<Server>] Servers to disable
72
+ # @return [Boolean] true on success, false otherwise
73
+ def deactivate_servers(servers)
74
+ raise "You have to provide at least one server" unless servers
75
+ options = {:server_ids => servers.collect { |s| s.id }.join(','), :load_balancer_id=> self.id}
76
+ xml = get_xml_and_update_attributes options, [:server_ids, :load_balancer_id]
77
+ response = Profitbricks.request :deactivate_load_balancing_on_servers, xml
78
+ return true if response.to_hash[:deactivate_load_balancing_on_servers_response][:return]
79
+ end
80
+
81
+ # Deletes an existing load balancer.
82
+ # Primary IP addresses of the server’s previously balanced NICs are reset and replaced with ProfitBricks assigned IP address.
83
+ # If a load balancer has been deleted, all servers will still be connected to the same LAN though.
84
+ #
85
+ # @return [Boolean] true on success, false otherwise
86
+ def delete
87
+ response = Profitbricks.request :delete_load_balancer, "<loadBalancerId>#{self.id}</loadBalancerId>"
88
+ return true if response.to_hash[:delete_load_balancer_response][:return]
89
+ end
90
+
91
+ class << self
92
+ # Creates a virtual Load Balancer within an existing virtual data center.
93
+ #
94
+ # A Load Balancer connected to a LAN will not distribute traffic to any server, until it is specified to
95
+ # do so. In the current version, a Load Balancer cannot distribute traffic across multiple data centers
96
+ # or LANs. Load Balancer and servers must always be in the same LAN.
97
+ #
98
+ # @param [Hash] options parameters for the new NIC
99
+ # @option options [String] :data_center_id data center ID wherein the load balancer is to be created (required)
100
+ # @option options [String] :name Name of the load balancer to be created
101
+ # @option options [String] :algorithm load balancer algorithm. 'ROUND_ROBIN' is default and the only supported algorithm at the moment
102
+ # @option options [String] :ip A DHCP IP adress is being assigned to the load balancer automatically by ProfitBricks. A private IP can be defined by the user. Additional, public IPs can be reserved and assigned to the load balancer manually.
103
+ # @option options [Fixnum] :lan_id Identifier of the target LAN ID > 0 If the specified LAN ID does not exist or if LAN ID is not specified, a new LAN with the given ID / with a next available ID starting from 1 will be created respectively
104
+ # @option options [Array<Server>] :servers Array of servers to connect to the LoadBalancer
105
+ # @return [LoadBalancer] The created LoadBalancer
106
+ def create(options = {})
107
+ options[:server_ids] = options[:servers].collect { |s| s.id }.join(',')
108
+ xml = "<arg0>"
109
+ xml += get_xml_and_update_attributes options, [:data_center_id, :lan_id, :ip, :name, :algorithm, :server_ids]
110
+ xml += "</arg0>"
111
+ response = Profitbricks.request :create_load_balancer, xml
112
+ self.find(:id => response.to_hash[:create_load_balancer_response][:return][:load_balancer_id])
113
+ end
114
+
115
+ # Returns information about a virtual load balancer.
116
+ #
117
+ # @param [Hash] options currently just :id is supported
118
+ # @option options [String] :id The id of the load balancer to locate
119
+ # @return [LoadBalancer] The found LoadBalancer
120
+ def find(options = {})
121
+ raise "Unable to locate the LoadBalancer named '#{options[:name]}'" unless options[:id]
122
+ response = Profitbricks.request :get_load_balancer, "<loadBalancerId>#{options[:id]}</loadBalancerId>"
123
+ PB::LoadBalancer.new(response.to_hash[:get_load_balancer_response][:return])
124
+ end
125
+ end
126
+ end
127
+ end
@@ -2,7 +2,7 @@ module Profitbricks
2
2
  class Model
3
3
  @@associations = {}
4
4
 
5
- def initialize(hash = {})
5
+ def initialize(hash = {}, parent=nil)
6
6
  klass = self.class.to_s.underscore
7
7
  hash.keys.each do |k|
8
8
  attribute = k.to_s.sub("#{klass}_", '').to_sym
@@ -20,14 +20,14 @@ module Profitbricks
20
20
  update_attributes(updated)
21
21
  end
22
22
 
23
- def self.has_many(model)
24
- klass = Profitbricks.get_class model.to_s[0..-2].camelcase
23
+ def self.has_many(model, options = {})
24
+ klass = Profitbricks.get_class model.to_s[0..-2], options
25
25
  @@associations[model] = {:type => :collection, :class => klass}
26
26
  define_method(model) { instance_variable_get("@#{model}") }
27
27
  end
28
28
 
29
- def self.belongs_to(model)
30
- klass = Profitbricks.get_class model.to_s.camelcase
29
+ def self.belongs_to(model, options = {})
30
+ klass = Profitbricks.get_class model.to_s, options
31
31
  @@associations[model] = {:type => :belongs_to, :class => klass}
32
32
  define_method(model) { instance_variable_get("@#{model}") }
33
33
  end
@@ -46,6 +46,14 @@ module Profitbricks
46
46
  self.build_xml(hash, attributes)
47
47
  end
48
48
 
49
+ def attributes
50
+ a = {}
51
+ self.instance_variables.each do |variable|
52
+ a[variable.to_s[1..-1].to_sym] = self.instance_variable_get(variable)
53
+ end
54
+ a
55
+ end
56
+
49
57
  private
50
58
  def update_attributes(updated)
51
59
  self.instance_variables.each do |var|
@@ -83,19 +91,23 @@ module Profitbricks
83
91
  def initialize_collection_association name, association, value
84
92
  self.instance_variable_set("@#{name}", [])
85
93
  [value].flatten.compact.each do |object|
86
- instance_variable_get("@#{name}").send(:push, association[:class].send(:new, object))
94
+ instance_variable_get("@#{name}").send(:push, association[:class].send(:new, object, self))
87
95
  end
88
96
  end
89
97
 
90
98
  def initialize_belongs_to_association name, association, value
91
- self.instance_variable_set("@#{name}", association[:class].send(:new, value))
99
+ self.instance_variable_set("@#{name}", association[:class].send(:new, value, self))
92
100
  end
93
101
 
94
102
  def self.expand_attributes(hash, attributes, klass=nil)
95
- name = hash.delete(:name)
96
- hash["#{klass.to_s.underscore}_name"] = name
97
- attributes.delete(:name)
98
- attributes.push "#{klass.to_s.underscore}_name"
103
+ [:name, :algorithm].each do |a|
104
+ deleted = hash.delete(a)
105
+ if deleted
106
+ hash["#{klass.to_s.underscore}_#{a.to_s}"] = deleted
107
+ attributes.delete(a)
108
+ attributes.push "#{klass.to_s.underscore}_#{a.to_s}"
109
+ end
110
+ end
99
111
  return hash, attributes
100
112
  end
101
113
  end
@@ -2,8 +2,8 @@ module Profitbricks
2
2
  class Ip < Profitbricks::Model; end;
3
3
 
4
4
  class Nic < Profitbricks::Model
5
-
6
- def initialize(hash)
5
+ belongs_to :firewall
6
+ def initialize(hash, parent=nil)
7
7
  super(hash)
8
8
  @ips = [@ips] if @ips.class != Array
9
9
  end
@@ -60,6 +60,7 @@ module Profitbricks
60
60
 
61
61
  def self.store(method, body, xml, json)
62
62
  require 'digest/sha1'
63
+ require 'json'
63
64
  hash = Digest::SHA1.hexdigest xml
64
65
 
65
66
  unless Dir.exists?(File.expand_path("../../../spec/fixtures/#{method}", __FILE__))
@@ -69,8 +70,9 @@ module Profitbricks
69
70
  File.open(File.expand_path("../../../spec/fixtures/#{method}/#{hash}.json", __FILE__), 'w').write(JSON.dump(json))
70
71
  end
71
72
 
72
- def self.get_class name
73
- klass = name
73
+ def self.get_class name, options = {}
74
+ klass = name.camelcase
75
+ klass = options[:class_name].to_s.camelcase if options[:class_name]
74
76
  if Profitbricks.const_defined?(klass)
75
77
  klass = Profitbricks.const_get(klass)
76
78
  else
@@ -83,4 +85,4 @@ module Profitbricks
83
85
  end
84
86
  klass
85
87
  end
86
- end
88
+ end
@@ -0,0 +1,11 @@
1
+ module Profitbricks
2
+ class FirewallRule < Profitbricks::Model
3
+ # Deletes the FirewallRule
4
+ #
5
+ # @return [Boolean] true on success, false otherwise
6
+ def delete
7
+ response = Profitbricks.request :remove_firewall_rules, "<firewallRuleIds>#{self.id}</firewallRuleIds>"
8
+ return true if response[:remove_firewall_rules_response][:return]
9
+ end
10
+ end
11
+ end
data/lib/profitbricks.rb CHANGED
@@ -8,9 +8,12 @@ require 'profitbricks/server'
8
8
  require 'profitbricks/image'
9
9
  require 'profitbricks/storage'
10
10
  require 'profitbricks/ip_block'
11
+ require 'profitbricks/load_balancer'
12
+ require 'profitbricks/firewall'
13
+ require 'profitbricks/rule'
11
14
 
12
15
  module Profitbricks
13
- VERSION = '0.0.5'
16
+ VERSION = '0.4.0'
14
17
  end
15
18
 
16
19
  PB = Profitbricks
@@ -0,0 +1,10 @@
1
+ {
2
+ "activate_firewalls_response": {
3
+ "@xmlns:ns2": "http://ws.api.profitbricks.com/",
4
+ "return": {
5
+ "data_center_id": "69ab6ed3-8355-4c90-9501-6fa4b21ebfa3",
6
+ "data_center_version": "40",
7
+ "request_id": "2201"
8
+ }
9
+ }
10
+ }
@@ -0,0 +1 @@
1
+ <?xml version='1.0' encoding='UTF-8'?><S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/"><S:Body><ns2:activateFirewallsResponse xmlns:ns2="http://ws.api.profitbricks.com/"><return><requestId>2201</requestId><dataCenterId>69ab6ed3-8355-4c90-9501-6fa4b21ebfa3</dataCenterId><dataCenterVersion>40</dataCenterVersion></return></ns2:activateFirewallsResponse></S:Body></S:Envelope>
@@ -0,0 +1,10 @@
1
+ {
2
+ "activate_load_balancing_on_servers_response": {
3
+ "@xmlns:ns2": "http://ws.api.profitbricks.com/",
4
+ "return": {
5
+ "data_center_id": "69ab6ed3-8355-4c90-9501-6fa4b21ebfa3",
6
+ "data_center_version": "24",
7
+ "request_id": "2192"
8
+ }
9
+ }
10
+ }
@@ -0,0 +1 @@
1
+ <?xml version='1.0' encoding='UTF-8'?><S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/"><S:Body><ns2:activateLoadBalancingOnServersResponse xmlns:ns2="http://ws.api.profitbricks.com/"><return><requestId>2192</requestId><dataCenterId>69ab6ed3-8355-4c90-9501-6fa4b21ebfa3</dataCenterId><dataCenterVersion>24</dataCenterVersion></return></ns2:activateLoadBalancingOnServersResponse></S:Body></S:Envelope>
@@ -0,0 +1,17 @@
1
+ {
2
+ "add_firewall_rules_to_load_balancer_response": {
3
+ "@xmlns:ns2": "http://ws.api.profitbricks.com/",
4
+ "return": {
5
+ "active": false,
6
+ "firewall_id": "aa5e5270-1e6d-6e3a-ba7b-0b1f2d9e2425",
7
+ "firewall_rules": {
8
+ "firewall_rule_id": "c0ccdcb3-302a-4353-836b-a31169a8df57",
9
+ "port_range_end": "80",
10
+ "port_range_start": "80",
11
+ "protocol": "TCP"
12
+ },
13
+ "nic_id": "5a6e677b-c0c1-93c3-38e1-7cda5eef6015",
14
+ "provisioning_state": "INPROCESS"
15
+ }
16
+ }
17
+ }
@@ -0,0 +1 @@
1
+ <?xml version='1.0' encoding='UTF-8'?><S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/"><S:Body><ns2:addFirewallRulesToLoadBalancerResponse xmlns:ns2="http://ws.api.profitbricks.com/"><return><active>false</active><firewallId>aa5e5270-1e6d-6e3a-ba7b-0b1f2d9e2425</firewallId><firewallRules><firewallRuleId>c0ccdcb3-302a-4353-836b-a31169a8df57</firewallRuleId><protocol>TCP</protocol><portRangeStart>80</portRangeStart><portRangeEnd>80</portRangeEnd></firewallRules><nicId>5a6e677b-c0c1-93c3-38e1-7cda5eef6015</nicId><provisioningState>INPROCESS</provisioningState></return></ns2:addFirewallRulesToLoadBalancerResponse></S:Body></S:Envelope>
@@ -0,0 +1,24 @@
1
+ {
2
+ "add_firewall_rules_to_nic_response": {
3
+ "@xmlns:ns2": "http://ws.api.profitbricks.com/",
4
+ "return": {
5
+ "active": false,
6
+ "firewall_id": "33f4e0a5-41d9-eb57-81d1-24854ed89834",
7
+ "firewall_rules": [
8
+ {
9
+ "firewall_rule_id": "77e8e8bd-5b72-b657-e97b-c010937cefdf",
10
+ "protocol": "ANY",
11
+ "target_ip": "10.14.186.225"
12
+ },
13
+ {
14
+ "firewall_rule_id": "3580cc62-41bb-46a8-8ce8-6a19fbbe884e",
15
+ "port_range_end": "80",
16
+ "port_range_start": "80",
17
+ "protocol": "TCP"
18
+ }
19
+ ],
20
+ "nic_id": "7f3a83fd-d158-5add-cb22-0cc6590f8791",
21
+ "provisioning_state": "INPROCESS"
22
+ }
23
+ }
24
+ }
@@ -0,0 +1 @@
1
+ <?xml version='1.0' encoding='UTF-8'?><S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/"><S:Body><ns2:addFirewallRulesToNicResponse xmlns:ns2="http://ws.api.profitbricks.com/"><return><active>false</active><firewallId>33f4e0a5-41d9-eb57-81d1-24854ed89834</firewallId><firewallRules><firewallRuleId>77e8e8bd-5b72-b657-e97b-c010937cefdf</firewallRuleId><protocol>ANY</protocol><targetIp>10.14.186.225</targetIp></firewallRules><firewallRules><firewallRuleId>3580cc62-41bb-46a8-8ce8-6a19fbbe884e</firewallRuleId><protocol>TCP</protocol><portRangeStart>80</portRangeStart><portRangeEnd>80</portRangeEnd></firewallRules><nicId>7f3a83fd-d158-5add-cb22-0cc6590f8791</nicId><provisioningState>INPROCESS</provisioningState></return></ns2:addFirewallRulesToNicResponse></S:Body></S:Envelope>
@@ -0,0 +1,11 @@
1
+ {
2
+ "create_load_balancer_response": {
3
+ "@xmlns:ns2": "http://ws.api.profitbricks.com/",
4
+ "return": {
5
+ "data_center_id": "69ab6ed3-8355-4c90-9501-6fa4b21ebfa3",
6
+ "data_center_version": "10",
7
+ "load_balancer_id": "5dadd2b2-3405-4ec5-a450-0df497bebab0",
8
+ "request_id": "2177"
9
+ }
10
+ }
11
+ }
@@ -0,0 +1 @@
1
+ <?xml version='1.0' encoding='UTF-8'?><S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/"><S:Body><ns2:createLoadBalancerResponse xmlns:ns2="http://ws.api.profitbricks.com/"><return><requestId>2177</requestId><dataCenterId>69ab6ed3-8355-4c90-9501-6fa4b21ebfa3</dataCenterId><dataCenterVersion>10</dataCenterVersion><loadBalancerId>5dadd2b2-3405-4ec5-a450-0df497bebab0</loadBalancerId></return></ns2:createLoadBalancerResponse></S:Body></S:Envelope>
@@ -0,0 +1,10 @@
1
+ {
2
+ "deactivate_firewalls_response": {
3
+ "@xmlns:ns2": "http://ws.api.profitbricks.com/",
4
+ "return": {
5
+ "data_center_id": "69ab6ed3-8355-4c90-9501-6fa4b21ebfa3",
6
+ "data_center_version": "42",
7
+ "request_id": "2203"
8
+ }
9
+ }
10
+ }
@@ -0,0 +1 @@
1
+ <?xml version='1.0' encoding='UTF-8'?><S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/"><S:Body><ns2:deactivateFirewallsResponse xmlns:ns2="http://ws.api.profitbricks.com/"><return><requestId>2203</requestId><dataCenterId>69ab6ed3-8355-4c90-9501-6fa4b21ebfa3</dataCenterId><dataCenterVersion>42</dataCenterVersion></return></ns2:deactivateFirewallsResponse></S:Body></S:Envelope>
@@ -0,0 +1,10 @@
1
+ {
2
+ "deactivate_load_balancing_on_servers_response": {
3
+ "@xmlns:ns2": "http://ws.api.profitbricks.com/",
4
+ "return": {
5
+ "data_center_id": "69ab6ed3-8355-4c90-9501-6fa4b21ebfa3",
6
+ "data_center_version": "22",
7
+ "request_id": "2191"
8
+ }
9
+ }
10
+ }
@@ -0,0 +1 @@
1
+ <?xml version='1.0' encoding='UTF-8'?><S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/"><S:Body><ns2:deactivateLoadBalancingOnServersResponse xmlns:ns2="http://ws.api.profitbricks.com/"><return><requestId>2191</requestId><dataCenterId>69ab6ed3-8355-4c90-9501-6fa4b21ebfa3</dataCenterId><dataCenterVersion>22</dataCenterVersion></return></ns2:deactivateLoadBalancingOnServersResponse></S:Body></S:Envelope>
@@ -0,0 +1,10 @@
1
+ {
2
+ "delete_firewalls_response": {
3
+ "@xmlns:ns2": "http://ws.api.profitbricks.com/",
4
+ "return": {
5
+ "data_center_id": "69ab6ed3-8355-4c90-9501-6fa4b21ebfa3",
6
+ "data_center_version": "52",
7
+ "request_id": "2224"
8
+ }
9
+ }
10
+ }
@@ -0,0 +1 @@
1
+ <?xml version='1.0' encoding='UTF-8'?><S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/"><S:Body><ns2:deleteFirewallsResponse xmlns:ns2="http://ws.api.profitbricks.com/"><return><requestId>2224</requestId><dataCenterId>69ab6ed3-8355-4c90-9501-6fa4b21ebfa3</dataCenterId><dataCenterVersion>52</dataCenterVersion></return></ns2:deleteFirewallsResponse></S:Body></S:Envelope>
@@ -0,0 +1,10 @@
1
+ {
2
+ "delete_load_balancer_response": {
3
+ "@xmlns:ns2": "http://ws.api.profitbricks.com/",
4
+ "return": {
5
+ "data_center_id": "69ab6ed3-8355-4c90-9501-6fa4b21ebfa3",
6
+ "data_center_version": "26",
7
+ "request_id": "2193"
8
+ }
9
+ }
10
+ }
@@ -0,0 +1 @@
1
+ <?xml version='1.0' encoding='UTF-8'?><S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/"><S:Body><ns2:deleteLoadBalancerResponse xmlns:ns2="http://ws.api.profitbricks.com/"><return><requestId>2193</requestId><dataCenterId>69ab6ed3-8355-4c90-9501-6fa4b21ebfa3</dataCenterId><dataCenterVersion>26</dataCenterVersion></return></ns2:deleteLoadBalancerResponse></S:Body></S:Envelope>
@@ -0,0 +1,10 @@
1
+ {
2
+ "deregister_servers_on_load_balancer_response": {
3
+ "@xmlns:ns2": "http://ws.api.profitbricks.com/",
4
+ "return": {
5
+ "data_center_id": "69ab6ed3-8355-4c90-9501-6fa4b21ebfa3",
6
+ "data_center_version": "18",
7
+ "request_id": "2188"
8
+ }
9
+ }
10
+ }
@@ -0,0 +1 @@
1
+ <?xml version='1.0' encoding='UTF-8'?><S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/"><S:Body><ns2:deregisterServersOnLoadBalancerResponse xmlns:ns2="http://ws.api.profitbricks.com/"><return><requestId>2188</requestId><dataCenterId>69ab6ed3-8355-4c90-9501-6fa4b21ebfa3</dataCenterId><dataCenterVersion>18</dataCenterVersion></return></ns2:deregisterServersOnLoadBalancerResponse></S:Body></S:Envelope>
@@ -0,0 +1,77 @@
1
+ {
2
+ "get_data_center_response": {
3
+ "@xmlns:ns2": "http://ws.api.profitbricks.com/",
4
+ "return": {
5
+ "data_center_id": "69ab6ed3-8355-4c90-9501-6fa4b21ebfa3",
6
+ "data_center_name": "Example Project",
7
+ "data_center_version": "37",
8
+ "load_balancers": {
9
+ "balanced_servers": {
10
+ "activate": true,
11
+ "balanced_nic_id": "7f3a83fd-d158-5add-cb22-0cc6590f8791",
12
+ "server_id": "05a17c46-3040-d1af-bb01-9579fe0300e7",
13
+ "server_name": "Server 1"
14
+ },
15
+ "creation_time": "2012-04-10T17:15:00+00:00",
16
+ "data_center_id": "69ab6ed3-8355-4c90-9501-6fa4b21ebfa3",
17
+ "data_center_version": "37",
18
+ "firewall": {
19
+ "active": false,
20
+ "firewall_id": "aa5e5270-1e6d-6e3a-ba7b-0b1f2d9e2425",
21
+ "nic_id": "5a6e677b-c0c1-93c3-38e1-7cda5eef6015",
22
+ "provisioning_state": "AVAILABLE"
23
+ },
24
+ "internet_access": false,
25
+ "ip": "10.14.186.225",
26
+ "lan_id": "1",
27
+ "last_modification_time": "2012-04-10T17:15:00+00:00",
28
+ "load_balancer_algorithm": "ROUND_ROBIN",
29
+ "load_balancer_id": "77b7ba71-3220-0045-ce35-2702caf66c18",
30
+ "load_balancer_name": "Load Balancer",
31
+ "provisioning_state": "AVAILABLE"
32
+ },
33
+ "provisioning_state": "AVAILABLE",
34
+ "servers": {
35
+ "cores": "1",
36
+ "creation_time": "2012-04-10T16:59:58+00:00",
37
+ "data_center_id": "69ab6ed3-8355-4c90-9501-6fa4b21ebfa3",
38
+ "data_center_version": "37",
39
+ "internet_access": false,
40
+ "ips": "10.14.186.225",
41
+ "last_modification_time": "2012-04-10T17:10:37+00:00",
42
+ "nics": {
43
+ "data_center_id": "69ab6ed3-8355-4c90-9501-6fa4b21ebfa3",
44
+ "data_center_version": "37",
45
+ "firewall": {
46
+ "active": false,
47
+ "firewall_id": "33f4e0a5-41d9-eb57-81d1-24854ed89834",
48
+ "firewall_rules": {
49
+ "firewall_rule_id": "77e8e8bd-5b72-b657-e97b-c010937cefdf",
50
+ "protocol": "ANY",
51
+ "target_ip": "10.14.186.225"
52
+ },
53
+ "nic_id": "7f3a83fd-d158-5add-cb22-0cc6590f8791",
54
+ "provisioning_state": "AVAILABLE"
55
+ },
56
+ "internet_access": false,
57
+ "ips": "10.14.186.225",
58
+ "lan_id": "1",
59
+ "mac_address": "02:01:ed:9e:0f:10",
60
+ "nic_id": "7f3a83fd-d158-5add-cb22-0cc6590f8791",
61
+ "nic_name": "eth0",
62
+ "server_id": "05a17c46-3040-d1af-bb01-9579fe0300e7"
63
+ },
64
+ "os_type": "OTHER",
65
+ "provisioning_state": "AVAILABLE",
66
+ "ram": "256",
67
+ "rom_drives": {
68
+ "image_id": "9de62e6e-ff1c-11e0-a1a7-0025901dfe2a",
69
+ "image_name": "grml64_2011.05.iso"
70
+ },
71
+ "server_id": "05a17c46-3040-d1af-bb01-9579fe0300e7",
72
+ "server_name": "Server 1",
73
+ "virtual_machine_state": "RUNNING"
74
+ }
75
+ }
76
+ }
77
+ }
@@ -0,0 +1 @@
1
+ <?xml version='1.0' encoding='UTF-8'?><S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/"><S:Body><ns2:getDataCenterResponse xmlns:ns2="http://ws.api.profitbricks.com/"><return><dataCenterId>69ab6ed3-8355-4c90-9501-6fa4b21ebfa3</dataCenterId><dataCenterVersion>37</dataCenterVersion><dataCenterName>Example Project</dataCenterName><servers><dataCenterId>69ab6ed3-8355-4c90-9501-6fa4b21ebfa3</dataCenterId><dataCenterVersion>37</dataCenterVersion><serverId>05a17c46-3040-d1af-bb01-9579fe0300e7</serverId><serverName>Server 1</serverName><cores>1</cores><ram>256</ram><internetAccess>false</internetAccess><ips>10.14.186.225</ips><romDrives><imageId>9de62e6e-ff1c-11e0-a1a7-0025901dfe2a</imageId><imageName>grml64_2011.05.iso</imageName></romDrives><nics><dataCenterId>69ab6ed3-8355-4c90-9501-6fa4b21ebfa3</dataCenterId><dataCenterVersion>37</dataCenterVersion><nicId>7f3a83fd-d158-5add-cb22-0cc6590f8791</nicId><nicName>eth0</nicName><lanId>1</lanId><internetAccess>false</internetAccess><serverId>05a17c46-3040-d1af-bb01-9579fe0300e7</serverId><ips>10.14.186.225</ips><macAddress>02:01:ed:9e:0f:10</macAddress><firewall><active>false</active><firewallId>33f4e0a5-41d9-eb57-81d1-24854ed89834</firewallId><firewallRules><firewallRuleId>77e8e8bd-5b72-b657-e97b-c010937cefdf</firewallRuleId><protocol>ANY</protocol><targetIp>10.14.186.225</targetIp></firewallRules><nicId>7f3a83fd-d158-5add-cb22-0cc6590f8791</nicId><provisioningState>AVAILABLE</provisioningState></firewall></nics><provisioningState>AVAILABLE</provisioningState><virtualMachineState>RUNNING</virtualMachineState><creationTime>2012-04-10T16:59:58.356Z</creationTime><lastModificationTime>2012-04-10T17:10:37.555Z</lastModificationTime><osType>OTHER</osType></servers><loadBalancers><dataCenterId>69ab6ed3-8355-4c90-9501-6fa4b21ebfa3</dataCenterId><dataCenterVersion>37</dataCenterVersion><loadBalancerId>77b7ba71-3220-0045-ce35-2702caf66c18</loadBalancerId><loadBalancerName>Load Balancer</loadBalancerName><loadBalancerAlgorithm>ROUND_ROBIN</loadBalancerAlgorithm><internetAccess>false</internetAccess><ip>10.14.186.225</ip><lanId>1</lanId><balancedServers><activate>true</activate><balancedNicId>7f3a83fd-d158-5add-cb22-0cc6590f8791</balancedNicId><serverId>05a17c46-3040-d1af-bb01-9579fe0300e7</serverId><serverName>Server 1</serverName></balancedServers><provisioningState>AVAILABLE</provisioningState><creationTime>2012-04-10T17:15:00.529Z</creationTime><lastModificationTime>2012-04-10T17:15:00.529Z</lastModificationTime><firewall><active>false</active><firewallId>aa5e5270-1e6d-6e3a-ba7b-0b1f2d9e2425</firewallId><nicId>5a6e677b-c0c1-93c3-38e1-7cda5eef6015</nicId><provisioningState>AVAILABLE</provisioningState></firewall></loadBalancers><provisioningState>AVAILABLE</provisioningState></return></ns2:getDataCenterResponse></S:Body></S:Envelope>
@@ -0,0 +1,24 @@
1
+ {
2
+ "get_firewall_response": {
3
+ "@xmlns:ns2": "http://ws.api.profitbricks.com/",
4
+ "return": {
5
+ "active": false,
6
+ "firewall_id": "33f4e0a5-41d9-eb57-81d1-24854ed89834",
7
+ "firewall_rules": [
8
+ {
9
+ "firewall_rule_id": "77e8e8bd-5b72-b657-e97b-c010937cefdf",
10
+ "protocol": "ANY",
11
+ "target_ip": "10.14.186.225"
12
+ },
13
+ {
14
+ "firewall_rule_id": "3580cc62-41bb-46a8-8ce8-6a19fbbe884e",
15
+ "port_range_end": "80",
16
+ "port_range_start": "80",
17
+ "protocol": "TCP"
18
+ }
19
+ ],
20
+ "nic_id": "7f3a83fd-d158-5add-cb22-0cc6590f8791",
21
+ "provisioning_state": "AVAILABLE"
22
+ }
23
+ }
24
+ }
@@ -0,0 +1 @@
1
+ <?xml version='1.0' encoding='UTF-8'?><S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/"><S:Body><ns2:getFirewallResponse xmlns:ns2="http://ws.api.profitbricks.com/"><return><active>false</active><firewallId>33f4e0a5-41d9-eb57-81d1-24854ed89834</firewallId><firewallRules><firewallRuleId>77e8e8bd-5b72-b657-e97b-c010937cefdf</firewallRuleId><protocol>ANY</protocol><targetIp>10.14.186.225</targetIp></firewallRules><firewallRules><firewallRuleId>3580cc62-41bb-46a8-8ce8-6a19fbbe884e</firewallRuleId><protocol>TCP</protocol><portRangeStart>80</portRangeStart><portRangeEnd>80</portRangeEnd></firewallRules><nicId>7f3a83fd-d158-5add-cb22-0cc6590f8791</nicId><provisioningState>AVAILABLE</provisioningState></return></ns2:getFirewallResponse></S:Body></S:Envelope>
@@ -0,0 +1,16 @@
1
+ {
2
+ "get_load_balancer_response": {
3
+ "@xmlns:ns2": "http://ws.api.profitbricks.com/",
4
+ "return": {
5
+ "data_center_id": "69ab6ed3-8355-4c90-9501-6fa4b21ebfa3",
6
+ "data_center_version": "15",
7
+ "internet_access": false,
8
+ "ip": null,
9
+ "lan_id": "0",
10
+ "load_balancer_algorithm": "ROUND_ROBIN",
11
+ "load_balancer_id": "3e3cb642-4d50-4371-980a-65959b2fa428",
12
+ "load_balancer_name": "Test",
13
+ "provisioning_state": "INACTIVE"
14
+ }
15
+ }
16
+ }
@@ -0,0 +1 @@
1
+ <?xml version='1.0' encoding='UTF-8'?><S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/"><S:Body><ns2:getLoadBalancerResponse xmlns:ns2="http://ws.api.profitbricks.com/"><return><dataCenterId>69ab6ed3-8355-4c90-9501-6fa4b21ebfa3</dataCenterId><dataCenterVersion>15</dataCenterVersion><loadBalancerId>3e3cb642-4d50-4371-980a-65959b2fa428</loadBalancerId><loadBalancerName>Test</loadBalancerName><loadBalancerAlgorithm>ROUND_ROBIN</loadBalancerAlgorithm><internetAccess>false</internetAccess><ip></ip><lanId>0</lanId><provisioningState>INACTIVE</provisioningState></return></ns2:getLoadBalancerResponse></S:Body></S:Envelope>
@@ -0,0 +1,17 @@
1
+ {
2
+ "register_servers_on_load_balancer_response": {
3
+ "@xmlns:ns2": "http://ws.api.profitbricks.com/",
4
+ "return": {
5
+ "balanced_servers": {
6
+ "activate": true,
7
+ "balanced_nic_id": "050aeccd-bc3c-416a-aa8a-da90ad6e8a2e",
8
+ "server_id": "206d10f2-035f-4ef2-8d24-3022653e9706",
9
+ "server_name": "Webserver"
10
+ },
11
+ "data_center_id": "69ab6ed3-8355-4c90-9501-6fa4b21ebfa3",
12
+ "data_center_version": "20",
13
+ "lan_id": "7",
14
+ "load_balancer_id": "3e3cb642-4d50-4371-980a-65959b2fa428"
15
+ }
16
+ }
17
+ }
@@ -0,0 +1 @@
1
+ <?xml version='1.0' encoding='UTF-8'?><S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/"><S:Body><ns2:registerServersOnLoadBalancerResponse xmlns:ns2="http://ws.api.profitbricks.com/"><return><dataCenterId>69ab6ed3-8355-4c90-9501-6fa4b21ebfa3</dataCenterId><dataCenterVersion>20</dataCenterVersion><loadBalancerId>3e3cb642-4d50-4371-980a-65959b2fa428</loadBalancerId><lanId>7</lanId><balancedServers><activate>true</activate><balancedNicId>050aeccd-bc3c-416a-aa8a-da90ad6e8a2e</balancedNicId><serverId>206d10f2-035f-4ef2-8d24-3022653e9706</serverId><serverName>Webserver</serverName></balancedServers></return></ns2:registerServersOnLoadBalancerResponse></S:Body></S:Envelope>
@@ -0,0 +1,10 @@
1
+ {
2
+ "remove_firewall_rules_response": {
3
+ "@xmlns:ns2": "http://ws.api.profitbricks.com/",
4
+ "return": {
5
+ "data_center_id": "69ab6ed3-8355-4c90-9501-6fa4b21ebfa3",
6
+ "data_center_version": "50",
7
+ "request_id": "2223"
8
+ }
9
+ }
10
+ }
@@ -0,0 +1 @@
1
+ <?xml version='1.0' encoding='UTF-8'?><S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/"><S:Body><ns2:removeFirewallRulesResponse xmlns:ns2="http://ws.api.profitbricks.com/"><return><requestId>2223</requestId><dataCenterId>69ab6ed3-8355-4c90-9501-6fa4b21ebfa3</dataCenterId><dataCenterVersion>50</dataCenterVersion></return></ns2:removeFirewallRulesResponse></S:Body></S:Envelope>
@@ -0,0 +1,10 @@
1
+ {
2
+ "update_load_balancer_response": {
3
+ "@xmlns:ns2": "http://ws.api.profitbricks.com/",
4
+ "return": {
5
+ "data_center_id": "69ab6ed3-8355-4c90-9501-6fa4b21ebfa3",
6
+ "data_center_version": "18",
7
+ "request_id": "2185"
8
+ }
9
+ }
10
+ }
@@ -0,0 +1 @@
1
+ <?xml version='1.0' encoding='UTF-8'?><S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/"><S:Body><ns2:updateLoadBalancerResponse xmlns:ns2="http://ws.api.profitbricks.com/"><return><requestId>2185</requestId><dataCenterId>69ab6ed3-8355-4c90-9501-6fa4b21ebfa3</dataCenterId><dataCenterVersion>18</dataCenterVersion></return></ns2:updateLoadBalancerResponse></S:Body></S:Envelope>
@@ -0,0 +1,49 @@
1
+ require 'spec_helper'
2
+ require 'json'
3
+
4
+ describe Profitbricks::Firewall do
5
+ include Savon::Spec::Macros
6
+ let(:dc) { DataCenter.new(JSON.parse(File.open('spec/fixtures/get_data_center/firewall.json').read)["get_data_center_response"]["return"])}
7
+
8
+ it "should add new rules to a firewall of a load balancer" do
9
+ savon.expects(:add_firewall_rules_to_load_balancer).returns(:success)
10
+ fw = dc.load_balancers.first.firewall
11
+ rule = FirewallRule.new(:port_range_start => 80, :port_range_end => 80, :protocol => 'TCP')
12
+ fw.add_rules([rule]).should == true
13
+ end
14
+
15
+ it "should add new rules to a firewall of a nic" do
16
+ savon.expects(:add_firewall_rules_to_nic).returns(:success)
17
+ fw = dc.servers.first.nics.first.firewall
18
+ rule = FirewallRule.new(:port_range_start => 80, :port_range_end => 80, :protocol => 'TCP')
19
+ fw.add_rules([rule]).should == true
20
+ end
21
+
22
+ it "should activate a firewall" do
23
+ savon.expects(:get_firewall).returns(:success)
24
+ savon.expects(:activate_firewalls).returns(:success)
25
+ fw = Firewall.find(:id => "33f4e0a5-41d9-eb57-81d1-24854ed89834")
26
+ fw.activate.should == true
27
+ end
28
+
29
+ it "should deactivate a firewall" do
30
+ savon.expects(:get_firewall).returns(:success)
31
+ savon.expects(:deactivate_firewalls).returns(:success)
32
+ fw = Firewall.find(:id => "33f4e0a5-41d9-eb57-81d1-24854ed89834")
33
+ fw.deactivate.should == true
34
+ end
35
+
36
+ it "should delete a firewall" do
37
+ savon.expects(:get_firewall).returns(:success)
38
+ savon.expects(:delete_firewalls).returns(:success)
39
+ fw = Firewall.find(:id => "33f4e0a5-41d9-eb57-81d1-24854ed89834")
40
+ fw.delete.should == true
41
+ end
42
+
43
+ it "should delete a firewall rule" do
44
+ savon.expects(:get_firewall).returns(:success)
45
+ savon.expects(:remove_firewall_rules).returns(:success)
46
+ fw = Firewall.find(:id => "33f4e0a5-41d9-eb57-81d1-24854ed89834")
47
+ fw.rules.first.delete.should == true
48
+ end
49
+ end
@@ -0,0 +1,60 @@
1
+ require 'spec_helper'
2
+
3
+ describe Profitbricks::LoadBalancer do
4
+ include Savon::Spec::Macros
5
+ let(:servers) { [Server.new(:id => "206d10f2-035f-4ef2-8d24-3022653e9706")]}
6
+
7
+ it "create a new LoadBalancer" do
8
+ savon.expects(:create_load_balancer).returns(:success)
9
+ savon.expects(:get_load_balancer).returns(:success)
10
+ lb = LoadBalancer.create(:data_center_id => "1111", :name => "Test", :servers => servers, :algorithm => 'ROUND_ROBIN')
11
+ lb.name.should == "Test"
12
+ lb.lan_id.should == 0
13
+ lb.algorithm.should == "ROUND_ROBIN"
14
+ end
15
+
16
+ it "should update an existing LoadBalancer" do
17
+ savon.expects(:get_load_balancer).returns(:success)
18
+ savon.expects(:update_load_balancer).returns(:success)
19
+ savon.expects(:get_load_balancer).returns(:success)
20
+ lb = LoadBalancer.find(:id => "5dadd2b2-3405-4ec5-a450-0df497bebab0")
21
+ lb.update(:name => "Wee").should == true
22
+ # FIXME seems to be a bug in the API
23
+ lb.name.should == "Test"
24
+ end
25
+
26
+ it "should be deleted" do
27
+ savon.expects(:get_load_balancer).returns(:success)
28
+ savon.expects(:delete_load_balancer).returns(:success)
29
+ lb = LoadBalancer.find(:id => "5dadd2b2-3405-4ec5-a450-0df497bebab0")
30
+ lb.delete.should == true
31
+ end
32
+
33
+ it "should register a server" do
34
+ savon.expects(:get_load_balancer).returns(:success)
35
+ savon.expects(:register_servers_on_load_balancer).returns(:success)
36
+ lb = LoadBalancer.find(:id => "5dadd2b2-3405-4ec5-a450-0df497bebab0")
37
+ lb.register_servers(servers).should == true
38
+ end
39
+
40
+ it "should deregister a server" do
41
+ savon.expects(:get_load_balancer).returns(:success)
42
+ savon.expects(:deregister_servers_on_load_balancer).returns(:success)
43
+ lb = LoadBalancer.find(:id => "5dadd2b2-3405-4ec5-a450-0df497bebab0")
44
+ lb.deregister_servers(servers).should == true
45
+ end
46
+
47
+ it "should activate a server" do
48
+ savon.expects(:get_load_balancer).returns(:success)
49
+ savon.expects(:activate_load_balancing_on_servers).returns(:success)
50
+ lb = LoadBalancer.find(:id => "5dadd2b2-3405-4ec5-a450-0df497bebab0")
51
+ lb.activate_servers(servers).should == true
52
+ end
53
+
54
+ it "should deactivate a server" do
55
+ savon.expects(:get_load_balancer).returns(:success)
56
+ savon.expects(:deactivate_load_balancing_on_servers).returns(:success)
57
+ lb = LoadBalancer.find(:id => "5dadd2b2-3405-4ec5-a450-0df497bebab0")
58
+ lb.deactivate_servers(servers).should == true
59
+ end
60
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: profitbricks
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.5
4
+ version: 0.4.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-03-07 00:00:00.000000000 Z
12
+ date: 2012-04-10 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: savon
16
- requirement: &21814460 !ruby/object:Gem::Requirement
16
+ requirement: &11811440 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: '0'
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *21814460
24
+ version_requirements: *11811440
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: rdoc
27
- requirement: &21813680 !ruby/object:Gem::Requirement
27
+ requirement: &11810820 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ~>
@@ -32,10 +32,10 @@ dependencies:
32
32
  version: '3.10'
33
33
  type: :development
34
34
  prerelease: false
35
- version_requirements: *21813680
35
+ version_requirements: *11810820
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: hoe
38
- requirement: &21813080 !ruby/object:Gem::Requirement
38
+ requirement: &11810240 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ~>
@@ -43,12 +43,8 @@ dependencies:
43
43
  version: '2.15'
44
44
  type: :development
45
45
  prerelease: false
46
- version_requirements: *21813080
47
- description: ! 'A Ruby client for the ProfitBricks API.
48
-
49
-
50
- BE AWARE: This software is in a very early state of development, the methods and
51
- responses will very likely change over time.'
46
+ version_requirements: *11810240
47
+ description: A Ruby client for the ProfitBricks API.
52
48
  email:
53
49
  - git@dsander.de
54
50
  executables:
@@ -72,14 +68,25 @@ files:
72
68
  - lib/profitbricks/config.rb
73
69
  - lib/profitbricks/data_center.rb
74
70
  - lib/profitbricks/extensions.rb
71
+ - lib/profitbricks/firewall.rb
75
72
  - lib/profitbricks/image.rb
76
73
  - lib/profitbricks/ip_block.rb
74
+ - lib/profitbricks/load_balancer.rb
77
75
  - lib/profitbricks/model.rb
78
76
  - lib/profitbricks/nic.rb
79
77
  - lib/profitbricks/profitbricks.rb
78
+ - lib/profitbricks/rule.rb
80
79
  - lib/profitbricks/server.rb
81
80
  - lib/profitbricks/storage.rb
82
81
  - profitbricks.gemspec
82
+ - spec/fixtures/activate_firewalls/success.json
83
+ - spec/fixtures/activate_firewalls/success.xml
84
+ - spec/fixtures/activate_load_balancing_on_servers/success.json
85
+ - spec/fixtures/activate_load_balancing_on_servers/success.xml
86
+ - spec/fixtures/add_firewall_rules_to_load_balancer/success.json
87
+ - spec/fixtures/add_firewall_rules_to_load_balancer/success.xml
88
+ - spec/fixtures/add_firewall_rules_to_nic/success.json
89
+ - spec/fixtures/add_firewall_rules_to_nic/success.xml
83
90
  - spec/fixtures/add_public_ip_to_nic/success.json
84
91
  - spec/fixtures/add_public_ip_to_nic/success.xml
85
92
  - spec/fixtures/clear_data_center/success.json
@@ -88,14 +95,24 @@ files:
88
95
  - spec/fixtures/connect_storage_to_server/success.xml
89
96
  - spec/fixtures/create_data_center/success.json
90
97
  - spec/fixtures/create_data_center/success.xml
98
+ - spec/fixtures/create_load_balancer/success.json
99
+ - spec/fixtures/create_load_balancer/success.xml
91
100
  - spec/fixtures/create_nic/success.json
92
101
  - spec/fixtures/create_nic/success.xml
93
102
  - spec/fixtures/create_server/minimal.json
94
103
  - spec/fixtures/create_server/minimal.xml
95
104
  - spec/fixtures/create_storage/success.json
96
105
  - spec/fixtures/create_storage/success.xml
106
+ - spec/fixtures/deactivate_firewalls/success.json
107
+ - spec/fixtures/deactivate_firewalls/success.xml
108
+ - spec/fixtures/deactivate_load_balancing_on_servers/success.json
109
+ - spec/fixtures/deactivate_load_balancing_on_servers/success.xml
97
110
  - spec/fixtures/delete_data_center/success.json
98
111
  - spec/fixtures/delete_data_center/success.xml
112
+ - spec/fixtures/delete_firewalls/success.json
113
+ - spec/fixtures/delete_firewalls/success.xml
114
+ - spec/fixtures/delete_load_balancer/success.json
115
+ - spec/fixtures/delete_load_balancer/success.xml
99
116
  - spec/fixtures/delete_nic/success.json
100
117
  - spec/fixtures/delete_nic/success.xml
101
118
  - spec/fixtures/delete_server/success.json
@@ -104,6 +121,8 @@ files:
104
121
  - spec/fixtures/delete_storage/failture.xml
105
122
  - spec/fixtures/delete_storage/success.json
106
123
  - spec/fixtures/delete_storage/success.xml
124
+ - spec/fixtures/deregister_servers_on_load_balancer/success.json
125
+ - spec/fixtures/deregister_servers_on_load_balancer/success.xml
107
126
  - spec/fixtures/disconnect_storage_from_server/failture.json
108
127
  - spec/fixtures/disconnect_storage_from_server/failture.xml
109
128
  - spec/fixtures/disconnect_storage_from_server/success.json
@@ -118,14 +137,20 @@ files:
118
137
  - spec/fixtures/get_all_public_ip_blocks/success.xml
119
138
  - spec/fixtures/get_data_center/create.json
120
139
  - spec/fixtures/get_data_center/create.xml
140
+ - spec/fixtures/get_data_center/firewall.json
141
+ - spec/fixtures/get_data_center/firewall.xml
121
142
  - spec/fixtures/get_data_center/two_servers_with_storage.json
122
143
  - spec/fixtures/get_data_center/two_servers_with_storage.xml
123
144
  - spec/fixtures/get_data_center_state/in_process.json
124
145
  - spec/fixtures/get_data_center_state/in_process.xml
125
146
  - spec/fixtures/get_data_center_state/success.json
126
147
  - spec/fixtures/get_data_center_state/success.xml
148
+ - spec/fixtures/get_firewall/success.json
149
+ - spec/fixtures/get_firewall/success.xml
127
150
  - spec/fixtures/get_image/success.json
128
151
  - spec/fixtures/get_image/success.xml
152
+ - spec/fixtures/get_load_balancer/success.json
153
+ - spec/fixtures/get_load_balancer/success.xml
129
154
  - spec/fixtures/get_nic/success.json
130
155
  - spec/fixtures/get_nic/success.xml
131
156
  - spec/fixtures/get_nic/two_ips.json
@@ -138,8 +163,12 @@ files:
138
163
  - spec/fixtures/get_storage/success.xml
139
164
  - spec/fixtures/reboot_server/success.json
140
165
  - spec/fixtures/reboot_server/success.xml
166
+ - spec/fixtures/register_servers_on_load_balancer/success.json
167
+ - spec/fixtures/register_servers_on_load_balancer/success.xml
141
168
  - spec/fixtures/release_public_ip_block/success.json
142
169
  - spec/fixtures/release_public_ip_block/success.xml
170
+ - spec/fixtures/remove_firewall_rules/success.json
171
+ - spec/fixtures/remove_firewall_rules/success.xml
143
172
  - spec/fixtures/remove_public_ip_from_nic/success.json
144
173
  - spec/fixtures/remove_public_ip_from_nic/success.xml
145
174
  - spec/fixtures/reserve_public_ip_block/success.json
@@ -150,6 +179,8 @@ files:
150
179
  - spec/fixtures/set_internet_access/success.xml
151
180
  - spec/fixtures/update_data_center/success.json
152
181
  - spec/fixtures/update_data_center/success.xml
182
+ - spec/fixtures/update_load_balancer/success.json
183
+ - spec/fixtures/update_load_balancer/success.xml
153
184
  - spec/fixtures/update_nic/success.json
154
185
  - spec/fixtures/update_nic/success.xml
155
186
  - spec/fixtures/update_server/basic.json
@@ -157,8 +188,10 @@ files:
157
188
  - spec/fixtures/update_storage/success.json
158
189
  - spec/fixtures/update_storage/success.xml
159
190
  - spec/profitbricks/data_center_spec.rb
191
+ - spec/profitbricks/firewall_spec.rb
160
192
  - spec/profitbricks/image_spec.rb
161
193
  - spec/profitbricks/ip_block_spec.rb
194
+ - spec/profitbricks/load_balancer_spec.rb
162
195
  - spec/profitbricks/model_spec.rb
163
196
  - spec/profitbricks/nic_spec.rb
164
197
  - spec/profitbricks/server_spec.rb
@@ -190,5 +223,5 @@ rubyforge_project: profitbricks
190
223
  rubygems_version: 1.8.11
191
224
  signing_key:
192
225
  specification_version: 3
193
- summary: A Ruby client for the ProfitBricks API
226
+ summary: A Ruby client for the ProfitBricks API.
194
227
  test_files: []