Module: Fog::VcloudDirector::Parsers::Compute::VmParserHelper
Instance Method Summary collapse
- #human_status(status) ⇒ Object
- #id_from_url(url, id_prefix: 'vapp-') ⇒ Object
- #initialize_vm ⇒ Object
- #parse_end_element(name, vm) ⇒ Object
- #parse_start_element(name, attributes, vm) ⇒ Object
- #parse_vm_attributes(attributes, vm) ⇒ Object
Instance Method Details
#human_status(status) ⇒ Object
90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 |
# File 'lib/fog/vcloud_director/parsers/compute/vm_parser_helper.rb', line 90 def human_status(status) case status when '-1', -1 'failed_creation' when '0', 0 'creating' when '8', 8 'off' when '4', 4 'on' when '3', 3 'suspended' else 'unknown' end end |
#id_from_url(url, id_prefix: 'vapp-') ⇒ Object
107 108 109 |
# File 'lib/fog/vcloud_director/parsers/compute/vm_parser_helper.rb', line 107 def id_from_url(url, id_prefix: 'vapp-') url.split('/').detect { |part| part.start_with?(id_prefix) } end |
#initialize_vm ⇒ Object
6 7 8 9 10 11 12 13 14 |
# File 'lib/fog/vcloud_director/parsers/compute/vm_parser_helper.rb', line 6 def initialize_vm { :vapp_id => nil, :ip_address => '', :description => '', :cpu_hot_add => nil, :memory_hot_add => nil } end |
#parse_end_element(name, vm) ⇒ Object
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 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/fog/vcloud_director/parsers/compute/vm_parser_helper.rb', line 16 def parse_end_element(name, vm) case name when 'IpAddress' vm[:ip_address] = value when 'Description' if @in_operating_system vm[:operating_system] = value @in_operating_system = false end when 'ResourceType' @resource_type = value when 'VirtualQuantity' case @resource_type when '3' vm[:cpu] = value when '4' vm[:memory] = value end when 'ElementName' @element_name = value when 'Item' if @resource_type == '17' # disk vm[:disks] ||= [] vm[:disks] << { @element_name => @current_host_resource[:capacity].to_i } end when 'Connection' vm[:network_adapters] ||= [] vm[:network_adapters] << { :ip_address => @current_network_connection[:ipAddress], :primary => (@current_network_connection[:primaryNetworkConnection] == 'true'), :ip_allocation_mode => @current_network_connection[:ipAddressingMode], :network => value } when 'Link' vm[:links] = @links when 'CoresPerSocket' vm[:cores_per_socket] = value when 'CpuHotAddEnabled' vm[:cpu_hot_add] = value == 'true' when 'MemoryHotAddEnabled' vm[:memory_hot_add] = value == 'true' end end |
#parse_start_element(name, attributes, vm) ⇒ Object
60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 |
# File 'lib/fog/vcloud_director/parsers/compute/vm_parser_helper.rb', line 60 def parse_start_element(name, attributes, vm) case name when 'OperatingSystemSection' @in_operating_system = true # VirtualHardwareSection was parsed if we're here. Set missing values to defaults since # repeatable parsing won't get them. vm[:cores_per_socket] ||= 1 vm[:disks] ||= [] vm[:network_adapters] ||= [] when 'HostResource' @current_host_resource = extract_attributes(attributes) when 'Connection' @current_network_connection = extract_attributes(attributes) when 'Link' # Parse vapp id from any link if not found elsewhere. vm[:vapp_id] ||= id_from_url(attr_value('href', attributes), :id_prefix => 'vapp-') @links << extract_attributes(attributes) end end |
#parse_vm_attributes(attributes, vm) ⇒ Object
82 83 84 85 86 87 88 |
# File 'lib/fog/vcloud_director/parsers/compute/vm_parser_helper.rb', line 82 def parse_vm_attributes(attributes, vm) vm_attrs = extract_attributes(attributes) vm.merge!(vm_attrs.select { |key, _| %i(href name status type deployed).include?(key) }) vm[:id] = vm[:href].split('/').last vm[:status] = human_status(vm[:status]) vm[:deployed] = vm[:deployed] == 'true' end |