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.



107
108
109
110
111
# File 'lib/azure/service_management/host.rb', line 107

def initialize(connection)
  @connection = connection
  @deploys_loaded = false
  @deploys = {}
end

Instance Attribute Details

#connectionObject

Returns the value of attribute connection.



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

def connection
  @connection
end

#dateCreatedObject

Returns the value of attribute dateCreated.



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

def dateCreated
  @dateCreated
end

#dateModifiedObject

Returns the value of attribute dateModified.



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

def dateModified
  @dateModified
end

#descriptionObject

Returns the value of attribute description.



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

def description
  @description
end

#labelObject

Returns the value of attribute label.



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

def label
  @label
end

#locationObject

Returns the value of attribute location.



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

def location
  @location
end

#nameObject

Returns the value of attribute name.



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

def name
  @name
end

#statusObject

Returns the value of attribute status.



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

def status
  @status
end

#urlObject

Returns the value of attribute url.



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

def url
  @url
end

Instance Method Details

#add_deploy(deploy) ⇒ Object

Deployments within this hostedservice



147
148
149
# File 'lib/azure/service_management/host.rb', line 147

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

#create(params) ⇒ Object



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

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



151
152
153
# File 'lib/azure/service_management/host.rb', line 151

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

#deploysObject



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

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



142
143
144
# File 'lib/azure/service_management/host.rb', line 142

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

#find_role(role_name, deploy_name = nil) ⇒ Object



174
175
176
177
178
179
180
181
182
# File 'lib/azure/service_management/host.rb', line 174

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



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

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



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

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