Class: Fog::Hyperv::VMCollection

Inherits:
ComputerCollection show all
Defined in:
lib/fog/collection.rb

Instance Attribute Summary collapse

Attributes inherited from ComputerCollection

#computer

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from ComputerCollection

requires_computer

Methods inherited from Collection

#all, #get, get_method, #new, requires?

Instance Attribute Details

#vmObject

Returns the value of attribute vm.



78
79
80
# File 'lib/fog/collection.rb', line 78

def vm
  @vm
end

Class Method Details

.match_on(attr = nil) ⇒ Object



70
71
72
# File 'lib/fog/collection.rb', line 70

def self.match_on(attr = nil)
  @match_on ||= attr
end

.requires_vmObject



74
75
76
# File 'lib/fog/collection.rb', line 74

def self.requires_vm
  requires? << :vm
end

Instance Method Details

#create(attributes = {}) ⇒ Object



89
90
91
92
93
94
95
96
# File 'lib/fog/collection.rb', line 89

def create(attributes = {})
  object = new(attributes)
  # Ensure both ID and Name are populated, regardless of `match_on`
  object.vm_id ||= vm.id if vm && object.respond_to?(:vm_id)
  object.vm_name ||= vm.name if vm && object.respond_to?(:vm_name)
  object.save
  object
end

#inspectObject



98
99
100
101
# File 'lib/fog/collection.rb', line 98

def inspect
  # To avoid recursing on VM
  to_s
end

#search_attributesObject



80
81
82
83
84
85
86
87
# File 'lib/fog/collection.rb', line 80

def search_attributes
  attrs = super
  if vm
    attrs[:computer_name] ||= vm.computer_name
    attrs[match] = vm.send(match)
  end
  attrs
end