fog-arubacloud 0.0.5 → 0.0.6

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: ffa635004717fc04fec344b20fd32351155d890a61d81feb1a024de92ac818d0
4
- data.tar.gz: 222d0047f68b9082a59e5d20a64226d2ce08726bc6ac82f036f0f205c2dd3b61
3
+ metadata.gz: 8ee7bdccbe197e3f4bc5591b739b61cfca8088504c04f999e6727a148711eda5
4
+ data.tar.gz: 7fff5cf532f0f70c877216440cfbe6ed79446fe65c239c702a1be547a10f3855
5
5
  SHA512:
6
- metadata.gz: 5bd96f4d0cf62987126ab6e59ad71df609b54dd344f9a1f67ddf857a138f62859f9301512a52b1fb86170e54f38e2dc663fb79ed217fbd4da91b77a136c29688
7
- data.tar.gz: c14069bb59ab739dbe82f36ff9e76cded50b592e3ecb0b7a4cc6985caf19f2b883649baefbbf914971ff9b8c0e593f839ddfb07d4b9442c7a780c844a57e17b8
6
+ metadata.gz: b54ebb4691fdfffae7f42a7a37b14b25aebbe291516931d4c9316f0001a346e3be0883b56c1fb9a6ac13e6afdbc25abd02cbc37cfdb41b33406cefecb9e540a8
7
+ data.tar.gz: 1b4e6ef025dae4ea6d211e0b093dd8ed0d89c321afd57678548a07be2c3a5345fbe5c303806c15875bd195548af2bad720636d6a62f1ae2b4bc3f46e7f767bd6
data/README.md CHANGED
@@ -23,6 +23,12 @@ Or install it yourself as:
23
23
 
24
24
  $ gem install fog-arubacloud
25
25
 
26
+
27
+ ## Update
28
+
29
+
30
+ In package has been updated the 'snapshot' methods , and has added 'list_snapshot ' feature to see if a snapshot exist;
31
+
26
32
  ## Usage
27
33
 
28
34
  TODO: Write usage instructions here
@@ -1,3 +1,4 @@
1
+ # coding: utf-8
1
2
  #
2
3
  # Author:: Alessio Rocchi (<alessio.rocchi@staff.aruba.it>)
3
4
  # © Copyright ArubaCloud.
@@ -17,7 +18,16 @@ module Fog
17
18
  DEFAULT_API_VERSION = '2.9'
18
19
  DEFAULT_WS_ENDUSER_URL = "https://api.dc2.computing.cloud.it/WsEndUser/v#{DEFAULT_API_VERSION}/WsEndUser.svc/json"
19
20
 
21
+ # fix for deadlock during : "SetEnqueueServerCreation" :
22
+ # wait response ( not completation of create_server... process) from cloud before continue
23
+ #
24
+ @@mymutex = Mutex.new
25
+
26
+ def self.getUserMutex
27
+ @@mymutex
28
+ end
29
+
20
30
  service(:compute, 'Compute')
21
31
 
22
32
  end
23
- end
33
+ end
@@ -19,6 +19,13 @@ module Fog
19
19
  PRO_HV_LC = 3
20
20
  SMART = 4
21
21
 
22
+ SNAPOPTYPE = {
23
+ "Create" => "1",
24
+ "Delete" => "2",
25
+ "Restore" => "3",
26
+ "List" => "4"
27
+ }
28
+
22
29
  recognizes :url
23
30
  requires :arubacloud_username, :arubacloud_password
24
31
 
@@ -59,6 +66,7 @@ module Fog
59
66
  request :get_purchased_ip_addresses
60
67
  request :get_hypervisors
61
68
  request :reinitialize_vm
69
+ request :list_snapshot
62
70
  request :create_snapshot
63
71
  request :apply_snapshot
64
72
  request :delete_snapshot
@@ -125,7 +133,6 @@ module Fog
125
133
  :body => Fog::JSON.encode(body)
126
134
  }
127
135
  response = nil
128
-
129
136
  if benchmark
