Class: Azure::Role
Instance Attribute Summary collapse
-
#connection ⇒ Object
Returns the value of attribute connection.
-
#deployname ⇒ Object
Returns the value of attribute deployname.
-
#hostedservicename ⇒ Object
Returns the value of attribute hostedservicename.
-
#hostname ⇒ Object
Returns the value of attribute hostname.
-
#ipaddress ⇒ Object
Returns the value of attribute ipaddress.
-
#name ⇒ Object
Returns the value of attribute name.
-
#publicipaddress ⇒ Object
Returns the value of attribute publicipaddress.
-
#size ⇒ Object
Returns the value of attribute size.
-
#sshport ⇒ Object
Returns the value of attribute sshport.
-
#status ⇒ Object
Returns the value of attribute status.
-
#tcpports ⇒ Object
Returns the value of attribute tcpports.
-
#udpports ⇒ Object
Returns the value of attribute udpports.
-
#winrmport ⇒ Object
Returns the value of attribute winrmport.
Instance Method Summary collapse
- #create(params, roleXML) ⇒ Object
-
#initialize(connection) ⇒ Role
constructor
A new instance of Role.
- #parse(roleXML, hostedservicename, deployname) ⇒ Object
- #setup(params) ⇒ Object
Methods included from AzureUtility
#error_from_response_xml, #xml_content
Constructor Details
#initialize(connection) ⇒ Role
Returns a new instance of Role.
178 179 180 |
# File 'lib/azure/role.rb', line 178 def initialize(connection) @connection = connection end |
Instance Attribute Details
#connection ⇒ Object
Returns the value of attribute connection.
173 174 175 |
# File 'lib/azure/role.rb', line 173 def connection @connection end |
#deployname ⇒ Object
Returns the value of attribute deployname.
174 175 176 |
# File 'lib/azure/role.rb', line 174 def deployname @deployname end |
#hostedservicename ⇒ Object
Returns the value of attribute hostedservicename.
174 175 176 |
# File 'lib/azure/role.rb', line 174 def hostedservicename @hostedservicename end |
#hostname ⇒ Object
Returns the value of attribute hostname.
176 177 178 |
# File 'lib/azure/role.rb', line 176 def hostname @hostname end |
#ipaddress ⇒ Object
Returns the value of attribute ipaddress.
173 174 175 |
# File 'lib/azure/role.rb', line 173 def ipaddress @ipaddress end |
#name ⇒ Object
Returns the value of attribute name.
173 174 175 |
# File 'lib/azure/role.rb', line 173 def name @name end |
#publicipaddress ⇒ Object
Returns the value of attribute publicipaddress.
173 174 175 |
# File 'lib/azure/role.rb', line 173 def publicipaddress @publicipaddress end |
#size ⇒ Object
Returns the value of attribute size.
173 174 175 |
# File 'lib/azure/role.rb', line 173 def size @size end |
#sshport ⇒ Object
Returns the value of attribute sshport.
174 175 176 |
# File 'lib/azure/role.rb', line 174 def sshport @sshport end |
#status ⇒ Object
Returns the value of attribute status.
173 174 175 |
# File 'lib/azure/role.rb', line 173 def status @status end |
#tcpports ⇒ Object
Returns the value of attribute tcpports.
176 177 178 |
# File 'lib/azure/role.rb', line 176 def tcpports @tcpports end |
#udpports ⇒ Object
Returns the value of attribute udpports.
176 177 178 |
# File 'lib/azure/role.rb', line 176 def udpports @udpports end |
#winrmport ⇒ Object
Returns the value of attribute winrmport.
175 176 177 |
# File 'lib/azure/role.rb', line 175 def winrmport @winrmport end |
Instance Method Details
#create(params, roleXML) ⇒ Object
342 343 344 345 346 |
# File 'lib/azure/role.rb', line 342 def create(params, roleXML) servicecall = "hostedservices/#{params[:azure_dns_name]}/deployments" + "/#{params['deploy_name']}/roles" @connection.query_azure(servicecall, "post", roleXML.to_xml) end |
#parse(roleXML, hostedservicename, deployname) ⇒ Object
181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 |
# File 'lib/azure/role.rb', line 181 def parse(roleXML, hostedservicename, deployname) @name = xml_content(roleXML, 'RoleName') @status = xml_content(roleXML, 'InstanceStatus') @size = xml_content(roleXML, 'InstanceSize') @ipaddress = xml_content(roleXML, 'IpAddress') @hostname = xml_content(roleXML, 'HostName') @hostedservicename = hostedservicename @deployname = deployname @tcpports = Array.new @udpports = Array.new endpoints = roleXML.css('InstanceEndpoint') @publicipaddress = xml_content(endpoints[0], 'Vip') if !endpoints.empty? endpoints.each do |endpoint| if xml_content(endpoint, 'Name').downcase == 'ssh' @sshport = xml_content(endpoint, 'PublicPort') elsif xml_content(endpoint, 'Name').downcase == 'winrm' @winrmport = xml_content(endpoint, 'PublicPort') else hash = Hash.new hash['Name'] = xml_content(endpoint, 'Name') hash['Vip'] = xml_content(endpoint, 'Vip') hash['PublicPort'] = xml_content(endpoint, 'PublicPort') hash['LocalPort'] = xml_content(endpoint, 'LocalPort') if xml_content(endpoint, 'Protocol') == 'tcp' @tcpports << hash else # == 'udp' @udpports << hash end end end end |
#setup(params) ⇒ Object
213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 |
# File 'lib/azure/role.rb', line 213 def setup(params) builder = Nokogiri::XML::Builder.new do |xml| xml.PersistentVMRole( 'xmlns'=>'http://schemas.microsoft.com/windowsazure', 'xmlns:i'=>'http://www.w3.org/2001/XMLSchema-instance' ) { xml.RoleName {xml.text params[:azure_vm_name]} xml.OsVersion('i:nil' => 'true') xml.RoleType 'PersistentVMRole' xml.ConfigurationSets { if params[:os_type] == 'Linux' xml.ConfigurationSet('i:type' => 'LinuxProvisioningConfigurationSet') { xml.ConfigurationSetType 'LinuxProvisioningConfiguration' xml.HostName params[:azure_vm_name] xml.UserName params[:ssh_user] unless params[:identity_file].nil? xml.DisableSshPasswordAuthentication 'true' xml.SSH { xml.PublicKeys { xml.PublicKey { xml.Fingerprint params[:fingerprint].to_s.upcase xml.Path '/home/' + params[:ssh_user] + '/.ssh/authorized_keys' } } } else xml.UserPassword params[:ssh_password] xml.DisableSshPasswordAuthentication 'false' end } elsif params[:os_type] == 'Windows' xml.ConfigurationSet('i:type' => 'WindowsProvisioningConfigurationSet') { xml.ConfigurationSetType 'WindowsProvisioningConfiguration' xml.ComputerName params[:azure_vm_name] xml.AdminPassword params[:admin_password] xml.ResetPasswordOnFirstLogon 'false' xml.EnableAutomaticUpdates 'false' xml.AdminUsername params[:winrm_user] if params[:bootstrap_proto].downcase == 'winrm' xml.WinRM { xml.Listeners { xml.Listener { xml.Protocol 'Http' } } } end } end xml.ConfigurationSet('i:type' => 'NetworkConfigurationSet') { xml.ConfigurationSetType 'NetworkConfiguration' xml.InputEndpoints { if params[:bootstrap_proto].downcase == 'ssh' xml.InputEndpoint { xml.LocalPort '22' xml.Name 'SSH' xml.Port params[:port] xml.Protocol 'TCP' } elsif params[:bootstrap_proto].downcase == 'winrm' and params[:os_type] == 'Windows' xml.InputEndpoint { xml.LocalPort '5985' xml.Name 'WinRM' xml.Port params[:port] xml.Protocol 'TCP' } end if params[:tcp_endpoints] params[:tcp_endpoints].split(',').each do |endpoint| ports = endpoint.split(':') if !(ports.length > 1 && ports[1] == params[:port] || ports.length == 1 && ports[0] == params[:port]) xml.InputEndpoint { xml.LocalPort ports[0] xml.Name 'tcpport_' + ports[0] + '_' + params[:azure_vm_name] if ports.length > 1 xml.Port ports[1] else xml.Port ports[0] end xml.Protocol 'TCP' } else = ports.length > 1 ? "#{ports.join(':')} because this ports are" : "#{ports[0]} because this port is" puts("Skipping tcp-endpoints: #{} already in use by ssh/winrm endpoint in current VM.") end end end if params[:udp_endpoints] params[:udp_endpoints].split(',').each do |endpoint| ports = endpoint.split(':') xml.InputEndpoint { xml.LocalPort ports[0] xml.Name 'udpport_' + ports[0] + '_' + params[:azure_vm_name] if ports.length > 1 xml.Port ports[1] else xml.Port ports[0] end xml.Protocol 'UDP' } end end } if params[:azure_subnet_name] xml.SubnetNames { xml.SubnetName params[:azure_subnet_name] } end } } if params[:azure_availability_set] xml.AvailabilitySetName params[:azure_availability_set] end xml.Label Base64.encode64(params[:azure_vm_name]).strip xml.OSVirtualHardDisk { disk_name = params[:azure_os_disk_name] || "disk_" + SecureRandom.uuid xml.DiskName disk_name xml.MediaLink 'http://' + params[:azure_storage_account] + '.blob.core.windows.net/vhds/' + disk_name + '.vhd' xml.SourceImageName params[:azure_source_image] } xml.RoleSize params[:azure_vm_size] } end builder.doc end |