Class: Azure::Armrest::VirtualMachineImageService

Inherits:
ArmrestService show all
Defined in:
lib/azure/armrest/virtual_machine_image_service.rb

Overview

Base class for managing virtual machine images

Instance Attribute Summary collapse

Attributes inherited from ArmrestService

#api_version, #armrest_configuration, #base_url, #provider, #service_name

Instance Method Summary collapse

Methods inherited from ArmrestService

configure, #get_provider, #get_subscription, #list_locations, #list_resource_groups, #list_resources, #list_subscriptions, #locations, #poll, #tags, #tenants, #wait

Constructor Details

#initialize(configuration, options = {}) ⇒ VirtualMachineImageService

Create and return a new VirtualMachineImageService instance.

This subclass accepts the additional :location, :provider, and :publisher options as well.



18
19
20
21
22
23
# File 'lib/azure/armrest/virtual_machine_image_service.rb', line 18

def initialize(configuration, options = {})
  super(configuration, 'locations/publishers', 'Microsoft.Compute', options)

  @location  = options[:location]
  @publisher = options[:publisher]
end

Instance Attribute Details

#locationObject

The location used in requests when gathering VM image information.



8
9
10
# File 'lib/azure/armrest/virtual_machine_image_service.rb', line 8

def location
  @location
end

#publisherObject

The publisher used in requests when gathering VM image information.



11
12
13
# File 'lib/azure/armrest/virtual_machine_image_service.rb', line 11

def publisher
  @publisher
end

Instance Method Details

#extension(type, version, location = @location, publisher = @publisher) ⇒ Object

Retrieve information about a specific extension image for type and version.

Example:

vmis.extension('LinuxDiagnostic', '2.3.9029', 'westus2', 'Microsoft.OSTCExtensions')


148
149
150
151
152
153
154
155
156
157
158
# File 'lib/azure/armrest/virtual_machine_image_service.rb', line 148

def extension(type, version, location = @location, publisher = @publisher)
  check_for_location_and_publisher(location, publisher)

  url = build_url(
    location, 'publishers', publisher, 'artifacttypes',
    'vmextension', 'types', type, 'versions', version
  )

  response = rest_get(url)
  Azure::Armrest::ExtensionType.new(response)
end

#extension_type_versions(type, location = @location, publisher = @publisher) ⇒ Object

Return a list of versions for the given type in the provided location and publisher.

Example:

vmis.extension_type_versions('LinuxDiagnostic', 'eastus', 'Microsoft.OSTCExtensions')


182
183
184
185
186
187
188
189
# File 'lib/azure/armrest/virtual_machine_image_service.rb', line 182

def extension_type_versions(type, location = @location, publisher = @publisher)
  check_for_location_and_publisher(location, publisher)

  url = build_url(location, 'publishers', publisher, 'artifacttypes', 'vmextension', 'types', type, 'versions')

  response = rest_get(url)
  JSON.parse(response).map { |hash| Azure::Armrest::ExtensionType.new(hash) }
end

#extension_types(location = @location, publisher = @publisher) ⇒ Object

Return a list of extension types for the given location and publisher.

Example:

vmis.extension_types('westus', 'Microsoft.OSTCExtensions')


166
167
168
169
170
171
172
173
# File 'lib/azure/armrest/virtual_machine_image_service.rb', line 166

def extension_types(location = @location, publisher = @publisher)
  check_for_location_and_publisher(location, publisher)

  url = build_url(location, 'publishers', publisher, 'artifacttypes', 'vmextension', 'types')

  response = rest_get(url)
  JSON.parse(response).map { |hash| Azure::Armrest::ExtensionType.new(hash) }
end

#get(offer, sku, version, location = @location, publisher = @publisher) ⇒ Object

Return information about a specific offer/sku/version for the given publisher within location.



28
29
30
31
32
33
34
35
36
37
38
# File 'lib/azure/armrest/virtual_machine_image_service.rb', line 28

