Sha256: a0b9b6dd4a9881b5ccb4d30f6f503245beaef6935e094372103997b2df36c482

Contents?: true

Size: 1.98 KB

Versions: 8

Compression:

Stored size: 1.98 KB

Contents

module Fog
  module Compute
    class Vsphere
      class Real
        def list_networks(filters = { })
          datacenter_name = filters[:datacenter]
          cluster_name = filters.fetch(:cluster, nil)
          # default to show all networks
          only_active = filters[:accessible] || false
          raw_networks(datacenter_name, cluster_name).map do |network|
            next if only_active and !network.summary.accessible
            network_attributes(network, datacenter_name)
          end.compact
        end

        def raw_networks(datacenter_name, cluster = nil)
          if cluster.nil?
            find_raw_datacenter(datacenter_name).network
          else
            get_raw_cluster(cluster, datacenter_name).network
          end
        end

        protected

        def network_attributes network, datacenter
          raw_network = get_raw_network(network.name, datacenter)
          if raw_network.kind_of? RbVmomi::VIM::DistributedVirtualPortgroup
            id = raw_network.key
          else
            id = managed_obj_id(network)
          end
          {
            :id            => id,
            :name          => network.name,
            :accessible    => network.summary.accessible,
            :datacenter    => datacenter,
            :virtualswitch => network.class.name == "DistributedVirtualPortgroup" ? network.config.distributedVirtualSwitch.name : nil
          }
        end
      end
      class Mock
        def list_networks(filters)
          datacenter_name = filters[:datacenter]
          cluster_name = filters.fetch(:cluster, nil)
          if cluster_name.nil?
            self.data[:networks].values.select { |d| d['datacenter'] == datacenter_name } or
              raise Fog::Compute::Vsphere::NotFound
          else
            self.data[:networks].values.select { |d| d['datacenter'] == datacenter_name && d['cluster'].include?(cluster_name) } or
              raise Fog::Compute::Vsphere::NotFound
          end
        end
      end
    end
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
fog-vsphere-2.0.1 lib/fog/vsphere/requests/compute/list_networks.rb
fog-vsphere-2.0.0 lib/fog/vsphere/requests/compute/list_networks.rb
fog-vsphere-1.13.1 lib/fog/vsphere/requests/compute/list_networks.rb
fog-vsphere-1.13.0 lib/fog/vsphere/requests/compute/list_networks.rb
fog-vsphere-1.12.0 lib/fog/vsphere/requests/compute/list_networks.rb
fog-vsphere-1.11.3 lib/fog/vsphere/requests/compute/list_networks.rb
fog-vsphere-1.11.2 lib/fog/vsphere/requests/compute/list_networks.rb
fog-vsphere-1.11.1 lib/fog/vsphere/requests/compute/list_networks.rb