Adds profitbricks driver
diff --git a/NOTICE b/NOTICE
index fad0b4b..74f0e40 100644
--- a/NOTICE
+++ b/NOTICE
@@ -20,3 +20,6 @@
 
 This product includes software developed by Christian Neukirchen
 (https://github.com/rack/rack)
+
+This product includes software developed by ProfitBricks GmbH
+(https://profitbricks.com/)
diff --git a/server/Gemfile b/server/Gemfile
index ad0d8e5..1864823 100644
--- a/server/Gemfile
+++ b/server/Gemfile
@@ -23,6 +23,7 @@
 gem 'savon'
 gem 'rbvmomi'
 gem 'rbovirt', '>=0.0.19'
+gem "profitbricks", '~> 1.0.3'
 
 platform :mri do
   gem 'sqlite3'
diff --git a/server/Rakefile b/server/Rakefile
index 6045173..bb2ab69 100644
--- a/server/Rakefile
+++ b/server/Rakefile
@@ -152,7 +152,7 @@
 if RUBY_PLATFORM == 'java'
   DRIVERS = [:mock, :ec2, :rhevm, :gogrid, :openstack, :fgcp]
 else
-  DRIVERS = [:mock, :ec2, :rhevm, :google, :gogrid, :openstack, :fgcp]
+  DRIVERS = [:mock, :ec2, :rhevm, :google, :gogrid, :openstack, :fgcp, :profitbricks]
 end
 
 desc 'Run all tests'
diff --git a/server/config/drivers/profitbricks.yaml b/server/config/drivers/profitbricks.yaml
new file mode 100644
index 0000000..1211499
--- /dev/null
+++ b/server/config/drivers/profitbricks.yaml
@@ -0,0 +1,3 @@
+---
+:profitbricks:
+  :name: Profitbricks
diff --git a/server/deltacloud-core.gemspec b/server/deltacloud-core.gemspec
index d2e3b1b..866f5c2 100644
--- a/server/deltacloud-core.gemspec
+++ b/server/deltacloud-core.gemspec
@@ -124,6 +124,7 @@
   # VSphere
   s.add_dependency('rbvmomi')
 
-
+  # Profitbricks
+  s.add_dependency('profitbricks')
 
 end
diff --git a/server/lib/deltacloud/collections/addresses.rb b/server/lib/deltacloud/collections/addresses.rb
index fb877d8..b6ffb33 100644
--- a/server/lib/deltacloud/collections/addresses.rb
+++ b/server/lib/deltacloud/collections/addresses.rb
@@ -22,7 +22,7 @@
       @address = driver.address(credentials, params )
       @instances = driver.instances(credentials)
       respond_to do |format|
-        format.html {haml :"addresses/associate"}
+        format.html {haml :"addresses/associate", :locals => {:address => @address, :instances => @instances}}
       end
     end
 
diff --git a/server/lib/deltacloud/collections/instances.rb b/server/lib/deltacloud/collections/instances.rb
index 6038bee..468b915 100644
--- a/server/lib/deltacloud/collections/instances.rb
+++ b/server/lib/deltacloud/collections/instances.rb
@@ -30,7 +30,7 @@
       if params[:realm_id]
         @opts[:realms] = [ Deltacloud::Realm.new(:id => params[:realm_id]) ] if params[:realm_id]
       else
-        @opts[:realms] = driver.realms(credentials)
+        @opts[:realms] = driver.realms(credentials, :image => @opts[:image])
       end
       if driver.class.has_feature?(:instances, :firewalls)
         @opts[:firewalls] = driver.firewalls(credentials)
diff --git a/server/lib/deltacloud/collections/storage_volumes.rb b/server/lib/deltacloud/collections/storage_volumes.rb
index b3a2958..7d03f81 100644
--- a/server/lib/deltacloud/collections/storage_volumes.rb
+++ b/server/lib/deltacloud/collections/storage_volumes.rb
@@ -24,9 +24,9 @@
     new_route_for(:storage_volumes)
 
     get "/storage_volumes/:id/attach_instance" do
-      @opts[:instances] = driver.instances(credentials)
+      @instances = driver.instances(credentials, :storage_id => params[:id])
       respond_to do |format|
-        format.html{ haml :"storage_volumes/attach"}
+        format.html{ haml :"storage_volumes/attach", :locals => { :instances=> @instances }}
       end
     end
 
diff --git a/server/lib/deltacloud/drivers/profitbricks/profitbricks_driver.rb b/server/lib/deltacloud/drivers/profitbricks/profitbricks_driver.rb
new file mode 100644
index 0000000..df7d3c1
--- /dev/null
+++ b/server/lib/deltacloud/drivers/profitbricks/profitbricks_driver.rb
@@ -0,0 +1,638 @@
+#
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements.  See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.  The
+# ASF licenses this file to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance with the
+# License.  You may obtain a copy of the License at
+#
+#       http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
+# License for the specific language governing permissions and limitations
+# under the License.
+
+require 'rubygems'
+require 'profitbricks'
+
+module Deltacloud
+  module Drivers
+    module Profitbricks
+
+class ProfitbricksDriver < Deltacloud::BaseDriver
+
+  define_hardware_profile('default') do
+    cpu              1..48,                            :default => 1
+    memory           (1..196*4).collect { |i| i*256 }, :default => 1024
+    storage          20..2048,                         :default => 50
+    architecture     'x86_64'
+  end
+
+  def images(credentials, opts = {})
+    new_client(credentials)
+    results = []
+    safely do
+      #get all HDD images - filter by HDD, because only HDD images can be attached to a storage
+      results = ::Profitbricks::Image.all.select { | img | img.type == 'HDD'}.collect do | img |
+        Image.new(
+            :id => img.id,
+            :name => img.name,
+            :description => "CPU Hot-Plugging: #{img.cpu_hotpluggable}, Region: #{img.region}, Os: (#{img.os_type}), Type: #{img.type}",
+            :owner_id => credentials.user,
+            :state => 'AVAILABLE',
+            :architecture => 'x86_64',
+        )
+      end
+    end
+    # Add hardware profiles to each image
+    profiles = hardware_profiles(credentials)
+    results.each { |img| img.hardware_profiles = profiles }
+    filter_on( results, opts, :id, :region, :name)
+  end
+
+  def realms(credentials, opts = {})
+    new_client(credentials)
+    results = []
+    safely do
+      datacenters = if opts[:image] != nil
+        ::Profitbricks::DataCenter.all.select { |dc| opts[:image].description.include? dc.region }
+      else
+        ::Profitbricks::DataCenter.all
+      end
+      results = datacenters.collect do |data_center|
+        convert_data_center(data_center)
+      end
+    end
+    filter_on(results, :id, opts)
+  end
+
+  def instances(credentials, opts = {})
+    new_client(credentials)
+
+    results = safely do
+      if opts[:storage_id]
+        storage = ::Profitbricks::Storage.find(:id => opts[:storage_id])
+        ::Profitbricks::DataCenter.find(:id => storage.data_center_id).servers.collect do |s|
+          convert_instance(s, credentials.user)
+        end
+      else
+        ::Profitbricks::Server.all.collect do |s|
+          convert_instance(s, credentials.user)
+        end
+      end
+    end
+    filter_on(results, opts, :id, :state, :realm_id)
+    results
+  end
+
+  def create_instance( credentials, image_id, opts)
+    new_client(credentials)
+    params = {}
+    storage = nil
+    server = nil
+
+    safely do
+      #Create storage first
+      if opts[:hwp_storage]
+        params[:name] = "Storage#{rand(1000)}"
+        params[:size] = opts.delete("hwp_storage")
+        params[:mount_image_id] = opts.delete("image_id")
+        if opts[:realm_id]
+          params[:data_center_id] = opts[:realm_id]
+        end
+        storage = convert_storage(::Profitbricks::Storage.create(params))
+      end
+
+      #Create instange
+      opts.delete("hwp_id");
+      opts[:name] = opts.delete('name');
+      opts[:name] = opts[:name] == "" ? "Sever#{rand(1000)}" : opts[:name]
+      opts[:ram] = opts.delete("hwp_memory")
+      opts[:cores] = opts.delete("hwp_cpu")
+      opts[:availability_zone] = "AUTO"
+      opts[:internet_access] = true
+      opts[:lan_id] = "1"
+      if storage.respond_to?('id')
+        opts[:boot_from_storage_id] = storage.id
+      end
+      opts[:data_center_id] = opts.delete("realm_id")
+      if opts[:data_center_id] == nil && storage.respond_to?('realm_id')
+        opts[:data_center_id] = storage.realm_id
+      end
+      server = convert_instance(::Profitbricks::Server.create(opts), credentials.user)
+    end
+    server
+  end
+
+
+  def reboot_instance( credentials, instance_id )
+    new_client(credentials)
+    safely do
+      server = ::Profitbricks::Server.find(:id => instance_id)
+      server.reset
+    end
+  end
+
+  def stop_instance( credentials, instance_id )
+    new_client(credentials)
+    safely do
+      server = ::Profitbricks::Server.find(:id => instance_id)
+      server.stop
+    end
+  end
+
+  def start_instance( credentials, instance_id )
+    new_client(credentials)
+    safely do
+      server = ::Profitbricks::Server.find(:id => instance_id)
+      server.start
+    end
+  end
+
+  def destroy_instance( credentials, instance_id )
+    new_client(credentials)
+    safely do
+      server = ::Profitbricks::Server.find(:id => instance_id)
+      server.delete
+    end
+  end
+
+
+  def storage_volumes( credentials, opts = {} )
+    new_client(credentials)
+    results = safely do
+      if opts[:id]
+        [convert_storage(::Profitbricks::Storage.find(:id => opts[:id]))]
+      else
+        ::Profitbricks::DataCenter.all.collect do |data_center|
+          (data_center.storages || []).collect do |storage|
+            convert_storage(storage)
+          end.flatten
+        end.flatten
+      end
+    end
+    results
+  end
+
+
+  def create_storage_volume(credentials, opts = {})
+    new_client(credentials)
+    result = nil
+    params = {}
+    safely do
+      opts[:size] = opts.delete("capacity") || 1
+      opts[:data_center_id] = opts.delete("realm_id") unless (opts["realm_id"].nil? || opts["realm_id"].empty?)
+      opts[:name] = opts.delete("name") || "Storage#{rand(1000)}"
+      opts.delete("commit")
+      opts.delete("snapshot_id")
+      opts.delete("description")
+      result = convert_storage(::Profitbricks::Storage.create(opts))
+    end
+    result
+  end
+
+  def destroy_storage_volume(credentials, opts = {})
+    new_client( credentials )
+    safely do
+      storage = ::Profitbricks::Storage.find(:id => opts[:id])
+      storage.delete
+    end
+  end
+
+  def attach_storage_volume( credentials, opts = {} )
+    new_client( credentials )
+    safely do
+      storage = ::Profitbricks::Storage.find(:id => opts[:id])
+      storage.connect(:server_id => opts[:instance_id])
+    end
+  end
+
+  def detach_storage_volume(credentials, opts = {})
+    new_client( credentials )
+    safely do
+      storage = ::Profitbricks::Storage.find(:id => opts[:id])
+      storage.disconnect(:server_id => opts[:instance_id])
+    end
+  end
+
+  def create_load_balancer(credentials, opts={})
+    new_client(credentials)
+    safely do
+      load_balancer = ::Profitbricks::LoadBalancer.create(:name => opts[:name], :data_center_id => opts[:realm_id])
+      load_balancer(credentials, :id => load_balancer.id)
+    end
+  end
+
+  def load_balancer(credentials, opts = {})
+    new_client(credentials)
+    safely do
+      load_balancer = ::Profitbricks::LoadBalancer.find(:id => opts[:id])
+      data_center = ::Profitbricks::DataCenter.find(:id => load_balancer.data_center_id)
+      convert_load_balancer(load_balancer, data_center)
+    end
+  end
+
+  def load_balancers(credentials, opts = {})
+    new_client(credentials)
+    safely do
+      ::Profitbricks::DataCenter.all.collect do |data_center|
+        (data_center.load_balancers || []).collect do |lb|
+          convert_load_balancer(lb, data_center)
+        end.flatten
+      end.flatten
+    end
+  end
+
+  def lb_register_instance(credentials, opts={})
+    new_client(credentials)
+    safely do
+      load_balancer = ::Profitbricks::LoadBalancer.find(:id => opts[:id])
+      server        = ::Profitbricks::Server.find(:id => opts[:instance_id])
+      load_balancer.register_servers([server])
+      load_balancer(credentials, :id => opts[:id])
+    end
+  end
+
+  def lb_unregister_instance(credentials, opts={})
+    new_client(credentials)
+    safely do
+      load_balancer = ::Profitbricks::LoadBalancer.find(:id => opts[:id])
+      server        = ::Profitbricks::Server.find(:id => opts[:instance_id])
+      load_balancer.deregister_servers([server])
+      load_balancer(credentials, :id => opts[:id])
+    end
+  end
+
+  def destroy_load_balancer(credentials, id)
+    new_client(credentials)
+    safely do
+      load_balancer = ::Profitbricks::LoadBalancer.find(:id => id)
+      load_balancer.delete
+    end
+  end
+
+  def firewalls(credentials, opts={})
+    new_client(credentials)
+    safely do
+      ::Profitbricks::Server.all.collect do |server|
+        (server.nics || []).collect do |nic|
+          convert_firewall(nic.firewall) if nic.firewall
+        end.flatten.compact
+      end.flatten
+    end
+  end
+
+  def create_firewall(credentials, opts={})
+    # TODO is this even possible?
+    raise "Error"
+  end
+
+  def delete_firewall(credentials, opts={})
+    new_client(credentials)
+    safely do
+      firewall = ::Profitbricks::Firewall.find(:id => opts[:id])
+      firewall.delete
+    end
+  end
+
+  def create_firewall_rule(credentials, opts={})
+    new_client(credentials)
+    safely do
+      firewall = ::Profitbricks::Firewall.find(:id => opts[:id])
+      rules = opts[:addresses].collect do |source_ip|
+        ::Profitbricks::FirewallRule.new({
+          :protocol => opts[:protocol],
+          :port_range_start => opts[:port_from],
+          :port_range_end => opts[:port_to],
+          :source_ip => source_ip.split('/').first,
+          :target_ip => '0.0.0.0'
+        })
+      end
+      firewall.add_rules(rules)
+    end
+  end
+
+  def delete_firewall_rule(credentials, opts={})
+    new_client(credentials)
+    safely do
+      ::Profitbricks::Firewall.find(:id => opts[:firewall]).rules.select { |rule|
+        rule.id == opts[:rule_id]
+      }.first.delete
+    end
+  end
+
+  def address(credentials, opts={})
+    new_client(credentials)
+    servers = safely do
+      ::Profitbricks::Server.all()
+    end
+    convert_ip_block(find_ip_block_by_ip(opts[:id]), servers)
+  end
+
+  def addresses(credentials, opts={})
+    new_client(credentials)
+    safely do
+      servers = ::Profitbricks::Server.all()
+      ::Profitbricks::IpBlock.all().collect do |ip_block|
+        convert_ip_block(ip_block, servers)
+      end
+    end
+  end
+
+  def create_address(credentials, opts={})
+    new_client(credentials)
+    safely do
+      convert_ip_block(::Profitbricks::IpBlock.reserve(1))
+    end
+  end
+
+  def destroy_address(credentials, opts={})
+    new_client(credentials)
+    safely do
+      ip_block = find_ip_block_by_ip(opts[:id])
+      ip_block.release
+    end
+  end
+
+  def associate_address(credentials, opts={})
+    new_client(credentials)
+    safely do
+      ip_block = find_ip_block_by_ip(opts[:id])
+      server = ::Profitbricks::Server.find(:id => opts[:instance_id])
+      server.nics.first.add_ip(opts[:id])
+      convert_ip_block(ip_block)
+    end
+  end
+
+  def disassociate_address(credentials, opts={})
+    new_client(credentials)
+    safely do
+      ip_block = find_ip_block_by_ip(opts[:id])
+      servers = ::Profitbricks::Server.all()
+      result = convert_ip_block(ip_block, servers)
+      server = ::Profitbricks::Server.find(:id => result.instance_id)
+      server.nics.first.remove_ip(opts[:id])
+      result
+    end
+  end
+
+  def network_interfaces(credentials, opts = {})
+    new_client(credentials)
+    safely do
+      ::Profitbricks::Server.all.select { | server| server.nics!=nil}.collect do |server|
+        server.nics.collect do |nic|
+          convert_network_interface(nic)
+        end.flatten
+      end.flatten
+    end
+  end
+
+  def create_network_interface(credentials, opts={})
+    new_client(credentials)
+    safely do
+      opts[:server_id] = opts.delete("instance");
+      opts[:lan_id] = opts[:network].nil?? "1" : opts.delete("network");
+      opts[:name] = opts[:name].nil?? "eth#{rand(100)}" : opts.delete("name");
+      convert_network_interface(::Profitbricks::Nic.create(opts))
+    end
+  end
+
+  def destroy_network_interface(credentials, nic_id)
+    new_client(credentials)
+    safely do
+      nic = ::Profitbricks::Nic.find({:id => nic_id})
+      nic.delete
+    end
+  end
+
+  def networks(credentials, opts = {})
+    new_client(credentials)
+    safely do
+      ::Profitbricks::Server.all.select { | server| server.nics!=nil}.collect do |server|
+        server.nics.collect do |nic|
+          Network.new({
+            :id => nic.lan_id,
+            :name => "Lan #{nic.lan_id} (Datacenter #{server.data_center_id})"
+          })
+        end.flatten
+      end.flatten
+    end
+  end
+
+  define_instance_states do
+    start.to( :pending )          .automatically
+    pending.to( :running )        .automatically
+
+    stopped.to( :running )        .on( :start )
+    stopped.to( :stopped )        .on( :destroy )
+
+    running.to( :running )        .on( :reboot )
+    running.to( :stopping )       .on( :stop )
+
+    stopping.to(:stopped)         .automatically
+    stopping.to(:finish)          .automatically
+    stopped.to( :finish )         .automatically
+  end
+
+  #
+  ### Private declarations
+  #
+
+  private
+
+  def convert_instance(server, user_name)
+    inst = Instance.new(
+      :id                => server.id,
+      :realm_id          => server.data_center_id,
+      :owner_id          => user_name,
+      :description       => server.name,
+      :name              => server.name,
+      :state             => convert_instance_state(server),
+      :architecture      => 'x86_64',
+      :image_id          => find_instance_image(server),
+      :instance_profile  => InstanceProfile::new('default'),
+      :public_addresses  => server.public_ips,
+      :private_addresses => server.private_ips,
+      :username          => nil,
+      :password          => nil,
+      :storage_volumes => convert_instance_storages_volumes(server)
+    )
+    inst.actions = instance_actions_for( inst.state )
+    inst
+  end
+
+  def convert_instance_state(server)
+    state = server.respond_to?('virtual_machine_state')? (server.provisioned?? server.virtual_machine_state : server.provisioning_state) : "ERROR"
+    case state
+      when /INPROCESS/
+        "PENDING"
+      when /SHUTOFF/
+        "STOPPED"
+      when /SHUTDOWN/
+        "STOPPED"
+      when /PAUSED/
+        "STOPPED"
+      when /INACTIVE/
+        "STOPPED"
+      when /CRASHED/
+        "ERROR"
+      when /NOSTATE/
+        "ERROR"
+      when /ERROR/
+        "ERROR"
+      when /RUNNING/
+        "RUNNING"
+      else
+        "UNKNOWN"
+    end
+  end
+
+  def convert_instance_storages_volumes(server)
+    return [] if server.connected_storages.nil?
+    server.connected_storages.collect { |s| {s.id => nil} }
+  end
+
+  def find_instance_image(server)
+    return nil if server.connected_storages.nil?
+    server.connected_storages.each do |s|
+      # FIXME due to the api not returning the bootDevice flag we just use the first image we find
+      storage = ::Profitbricks::Storage.find(id: s.id)
+      return storage.mount_image.id if storage.mount_image
+    end
+    return nil
+  end
+
+  def convert_storage (storage)
+    result = StorageVolume.new(
+        :id => storage.id,
+        :name => storage.respond_to?(:name) ? storage.name : 'unknown',
+        :description => "Capacity: #{storage.size}GB",
+        :state => convert_storage_state(storage),
+        :capacity => storage.size,
+        :realm_id => storage.data_center_id,
+        :actions => [:attach, :detach, :destroy]
+    )
+    if storage.respond_to?("server_ids")
+      result.instance_id= storage.server_ids
+    end
+    if storage.respond_to?("creation_time")
+      result.created = storage.creation_time
+    end
+    result
+  end
+
+  def convert_storage_state(storage)
+    state = storage.respond_to?('provisioning_state')? storage.provisioning_state : "ERROR"
+    case state
+      when /INPROCESS/
+        "PENDING"
+      when /INACTIVE/
+        "ERROR"
+      when /ERROR/
+        "ERROR"
+      when /AVAILABLE/
+        "AVAILABLE"
+      else
+        "UNKNOWN"
+    end
+  end
+
+  def convert_data_center(data_center)
+    Realm.new(
+      :id => data_center.id,
+      :name => "#{data_center.name} (#{data_center.region})",
+      :state => 'AVAILABLE', # ProfitBricks doesn't return the states when calling getAllDataCenters()
+      :limit => :unlimited
+    )
+  end
+
+  def convert_load_balancer(lb, dc)
+    realms = []
+    balancer = LoadBalancer.new({
+      :id => lb.id,
+      :name => lb.name,
+      :created_at => lb.creation_time,
+      :public_addresses => [lb.ip],
+      :realms => [convert_data_center(dc)],
+      :instances => lb.balanced_servers ? lb.balanced_servers.collect { |s| convert_instance(s, "") } : [],
+      :listeners => []
+    })
+    balancer
+  end
+
+  def convert_network_interface(nic)
+    net = NetworkInterface.new({
+      :id => nic.id,
+      :name => nic.name,
+      :state => "UP",
+      :instance => nic.server_id,
+      :network => nic.lan_id,
+      :ip_address => nic.ips.first
+    })
+  end
+
+  def convert_firewall(firewall)
+    Firewall.new({
+      :id => firewall.id,
+      :description => "Firewall of #{firewall.nic_id}",
+      :owner_id => firewall.nic_id,
+      :rules => firewall.rules ? firewall.rules.collect { |r| convert_firewall_rule(r)} : []
+    })
+  end
+
+  def convert_firewall_rule(rule)
+    FirewallRule.new({
+      :id => rule.id,
+      :allow_protocol => rule.protocol,
+      :port_from => rule.port_range_start,
+      :port_to => rule.port_range_end,
+      :sources => [{:type => "address", :family=>"ipv4",
+                    :address=>rule.source_ip,
+                    :prefix=>''}],
+      :direction => 'ingress',
+    })
+  end
+
+  def convert_ip_block(ip_block, servers = [])
+    server = servers.select do |server|
+      server.public_ips.include? ip_block.ips.first
+    end.first
+    Address.new({
+      :id => ip_block.ips.first,
+      :instance_id => server ? server.id : nil
+    })
+  end
+
+  def find_ip_block_by_ip(ip)
+    ::Profitbricks::IpBlock.all().each do |ip_block|
+      return ip_block if ip_block.ips.include? ip
+    end
+  end
+
+  def new_client(credentials)
+    client = nil
+    safely do
+      ::Profitbricks.configure do |config|
+        config.username = credentials.user
+        config.password = credentials.password
+      end
+    end
+  end
+
+  exceptions do
+    on /Failed to authenticate/ do
+      status 401
+    end
+
+    on /Error/ do
+      status 500
+    end
+  end
+end
+
+    end
+  end
+end
+
diff --git a/server/tests/drivers/profitbricks/address_test.rb b/server/tests/drivers/profitbricks/address_test.rb
new file mode 100644
index 0000000..c0ff30e
--- /dev/null
+++ b/server/tests/drivers/profitbricks/address_test.rb
@@ -0,0 +1,101 @@
+require 'rubygems'
+require 'require_relative' if RUBY_VERSION < '1.9'
+
+require_relative 'common.rb'
+
+describe 'Profitbricks addresses' do
+
+  before do
+    Deltacloud::Drivers::Profitbricks::ProfitbricksDriver.send(:public, *Deltacloud::Drivers::Profitbricks::ProfitbricksDriver.private_instance_methods)
+    @driver = Deltacloud::new(:profitbricks, credentials)
+
+    @ip_block = ::Profitbricks::IpBlock.new(:ips => ['127.0.0.1'])
+    @server = ::Profitbricks::Server.new(:id => '1234a',
+                                         :data_center_id => 'data-center-id',
+                                         :name => 'server',
+                                         :virtual_machine_state => 'INPROCESS',
+                                         :private_ips => nil,
+                                         :public_ips => ['127.0.0.1'],
+                                         :provisioning_state => 'AVAILABLE',
+                                         :connected_storages => {:id => 'storage'})
+    @credentials = MiniTest::Mock.new
+    @credentials.expect(:user, 'test')
+    @credentials.expect(:password, 'test')
+  end
+
+  it "must find all addresses" do
+    ::Profitbricks::Server.stub(:all, [@server]) do
+      ::Profitbricks::IpBlock.stub(:all, [@ip_block]) do
+        addresses = @driver.backend.addresses(@credentials)
+        addresses.class.must_equal Array
+        addresses.length.must_equal 1
+        addresses[0].id.must_equal '127.0.0.1'
+        addresses[0].instance_id.must_equal '1234a'
+      end
+    end
+  end
+
+  it "must find an adress by id" do
+    ::Profitbricks::Server.stub(:all, [@server]) do
+      ::Profitbricks::IpBlock.stub(:all, [@ip_block]) do
+        address = @driver.backend.address(@credentials, :id => '127.0.0.1')
+        address.class.must_equal Deltacloud::Address
+        address.id.must_equal '127.0.0.1'
+        address.instance_id.must_equal '1234a'
+      end
+    end
+  end
+  
+  it "muste create an address" do
+    ::Profitbricks::IpBlock.stub(:reserve, @ip_block) do
+      address = @driver.backend.create_address(@credentials)
+      address.class.must_equal Deltacloud::Address
+      address.id.must_equal '127.0.0.1'
+      address.instance_id.must_equal nil
+    end
+  end
+
+  it "must destroy an address" do
+    ip_block = MiniTest::Mock.new
+    ip_block.expect(:release, true)
+    ip_block.expect(:ips, ['127.0.0.1'])
+    ::Profitbricks::Server.stub(:all, [@server]) do
+      ::Profitbricks::IpBlock.stub(:all, [ip_block]) do
+        @driver.backend.destroy_address(@credentials,  :id => '127.0.0.1')
+      end
+    end
+  end
+
+  it "must associate an address" do
+    nic = MiniTest::Mock.new
+    nic.expect(:add_ip, true, ['127.0.0.1'])
+    server = MiniTest::Mock.new
+    server.expect(:nics, [nic])
+    ::Profitbricks::Server.stub(:find, server) do
+      ::Profitbricks::IpBlock.stub(:all, [@ip_block]) do
+        address = @driver.backend.associate_address(@credentials,  :id => '127.0.0.1', :instance_id => '1234a')
+        address.class.must_equal Deltacloud::Address
+        address.id.must_equal '127.0.0.1'
+        address.instance_id.must_equal nil
+      end
+    end
+  end
+
+  it "must associate an address" do
+    nic = MiniTest::Mock.new
+    nic.expect(:remove_ip, true, ['127.0.0.1'])
+    server = MiniTest::Mock.new
+    server.expect(:nics, [nic])
+    server.expect(:public_ips, [['127.0.0.1']])
+    ::Profitbricks::Server.stub(:all, [server]) do
+      ::Profitbricks::Server.stub(:find, server) do
+        ::Profitbricks::IpBlock.stub(:all, [@ip_block]) do
+        address = @driver.backend.disassociate_address(@credentials,  :id => '127.0.0.1')
+        address.class.must_equal Deltacloud::Address
+        address.id.must_equal '127.0.0.1'
+        address.instance_id.must_equal nil
+      end
+    end
+    end
+  end
+end
diff --git a/server/tests/drivers/profitbricks/common.rb b/server/tests/drivers/profitbricks/common.rb
new file mode 100644
index 0000000..a5b7f66
--- /dev/null
+++ b/server/tests/drivers/profitbricks/common.rb
@@ -0,0 +1,11 @@
+# Warning: RightHttpConnection has to be required before WebMock is required !!!
+# Lets require that:
+#require 'right_http_connection'
+#require 'vcr'
+
+require_relative '../../test_helper.rb'
+#require_relative '../../../lib/deltacloud/drivers/ec2/ec2_driver'
+
+def credentials
+  Deltacloud::Test::config.credentials('ec2')
+end
\ No newline at end of file
diff --git a/server/tests/drivers/profitbricks/conversion_test.rb b/server/tests/drivers/profitbricks/conversion_test.rb
new file mode 100644
index 0000000..b4167f3
--- /dev/null
+++ b/server/tests/drivers/profitbricks/conversion_test.rb
@@ -0,0 +1,145 @@
+require 'rubygems'
+require 'require_relative' if RUBY_VERSION < '1.9'
+
+require_relative 'common.rb'
+
+describe 'Profitbricks data conversions' do
+
+  before do
+    Deltacloud::Drivers::Profitbricks::ProfitbricksDriver.send(:public, *Deltacloud::Drivers::Profitbricks::ProfitbricksDriver.private_instance_methods)
+    @driver = Deltacloud::new(:profitbricks, credentials)
+    @dc = ::Profitbricks::DataCenter.new(:id => '1234a',
+                                        :name => 'test',
+                                        :region => 'EUROPE')
+    #@image = ::Profitbricks::Image.new(:id => '5678a')
+    @storage = ::Profitbricks::Storage.new(:id => '1234a',
+                                          :name => 'test',
+                                          :provisioning_state => 'INPROCESS',
+                                          :size => 20,
+                                          :data_center_id => '4321',
+                                          :creation_time => Time.now,
+                                          :server_ids => ['5678'],
+                                          :mount_image => {:id => '5678a'})
+    @lb = ::Profitbricks::LoadBalancer.new(:id => '5678a',
+                                          :name => 'test',
+                                          :creation_time => Time.now,
+                                          :ip => '127.0.0.1')
+    @nic = ::Profitbricks::Nic.new(:id => '1234a',
+                                   :name => 'test',
+                                   :server_id => 'server-id',
+                                   :lan_id => 1,
+                                   :ips => ['127.0.0.1'])
+    @fwr = ::Profitbricks::FirewallRule.new(:id => '1234a',
+                                            :protocol => 'TCP',
+                                            :port_range_start => 80,
+                                            :port_range_end => 81,
+                                            :source_ip => '0.0.0.0')
+    @fw = ::Profitbricks::Firewall.new(:id => '1234a',
+                                       :nic_id => '5678a',
+                                       :rules => [@fwr.attributes])
+    @ip_block = ::Profitbricks::IpBlock.new(:ips => ['127.0.0.1'])
+    @server = ::Profitbricks::Server.new(:id => '1234a',
+                                         :data_center_id => 'data-center-id',
+                                         :name => 'server',
+                                         :virtual_machine_state => 'INPROCESS',
+                                         :private_ips => nil,
+                                         :public_ips => ['127.0.0.1'],
+                                         :provisioning_state => 'AVAILABLE',
+                                         :connected_storages => {:id => 'storage'})
+  end
+
+  it "must convert an instance" do
+    @driver.backend.stub(:find_instance_image, '5678a') do
+      ::Profitbricks::Server.stub(:find, @server) do
+        server = @driver.backend.convert_instance(@server, 'test')
+        server.must_be_kind_of Deltacloud::Instance
+        server.id.must_equal '1234a'
+        server.name.must_equal 'server'
+        server.image_id.must_equal '5678a'
+        server.storage_volumes.must_equal [{'storage' => nil}]
+      end
+    end
+  end
+
+  it "must find the instance image" do
+    ::Profitbricks::Storage.stub(:find, @storage) do
+      @server.instance_variable_set(:@connected_storages, [@storage])
+      storage_id = @driver.backend.find_instance_image(@server)
+      storage_id.must_equal '5678a'
+    end
+  end
+
+  it "must convert a storage volume" do
+    s = @driver.backend.convert_storage(@storage)
+    s.must_be_kind_of Deltacloud::StorageVolume
+    s.id.must_equal '1234a'
+    s.capacity.must_equal 20
+    s.name.must_equal 'test'
+    s.state.must_equal 'PENDING'
+  end
+
+  it "must convert a data center" do
+    d = @driver.backend.convert_data_center(@dc)
+    d.must_be_kind_of Deltacloud::Realm
+    d.id.must_equal '1234a'
+    d.name.must_equal 'test (EUROPE)'
+  end
+
+  it "must convert a load balancer" do
+    l = @driver.backend.convert_load_balancer(@lb, @dc)
+    l.must_be_kind_of Deltacloud::LoadBalancer
+    l.id.must_equal '5678a'
+    l.name.must_equal 'test'
+    l.public_addresses.must_equal ['127.0.0.1']
+    l.realms.must_be_kind_of Array
+    l.realms[0].must_be_kind_of Deltacloud::Realm
+  end
+
+  it "must convert a network interface" do
+    nic = @driver.backend.convert_network_interface(@nic)
+    nic.must_be_kind_of Deltacloud::NetworkInterface
+    nic.id.must_equal '1234a'
+    nic.name.must_equal 'test'
+    nic.instance.must_equal 'server-id'
+    nic.network.must_equal 1
+    nic.ip_address.must_equal '127.0.0.1'
+  end
+
+  it "must convert a firewall rule" do
+    fwr = @driver.backend.convert_firewall_rule(@fwr)
+    fwr.must_be_kind_of Deltacloud::FirewallRule
+    fwr.id.must_equal '1234a'
+    fwr.allow_protocol.must_equal 'TCP'
+    fwr.port_from.must_equal 80
+    fwr.port_to.must_equal 81
+    fwr.sources.must_be_kind_of Array
+    fwr.sources[0].must_equal({:type => 'address', :family => 'ipv4',
+                               :address => '0.0.0.0', :prefix => ''})
+    fwr.direction.must_equal 'ingress'
+  end
+
+  it "must convert a firewall" do
+    fw = @driver.backend.convert_firewall(@fw)
+    fw.must_be_kind_of Deltacloud::Firewall
+    fw.id.must_equal '1234a'
+    fw.description.must_equal 'Firewall of 5678a'
+    fw.owner_id.must_equal '5678a'
+    fw.rules.must_be_kind_of Array
+    fw.rules[0].must_be_kind_of Deltacloud::FirewallRule
+  end
+
+  it "must convert a ip block" do
+    adr = @driver.backend.convert_ip_block(@ip_block, [@server])
+    adr.must_be_kind_of Deltacloud::Address
+    adr.id.must_equal '127.0.0.1'
+    adr.instance_id.must_equal '1234a'
+  end
+
+  it "must find an ip block by ip" do
+    ::Profitbricks::IpBlock.stub(:all, [@ip_block]) do
+      ip_block = @driver.backend.find_ip_block_by_ip('127.0.0.1')
+      ip_block.must_be_kind_of ::Profitbricks::IpBlock
+      ip_block.must_equal @ip_block
+    end
+  end
+end
diff --git a/server/tests/drivers/profitbricks/firewall_test.rb b/server/tests/drivers/profitbricks/firewall_test.rb
new file mode 100644
index 0000000..9b304d4
--- /dev/null
+++ b/server/tests/drivers/profitbricks/firewall_test.rb
@@ -0,0 +1,68 @@
+require 'rubygems'
+require 'require_relative' if RUBY_VERSION < '1.9'
+
+require_relative 'common.rb'
+
+describe 'Profitbricks data conversions' do
+
+  before do
+    Deltacloud::Drivers::Profitbricks::ProfitbricksDriver.send(:public, *Deltacloud::Drivers::Profitbricks::ProfitbricksDriver.private_instance_methods)
+    @driver = Deltacloud::new(:profitbricks, credentials)
+
+    @nic = ::Profitbricks::Nic.new(:id => '1234a',
+                                   :name => 'test',
+                                   :server_id => 'server-id',
+                                   :lan_id => 1,
+                                   :firewall => {},
+                                   :ips => ['127.0.0.1'])
+    @fwr = ::Profitbricks::FirewallRule.new(:id => '1234a',
+                                            :protocol => 'TCP',
+                                            :port_range_start => 80,
+                                            :port_range_end => 81,
+                                            :source_ip => '0.0.0.0')
+    @fw = ::Profitbricks::Firewall.new(:id => '1234a',
+                                       :nic_id => '5678a',
+                                       :rules => [@fwr.attributes])
+    @credentials = MiniTest::Mock.new
+    @credentials.expect(:user, 'test')
+    @credentials.expect(:password, 'test')
+  end
+
+  it "must find all firewalls" do
+    server = MiniTest::Mock.new
+    server.expect(:nics, [@nic])
+    @nic.stub(:firewall, @fw) do
+      ::Profitbricks::Server.stub(:all, [server]) do
+        @driver.backend.firewalls(@credentials)
+      end
+    end
+  end
+
+  it "must be deletable" do
+    ::Profitbricks::Firewall.stub(:find, @fw) do
+      ::Profitbricks.stub(:request, true) do
+        @driver.backend.delete_firewall(@credentials, :id => '!234a')
+      end
+    end
+  end
+
+  it "must be able to create firewall rules" do
+    fw = MiniTest::Mock.new
+    fw.expect(:add_rules, true, [[@fwr]])
+    ::Profitbricks::FirewallRule.stub(:new, @fwr) do
+      ::Profitbricks::Firewall.stub(:find, fw) do
+        @driver.backend.create_firewall_rule(@credentials, :addresses => ['127.0.0.1'], :protocol => 'TCP', :port_from => 80, :port_to => 81)
+      end
+    end
+  end
+
+  it "must delete a firewall rule" do
+    fw = MiniTest::Mock.new
+    fw.expect(:rules, [@fwr])
+    ::Profitbricks::Firewall.stub(:find, fw) do
+      ::Profitbricks.stub(:request, true) do
+        @driver.backend.delete_firewall_rule(@credentials, :firewall => '4567a', :rule_id => '1234a' )
+      end
+    end
+  end
+end
diff --git a/server/tests/drivers/profitbricks/image_test.rb b/server/tests/drivers/profitbricks/image_test.rb
new file mode 100644
index 0000000..118fac0
--- /dev/null
+++ b/server/tests/drivers/profitbricks/image_test.rb
@@ -0,0 +1,27 @@
+require 'rubygems'
+require 'require_relative' if RUBY_VERSION < '1.9'
+
+require_relative 'common.rb'
+
+describe 'Profitbricks data conversions' do
+
+  before do
+    Deltacloud::Drivers::Profitbricks::ProfitbricksDriver.send(:public, *Deltacloud::Drivers::Profitbricks::ProfitbricksDriver.private_instance_methods)
+    @driver = Deltacloud::new(:profitbricks, credentials)
+    @credentials = MiniTest::Mock.new
+    @credentials.expect(:user, 'test')
+    @credentials.expect(:password, 'test')
+  end
+
+  it "must find all images" do
+    @credentials.expect(:user, 'test')
+    image1 = ::Profitbricks::Image.new(:id => '1234a', :name => 'test1', :type => 'CDROM', cpu_hotpluggable: true, :region => 'EUROPE', :os_type => 'linux')
+    image2 = ::Profitbricks::Image.new(:id => '567a', :name => 'test1', :type => 'HDD', cpu_hotpluggable: true, :region => 'EUROPE', :os_type => 'linux')
+    ::Profitbricks::Image.stub(:all, [image1, image2]) do
+      images = @driver.backend.images(@credentials)
+      images.length.must_equal 1
+      images[0].id.must_equal '567a'
+      images[0].name.must_equal 'test1'
+    end
+  end
+end
diff --git a/server/tests/drivers/profitbricks/instance_test.rb b/server/tests/drivers/profitbricks/instance_test.rb
new file mode 100644
index 0000000..6b083a4
--- /dev/null
+++ b/server/tests/drivers/profitbricks/instance_test.rb
@@ -0,0 +1,97 @@
+require 'rubygems'
+require 'require_relative' if RUBY_VERSION < '1.9'
+
+require_relative 'common.rb'
+
+describe 'Profitbricks data conversions' do
+
+  before do
+    Deltacloud::Drivers::Profitbricks::ProfitbricksDriver.send(:public, *Deltacloud::Drivers::Profitbricks::ProfitbricksDriver.private_instance_methods)
+    @driver = Deltacloud::new(:profitbricks, credentials)
+    @storage = ::Profitbricks::Storage.new(:id => '1234a',
+                                          :name => 'test',
+                                          :provisioning_state => 'INPROCESS',
+                                          :size => 20,
+                                          :data_center_id => '4321',
+                                          :creation_time => Time.now,
+                                          :server_ids => ['5678'],
+                                          :mount_image => {:id => '5678a'})
+
+    @server = MiniTest::Mock.new
+    @credentials = MiniTest::Mock.new
+    @credentials.expect(:user, 'test')
+    @credentials.expect(:password, 'test')
+  end
+  describe "finding and creating instances" do
+    before do
+      @server.expect(:id, '1234a')
+      @server.expect(:data_center_id, '5678a')
+      @server.expect(:name, 'text')
+      @server.expect(:name, 'text')
+      @server.expect(:connected_storages, nil)
+      @server.expect(:connected_storages, nil)
+      @server.expect(:public_ips, ['127.0.0.1'])
+      @server.expect(:private_ips, ['127.0.0.1'])
+    end
+
+    it "must find all instances" do
+      @credentials.expect(:user, 'test')
+      ::Profitbricks::Server.stub(:all, [@server]) do
+        @driver.backend.instances(@credentials)
+      end
+    end
+
+    it "must find all instances of the same datacenter as the given storage_id" do
+      @credentials.expect(:user, 'test')
+      datacenter = MiniTest::Mock.new
+      datacenter.expect(:servers, [@server])
+      ::Profitbricks::Storage.stub(:find, @storage) do
+        ::Profitbricks::DataCenter.stub(:find, datacenter) do
+          @driver.backend.instances(@credentials, :storage_id => '1234a')
+        end
+      end
+    end
+    it "must create an instacne" do
+      @credentials.expect(:user, 'test')
+      ::Profitbricks::Storage.stub(:create, @storage) do
+        ::Profitbricks::Server.stub(:create, @server) do
+          @driver.backend.create_instance(@credentials, '1234a', :name => 'test', :hwp_storage => 20)
+        end
+      end
+    end
+
+  end
+  it "must be rebooted" do
+    @server.expect(:reset, true)
+    ::Profitbricks::Server.stub(:find, @server) do
+      @driver.backend.reboot_instance(@credentials, '1234a')
+    end
+    @server.verify
+  end
+
+  it "must be stopped" do
+    @server.expect(:stop, true)
+    ::Profitbricks::Server.stub(:find, @server) do
+      @driver.backend.stop_instance(@credentials, '1234a')
+    end
+    @server.verify
+  end
+
+  it "must be started" do
+    @server.expect(:start, true)
+    ::Profitbricks::Server.stub(:find, @server) do
+      @driver.backend.start_instance(@credentials, '1234a')
+    end
+    @server.verify
+  end
+
+  it "must be destroyed" do
+    server = ::Profitbricks::Server.new :id => '1234a'
+    ::Profitbricks::Server.stub(:find, server) do
+      ::Profitbricks.stub(:request, true) do
+        @driver.backend.destroy_instance(@credentials, '1234a')
+      end
+    end
+    
+  end
+end
diff --git a/server/tests/drivers/profitbricks/load_balancer_test.rb b/server/tests/drivers/profitbricks/load_balancer_test.rb
new file mode 100644
index 0000000..f40052b
--- /dev/null
+++ b/server/tests/drivers/profitbricks/load_balancer_test.rb
@@ -0,0 +1,90 @@
+require 'rubygems'
+require 'require_relative' if RUBY_VERSION < '1.9'
+
+require_relative 'common.rb'
+
+describe 'Profitbricks data conversions' do
+
+  before do
+    Deltacloud::Drivers::Profitbricks::ProfitbricksDriver.send(:public, *Deltacloud::Drivers::Profitbricks::ProfitbricksDriver.private_instance_methods)
+    @driver = Deltacloud::new(:profitbricks, credentials)
+    @dc = ::Profitbricks::DataCenter.new(:id => '1234a',
+                                        :name => 'test',
+                                        :region => 'EUROPE')
+    @lb = ::Profitbricks::LoadBalancer.new(:id => '5678a',
+                                          :name => 'test',
+                                          :creation_time => Time.now,
+                                          :data_center_id => '1234a',
+                                          :ip => '127.0.0.1')
+    @server = ::Profitbricks::Server.new(:id => '1234a',
+                                         :data_center_id => 'data-center-id',
+                                         :name => 'server',
+                                         :virtual_machine_state => 'INPROCESS',
+                                         :private_ips => nil,
+                                         :public_ips => ['127.0.0.1'],
+                                         :provisioning_state => 'AVAILABLE',
+                                         :connected_storages => {:id => 'storage'})
+    @credentials = MiniTest::Mock.new
+    @credentials.expect(:user, 'test')
+    @credentials.expect(:password, 'test')
+  end
+
+  it "must find a load balancer" do
+    ::Profitbricks::LoadBalancer.stub(:find, @lb) do
+      ::Profitbricks::DataCenter.stub(:find, @dc) do
+        @driver.backend.load_balancer(@credentials, :id => '1234a')
+      end
+    end
+  end
+
+  it "must find all load balancer" do
+    datacenter = MiniTest::Mock.new
+    datacenter.expect(:id, '1234a')
+    datacenter.expect(:name, 'test')
+    datacenter.expect(:load_balancers, [@lb])
+    datacenter.expect(:region, 'EUROPE')
+    ::Profitbricks::DataCenter.stub(:all, [datacenter]) do
+      @driver.backend.load_balancers(@credentials)
+    end
+  end
+
+  it "must create a load balancer" do
+    ::Profitbricks::LoadBalancer.stub(:create, @lb) do
+      @driver.backend.stub(:load_balancer, true) do
+        @driver.backend.create_load_balancer(@credentials, :name => 'test')
+      end
+    end
+  end
+
+  it "must register an instance" do
+    lb = MiniTest::Mock.new
+    lb.expect(:register_servers, true, [[@server]])
+    ::Profitbricks::LoadBalancer.stub(:find, lb) do
+      ::Profitbricks::Server.stub(:find, @server) do
+        @driver.backend.stub(:load_balancer, true) do
+          @driver.backend.lb_register_instance(@credentials)
+        end
+      end
+    end
+  end
+
+  it "must unregister an instance" do
+    lb = MiniTest::Mock.new
+    lb.expect(:deregister_servers, true, [[@server]])
+    ::Profitbricks::LoadBalancer.stub(:find, lb) do
+      ::Profitbricks::Server.stub(:find, @server) do
+        @driver.backend.stub(:load_balancer, true) do
+          @driver.backend.lb_unregister_instance(@credentials)
+        end
+      end
+    end
+  end
+
+  it "must be deletable" do
+    ::Profitbricks::LoadBalancer.stub(:find, @lb) do
+      ::Profitbricks.stub(:request, :true) do
+        @driver.backend.destroy_load_balancer(@credentials, '1234a') 
+      end
+    end
+  end
+end
diff --git a/server/tests/drivers/profitbricks/networks_test.rb b/server/tests/drivers/profitbricks/networks_test.rb
new file mode 100644
index 0000000..785f853
--- /dev/null
+++ b/server/tests/drivers/profitbricks/networks_test.rb
@@ -0,0 +1,96 @@
+require 'rubygems'
+require 'require_relative' if RUBY_VERSION < '1.9'
+
+require_relative 'common.rb'
+
+describe 'Profitbricks networks' do
+
+  before do
+    Deltacloud::Drivers::Profitbricks::ProfitbricksDriver.send(:public, *Deltacloud::Drivers::Profitbricks::ProfitbricksDriver.private_instance_methods)
+    @driver = Deltacloud::new(:profitbricks, credentials)
+    @dc = ::Profitbricks::DataCenter.new(:id => '1234a',
+                                        :name => 'test',
+                                        :region => 'EUROPE')
+    #@image = ::Profitbricks::Image.new(:id => '5678a')
+    @storage = ::Profitbricks::Storage.new(:id => '1234a',
+                                          :name => 'test',
+                                          :provisioning_state => 'INPROCESS',
+                                          :size => 20,
+                                          :data_center_id => '4321',
+                                          :creation_time => Time.now,
+                                          :server_ids => ['5678'],
+                                          :mount_image => {:id => '5678a'})
+    @lb = ::Profitbricks::LoadBalancer.new(:id => '5678a',
+                                          :name => 'test',
+                                          :creation_time => Time.now,
+                                          :data_center_id => '1234a',
+                                          :ip => '127.0.0.1')
+    @nic = ::Profitbricks::Nic.new(:id => '1234a',
+                                   :name => 'test',
+                                   :server_id => 'server-id',
+                                   :lan_id => 1,
+                                   :firewall => {},
+                                   :ips => ['127.0.0.1'])
+    @fwr = ::Profitbricks::FirewallRule.new(:id => '1234a',
+                                            :protocol => 'TCP',
+                                            :port_range_start => 80,
+                                            :port_range_end => 81,
+                                            :source_ip => '0.0.0.0')
+    @fw = ::Profitbricks::Firewall.new(:id => '1234a',
+                                       :nic_id => '5678a',
+                                       :rules => [@fwr.attributes])
+    @ip_block = ::Profitbricks::IpBlock.new(:ips => ['127.0.0.1'])
+    @server = ::Profitbricks::Server.new(:id => '1234a',
+                                         :data_center_id => 'data-center-id',
+                                         :name => 'server',
+                                         :virtual_machine_state => 'INPROCESS',
+                                         :private_ips => nil,
+                                         :public_ips => ['127.0.0.1'],
+                                         :provisioning_state => 'AVAILABLE',
+                                         :connected_storages => {:id => 'storage'})
+    @credentials = MiniTest::Mock.new
+    @credentials.expect(:user, 'test')
+    @credentials.expect(:password, 'test')
+  end
+  
+  it "must get all network interfaces" do
+    server = MiniTest::Mock.new
+    server.expect(:nics, [@nic])
+    server.expect(:nics, [@nic])
+    ::Profitbricks::Server.stub(:all,[server]) do
+      nic = @driver.backend.network_interfaces(@credentials)
+      nic.class.must_equal Array
+      nic[0].id.must_equal '1234a'
+      nic[0].instance.must_equal 'server-id'
+    end
+  end
+  
+  it "must create a network interface" do
+    ::Profitbricks::Nic.stub(:create, @nic) do
+      nic = @driver.backend.create_network_interface(@credentials, :server_id => '!234a')
+      nic.class.must_equal Deltacloud::NetworkInterface
+      nic.id.must_equal '1234a'
+    end
+  end
+
+  it "must destroy a network interface" do
+    ::Profitbricks::Nic.stub(:find, @nic) do
+      ::Profitbricks.stub(:request, true) do
+        @driver.backend.destroy_network_interface(@credentials, :id => '!234a')
+      end
+    end
+  end
+
+  it "must find all networks" do
+    server = MiniTest::Mock.new
+    server.expect(:nics, [@nic])
+    server.expect(:nics, [@nic])
+    server.expect(:data_center_id, ['4567a'])
+    ::Profitbricks::Server.stub(:all,[server]) do
+      networks = @driver.backend.networks(@credentials)
+      networks[0].class.must_equal Deltacloud::Network
+      networks[0].id.must_equal 1
+    end
+  end
+
+end
diff --git a/server/tests/drivers/profitbricks/realm_test.rb b/server/tests/drivers/profitbricks/realm_test.rb
new file mode 100644
index 0000000..4fc986c
--- /dev/null
+++ b/server/tests/drivers/profitbricks/realm_test.rb
@@ -0,0 +1,39 @@
+require 'rubygems'
+require 'require_relative' if RUBY_VERSION < '1.9'
+
+require_relative 'common.rb'
+
+describe 'Profitbricks data conversions' do
+
+  before do
+    Deltacloud::Drivers::Profitbricks::ProfitbricksDriver.send(:public, *Deltacloud::Drivers::Profitbricks::ProfitbricksDriver.private_instance_methods)
+    @driver = Deltacloud::new(:profitbricks, credentials)
+    @dc = ::Profitbricks::DataCenter.new(:id => '1234a',
+                                        :name => 'test',
+                                        :region => 'EUROPE')
+    @credentials = MiniTest::Mock.new
+    @credentials.expect(:user, 'test')
+    @credentials.expect(:password, 'test')
+  end
+
+  it "must find all realms" do
+    @credentials.expect(:user, 'test')
+    ::Profitbricks::DataCenter.stub(:all, [@dc]) do
+      dcs = @driver.backend.realms(@credentials)
+      dcs.length.must_equal 1
+      dcs[0].id.must_equal '1234a'
+      dcs[0].name.must_equal 'test (EUROPE)'
+    end
+  end
+
+  it "must find realms of the same region as the given image" do
+    @credentials.expect(:user, 'test')
+    dc2 = ::Profitbricks::DataCenter.new(:id => '567a', :region => 'US')
+    ::Profitbricks::DataCenter.stub(:all, [@dc, dc2]) do
+      dcs = @driver.backend.realms(@credentials, :image => OpenStruct.new(:description => 'Region: (EUROPE),'))
+      dcs.length.must_equal 1
+      dcs[0].id.must_equal '1234a'
+      dcs[0].name.must_equal 'test (EUROPE)'
+    end
+  end
+end
diff --git a/server/tests/drivers/profitbricks/storages_test.rb b/server/tests/drivers/profitbricks/storages_test.rb
new file mode 100644
index 0000000..543c553
--- /dev/null
+++ b/server/tests/drivers/profitbricks/storages_test.rb
@@ -0,0 +1,64 @@
+require 'rubygems'
+require 'require_relative' if RUBY_VERSION < '1.9'
+
+require_relative 'common.rb'
+
+describe 'Profitbricks storage volumes' do
+
+  before do
+    Deltacloud::Drivers::Profitbricks::ProfitbricksDriver.send(:public, *Deltacloud::Drivers::Profitbricks::ProfitbricksDriver.private_instance_methods)
+    @driver = Deltacloud::new(:profitbricks, credentials)
+    @storage = ::Profitbricks::Storage.new(:id => '1234a',
+                                          :name => 'test',
+                                          :provisioning_state => 'INPROCESS',
+                                          :size => 20,
+                                          :data_center_id => '4321',
+                                          :creation_time => Time.now,
+                                          :server_ids => ['5678'],
+                                          :mount_image => {:id => '5678a'})
+    @credentials = MiniTest::Mock.new
+    @credentials.expect(:user, 'test')
+    @credentials.expect(:password, 'test')
+  end
+  describe "finding and creating storage volumnes" do
+
+    it "must find all storage volumnes" do
+      datacenter = MiniTest::Mock.new
+      datacenter.expect(:storages, [@storage])
+      ::Profitbricks::DataCenter.stub(:all, [datacenter]) do
+        @driver.backend.storage_volumes(@credentials)
+      end
+    end
+    it "must find a storage by id" do
+      ::Profitbricks::Storage.stub(:find, @storage) do
+        @driver.backend.storage_volumes(@credentials, :id => '1234a')
+      end
+    end
+    it "must create a storage volume" do
+      ::Profitbricks::Storage.stub(:create, @storage) do
+        @driver.backend.create_storage_volume(@credentials, :capacity => 10, :name => 'test')
+      end
+    end
+    it "must destroy a storage volume" do
+      ::Profitbricks::Storage.stub(:find, @storage) do
+        ::Profitbricks.stub(:request, true) do
+         @driver.backend.destroy_storage_volume(@credentials)
+       end
+      end
+    end
+    it "must attach a storage volume" do
+      storage = MiniTest::Mock.new
+      storage.expect(:connect, true, [{:server_id => '567a'}]) 
+      ::Profitbricks::Storage.stub(:find, storage) do
+        @driver.backend.attach_storage_volume(@credentials, :id => '1234a', :instance_id => '567a')     
+      end
+    end
+    it "must detach a storage volume" do
+      storage = MiniTest::Mock.new
+      storage.expect(:disconnect, true, [{:server_id => '567a'}]) 
+      ::Profitbricks::Storage.stub(:find, storage) do
+        @driver.backend.detach_storage_volume(@credentials, :id => '1234a', :instance_id => '567a')     
+      end
+    end
+  end
+end
diff --git a/server/views/load_balancers/index.html.haml b/server/views/load_balancers/index.html.haml
index 8b2f41f..e504189 100644
--- a/server/views/load_balancers/index.html.haml
+++ b/server/views/load_balancers/index.html.haml
@@ -8,6 +8,9 @@
       %li
         %a{ :href => load_balancer_url(balancer.id), :'data-ajax' => 'false'}
           %img{ :class => 'ui-link-thumb', :src => '/images/balancer.png'}
-          %h3=balancer.id
+          - if balancer.name
+            %h3="#{balancer.name} (#{balancer.id})"
+          - else
+            %h3=balancer.id
           %p=balancer.public_addresses.join(', ')
           %span{ :class => 'ui-li-count'}=balancer.realms.first.id
diff --git a/server/views/storage_volumes/new.html.haml b/server/views/storage_volumes/new.html.haml
index f0923cb..476bfb8 100644
--- a/server/views/storage_volumes/new.html.haml
+++ b/server/views/storage_volumes/new.html.haml
@@ -18,6 +18,8 @@
     %p
       %label
         Realm ID:
-      %input{ :name => "realm_id", :size => 10, :value => driver.realms(credentials).first.id}
+      %select{ :name => 'realm_id' }
+        - driver.realms(credentials).each do |i|
+          %option{ :value => "#{i.id}"} #{i.name}
     %p
       %input{ :type => :submit, :name => "commit", :value => "Create" }/