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

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

Instance Attribute Summary

Attributes inherited from Fog::Collection

#connection

Instance Method Summary collapse

Methods inherited from Fog::Collection

#clear, #create, #destroy, #initialize, #inspect, #load, model, #model, #new, #reload, #table, #to_json

Methods included from Attributes::ClassMethods

#_load, #aliases, #attribute, #attributes, #identity, #ignore_attributes, #ignored_attributes

Methods included from Attributes::InstanceMethods

#_dump, #attributes, #dup, #identity, #identity=, #merge_attributes, #new_record?, #requires, #requires_one

Constructor Details

This class inherits a constructor from Fog::Collection

Instance Method Details

#all(options = {}) ⇒ Object



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

def all(options = {})
  data = connection.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



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

def builtin_templates
  data = connection.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



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

def custom_templates
  data = connection.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



51
52
53
54
55
56
57
# File 'lib/fog/xenserver/models/compute/servers.rb', line 51

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

#get_by_name(name) ⇒ Object



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

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

#templatesObject



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

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