Class: Azure::Deploy

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from AzureUtility

#error_from_response_xml, #xml_content

Constructor Details

#initialize(connection) ⇒ Deploy

Returns a new instance of Deploy.



122
123
124
# File 'lib/azure/service_management/deploy.rb', line 122

def initialize(connection)
  @connection = connection
end

Instance Attribute Details

#connectionObject

Returns the value of attribute connection.



120
121
122
# File 'lib/azure/service_management/deploy.rb', line 120

def connection
  @connection
end

#hostedservicenameObject

Returns the value of attribute hostedservicename.



120
121
122
# File 'lib/azure/service_management/deploy.rb', line 120

def hostedservicename
  @hostedservicename
end

#input_endpointsObject

Returns the value of attribute input_endpoints.



120
121
122
# File 'lib/azure/service_management/deploy.rb', line 120

def input_endpoints
  @input_endpoints
end

#loadbalancersObject

Returns the value of attribute loadbalancers.



120
121
122
# File 'lib/azure/service_management/deploy.rb', line 120

def loadbalancers
  @loadbalancers
end

#nameObject

Returns the value of attribute name.



120
121
122
# File 'lib/azure/service_management/deploy.rb', line 120

def name
  @name
end

#statusObject

Returns the value of attribute status.



120
121
122
# File 'lib/azure/service_management/deploy.rb', line 120

def status
  @status
end

#urlObject

Returns the value of attribute url.



120
121
122
# File 'lib/azure/service_management/deploy.rb', line 120

def url
  @url
end

Instance Method Details

#create(params, deployXML) ⇒ Object



181
182
183
184
# File 'lib/azure/service_management/deploy.rb', line 181

def create(params, deployXML)
  servicecall = "hostedservices/#{params[:azure_dns_name]}/deployments"
  @connection.query_azure(servicecall, "post", deployXML.to_xml)
end

#delete_role_if_present(role) ⇒ Object

just delete from local cache



212
213
214
# File 'lib/azure/service_management/deploy.rb', line 212

def delete_role_if_present(role)
  @roles.delete(role.name) if @roles
end

#find_role(name) ⇒ Object



216
217
218
# File 'lib/azure/service_management/deploy.rb', line 216

def find_role(name)
  @roles[name] if @roles
end

#parse_endpoint(inputendpoint_xml) ⇒ Object

This parses endpoints from a RoleList-Role-InputEndpoint, NOT a RoleInstanceList-RoleInstance-InstanceEndpoint Refactor: make this an object rather than a hash..?



188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
# File 'lib/azure/service_management/deploy.rb', line 188

def parse_endpoint(inputendpoint_xml)
  hash = {}
  %w{LoadBalancedEndpointSetName LocalPort Name Port Protocol EnableDirectServerReturn LoadBalancerName IdleTimeoutInMinutes}.each do |key|
    hash[key] = xml_content(inputendpoint_xml, key, nil)
  end
  # Protocol could be in there twice... If we have two, pick the second one as the first is for the probe.
  if inputendpoint_xml.css("Protocol").count > 1
    hash["Protocol"] = inputendpoint_xml.css("Protocol")[1].content
  end
  probe = inputendpoint_xml.css("LoadBalancerProbe")
  if probe
    hash["LoadBalancerProbe"] = {}
    %w{Path Port Protocol IntervalInSeconds TimeoutInSeconds}.each do |key|
      hash["LoadBalancerProbe"][key] = xml_content(probe, key, nil)
    end
  end
  hash
end

#retrieve(hostedservicename) ⇒ Object



126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
# File 'lib/azure/service_management/deploy.rb', line 126

def retrieve(hostedservicename)
  @hostedservicename = hostedservicename
  deployXML = @connection.query_azure("hostedservices/#{hostedservicename}/deploymentslots/Production")
  if deployXML.at_css("Deployment Name") != nil
    @name = xml_content(deployXML, "Deployment Name")
    @status = xml_content(deployXML, "Deployment Status")
    @url = xml_content(deployXML, "Deployment Url")
    @roles = {}
    rolesXML = deployXML.css("Deployment RoleInstanceList RoleInstance")
    rolesListXML = deployXML.css("Deployment RoleList Role")
    rolesXML.zip(rolesListXML).each do |roleXML, roleListXML|
      role = Role.new(@connection)
      role.parse(roleXML, hostedservicename, @name)
      if role.publicipaddress.to_s.empty?
        role.publicipaddress = xml_content(deployXML, "VirtualIPs VirtualIP Address")
      end
      role.parse_role_list_xml(roleListXML)
      @roles[role.name] = role
    end
    @input_endpoints = []
    endpointsXML = deployXML.css("InputEndpoint")
    endpointsXML.each do |endpointXML|
      @input_endpoints << parse_endpoint(endpointXML)
    end
    @loadbalancers = {}
    lbsXML = deployXML.css("Deployment LoadBalancers LoadBalancer")
    lbsXML.each do |lbXML|
      loadbalancer = Loadbalancer.new(@connection)
      loadbalancer.parse(lbXML, hostedservicename)
      @loadbalancers[loadbalancer.name] = loadbalancer
    end
  end
end

#rolesObject



207
208
209
# File 'lib/azure/service_management/deploy.rb', line 207

def roles
  @roles.values if @roles
end

#setup(params) ⇒ Object



160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
# File 'lib/azure/service_management/deploy.rb', line 160

def setup(params)
  role = Role.new(@connection)
  roleXML = role.setup(params)
  builder = Nokogiri::XML::Builder.new do |xml|
    xml.Deployment(
      "xmlns" => "http://schemas.microsoft.com/windowsazure",
      "xmlns:i" => "http://www.w3.org/2001/XMLSchema-instance"
    ) do
      xml.Name params["deploy_name"]
      xml.DeploymentSlot "Production"
      xml.Label Base64.encode64(params["deploy_name"]).strip
      xml.RoleList { xml.Role("i:type" => "PersistentVMRole") }
      if params[:azure_network_name]
        xml.VirtualNetworkName params[:azure_network_name]
      end
    end
  end
  builder.doc.at_css("Role") << roleXML.at_css("PersistentVMRole").children.to_s
  builder.doc
end