Module: Azure::SqlDatabaseManagement::Serialization
- Extended by:
- Core::Utility
- Defined in:
- lib/azure/sql_database_management/serialization.rb
Class Method Summary collapse
-
.database_firewall_from_xml(response_xml) ⇒ Array<Azure::SqlDatabaseManagement::FirewallRule>
Create a list of firewall hashes from xml.
-
.firewall_rule_to_xml(rule) ⇒ String
Serialize a firewall rule to xml.
- .reset_password_to_xml(password) ⇒ Object
- .server_name_from_xml(response_xml, login, location, version) ⇒ Object
- .server_to_xml(login, password, location, version = 12.0) ⇒ Object
- .servers_from_xml(wrapper_XML) ⇒ Object
Class Method Details
.database_firewall_from_xml(response_xml) ⇒ Array<Azure::SqlDatabaseManagement::FirewallRule>
Create a list of firewall hashes from xml
88 89 90 91 92 93 94 95 96 97 98 99 100 |
# 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) ⇒ String
Serialize a firewall rule to xml
74 75 76 77 78 79 80 81 82 83 |
# 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) ⇒ Object
64 65 66 67 68 69 |
# 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) ⇒ Object
49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
# 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) ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 |
# 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) ⇒ Object
35 36 37 38 39 40 41 42 43 44 45 46 47 |
# 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 |