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
@@ -0,0 +1,43 @@
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/collection'
9
+ require 'fog/arubacloud/models/compute/server'
10
+
11
+
12
+ module Fog
13
+ module Compute
14
+ class ArubaCloud
15
+ class Servers < Fog::Collection
16
+ model Fog::Compute::ArubaCloud::Server
17
+
18
+ # Returns list of servers
19
+ # @return [Fog::Compute::ArubaCloud::Servers] Retrieves a list servers.
20
+ # @raise [Fog::Compute::ArubaCloud::NotFound]
21
+ # @note The filter parameter on the method is just to maintain compatibility with other providers that support
22
+ # filtering.
23
+ def all(filters = [])
24
+ data = service.get_servers
25
+ objects = data['Value']
26
+ load(objects)
27
+ end
28
+
29
+ # Retrieves server
30
+ # @param [String] server_id for server to be returned.
31
+ # @return [Fog::Compute::ArubaCloud::Server]
32
+ def get(server_id)
33
+ data = service.get_server_details(server_id)
34
+ objects = data['Value']
35
+ msg = "Fog::Compute::ArubaCloud::Servers.get 'objects' must be an hash, actually is: #{objects.class} #{objects.to_yaml}"
36
+ Fog::Logger.debug(msg)
37
+ raise Fog::ArubaCloud::Errors::BadObjectType.new("#{msg}") unless objects.instance_of? Hash
38
+ new(objects)
39
+ end
40
+ end
41
+ end
42
+ end
43
+ end
@@ -0,0 +1,33 @@
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/model'
9
+
10
+ module Fog
11
+ module Compute
12
+ class ArubaCloud
13
+
14
+ class Template < Fog::Model
15
+ identity :id, :aliases => 'Id'
16
+
17
+ attribute :name, :aliases => 'Name'
18
+ attribute :description, :aliases => 'Description'
19
+ attribute :enabled, :aliases => 'Enabled'
20
+ attribute :export_enabled, :aliases => 'ExportEnabled'
21
+ attribute :identification_code, :aliases => 'IdentificationCode'
22
+ attribute :product_id, :aliases => 'ProductId'
23
+ attribute :hypervisor
24
+
25
+ ignore_attributes :ApplianceType, :ArchitectureType, :CompanyID, :CompatiblePreConfiguredPackages,
26
+ :FeatureTypes, :Icon, :OwnerUserId, :ParentTemplateID, :OSFamily, :OSVersion, :ResourceBounds,
27
+ :Revision, :TemplateExtendedDescription, :TemplateOwnershipType, :TemplatePassword,
28
+ :TemplateSellingStatus, :TemplateType, :TemplateUsername, :ToolsAvailable
29
+ end
30
+
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,67 @@
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/collection'
9
+ require 'fog/arubacloud/models/compute/template'
10
+
11
+
12
+ module Fog
13
+ module Compute
14
+ class ArubaCloud
15
+ class Templates < Fog::Collection
16
+ model Fog::Compute::ArubaCloud::Template
17
+
18
+ # Returns list of Template
19
+ # @return [Fog::Compute::ArubaCloud::Template] Retrieves the complete Templates list.
20
+ # @raise [Fog::Compute::ArubaCloud::NotFound]
21
+ def all
22
+ data = service.get_hypervisors
23
+ objects = data['Value']
24
+ manipulated_objects = Array.new
25
+ objects.each do |h|
26
+ hv_type = h['HypervisorType']
27
+ h['Templates'].each do |t|
28
+ t.merge!({'hypervisor' => hv_type})
29
+ manipulated_objects << t
30
+ end
31
+ end
32
+ load(manipulated_objects)
33
+ end
34
+
35
+ # Return only templates assigned to a specific service, default is smart (4)
36
+ # @param hv [Int] The ID of the hypervisor
37
+ # @return [Fog::Compute::ArubaCloud::Template] List of templates
38
+ # @raise [Fog::Compute::ArubaCloud::NotFound]
39
+ def get_hypervisor(hv=4)
40
+ manipulated_objects = Array.new
41
+ data = service.get_hypervisors
42
+ objects = data['Value']
43
+ objects.each do |h|
44
+ hv_type = h['HypervisorType']
45
+ h['Templates'].each do |t|
46
+ # select{|f| f['HypervisorType'].eql?(hv)}
47
+ t.merge!({'hypervisor' => hv_type})
48
+ if t['hypervisor'].eql?(4)
49
+ Fog::Logger.debug("Fog::Compute::ArubaCloud::Templates.get_hypervisors: t: #{h.to_yaml}")
50
+ manipulated_objects << t
51
+ end
52
+ end
53
+ end
54
+ load(manipulated_objects)
55
+ end
56
+
57
+ # Retrieves Single Template Item
58
+ # @param [String] template_id for server to be returned.
59
+ # @return [Fog::Compute::ArubaCloud::Template]
60
+ def get(template_id)
61
+ # TODO: Implement retrieve of a single template
62
+ end
63
+
64
+ end
65
+ end
66
+ end
67
+ end
@@ -0,0 +1,88 @@
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
+ require 'benchmark'
10
+
11
+ module Fog
12
+ module Compute
13
+ class ArubaCloud
14
+ class Real
15
+ # Create a new VM: Pro.
16
+ # @param [String] name name of the server
17
+ # @param [String] admin_password server administrative password
18
+ # @param [Int] cpu amount of vcpu
19
+ # @param [Int] ram amount of ram in GB
20
+ # @param [String] template_id id of template to use
21
+ # @param [String] ipv4_id if present, the ID of the ip resource to associate
22
+ # @param [String] note Metadata for VM
23
+ # @return [Excon::Response]
24
+ def create_vm_pro(data)
25
+ body = self.body('SetEnqueueServerCreation').merge(
26
+ {
27
+ :Server => {
28
+ :AdministratorPassword => data[:admin_passwd],
29
+ :CPUQuantity => data[:cpu],
30
+ :Name => data[:name],
31
+ :NetworkAdaptersConfiguration => [],
32
+ :Note => 'Created by Fog Cloud.',
33
+ :OSTemplateId => data[:template_id],
34
+ :RAMQuantity => data[:memory],
35
+ :VirtualDisks => []
36
+ }
37
+ }
38
+ )
39
+ unless data[:ipv4_id].nil?
40
+ body[:Server][:NetworkAdaptersConfiguration] << {
41
+ :NetworkAdapterType => 0,
42
+ :PublicIpAddresses => [{
43
+ :PrimaryIPAddress => 'true',
44
+ :PublicIpAddressResourceId => data[:ipv4_id]
45
+ }]
46
+ }
47
+ end
48
+ unless data[:disks].nil? && data[:disks].instance_of?(Array)
49
+ data[:disks].each { |d| body[:Server][:VirtualDisks] << d}
50
+ end
51
+
52
+ options = {
53
+ :http_method => :post,
54
+ :method => 'SetEnqueueServerCreation',
55
+ :body => Fog::JSON.encode(body)
56
+ }
57
+
58
+ response = nil
59
+ time = Benchmark.realtime {
60
+ response = request(options)
61
+ }
62
+ Fog::Logger.debug("SetEnqueueServerCreation time: #{time}")
63
+ if response['Success']
64
+ response
65
+ else
66
+ raise Fog::ArubaCloud::Errors::RequestError.new("Error during the VM creation. Object: \n#{body}\nError: \n#{response}")
67
+ end
68
+
69
+ end
70
+ end
71
+
72
+ class Mock
73
+ def create_vm_pro(data)
74
+ response = Excon::Response.new
75
+ response.status = 201
76
+ response.body = {
77
+ 'ExceptionInfo' => nil,
78
+ 'ResultCode' => 0,
79
+ 'ResultMessage' => nil,
80
+ 'Success' => true
81
+ }
82
+ response.body
83
+ end
84
+ end
85
+
86
+ end # ArubaCloud
87
+ end # Compute
88
+ end # Fog
@@ -0,0 +1,74 @@
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
13
+ class Real
14
+ # Create a new VM: Smart.
15
+ # @param [String] name name of the server
16
+ # @param [String] admin_password server administrative password
17
+ # @param [String] template_id id of template to use
18
+ # @param [Int] size
19
+ # * 1 => small
20
+ # * 2 => medium
21
+ # * 3 => large
22
+ # * 4 => extra-large
23
+ # @param [String] note Metadata for VM
24
+ # @return [Excon::Response]
25
+ def create_vm_smart(data)
26
+ body = self.body('SetEnqueueServerCreation').merge(
27
+ {
28
+ :Server => {
29
+ :AdministratorPassword => data[:admin_passwd],
30
+ :Name => data[:name],
31
+ :SmartVMWarePackageID => data[:size] || 1,
32
+ :Note => data[:note] || 'Created by Fog Cloud.',
33
+ :OSTemplateId => data[:template_id]
34
+ }
35
+ }
36
+ )
37
+
38
+ options = {
39
+ :http_method => :post,
40
+ :method => 'SetEnqueueServerCreation',
41
+ :body => Fog::JSON.encode(body),
42
+ }
43
+
44
+ response = nil
45
+ time = Benchmark.realtime {
46
+ response = request(options)
47
+ }
48
+ Fog::Logger.debug("SetEnqueueServerCreation time: #{time}")
49
+ if response['Success']
50
+ response
51
+ else
52
+ raise Fog::ArubaCloud::Errors::RequestError.new("Error during the VM creation. Object: \n#{body}",
53
+ response=response)
54
+ end
55
+ end
56
+ end
57
+
58
+ class Mock
59
+ def create_vm_smart(data)
60
+ response = Excon::Response.new
61
+ response.status = 201
62
+ response.body = {
63
+ 'ExceptionInfo' => nil,
64
+ 'ResultCode' => 0,
65
+ 'ResultMessage' => nil,
66
+ 'Success' => true
67
+ }
68
+ response.body
69
+ end # create_vm_smart
70
+ end # Mock
71
+
72
+ end # ArubaCloud
73
+ end # Compute
74
+ end # Fog
@@ -0,0 +1,50 @@
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 Compute
10
+ class ArubaCloud
11
+
12
+ class Real
13
+ def delete_vm(id)
14
+ body = self.body('SetEnqueueServerDeletion').merge({:ServerId => "#{id}"})
15
+ options = {
16
+ :http_method => :post,
17
+ :method => 'SetEnqueueServerDeletion',
18
+ :body => Fog::JSON.encode(body)
19
+ }
20
+ response = nil
21
+ time = Benchmark.realtime {
22
+ response = request(options)
23
+ }
24
+ Fog::Logger.debug("SetEnqueueServerDeletion time: #{time}")
25
+ if response['Success']
26
+ response
27
+ else
28
+ raise Fog::ArubaCloud::Errors::RequestError.new("Error Powering off the VM. Error: #{response}")
29
+ end
30
+ end # delete_vm
31
+ end # Real
32
+
33
+ class Mock
34
+ def delete_vm(id)
35
+ self.servers.select!{|s| s.id.eql?(id)}
36
+ response = Excon::Response.new
37
+ response.status = 200
38
+ response.body = {
39
+ 'ExceptionInfo' => nil,
40
+ 'ResultCode' => 0,
41
+ 'ResultMessage' => nil,
42
+ 'Success' => true
43
+ }
44
+ response.body
45
+ end # delete_vm
46
+ end # Mock
47
+
48
+ end # ArubaCloud
49
+ end # Compute
50
+ end # Fog
@@ -0,0 +1,49 @@
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
+ require 'fog/arubacloud/error'
10
+ require 'benchmark'
11
+
12
+ module Fog
13
+ module Compute
14
+ class ArubaCloud
15
+ class Real
16
+ def get_hypervisors
17
+ body = self.body('GetHypervisors')
18
+ options = {
19
+ :http_method => :post,
20
+ :method => 'GetHypervisors',
21
+ :body => Fog::JSON.encode(body)
22
+ }
23
+ response = nil
24
+ time = Benchmark.realtime {
25
+ response = request(options)
26
+ }
27
+ Fog::Logger.debug("GetHypervisors time: #{time}")
28
+ if response['Success']
29
+ response
30
+ else
31
+ raise Fog::ArubaCloud::Errors::RequestError.new('Error in request.')
32
+ end
33
+ end # get_hypervisors
34
+ end # Real
35
+
36
+ class Mock
37
+ # Due to the length of the response body, I actually decided to not implement
38
+ # the mock method of the request. I will introduce it in the next version after structuring the mock
39
+ # objects in a more reasonable way.
40
+ def get_hypervisors
41
+ raise Fog::Errors::MockNotImplemented.new(
42
+ 'Mock object for get_hypervisor not present, read code comments for details.'
43
+ )
44
+ end # get_hypervisors
45
+ end # Mock
46
+
47
+ end # ArubaCloud
48
+ end # Compute
49
+ end # Fog
@@ -0,0 +1,79 @@
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
+ require 'fog/arubacloud/error'
10
+ require 'benchmark'
11
+
12
+ module Fog
13
+ module Compute
14
+ class ArubaCloud
15
+
16
+ # noinspection RubyResolve
17
+ class Real
18
+ def get_purchased_ip_addresses
19
+ body = self.body('GetPurchasedIpAddresses')
20
+ get_servers_options = {
21
+ :http_method => :post,
22
+ :method => 'GetPurchasedIpAddresses',
23
+ :body => Fog::JSON.encode(body)
24
+ }
25
+ response = nil
26
+ time = Benchmark.realtime {
27
+ response = request(get_servers_options)
28
+ }
29
+ Fog::Logger.debug("GetPurchasedIpAddresses time: #{time}")
30
+ if response['Success']
31
+ response
32
+ else
33
+ raise Fog::ArubaCloud::Error::RequestError
34
+ end
35
+ end # get_purchased_ip_addresses
36
+ end # Real
37
+
38
+ class Mock
39
+ def get_purchased_ip_addresses
40
+ response = Excon::Response.new
41
+ response.status = 200
42
+ response.body = {
43
+ 'ExceptionInfo' => nil,
44
+ 'ResultCode' => 0,
45
+ 'ResultMessage' => nil,
46
+ 'Success' => true,
47
+ 'Value' => [
48
+ {
49
+ 'CompanyId' => 1,
50
+ 'ProductId' => 20,
51
+ 'ResourceId' => 96052,
52
+ 'ResourceType' => 6,
53
+ 'UserId' => 1856,
54
+ 'Gateway' => '5.249.158.1',
55
+ 'LoadBalancerID' => nil,
56
+ 'ServerId' => nil,
57
+ 'SubNetMask' => '255.255.255.0',
58
+ 'Value' => '5.249.158.66'
59
+ }, {
60
+ 'CompanyId' => 1,
61
+ 'ProductId' => 20,
62
+ 'ResourceId' => 96054,
63
+ 'ResourceType' => 6,
64
+ 'UserId' => 1856,
65
+ 'Gateway' => '5.249.158.1',
66
+ 'LoadBalancerID' => nil,
67
+ 'ServerId' => nil,
68
+ 'SubNetMask' => '255.255.255.0',
69
+ 'Value' => '5.249.158.102'
70
+ }
71
+ ]
72
+ }
73
+ response.body
74
+ end # get_purchased_ip_addresses
75
+ end # Mock
76
+
77
+ end # ArubaCloud
78
+ end # Compute
79
+ end # Fog