Class: Azure::Host

Inherits:
Object
  • Object
show all
Includes:
AzureUtility
Defined in:
lib/azure/service_management/host.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from AzureUtility

#error_from_response_xml, #xml_content

Constructor Details

#initialize(connection) ⇒ Host

Returns a new instance of Host.



105
106
107
108
109
# File 'lib/azure/service_management/host.rb', line 105

def initialize(connection)
  @connection = connection
  @deploys_loaded = false
  @deploys = Hash.new
end

Instance Attribute Details

#connectionObject

Returns the value of attribute connection.



101
102
103
# File 'lib/azure/service_management/host.rb', line 101

def connection
  @connection
end

#dateCreatedObject

Returns the value of attribute dateCreated.



102
103
104
# File 'lib/azure/service_management/host.rb', line 102

def dateCreated
  @dateCreated
end

#dateModifiedObject

Returns the value of attribute dateModified.



103
104
105
# File 'lib/azure/service_management/host.rb', line 103

def dateModified
  @dateModified
end

#descriptionObject

Returns the value of attribute description.



102
103
104
# File 'lib/azure/service_management/host.rb', line 102

def description
  @description
end

#labelObject

Returns the value of attribute label.



101
102
103
# File 'lib/azure/service_management/host.rb', line 101

def label
  @label
end

#locationObject

Returns the value of attribute location.



102
103
104
# File 'lib/azure/service_management/host.rb', line 102

def location
  @location
end

#nameObject

Returns the value of attribute name.



101
102
103
# File 'lib/azure/service_management/host.rb', line 101

def name
  @name
end

#statusObject

Returns the value of attribute status.



103
104
105
# File 'lib/azure/service_management/host.rb', line 103

def status
  @status
end

#urlObject

Returns the value of attribute url.



101
102
103
# File 'lib/azure/service_management/host.rb', line 101

def url
  @url
end

Instance Method Details

#add_deploy(deploy) ⇒ Object

Deployments within this hostedservice



145
146
147
# File 'lib/azure/service_management/host.rb', line 145

def add_deploy(deploy)
  @deploys[deploy.name] = deploy
end

#create(params) ⇒ Object



123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
# File 'lib/azure/service_management/host.rb', line 123

def create(params)
  builder = Nokogiri::XML::Builder.new do |xml|
    xml.CreateHostedService("xmlns" => "http://schemas.microsoft.com/windowsazure") do
      xml.ServiceName params[:azure_dns_name]
      xml.Label Base64.encode64(params[:azure_dns_name])
      xml.Description "Explicitly created hosted service"
      unless params[:azure_service_location].nil?
        xml.Location params[:azure_service_location]
      end
      unless params[:azure_affinity_group].nil?
        xml.AffinityGroup params[:azure_affinity_group]
      end
    end
  end
  @connection.query_azure("hostedservices", "post", builder.to_xml)
end

#delete_role(role) ⇒ Object



149
150
151
# File 'lib/azure/service_management/host.rb', line 149

def delete_role(role)
  deploys.each { |d| d.delete_role_if_present(role) }
end

#deploysObject



153
154
155
156
157
158
159
160
161
162
# File 'lib/azure/service_management/host.rb', line 153

def deploys
  # check if we have deploys loaded, else load.
  if (@deploys.length == 0) && !@deploys_loaded
    deploy = Deploy.new(@connection)
    deploy.retrieve(@name)
    @deploys[deploy.name] = deploy
    @deploys_loaded = true
  end
  @deploys.values
end

#detailsObject



140
141
142
# File 'lib/azure/service_management/host.rb', line 140

def details
  response = @connection.query_azure("hostedservices/" + @name + "?embed-detail=true")
end

#find_role(role_name, deploy_name = nil) ⇒ Object



172
173
174
175
176
177
178
179
# File 'lib/azure/service_management/host.rb', line 172

def find_role(role_name, deploy_name = nil)
  return @deploys[deploy_name].find_role(role_name) if deploy_name && deploys
  # else lookup all deploys within hostedservice
  deploys.each do |deploy|
    role = deploy.find_role(role_name)
    return role if role
  end
end

#parse(serviceXML) ⇒ Object



111
112
113
114
115
116
117
118
119
120
121
# File 'lib/azure/service_management/host.rb', line 111

def parse(serviceXML)
  @name = xml_content(serviceXML, "ServiceName")
  @url = xml_content(serviceXML, "Url")
  @label = xml_content(serviceXML, "HostedServiceProperties Label")
  @dateCreated = xml_content(serviceXML, "HostedServiceProperties DateCreated")
  @description = xml_content(serviceXML, "HostedServiceProperties Description")
  @location = xml_content(serviceXML, "HostedServiceProperties Location")
  @dateModified = xml_content(serviceXML, "HostedServiceProperties DateLastModified")
  @status = xml_content(serviceXML, "HostedServiceProperties Status")
  self
end

#rolesObject



164
165
166
167
168
169
170
# File 'lib/azure/service_management/host.rb', line 164

def roles
  roles = []
  deploys.each do |deploy|
    roles.concat(deploy.roles) if deploy.roles
  end
  roles
end