Module: Azure::SqlDatabaseManagement::Serialization

Extended by:
Core::Utility
Defined in:
lib/azure/sql_database_management/serialization.rb

Class Method Summary collapse

Methods included from Core::Utility

enable_winrm?, export_der, export_fingerprint, get_certificate, initialize_external_logger, locate_file, random_string, xml_content

Class Method Details

.database_firewall_from_xml(response_xml) ⇒ Object



79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
# File 'lib/azure/sql_database_management/serialization.rb', line 79

def self.database_firewall_from_xml(response_xml)
  firewalls = []
  if Azure.config.sql_database_authentication_mode == :sql_server
    database_firewallXML = response_xml.css('FirewallRules  FirewallRule')
    database_firewallXML.each do |firewall_xml|
      firewall = {
        :rule => xml_content(firewall_xml, 'Name'),
        :start_ip_address => xml_content(firewall_xml, 'StartIpAddress'),
        :end_ip_address => xml_content(firewall_xml, 'EndIpAddress')
      }
      firewalls << firewall
    end
  else
    service_resources = response_xml.css(
      'ServiceResources ServiceResource'
    )
    service_resources.each do |resource|
      type = xml_content(resource, 'Type')
      if type == 'Microsoft.SqlAzure.FirewallRule'
        firewall = {
          rule: xml_content(resource, 'Name'),
          start_ip_address: xml_content(resource, 'StartIPAddress'),
          end_ip_address: xml_content(resource, 'EndIPAddress')
        }
        firewalls << firewall
      end
    end
  end
  firewalls.compact
end

.database_to_xml(login, password, location) ⇒ Object



22
23
24
25
26
27
28
29
30
31
# File 'lib/azure/sql_database_management/serialization.rb', line 22

def self.database_to_xml(, password, location)
  builder = Nokogiri::XML::Builder.new do |xml|
    xml.Server('xmlns'=>'http://schemas.microsoft.com/sqlazure/2010/12/') {
      xml.AdministratorLogin 
      xml.AdministratorLoginPassword password
      xml.Location location
    }
  end
  builder.doc.to_xml
end

.databases_from_xml(databasesXML) ⇒ Object



33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/azure/sql_database_management/serialization.rb', line 33

def self.databases_from_xml(databasesXML)
  databases = []
  databases_servicesXML = databasesXML.css('Servers  Server')
  databases_servicesXML.each do |database_xml|
    database = SqlDatabase.new
    database.name = xml_content(database_xml, 'Name')
    database. = xml_content(database_xml, 'AdministratorLogin')
    database.location = xml_content(database_xml, 'Location')
    database.feature_name = xml_content(database_xml, 'Features Feature Name')
    database.feature_value = xml_content(database_xml, 'Features Feature Value')
    databases << database
  end
  databases.compact
end

.firewall_rule_to_xml(options) ⇒ Object



64
65
66
67
68
69
70
71
72
73
74
75
76
77
# File 'lib/azure/sql_database_management/serialization.rb', line 64

def self.firewall_rule_to_xml(options)
  # Need to revisit and implement RDFE request XML.
  # Currently Azure is throwing Internal Server Error when executing the
  # API
  builder = Nokogiri::XML::Builder.new do |xml|
    xml.FirewallRule('xmlns'=>'http://schemas.microsoft.com/sqlazure/2010/12/',
      'xmlns:xsi'=>'http://www.w3.org/2001/XMLSchema-instance',
      'xsi:schemaLocation'=>'http://schemas.microsoft.com/sqlazure/2010/12/ FirewallRule.xsd') {
      xml.StartIpAddress options[:start_ip_address]
      xml.EndIpAddress options[:end_ip_address]
    }
  end
  builder.doc.to_xml
end

.reset_password_to_xml(password) ⇒ Object



57
58
59
60
61
62
# File 'lib/azure/sql_database_management/serialization.rb', line 57

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) ⇒ Object



48
49
50
51
52
53
54
55
# File 'lib/azure/sql_database_management/serialization.rb', line 48

def self.server_name_from_xml(response_xml, , location)
  server_name = xml_content(response_xml, 'ServerName')
  SqlDatabase.new do |db|
    db.name = server_name
    db.location = location
    db. = 
  end
end