fog-arubacloud 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.codeclimate.yml +26 -0
- data/.gitignore +15 -0
- data/.rubocop.yml +1168 -0
- data/.ruby-version +1 -0
- data/.travis.yml +18 -0
- data/CONTRIBUTING.md +28 -0
- data/CONTRIBUTORS.md +2 -0
- data/Gemfile +6 -0
- data/LICENSE.md +20 -0
- data/README.md +36 -0
- data/Rakefile +24 -0
- data/fog-arubacloud.gemspec +31 -0
- data/gemfiles/fog-arubacloud-0.0.1.gem +0 -0
- data/gemfiles/fog-arubacloud-0.0.2.gem +0 -0
- data/lib/fog/arubacloud.rb +31 -0
- data/lib/fog/arubacloud/compute.rb +96 -0
- data/lib/fog/arubacloud/error.rb +84 -0
- data/lib/fog/arubacloud/examples/create_pro_server.rb +53 -0
- data/lib/fog/arubacloud/examples/create_smart_server.rb +39 -0
- data/lib/fog/arubacloud/examples/get_objects.rb +44 -0
- data/lib/fog/arubacloud/examples/get_servers.rb +31 -0
- data/lib/fog/arubacloud/examples/vm_operations.rb +60 -0
- data/lib/fog/arubacloud/models/compute/disk.rb +47 -0
- data/lib/fog/arubacloud/models/compute/disks.rb +31 -0
- data/lib/fog/arubacloud/models/compute/ip.rb +45 -0
- data/lib/fog/arubacloud/models/compute/ips.rb +50 -0
- data/lib/fog/arubacloud/models/compute/network_adapter.rb +26 -0
- data/lib/fog/arubacloud/models/compute/network_adapters.rb +20 -0
- data/lib/fog/arubacloud/models/compute/server.rb +185 -0
- data/lib/fog/arubacloud/models/compute/servers.rb +43 -0
- data/lib/fog/arubacloud/models/compute/template.rb +33 -0
- data/lib/fog/arubacloud/models/compute/templates.rb +67 -0
- data/lib/fog/arubacloud/requests/compute/create_vm_pro.rb +88 -0
- data/lib/fog/arubacloud/requests/compute/create_vm_smart.rb +74 -0
- data/lib/fog/arubacloud/requests/compute/delete_vm.rb +50 -0
- data/lib/fog/arubacloud/requests/compute/get_hypervisors.rb +49 -0
- data/lib/fog/arubacloud/requests/compute/get_purchased_ip_addresses.rb +79 -0
- data/lib/fog/arubacloud/requests/compute/get_server_details.rb +51 -0
- data/lib/fog/arubacloud/requests/compute/get_servers.rb +86 -0
- data/lib/fog/arubacloud/requests/compute/power_off_vm.rb +51 -0
- data/lib/fog/arubacloud/requests/compute/power_on_vm.rb +49 -0
- data/lib/fog/arubacloud/requests/compute/purchase_ip.rb +62 -0
- data/lib/fog/arubacloud/requests/compute/reinitialize_vm.rb +56 -0
- data/lib/fog/arubacloud/requests/compute/remove_ip.rb +53 -0
- data/lib/fog/arubacloud/service.rb +54 -0
- data/lib/fog/arubacloud/version.rb +12 -0
- data/spec/fog/arubacloud/config_spec.rb +0 -0
- data/spec/fog/compute/arubacloud/server_spec.rb +26 -0
- data/spec/fog/compute/arubacloud/servers_spec.rb +11 -0
- data/spec/fog/compute/arubacloud_spec.rb +32 -0
- data/spec/model_setup.rb +16 -0
- data/spec/spec_helper.rb +6 -0
- data/tests/test_helper.rb +8 -0
- metadata +217 -0
@@ -0,0 +1,51 @@
|
|
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
|
+
class Real
|
17
|
+
# Return the server details
|
18
|
+
# @return [Excon::Response]
|
19
|
+
def get_server_details(server_id)
|
20
|
+
body = self.body('GetServerDetails').merge({:ServerId => server_id})
|
21
|
+
options = {
|
22
|
+
:http_method => :post,
|
23
|
+
:method => 'GetServerDetails',
|
24
|
+
:body => Fog::JSON.encode(body)
|
25
|
+
}
|
26
|
+
response = nil
|
27
|
+
time = Benchmark.realtime {
|
28
|
+
response = request(options)
|
29
|
+
}
|
30
|
+
Fog::Logger.debug("GetServerDetails time: #{time}")
|
31
|
+
if response['Success']
|
32
|
+
response
|
33
|
+
else
|
34
|
+
raise Fog::ArubaCloud::Errors::RequestError.new(
|
35
|
+
"Error during GetServerDetails request. Error message: \n#{response}"
|
36
|
+
)
|
37
|
+
end
|
38
|
+
end # get_server_details
|
39
|
+
end # Real
|
40
|
+
|
41
|
+
class Mock
|
42
|
+
def get_server_details(server_id)
|
43
|
+
raise Fog::Errors::MockNotImplemented.new(
|
44
|
+
'Mock not implemented. Feel free to contribute.'
|
45
|
+
)
|
46
|
+
end # get_server_details
|
47
|
+
end # Mock
|
48
|
+
|
49
|
+
end # ArubaCloud
|
50
|
+
end # Compute
|
51
|
+
end # Fog
|
@@ -0,0 +1,86 @@
|
|
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
|
+
class Real
|
17
|
+
def get_servers
|
18
|
+
body = self.body('GetServers')
|
19
|
+
options = {
|
20
|
+
:http_method => :post,
|
21
|
+
:method => 'GetServers',
|
22
|
+
:body => Fog::JSON.encode(body)
|
23
|
+
}
|
24
|
+
response = nil
|
25
|
+
time = Benchmark.realtime {
|
26
|
+
response = request(options)
|
27
|
+
}
|
28
|
+
Fog::Logger.debug("GetServer time: #{time}")
|
29
|
+
if response['Success']
|
30
|
+
response
|
31
|
+
else
|
32
|
+
raise Fog::ArubaCloud::Errors::RequestError.new(response)
|
33
|
+
end
|
34
|
+
end # get_servers
|
35
|
+
end # Real
|
36
|
+
|
37
|
+
class Mock
|
38
|
+
def get_servers
|
39
|
+
response = Excon::Response.new
|
40
|
+
response.status = 200
|
41
|
+
response.body = {
|
42
|
+
'ExceptionInfo' => nil,
|
43
|
+
'ResultCode' => 0,
|
44
|
+
'ResultMessage' => nil,
|
45
|
+
'Success' => true,
|
46
|
+
'Value' => [
|
47
|
+
{
|
48
|
+
'Busy' => false,
|
49
|
+
'CPUQuantity' => 1,
|
50
|
+
'CompanyId' => 1,
|
51
|
+
'DatacenterId' => 2,
|
52
|
+
'HDQuantity' => 1,
|
53
|
+
'HDTotalSize' => 20,
|
54
|
+
'HypervisorServerType' => 2,
|
55
|
+
'HypervisorType' => 4,
|
56
|
+
'Name' => 'testfog1',
|
57
|
+
'OSTemplateId' => 415,
|
58
|
+
'RAMQuantity' => 1,
|
59
|
+
'ServerId' => 16763,
|
60
|
+
'ServerStatus' => 3,
|
61
|
+
'UserId' => 1856
|
62
|
+
}, {
|
63
|
+
'Busy' => false,
|
64
|
+
'CPUQuantity' => 1,
|
65
|
+
'CompanyId' => 1,
|
66
|
+
'DatacenterId' => 2,
|
67
|
+
'HDQuantity' => 2,
|
68
|
+
'HDTotalSize' => 50,
|
69
|
+
'HypervisorServerType' => 2,
|
70
|
+
'HypervisorType' => 2,
|
71
|
+
'Name' => 'testpro4504',
|
72
|
+
'OSTemplateId' => 60,
|
73
|
+
'RAMQuantity' => 1,
|
74
|
+
'ServerId' => 16779,
|
75
|
+
'ServerStatus' => 3,
|
76
|
+
'UserId' => 1856
|
77
|
+
}
|
78
|
+
]
|
79
|
+
}
|
80
|
+
response.body
|
81
|
+
end # get_servers
|
82
|
+
end # Mock
|
83
|
+
|
84
|
+
end # ArubaCloud
|
85
|
+
end # Compute
|
86
|
+
end # Fog
|
@@ -0,0 +1,51 @@
|
|
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
|
+
|
11
|
+
module Fog
|
12
|
+
module Compute
|
13
|
+
class ArubaCloud
|
14
|
+
|
15
|
+
class Real
|
16
|
+
def power_off_vm(id)
|
17
|
+
body = self.body('SetEnqueueServerStop').merge({:ServerId => "#{id}"})
|
18
|
+
options = {
|
19
|
+
:http_method => :post,
|
20
|
+
:method => 'SetEnqueueServerStop',
|
21
|
+
:body => Fog::JSON.encode(body)
|
22
|
+
}
|
23
|
+
response = nil
|
24
|
+
time = Benchmark.realtime {
|
25
|
+
response = request(options)
|
26
|
+
}
|
27
|
+
Fog::Logger.debug("SetEnqueueServerStop time: #{time}")
|
28
|
+
if response['Success']
|
29
|
+
response
|
30
|
+
else
|
31
|
+
raise Fog::ArubaCloud::Errors::RequestError.new("Error Powering off the VM. Error: #{response}")
|
32
|
+
end
|
33
|
+
end # power_off_vm
|
34
|
+
end # Real
|
35
|
+
|
36
|
+
class Mock
|
37
|
+
def power_off_vm(id)
|
38
|
+
response = Excon::Response.new
|
39
|
+
response.status = 200
|
40
|
+
response.body = {
|
41
|
+
'ExceptionInfo' => nil,
|
42
|
+
'ResultCode' => 0,
|
43
|
+
'ResultMessage' => nil,
|
44
|
+
'Success' => true
|
45
|
+
}
|
46
|
+
response.body
|
47
|
+
end
|
48
|
+
end # Mock
|
49
|
+
end # ArubaCloud
|
50
|
+
end # Compute
|
51
|
+
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
|
+
|
10
|
+
module Fog
|
11
|
+
module Compute
|
12
|
+
class ArubaCloud
|
13
|
+
class Real
|
14
|
+
def power_on_vm(id)
|
15
|
+
body = self.body('SetEnqueueServerStart').merge({:ServerId => "#{id}"})
|
16
|
+
options = {
|
17
|
+
:http_method => :post,
|
18
|
+
:method => 'SetEnqueueServerStart',
|
19
|
+
:body => Fog::JSON.encode(body)
|
20
|
+
}
|
21
|
+
response = nil
|
22
|
+
time = Benchmark.realtime {
|
23
|
+
response = request(options)
|
24
|
+
}
|
25
|
+
Fog::Logger.debug("SetEnqueueServerStart time: #{time}")
|
26
|
+
if response['Success']
|
27
|
+
response
|
28
|
+
else
|
29
|
+
raise Fog::ArubaCloud::Error::RequestError
|
30
|
+
end
|
31
|
+
end # power_on_vm
|
32
|
+
end # Real
|
33
|
+
|
34
|
+
class Mock
|
35
|
+
def power_on_vm(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 # power_on_vm
|
46
|
+
end # Mock
|
47
|
+
end # ArubaCloud
|
48
|
+
end # Compute
|
49
|
+
end # Fog
|
@@ -0,0 +1,62 @@
|
|
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
|
+
def purchase_ip
|
15
|
+
body = self.body('SetPurchaseIpAddress')
|
16
|
+
options = {
|
17
|
+
:http_method => :post,
|
18
|
+
:method => 'SetPurchaseIpAddress',
|
19
|
+
:body => Fog::JSON.encode(body)
|
20
|
+
}
|
21
|
+
response = nil
|
22
|
+
time = Benchmark.realtime {
|
23
|
+
response = request(options)
|
24
|
+
}
|
25
|
+
Fog::Logger.debug("SetPurchaseIpAddress time: #{time}")
|
26
|
+
if response['Success']
|
27
|
+
response
|
28
|
+
else
|
29
|
+
raise Fog::ArubaCloud::Errors::RequestError.new("Error purchasing new ip. Error: \n#{response}")
|
30
|
+
end
|
31
|
+
end # purchase_ip
|
32
|
+
end # Real
|
33
|
+
|
34
|
+
class Mock
|
35
|
+
def purchase_ip
|
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
|
+
'Value' => {
|
44
|
+
'CompanyId' => 1,
|
45
|
+
'ProductId' => 20,
|
46
|
+
'ResourceId' => 96034,
|
47
|
+
'ResourceType' => 6,
|
48
|
+
'UserId' => 1856,
|
49
|
+
'Gateway' => '5.249.158.1',
|
50
|
+
'LoadBalancerID' => nil,
|
51
|
+
'ServerId' => nil,
|
52
|
+
'SubNetMask' => '255.255.255.0',
|
53
|
+
'Value' => '5.249.158.23'
|
54
|
+
}
|
55
|
+
}
|
56
|
+
response.body
|
57
|
+
end # purchase_ip
|
58
|
+
end # Mock
|
59
|
+
|
60
|
+
end # ArubaCloud
|
61
|
+
end # Compute
|
62
|
+
end # Fog
|
@@ -0,0 +1,56 @@
|
|
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
|
+
# Reinitialize a Smart VM
|
16
|
+
# @param id [String] the id of the virtual machine to reinitialize
|
17
|
+
# @return response [Excon::Response]
|
18
|
+
def reinitialize_vm(id)
|
19
|
+
body = self.body('SetEnqueueReinitializeServer').merge({
|
20
|
+
:ServerId => id
|
21
|
+
})
|
22
|
+
options = {
|
23
|
+
:http_method => :post,
|
24
|
+
:method => 'GetServers',
|
25
|
+
:body => Fog::JSON.encode(body)
|
26
|
+
}
|
27
|
+
response = nil
|
28
|
+
time = Benchmark.realtime {
|
29
|
+
response = request(options)
|
30
|
+
}
|
31
|
+
Fog::Logger.debug("SetEnqueueReinitializeServer time: #{time}")
|
32
|
+
if response['Success']
|
33
|
+
response
|
34
|
+
else
|
35
|
+
raise Fog::ArubaCloud::Errors::RequestError
|
36
|
+
end
|
37
|
+
end # reinitialize_vm
|
38
|
+
end # Real
|
39
|
+
|
40
|
+
class Mock
|
41
|
+
def reinitialize_vm(id)
|
42
|
+
response = Excon::Response.new
|
43
|
+
response.status = 200
|
44
|
+
response.body = {
|
45
|
+
'ExceptionInfo' => nil,
|
46
|
+
'ResultCode' => 0,
|
47
|
+
'ResultMessage' => nil,
|
48
|
+
'Success' => true
|
49
|
+
}
|
50
|
+
response.body
|
51
|
+
end # reinitialize_vm
|
52
|
+
end # Mock
|
53
|
+
|
54
|
+
end # ArubaCloud
|
55
|
+
end # Compute
|
56
|
+
end # Fog
|
@@ -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 'fog/arubacloud/service'
|
9
|
+
|
10
|
+
module Fog
|
11
|
+
module Compute
|
12
|
+
class ArubaCloud
|
13
|
+
class Real
|
14
|
+
def remove_ip(id)
|
15
|
+
body = self.body('SetRemoveIpAddress').merge(
|
16
|
+
{:IpAddressResourceId => id}
|
17
|
+
)
|
18
|
+
options = {
|
19
|
+
:http_method => :post,
|
20
|
+
:method => 'SetRemoveIpAddress',
|
21
|
+
:body => Fog::JSON.encode(body)
|
22
|
+
}
|
23
|
+
response = nil
|
24
|
+
time = Benchmark.realtime {
|
25
|
+
response = request(options)
|
26
|
+
}
|
27
|
+
Fog::Logger.debug("SetRemoveIpAddress time: #{time}")
|
28
|
+
if response['Success']
|
29
|
+
response
|
30
|
+
else
|
31
|
+
raise Fog::ArubaCloud::Error::RequestError
|
32
|
+
end
|
33
|
+
end # remove_ip
|
34
|
+
end # Real
|
35
|
+
|
36
|
+
class Mock
|
37
|
+
def remove_ip(id)
|
38
|
+
self.ips.select!{|i| !i.id.eql?(id)}
|
39
|
+
response = Excon::Response.new
|
40
|
+
response.status = 200
|
41
|
+
response.body = {
|
42
|
+
'ExceptionInfo' => nil,
|
43
|
+
'ResultCode' => 0,
|
44
|
+
'ResultMessage' => nil,
|
45
|
+
'Success' => true
|
46
|
+
}
|
47
|
+
response.body
|
48
|
+
end # remove_ip
|
49
|
+
end # Mock
|
50
|
+
|
51
|
+
end # ArubaCloud
|
52
|
+
end # Compute
|
53
|
+
end # Fog
|
@@ -0,0 +1,54 @@
|
|
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
|
+
class Service
|
11
|
+
def datacenter
|
12
|
+
raise Fog::Errors::NotImplemented.new('Please implement the #datacenter method')
|
13
|
+
end
|
14
|
+
|
15
|
+
def ws_enduser_url(url=nil)
|
16
|
+
@ws_enduser_url = url || Fog::ArubaCloud::DEFAULT_WS_ENDUSER_URL
|
17
|
+
end
|
18
|
+
|
19
|
+
def request(options)
|
20
|
+
http_method = options[:http_method] || :get
|
21
|
+
@request_url = "#{@ws_enduser_url}/#{options[:method]}"
|
22
|
+
|
23
|
+
params = {headers: headers}
|
24
|
+
params[:expects] = options[:expected] || [200, 201]
|
25
|
+
unless options[:body].nil?
|
26
|
+
params[:body] = options[:body]
|
27
|
+
end
|
28
|
+
params[:read_timeout] = 360
|
29
|
+
|
30
|
+
# initialize connection object
|
31
|
+
@connection = Fog::Core::Connection.new(@request_url, false, params)
|
32
|
+
|
33
|
+
# send request
|
34
|
+
begin
|
35
|
+
response = @connection.request(:method => http_method)
|
36
|
+
rescue Excon::Errors::Timeout
|
37
|
+
# raise an error
|
38
|
+
raise Fog::ArubaCloud::Errors::RequestTimeOut.new("Request timed out after: #{60 unless params[:read_timeout]}")
|
39
|
+
end
|
40
|
+
|
41
|
+
# decode the response and return it
|
42
|
+
Fog::JSON.decode(response.body)
|
43
|
+
end
|
44
|
+
|
45
|
+
def headers(options={})
|
46
|
+
{'Content-Type' => 'application/json'}.merge(options[:headers] || {})
|
47
|
+
end
|
48
|
+
|
49
|
+
def login
|
50
|
+
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|