Class: Fog::Compute::XenServer::Servers

Inherits:
Fog::Collection
  • Object
show all
Defined in:
lib/fog/xenserver/models/compute/servers.rb

Instance Method Summary collapse

Instance Method Details

#all(options = {}) ⇒ Object



34
35
36
37
38
39
40
41
42
# File 'lib/fog/xenserver/models/compute/servers.rb', line 34

def all(options = {})
  data = service.get_records 'VM'
  # Exclude templates
  data.delete_if { |vm| vm[:is_control_domain] or vm[:is_a_template] }
  data.delete_if { |vm| vm[:is_a_snapshot] and !options[:include_snapshots] }
  data.delete_if { |vm| options[:name_matches] and (vm[:name_label] !~ /#{Regexp.escape(options[:name_matches])}/i ) }
  data.delete_if { |vm| options[:name_equals] and (vm[:name_label] != options[:name_equals] ) }
  load(data)
end

#builtin_templatesObject



26
27
28
29
30
31
32
# File 'lib/fog/xenserver/models/compute/servers.rb', line 26

def builtin_templates
  data = service.get_records 'VM'
  data.delete_if do |vm|
    !vm[:is_a_template] or vm[:other_config]['default_template'].nil?
  end
  load(data)
end

#custom_templatesObject



18
19
20
21
22
23
24
# File 'lib/fog/xenserver/models/compute/servers.rb', line 18

def custom_templates
  data = service.get_records 'VM'
  data.delete_if do |vm|
    !vm[:is_a_template] or !vm[:other_config]['default_template'].nil?
  end
  load(data)
end

#get(vm_ref) ⇒ Object



54
55
56
57
58
59
60
# File 'lib/fog/xenserver/models/compute/servers.rb', line 54

def get( vm_ref )
  if vm_ref && vm = service.get_record( vm_ref, 'VM' )
    new(vm)
  end
rescue Fog::XenServer::NotFound
  nil
end

#get_by_name(name) ⇒ Object



44
45
46
47
# File 'lib/fog/xenserver/models/compute/servers.rb', line 44

def get_by_name( name )
  ref = service.get_vm_by_name( name )
  get ref
end

#get_by_uuid(uuid) ⇒ Object



49
50
51
52
# File 'lib/fog/xenserver/models/compute/servers.rb', line 49

def get_by_uuid( uuid )
  ref = service.get_vm_by_uuid( uuid )
  get ref
end

#templatesObject



10
11
12
13
14
15
16
# File 'lib/fog/xenserver/models/compute/servers.rb', line 10

def templates
  data = service.get_records 'VM'
  data.delete_if do |vm|
    !vm[:is_a_template]
  end
  load(data)
end