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
@@ -0,0 +1,67 @@
1
+ module Fog
2
+ module Compute
3
+ class Serverlove
4
+ class Server < Fog::Model
5
+ identity :id, :aliases => 'server'
6
+
7
+ attribute :name
8
+ attribute :cpu
9
+ attribute :mem
10
+ attribute :smp
11
+ attribute :ide_0_0, :aliases => 'ide:0:0'
12
+ attribute :ide_0_1, :aliases => 'ide:0:1'
13
+ attribute :ide_1_0, :aliases => 'ide:1:0'
14
+ attribute :ide_1_1, :aliases => 'ide:1:1'
15
+ attribute :boot
16
+ attribute :persistent
17
+ attribute :vnc
18
+ attribute :vnc_password, :aliases => 'vnc:password'
19
+ attribute :status
20
+ attribute :user
21
+ attribute :started
22
+ attribute :nic_0_model, :aliases => 'nic:0:model'
23
+ attribute :nic_0_dhcp, :aliases => 'nic:0:dhcp'
24
+
25
+ def save
26
+ attributes = {}
27
+
28
+ if(identity)
29
+ attributes = service.update_server(identity, allowed_attributes).body
30
+ else
31
+ requires :name
32
+ requires :cpu
33
+ attributes = service.create_server(self.class.defaults.merge(allowed_attributes)).body
34
+ end
35
+
36
+ merge_attributes(attributes)
37
+ self
38
+ end
39
+
40
+ def destroy
41
+ requires :identity
42
+ service.destroy_server(identity)
43
+ self
44
+ end
45
+
46
+ def allowed_attributes
47
+ allowed = [
48
+ :name, :cpu, :smp, :mem, :persistent,
49
+ :vnc_password, :vnc,
50
+ :ide_0_0, :ide_0_1, :ide_1_0, :ide_1_1,
51
+ :boot, :nic_0_model, :nic_0_dhcp
52
+ ]
53
+ attributes.select {|k,v| allowed.include? k}
54
+ end
55
+
56
+ def self.defaults
57
+ # TODO: Document default settings.
58
+ # Note that VNC password standards are strict (need explaining)
59
+ { 'nic:0:model' => 'e1000', 'nic:0:dhcp' => 'auto',
60
+ 'smp' => 'auto', 'vnc' => 'auto',
61
+ 'vnc:password' => Fog::Compute::Serverlove::PasswordGenerator.generate
62
+ }
63
+ end
64
+ end
65
+ end
66
+ end
67
+ end
@@ -0,0 +1,19 @@
1
+ module Fog
2
+ module Compute
3
+ class Serverlove
4
+ class Servers < Fog::Collection
5
+ model Fog::Compute::Serverlove::Server
6
+
7
+ def all
8
+ data = service.get_servers.body
9
+ load(data)
10
+ end
11
+
12
+ def get(server_id)
13
+ data = service.get_server(server_id).body
14
+ new(data)
15
+ end
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,11 @@
1
+ module Fog
2
+ module Compute
3
+ class Serverlove
4
+ class PasswordGenerator
5
+ def self.generate
6
+ ('a'...'z').to_a.concat(('A'...'Z').to_a).shuffle[0,8].join
7
+ end
8
+ end
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,28 @@
1
+ module Fog
2
+ module Compute
3
+ class Serverlove
4
+ class Real
5
+ def create_image(options)
6
+ return nil if options.empty? || options.nil?
7
+ request(:method => "post", :path => "/drives/create", :expects => 200, :options => options)
8
+ end
9
+ end
10
+
11
+ class Mock
12
+ def create_image(options = {})
13
+ response = Excon::Response.new
14
+ response.status = 200
15
+
16
+ data = {
17
+ 'drive' => Fog::Mock.random_numbers(1000000).to_s,
18
+ 'name' => options['name'] || 'Test',
19
+ 'size' => options['size'] || 12345
20
+ }
21
+
22
+ response.body = data
23
+ response
24
+ end
25
+ end
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,30 @@
1
+ module Fog
2
+ module Compute
3
+ class Serverlove
4
+ class Real
5
+ def create_server(options)
6
+ return nil if options.empty? || options.nil?
7
+ request(:method => "post", :path => "/servers/create/stopped", :expects => 200, :options => options)
8
+ end
9
+ end
10
+
11
+ class Mock
12
+ def create_server(options = {})
13
+ response = Excon::Response.new
14
+ response.status = 200
15
+
16
+ data = {
17
+ 'server' => Fog::Mock.random_numbers(1000000).to_s,
18
+ 'name' => options['name'] || 'Test',
19
+ 'cpu' => options['cpu'] || 1000,
20
+ 'persistent' => options['persistent'] || false,
21
+ 'vnc:password' => options['vnc:password'] || 'T35tServER!'
22
+ }
23
+
24
+ response.body = data
25
+ response
26
+ end
27
+ end
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,11 @@
1
+ module Fog
2
+ module Compute
3
+ class Serverlove
4
+ class Real
5
+ def destroy_image(drive_id)
6
+ request(:method => "post", :path => "/drives/#{drive_id}/destroy", :expects => 204)
7
+ end
8
+ end
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,11 @@
1
+ module Fog
2
+ module Compute
3
+ class Serverlove
4
+ class Real
5
+ def destroy_server(server_id)
6
+ request(:method => "post", :path => "/servers/#{server_id}/destroy", :expects => 204)
7
+ end
8
+ end
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,11 @@
1
+ module Fog
2
+ module Compute
3
+ class Serverlove
4
+ class Real
5
+ def get_image(image_id)
6
+ request(:method => "get", :path => "/drives/#{image_id}/info", :expects => 200)
7
+ end
8
+ end
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,11 @@
1
+ module Fog
2
+ module Compute
3
+ class Serverlove
4
+ class Real
5
+ def get_images
6
+ request(:method => "get", :path => "/drives/info", :expects => 200)
7
+ end
8
+ end
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,11 @@
1
+ module Fog
2
+ module Compute
3
+ class Serverlove
4
+ class Real
5
+ def get_server(server_id)
6
+ request(:method => "get", :path => "/servers/#{server_id}/info", :expects => 200)
7
+ end
8
+ end
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,11 @@
1
+ module Fog
2
+ module Compute
3
+ class Serverlove
4
+ class Real
5
+ def get_servers
6
+ request(:method => "get", :path => "/servers/info", :expects => 200)
7
+ end
8
+ end
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,11 @@
1
+ module Fog
2
+ module Compute
3
+ class Serverlove
4
+ class Real
5
+ def load_standard_image(destination_image, source_image)
6
+ request(:method => "post", :path => "/drives/#{destination_image}/image/#{source_image}/gunzip", :expects => 204)
7
+ end
8
+ end
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,11 @@
1
+ module Fog
2
+ module Compute
3
+ class Serverlove
4
+ class Real
5
+ def reset_server(server_id)
6
+ request(:method => "post", :path => "/servers/#{server_id}/reset", :expects => 204)
7
+ end
8
+ end
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,11 @@
1
+ module Fog
2
+ module Compute
3
+ class Serverlove
4
+ class Real
5
+ def shutdown_server(server_id)
6
+ request(:method => "post", :path => "/servers/#{server_id}/shutdown", :expects => 204)
7
+ end
8
+ end
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,11 @@
1
+ module Fog
2
+ module Compute
3
+ class Serverlove
4
+ class Real
5
+ def start_server(server_id)
6
+ request(:method => "post", :path => "/servers/#{server_id}/start", :expects => 200)
7
+ end
8
+ end
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,11 @@
1
+ module Fog
2
+ module Compute
3
+ class Serverlove
4
+ class Real
5
+ def stop_server(server_id)
6
+ request(:method => "post", :path => "/servers/#{server_id}/stop", :expects => 204)
7
+ end
8
+ end
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,13 @@
1
+ module Fog
2
+ module Compute
3
+ class Serverlove
4
+ class Real
5
+ def update_image(identifier, options)
6
+ return nil if identifier.nil? || identifier == ""
7
+ return nil if options.empty? || options.nil?
8
+ request(:method => "post", :path => "/drives/#{identifier}/set", :expects => 200, :options => options)
9
+ end
10
+ end
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,13 @@
1
+ module Fog
2
+ module Compute
3
+ class Serverlove
4
+ class Real
5
+ def update_server(identifier, options)
6
+ return nil if identifier.nil? || identifier == ""
7
+ return nil if options.empty? || options.nil?
8
+ request(:method => "post", :path => "/servers/#{identifier}/set", :expects => 200, :options => options)
9
+ end
10
+ end
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,15 @@
1
+ require 'fog/serverlove/version'
2
+ require 'fog/core'
3
+ require 'fog/json'
4
+
5
+ module Fog
6
+ module Compute
7
+ autoload :Serverlove, 'fog/compute/serverlove'
8
+ end
9
+
10
+ module Serverlove
11
+ extend Fog::Provider
12
+
13
+ service(:compute, 'Compute')
14
+ end
15
+ end
File without changes
@@ -0,0 +1,5 @@
1
+ module Fog
2
+ module Serverlove
3
+ VERSION = "0.1.0"
4
+ end
5
+ end
@@ -0,0 +1,31 @@
1
+ require 'minitest/spec'
2
+ require 'minitest/autorun'
3
+ require 'turn'
4
+
5
+ Turn.config do |c|
6
+ # use one of output formats:
7
+ # :outline - turn's original case/test outline mode [default]
8
+ # :progress - indicates progress with progress bar
9
+ # :dotted - test/unit's traditional dot-progress mode
10
+ # :pretty - new pretty reporter
11
+ # :marshal - dump output as YAML (normal run mode only)
12
+ # :cue - interactive testing
13
+ # c.format = :outline
14
+ # turn on invoke/execute tracing, enable full backtrace
15
+ c.trace = 20
16
+ # use humanized test names (works only with :outline format)
17
+ c.natural = true
18
+ end
19
+
20
+ if ENV['COVERAGE']
21
+ require 'coveralls'
22
+ require 'simplecov'
23
+
24
+ SimpleCov.start do
25
+ add_filter '/spec/'
26
+ end
27
+ end
28
+
29
+ require File.join(File.dirname(__FILE__), '../lib/fog/serverlove')
30
+
31
+ Coveralls.wear! if ENV['COVERAGE']
@@ -0,0 +1,15 @@
1
+ Shindo.tests('Fog::Compute::Serverlove::PasswordGenerator | generate password', ['serverlove']) do
2
+ @password = Fog::Compute::Serverlove::PasswordGenerator.generate
3
+
4
+ tests("@password.length").returns(8) do
5
+ @password.length
6
+ end
7
+
8
+ tests("@password contains one capital letter").returns(true) do
9
+ @password.match(/[A-Z]/) && true
10
+ end
11
+
12
+ tests("@password contains one lower case letter").returns(true) do
13
+ @password.match(/[a-z]/) && true
14
+ end
15
+ end
@@ -0,0 +1,59 @@
1
+ Shindo.tests('Fog::Compute[:serverlove] | drive requests', ['serverlove']) do
2
+ @image_format = {
3
+ 'drive' => String,
4
+ 'name' => String,
5
+ 'user' => String,
6
+ 'size' => Integer,
7
+ 'claimed' => Fog::Nullable::String,
8
+ 'status' => String,
9
+ 'encryption:cipher' => String,
10
+ 'read:bytes' => String,
11
+ 'write:bytes' => String,
12
+ 'read:requests' => String,
13
+ 'write:requests' => String
14
+ }
15
+
16
+ tests('success') do
17
+ attributes = { 'name' => 'Test', 'size' => '24234567890' }
18
+
19
+ tests("#create_image").formats(@image_format) do
20
+ pending
21
+ @image = Fog::Compute[:serverlove].create_image(attributes).body
22
+ end
23
+
24
+ tests("#list_images").succeeds do
25
+ pending
26
+ Fog::Compute[:serverlove].images
27
+ end
28
+
29
+ tests("#update_image").returns(true) do
30
+ pending
31
+ @image['name'] = "Diff"
32
+ Fog::Compute[:serverlove].update_image(@image['drive'], { :name => @image['name'], :size => @image['size']})
33
+ Fog::Compute[:serverlove].images.get(@image['drive']).name == "Diff"
34
+ end
35
+
36
+ tests("#load_standard_image").returns(true) do
37
+ pending
38
+ # Load centos
39
+ Fog::Compute[:serverlove].load_standard_image(@image['drive'], '88ed067f-d2b8-42ce-a25f-5297818a3b6f')
40
+ Fog::Compute[:serverlove].images.get(@image['drive']).imaging != "" # This will be "x%" when imaging
41
+ end
42
+
43
+ tests("waits for imaging...").returns(true) do
44
+ pending
45
+ while(percent_complete = Fog::Compute[:serverlove].images.get(@image['drive']).imaging)
46
+ sleep(1)
47
+ STDERR.print "#{percent_complete} "
48
+ break if percent_complete.include?("100")
49
+ end
50
+ STDERR.print "100% "
51
+ true
52
+ end
53
+
54
+ tests("#destroy_image").succeeds do
55
+ pending
56
+ Fog::Compute[:serverlove].destroy_image(@image['drive'])
57
+ end
58
+ end
59
+ end