Class: Azure::Images

Inherits:
Object
  • Object
show all
Defined in:
lib/azure/service_management/image.rb

Instance Method Summary collapse

Constructor Details

#initialize(connection) ⇒ Images

Returns a new instance of Images.



21
22
23
# File 'lib/azure/service_management/image.rb', line 21

def initialize(connection)
  @connection = connection
end

Instance Method Details

#allObject



34
35
36
# File 'lib/azure/service_management/image.rb', line 34

def all
  load.values
end

#exists?(name) ⇒ Boolean

Returns:

  • (Boolean)


70
71
72
# File 'lib/azure/service_management/image.rb', line 70

def exists?(name)
  all.detect { |img| img.name == name } ? true : false
end

#find(name) ⇒ Object



74
75
76
# File 'lib/azure/service_management/image.rb', line 74

def find(name)
  load[name]
end

#get_images(img_type) ⇒ Object

img_type = OSImages or VMImage



39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/azure/service_management/image.rb', line 39

def get_images(img_type)
  images = {}

  if img_type == "OSImage"
    response = @connection.query_azure("images")
  elsif img_type == "VMImage"
    response = @connection.query_azure("vmimages")
  end

  unless response.to_s.empty?
    osimages = response.css(img_type)

    osimages.each do |image|
      item = Image.new(image)
      images[item.name] = item
    end
  end

  images
end

#is_os_image(image_name) ⇒ Object



60
61
62
63
# File 'lib/azure/service_management/image.rb', line 60

def is_os_image(image_name)
  os_images = get_images("OSImage").values
  os_images.detect { |img| img.name == image_name } ? true : false
end

#is_vm_image(image_name) ⇒ Object



65
66
67
68
# File 'lib/azure/service_management/image.rb', line 65

def is_vm_image(image_name)
  vm_images = get_images("VMImage").values
  vm_images.detect { |img| img.name == image_name } ? true : false
end

#loadObject



25
26
27
28
29
30
31
32
# File 'lib/azure/service_management/image.rb', line 25

def load
  @images ||= begin
    osimages = get_images("OSImage")   # get OSImages
    vmimages = get_images("VMImage")   # get VMImages

    all_images = osimages.merge(vmimages)
  end
end