Module: Azure::CloudServiceManagement::Serialization
- Defined in:
- lib/azure/cloud_service_management/serialization.rb
Class Method Summary collapse
- .add_certificate_to_xml(data) ⇒ Object
- .cloud_services_from_xml(cloud_xml) ⇒ Object
- .cloud_services_to_xml(name, options = {}) ⇒ Object
- .configuration_set_from_xml(configuration_set_xml) ⇒ Object
- .create_deployment_to_xml(name, package_url, service_configuration, options = {}) ⇒ Object
- .deployment_from_xml(cloud_xml) ⇒ Object
- .input_endpoint_from_xml(input_enpoint_xml) ⇒ Object
- .instance_endpoint_from_xml(instance_endpoint_xml) ⇒ Object
- .persistent_vm_downtime_from_xml(persistent_vm_downtime_xml) ⇒ Object
- .role_from_xml(role_xml) ⇒ Object
- .role_instance_from_xml(role_instance_xml) ⇒ Object
- .swap_deployments_to_xml(production_deployment_name, staging_deployment_name) ⇒ Object
- .upgrade_deployment_to_xml(package_url, service_configuration, options = {}) ⇒ Object
- .virtual_ip_from_xml(virtual_ip_xml) ⇒ Object
Class Method Details
.add_certificate_to_xml(data) ⇒ Object
317 318 319 320 321 322 323 324 325 326 |
# File 'lib/azure/cloud_service_management/serialization.rb', line 317 def self.add_certificate_to_xml(data) builder = Nokogiri::XML::Builder.new do |xml| xml.CertificateFile('xmlns' => 'http://schemas.microsoft.com/windowsazure') do xml.Data data xml.CertificateFormat 'pfx' xml.Password nil end end builder.doc.to_xml end |
.cloud_services_from_xml(cloud_xml) ⇒ Object
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 |
# File 'lib/azure/cloud_service_management/serialization.rb', line 267 def self.cloud_services_from_xml(cloud_xml) clouds = [] cloud_services_xml = cloud_xml.css('HostedServices HostedService') cloud_services_xml = cloud_xml.css('HostedService') if \ cloud_services_xml.length == 0 cloud_services_xml.each do |cloud_service_xml| cloud = CloudService.new cloud.url = xml_content(cloud_service_xml, 'Url') cloud.name = xml_content(cloud_service_xml, 'ServiceName') props_xml = cloud_service_xml.css('HostedServiceProperties') cloud.label = Base64.decode64(xml_content(props_xml, 'Label')) cloud.description = xml_content(props_xml, 'Description') location = xml_content(props_xml, 'Location') cloud.location = location unless location.empty? affinity_group = xml_content(props_xml, 'AffinityGroup') cloud.affinity_group = affinity_group unless affinity_group cloud.status = xml_content(props_xml, 'Status') cloud.date_created = xml_content(props_xml, 'DateCreated') cloud.date_modified = xml_content(props_xml, 'DateLastModified') cloud.extended_properties = {} props_xml.css('ExtendedProperties ExtendedProperty').map do |prop| p_name = xml_content(prop, 'Name') p_value = xml_content(prop, 'Value') cloud.extended_properties[p_name] = p_value end cloud.default_winrm_certificate_thumbprint = xml_content( cloud_service_xml, 'DefaultWinRMCertificateThumbprint' ) deployment_xml = cloud_services_xml.css('Deployments Deployment') cloud.deployment_name = xml_content(deployment_xml, 'Name') vms_in_deployment = {} cloud_service_xml.css('Deployments').each do |deployxml| deployment_name = xml_content(deployxml, 'Deployment Name') vms = Azure::VirtualMachineManagement::Serialization.virtual_machines_from_xml( deployxml, cloud.name ) vms_in_deployment[deployment_name.to_sym] = vms if vms end cloud.virtual_machines = vms_in_deployment clouds << cloud end clouds.compact end |
.cloud_services_to_xml(name, options = {}) ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/azure/cloud_service_management/serialization.rb', line 30 def self.cloud_services_to_xml(name, = {}) [:label] = [:label] || name builder = Nokogiri::XML::Builder.new do |xml| xml.CreateHostedService( 'xmlns' => 'http://schemas.microsoft.com/windowsazure' ) do xml.ServiceName(name) xml.Label(Base64.encode64([:label])) xml.Description([:description]) unless\ [:description].nil? || [:description].empty? unless [:affinity_group_name].nil? xml.AffinityGroup([:affinity_group_name]) else xml.Location([:location]) end xml.ExtendedProperties do [:extended_properties].each do |prop_name, prop_value| xml.ExtendedProperty do xml.Name(prop_name) xml.Value(prop_value) end unless (prop_name.nil? || prop_name.empty?)\ || (prop_value.nil? || prop_value.empty?) end end unless [:extended_properties].nil?\ || [:extended_properties].empty? end end builder.doc.to_xml end |
.configuration_set_from_xml(configuration_set_xml) ⇒ Object
244 245 246 247 248 249 250 251 252 253 254 |
# File 'lib/azure/cloud_service_management/serialization.rb', line 244 def self.configuration_set_from_xml(configuration_set_xml) configuration_set = nil unless configuration_set_xml.nil? configuration_set = ConfigurationSet.new configuration_set.configuration_set_type = xml_content(configuration_set_xml, 'ConfigurationSetType') configuration_set.input_endpoints = configuration_set_xml.css("InputEndpoints InputEndpoint").map{ |xml| self.input_endpoint_from_xml(xml) } end return configuration_set end |
.create_deployment_to_xml(name, package_url, service_configuration, options = {}) ⇒ Object
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 |
# File 'lib/azure/cloud_service_management/serialization.rb', line 63 def self.create_deployment_to_xml(name, package_url, service_configuration, ={}) [:label] = [:label] || name [:start_deployment] = [:start_deployment].nil? ? false : [:start_deployment] [:treat_warnings_as_error] = [:treat_warnings_as_error].nil? ? false : [:treat_warnings_as_error] builder = Nokogiri::XML::Builder.new do |xml| xml.CreateDeployment( 'xmlns' => 'http://schemas.microsoft.com/windowsazure' ) do xml.Name(name) xml.PackageUrl(package_url) xml.Label(Base64.strict_encode64([:label])) xml.Configuration(Base64.strict_encode64(service_configuration)) xml.StartDeployment([:start_deployment]) xml.TreatWarningsAsError([:treat_warnings_as_error]) xml.ExtendedProperties do [:extended_properties].each do |prop_name, prop_value| xml.ExtendedProperty do xml.Name(prop_name) xml.Value(prop_value) end unless (prop_name.nil? || prop_name.empty?)\ || (prop_value.nil? || prop_value.empty?) end end unless [:extended_properties].nil?\ || [:extended_properties].empty? end end builder.doc.to_xml end |
.deployment_from_xml(cloud_xml) ⇒ Object
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 164 165 166 167 168 169 170 171 172 173 |
# File 'lib/azure/cloud_service_management/serialization.rb', line 137 def self.deployment_from_xml(cloud_xml) deployment = nil unless cloud_xml.nil? deployment_xml = cloud_xml.css('Deployment') deployment = Deployment.new deployment.name = xml_content(deployment_xml, 'Name') deployment.deployment_slot = xml_content(deployment_xml, 'DeploymentSlot') deployment.private_id = xml_content(deployment_xml, 'PrivateID') deployment.status = xml_content(deployment_xml, 'Status') deployment.label = xml_content(deployment_xml, 'Label') deployment.url = xml_content(deployment_xml, 'Url') deployment.configuration = xml_content(deployment_xml, 'Configuration') deployment.upgrade_domain_count = xml_content(deployment_xml, 'UpgradeDomainCount') deployment.sdk_version = xml_content(deployment_xml, 'SdkVersion') deployment.locked = xml_content(deployment_xml, 'Locked') deployment.rollback_allowed = xml_content(deployment_xml, 'RollbackAllowed') deployment.created_time = xml_content(deployment_xml, 'CreatedTime') deployment.last_modified_time = xml_content(deployment_xml, 'LastModifiedTime') deployment.extended_properties = {} deployment_xml.css('ExtendedProperties ExtendedProperty').map do |prop| p_name = xml_content(prop, 'Name') p_value = xml_content(prop, 'Value') deployment.extended_properties[p_name] = p_value end deployment.role_instances = deployment_xml.css("RoleInstanceList RoleInstance").map{ |xml| self.role_instance_from_xml(xml) } deployment.roles = deployment_xml.css("RoleList Role").map{ |xml| self.role_from_xml(xml) } deployment.persistent_vm_downtime = self.persistent_vm_downtime_from_xml(deployment_xml.css("PersistentVMDowntime")) deployment.virtual_ips = deployment_xml.css("VirtualIPs VirtualIP").map{ |xml| self.virtual_ip_from_xml(xml) } end return deployment end |
.input_endpoint_from_xml(input_enpoint_xml) ⇒ Object
256 257 258 259 260 261 262 263 264 265 |
# File 'lib/azure/cloud_service_management/serialization.rb', line 256 def self.input_endpoint_from_xml(input_enpoint_xml) input_endpoint = nil unless input_enpoint_xml.nil? input_endpoint = InputEndpoint.new input_endpoint.port = xml_content(input_enpoint_xml, 'Port') input_endpoint.protocol = xml_content(input_enpoint_xml, 'Protocol') input_endpoint.vip = xml_content(input_enpoint_xml, 'Vip') end return input_endpoint end |
.instance_endpoint_from_xml(instance_endpoint_xml) ⇒ Object
196 197 198 199 200 201 202 203 204 205 206 207 |
# File 'lib/azure/cloud_service_management/serialization.rb', line 196 def self.instance_endpoint_from_xml(instance_endpoint_xml) instance_endpoint = nil unless instance_endpoint_xml.nil? instance_endpoint = InstanceEndpoint.new instance_endpoint.name = xml_content(instance_endpoint_xml, 'Name') instance_endpoint.vip = xml_content(instance_endpoint_xml, 'Vip') instance_endpoint.public_port = xml_content(instance_endpoint_xml, 'PublicPort') instance_endpoint.local_port = xml_content(instance_endpoint_xml, 'LocalPort') instance_endpoint.protocol = xml_content(instance_endpoint_xml, 'Protocol') end return instance_endpoint end |
.persistent_vm_downtime_from_xml(persistent_vm_downtime_xml) ⇒ Object
220 221 222 223 224 225 226 227 228 229 |
# File 'lib/azure/cloud_service_management/serialization.rb', line 220 def self.persistent_vm_downtime_from_xml(persistent_vm_downtime_xml) persistent_vm_downtime = nil unless persistent_vm_downtime_xml.nil? persistent_vm_downtime = PersistentVmDowntime.new persistent_vm_downtime.start_time = xml_content(persistent_vm_downtime_xml, 'StartTime') persistent_vm_downtime.end_time = xml_content(persistent_vm_downtime_xml, 'EndTime') persistent_vm_downtime.status = xml_content(persistent_vm_downtime_xml, 'Status') end return persistent_vm_downtime end |
.role_from_xml(role_xml) ⇒ Object
231 232 233 234 235 236 237 238 239 240 241 242 |
# File 'lib/azure/cloud_service_management/serialization.rb', line 231 def self.role_from_xml(role_xml) role = nil unless role_xml.nil? role = Role.new role.role_name = xml_content(role_xml, 'RoleName') role.os_version = xml_content(role_xml, 'OsVersion') role.configuration_sets = role_xml.css("ConfigurationSets ConfigurationSet").map{ |xml| self.configuration_set_from_xml(xml) } end return role end |
.role_instance_from_xml(role_instance_xml) ⇒ Object
175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 |
# File 'lib/azure/cloud_service_management/serialization.rb', line 175 def self.role_instance_from_xml(role_instance_xml) role_instance = nil unless role_instance_xml.nil? role_instance = RoleInstance.new role_instance.role_name = xml_content(role_instance_xml, 'RoleName') role_instance.instance_name = xml_content(role_instance_xml, 'InstanceName') role_instance.instance_status = xml_content(role_instance_xml, 'InstanceStatus') role_instance.instance_upgrade_domain = xml_content(role_instance_xml, 'InstanceUpgradeDomain') role_instance.instance_fault_domain = xml_content(role_instance_xml, 'InstanceFaultDomain') role_instance.instance_size = xml_content(role_instance_xml, 'InstanceSize') role_instance.instance_state_details = xml_content(role_instance_xml, 'InstanceStateDetails') role_instance.ip_address = xml_content(role_instance_xml, 'IpAddress') role_instance.power_state = xml_content(role_instance_xml, 'PowerState') role_instance.instance_endpoints = role_instance_xml.css("InstanceEndpoints InstanceEndpoint").map{ |xml| self.instance_endpoint_from_xml(xml) } end return role_instance end |
.swap_deployments_to_xml(production_deployment_name, staging_deployment_name) ⇒ Object
125 126 127 128 129 130 131 132 133 134 135 |
# File 'lib/azure/cloud_service_management/serialization.rb', line 125 def self.swap_deployments_to_xml(production_deployment_name, staging_deployment_name) builder = Nokogiri::XML::Builder.new do |xml| xml.Swap( 'xmlns' => 'http://schemas.microsoft.com/windowsazure' ) do xml.Production(production_deployment_name) xml.SourceDeployment(staging_deployment_name) end end builder.doc.to_xml end |
.upgrade_deployment_to_xml(package_url, service_configuration, options = {}) ⇒ Object
94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 |
# File 'lib/azure/cloud_service_management/serialization.rb', line 94 def self.upgrade_deployment_to_xml(package_url, service_configuration, ={}) [:label] = [:label] [:force] = [:force].nil? ? false : [:force] [:mode] = [:mode].nil? ? "Auto" : [:mode] builder = Nokogiri::XML::Builder.new do |xml| xml.UpgradeDeployment( 'xmlns' => 'http://schemas.microsoft.com/windowsazure' ) do xml.Mode([:mode]) xml.PackageUrl(package_url) xml.Configuration(Base64.strict_encode64(service_configuration)) xml.Label(Base64.strict_encode64([:label])) xml.RoleToUpgrade([:role_to_upgrade]) xml.Force([:force]) xml.ExtendedProperties do [:extended_properties].each do |prop_name, prop_value| xml.ExtendedProperty do xml.Name(prop_name) xml.Value(prop_value) end unless (prop_name.nil? || prop_name.empty?)\ || (prop_value.nil? || prop_value.empty?) end end unless [:extended_properties].nil?\ || [:extended_properties].empty? end end builder.doc.to_xml end |
.virtual_ip_from_xml(virtual_ip_xml) ⇒ Object
209 210 211 212 213 214 215 216 217 218 |
# File 'lib/azure/cloud_service_management/serialization.rb', line 209 def self.virtual_ip_from_xml(virtual_ip_xml) virtual_ip = nil unless virtual_ip_xml.nil? virtual_ip = VirtualIp.new virtual_ip.address = xml_content(virtual_ip_xml, 'Address') virtual_ip.is_dns_programmed = xml_content(virtual_ip_xml, 'IsDnsProgrammed') virtual_ip.name = xml_content(virtual_ip_xml, 'Name') end return virtual_ip end |