Class: ForemanGridscale::Gridscale
- Inherits:
-
ComputeResource
- Object
- ComputeResource
- ForemanGridscale::Gridscale
- Defined in:
- app/models/foreman_gridscale/gridscale.rb
Class Method Summary collapse
Instance Method Summary collapse
- #api_token ⇒ Object
- #api_token=(api_token) ⇒ Object
- #associated_host(vm) ⇒ Object
- #available_templates ⇒ Object
- #capabilities ⇒ Object
- #create_vm(args = {}) ⇒ Object
- #default_region_name ⇒ Object
- #destroy_vm(uuid) ⇒ Object
- #find_vm_by_uuid(uuid) ⇒ Object
- #get_ip(ipaddr_uuid) ⇒ Object
- #interfaces ⇒ Object
- #ips ⇒ Object
- #isoimages ⇒ Object
- #network ⇒ Object
- #networks ⇒ Object
- #new_interface(attr = {}) ⇒ Object
- #power_check(uuid) ⇒ Object
- #power_off(uuid) ⇒ Object
- #provided_attributes ⇒ Object
- #save_vm(uuid, attr) ⇒ Object
- #sshkeys ⇒ Object
- #storages ⇒ Object
- #supports_update? ⇒ Boolean
- #templates ⇒ Object
- #test_connection(options = {}) ⇒ Object
- #to_label ⇒ Object
- #user_data_supported? ⇒ Boolean
- #user_uuid ⇒ Object
- #user_uuid=(user_uuid) ⇒ Object
Class Method Details
.model_name ⇒ Object
145 146 147 |
# File 'app/models/foreman_gridscale/gridscale.rb', line 145 def self.model_name ComputeResource.model_name end |
.provider_friendly_name ⇒ Object
170 171 172 |
# File 'app/models/foreman_gridscale/gridscale.rb', line 170 def self.provider_friendly_name 'gridscale' end |
Instance Method Details
#api_token ⇒ Object
17 18 19 |
# File 'app/models/foreman_gridscale/gridscale.rb', line 17 def api_token attrs[:api_token] end |
#api_token=(api_token) ⇒ Object
25 26 27 |
# File 'app/models/foreman_gridscale/gridscale.rb', line 25 def api_token=(api_token) attrs[:api_token] = api_token end |
#associated_host(vm) ⇒ Object
49 50 51 |
# File 'app/models/foreman_gridscale/gridscale.rb', line 49 def associated_host(vm) associate_by('ip', [vm.ipv4_address]) end |
#available_templates ⇒ Object
136 137 138 139 140 141 142 143 |
# File 'app/models/foreman_gridscale/gridscale.rb', line 136 def available_templates images = [] collection = client.templates begin images += collection.to_a end until !collection.next_page images end |
#capabilities ⇒ Object
45 46 47 |
# File 'app/models/foreman_gridscale/gridscale.rb', line 45 def capabilities [:build, :images] end |
#create_vm(args = {}) ⇒ Object
53 54 55 56 57 58 59 60 61 62 |
# File 'app/models/foreman_gridscale/gridscale.rb', line 53 def create_vm(args = {}) args['cores'] = args['cores'].to_i args['memory'] = args['memory'].to_i args['storage'] = args['storage'].to_i super(args) rescue Fog::Errors::Error => e logger.error "Unhandled gridscale error: #{e.status}:#{e.}\n " + e.backtrace.join("\n ") raise e end |
#default_region_name ⇒ Object
164 165 166 167 168 |
# File 'app/models/foreman_gridscale/gridscale.rb', line 164 def default_region_name @default_region_name ||= 'de/fra' rescue Excon::Errors::Unauthorized => e errors[:base] << e.response.body end |
#destroy_vm(uuid) ⇒ Object
76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 |
# File 'app/models/foreman_gridscale/gridscale.rb', line 76 def destroy_vm(uuid) attached_storage = [] client.servers.get(uuid).relations['storages'].each do |storage| attached_storage << storage['object_uuid'] end if power_check(uuid) client.server_power_off(uuid) end sleep(1) until client.servers.get(uuid).status != "in-provisioning" find_vm_by_uuid(uuid).destroy attached_storage.each do |storage_uuid| client.storages.destroy(storage_uuid) end rescue ActiveRecord::RecordNotFound # if the VM does not exists, we don't really care. true end |
#find_vm_by_uuid(uuid) ⇒ Object
149 150 151 152 153 |
# File 'app/models/foreman_gridscale/gridscale.rb', line 149 def find_vm_by_uuid(uuid) client.servers.get(uuid) rescue Fog::Compute::Gridscale::Error raise(ActiveRecord::RecordNotFound) end |
#get_ip(ipaddr_uuid) ⇒ Object
41 42 43 |
# File 'app/models/foreman_gridscale/gridscale.rb', line 41 def get_ip(ipaddr_uuid) client.ips.get(ipaddr_uuid).ip end |
#interfaces ⇒ Object
108 109 110 |
# File 'app/models/foreman_gridscale/gridscale.rb', line 108 def interfaces client.interfaces rescue [] end |
#ips ⇒ Object
104 105 106 |
# File 'app/models/foreman_gridscale/gridscale.rb', line 104 def ips client.ips end |
#isoimages ⇒ Object
132 133 134 |
# File 'app/models/foreman_gridscale/gridscale.rb', line 132 def isoimages client.isoimages end |
#network ⇒ Object
116 117 118 |
# File 'app/models/foreman_gridscale/gridscale.rb', line 116 def network client.networks.get(network_uuid) end |
#networks ⇒ Object
112 113 114 |
# File 'app/models/foreman_gridscale/gridscale.rb', line 112 def networks client.networks rescue [] end |
#new_interface(attr = {}) ⇒ Object
64 65 66 |
# File 'app/models/foreman_gridscale/gridscale.rb', line 64 def new_interface(attr = {}) client.interfaces.new attr end |
#power_check(uuid) ⇒ Object
68 69 70 |
# File 'app/models/foreman_gridscale/gridscale.rb', line 68 def power_check(uuid) client.server_power_get(uuid).body['power'] end |
#power_off(uuid) ⇒ Object
72 73 74 |
# File 'app/models/foreman_gridscale/gridscale.rb', line 72 def power_off(uuid) client.server_power_off(uuid) if power_check(uuid) end |
#provided_attributes ⇒ Object
37 38 39 |
# File 'app/models/foreman_gridscale/gridscale.rb', line 37 def provided_attributes super.merge({}) end |
#save_vm(uuid, attr) ⇒ Object
97 98 99 100 101 102 |
# File 'app/models/foreman_gridscale/gridscale.rb', line 97 def save_vm(uuid, attr) vm = find_vm_by_uuid(uuid) vm.attributes.merge!(attr.symbolize_keys).deep_symbolize_keys update_interfaces(vm, attr[:interfaces_attributes]) vm.save end |
#sshkeys ⇒ Object
128 129 130 |
# File 'app/models/foreman_gridscale/gridscale.rb', line 128 def sshkeys client.sshkeys end |
#storages ⇒ Object
120 121 122 |
# File 'app/models/foreman_gridscale/gridscale.rb', line 120 def storages client.storages end |
#supports_update? ⇒ Boolean
13 14 15 |
# File 'app/models/foreman_gridscale/gridscale.rb', line 13 def supports_update? true end |
#templates ⇒ Object
124 125 126 |
# File 'app/models/foreman_gridscale/gridscale.rb', line 124 def templates client.templates end |
#test_connection(options = {}) ⇒ Object
155 156 157 158 159 160 161 162 |
# File 'app/models/foreman_gridscale/gridscale.rb', line 155 def test_connection( = {}) super errors[:token].empty? && errors[:uuid].empty? && networks.count rescue Excon::Errors::Unauthorized => e errors[:base] << e.response.body rescue Fog::Errors::Error => e errors[:base] << e. end |
#to_label ⇒ Object
33 34 35 |
# File 'app/models/foreman_gridscale/gridscale.rb', line 33 def to_label "#{name} (#{provider_friendly_name})" end |
#user_data_supported? ⇒ Boolean
174 175 176 |
# File 'app/models/foreman_gridscale/gridscale.rb', line 174 def user_data_supported? true end |
#user_uuid ⇒ Object
21 22 23 |
# File 'app/models/foreman_gridscale/gridscale.rb', line 21 def user_uuid attrs[:user_uuid] end |
#user_uuid=(user_uuid) ⇒ Object
29 30 31 |
# File 'app/models/foreman_gridscale/gridscale.rb', line 29 def user_uuid=(user_uuid) attrs[:user_uuid] = user_uuid end |