fog-profitbricks 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (109) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +24 -0
  3. data/.rubocop.yml +21 -0
  4. data/.ruby-gemset +1 -0
  5. data/.ruby-version +1 -0
  6. data/.travis.yml +25 -0
  7. data/CONTRIBUTING.md +18 -0
  8. data/CONTRIBUTORS.md +2 -0
  9. data/Gemfile +4 -0
  10. data/LICENSE.md +20 -0
  11. data/README.md +29 -0
  12. data/Rakefile +21 -0
  13. data/examples/pb_demo.rb +53 -0
  14. data/fog-profitbricks.gemspec +31 -0
  15. data/gemfiles/Gemfile.1.8.7 +7 -0
  16. data/gemfiles/Gemfile.1.9.2+ +6 -0
  17. data/lib/fog/bin/profitbricks.rb +29 -0
  18. data/lib/fog/profitbricks.rb +13 -0
  19. data/lib/fog/profitbricks/compute.rb +215 -0
  20. data/lib/fog/profitbricks/core.rb +18 -0
  21. data/lib/fog/profitbricks/models/compute/datacenter.rb +59 -0
  22. data/lib/fog/profitbricks/models/compute/datacenters.rb +24 -0
  23. data/lib/fog/profitbricks/models/compute/flavor.rb +27 -0
  24. data/lib/fog/profitbricks/models/compute/flavors.rb +24 -0
  25. data/lib/fog/profitbricks/models/compute/image.rb +30 -0
  26. data/lib/fog/profitbricks/models/compute/images.rb +23 -0
  27. data/lib/fog/profitbricks/models/compute/interface.rb +64 -0
  28. data/lib/fog/profitbricks/models/compute/interfaces.rb +24 -0
  29. data/lib/fog/profitbricks/models/compute/region.rb +15 -0
  30. data/lib/fog/profitbricks/models/compute/regions.rb +24 -0
  31. data/lib/fog/profitbricks/models/compute/server.rb +107 -0
  32. data/lib/fog/profitbricks/models/compute/servers.rb +23 -0
  33. data/lib/fog/profitbricks/models/compute/volume.rb +74 -0
  34. data/lib/fog/profitbricks/models/compute/volumes.rb +24 -0
  35. data/lib/fog/profitbricks/parsers/base.rb +49 -0
  36. data/lib/fog/profitbricks/parsers/compute/clear_data_center.rb +22 -0
  37. data/lib/fog/profitbricks/parsers/compute/connect_storage_to_server.rb +22 -0
  38. data/lib/fog/profitbricks/parsers/compute/create_data_center.rb +22 -0
  39. data/lib/fog/profitbricks/parsers/compute/create_nic.rb +22 -0
  40. data/lib/fog/profitbricks/parsers/compute/create_server.rb +22 -0
  41. data/lib/fog/profitbricks/parsers/compute/create_storage.rb +22 -0
  42. data/lib/fog/profitbricks/parsers/compute/delete_data_center.rb +20 -0
  43. data/lib/fog/profitbricks/parsers/compute/delete_nic.rb +22 -0
  44. data/lib/fog/profitbricks/parsers/compute/delete_server.rb +22 -0
  45. data/lib/fog/profitbricks/parsers/compute/delete_storage.rb +22 -0
  46. data/lib/fog/profitbricks/parsers/compute/disconnect_storage_from_server.rb +22 -0
  47. data/lib/fog/profitbricks/parsers/compute/get_all_data_centers.rb +26 -0
  48. data/lib/fog/profitbricks/parsers/compute/get_all_images.rb +30 -0
  49. data/lib/fog/profitbricks/parsers/compute/get_all_nic.rb +30 -0
  50. data/lib/fog/profitbricks/parsers/compute/get_all_servers.rb +56 -0
  51. data/lib/fog/profitbricks/parsers/compute/get_all_storages.rb +33 -0
  52. data/lib/fog/profitbricks/parsers/compute/get_data_center.rb +23 -0
  53. data/lib/fog/profitbricks/parsers/compute/get_data_center_state.rb +20 -0
  54. data/lib/fog/profitbricks/parsers/compute/get_image.rb +26 -0
  55. data/lib/fog/profitbricks/parsers/compute/get_nic.rb +27 -0
  56. data/lib/fog/profitbricks/parsers/compute/get_server.rb +55 -0
  57. data/lib/fog/profitbricks/parsers/compute/get_storage.rb +30 -0
  58. data/lib/fog/profitbricks/parsers/compute/reset_server.rb +20 -0
  59. data/lib/fog/profitbricks/parsers/compute/set_internet_access.rb +22 -0
  60. data/lib/fog/profitbricks/parsers/compute/update_data_center.rb +22 -0
  61. data/lib/fog/profitbricks/parsers/compute/update_nic.rb +22 -0
  62. data/lib/fog/profitbricks/parsers/compute/update_server.rb +22 -0
  63. data/lib/fog/profitbricks/parsers/compute/update_storage.rb +22 -0
  64. data/lib/fog/profitbricks/requests/compute/clear_data_center.rb +53 -0
  65. data/lib/fog/profitbricks/requests/compute/connect_storage_to_server.rb +85 -0
  66. data/lib/fog/profitbricks/requests/compute/create_data_center.rb +64 -0
  67. data/lib/fog/profitbricks/requests/compute/create_flavor.rb +40 -0
  68. data/lib/fog/profitbricks/requests/compute/create_nic.rb +81 -0
  69. data/lib/fog/profitbricks/requests/compute/create_server.rb +107 -0
  70. data/lib/fog/profitbricks/requests/compute/create_storage.rb +98 -0
  71. data/lib/fog/profitbricks/requests/compute/delete_data_center.rb +62 -0
  72. data/lib/fog/profitbricks/requests/compute/delete_nic.rb +66 -0
  73. data/lib/fog/profitbricks/requests/compute/delete_server.rb +66 -0
  74. data/lib/fog/profitbricks/requests/compute/delete_storage.rb +66 -0
  75. data/lib/fog/profitbricks/requests/compute/disconnect_storage_from_server.rb +78 -0
  76. data/lib/fog/profitbricks/requests/compute/get_all_data_centers.rb +32 -0
  77. data/lib/fog/profitbricks/requests/compute/get_all_flavors.rb +77 -0
  78. data/lib/fog/profitbricks/requests/compute/get_all_images.rb +67 -0
  79. data/lib/fog/profitbricks/requests/compute/get_all_locations.rb +44 -0
  80. data/lib/fog/profitbricks/requests/compute/get_all_nic.rb +55 -0
  81. data/lib/fog/profitbricks/requests/compute/get_all_servers.rb +58 -0
  82. data/lib/fog/profitbricks/requests/compute/get_all_storages.rb +58 -0
  83. data/lib/fog/profitbricks/requests/compute/get_data_center.rb +40 -0
  84. data/lib/fog/profitbricks/requests/compute/get_data_center_state.rb +43 -0
  85. data/lib/fog/profitbricks/requests/compute/get_flavor.rb +82 -0
  86. data/lib/fog/profitbricks/requests/compute/get_image.rb +71 -0
  87. data/lib/fog/profitbricks/requests/compute/get_location.rb +48 -0
  88. data/lib/fog/profitbricks/requests/compute/get_nic.rb +65 -0
  89. data/lib/fog/profitbricks/requests/compute/get_server.rb +100 -0
  90. data/lib/fog/profitbricks/requests/compute/get_storage.rb +65 -0
  91. data/lib/fog/profitbricks/requests/compute/reset_server.rb +51 -0
  92. data/lib/fog/profitbricks/requests/compute/set_internet_access.rb +61 -0
  93. data/lib/fog/profitbricks/requests/compute/start_server.rb +59 -0
  94. data/lib/fog/profitbricks/requests/compute/stop_server.rb +59 -0
  95. data/lib/fog/profitbricks/requests/compute/update_data_center.rb +55 -0
  96. data/lib/fog/profitbricks/requests/compute/update_nic.rb +76 -0
  97. data/lib/fog/profitbricks/requests/compute/update_server.rb +81 -0
  98. data/lib/fog/profitbricks/requests/compute/update_storage.rb +75 -0
  99. data/lib/fog/profitbricks/version.rb +5 -0
  100. data/spec/minitest_helper.rb +33 -0
  101. data/tests/helper.rb +19 -0
  102. data/tests/helpers/formats_helper.rb +23 -0
  103. data/tests/helpers/mock_helper.rb +8 -0
  104. data/tests/profitbricks/requests/compute/flavor_tests.rb +43 -0
  105. data/tests/profitbricks/requests/compute/image_tests.rb +50 -0
  106. data/tests/profitbricks/requests/compute/interface_tests.rb +101 -0
  107. data/tests/profitbricks/requests/compute/location_tests.rb +33 -0
  108. data/tests/profitbricks/requests/compute/server_tests.rb +246 -0
  109. metadata +293 -0
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 03f366af928abd2f482a610a276cd7511d1be2af
4
+ data.tar.gz: af46d443b445216869a0ae92d8cffc6256652e4c
5
+ SHA512:
6
+ metadata.gz: a680334c5285ce54b790d242739a4a1b1a6cd7951fcd21953d975de3bc3a8156565c085ae742b1f799c638520f5e5502ce7818e732eccc4f4489353d94441c27
7
+ data.tar.gz: 86fe3c96f303573a3cd1f65de3b3aa5e8734ccd3f81bb9b7f7027445844e160ed11e839040d2fd7ddb6fbcaec7f4ab98ce5e2b6ef16ff52e6e6d523b4fcaeb48
@@ -0,0 +1,24 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
18
+ *.bundle
19
+ *.so
20
+ *.o
21
+ *.a
22
+ mkmf.log
23
+ gemfiles/*.lock
24
+ .fog
@@ -0,0 +1,21 @@
1
+ Metrics/LineLength:
2
+ Enabled: false
3
+
4
+ Style/EachWithObject:
5
+ Enabled: false
6
+
7
+ Style/Encoding:
8
+ EnforcedStyle: when_needed
9
+
10
+ Style/FormatString:
11
+ Enabled: false
12
+
13
+ Style/HashSyntax:
14
+ EnforcedStyle: hash_rockets
15
+
16
+ Style/SignalException:
17
+ EnforcedStyle: only_raise
18
+
19
+ Style/StringLiterals:
20
+ Enabled: false
21
+ # EnforcedStyle: double_quotes
@@ -0,0 +1 @@
1
+ fog-profitbricks
@@ -0,0 +1 @@
1
+ 2.1.2
@@ -0,0 +1,25 @@
1
+ language: ruby
2
+
3
+ script: bundle exec rake travis
4
+
5
+ matrix:
6
+ include:
7
+ - rvm: 1.8.7
8
+ gemfile: gemfiles/Gemfile.1.8.7
9
+ - rvm: 1.9.2
10
+ gemfile: gemfiles/Gemfile.1.9.2+
11
+ env: COVERAGE=true
12
+ - rvm: 1.9.3
13
+ gemfile: gemfiles/Gemfile.1.9.2+
14
+ env: COVERAGE=true
15
+ - rvm: 2.0.0
16
+ gemfile: gemfiles/Gemfile.1.9.2+
17
+ env: COVERAGE=true
18
+ - rvm: 2.1.1
19
+ gemfile: gemfiles/Gemfile.1.9.2+
20
+ env: COVERAGE=true
21
+ - rvm: ree
22
+ gemfile: gemfiles/Gemfile.1.8.7
23
+ - rvm: jruby
24
+ gemfile: gemfiles/Gemfile.1.9.2+
25
+ env: COVERAGE=true
@@ -0,0 +1,18 @@
1
+ ## Getting Involved
2
+
3
+ New contributors are always welcome, when it doubt please ask questions. We strive to be an open and welcoming community. Please be nice to one another.
4
+
5
+ ### Coding
6
+
7
+ * Pick a task:
8
+ * Offer feedback on open [pull requests](https://github.com/fog/fog-profitbricks/pulls).
9
+ * Review open [issues](https://github.com/fog/fog-profitbricks/issues) for things to help on.
10
+ * [Create an issue](https://github.com/fog/fog-profitbricks/issues/new) to start a discussion on additions or features.
11
+ * Fork the project, add your changes and tests to cover them in a topic branch.
12
+ * Commit your changes and rebase against `fog/fog-profitbricks` to ensure everything is up to date.
13
+ * [Submit a pull request](https://github.com/fog/fog-profitbricks/compare/)
14
+
15
+ ### Non-Coding
16
+
17
+ * Offer feedback on open [issues](https://github.com/fog/fog-profitbricks/issues).
18
+ * Organize or volunteer at events.
@@ -0,0 +1,2 @@
1
+ * Ethan Devenport <ethand@stackpointcloud.com>
2
+ * Paulo Henrique Lopes Ribeiro <plribeiro3000@gmail.com>
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in fog-profitbricks.gemspec
4
+ gemspec
@@ -0,0 +1,20 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2014-2014 [CONTRIBUTORS.md](https://github.com/fog/fog-profitbricks/blob/master/CONTRIBUTORS.md)
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy of
6
+ this software and associated documentation files (the "Software"), to deal in
7
+ the Software without restriction, including without limitation the rights to
8
+ use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
9
+ the Software, and to permit persons to whom the Software is furnished to do so,
10
+ subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
17
+ FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
18
+ COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
19
+ IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
20
+ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,29 @@
1
+ # Fog::profitbricks
2
+
3
+ TODO: Write a gem description
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'fog-profitbricks'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install fog-profitbricks
18
+
19
+ ## Usage
20
+
21
+ TODO: Write usage instructions here
22
+
23
+ ## Contributing
24
+
25
+ 1. Fork it ( https://github.com/[my-github-username]/fog-profitbricks/fork )
26
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
27
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
28
+ 4. Push to the branch (`git push origin my-new-feature`)
29
+ 5. Create a new Pull Request
@@ -0,0 +1,21 @@
1
+ require "bundler/gem_tasks"
2
+ require "rake/testtask"
3
+
4
+ task :default => :test
5
+ task :travis => ["test", "test:travis"]
6
+
7
+ Rake::TestTask.new do |t|
8
+ t.libs.push %w(spec)
9
+ t.test_files = FileList["spec/**/*_spec.rb"]
10
+ t.verbose = true
11
+ end
12
+
13
+ namespace :test do
14
+ mock = ENV["FOG_MOCK"] || "true"
15
+ task :travis do
16
+ sh("export FOG_MOCK=#{mock} && bundle exec shindont")
17
+ end
18
+ end
19
+
20
+ desc "Default Task"
21
+ task :default => [ :test ]
@@ -0,0 +1,53 @@
1
+ require 'fog'
2
+
3
+ Excon.defaults[:connection_timeout] = 200
4
+
5
+ compute = Fog::Compute.new(:provider => 'ProfitBricks')
6
+
7
+ # Create data center
8
+ datacenter = compute.datacenters.create(:name => 'MyDataCenter', :region => 'us/las')
9
+ datacenter.wait_for { ready? }
10
+
11
+ # Get the data center
12
+ compute.datacenters.get(datacenter.id)
13
+
14
+ # List all data centers
15
+ compute.datacenters.all
16
+
17
+ # Update the data center
18
+ datacenter.options = { :dataCenterName => 'TestDataCenter'}
19
+ datacenter.update
20
+ datacenter.wait_for { ready? }
21
+
22
+ # Refresh data center properties
23
+ datacenter.reload
24
+
25
+ # Find HDD image in North America running Linux
26
+ image = compute.images.all.find do |image|
27
+ image.region == 'us/las' &&
28
+ image.type == 'HDD' &&
29
+ image.os_type == 'LINUX'
30
+ end
31
+
32
+ # Create volume
33
+ volume = compute.volumes.create(:data_center_id => datacenter.id, :size => 5, :options => { :storageName => 'MyVolume', :mountImageId => image.id })
34
+ volume.wait_for { ready? }
35
+
36
+ # Create server
37
+ server = compute.servers.create(:data_center_id => datacenter.id, :cores => 1, :ram => 1024, :options => { :serverName => 'MyServer' })
38
+ server.wait_for { ready? }
39
+
40
+ # Attach volume to server
41
+ volume.attach(server.id)
42
+
43
+ # Create network interface and attach to server
44
+ nic = compute.interfaces.create(:server_id => server.id, :lan_id => 1, :options => { :nicName => 'TestNic', :ip => '10.0.0.1', :dhcpActive => false })
45
+
46
+ # Enable LAN for public Internet access
47
+ nic.set_internet_access(:data_center_id => datacenter.id, :lan_id => 1, :internet_access => true)
48
+
49
+ # Clear data center (WARNING - this will remove all items under a data center)
50
+ datacenter.clear(true)
51
+
52
+ # Delete data center
53
+ datacenter.destroy
@@ -0,0 +1,31 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'fog/profitbricks/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "fog-profitbricks"
8
+ spec.version = Fog::ProfitBricks::VERSION
9
+ spec.authors = ["Ethan Devenport"]
10
+ spec.email = ["ethand@stackpointcloud.com"]
11
+ spec.summary = %q{Module for the 'fog' gem to support ProfitBricks.}
12
+ spec.description = %q{Module for the 'fog' gem to support ProfitBricks.}
13
+ spec.homepage = "https://github.com/fog/fog-profitbricks"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_runtime_dependency "fog-core"
22
+ spec.add_runtime_dependency "fog-xml"
23
+ spec.add_runtime_dependency "nokogiri"
24
+ spec.add_development_dependency "rake"
25
+ spec.add_development_dependency "minitest"
26
+ spec.add_development_dependency "shindo"
27
+ spec.add_development_dependency "turn"
28
+ spec.add_development_dependency "pry"
29
+ spec.add_development_dependency "rubocop" if RUBY_VERSION >= "1.9.3"
30
+ spec.add_development_dependency "coveralls" if RUBY_VERSION.to_f >= 1.9
31
+ end
@@ -0,0 +1,7 @@
1
+ source :rubygems
2
+
3
+ gem 'mime-types', '< 2.0'
4
+ gem 'nokogiri', '< 1.6'
5
+ gem 'rest-client', '~> 1.6.8'
6
+
7
+ gemspec :path => '../'
@@ -0,0 +1,6 @@
1
+ source :rubygems
2
+
3
+ gem 'activesupport', '>= 3.0', '< 4'
4
+ gem 'mime-types', '< 2.0'
5
+
6
+ gemspec :path => '../'
@@ -0,0 +1,29 @@
1
+ class ProfitBricks < Fog::Bin
2
+ class << self
3
+ def class_for(key)
4
+ case key
5
+ when :compute
6
+ Fog::Compute::ProfitBricks
7
+ else
8
+ raise ArgumentError, "Unrecognized service: #{key}"
9
+ end
10
+ end
11
+
12
+ def [](service)
13
+ @@connections ||= Hash.new do |hash, key|
14
+ hash[key] = case key
15
+ when :compute
16
+ Fog::Logger.warning("ProfitBricks[:compute] is not recommended, use Fog::Compute[:profitbricks] for portability")
17
+ Fog::Compute.new(:provider => 'ProfitBricks')
18
+ else
19
+ raise ArgumentError, "Unrecognized service: #{key.inspect}"
20
+ end
21
+ end
22
+ @@connections[service]
23
+ end
24
+
25
+ def services
26
+ Fog::ProfitBricks.services
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,13 @@
1
+ require "fog/core"
2
+ require "fog/xml"
3
+ require "fog/profitbricks/core"
4
+ require "fog/profitbricks/version"
5
+ require "fog/profitbricks/compute"
6
+ require "fog/profitbricks/parsers/base"
7
+
8
+ module Fog
9
+ module ProfitBricks
10
+ extend Fog::Provider
11
+ service(:compute, "Compute")
12
+ end
13
+ end
@@ -0,0 +1,215 @@
1
+ module Fog
2
+ module Compute
3
+ class ProfitBricks < Fog::Service
4
+ API_VERSION = '1.3'
5
+
6
+ requires :profitbricks_username, :profitbricks_password
7
+ recognizes :profitbricks_url
8
+
9
+ # Models
10
+ model_path 'fog/profitbricks/models/compute'
11
+ model :server
12
+ collection :servers
13
+ model :datacenter
14
+ collection :datacenters
15
+ model :region
16
+ collection :regions
17
+ model :image
18
+ collection :images
19
+ model :flavor
20
+ collection :flavors
21
+ model :volume
22
+ collection :volumes
23
+ model :interface
24
+ collection :interfaces
25
+
26
+ # Requests
27
+ request_path 'fog/profitbricks/requests/compute'
28
+ request :create_server # createServer
29
+ request :delete_server # deleteServer
30
+ request :update_server # updateServer
31
+ request :get_all_servers # getAllServers
32
+ request :get_server # getServer
33
+ request :reset_server # resetServer
34
+ request :start_server # startServer
35
+ request :stop_server # stopServer
36
+
37
+ request :clear_data_center # clearDataCenter
38
+ request :create_data_center # createDataCenter
39
+ request :delete_data_center # deleteDataCenter
40
+ request :update_data_center # updateDataCenter
41
+ request :get_all_data_centers # getAllDataCenters
42
+ request :get_data_center # getDataCenter
43
+ request :get_data_center_state # getDataCenterState
44
+
45
+ request :get_all_locations # getAllLocations
46
+ request :get_location # getLocation
47
+
48
+ request :get_all_images # getAllImages
49
+ request :get_image # getImage
50
+
51
+ request :get_all_flavors # getAllFlavors
52
+ request :get_flavor # getFlavor
53
+ request :create_flavor # createFlavor
54
+
55
+ request :create_storage # createStorage
56
+ request :delete_storage # deleteStorage
57
+ request :update_storage # updateStorage
58
+ request :get_all_storages # getAllStorages
59
+ request :get_storage # getStorage
60
+ request :connect_storage_to_server # connectStorageToServer
61
+ request :disconnect_storage_from_server # disconnectStorageFromServer
62
+
63
+ request :create_nic # createNic
64
+ request :delete_nic # deleteNic
65
+ request :update_nic # updateNic
66
+ request :get_all_nic # getAllNic
67
+ request :get_nic # getNic
68
+ request :set_internet_access # setInternetAccess
69
+
70
+ class Real
71
+ def initialize(options={})
72
+ @profitbricks_username = options[:profitbricks_username]
73
+ @profitbricks_password = options[:profitbricks_password]
74
+ @profitbricks_url = options[:profitbricks_url] ||
75
+ "https://api.profitbricks.com/#{API_VERSION}"
76
+
77
+ @connection = Fog::XML::Connection.new(@profitbricks_url, false)
78
+ end
79
+
80
+ def request(params)
81
+ begin
82
+ response = @connection.request(params.merge({
83
+ :headers => {
84
+ 'Authorization' => "Basic #{auth_header}"
85
+ }.merge!(params[:headers] || {})
86
+ }))
87
+ rescue Excon::Errors::Unauthorized => error
88
+ raise error
89
+ rescue Excon::Errors::HTTPStatusError => error
90
+ raise error
91
+ rescue Excon::Errors::InternalServerError => error
92
+ raise error
93
+ end
94
+ response
95
+ end
96
+
97
+ private
98
+
99
+ def auth_header
100
+ return Base64.encode64(
101
+ "#{@profitbricks_username}:#{@profitbricks_password}"
102
+ ).delete("\r\n")
103
+ end
104
+ end
105
+
106
+ class Mock
107
+ def self.data
108
+ @data ||= Hash.new do |hash, key|
109
+ hash[key] = {
110
+ :servers => [],
111
+ :datacenters => [],
112
+ :regions =>
113
+ [
114
+ {
115
+ 'locationId' => 'c0420cc0-90e8-4f4b-8860-df0a07d18047',
116
+ 'locationName' => 'de/fkb',
117
+ 'country' => 'DEU'
118
+ },
119
+ {
120
+ 'locationId' => '68c4099a-d9d8-4683-bdc2-12789aacfa2a',
121
+ 'locationName' => 'de/fra',
122
+ 'country' => 'DEU'
123
+ },
124
+ {
125
+ 'locationId' => 'e102ba74-6764-47f3-8896-246141da8ada',
126
+ 'locationName' => 'us/las',
127
+ 'country' => 'USA'
128
+ }
129
+ ],
130
+ :images =>
131
+ [
132
+ {
133
+ 'imageId' => 'ece948c0-14f8-4d49-8bdc-b966b746b6f9',
134
+ 'imageName' => 'CentOS-6.5-x86_64-netinstall.iso',
135
+ 'imageType' => 'CDROM',
136
+ 'imageSize' => 244,
137
+ 'bootable' => 'true',
138
+ 'cpuHotPlug' => 'false',
139
+ 'cpuHotUnPlug' => 'false',
140
+ 'ramHotPlug' => 'false',
141
+ 'ramHotUnPlug' => 'false',
142
+ 'discVirtioHotPlug' => 'false',
143
+ 'discVirtioHotUnPlug' => 'false',
144
+ 'nicHotPlug' => 'false',
145
+ 'nicHotUnPlug' => 'false',
146
+ 'osType' => 'LINUX',
147
+ 'serverIds' => nil,
148
+ 'writeable' => 'true',
149
+ 'location' => 'us/las',
150
+ 'public' => 'true'
151
+ },
152
+ {
153
+ 'imageId' => 'cc43d811-c423-402c-8bd0-6a04073a65ca',
154
+ 'imageName' => 'CentOS-6-server',
155
+ 'imageType' => 'HDD',
156
+ 'imageSize' => 11264,
157
+ 'bootable' => 'true',
158
+ 'cpuHotPlug' => 'false',
159
+ 'cpuHotUnPlug' => 'false',
160
+ 'ramHotPlug' => 'false',
161
+ 'ramHotUnPlug' => 'false',
162
+ 'discVirtioHotPlug' => 'false',
163
+ 'discVirtioHotUnPlug' => 'false',
164
+ 'nicHotPlug' => 'false',
165
+ 'nicHotUnPlug' => 'false',
166
+ 'osType' => 'LINUX',
167
+ 'serverIds' => nil,
168
+ 'writeable' => 'true',
169
+ 'location' => 'us/las',
170
+ 'public' => 'true'
171
+ }
172
+ ],
173
+ :flavors =>
174
+ [
175
+ {
176
+ 'flavorId' => Fog::UUID.uuid,
177
+ 'flavorName' => 'Micro',
178
+ 'ram' => 1024,
179
+ 'disk' => 50,
180
+ 'cores' => 1
181
+ },
182
+ {
183
+ 'flavorId' => Fog::UUID.uuid,
184
+ 'flavorName' => 'Small',
185
+ 'ram' => 2048,
186
+ 'disk' => 50,
187
+ 'cores' => 1
188
+ }
189
+ ],
190
+ :volumes => [],
191
+ :interfaces => []
192
+ }
193
+ end
194
+ end
195
+
196
+ def self.reset
197
+ @data = nil
198
+ end
199
+
200
+ def initialize(options={})
201
+ @profitbricks_username = options[:profitbricks_username]
202
+ @profitbricks_password = options[:profitbricks_password]
203
+ end
204
+
205
+ def data
206
+ self.class.data[@profitbricks_username]
207
+ end
208
+
209
+ def reset_data
210
+ self.class.data.delete(@profitbricks_username)
211
+ end
212
+ end
213
+ end
214
+ end
215
+ end