130
137
  time = Benchmark.realtime {
131
138
  response = _request(options)
@@ -20,6 +20,13 @@ module Fog
20
20
  ARCHIVED = 4
21
21
  DELETED = 5
22
22
 
23
+ STATE_DES = { Fog::ArubaCloud::Compute::Server::CREATING => "Creating",
24
+ Fog::ArubaCloud::Compute::Server::STOPPED => "Stopped",
25
+ Fog::ArubaCloud::Compute::Server::RUNNING => "Running",
26
+ Fog::ArubaCloud::Compute::Server::ARCHIVED => "Archived",
27
+ Fog::ArubaCloud::Compute::Server::DELETED => "Deleted"
28
+ }
29
+
23
30
  #collection_name :servers
24
31
 
25
32
  # This is the instance ID which is unique per Datacenter
@@ -196,22 +203,22 @@ module Fog
196
203
  def restore
197
204
  requires :id, :memory, :cpu
198
205
  state == ARCHIVED and memory != nil and cpu != nil ? service.restore_vm(id) : raise(
199
- Fog::ArubaCloud::Errors::VmStatus.new("Cannot restore VM without specifying #{cpu} and #{memory}"
200
- ))
206
+ Fog::ArubaCloud::Errors::VmStatus.new("Cannot restore VM without specifying #{cpu} and #{memory}"))
207
+ end
208
+
209
+ def list_snapshot
210
+ requires :id
211
+ id != nil ? service.list_snapshot(id) : raise(Fog::ArubaCloud::Errors::VmStatus.new('Cannot list snapshot without vm id'))
201
212
  end
202
213
 
203
214
  def create_snapshot
204
215
  requires :id
205
- id != nil ? service.create_snapshot(id) : raise(Fog::ArubaCloud::Errors::VmStatus.new(
206
- 'Cannot crate snapshot without vm id'
207
- ))
216
+ id != nil ? service.create_snapshot(id) : raise(Fog::ArubaCloud::Errors::VmStatus.new('Cannot create snapshot without vm id'))
208
217
  end
209
218
 
210
219
  def apply_snapshot
211
220
  requires :id
212
- self.action_hook(method=:apply_snapshot, expected_state=STOPPED,
213
- message="Cannot restore vm in current state: #{state}"
214
- )
221
+ self.action_hook(method=:apply_snapshot, expected_state=STOPPED, message="Cannot restore vm in current state: #{state}" )
215
222
  end
216
223
 
217
224
  def delete_snapshot
@@ -1,3 +1,4 @@
1
+ # coding: utf-8
1
2
  #
2
3
  # Author:: Dangleterre Michaël
3
4
  # © Copyright ArubaCloud.
@@ -14,10 +15,11 @@ module Fog
14
15
  CREATING = 'Create'
15
16
  APPLYING = 'Restore'
16
17
  DELETING = 'Delete'
18
+ LIST = 'List'
17
19
  identity :id, :aliases => 'id'
18
20
 
19
- attribute :ServerId, :aliases => 'serverid'
20
- attribute :SnapshotOperation, :aliases => 'Snapshot Operation'
21
+ attribute :serverId, :aliases => 'serverId'
22
+ attribute :snapshotOperation, :aliases => 'snapshotOperation'
21
23
 
22
24
  def initialize(attributes = {})
23
25
  @service = attributes[:service]
@@ -25,8 +27,19 @@ module Fog
25
27
  'operation impossible'
26
28
  end
27
29
  end
30
+
31
+ def list
32
+ requires :serverId
33
+ data = :attributes
34
+ if :name != nil
35
+ data[:name] = name
36
+ else
37
+ raise Fog::ArubaCloud::Errors::BadParameters.Exception('Missing Parameter')
38
+ end
39
+ end # List
40
+
28
41
  def create
29
- requires :ServerId
42
+ requires :serverId
30
43
  data = :attributes
31
44
  if :name != nil
32
45
  data[:name] = name
@@ -34,8 +47,9 @@ module Fog
34
47
  raise Fog::ArubaCloud::Errors::BadParameters.Exception('Missing Parameter')
35
48
  end
36
49
  end # Create
50
+
37
51
  def apply
38
- requires :ServerId
52
+ requires :serverId
39
53
  data = :attributes
40
54
  if :name != nil
41
55
  data[:name] = name
