lib/vcloud-rest/vcloud/vm.rb
def get_vm(vmId)
      params = {
        'method' => :get,
        'command' => "/vApp/vm-#{vmId}"
      }

      response, headers = send_request(params)

      vm_name = response.css('Vm').attribute("name")
      vm_name = vm_name.text unless vm_name.nil?

      status = convert_vapp_status(response.css('Vm').attribute("status").text)

      os_desc = response.css('ovf|OperatingSystemSection ovf|Description').first.text

      networks = {}
      response.css('NetworkConnection').each do |network|
        ip = network.css('IpAddress').first
        ip = ip.text if ip

        external_ip = network.css('ExternalIpAddress').first
        external_ip = external_ip.text if external_ip

        # Append NetworkConnectionIndex to network name to generate a unique hash key,
        # otherwise different interfaces on the same network would use the same hash key
        key = "#{network['network']}_#{network.css('NetworkConnectionIndex').first.text}"

        networks[key] = {
          :index => network.css('NetworkConnectionIndex').first.text,
          :ip => ip,
          :external_ip => external_ip,
          :is_connected => network.css('IsConnected').first.text,
          :mac_address => network.css('MACAddress').first.text,
          :ip_allocation_mode => network.css('IpAddressAllocationMode').first.text
        }
      end

      admin_password = response.css('GuestCustomizationSection AdminPassword').first
      admin_password = admin_password.text if admin_password

      guest_customizations = {
        :enabled => response.css('GuestCustomizationSection Enabled').first.text,
        :admin_passwd_enabled => response.css('GuestCustomizationSection AdminPasswordEnabled').first.text,
        :admin_passwd_auto => response.css('GuestCustomizationSection AdminPasswordAuto').first.text,
        :admin_passwd => admin_password,
        :reset_passwd_required => response.css('GuestCustomizationSection ResetPasswordRequired').first.text,
        :computer_name => response.css('GuestCustomizationSection ComputerName').first.text
      }

      { :id => vmId,
        :vm_name => vm_name, :os_desc => os_desc, :networks => networks,
        :guest_customizations => guest_customizations, :status => status
      }
    end
def get_vm(vmId)
      params = {
        'method' => :get,
        'command' => "/vApp/vm-#{vmId}"
      }

      response, headers = send_request(params)

      vm_name = response.css('Vm').attribute("name")
      vm_name = vm_name.text unless vm_name.nil?

      status = convert_vapp_status(response.css('Vm').attribute("status").text)

      os_desc = response.css('ovf|OperatingSystemSection ovf|Description').first.text

      networks = {}
      response.css('NetworkConnection').each do |network|
        ip = network.css('IpAddress').first
        ip = ip.text if ip

        external_ip = network.css('ExternalIpAddress').first
        external_ip = external_ip.text if external_ip

        # Append NetworkConnectionIndex to network name to generate a unique hash key,
        # otherwise different interfaces on the same network would use the same hash key
        key = "#{network['network']}_#{network.css('NetworkConnectionIndex').first.text}"

        networks[key] = {
          :index => network.css('NetworkConnectionIndex').first.text,
          :ip => ip,
          :external_ip => external_ip,
          :is_connected => network.css('IsConnected').first.text,
          :mac_address => network.css('MACAddress').first.text,
          :ip_allocation_mode => network.css('IpAddressAllocationMode').first.text
        }
      end

      admin_password = response.css('GuestCustomizationSection AdminPassword').first
      admin_password = admin_password.text if admin_password

      guest_customizations = {
        :enabled => response.css('GuestCustomizationSection Enabled').first.text,
        :admin_passwd_enabled => response.css('GuestCustomizationSection AdminPasswordEnabled').first.text,
        :admin_passwd_auto => response.css('GuestCustomizationSection AdminPasswordAuto').first.text,
        :admin_passwd => admin_password,
        :reset_passwd_required => response.css('GuestCustomizationSection ResetPasswordRequired').first.text,
        :computer_name => response.css('GuestCustomizationSection ComputerName').first.text
      }

      { :id => vmId,
        :vm_name => vm_name, :os_desc => os_desc, :networks => networks,
        :guest_customizations => guest_customizations, :status => status
      }
    end
def get_vm ( vmId ) params = { 'method' => :get , 'command' => "/vApp/vm-#{vmId}" } response , headers = send_request ( params ) vm_name = response . css ( 'Vm' ) . attribute ( "name" ) vm_name = vm_name . text unless vm_name . nil? status = convert_vapp_status ( response . css ( 'Vm' ) . attribute ( "status" ) . text ) os_desc = response . css ( 'ovf|OperatingSystemSection ovf|Description' ) . first . text networks = { } response . css ( 'NetworkConnection' ) . each do | network | ip = network . css ( 'IpAddress' ) . first ip = ip . text if ip external_ip = network . css ( 'ExternalIpAddress' ) . first external_ip = external_ip . text if external_ip # Append NetworkConnectionIndex to network name to generate a unique hash key, # otherwise different interfaces on the same network would use the same hash key key = "#{network['network']}_#{network.css('NetworkConnectionIndex').first.text}" networks [ key ] = { :index => network . css ( 'NetworkConnectionIndex' ) . first . text , :ip => ip , :external_ip => external_ip , :is_connected => network . css ( 'IsConnected' ) . first . text , :mac_address => network . css ( 'MACAddress' ) . first . text , :ip_allocation_mode => network . css ( 'IpAddressAllocationMode' ) . first . text } end admin_password = response . css ( 'GuestCustomizationSection AdminPassword' ) . first admin_password = admin_password . text if admin_password guest_customizations = { :enabled => response . css ( 'GuestCustomizationSection Enabled' ) . first . text , :admin_passwd_enabled => response . css ( 'GuestCustomizationSection AdminPasswordEnabled' ) . first . text , :admin_passwd_auto => response . css ( 'GuestCustomizationSection AdminPasswordAuto' ) . first . text , :admin_passwd => admin_password , :reset_passwd_required => response . css ( 'GuestCustomizationSection ResetPasswordRequired' ) . first . text , :computer_name => response . css ( 'GuestCustomizationSection ComputerName' ) . first . text } { :id => vmId , :vm_name => vm_name , :os_desc => os_desc , :networks => networks , :guest_customizations => guest_customizations , :status => status } end
Fetch details about a given VM
Fetch details about a given VM