Class: ForemanAzure::Azure

Inherits:
ComputeResource
  • Object
show all
Defined in:
app/models/foreman_azure/azure.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.model_nameObject



22
23
24
# File 'app/models/foreman_azure/azure.rb', line 22

def self.model_name
  ComputeResource.model_name
end

Instance Method Details

#available_imagesObject



35
36
37
# File 'app/models/foreman_azure/azure.rb', line 35

def available_images
  client.images
end

#capabilitiesObject



18
19
20
# File 'app/models/foreman_azure/azure.rb', line 18

def capabilities
  [:build, :image]
end

#create_vm(args = {}) ⇒ Object



47
48
49
50
51
52
53
54
55
56
# File 'app/models/foreman_azure/azure.rb', line 47

def create_vm(args = {})
  args.delete_if { |_key, value| value.blank? }
  args[:hostname] = args[:name]
  args[:vm_name] = args[:name].split('.').first
  args[:cloud_service_name] ||= args[:vm_name]
  args[:image] = args[:image_id]
  args[:vm_user] = Image.unscoped.find_by_uuid(args[:image_id]).username
  args[:private_key_file] = url
  super(args)
end

#find_vm_by_uuid(uuid) ⇒ Object

Azure does not have an UUID for each vm. It has a unique pair ‘cloud_service_name’ and ‘vm_name’. We will need to override all destroy_vm, start_vm, stop_vm… to accept two parameters.

fog-azure should probably build this UUID concept instead, but until then, we can just do our best to match it



65
66
67
# File 'app/models/foreman_azure/azure.rb', line 65

def find_vm_by_uuid(uuid)
  client.servers.find { |vm| vm.vm_name == uuid }
end

#image_locations(image_id) ⇒ Object



43
44
45
# File 'app/models/foreman_azure/azure.rb', line 43

def image_locations(image_id)
  client.images.get(image_id).locations.split(';')
end

#provided_attributesObject



39
40
41
# File 'app/models/foreman_azure/azure.rb', line 39

def provided_attributes
  super.merge(:ip => :public_ip_address)
end

#provider_friendly_nameObject



26
27
28
# File 'app/models/foreman_azure/azure.rb', line 26

def provider_friendly_name
  'Azure'
end

#test_connection(options = {}) ⇒ Object



30
31
32
33
# File 'app/models/foreman_azure/azure.rb', line 30

def test_connection(options = {})
  client.storage_accounts # Make a simple 'ping' request
  super(options)
end

#to_labelObject



14
15
16
# File 'app/models/foreman_azure/azure.rb', line 14

def to_label
  "#{name} (#{provider_friendly_name})"
end