Sha256: 6c910825438c82e241f283a999313d742523c9bd9bd41b2ed96187b631a2ae34

Contents?: true

Size: 1.15 KB

Versions: 35

Compression:

Stored size: 1.15 KB

Contents

#
# Author:: Matt Eldridge (<matt.eldridge@us.ibm.com>)
# © Copyright IBM Corporation 2014.
#
# LICENSE: MIT (http://opensource.org/licenses/MIT)
#

require 'fog/core/collection'
require 'fog/softlayer/models/network/network'

module Fog
  module Network
    class Softlayer
      class Networks < Fog::Collection
        model Fog::Network::Softlayer::Network

        def all
          data = service.list_networks.body
          load(data)
        end

        def get(id)
          if network = service.get_network(id).body
            new(network)
          end
        rescue Fog::Network::Softlayer::NotFound
          nil
        end

        def tagged_with(tags)
          raise ArgumentError, "Tags argument for #{self.class.name}##{__method__} must be Array." unless tags.is_a?(Array)
          ids = service.get_references_by_tag_name(tags.join(',')).body.map do |tag|
            tag['references'].map do |ref|
              ref['resourceTableId']
            end
          end.flatten.uniq
          ids.map { |id| get(id) }
        end

        def by_name(name)
          all.select { |vlan| vlan.name == name }.first
        end

      end
    end
  end
end

Version data entries

35 entries across 35 versions & 1 rubygems

Version Path
fog-softlayer-0.4.2.pre lib/fog/softlayer/models/network/networks.rb
fog-softlayer-0.4.1 lib/fog/softlayer/models/network/networks.rb
fog-softlayer-0.4.0 lib/fog/softlayer/models/network/networks.rb
fog-softlayer-0.3.30 lib/fog/softlayer/models/network/networks.rb
fog-softlayer-0.3.29 lib/fog/softlayer/models/network/networks.rb
fog-softlayer-0.3.28 lib/fog/softlayer/models/network/networks.rb
fog-softlayer-0.3.27 lib/fog/softlayer/models/network/networks.rb
fog-softlayer-0.3.26 lib/fog/softlayer/models/network/networks.rb
fog-softlayer-0.3.25 lib/fog/softlayer/models/network/networks.rb
fog-softlayer-0.3.24 lib/fog/softlayer/models/network/networks.rb
fog-softlayer-0.3.23 lib/fog/softlayer/models/network/networks.rb
fog-softlayer-0.3.22 lib/fog/softlayer/models/network/networks.rb
fog-softlayer-0.3.21 lib/fog/softlayer/models/network/networks.rb
fog-softlayer-0.3.20 lib/fog/softlayer/models/network/networks.rb
fog-softlayer-0.3.19 lib/fog/softlayer/models/network/networks.rb
fog-softlayer-0.3.18 lib/fog/softlayer/models/network/networks.rb
fog-softlayer-0.3.17 lib/fog/softlayer/models/network/networks.rb
fog-softlayer-0.3.16 lib/fog/softlayer/models/network/networks.rb
fog-softlayer-0.3.15 lib/fog/softlayer/models/network/networks.rb
fog-softlayer-0.3.14 lib/fog/softlayer/models/network/networks.rb