fog-serverlove 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (56) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +23 -0
  3. data/.hound.yml +20 -0
  4. data/.rubocop.yml +20 -0
  5. data/.ruby-gemset +1 -0
  6. data/.ruby-version +1 -0
  7. data/.travis.yml +17 -0
  8. data/CONTRIBUTING.md +18 -0
  9. data/CONTRIBUTORS.md +7 -0
  10. data/Gemfile +4 -0
  11. data/LICENSE.md +20 -0
  12. data/README.md +38 -0
  13. data/Rakefile +18 -0
  14. data/fog-serverlove.gemspec +35 -0
  15. data/gemfiles/Gemfile.1.9.2- +8 -0
  16. data/gemfiles/Gemfile.1.9.3+ +7 -0
  17. data/lib/fog/compute/serverlove.rb +95 -0
  18. data/lib/fog/compute/serverlove/models/image.rb +52 -0
  19. data/lib/fog/compute/serverlove/models/images.rb +19 -0
  20. data/lib/fog/compute/serverlove/models/server.rb +67 -0
  21. data/lib/fog/compute/serverlove/models/servers.rb +19 -0
  22. data/lib/fog/compute/serverlove/password_generator.rb +11 -0
  23. data/lib/fog/compute/serverlove/requests/create_image.rb +28 -0
  24. data/lib/fog/compute/serverlove/requests/create_server.rb +30 -0
  25. data/lib/fog/compute/serverlove/requests/destroy_image.rb +11 -0
  26. data/lib/fog/compute/serverlove/requests/destroy_server.rb +11 -0
  27. data/lib/fog/compute/serverlove/requests/get_image.rb +11 -0
  28. data/lib/fog/compute/serverlove/requests/get_images.rb +11 -0
  29. data/lib/fog/compute/serverlove/requests/get_server.rb +11 -0
  30. data/lib/fog/compute/serverlove/requests/get_servers.rb +11 -0
  31. data/lib/fog/compute/serverlove/requests/load_standard_image.rb +11 -0
  32. data/lib/fog/compute/serverlove/requests/reset_server.rb +11 -0
  33. data/lib/fog/compute/serverlove/requests/shutdown_server.rb +11 -0
  34. data/lib/fog/compute/serverlove/requests/start_server.rb +11 -0
  35. data/lib/fog/compute/serverlove/requests/stop_server.rb +11 -0
  36. data/lib/fog/compute/serverlove/requests/update_image.rb +13 -0
  37. data/lib/fog/compute/serverlove/requests/update_server.rb +13 -0
  38. data/lib/fog/serverlove.rb +15 -0
  39. data/lib/fog/serverlove/compute.rb +0 -0
  40. data/lib/fog/serverlove/version.rb +5 -0
  41. data/spec/minitest_helper.rb +31 -0
  42. data/tests/compute/password_generator_tests.rb +15 -0
  43. data/tests/compute/requests/image_tests.rb +59 -0
  44. data/tests/compute/requests/server_tests.rb +92 -0
  45. data/tests/helper.rb +34 -0
  46. data/tests/helpers/collection_helper.rb +97 -0
  47. data/tests/helpers/flavors_helper.rb +32 -0
  48. data/tests/helpers/formats_helper.rb +98 -0
  49. data/tests/helpers/formats_helper_tests.rb +110 -0
  50. data/tests/helpers/model_helper.rb +29 -0
  51. data/tests/helpers/responds_to_helper.rb +11 -0
  52. data/tests/helpers/schema_validator_tests.rb +107 -0
  53. data/tests/helpers/server_helper.rb +25 -0
  54. data/tests/helpers/servers_helper.rb +10 -0
  55. data/tests/helpers/succeeds_helper.rb +9 -0
  56. metadata +227 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 88e3da07e4d10d6d77c4114e281d62ecdb91d1e4
