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

      response, headers = send_request(params)

      vapp_node = response.css('VApp').first
      if vapp_node
        name = vapp_node['name']
        status = convert_vapp_status(vapp_node['status'])
      end

      description = response.css("Description").first
      description = description.text unless description.nil?

      ip = response.css('IpAddress').first
      ip = ip.text unless ip.nil?

      networks = response.css('NetworkConfig').reject{|n| n.attribute('networkName').text == 'none'}.
        collect do |network|
          net_id = network.css('Link[rel="repair"]')
          net_id = net_id.attribute('href').text.gsub(/.*\/network\/(.*)\/action.*/, '\1') unless net_id.empty?

          net_name = network.attribute('networkName').text

          gateway = network.css('Gateway')
          gateway = gateway.text unless gateway.nil?

          netmask = network.css('Netmask')
          netmask = netmask.text unless netmask.nil?

          fence_mode = network.css('FenceMode')
          fence_mode = fence_mode.text unless fence_mode.nil?

          parent_network = network.css('ParentNetwork')
          parent_network = parent_network.attribute('name').text unless parent_network.empty?
          parent_network = nil if parent_network.empty?

          retain_network = network.css('RetainNetInfoAcrossDeployments')
          retain_network = retain_network.text unless retain_network.nil?

          # TODO: handle multiple scopes?
          ipscope =  {
              :gateway => gateway,
              :netmask => netmask,
              :fence_mode => fence_mode,
              :parent_network => parent_network,
              :retain_network => retain_network
            }

          {
            :id => net_id,
            :name => net_name,
            :scope => ipscope
          }
        end

      vapp_snapshot = nil
      response.css('SnapshotSection').each do |snapshot_section|
        if snapshot_section['href'] =~ /.*\/vApp\/vapp\-/
          snapshot = snapshot_section.css("Snapshot").first
          if snapshot
            vapp_snapshot = {
              :size => snapshot['size'],
              :creation_date => snapshot['created']
            }
          end
          break
        end
      end

      vms = response.css('Children Vm')
      vms_hash = {}

      vms.each do |vm|
        vapp_local_id = vm.css('VAppScopedLocalId')
        addresses = vm.css('rasd|Connection').collect do |n|
          address = n.attribute('vcloud:ipAddress')
          address = n.attribute('ipAddress') unless address
          address = address.text if address
        end

        vms_hash[vm['name']] = {
          :addresses => addresses,
          :status => convert_vapp_status(vm['status']),
          :id => vm['href'].gsub(/.*\/vApp\/vm\-/, ""),
          :vapp_scoped_local_id => vapp_local_id.text
        }
      end

      { :id => vAppId, :name => name, :description => description,
        :status => status, :ip => ip, :networks => networks,
        :vapp_snapshot => vapp_snapshot, :vms_hash => vms_hash }
    end
def get_vapp(vAppId)
      params = {
        'method' => :get,
        'command' => "/vApp/vapp-#{vAppId}"
      }

      response, headers = send_request(params)

      vapp_node = response.css('VApp').first
      if vapp_node
        name = vapp_node['name']
        status = convert_vapp_status(vapp_node['status'])
      end

      description = response.css("Description").first
      description = description.text unless description.nil?

      ip = response.css('IpAddress').first
      ip = ip.text unless ip.nil?

      networks = response.css('NetworkConfig').reject{|n| n.attribute('networkName').text == 'none'}.
        collect do |network|
          net_id = network.css('Link[rel="repair"]')
          net_id = net_id.attribute('href').text.gsub(/.*\/network\/(.*)\/action.*/, '\1') unless net_id.empty?

          net_name = network.attribute('networkName').text

          gateway = network.css('Gateway')
          gateway = gateway.text unless gateway.nil?

          netmask = network.css('Netmask')
          netmask = netmask.text unless netmask.nil?

          fence_mode = network.css('FenceMode')
          fence_mode = fence_mode.text unless fence_mode.nil?

          parent_network = network.css('ParentNetwork')
          parent_network = parent_network.attribute('name').text unless parent_network.empty?
          parent_network = nil if parent_network.empty?

          retain_network = network.css('RetainNetInfoAcrossDeployments')
          retain_network = retain_network.text unless retain_network.nil?

          # TODO: handle multiple scopes?
          ipscope =  {
              :gateway => gateway,
              :netmask => netmask,
              :fence_mode => fence_mode,
              :parent_network => parent_network,
              :retain_network => retain_network
            }

          {
            :id => net_id,
            :name => net_name,
            :scope => ipscope
          }
        end

      vapp_snapshot = nil
      response.css('SnapshotSection').each do |snapshot_section|
        if snapshot_section['href'] =~ /.*\/vApp\/vapp\-/
          snapshot = snapshot_section.css("Snapshot").first
          if snapshot
            vapp_snapshot = {
              :size => snapshot['size'],
              :creation_date => snapshot['created']
            }
          end
          break
        end
      end

      vms = response.css('Children Vm')
      vms_hash = {}

      vms.each do |vm|
        vapp_local_id = vm.css('VAppScopedLocalId')
        addresses = vm.css('rasd|Connection').collect do |n|
          address = n.attribute('vcloud:ipAddress')
          address = n.attribute('ipAddress') unless address
          address = address.text if address
        end

        vms_hash[vm['name']] = {
          :addresses => addresses,
          :status => convert_vapp_status(vm['status']),
          :id => vm['href'].gsub(/.*\/vApp\/vm\-/, ""),
          :vapp_scoped_local_id => vapp_local_id.text
        }
      end

      { :id => vAppId, :name => name, :description => description,
        :status => status, :ip => ip, :networks => networks,
        :vapp_snapshot => vapp_snapshot, :vms_hash => vms_hash }
    end