@@ -43,8 +57,9 @@ module Fog
43
57
  raise Fog::ArubaCloud::Errors::BadParameters.Exception('Missing Parameter')
44
58
  end
45
59
  end # Apply
60
+
46
61
  def delete
47
- requires :ServerId
62
+ requires :serverId
48
63
  data = :attributes
49
64
  if :name != nil
50
65
  data[:name] = name
@@ -55,4 +70,4 @@ module Fog
55
70
  end
56
71
  end
57
72
  end
58
- end
73
+ end
@@ -1,3 +1,4 @@
1
+ # coding: utf-8
1
2
  #
2
3
  # Author:: Dangleterre Michaël
3
4
  # © Copyright ArubaCloud.
@@ -13,7 +14,17 @@ module Fog
13
14
  class Compute
14
15
  class Snapshots < Fog::Collection
15
16
  model Fog::ArubaCloud::Compute::Snapshot
17
+ # Returns list of Ip Addresses
18
+ # @return [Fog::ArubaCloud::Compute::Ips]
19
+ # @raise [Fog::ArubaCloud::Errors::NotFound]
20
+ def all
21
+ # TODO: Implement single item retrieve
22
+ end
23
+ # Returns a single snapshot object
24
+ def get
25
+ # TODO: Implement single item retrieve
26
+ end
16
27
  end
17
28
  end
18
29
  end
19
- end
30
+ end
@@ -15,22 +15,25 @@ module Fog
15
15
  module ArubaCloud
16
16
  class Compute
17
17
  class Real
