fog-arubacloud 0.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (55) hide show
  1. checksums.yaml +7 -0
  2. data/.codeclimate.yml +26 -0
  3. data/.gitignore +15 -0
  4. data/.rubocop.yml +1168 -0
  5. data/.ruby-version +1 -0
  6. data/.travis.yml +18 -0
  7. data/CONTRIBUTING.md +28 -0
  8. data/CONTRIBUTORS.md +2 -0
  9. data/Gemfile +6 -0
  10. data/LICENSE.md +20 -0
  11. data/README.md +36 -0
  12. data/Rakefile +24 -0
  13. data/fog-arubacloud.gemspec +31 -0
  14. data/gemfiles/fog-arubacloud-0.0.1.gem +0 -0
  15. data/gemfiles/fog-arubacloud-0.0.2.gem +0 -0
  16. data/lib/fog/arubacloud.rb +31 -0
  17. data/lib/fog/arubacloud/compute.rb +96 -0
  18. data/lib/fog/arubacloud/error.rb +84 -0
  19. data/lib/fog/arubacloud/examples/create_pro_server.rb +53 -0
  20. data/lib/fog/arubacloud/examples/create_smart_server.rb +39 -0
  21. data/lib/fog/arubacloud/examples/get_objects.rb +44 -0
  22. data/lib/fog/arubacloud/examples/get_servers.rb +31 -0
  23. data/lib/fog/arubacloud/examples/vm_operations.rb +60 -0
  24. data/lib/fog/arubacloud/models/compute/disk.rb +47 -0
  25. data/lib/fog/arubacloud/models/compute/disks.rb +31 -0
  26. data/lib/fog/arubacloud/models/compute/ip.rb +45 -0
  27. data/lib/fog/arubacloud/models/compute/ips.rb +50 -0
  28. data/lib/fog/arubacloud/models/compute/network_adapter.rb +26 -0
  29. data/lib/fog/arubacloud/models/compute/network_adapters.rb +20 -0
  30. data/lib/fog/arubacloud/models/compute/server.rb +185 -0
  31. data/lib/fog/arubacloud/models/compute/servers.rb +43 -0
  32. data/lib/fog/arubacloud/models/compute/template.rb +33 -0
  33. data/lib/fog/arubacloud/models/compute/templates.rb +67 -0
  34. data/lib/fog/arubacloud/requests/compute/create_vm_pro.rb +88 -0
  35. data/lib/fog/arubacloud/requests/compute/create_vm_smart.rb +74 -0
  36. data/lib/fog/arubacloud/requests/compute/delete_vm.rb +50 -0
  37. data/lib/fog/arubacloud/requests/compute/get_hypervisors.rb +49 -0
  38. data/lib/fog/arubacloud/requests/compute/get_purchased_ip_addresses.rb +79 -0
  39. data/lib/fog/arubacloud/requests/compute/get_server_details.rb +51 -0
  40. data/lib/fog/arubacloud/requests/compute/get_servers.rb +86 -0
  41. data/lib/fog/arubacloud/requests/compute/power_off_vm.rb +51 -0
  42. data/lib/fog/arubacloud/requests/compute/power_on_vm.rb +49 -0
  43. data/lib/fog/arubacloud/requests/compute/purchase_ip.rb +62 -0
  44. data/lib/fog/arubacloud/requests/compute/reinitialize_vm.rb +56 -0
  45. data/lib/fog/arubacloud/requests/compute/remove_ip.rb +53 -0
  46. data/lib/fog/arubacloud/service.rb +54 -0
  47. data/lib/fog/arubacloud/version.rb +12 -0
  48. data/spec/fog/arubacloud/config_spec.rb +0 -0
  49. data/spec/fog/compute/arubacloud/server_spec.rb +26 -0
  50. data/spec/fog/compute/arubacloud/servers_spec.rb +11 -0
  51. data/spec/fog/compute/arubacloud_spec.rb +32 -0
  52. data/spec/model_setup.rb +16 -0
  53. data/spec/spec_helper.rb +6 -0
  54. data/tests/test_helper.rb +8 -0
  55. metadata +217 -0
