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
- #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
- #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
138 139 140 |
# File 'app/models/foreman_gridscale/gridscale.rb', line 138 def self.model_name ComputeResource.model_name end |
.provider_friendly_name ⇒ Object
163 164 165 |
# File 'app/models/foreman_gridscale/gridscale.rb', line 163 def self.provider_friendly_name 'gridscale' end |
Instance Method Details
#api_token ⇒ Object
14 15 16 |
# File 'app/models/foreman_gridscale/gridscale.rb', line 14 def api_token attrs[:api_token] end |
#api_token=(api_token) ⇒ Object
22 23 24 |
# File 'app/models/foreman_gridscale/gridscale.rb', line 22 def api_token=(api_token) attrs[:api_token] = api_token end |
#associated_host(vm) ⇒ Object
46 47 48 |
# File 'app/models/foreman_gridscale/gridscale.rb', line 46 def associated_host(vm) associate_by('ip', [vm.ipv4_address]) end |
#available_templates ⇒ Object
129 130 131 132 133 134 135 136 |
# File 'app/models/foreman_gridscale/gridscale.rb', line 129 def available_templates images = [] collection = client.templates begin images += collection.to_a end until !collection.next_page images end |
#capabilities ⇒ Object
42 43 44 |
# File 'app/models/foreman_gridscale/gridscale.rb', line 42 def capabilities [:build, :images] end |
#create_vm(args = {}) ⇒ Object
50 51 52 53 54 55 56 57 58 59 |
# File 'app/models/foreman_gridscale/gridscale.rb', line 50 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.message}\n " + e.backtrace.join("\n ") raise e end |
#default_region_name ⇒ Object
157 158 159 160 161 |
# File 'app/models/foreman_gridscale/gridscale.rb', line 157 def default_region_name @default_region_name ||= 'de/fra' rescue Excon::Errors:: => e errors[:base] << e.response.body end |
#destroy_vm(uuid) ⇒ Object
73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 |
# File 'app/models/foreman_gridscale/gridscale.rb', line 73 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
142 143 144 145 146 |
# File 'app/models/foreman_gridscale/gridscale.rb', line 142 def find_vm_by_uuid(uuid) client.servers.get(uuid) rescue Fog::Compute::Gridscale::Error raise(ActiveRecord::RecordNotFound) end |
#get_ip(ipaddr_uuid) ⇒ Object
38 39 40 |
# File 'app/models/foreman_gridscale/gridscale.rb', line 38 def get_ip(ipaddr_uuid) client.ips.get(ipaddr_uuid).ip end |
#interfaces ⇒ Object
105 106 107 |
# File 'app/models/foreman_gridscale/gridscale.rb', line 105 def interfaces client.interfaces rescue [] end |
#ips ⇒ Object
101 102 103 |
# File 'app/models/foreman_gridscale/gridscale.rb', line 101 def ips client.ips end |
#network ⇒ Object
113 114 115 |
# File 'app/models/foreman_gridscale/gridscale.rb', line 113 def network client.networks.get(network_uuid) end |
#networks ⇒ Object
109 110 111 |
# File 'app/models/foreman_gridscale/gridscale.rb', line 109 def networks client.networks rescue [] end |
#new_interface(attr = {}) ⇒ Object
61 62 63 |
# File 'app/models/foreman_gridscale/gridscale.rb', line 61 def new_interface(attr = {}) client.interfaces.new attr end |
#power_check(uuid) ⇒ Object
65 66 67 |
# File 'app/models/foreman_gridscale/gridscale.rb', line 65 def power_check(uuid) client.server_power_get(uuid).body['power'] end |
#power_off(uuid) ⇒ Object
69 70 71 |
# File 'app/models/foreman_gridscale/gridscale.rb', line 69 def power_off(uuid) client.server_power_off(uuid) if power_check(uuid) end |
#provided_attributes ⇒ Object
34 35 36 |
# File 'app/models/foreman_gridscale/gridscale.rb', line 34 def provided_attributes super.merge({}) end |
#save_vm(uuid, attr) ⇒ Object
94 95 96 97 98 99 |
# File 'app/models/foreman_gridscale/gridscale.rb', line 94 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
125 126 127 |
# File 'app/models/foreman_gridscale/gridscale.rb', line 125 def sshkeys client.sshkeys end |
#storages ⇒ Object
117 118 119 |
# File 'app/models/foreman_gridscale/gridscale.rb', line 117 def storages client.storages end |
#templates ⇒ Object
121 122 123 |
# File 'app/models/foreman_gridscale/gridscale.rb', line 121 def templates client.templates end |
#test_connection(options = {}) ⇒ Object
148 149 150 151 152 153 154 155 |
# File 'app/models/foreman_gridscale/gridscale.rb', line 148 def test_connection( = {}) super errors[:token].empty? && errors[:uuid].empty? && networks.count rescue Excon::Errors:: => e errors[:base] << e.response.body rescue Fog::Errors::Error => e errors[:base] << e. end |
#to_label ⇒ Object
30 31 32 |
# File 'app/models/foreman_gridscale/gridscale.rb', line 30 def to_label "#{name} (#{provider_friendly_name})" end |
#user_data_supported? ⇒ Boolean
167 168 169 |
# File 'app/models/foreman_gridscale/gridscale.rb', line 167 def user_data_supported? true end |
#user_uuid ⇒ Object
18 19 20 |
# File 'app/models/foreman_gridscale/gridscale.rb', line 18 def user_uuid attrs[:user_uuid] end |
#user_uuid=(user_uuid) ⇒ Object
26 27 28 |
# File 'app/models/foreman_gridscale/gridscale.rb', line 26 def user_uuid=(user_uuid) attrs[:user_uuid] = user_uuid end |