Class: ForemanDigitalocean::Digitalocean

Inherits:
ComputeResource
  • Object
show all
Defined in:
app/models/foreman_digitalocean/digitalocean.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.model_nameObject



23
24
25
# File 'app/models/foreman_digitalocean/digitalocean.rb', line 23

def self.model_name
  ComputeResource.model_name
end

.provider_friendly_nameObject



75
76
77
# File 'app/models/foreman_digitalocean/digitalocean.rb', line 75

def self.provider_friendly_name
  "DigitalOcean"
end

Instance Method Details

#associated_host(vm) ⇒ Object



79
80
81
# File 'app/models/foreman_digitalocean/digitalocean.rb', line 79

def associated_host(vm)
  associate_by("ip", [vm.public_ip_address])
end

#available_imagesObject



46
47
48
# File 'app/models/foreman_digitalocean/digitalocean.rb', line 46

def available_images
  client.images
end

#capabilitiesObject



27
28
29
# File 'app/models/foreman_digitalocean/digitalocean.rb', line 27

def capabilities
  [:image]
end

#create_vm(args = {}) ⇒ Object



37
38
39
40
41
42
43
44
# File 'app/models/foreman_digitalocean/digitalocean.rb', line 37

def create_vm(args = {})
  args["ssh_keys"] = [ssh_key] if ssh_key
  args['image'] = args['image_id']
  super(args)
rescue Fog::Errors::Error => e
  logger.error "Unhandled DigitalOcean error: #{e.class}:#{e.message}\n " + e.backtrace.join("\n ")
  raise e
end

#default_region_nameObject



87
88
89
90
91
# File 'app/models/foreman_digitalocean/digitalocean.rb', line 87

def default_region_name
  @default_region_name ||= client.regions[region.to_i].try(:name)
rescue Excon::Errors::Unauthorized => e
  errors[:base] << e.response.body
end

#destroy_vm(uuid) ⇒ Object



64
65
66
67
68
# File 'app/models/foreman_digitalocean/digitalocean.rb', line 64

def destroy_vm(uuid)
  vm = find_vm_by_uuid(uuid)
  vm.delete if vm.present?
  true
end

#find_vm_by_uuid(uuid) ⇒ Object



31
32
33
34
35
# File 'app/models/foreman_digitalocean/digitalocean.rb', line 31

def find_vm_by_uuid(uuid)
  client.servers.get(uuid)
rescue Fog::Compute::DigitalOcean::Error
  raise(ActiveRecord::RecordNotFound)
end

#provided_attributesObject



19
20
21
# File 'app/models/foreman_digitalocean/digitalocean.rb', line 19

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

#regionsObject



50
51
52
53
# File 'app/models/foreman_digitalocean/digitalocean.rb', line 50

def regions
  return [] if api_key.blank?
  client.regions
end

#test_connection(options = {}) ⇒ Object



55
56
57
58
59
60
61
62
# File 'app/models/foreman_digitalocean/digitalocean.rb', line 55

def test_connection(options = {})
  super
  errors[:password].empty? && regions.count
rescue Excon::Errors::Unauthorized => e
  errors[:base] << e.response.body
rescue Fog::Errors::Error => e
  errors[:base] << e.message
end

#to_labelObject



15
16
17
# File 'app/models/foreman_digitalocean/digitalocean.rb', line 15

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

#update_required?Boolean

not supporting update at the moment

Returns:

  • (Boolean)


71
72
73
# File 'app/models/foreman_digitalocean/digitalocean.rb', line 71

def update_required?(*)
  false
end

#user_data_supported?Boolean

Returns:

  • (Boolean)


83
84
85
# File 'app/models/foreman_digitalocean/digitalocean.rb', line 83

def user_data_supported?
  true
end