def get(offer, sku, version, location = @location, publisher = @publisher)
  check_for_location_and_publisher(location, publisher)

  url = build_url(
    location, 'publishers', publisher, 'artifacttypes',
    'vmimage', 'offers', offer, 'skus', sku, 'versions', version
  )

  response = rest_get(url)
  Azure::Armrest::VirtualMachineImage.new(response)
end

#list_all(location = @location) ⇒ Object

Return a list of all VM image offers from the given location.

Example:

vmis.list_all('eastus')

Raises:

  • (ArgumentError)


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
# File 'lib/azure/armrest/virtual_machine_image_service.rb', line 46

def list_all(location = @location)
  raise ArgumentError, "No location specified" unless location

  mutex  = Mutex.new
  images = []
  max    = configuration.max_threads

  Parallel.each(publishers(location), :in_threads => max) do |publisher|
    Parallel.each(offers(location, publisher.name), :in_threads => max) do |offer|
      Parallel.each(skus(offer.name, location, publisher.name), :in_threads => max) do |sku|
        Parallel.each(versions(sku.name, offer.name, location, publisher.name), :in_threads => max) do |version|
          mutex.synchronize do
            images << Azure::Armrest::VirtualMachineImage.new(
              :location  => version.location,
              :publisher => publisher.name,
              :offer     => offer.name,
              :sku       => sku.name,
              :version   => version.name,
              :id        => "#{publisher.name}:#{offer.name}:#{sku.name}:#{version.name}"
            )
          end
        end
      end
    end
  end

  images
end

#offers(location = @location, publisher = @publisher) ⇒ Object

Return a list of VM image offers from the given publisher and location.

Example:

vmis.offers('eastus', 'Canonical')


81
82
83
84
85
86
87
# File 'lib/azure/armrest/virtual_machine_image_service.rb', line 81

def offers(location = @location, publisher = @publisher)
  check_for_location_and_publisher(location, publisher)

  url = build_url(location, 'publishers', publisher, 'artifacttypes', 'vmimage', 'offers')

  JSON.parse(rest_get(url)).map { |hash| Azure::Armrest::Offer.new(hash) }
end

#publishers(location = @location) ⇒ Object

Return a list of VM image publishers for the given location.

Example:

vmis.publishers('eastus')

Raises:

  • (ArgumentError)


95
96
97
98
99
100
101
# File 'lib/azure/armrest/virtual_machine_image_service.rb', line 95

def publishers(location = @location)
  raise ArgumentError, "No location specified" unless location

  url = build_url(location, 'publishers')

  JSON.parse(rest_get(url)).map { |hash| Azure::Armrest::Publisher.new(hash) }
end

#skus(offer, location = @location, publisher = @publisher) ⇒ Object

Return a list of VM image skus for the given offer, location, and publisher.

Example:

vmis.skus('UbuntuServer', 'eastus', 'Canonical')


110
111
112
113
114
115
116
117
118
119
# File 'lib/azure/armrest/virtual_machine_image_service.rb', line 110

def skus(offer, location = @location, publisher = @publisher)
  check_for_location_and_publisher(location, publisher)

  url = build_url(
    location, 'publishers', publisher, 'artifacttypes',
    'vmimage', 'offers', offer, 'skus'
  )

  JSON.parse(rest_get(url)).map { |hash| Azure::Armrest::Sku.new(hash) }
end

#versions(sku, offer, location = @location, publisher = @publisher) ⇒ Object

Return a list of VM image versions for the given sku, offer, location and publisher.

Example:

vmis.versions('15.10', 'UbuntuServer', 'eastus', 'Canonical').map(&:name)

# sample output
=> ["15.10.201511111", "15.10.201511161", "15.10.201512030"]


131
132
133
134
135
136
137
138
139
140
# File 'lib/azure/armrest/virtual_machine_image_service.rb', line 131

def versions(sku, offer, location = @location, publisher = @publisher)
  check_for_location_and_publisher(location, publisher)

  url = build_url(
    location, 'publishers', publisher, 'artifacttypes',
    'vmimage', 'offers', offer, 'skus', sku, 'versions'
  )

  JSON.parse(rest_get(url)).map { |hash| Azure::Armrest::ImageVersion.new(hash) }
end