def get_vapp ( vAppId ) params = { 'method' => :get , 'command' => "/vApp/vapp-#{vAppId}" } response , headers = send_request ( params ) vapp_node = response . css ( 'VApp' ) . first if vapp_node name = vapp_node [ 'name' ] status = convert_vapp_status ( vapp_node [ 'status' ] ) end description = response . css ( "Description" ) . first description = description . text unless description . nil? ip = response . css ( 'IpAddress' ) . first ip = ip . text unless ip . nil? networks = response . css ( 'NetworkConfig' ) . reject { | n | n . attribute ( 'networkName' ) . text == 'none' } . collect do | network | net_id = network . css ( 'Link[rel="repair"]' ) net_id = net_id . attribute ( 'href' ) . text . gsub ( / \/ \/ \/ / , '\1' ) unless net_id . empty? net_name = network . attribute ( 'networkName' ) . text gateway = network . css ( 'Gateway' ) gateway = gateway . text unless gateway . nil? netmask = network . css ( 'Netmask' ) netmask = netmask . text unless netmask . nil? fence_mode = network . css ( 'FenceMode' ) fence_mode = fence_mode . text unless fence_mode . nil? parent_network = network . css ( 'ParentNetwork' ) parent_network = parent_network . attribute ( 'name' ) . text unless parent_network . empty? parent_network = nil if parent_network . empty? retain_network = network . css ( 'RetainNetInfoAcrossDeployments' ) retain_network = retain_network . text unless retain_network . nil? # TODO: handle multiple scopes? ipscope = { :gateway => gateway , :netmask => netmask , :fence_mode => fence_mode , :parent_network => parent_network , :retain_network => retain_network } { :id => net_id , :name => net_name , :scope => ipscope } end vapp_snapshot = nil response . css ( 'SnapshotSection' ) . each do | snapshot_section | if snapshot_section [ 'href' ] =~ / \/ \/ \- / snapshot = snapshot_section . css ( "Snapshot" ) . first if snapshot vapp_snapshot = { :size => snapshot [ 'size' ] , :creation_date => snapshot [ 'created' ] } end break end end vms = response . css ( 'Children Vm' ) vms_hash = { } vms . each do | vm | vapp_local_id = vm . css ( 'VAppScopedLocalId' ) addresses = vm . css ( 'rasd|Connection' ) . collect do | n | address = n . attribute ( 'vcloud:ipAddress' ) address = n . attribute ( 'ipAddress' ) unless address address = address . text if address end vms_hash [ vm [ 'name' ] ] = { :addresses => addresses , :status => convert_vapp_status ( vm [ 'status' ] ) , :id => vm [ 'href' ] . gsub ( / \/ \/ \- / , "" ) , :vapp_scoped_local_id => vapp_local_id . text } end { :id => vAppId , :name => name , :description => description , :status => status , :ip => ip , :networks => networks , :vapp_snapshot => vapp_snapshot , :vms_hash => vms_hash } end
Fetch details about a given vapp:
 - name
 - description
 - status
 - IP
 - Children VMs:
   -- IP addresses
   -- status
   -- ID
Fetch details about a given vapp : - name - description - status - IP - Children VMs : -- IP addresses -- status -- ID