18
- # Apply a snapshot on a VM
19
- def apply_snapshot(data)
20
- (service.servers).all.each do |server|
21
- id = server.id if (server.name).include? data[:name]
22
- end
23
- body = {
24
- :Snapshot => {
25
- :ServerId => id,
26
- :SnapshotOperationTypes => 'Restore'
27
- }
28
- }
29
- self.request(
30
- body=body,
31
- method_name='SetEnqueueServerSnapshot',
32
- failure_message='Error while applying snapshot.'
18
+ # Apply (restore) a snapshot on a VM
19
+ def apply_snapshot(id)
20
+ body = self.body('SetEnqueueServerSnapshot').merge(
21
+ {
22
+ :ServerId => id , :SnapshotOperation => Fog::ArubaCloud::Compute::SNAPOPTYPE["Restore"]
23
+ }
33
24
  )
25
+ response = nil
26
+ time = Benchmark.realtime {
27
+ response = request(body , 'SetEnqueueServerSnapshot', 'Error while attempting to restore a snapshot.')
28
+ }
29
+ Fog::Logger.debug("SetEnqueueServerSnapshot time: #{time}")
30
+ if response['Success']
31
+ response_ext = response.merge( { "Req" => "restore" , "Id" => id })
32
+ response_ext
33
+ else
34
+ raise Fog::ArubaCloud::Errors::RequestError.new(response)
35
+ end
36
+
34
37
  end #Apply
35
38
  end #Real
36
39
 
@@ -17,21 +17,24 @@ module Fog
17
17
 
18
18
  class Real
19
19
  # Create a new snapshot of a VM
20
- def create_snapshot(data)
21
- (service.servers).all.each do |server|
22
- id = server.id if (server.name).include? data[:name]
23
- end
24
- body = {
25
- :Snapshot => {
26
- :ServerId => id,
27
- :SnapshotOperationTypes => 'Create'
28
- }
29
- }
30
- self.request(
31
- body=body,
32
- method_name='SetEnqueueServerSnapshot',
33
- failure_message='Error while attempting to create a snapshot.'
20
+ def create_snapshot(id)
21
+ body = self.body('SetEnqueueServerSnapshot').merge(
22
+ {
23
+ :ServerId => id , :SnapshotOperation => Fog::ArubaCloud::Compute::SNAPOPTYPE["Create"]
24
+ }
34
25
  )
26
+ response = nil
27
+ time = Benchmark.realtime {
28
+ response = request(body , 'SetEnqueueServerSnapshot', 'Error while attempting to create a snapshot.')
29
+ }
30
+ Fog::Logger.debug("SetEnqueueServerSnapshot time: #{time}")
31
+ if response['Success']
32
+ response_ext = response.merge( { "Req" => "create" , "Id" => id })
33
+ response_ext
34
+ else
35
+ raise Fog::ArubaCloud::Errors::RequestError.new(response)
36
+ end
37
+
35
38
  end #Create_snapshot
36
39
  end #Real
37
40
 
@@ -52,8 +52,12 @@ module Fog
52
52
 
53
53
  response = nil
54
54
  time = Benchmark.realtime {
55
- response = request(body, 'SetEnqueueServerCreation', 'SetEnqueueServerCreation Error')
55
+ mymux = Fog::ArubaCloud.getUserMutex
56
+ mymux.synchronize {
57
+ response = request( body, 'SetEnqueueServerCreation', 'Pro_vm creation error')
58
+ }
56
59
  }
60
+
57
61
  Fog::Logger.debug("SetEnqueueServerCreation time: #{time}")
58
62
  if response['Success']
59
63
  response
@@ -40,8 +40,12 @@ module Fog
40
40
 
41
41
  response = nil
42
42
  time = Benchmark.realtime {
43
- response = request( body, 'SetEnqueueServerCreation', "Smart_vm creation error" )
43
+ mymux = Fog::ArubaCloud.getUserMutex
44
+ mymux.synchronize {
45
+ response = request( body, 'SetEnqueueServerCreation', "Smart_vm creation error" )
46
+ }
44
47
  }
48
+
45
49
  Fog::Logger.debug("SetEnqueueServerCreation time: #{time}")
46
50
  if response['Success']
47
51
  response
@@ -15,30 +15,25 @@ module Fog
15
15
  module ArubaCloud
16
16
  class Compute
17
17
  class Real
18
- # Apply a snapshot on a VM
19
- def delete_snapshot(data)
20
- (service.servers).all.each do |server|
21
- id = server.id if (server.name).include? data[:name]
22
- end
18
+ # Delete a snapshot on a VM
19
+ def delete_snapshot(id)
23
20
  body = self.body('SetEnqueueServerSnapshot').merge(
24
- {
25
- :Snapshot => {
26
- :ServerId => id,
27
- :SnapshotOperationTypes => 'Delete'
28
- }
29
- }
21
+ {
22
+ :ServerId => id , :SnapshotOperation => Fog::ArubaCloud::Compute::SNAPOPTYPE["Delete"]
23
+ }
30
24
  )
31
25
  response = nil
32
26
  time = Benchmark.realtime {
33
- response = request(body , 'SetEnqueueServerSnapshot', 'SetEnqueueServerSnapshot Error')
27
+ response = request(body , 'SetEnqueueServerSnapshot', 'Error while attempting to delete a snapshot.')
34
28
  }
35
29
  Fog::Logger.debug("SetEnqueueServerSnapshot time: #{time}")
36
30
  if response['Success']
37
- response
31
+ response_ext = response.merge( { "Req" => "Delete" , "Id" => id })
32
+ response_ext
38
33
  else
39
34
  raise Fog::ArubaCloud::Errors::RequestError.new(response)
40
35
  end
41
- end #Apply
36
+ end #Delete
42
37
  end #Real
43
38
 
44
39
  class Mock
@@ -0,0 +1,90 @@
1
+ # coding: utf-8
2
+ #
3
+ # Author:: Ugo Vierucci (<ugo.vierucci@staff.aruba.it>)
4
+ # © Copyright ArubaCloud.
5
+ #
6
+ # LICENSE: MIT (http://opensource.org/licenses/MIT)
7
+ #
8
+
9
+ require 'fog/arubacloud/service'
10
+ require 'fog/arubacloud/error'
11
+ require 'benchmark'
12
+
13
+
14
+ module Fog
15
+ module ArubaCloud
16
+ class Compute
17
+
18
+ class Real
19
+ # List snapshot info of a VM if exist a snapshot
20
+ def list_snapshot(id)
21
+ body = self.body('GetServersList').merge(
22
+ {
23
+ :operationRequest => { :ServerStatuses => {} }
24
+ }
25
+ )
26
+ body = self.body('GetServersList')
27
+ response = nil
28
+ dataresp = nil
29
+ time = Benchmark.realtime {
30
+ dataresp = request( body, 'GetServersList', "GetServersList Error" )
31
+ }
32
+
33
+ if dataresp
34
+ xs = dataresp["Value"]
35
+ if xs
36
+ xs.each do | x |
37
+ if x["ServerId"] == id
38
+ if x["Snapshots"] != [] && x["Snapshots"].length > 0
39
+ winfo = x['Snapshots'][0]
40
+ wcre = winfo['CreationDate']
41
+ wexp = winfo['ExpirationDate']
42
+ wdatecre = "unknow"
43
+ wdateexp = "unknow"
44
+ if wcre
45
+ w = wcre.match(/\/Date\((\d+\+\d+)\)\//)
46
+ if w && w.length > 1
47
+ wdatecre = DateTime.strptime(w[1], "%Q%z").strftime("%Y-%m-%d %H:%M:%S")
48
+ end
49
+ end
50
+ if wexp
51
+ w = wexp.match(/\/Date\((\d+\+\d+)\)\//)
52
+ if w && w.length > 1
53
+ wdateexp = DateTime.strptime(w[1], "%Q%z").strftime("%Y-%m-%d %H:%M:%S")
54
+ end
55
+ end
56
+ response = { "Success" => true , "credate" => wdatecre , "expdate" => wdateexp , "Req" => "list" , "Id" => id}
57
+ break
58
+ end
59
+ end
60
+ end
61
+ end
62
+ end
63
+
64
+ Fog::Logger.debug("GetServersList time: #{time}")
65
+ if response && response['Success']
66
+ response
67
+ else
68
+ return { "Success" => false , "Req" => "list", "Id" => id }
69
+ end
70
+
71
+ end #list_snapshot
72
+ end #Real
73
+
74
+ class Mock
75
+ def list_snapshot
76
+ response = Excon::Response.new
77
+ response.status = 200
78
+ response.body = {
79
+ 'ExceptionInfo' => nil,
80
+ 'ResultCode' => 0,
81
+ 'ResultMessage' => nil,
82
+ 'Success' => true
83
+ }
84
+ response.body
85
+ end # list snapshot
86
+ end # Mock
87
+
88
+ end # Compute
89
+ end # ArubaCloud
90
+ end #Fog
@@ -1,3 +1,4 @@
1
+ # coding: utf-8
1
2
  #
2
3
  # Author:: Alessio Rocchi (<alessio.rocchi@staff.aruba.it>)
3
4
  # © Copyright ArubaCloud.
@@ -29,10 +30,10 @@ module Fog
29
30
 
30
31
  # initialize connection object
31
32
  @connection = Fog::Core::Connection.new(@request_url, false, params)
32
-
33
33
  # send request
34
34
  begin
35
35
  response = @connection.request(:method => http_method)
36
+ @connection.reset
36
37
  rescue Excon::Errors::Timeout
37
38
  # raise an error
38
39
  raise Fog::ArubaCloud::Errors::RequestTimeOut.new(
@@ -53,4 +54,4 @@ module Fog
53
54
  end
54
55
  end
55
56
  end
56
- end
57
+ end
@@ -8,6 +8,6 @@
8
8
 
9
9
  module Fog
10
10
  module ArubaCloud
11
- VERSION = '0.0.5'
11
+ VERSION = '0.0.6'
12
12
  end
13
13
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fog-arubacloud
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.5
4
+ version: 0.0.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Aruba S.p.A.
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-01-22 00:00:00.000000000 Z
11
+ date: 2018-03-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: fog-core
@@ -203,6 +203,7 @@ files:
203
203
  - lib/fog/arubacloud/compute/requests/get_server_details.rb
204
204
  - lib/fog/arubacloud/compute/requests/get_servers.rb
205
205
  - lib/fog/arubacloud/compute/requests/get_shared_storage.rb
206
+ - lib/fog/arubacloud/compute/requests/list_snapshot.rb
206
207
  - lib/fog/arubacloud/compute/requests/manage_custom_template.rb
207
208
  - lib/fog/arubacloud/compute/requests/modify_loadbalancer.rb
208
209
  - lib/fog/arubacloud/compute/requests/power_off_vm.rb