Module: Azure::BaseManagement::Serialization

Extended by:
Core::Utility
Defined in:
lib/azure/base_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

.affinity_group_from_xml(affinity_xml) ⇒ Object



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
114
115
116
117
118
119
120
# File 'lib/azure/base_management/serialization.rb', line 72

def self.affinity_group_from_xml(affinity_xml)
  hosted_services_xml = affinity_xml.css(
    'AffinityGroup HostedServices HostedService'
  )

  storage_services_xml = affinity_xml.css(
    'AffinityGroup StorageServices StorageService'
  )

  capability_xml = affinity_xml.css(
    'AffinityGroup Capabilities Capability'
  )

  AffinityGroup.new do |affinity_group|
    affinity_group.name = xml_content(
      affinity_xml,
      'AffinityGroup Name'
    )
    affinity_group.label = Base64.decode64(
      xml_content(
        affinity_xml,
        'AffinityGroup Label'
      )
    )
    affinity_group.description = xml_content(
      affinity_xml,
      'AffinityGroup Description'
    )
    affinity_group.location = xml_content(
      affinity_xml,
      'AffinityGroup Location'
    )
    affinity_group.hosted_services = []
    hosted_services_xml.each do |hosted_service_xml|
      affinity_group.hosted_services << {
        url: xml_content(hosted_service_xml, 'Url'),
        service_name: xml_content(hosted_service_xml, 'ServiceName')
      }
    end
    affinity_group.storage_services = []
    storage_services_xml.each do |storage_service_xml|
      affinity_group.storage_services << {
        url: xml_content(storage_service_xml, 'Url'),
        service_name: xml_content(storage_service_xml, 'ServiceName')
      }
    end
    affinity_group.capability = capability_xml.map { |x| x.content }
  end
end

.affinity_group_to_xml(name, location, label, options = {}) ⇒ Object



38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/azure/base_management/serialization.rb', line 38

def self.affinity_group_to_xml(name, location, label, options = {})
  builder = Nokogiri::XML::Builder.new do |xml|
    xml.CreateAffinityGroup(
      'xmlns' => 'http://schemas.microsoft.com/windowsazure'
    ) do
      xml.Name name
      xml.Label Base64.encode64(label).strip
      xml.Description options[:description]
      xml.Location location
    end
  end
  builder.doc.to_xml
end

.affinity_groups_from_xml(affinity_xml) ⇒ Object



52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# File 'lib/azure/base_management/serialization.rb', line 52

def self.affinity_groups_from_xml(affinity_xml)
  affinity_groups = []
  affinity_group_services_xml = affinity_xml.css(
    'AffinityGroups  AffinityGroup'
  )

  affinity_group_services_xml.each do |ag_xml|
    affinity_group = AffinityGroup.new
    affinity_group.name = xml_content(ag_xml, 'Name')
    affinity_group.label = Base64.decode64(xml_content(ag_xml, 'Label'))
    affinity_group.description = xml_content(ag_xml, 'Description')
    affinity_group.location = xml_content(ag_xml, 'Location')

    capabilities = ag_xml.css('Capabilities Capability')
    affinity_group.capability = capabilities.map { |x|  x.content }
    affinity_groups << affinity_group
  end
  affinity_groups.compact
end

.locations_from_xml(locationXML) ⇒ Object



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/azure/base_management/serialization.rb', line 20

def self.locations_from_xml(locationXML)
  location_objs = []
  xml = locationXML.css('Locations Location')
  xml.each do |meta_node|
    loc = Location.new
    loc.name = xml_content(meta_node, 'Name')
    available_services = meta_node.css('AvailableServices').children
    loc.available_services = available_services.to_ary.join(', ')
    role_sizes = []
    meta_node.css('VirtualMachinesRoleSizes RoleSize').each do | role_size_node |
      role_sizes << role_size_node.text
    end
    loc.role_sizes = role_sizes
    location_objs << loc
  end
  location_objs
end

.resource_to_xml(label, options = {}) ⇒ Object



122
123
124
125
126
127
128
129
130
131
132
# File 'lib/azure/base_management/serialization.rb', line 122

def self.resource_to_xml(label, options = {})
  builder = Nokogiri::XML::Builder.new do |xml|
    xml.UpdateAffinityGroup(
      'xmlns' => 'http://schemas.microsoft.com/windowsazure'
    ) do
      xml.Label Base64.encode64(label).strip
      xml.Description options[:description] if options[:description]
    end
  end
  builder.doc.to_xml
end