Sha256: 2ce2eb88b3490897c5d3c6aefe7ba3340ff68d768977dbad9e30cf395161fe5f

Contents?: true

Size: 1.07 KB

Versions: 1

Compression:

Stored size: 1.07 KB

Contents

require 'fog/core/collection'
require 'fog/azurerm/models/network/subnet'

module Fog
  module Network
    class AzureRM
      # Subnet collection for network service
      class Subnets < Fog::Collection
        model Fog::Network::AzureRM::Subnet
        attribute :resource_group
        attribute :virtual_network_name

        def all
          requires :resource_group
          requires :virtual_network_name
          subnets = []
          service.list_subnets(resource_group, virtual_network_name).each do |subnet|
            hash = {}
            subnet.instance_variables.each do |var|
              hash[var.to_s.delete('@')] = subnet.instance_variable_get(var)
            end
            hash['resource_group'] = subnet.instance_variable_get('@id').split('/')[4]
            hash['virtual_network_name'] = subnet.instance_variable_get('@id').split('/')[8]
            subnets << hash
          end
          load(subnets)
        end

        def get(identity)
          all.find { |f| f.name == identity }
        end
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
fog-azure-rm-0.0.1 lib/fog/azurerm/models/network/subnets.rb