Class: Azure::Hosts
- Inherits:
-
Object
- Object
- Azure::Hosts
- Includes:
- AzureUtility
- Defined in:
- lib/azure/service_management/host.rb
Instance Method Summary collapse
- #all ⇒ Object
- #create(params) ⇒ Object
- #delete(name) ⇒ Object
-
#exists?(name) ⇒ Boolean
first look up local cache if we have already loaded list.
-
#exists_on_cloud?(name) ⇒ Boolean
Look up on cloud and not local cache.
-
#fetch_from_cloud(name) ⇒ Object
Look up hosted service on cloud and not local cache.
-
#find(name) ⇒ Object
first look up local cache if we have already loaded list.
-
#initialize(connection) ⇒ Hosts
constructor
A new instance of Hosts.
-
#load(force_load = false) ⇒ Object
force_load should be true when there is something in local cache and we want to reload first call is always load.
Methods included from AzureUtility
#error_from_response_xml, #xml_content
Constructor Details
#initialize(connection) ⇒ Hosts
Returns a new instance of Hosts.
22 23 24 |
# File 'lib/azure/service_management/host.rb', line 22 def initialize(connection) @connection=connection end |
Instance Method Details
#all ⇒ Object
44 45 46 |
# File 'lib/azure/service_management/host.rb', line 44 def all self.load.values end |
#create(params) ⇒ Object
84 85 86 87 |
# File 'lib/azure/service_management/host.rb', line 84 def create(params) host = Host.new(@connection) host.create(params) end |
#delete(name) ⇒ Object
88 89 90 91 92 93 |
# File 'lib/azure/service_management/host.rb', line 88 def delete(name) if self.exists?(name) servicecall = "hostedservices/" + name @connection.query_azure(servicecall, "delete") end end |
#exists?(name) ⇒ Boolean
first look up local cache if we have already loaded list.
49 50 51 52 |
# File 'lib/azure/service_management/host.rb', line 49 def exists?(name) return @hosted_services.key?(name) if @hosted_services self.exists_on_cloud?(name) end |
#exists_on_cloud?(name) ⇒ Boolean
Look up on cloud and not local cache
55 56 57 58 59 60 61 62 63 64 |
# File 'lib/azure/service_management/host.rb', line 55 def exists_on_cloud?(name) ret_val = @connection.query_azure("hostedservices/#{name}") error_code, = error_from_response_xml(ret_val) if ret_val if ret_val.nil? || error_code.length > 0 Chef::Log.debug('Unable to find hosted(cloud) service:' + error_code + ' : ' + ) if ret_val false else true end end |
#fetch_from_cloud(name) ⇒ Object
Look up hosted service on cloud and not local cache
73 74 75 76 77 78 79 80 81 82 |
# File 'lib/azure/service_management/host.rb', line 73 def fetch_from_cloud(name) ret_val = @connection.query_azure("hostedservices/#{name}") error_code, = error_from_response_xml(ret_val) if ret_val if ret_val.nil? || error_code.length > 0 Chef::Log.warn('Unable to find hosted(cloud) service:' + error_code + ' : ' + ) if ret_val nil else Host.new(@connection).parse(ret_val) end end |
#find(name) ⇒ Object
first look up local cache if we have already loaded list.
67 68 69 70 |
# File 'lib/azure/service_management/host.rb', line 67 def find(name) return @hosted_services[name] if @hosted_services && @hosted_services.key?(name) self.fetch_from_cloud(name) end |
#load(force_load = false) ⇒ Object
force_load should be true when there is something in local cache and we want to reload first call is always load.
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/azure/service_management/host.rb', line 28 def load(force_load = false) if not @hosted_services || force_load @hosted_services = begin hosted_services = Hash.new responseXML = @connection.query_azure('hostedservices') servicesXML = responseXML.css('HostedServices HostedService') servicesXML.each do |serviceXML| host = Host.new(@connection).parse(serviceXML) hosted_services[host.name] = host end hosted_services end end @hosted_services end |