Class: CloudstackSpec::Resource::Snapshot

Inherits:
Base
  • Object
show all
Defined in:
lib/cloudstack_spec/resource/snapshot.rb

Instance Attribute Summary

Attributes inherited from Base

#name

Instance Method Summary collapse

Methods inherited from Base

#get_zone, #inspect, #job_status?, #to_ary, #to_s

Constructor Details

#initialize(name = 'root_disk') ⇒ Snapshot

Returns a new instance of Snapshot.



4
5
6
7
8
# File 'lib/cloudstack_spec/resource/snapshot.rb', line 4

def initialize(name='root_disk')
  @volume_name = name
  @connection = CloudstackSpec::Helper::Api.new.connection
  @version = CloudstackSpec::Helper::Api.new.version
end

Instance Method Details

#created?Boolean

Returns:

  • (Boolean)


21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/cloudstack_spec/resource/snapshot.rb', line 21

def created?
  # start the VM creation job
  # Return {true/false}
  #if self.exist?
  #  creation_job = "Already exist" 
  #  puts "    #{creation_job}"
  #  return false
  #end
  begin
    newsnap = @connection.create_snapshot(volumeid: get_volume_id)
    creation_job = newsnap['jobid']
  rescue Exception => e
    creation_job = "vm creation fail with #{e.message}"
  end
  if UUID.validate(creation_job) == true
    puts "  jobid: #{creation_job}"
    return job_status?(creation_job)
  else
    puts "  #{creation_job}"
    return false
  end
end

#exist?Boolean

Returns:

  • (Boolean)


10
11
12
13
14
15
16
17
18
19
# File 'lib/cloudstack_spec/resource/snapshot.rb', line 10

def exist?
  snapshots = @connection.list_snapshots(volumeid: get_volume_id)
  if ! snapshots.empty?
    if snapshots['count'] >= 1
      return true
    end
  else
    return false
  end
end