Class: Ovirt::Template
- Inherits:
-
Base
- Object
- Base
- Ovirt::Template
show all
- Defined in:
- lib/ovirt/template.rb
Direct Known Subclasses
Vm
Constant Summary
collapse
- REQUIRED_CLONE_PARAMETERS =
[:name, :cluster]
- CLONE_ATTRIBUTES_WITH_SCALARS =
[:memory, :stateless, :type]
- CLONE_ATTRIBUTES_WITH_HASHES =
[:display, :usb, :cpu, :high_availability]
- ALLOWED_CLONE_TYPES =
[:full, :linked, :skeletal]
Instance Attribute Summary
Attributes inherited from Base
#attributes, #operations, #relationships, #service
Class Method Summary
collapse
Instance Method Summary
collapse
Methods inherited from Base
#[], all, all_xml_objects, #api_endpoint, api_endpoint, #class_suffix, create_from_xml, #destroy, element_name, element_names, find_by_href, find_by_id, find_by_name, has_first_node?, hash_from_id_and_href, href_from_creation_status_link, #initialize, #keys, #method_missing, object_to_id, #operation, parse_attribute, parse_boolean, parse_first_node, parse_first_node_with_hash, parse_first_text, parse_xml, #relationship, #reload, #replace, set_value, #update, #update!, xml_to_actions, xml_to_hash, xml_to_nokogiri, xml_to_relationships
Methods included from Logging
#logger
Constructor Details
This class inherits a constructor from Ovirt::Base
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
in the class Ovirt::Base
Class Method Details
.parse_node_extended(node, hash) ⇒ Object
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
|
# File 'lib/ovirt/template.rb', line 9
def self.parse_node_extended(node, hash)
parse_first_node(node, :status, hash, :node => [:state])
parse_first_node(node, :display, hash,
:node => [:type, :address],
:node_to_i => [:port, :monitors, :secure_port])
parse_first_node(node, :usb, hash,
:node_to_bool => [:enabled])
parse_first_node_with_hash(node, 'cpu/topology', hash.store_path(:cpu, :topology, {}),
:attribute_to_i => [:sockets, :cores])
parse_first_node(node, :high_availability, hash,
:node_to_bool => [:enabled],
:node_to_i => [:priority])
parse_first_node(node, :os, hash,
:attribute => [:type],
:node => [:kernel, :initrd, :cmdline])
boot_order = []
hash.store_path(:os, :boot_order, boot_order)
node.xpath('os/boot').each do |boot|
dev = boot['dev']
boot_order << {:dev => dev} unless dev.blank?
end
hash[:custom_attributes] = []
node.xpath('custom_properties/custom_property').each do |ca|
hash[:custom_attributes] << {:name => ca[:name], :value => ca[:value]}
end
end
|
Instance Method Details
#boot_order ⇒ Object
49
50
51
|
# File 'lib/ovirt/template.rb', line 49
def boot_order
attributes.fetch_path(:os, :boot_order) || []
end
|
#create_vm(options = {}) ⇒ Object
85
86
87
88
89
90
91
92
93
94
95
|
# File 'lib/ovirt/template.rb', line 85
def create_vm(options = {})
options = options.dup
determine_clone_type(options)
options[:storage] = Base.object_to_id(options[:storage]) if options[:storage]
case options[:clone_type]
when :full then clone_to_vm(options)
when :linked then clone_to_vm(options)
when :skeletal then clone_to_vm_via_blank_template(options)
end
end
|
#getCfg(_snap = nil) ⇒ Object
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
|
# File 'lib/ovirt/template.rb', line 53
def getCfg(_snap = nil)
raise MiqException::MiqVimError, "Failed to retrieve configuration information for VM" if attributes.nil?
cfg_hash = {}
cfg_hash['displayname'] = attributes[:name]
cfg_hash['guestos'] = attributes.fetch_path(:os, :type)
cfg_hash['memsize'] = attributes[:memory] / 1_048_576 cfg_hash['numvcpu'] = attributes.fetch_path(:cpu, :sockets)
attributes[:disks] = send(:disks, :disk) if self[:disks].nil?
disks.each_with_index do |disk, idx|
storage_domain = disk[:storage_domains].first
storage_id = storage_domain && storage_domain[:id]
disk_key = disk[:image_id].blank? ? :id : :image_id
file_path = storage_id && ::File.join('/dev', storage_id, disk[disk_key])
tag = "scsi0:#{idx}"
cfg_hash["#{tag}.present"] = "true"
cfg_hash["#{tag}.devicetype"] = "disk"
cfg_hash["#{tag}.filename"] = file_path.to_s
cfg_hash["#{tag}.format"] = disk[:format]
end
cfg_hash
end
|
#os_type ⇒ Object
45
46
47
|
# File 'lib/ovirt/template.rb', line 45
def os_type
attributes.fetch_path(:os, :type) || 'unassigned'
end
|