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

#list_all(location = @location) ⇒ Object

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

Example:

vmis.list_all('eastus')

Raises:

  • (ArgumentError)


31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/azure/armrest/virtual_machine_image_service.rb', line 31

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

  images = []
  publishers(location).each do |publisher|
    offers(location, publisher.name).each do |offer|
      skus(offer.name, location, publisher.name).each do |sku|
        versions(sku.name, offer.name, location, publisher.name).each do |version|
          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
  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')

Raises:

  • (ArgumentError)


60
61
62
63
64
65
66
67
# File 'lib/azure/armrest/virtual_machine_image_service.rb', line 60

def offers(location = @location, publisher = @publisher)
  raise ArgumentError, "No location specified" unless location
  raise ArgumentError, "No publisher specified" unless 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)


75
76
77
78
79
80
81
# File 'lib/azure/armrest/virtual_machine_image_service.rb', line 75

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')

Raises:

  • (ArgumentError)


90
91
92
93
94
95
96
97
98
99
100
# File 'lib/azure/armrest/virtual_machine_image_service.rb', line 90

def skus(offer, location = @location, publisher = @publisher)
  raise ArgumentError, "No location specified" unless location
  raise ArgumentError, "No publisher specified" unless 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"]

Raises:

  • (ArgumentError)


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

def versions(sku, offer, location = @location, publisher = @publisher)
  raise ArgumentError, "No location specified" unless location
  raise ArgumentError, "No publisher specified" unless 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