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.



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

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

Instance Attribute Details

#connectionObject

Returns the value of attribute connection.



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

def connection
  @connection
end

#dateCreatedObject

Returns the value of attribute dateCreated.



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

def dateCreated
  @dateCreated
end

#dateModifiedObject

Returns the value of attribute dateModified.



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

def dateModified
  @dateModified
end

#descriptionObject

Returns the value of attribute description.



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

def description
  @description
end

#labelObject

Returns the value of attribute label.



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

def label
  @label
end

#locationObject

Returns the value of attribute location.



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

def location
  @location
end

#nameObject

Returns the value of attribute name.



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

def name
  @name
end

#statusObject

Returns the value of attribute status.



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

def status
  @status
end

#urlObject

Returns the value of attribute url.



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

def url
  @url
end

Instance Method Details

#add_deploy(deploy) ⇒ Object

Deployments within this hostedservice



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

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

#create(params) ⇒ Object



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

def create(params)
  builder = Nokogiri::XML::Builder.new do |xml|
    xml.CreateHostedService('xmlns'=>'http://schemas.microsoft.com/windowsazure') {
      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
  @connection.query_azure("hostedservices", "post", builder.to_xml)
end

#delete_role(role) ⇒ Object



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

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

#deploysObject



149
150
151
152
153
154
155
156
157
158
# File 'lib/azure/service_management/host.rb', line 149

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



136
137
138
# File 'lib/azure/service_management/host.rb', line 136

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

#find_role(role_name, deploy_name = nil) ⇒ Object



168
169
170
171
172
173
174
175
# File 'lib/azure/service_management/host.rb', line 168

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



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

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



160
161
162
163
164
165
166
# File 'lib/azure/service_management/host.rb', line 160

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