4
+ data.tar.gz: 86a5ef00c3dc87435a03ec9edf9e85c5362ef6dc
5
+ SHA512:
6
+ metadata.gz: b5aa6980236a1c8314158efcee2a9f7e909a4b6f7ec33a7cb79b6da81a13b6cd1e9d75f211e345c707f2765eb1cfdf75c31717cc68709f1fedd0b5930f380e5d
7
+ data.tar.gz: 7516d4da8192f1e6fb2fef2a5297cbdc47fe759b6a98da9a37355764ec8541a58519b169376c02fe4896e2f84ebdd11652540ec0e17cc435931dcf9087b5570d
data/.gitignore ADDED
@@ -0,0 +1,23 @@
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
data/.hound.yml ADDED
@@ -0,0 +1,20 @@
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
+ EnforcedStyle: double_quotes
data/.rubocop.yml ADDED
@@ -0,0 +1,20 @@
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
+ EnforcedStyle: double_quotes
data/.ruby-gemset ADDED
@@ -0,0 +1 @@
1
+ fog-serverlove
data/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ 2.1.5
data/.travis.yml ADDED
@@ -0,0 +1,17 @@
1
+ matrix:
2
+ include:
3
+ - rvm: 1.8.7
4
+ gemfile: gemfiles/Gemfile.1.9.2-
5
+ - rvm: 1.9.2
6
+ gemfile: gemfiles/Gemfile.1.9.2-
7
+ - rvm: 1.9.3
8
+ gemfile: gemfiles/Gemfile.1.9.3+
9
+ - rvm: 2.0.0
10
+ gemfile: gemfiles/Gemfile.1.9.3+
11
+ - rvm: 2.1.4
12
+ gemfile: gemfiles/Gemfile.1.9.3+
13
+ env: COVERAGE=true
14
+ - rvm: ree
15
+ gemfile: gemfiles/Gemfile.1.9.2-
16
+ - rvm: jruby
17
+ gemfile: gemfiles/Gemfile.1.9.3+
data/CONTRIBUTING.md ADDED
@@ -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-serverlove/pulls).
9
+ * Review open [issues](https://github.com/fog/fog-serverlove/issues) for things to help on.
10
+ * [Create an issue](https://github.com/fog/fog-serverlove/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-serverlove` to ensure everything is up to date.
13
+ * [Submit a pull request](https://github.com/fog/fog-serverlove/compare/)
14
+
15
+ ### Non-Coding
16
+
17
+ * Offer feedback on open [issues](https://github.com/fog/fog-serverlove/issues).
18
+ * Organize or volunteer at events.
data/CONTRIBUTORS.md ADDED
@@ -0,0 +1,7 @@
1
+ * Frederick Cheung <frederick.cheung@gmail.com>
2
+ * James Rose <jamesbrose123@gmail.com>
3
+ * Lance Ivy <lance@cainlevy.net>
4
+ * Paul Thornthwaite <tokengeek@gmail.com>
5
+ * Paulo Henrique Lopes Ribeiro <plribeiro3000@gmail.com>
6
+ * Sean Handley <sean.handley@gmail.com>
7
+ * Wesley Beary <geemus@gmail.com>
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in fog-serverlove.gemspec
4
+ gemspec
data/LICENSE.md ADDED
@@ -0,0 +1,20 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2014-2014 [CONTRIBUTORS.md](https://github.com/fog/fog-serverlove/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.
data/README.md ADDED
@@ -0,0 +1,38 @@
1
+ # Fog::Serverlove
2
+
3
+ ![Gem Version](https://badge.fury.io/rb/fog-serverlove.svg) [![Build Status](https://travis-ci.org/fog/fog-serverlove.svg?branch=master)](https://travis-ci.org/fog/fog-serverlove) [![Dependency Status](https://gemnasium.com/fog/fog-serverlove.svg)](https://gemnasium.com/fog/fog-serverlove) [![Coverage Status](https://img.shields.io/coveralls/fog/fog-serverlove.svg)](https://coveralls.io/r/fog/fog-serverlove?branch=master) [![Code Climate](https://codeclimate.com/github/fog/fog-serverlove.png)](https://codeclimate.com/github/fog/fog-serverlove)
4
+
5
+ Module for the 'fog' gem to support ServerLove
6
+
7
+ ## Help Needed
8
+
9
+ This gem needs a maintainer. If you want to work on it, please contact
10
+ [@geemus](mailto:geemus@gmail.com) or [@plribeiro3000](mailto:plribeiro3000@gmail.com)
11
+
12
+ ## Installation
13
+
14
+ Add this line to your application's Gemfile:
15
+
16
+ ```ruby
17
+ gem 'fog-serverlove'
18
+ ```
19
+
20
+ And then execute:
21
+
22
+ $ bundle
23
+
24
+ Or install it yourself as:
25
+
26
+ $ gem install fog-serverlove
27
+
28
+ ## Usage
29
+
30
+ TODO: Write usage instructions here
31
+
32
+ ## Contributing
33
+
34
+ 1. Fork it ( https://github.com/fog/fog-serverlove/fork )
35
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
36
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
37
+ 4. Push to the branch (`git push origin my-new-feature`)
38
+ 5. Create a new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,18 @@
1
+ require 'bundler/gem_tasks'
2
+ require 'rake/testtask'
3
+
4
+ Rake::TestTask.new do |t|
5
+ t.libs.push %w(spec)
6
+ t.test_files = FileList['spec/**/*_spec.rb']
7
+ t.verbose = true
8
+ end
9
+
10
+ desc 'Default Task'
11
+ task :default => [ :test, 'test:travis' ]
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
@@ -0,0 +1,35 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'fog/serverlove/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "fog-serverlove"
8
+ spec.version = Fog::Serverlove::VERSION
9
+ spec.authors = ["Paulo Henrique Lopes Ribeiro"]
10
+ spec.email = ["plribeiro3000@gmail.com"]
11
+ spec.summary = %q{Module for the 'fog' gem to support ServerLove.}
12
+ spec.description = %q{This library can be used as a module for `fog` or as standalone provider
13
+ to use the ServerLove in applications.}
14
+ spec.homepage = ""
15
+ spec.license = "MIT"
16
+
17
+ spec.files = `git ls-files -z`.split("\x0")
18
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
19
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
20
+ spec.require_paths = ["lib"]
21
+
22
+ spec.add_dependency "fog-core"
23
+ spec.add_dependency "fog-json"
24
+
25
+ spec.add_development_dependency "rake"
26
+ spec.add_development_dependency "minitest"
27
+ spec.add_development_dependency "shindo"
28
+ spec.add_development_dependency "turn"
29
+ spec.add_development_dependency "pry"
30
+
31
+ if RUBY_VERSION.to_f > 1.9
32
+ spec.add_development_dependency "coveralls"
33
+ spec.add_development_dependency "rubocop"
34
+ end
35
+ end
@@ -0,0 +1,8 @@
1
+ source :rubygems
2
+
3
+ gem 'mime-types', '< 2.0'
4
+ gem 'nokogiri', '< 1.6'
5
+ gem 'rest-client', '~> 1.6.8'
6
+ gem 'fog-core'
7
+
8
+ gemspec :path => '../'
@@ -0,0 +1,7 @@
1
+ source :rubygems
2
+
3
+ gem 'activesupport', '>= 3.0', '< 4'
4
+ gem 'mime-types', '< 2.0'
5
+ gem 'fog-core'
6
+
7
+ gemspec :path => '../'
@@ -0,0 +1,95 @@
1
+ module Fog
2
+ module Compute
3
+ class Serverlove < Fog::Service
4
+ autoload :Image, 'fog/compute/serverlove/models/image'
5
+ autoload :Images, 'fog/compute/serverlove/models/images'
6
+ autoload :Server, 'fog/compute/serverlove/models/server'
7
+ autoload :Servers, 'fog/compute/serverlove/models/servers'
8
+ autoload :PasswordGenerator, 'fog/compute/serverlove/password_generator'
9
+
10
+ API_HOST = "api.z1-man.serverlove.com"
11
+
12
+ requires :serverlove_uuid, :serverlove_api_key
13
+ recognizes :serverlove_api_url
14
+
15
+ model_path 'fog/compute/serverlove/models'
16
+ model :image
17
+ collection :images
18
+ model :server
19
+ collection :servers
20
+
21
+ request_path 'fog/compute/serverlove/requests'
22
+ # Image
23
+ request :get_image
24
+ request :get_images
25
+ request :destroy_image
26
+ request :create_image
27
+ request :update_image
28
+ request :load_standard_image
29
+ # Server
30
+ request :get_servers
31
+ request :get_server
32
+ request :destroy_server
33
+ request :create_server
34
+ request :update_server
35
+ request :start_server
36
+ request :stop_server
37
+ request :shutdown_server
38
+ request :reset_server
39
+
40
+ class Mock
41
+ def initialize(options)
42
+ @serverlove_uuid = options[:serverlove_uuid]
43
+ @serverlove_api_key = options[:serverlove_api_key]
44
+ end
45
+
46
+ def request(options)
47
+ raise "Not implemented"
48
+ end
49
+ end
50
+
51
+ class Real
52
+ def initialize(options)
53
+ @api_uuid = options[:serverlove_uuid] || Fog.credentials[:serverlove_uuid]
54
+ @api_key = options[:serverlove_api_key] || Fog.credentials[:serverlove_api_key]
55
+ @api_host = options[:serverlove_api_url] || Fog.credentials[:serverlove_api_url] || API_HOST
56
+
57
+ @connection = Fog::Core::Connection.new("https://#{@api_uuid}:#{@api_key}@#{@api_host}")
58
+ end
59
+
60
+ def request(params)
61
+ params = params.merge!(
62
+ :headers => {
63
+ "Accept" => "application/json"
64
+ }
65
+ )
66
+ unless params[:options].nil?
67
+ params[:body] = encode_pairs(params[:options])
68
+ params.delete(:options)
69
+ end
70
+ response = @connection.request(params)
71
+
72
+ raise_if_error!(response)
73
+
74
+ response.body = Fog::JSON.decode(response.body) if response.body && response.body.length > 0
75
+
76
+ response
77
+ end
78
+
79
+ def encode_pairs(params)
80
+ params.keys.map do |key|
81
+ "#{key} #{params[key]}"
82
+ end.join("\n")
83
+ end
84
+
85
+ # TODO
86
+ def raise_if_error!(response)
87
+ case response.status
88
+ when 400 then
89
+ raise 'omg'
90
+ end
91
+ end
92
+ end
93
+ end
94
+ end
95
+ end
@@ -0,0 +1,52 @@
1
+ module Fog
2
+ module Compute
3
+ class Serverlove
4
+ class Image < Fog::Model
5
+ identity :id, :aliases => 'drive'
6
+
7
+ attribute :name
8
+ attribute :user
9
+ attribute :size
10
+ attribute :claimed
11
+ attribute :status
12
+ attribute :imaging
13
+ attribute :encryption_cipher, :aliases => 'encryption:cipher'
14
+
15
+ def save
16
+ attributes = {}
17
+
18
+ if(identity)
19
+ attributes = service.update_image(identity, allowed_attributes).body
20
+ else
21
+ requires :name
22
+ requires :size
23
+ attributes = service.create_image(allowed_attributes).body
24
+ end
25
+
26
+ merge_attributes(attributes)
27
+ self
28
+ end
29
+
30
+ def load_standard_image(standard_image_uuid)
31
+ requires :identity
32
+ service.load_standard_image(identity, standard_image_uuid)
33
+ end
34
+
35
+ def ready?
36
+ status.upcase == 'ACTIVE'
37
+ end
38
+
39
+ def destroy
40
+ requires :identity
41
+ service.destroy_image(identity)
42
+ self
43
+ end
44
+
45
+ def allowed_attributes
46
+ allowed = [:name, :size]
47
+ attributes.select {|k,v| allowed.include? k}
48
+ end
49
+ end
50
+ end
51
+ end
52
+ end
@@ -0,0 +1,19 @@
1
+ module Fog
2
+ module Compute
3
+ class Serverlove
4
+ class Images < Fog::Collection
5
+ model Fog::Compute::Serverlove::Image
6
+
7
+ def all
8
+ data = service.get_images.body
9
+ load(data)
10
+ end
11
+
12
+ def get(image_id)
13
+ data = service.get_image(image_id).body
14
+ new(data)
15
+ end
16
+ end
17
+ end
18
+ end
19
+ end