Sha256: 09e1f63e5a350df1f7bcbc5c5821de29c187da3b7c90806b19da49e5856a0d8e

Contents?: true

Size: 1.4 KB

Versions: 80

Compression:

Stored size: 1.4 KB

Contents

module Fog
  module Compute
    class Libvirt
      class Real
        def list_networks(filter = { })

          data=[]
          if filter.keys.empty?
            (client.list_networks + client.list_defined_networks).each do |network_name|
              data << network_to_attributes(client.lookup_network_by_name(network_name))
            end
          else
            data = [network_to_attributes(get_network_by_filter(filter))]
          end
          data
        end

        private
        # Retrieve the network by uuid or name
        def get_network_by_filter(filter)
          case filter.keys.first
            when :uuid
              client.lookup_network_by_uuid(filter[:uuid])
            when :name
              client.lookup_network_by_name(filter[:name])
          end

        end

        def network_to_attributes(net)
          return if net.nil?
          {
            :uuid        => net.uuid,
            :name        => net.name,
            :bridge_name => net.bridge_name
          }
        end

      end

      class Mock
        def list_networks(filters={ })
          net1 = mock_network 'net1'
          net2 = mock_network 'net2'
          [net1, net2]
        end

        def mock_network name
          {
              :uuid        => 'net.uuid',
              :name        => name,
              :bridge_name => 'net.bridge_name'
          }
        end
      end
    end
  end
end

Version data entries

80 entries across 80 versions & 13 rubygems

Version Path
fog-maestrodev-1.18.0.20131209090811 lib/fog/libvirt/requests/compute/list_networks.rb
fog-maestrodev-1.18.0.20131206115947 lib/fog/libvirt/requests/compute/list_networks.rb
fog-maestrodev-1.18.0.20131205181604 lib/fog/libvirt/requests/compute/list_networks.rb
fog-maestrodev-1.18.0.20131127194823 lib/fog/libvirt/requests/compute/list_networks.rb
fog-maestrodev-1.18.0.20131126183714 lib/fog/libvirt/requests/compute/list_networks.rb
fog-maestrodev-1.18.0.20131126122111 lib/fog/libvirt/requests/compute/list_networks.rb
fog-maestrodev-1.18.0.20131125111730 lib/fog/libvirt/requests/compute/list_networks.rb
fog-maestrodev-1.18.0.20131125083406 lib/fog/libvirt/requests/compute/list_networks.rb
fog-maestrodev-1.18.0.20131123105121 lib/fog/libvirt/requests/compute/list_networks.rb
fog-maestrodev-1.18.0.20131122203507 lib/fog/libvirt/requests/compute/list_networks.rb
fog-maestrodev-1.18.0.20131121075022 lib/fog/libvirt/requests/compute/list_networks.rb
fog-maestrodev-1.18.0.20131118164830 lib/fog/libvirt/requests/compute/list_networks.rb
fog-maestrodev-1.18.0.20131115184302 lib/fog/libvirt/requests/compute/list_networks.rb
fog-maestrodev-1.18.0.20131114200144 lib/fog/libvirt/requests/compute/list_networks.rb
gapinc-fog-1.12.1.2.1 lib/fog/libvirt/requests/compute/list_networks.rb
fog-maestrodev-1.18.0.20131112185232 lib/fog/libvirt/requests/compute/list_networks.rb
fog-maestrodev-1.18.0.20131111203459 lib/fog/libvirt/requests/compute/list_networks.rb
fog-1.18.0 lib/fog/libvirt/requests/compute/list_networks.rb
fog-1.17.0 lib/fog/libvirt/requests/compute/list_networks.rb
fog-1.16.0 lib/fog/libvirt/requests/compute/list_networks.rb