data/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ 2.1.5
data/.travis.yml ADDED
@@ -0,0 +1,18 @@
1
+ language: ruby
2
+ sudo: false
3
+ matrix:
4
+ fast_finish: true
5
+ include:
6
+ - rvm: 2.0
7
+ - rvm: 2.1
8
+ - rvm: 2.2
9
+ - rvm: jruby-head
10
+ allow_failures:
11
+ - rvm: jruby-head
12
+
13
+ notifications:
14
+ email: false
15
+
16
+ addons:
17
+ code_climate:
18
+ repo_token: aa685a2a9df69442e10939c85a9bd733c8baaef581d7ec8f8596e637f6abfe66
data/CONTRIBUTING.md ADDED
@@ -0,0 +1,28 @@
1
+ # Getting Involved
2
+
3
+ New contributors are always welcome, and when in doubt please ask questions! We strive to be an open and welcoming community. Please be nice to one another.
4
+
5
+ I recommend heading over to fog's [CONTRIBUTING](https://github.com/blackms/fog/blob/master/CONTRIBUTING.md) and having a look around as well. It has information and context about the state of the `fog` project as a whole.
6
+
7
+ ### Coding
8
+
9
+ * Pick a task:
10
+ * Offer feedback on open [pull requests](https://github.com/blackms/fog-arubacloud/pulls).
11
+ * Review open [issues](https://github.com/blackms/fog-arubacloud/issues) for things to help on.
12
+ * [Create an issue](https://github.com/blackms/fog-arubacloud/issues/new) to start a discussion on additions or features.
13
+ * Fork the project, add your changes and tests to cover them in a topic branch.
14
+ * [Fork](https://github.com/blackms/fog-arubacloud/fork)
15
+ * Create your feature branch (`git checkout -b my-new-feature`)
16
+ * Commit your changes (`git commit -am 'Add some feature'`)
17
+ * Push to the branch (`git push origin my-new-feature`)
18
+ * Create a new pull request
19
+ * Commit your changes and rebase against `fog/fog-arubacloud` to ensure everything is up to date.
20
+ * [Submit a pull request](https://github.com/blackms/fog-arubacloud/compare/)
21
+
22
+ ### Non-Coding
23
+
24
+ * Offer feedback on open [issues](https://github.com/blackms/fog-arubacloud/issues).
25
+
26
+ ## Contributing Code
27
+
28
+ This document is very much a work in progress. Sorry about that.
data/CONTRIBUTORS.md ADDED
@@ -0,0 +1,2 @@
1
+ * Alessio Rocchi <alessio.rocchi@staff.aruba.it>
2
+ * ArubaCloud
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in fog-arubacloud.gemspec
4
+ gemspec
5
+
6
+ gem 'codeclimate-test-reporter', group: :test, require: nil
data/LICENSE.md ADDED
@@ -0,0 +1,20 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2014-2014 [CONTRIBUTORS.md](https://github.com/blackms/fog-arubacloud/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,36 @@
1
+ # Fog::Arubacloud
2
+
3
+ [![Code Climate](https://codeclimate.com/github/fog/fog-arubacloud/badges/gpa.svg)](https://codeclimate.com/github/fog/fog-arubacloud)
4
+ [![Test Coverage](https://codeclimate.com/github/fog/fog-arubacloud/badges/coverage.svg)](https://codeclimate.com/github/fog/fog-arubacloud/coverage)
5
+ [![Gitter](https://badges.gitter.im/fog/fog-arubacloud.svg)](https://gitter.im/fog/fog-arubacloud?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=body_badge)
6
+
7
+ Module for the 'fog' gem to support ArubaCloud IaaS Service
8
+
9
+ ## Installation
10
+
11
+ Add this line to your application's Gemfile:
12
+
13
+ ```ruby
14
+ gem 'fog-arubacloud'
15
+ ```
16
+
17
+ And then execute:
18
+
19
+ $ bundle
20
+
21
+ Or install it yourself as:
22
+
23
+ $ gem install fog-arubacloud
24
+
25
+ ## Usage
26
+
27
+ TODO: Write usage instructions here
28
+
29
+ ## Contributing
30
+
31
+ 1. Fork it ( https://github.com/[my-github-username]/fog-arubacloud/fork )
32
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
33
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
34
+ 4. Push to the branch (`git push origin my-new-feature`)
35
+ 5. Create a new Pull Request
36
+ # fog-arubacloud
data/Rakefile ADDED
@@ -0,0 +1,24 @@
1
+ require 'bundler/gem_tasks'
2
+
3
+ require 'rubygems'
4
+ require 'bundler/setup'
5
+ require 'rake/testtask'
6
+
7
+ require File.dirname(__FILE__) + '/lib/fog/arubacloud'
8
+
9
+ task :default => :test
10
+ mock = ENV['FOG_MOCK'] || 'true'
11
+
12
+ Rake::TestTask.new do |t|
13
+ t.pattern = File.join('spec', '**', '*_spec.rb')
14
+ t.libs << 'spec'
15
+ end
16
+
17
+ namespace :test do
18
+ task :arubacloud_specs do
19
+ sh('export FOG_MOCK=false && bundle exec rspec spec/fog/arubacloud/*_spec.rb')
20
+ end
21
+ task :travis => [:arubacloud_specs] do
22
+ sh("export FOG_MOCK=#{mock} && bundle exec shindont")
23
+ end
24
+ end
@@ -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/arubacloud/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = 'fog-arubacloud'
8
+ spec.version = Fog::Arubacloud::VERSION
9
+ spec.authors = ['Alessio Rocchi']
10
+ spec.email = ['alessio.rocchi@staff.aruba.it']
11
+ spec.summary = %q{Module for the 'fog' gem to support ArubaCloud}
12
+ spec.description = %q{This library can be used as a module for 'fog' or a standalone provider to use
13
+ the ArubaCloud IaaS in applications}
14
+ spec.homepage = 'https://www.github.com/blackms/fog-arubacloud'
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('bundler')
26
+ spec.add_development_dependency('rake')
27
+ spec.add_development_dependency('rspec')
28
+ spec.add_development_dependency('webmock')
29
+ spec.add_development_dependency('shindo')
30
+ spec.add_development_dependency('minitest')
31
+ end
Binary file
Binary file
@@ -0,0 +1,31 @@
1
+ #
2
+ # Author:: Alessio Rocchi (<alessio.rocchi@staff.aruba.it>)
3
+ # © Copyright ArubaCloud.
4
+ #
5
+ # LICENSE: MIT (http://opensource.org/licenses/MIT)
6
+ #
7
+
8
+ require 'fog/core'
9
+ require 'fog/json'
10
+
11
+
12
+ module Fog
13
+ module Compute
14
+ autoload :ArubaCloud, File.expand_path('../arubacloud/compute', __FILE__)
15
+
16
+ def self.new(attributes)
17
+ attributes.delete(:provider)
18
+ Fog::Compute::ArubaCloud.new(attributes)
19
+ end
20
+
21
+ end
22
+
23
+ module ArubaCloud
24
+ extend Fog::Provider
25
+
26
+ DEFAULT_API_VERSION = '2.9'
27
+ DEFAULT_WS_ENDUSER_URL = "https://api.dc2.computing.cloud.it/WsEndUser/v#{DEFAULT_API_VERSION}/WsEndUser.svc/json"
28
+
29
+ service(:compute, 'Compute')
30
+ end
31
+ end
@@ -0,0 +1,96 @@
1
+ #
2
+ # Author:: Alessio Rocchi (<alessio.rocchi@staff.aruba.it>)
3
+ # © Copyright ArubaCloud.
4
+ #
5
+ # LICENSE: MIT (http://opensource.org/licenses/MIT)
6
+ #
7
+
8
+ require 'fog/arubacloud/service'
9
+
10
+ module Fog
11
+ module Compute
12
+ class ArubaCloud < Fog::Service
13
+
14
+ # Define global constant to enumerate service type (We will need them in Vagrant :P)
15
+ PRO_HV = 1
16
+ PRO_VMW = 2
17
+ PRO_HV_LC = 3
18
+ SMART = 4
19
+
20
+ recognizes :url
21
+ requires :arubacloud_username, :arubacloud_password
22
+
23
+ # Models
24
+ model_path 'fog/arubacloud/models/compute'
25
+ collection :servers
26
+ model :server
27
+ collection :ips
28
+ model :ip
29
+ collection :templates
30
+ model :template
31
+ collection :disks
32
+ model :disk
33
+ collection :network_adapters
34
+ model :network_adapter
35
+
36
+ # Requests
37
+ request_path 'fog/arubacloud/requests/compute'
38
+ request :power_on_vm
39
+ request :power_off_vm
40
+ request :get_servers
41
+ request :get_server_details
42
+ request :delete_vm
43
+ request :create_vm_pro
44
+ request :create_vm_smart
45
+ request :purchase_ip
46
+ request :remove_ip
47
+ request :get_purchased_ip_addresses
48
+ request :get_hypervisors
49
+ request :reinitialize_vm
50
+
51
+ # Mock class to run a fake instance of the Service with no real connections.
52
+ class Mock < Fog::ArubaCloud::Service
53
+ def initialize(options={})
54
+ @arubacloud_username = options[:arubacloud_username] || ''
55
+ @arubacloud_password = options[:arubacloud_password] || ''
56
+ @ws_enduser_url = options[:url] || Fog::ArubaCloud::DEFAULT_WS_ENDUSER_URL
57
+ end
58
+
59
+ # Return the base json object used by each request.
60
+ # @param method [String] the name of the method to call.
61
+ # @return [Hash] base scheme for json request.
62
+ def body(method)
63
+ {
64
+ :ApplicationId => method,
65
+ :RequestId => method,
66
+ :Sessionid => method,
67
+ :Username => @arubacloud_username,
68
+ :Password => @arubacloud_password
69
+ }
70
+ end
71
+ end #Mock
72
+
73
+ class Real < Fog::ArubaCloud::Service
74
+ def initialize(options={})
75
+ @arubacloud_username = options[:arubacloud_username] || ''
76
+ @arubacloud_password = options[:arubacloud_password] || ''
77
+ @ws_enduser_url = options[:url] || Fog::ArubaCloud::DEFAULT_WS_ENDUSER_URL
78
+ end
79
+
80
+ # Return the base json object used by each request.
81
+ # @param method [String] the name of the method to call.
82
+ # @return [Hash] base scheme for json request.
83
+ def body(method)
84
+ {
85
+ :ApplicationId => method,
86
+ :RequestId => method,
87
+ :Sessionid => method,
88
+ :Username => @arubacloud_username,
89
+ :Password => @arubacloud_password
90
+ }
91
+ end
92
+ end #Real
93
+
94
+ end #ArubaCloud
95
+ end #Compute
96
+ end #Fog
@@ -0,0 +1,84 @@
1
+ #
2
+ # Author:: Alessio Rocchi (<alessio.rocchi@staff.aruba.it>)
3
+ # © Copyright ArubaCloud.
4
+ #
5
+ # LICENSE: MIT (http://opensource.org/licenses/MIT)
6
+ #
7
+
8
+ module Fog
9
+ module ArubaCloud
10
+ module Errors
11
+
12
+ class Error < Fog::Errors::Error
13
+ attr_accessor :type, :error_point
14
+
15
+ def initialize(message, type='n/a', error_point=nil)
16
+ @type = type
17
+ @error_point = error_point
18
+ super(message)
19
+ end
20
+ end
21
+
22
+ class BadObjectType < Error
23
+ def initialize(message='BadObjectType', expected=nil, received=nil)
24
+ @expected = expected
25
+ @received = received
26
+ super(message)
27
+ end
28
+ end
29
+
30
+ # This class will contains the response object in order to access the ResultCode easily.
31
+ class RequestError < Fog::Errors::Error
32
+ attr_accessor :type, :error_point, :response
33
+
34
+ def initialize(message, response=nil, type='n/a', error_point=nil)
35
+ @type = type
36
+ @error_point = error_point
37
+ @response = response
38
+ super(message)
39
+ end
40
+ end
41
+
42
+ class NotFound < Error
43
+
44
+ end
45
+
46
+ class BadParameters < Error
47
+
48
+ end
49
+
50
+ class VmStatus < Error
51
+
52
+ end
53
+
54
+ class BadDiskSize < Error
55
+
56
+ end
57
+
58
+ class BadDiskNumber < Error
59
+
60
+ end
61
+
62
+ class InvalidStateException < ::RuntimeError
63
+ attr_reader :desired_state
64
+ attr_reader :current_state
65
+
66
+ def initialize(desired_state, current_state)
67
+ @desired_state = desired_state
68
+ @current_state = current_state
69
+ end
70
+ end
71
+
72
+ class InvalidServerStateException < InvalidStateException
73
+ def to_s
74
+ "Server should have transitioned to '#{desired_state}' not '#{current_state}'"
75
+ end
76
+ end
77
+
78
+ class RequestTimeOut < Error
79
+
80
+ end
81
+
82
+ end
83
+ end
84
+ end
@@ -0,0 +1,53 @@
1
+ #
2
+ # Author:: Alessio Rocchi (<alessio.rocchi@staff.aruba.it>)
3
+ # © Copyright ArubaCloud.
4
+ #
5
+ # LICENSE: MIT (http://opensource.org/licenses/MIT)
6
+ #
7
+
8
+ require 'rubygems'
9
+ require 'fog/arubacloud'
10
+ require 'securerandom'
11
+ require 'optparse'
12
+
13
+ options = {}
14
+ OptionParser.new do |opts|
15
+ opts.banner = 'Usage: get_servers.rb [options]'
16
+ opts.on('-uUSERNAME', '--username=USERNAME', 'ArubaCloud Username') { |n| options[:username] = n}
17
+ opts.on('-pPASSWORD', '--password=PASSWORD', 'ArubaCloud Password') { |p| options[:password] = p}
18
+ end.parse!
19
+
20
+ # Fog.mock!
21
+ service = Fog::Compute.new({
22
+ :provider => 'ArubaCloud',
23
+ :arubacloud_username => options[:username],
24
+ :arubacloud_password => options[:password]
25
+ })
26
+
27
+ ## Generate random string to append to vm name
28
+ rnd_string = SecureRandom.hex(2)
29
+
30
+ # Create a Pro VM
31
+ ## Create first disk
32
+ disk0 = service.disks.create({
33
+ :size => 20,
34
+ :virtual_disk_type => 0
35
+ }).get_hash
36
+ ## Create second disk
37
+ disk1 = service.disks.create({
38
+ :size => 30,
39
+ :virtual_disk_type => 1
40
+ }).get_hash
41
+ ## Create the Array containing both disks
42
+ disks = [disk0, disk1]
43
+
44
+ ## Create the virtual machine
45
+ server = service.servers.create({
46
+ :name => "testpro#{rnd_string}",
47
+ :vm_type => 'pro',
48
+ :admin_passwd => 'Prova123',
49
+ :cpu => 1,
50
+ :memory => 1,
51
+ :template_id => 60, # ac_Centos6_web_x64_3_1
52
+ :disks => disks
53
+ })