-
Notifications
You must be signed in to change notification settings - Fork 92
/
Copy pathtemplate.rb
116 lines (94 loc) · 3.41 KB
/
template.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
class ManageIQ::Providers::Openstack::CloudManager::Template < ManageIQ::Providers::Openstack::CloudManager::BaseTemplate
include ManageIQ::Providers::Openstack::HelperMethods
belongs_to :cloud_tenant
include ManageIQ::Providers::Openstack::CloudManager::VmOrTemplateShared
has_and_belongs_to_many :cloud_tenants,
:foreign_key => "vm_id",
:join_table => "cloud_tenants_vms",
:association_foreign_key => "cloud_tenant_id",
:class_name => "ManageIQ::Providers::Openstack::CloudManager::CloudTenant"
supports :create_image do
if ext_management_system.nil?
_("The Image is not connected to an active %{table}") % {:table => ui_lookup(:table => "ext_management_system")}
end
end
supports :delete_image
def provider_object(connection = nil)
connection ||= ext_management_system.connect
connection.images.get(ems_ref)
end
def perform_metadata_scan(ost)
require 'OpenStackExtract/MiqOpenStackVm/MiqOpenStackImage'
image_id = ems_ref
_log.debug "image_id = #{image_id}"
ost.scanTime = Time.now.utc unless ost.scanTime
ems = ext_management_system
os_handle = ems.openstack_handle
begin
miqVm = MiqOpenStackImage.new(image_id, :os_handle => os_handle)
scan_via_miq_vm(miqVm, ost)
ensure
miqVm.unmount if miqVm
end
end
def perform_metadata_sync(ost)
sync_stashed_metadata(ost)
end
# TODO: Does this code need to be reimplemented?
def proxies4job(_job = nil)
{
:proxies => [MiqServer.my_server],
:message => 'Perform SmartState Analysis on this Image'
}
end
def allocated_disk_storage
hardware.try(:size_on_disk)
end
def has_active_proxy?
true
end
def has_proxy?
true
end
def requires_storage_for_scan?
false
end
def self.raw_create_image(ext_management_system, create_options)
ext_management_system.with_provider_connection(:service => 'Image') do |service|
service.create_image(create_options)
end
rescue => err
_log.error("image=[#{name}], error=[#{err}]")
raise MiqException::MiqOpenstackApiRequestError, parse_error_message_from_fog_response(err), err.backtrace
end
def self.create_image(ext_management_system, create_options)
raw_create_image(ext_management_system, create_options)
end
def raw_update_image(options)
ext_management_system.with_provider_connection(:service => 'Image') do |service|
image_attrs = service.images.find_by_id(ems_ref).attributes.stringify_keys
options = options.select { |k| image_attrs.key?(k) }
service.images.find_by_id(ems_ref).update(options)
end
rescue => err
_log.error("image=[#{name}], error: #{err}")
raise MiqException::MiqOpenstackApiRequestError, parse_error_message_from_fog_response(err), err.backtrace
end
def update_image(options)
raw_update_image(options)
end
def raw_delete_image
ext_management_system.with_provider_connection(:service => 'Image') do |service|
service.delete_image(ems_ref)
end
rescue => err
_log.error("image=[#{name}], error: #{err}")
raise MiqException::MiqOpenstackApiRequestError, parse_error_message_from_fog_response(err), err.backtrace
end
def delete_image
raw_delete_image
end
def self.display_name(number = 1)
n_('Image (OpenStack)', 'Images (OpenStack)', number)
end
end