Module: Azure::StorageManagement::Serialization
- Extended by:
- Core::Utility
- Defined in:
- lib/azure/storage_management/serialization.rb
Overview
Storage management serialization module is responsible for converting the objects to XML and vice versa.
Class Method Summary collapse
- .add_options_to_xml(xml, options = {}) ⇒ Object
- .regenerate_storage_account_keys_to_xml(key_type) ⇒ Object
- .storage_account_keys_from_xml(storage_xml) ⇒ Object
- .storage_services_from_xml(storage_xml) ⇒ Object
- .storage_services_to_xml(name, options = {}) ⇒ Object
- .storage_update_to_xml(options) ⇒ Object
Class Method Details
.add_options_to_xml(xml, options = {}) ⇒ Object
165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 |
# File 'lib/azure/storage_management/serialization.rb', line 165 def self.(xml, = {}) gre = [:geo_replication_enabled] xml.GeoReplicationEnabled( gre ) unless gre.nil? || !(gre.is_a?(TrueClass) || gre.is_a?(FalseClass)) xml.ExtendedProperties do [:extended_properties].each do |name, value| xml.ExtendedProperty do xml.Name name xml.Value value end unless (name.to_s.empty?) || (value.to_s.empty?) end end unless [:extended_properties].to_s.empty? xml.AccountType [:account_type] if [:account_type] end |
.regenerate_storage_account_keys_to_xml(key_type) ⇒ Object
192 193 194 195 196 197 198 199 200 201 |
# File 'lib/azure/storage_management/serialization.rb', line 192 def self.regenerate_storage_account_keys_to_xml(key_type) builder = Nokogiri::XML::Builder.new do |xml| xml.RegenerateKeys( 'xmlns' => 'http://schemas.microsoft.com/windowsazure' ) do xml.KeyType(key_type) end end builder.doc.to_xml end |
.storage_account_keys_from_xml(storage_xml) ⇒ Object
181 182 183 184 185 186 187 188 189 190 |
# File 'lib/azure/storage_management/serialization.rb', line 181 def self.storage_account_keys_from_xml(storage_xml) storage_xml.css('StorageService') storage_service_xml = storage_xml.css('StorageService').first service_key_xml = storage_service_xml.css('StorageServiceKeys').first storage_account_keys = StorageAccountKeys.new storage_account_keys.url = xml_content(storage_service_xml, 'Url') storage_account_keys.primary_key = xml_content(service_key_xml, 'Primary') storage_account_keys.secondary_key = xml_content(service_key_xml, 'Secondary') storage_account_keys end |
.storage_services_from_xml(storage_xml) ⇒ Object
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 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 109 110 111 112 113 |
# File 'lib/azure/storage_management/serialization.rb', line 45 def self.storage_services_from_xml(storage_xml) storage_accounts = [] storage_services_xml = storage_xml.css('StorageService') storage_services_xml.each do |storage_service_xml| storage_account = StorageAccount.new storage_account.url = xml_content(storage_service_xml, 'Url') storage_account.name = xml_content( storage_service_xml, 'ServiceName' ) storage_service_properties = storage_service_xml.css( 'StorageServiceProperties' ) storage_account.description = xml_content( storage_service_properties, 'Description' ) storage_account.affinity_group = xml_content( storage_service_properties, 'AffinityGroup' ) storage_account.location = xml_content( storage_service_properties, 'Location' ) storage_account.label = Base64.decode64( xml_content(storage_service_properties, 'Label') ) storage_account.status = xml_content( storage_service_properties, 'Status' ) storage_account.endpoints = storage_service_properties.css( 'Endpoints Endpoint' ).map { |endpoint| endpoint.content } storage_account.geo_replication_enabled = xml_content( storage_service_properties, 'GeoReplicationEnabled' ) storage_account.account_type = xml_content( storage_service_properties, 'AccountType' ) storage_account.geo_primary_region = xml_content( storage_service_properties, 'GeoPrimaryRegion' ) storage_account.status_of_primary = xml_content( storage_service_properties, 'StatusOfPrimary' ) storage_account.last_geo_failover_time = xml_content( storage_service_properties, 'LastGeoFailoverTime' ) storage_account.geo_secondary_region = xml_content( storage_service_properties, 'GeoSecondaryRegion' ) storage_account.status_of_secondary = xml_content( storage_service_properties, 'StatusOfSecondary' ) storage_account.creation_time = xml_content( storage_service_properties, 'CreationTime' ) storage_account.extended_properties = storage_service_xml.css( 'ExtendedProperties ExtendedProperty' ).map do |prop| { name: xml_content(prop, 'Name'), value: xml_content(prop, 'Value') } end storage_accounts << storage_account end storage_accounts.compact end |
.storage_services_to_xml(name, options = {}) ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/azure/storage_management/serialization.rb', line 24 def self.storage_services_to_xml(name, = {}) builder = Nokogiri::XML::Builder.new do |xml| xml.CreateStorageServiceInput( 'xmlns' => 'http://schemas.microsoft.com/windowsazure' ) do xml.ServiceName(name) label = [:label] || name xml.Label(Base64.encode64(label)) xml.Description [:description]\ || 'Explicitly created storage service' unless [:affinity_group_name].nil? xml.AffinityGroup [:affinity_group_name] else xml.Location [:location] end (xml, ) end end builder.doc.to_xml end |
.storage_update_to_xml(options) ⇒ Object
115 116 117 118 119 120 121 122 123 124 125 126 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 160 161 162 163 |
# File 'lib/azure/storage_management/serialization.rb', line 115 def self.storage_update_to_xml() # Cannot update if options is nil or empty fail 'No options specified' if .empty? # Either one of Label, or Description is required. if ([:label].nil? || [:label].empty?) && ([:description].nil? || [:description].empty?) fail 'Either one of Label or Description'\ ' has to be provided. Both cannot be empty' end # The input param may not be nil or empty, but the values inside may # be. Check if atleast one value exists before proceeding. is_empty = true .each do |option, value| case option when :description, :label is_empty = value.nil? || value.empty? when :geo_replication_enabled is_empty = !(value.is_a?(TrueClass) || value.is_a?(FalseClass)) when :extended_properties value.each do |p, v| is_empty = ((p.nil? || p.empty?) || (v.nil? || v.empty?)) break unless is_empty end end break unless is_empty end # Raise a RuntimeError if no options were provided fail 'No Options Specified' if is_empty builder = Nokogiri::XML::Builder.new do |xml| xml.UpdateStorageServiceInput( 'xmlns' => 'http://schemas.microsoft.com/windowsazure' ) do # Check if label is nil. Use description only if label is nil if [:label].nil? || [:label].empty? desc = [:description] xml.Description(desc) unless desc.nil? || desc.empty? else label = Base64.encode64([:label]) xml.Label(label) unless label.nil? || label.empty? end (xml, ) end end builder.to_xml end |