Sha256: 1988c12b6d013eb2fb24080269d8f4cf519641998f378083515f00d52873e00a

Contents?: true

Size: 1.34 KB

Versions: 1

Compression:

Stored size: 1.34 KB

Contents

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

module Fog
  module Network
    class AzureRM
      class VirtualNetworks < Fog::Collection
        model Fog::Network::AzureRM::VirtualNetwork
        attribute :resource_group

        def all
          requires :resource_group
          virtual_networks = []
          service.list_virtual_networks(resource_group).each do |vnet|
            hash = {}
            vnet.instance_variables.each do |var|
              hash[var.to_s.delete('@')] = vnet.instance_variable_get(var)
            end
            hash['resource_group'] = vnet.instance_variable_get('@id').split('/')[4]
            virtual_networks << hash
          end
          load(virtual_networks)
        end

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

        def check_if_exists(name, resource_group)
          Fog::Logger.debug "Checkng if Virtual Network #{name} exists."
          if service.check_for_virtual_network(name, resource_group)
            Fog::Logger.debug "Virtual Network #{name} exists."
            true
          else
            Fog::Logger.debug "Virtual Network #{name} doesn't exists."
            false
          end
        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/virtual_networks.rb