module Azure::SqlDatabaseManagement::Serialization

Public Class Methods

database_firewall_from_xml(response_xml) click to toggle source

Create a list of firewall hashes from xml @param response_xml The xml containing the list of ServiceResources (firewall rules) @return [Array<Azure::SqlDatabaseManagement::FirewallRule>]

# File lib/azure/sql_database_management/serialization.rb, line 88
def self.database_firewall_from_xml(response_xml)
  service_resources = response_xml.css(
      'ServiceResources ServiceResource'
  )
  service_resources.map do |resource|
    FirewallRule.new do |rule|
      rule.name = xml_content(resource, 'Name')
      rule.type = xml_content(resource, 'Type')
      rule.start_ip_address = xml_content(resource, 'StartIPAddress')
      rule.end_ip_address = xml_content(resource, 'EndIPAddress')
    end
  end
end
firewall_rule_to_xml(rule) click to toggle source

Serialize a firewall rule to xml @param rule [Azure::SqlDatabaseManagement::FirewallRule] The firewall rule to serialize @return [String] xml document contain the firewall rule

# File lib/azure/sql_database_management/serialization.rb, line 74
def self.firewall_rule_to_xml(rule)
  builder = Nokogiri::XML::Builder.new do |xml|
    xml.ServiceResource('xmlns' => 'http://schemas.microsoft.com/windowsazure') {
      xml.Name rule.name
      xml.StartIPAddress rule.start_ip_address
      xml.EndIPAddress rule.end_ip_address
    }
  end
  builder.doc.to_xml
end
reset_password_to_xml(password) click to toggle source
# File lib/azure/sql_database_management/serialization.rb, line 64
def self.reset_password_to_xml(password)
  builder = Nokogiri::XML::Builder.new do |xml|
    xml.AdministratorLoginPassword(password, {'xmlns' => 'http://schemas.microsoft.com/sqlazure/2010/12/'})
  end
  builder.doc.to_xml
end
server_name_from_xml(response_xml, login, location, version) click to toggle source
# File lib/azure/sql_database_management/serialization.rb, line 49
def self.server_name_from_xml(response_xml, login, location, version)
  if response_xml.css('Error').css('Message').to_s != ''
    raise Azure::SqlDatabaseManagement::Error.new(response_xml.css('Error').css('Message').to_s)
  end

  server_name = xml_content(response_xml, 'ServerName')
  SqlServer.new do |db|
    db.name = server_name
    db.location = location
    db.administrator_login = login
    db.version = version
    db.fully_qualified_domain_name = response_xml.css('ServerName').first['FullyQualifiedDomainName']
  end
end
server_to_xml(login, password, location, version = 12.0) click to toggle source
# File lib/azure/sql_database_management/serialization.rb, line 23
def self.server_to_xml(login, password, location, version = 12.0)
  builder = Nokogiri::XML::Builder.new do |xml|
    xml.Server('xmlns' => 'http://schemas.microsoft.com/sqlazure/2010/12/') {
      xml.AdministratorLogin login
      xml.AdministratorLoginPassword password
      xml.Location location
      xml.Version version
    }
  end
  builder.doc.to_xml
end
servers_from_xml(wrapper_XML) click to toggle source
# File lib/azure/sql_database_management/serialization.rb, line 35
def self.servers_from_xml(wrapper_XML)
  servers_XML = wrapper_XML.css('Servers  Server')
  servers_XML.map do |server_xml|
    server = SqlServer.new
    server.name = xml_content(server_xml, 'Name')
    server.administrator_login = xml_content(server_xml, 'AdministratorLogin')
    server.location = xml_content(server_xml, 'Location')
    server.version = xml_content(server_xml, 'Version')
    server.state = xml_content(server_xml, 'State')
    server.fully_qualified_domain_name = xml_content(server_xml, 'FullyQualifiedDomainName')
    server
  end
end