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.



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

def initialize(connection)
  @connection = connection
end

Instance Attribute Details

#connectionObject

Returns the value of attribute connection.



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

def connection
  @connection
end

#hostedservicenameObject

Returns the value of attribute hostedservicename.



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

def hostedservicename
  @hostedservicename
end

#input_endpointsObject

Returns the value of attribute input_endpoints.



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

def input_endpoints
  @input_endpoints
end

#loadbalancersObject

Returns the value of attribute loadbalancers.



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

def loadbalancers
  @loadbalancers
end

#nameObject

Returns the value of attribute name.



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

def name
  @name
end

#statusObject

Returns the value of attribute status.



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

def status
  @status
end

#urlObject

Returns the value of attribute url.



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

def url
  @url
end

Instance Method Details

#create(params, deployXML) ⇒ Object



183
184
185
186
# File 'lib/azure/service_management/deploy.rb', line 183

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



214
215
216
# File 'lib/azure/service_management/deploy.rb', line 214

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

#find_role(name) ⇒ Object



218
219
220
# File 'lib/azure/service_management/deploy.rb', line 218

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..?



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

def parse_endpoint(inputendpoint_xml)
  hash = Hash.new
  %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"] = Hash.new
    %w{Path Port Protocol IntervalInSeconds TimeoutInSeconds}.each do |key|
      hash["LoadBalancerProbe"][key] = xml_content(probe, key, nil)
    end
  end
  hash
end

#retrieve(hostedservicename) ⇒ Object



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
159
# File 'lib/azure/service_management/deploy.rb', line 127

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 = Hash.new
    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 = Array.new
    endpointsXML = deployXML.css("InputEndpoint")
    endpointsXML.each do |endpointXML|
      @input_endpoints << parse_endpoint(endpointXML)
    end
    @loadbalancers = Hash.new
    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



209
210
211
# File 'lib/azure/service_management/deploy.rb', line 209

def roles
  @roles.values if @roles
end

#setup(params) ⇒ Object



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

def setup(params)
  role = Role.new(@connection)
  roleXML = role.setup(params)
  #roleXML = Nokogiri::XML 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