Module: Azure

Defined in:
lib/fog/bin/azure.rb

Overview

Copyright (c) Microsoft Open Technologies, Inc. All rights reserved.

The MIT License (MIT)

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Class Method Summary collapse

Class Method Details

.[](service) ⇒ Object



33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/fog/bin/azure.rb', line 33

def [](service)
  @@connections ||= Hash.new do |hash, key|
    hash[key] = case key
    when :compute
      Fog::Logger.warning("Azure[:compute] is not recommended, use Compute[:azure] for portability")
      Fog::Compute.new(:provider => 'Azure')
    else
      raise ArgumentError, "Unrecognized service: #{key.inspect}"
    end
  end
  @@connections[service]
end

.available?Boolean

Returns:

  • (Boolean)


46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
# File 'lib/fog/bin/azure.rb', line 46

def available?
  availability = true
  for service in services
    begin
      service = self.class_for(service)
      availability &&= service.requirements.all? { |requirement| Fog.credentials.include?(requirement) }
    rescue ArgumentError => e
      Fog::Logger.warning(e.message)
      availability = false
    rescue => e
      availability = false
    end
  end

  if availability
    for service in services
      for collection in self.class_for(service).collections
        unless self.respond_to?(collection)
          self.class_eval <<-EOS, __FILE__, __LINE__
            def self.#{collection}
              self[:#{service}].#{collection}
            end
          EOS
        end
      end
    end
  end
  availability
end

.class_for(key) ⇒ Object



24
25
26
27
28
29
30
31
# File 'lib/fog/bin/azure.rb', line 24

def class_for(key)
  case key
  when :compute
    Fog::Compute::Azure
  else
    raise ArgumentError, "Unrecognized service: #{key}"
  end
end

.collectionsObject



76
77
78
# File 'lib/fog/bin/azure.rb', line 76

def collections
  services.map {|service| self[service].collections}.flatten.sort_by {|service| service.to_s}
end

.servicesObject



80
81
82
# File 'lib/fog/bin/azure.rb', line 80

def services
  Fog::Azure.services
end